26 if (!defined(
'NOTOKENRENEWAL')) define(
'NOTOKENRENEWAL', 1);
27 if (!defined(
'NOREQUIREMENU')) define(
'NOREQUIREMENU',
'1');
28 if (!defined(
'NOREQUIREHTML')) define(
'NOREQUIREHTML',
'1');
29 if (!defined(
'NOREQUIREAJAX')) define(
'NOREQUIREAJAX',
'1');
30 if (!defined(
'NOREQUIRESOC')) define(
'NOREQUIRESOC',
'1');
31 if (!defined(
'NOCSRFCHECK')) define(
'NOCSRFCHECK',
'1');
32 if (empty($_GET[
'keysearch']) && !defined(
'NOREQUIREHTML')) define(
'NOREQUIREHTML',
'1');
34 require
'../../main.inc.php';
36 $htmlname =
GETPOST(
'htmlname',
'alpha');
37 $socid =
GETPOST(
'socid',
'int');
40 $status = ((
GETPOST(
'status',
'int') >= 0) ?
GETPOST(
'status',
'int') : - 1);
41 $outjson = (
GETPOST(
'outjson',
'int') ?
GETPOST(
'outjson',
'int') : 0);
42 $price_level =
GETPOST(
'price_level',
'int');
43 $action =
GETPOST(
'action',
'aZ09');
45 $price_by_qty_rowid =
GETPOST(
'pbq',
'int');
46 $finished =
GETPOST(
'finished',
'int');
47 $alsoproductwithnosupplierprice =
GETPOST(
'alsoproductwithnosupplierprice',
'int');
48 $warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
49 $hidepriceinlabel =
GETPOST(
'hidepriceinlabel',
'int');
61 if (!empty($action) && $action ==
'fetch' && !empty($id))
64 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
65 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
70 $ret = $object->fetch($id);
73 $outref = $object->ref;
74 $outlabel = $object->label;
75 $outdesc = $object->description;
76 $outtype = $object->type;
83 if ($socid > 0 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
84 $thirdpartytemp =
new Societe($db);
85 $thirdpartytemp->fetch($socid);
86 $price_level = $thirdpartytemp->price_level;
90 if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)))
92 $sql =
"SELECT price, unitprice, quantity, remise_percent";
93 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty ";
94 $sql .=
" WHERE rowid=".$price_by_qty_rowid.
"";
96 $result = $db->query($sql);
98 $objp = $db->fetch_object($result);
101 $outprice_ht =
price($objp->unitprice);
102 $outprice_ttc =
price($objp->unitprice * (1 + ($object->tva_tx / 100)));
103 $outpricebasetype = $object->price_base_type;
104 $outtva_tx = $object->tva_tx;
105 $outqty = $objp->quantity;
106 $outdiscount = $objp->remise_percent;
112 if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)))
114 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx";
115 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
116 $sql .=
" WHERE fk_product = '".$id.
"'";
117 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
118 $sql .=
" AND price_level = ".((int) $price_level);
119 $sql .=
" ORDER BY date_price";
120 $sql .=
" DESC LIMIT 1";
122 $result = $db->query($sql);
124 $objp = $db->fetch_object($result);
127 $outprice_ht =
price($objp->price);
128 $outprice_ttc =
price($objp->price_ttc);
129 $outpricebasetype = $objp->price_base_type;
130 $outtva_tx = $objp->tva_tx;
136 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
137 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
141 $filter = array(
't.fk_product' => $object->id,
't.fk_soc' => $socid);
143 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
145 if (count($prodcustprice->lines) > 0) {
147 $outprice_ht =
price($prodcustprice->lines [0]->price);
148 $outprice_ttc =
price($prodcustprice->lines [0]->price_ttc);
149 $outpricebasetype = $prodcustprice->lines [0]->price_base_type;
150 $outtva_tx = $prodcustprice->lines [0]->tva_tx;
156 $outprice_ht =
price($object->price);
157 $outprice_ttc =
price($object->price_ttc);
158 $outpricebasetype = $object->price_base_type;
159 $outtva_tx = $object->tva_tx;
162 $outjson = array(
'ref' => $outref,
'label' => $outlabel,
'desc' => $outdesc,
'type' => $outtype,
'price_ht' => $outprice_ht,
'price_ttc' => $outprice_ttc,
'pricebasetype' => $outpricebasetype,
'tva_tx' => $outtva_tx,
'qty' => $outqty,
'discount' => $outdiscount);
165 echo json_encode($outjson);
167 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
169 $langs->loadLangs(array(
"main",
"products"));
173 if (empty($htmlname))
175 print json_encode(array());
179 $match = preg_grep(
'/('.$htmlname.
'[0-9]+)/', array_keys($_GET));
182 $idprod = (!empty($match[0]) ? $match[0] :
'');
184 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha')))
186 print json_encode(array());
191 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
193 $form =
new Form($db);
195 if (empty($mode) || $mode == 1) {
196 $arrayresult = $form->select_produits_list(
"", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid,
'1', 0,
'', $hidepriceinlabel, $warehouseStatus);
197 } elseif ($mode == 2) {
198 $arrayresult = $form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice);
204 print json_encode($arrayresult);
File of class to manage predefined price products or services by customer.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to manage third parties objects (customers, suppliers, prospects...)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.