26 if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL', 1);
29 if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32 if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
35 if (!defined(
'NOREQUIREAJAX')) {
36 define(
'NOREQUIREAJAX',
'1');
38 if (!defined(
'NOREQUIRESOC')) {
39 define(
'NOREQUIRESOC',
'1');
41 if (!defined(
'NOCSRFCHECK')) {
42 define(
'NOCSRFCHECK',
'1');
44 if (empty($_GET[
'keysearch']) && !defined(
'NOREQUIREHTML')) {
45 define(
'NOREQUIREHTML',
'1');
48 require
'../../main.inc.php';
50 $htmlname =
GETPOST(
'htmlname',
'aZ09');
51 $socid =
GETPOST(
'socid',
'int');
54 $status = ((
GETPOST(
'status',
'int') >= 0) ?
GETPOST(
'status',
'int') : - 1);
55 $status_purchase = ((
GETPOST(
'status_purchase',
'int') >= 0) ?
GETPOST(
'status_purchase',
'int') : - 1);
56 $outjson = (
GETPOST(
'outjson',
'int') ?
GETPOST(
'outjson',
'int') : 0);
57 $price_level =
GETPOST(
'price_level',
'int');
58 $action =
GETPOST(
'action',
'aZ09');
60 $price_by_qty_rowid =
GETPOST(
'pbq',
'int');
61 $finished =
GETPOST(
'finished',
'int');
62 $alsoproductwithnosupplierprice =
GETPOST(
'alsoproductwithnosupplierprice',
'int');
63 $warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
64 $hidepriceinlabel =
GETPOST(
'hidepriceinlabel',
'int');
77 if ($action ==
'fetch' && !empty($id)) {
79 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
80 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
85 $ret = $object->fetch($id);
87 $outref = $object->ref;
88 $outlabel = $object->label;
90 $outdesc = $object->description;
92 $outtype = $object->type;
95 $outpricebasetype =
null;
97 $outdefault_vat_code =
'';
100 $mandatory_period = $object->mandatory_period;
105 $thirdpartytemp =
new Societe($db);
106 $thirdpartytemp->fetch($socid);
109 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
110 $newlang = $thirdpartytemp->default_lang;
112 if (!empty($newlang)) {
114 $outputlangs->setDefaultLang($newlang);
115 $outdesc_trans = (!empty($object->multilangs[$outputlangs->defaultlang][
"description"])) ? $object->multilangs[$outputlangs->defaultlang][
"description"] : $object->description;
116 $outlabel_trans = (!empty($object->multilangs[$outputlangs->defaultlang][
"label"])) ? $object->multilangs[$outputlangs->defaultlang][
"label"] : $object->label;
118 $outdesc_trans = $object->description;
119 $outlabel_trans = $object->label;
123 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
124 $price_level = $thirdpartytemp->price_level;
129 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))) {
130 $sql =
"SELECT price, unitprice, quantity, remise_percent";
131 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
132 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
134 $result = $db->query($sql);
136 $objp = $db->fetch_object($result);
139 $outprice_ht =
price($objp->unitprice);
140 $outprice_ttc =
price($objp->unitprice * (1 + ($object->tva_tx / 100)));
142 $outpricebasetype = $object->price_base_type;
143 $outtva_tx = $object->tva_tx;
144 $outdefault_vat_code = $object->default_vat_code;
146 $outqty = $objp->quantity;
147 $outdiscount = $objp->remise_percent;
153 if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
154 $sql =
"SELECT price, price_ttc, price_base_type,";
155 $sql .=
" tva_tx, default_vat_code";
156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
157 $sql .=
" WHERE fk_product = ".((int) $id);
158 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
159 $sql .=
" AND price_level = ".((int) $price_level);
160 $sql .=
" ORDER BY date_price";
161 $sql .=
" DESC LIMIT 1";
163 $result = $db->query($sql);
165 $objp = $db->fetch_object($result);
168 $outprice_ht =
price($objp->price);
169 $outprice_ttc =
price($objp->price_ttc);
170 $outpricebasetype = $objp->price_base_type;
171 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
172 $outtva_tx = $objp->tva_tx;
173 $outdefault_vat_code = $objp->default_vat_code;
176 $outtva_tx = $object->tva_tx;
177 $outdefault_vat_code = $object->default_vat_code;
184 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
185 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
189 $filter = array(
't.fk_product' => $object->id,
't.fk_soc' => $socid);
191 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
193 if (count($prodcustprice->lines) > 0) {
195 $outprice_ht =
price($prodcustprice->lines[0]->price);
196 $outprice_ttc =
price($prodcustprice->lines[0]->price_ttc);
197 $outpricebasetype = $prodcustprice->lines[0]->price_base_type;
198 $outtva_tx = $prodcustprice->lines[0]->tva_tx;
199 $outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code;
205 $outprice_ht =
price($object->price);
206 $outprice_ttc =
price($object->price_ttc);
207 $outpricebasetype = $object->price_base_type;
208 $outtva_tx = $object->tva_tx;
209 $outdefault_vat_code = $object->default_vat_code;
214 'label' => $outlabel,
215 'label_trans' => $outlabel_trans,
217 'desc_trans' => $outdesc_trans,
219 'price_ht' => $outprice_ht,
220 'price_ttc' => $outprice_ttc,
221 'pricebasetype' => $outpricebasetype,
222 'tva_tx' => $outtva_tx,
223 'default_vat_code' => $outdefault_vat_code,
225 'discount' => $outdiscount,
226 'mandatory_period' => $mandatory_period,
227 'array_options'=>$object->array_options);
230 echo json_encode($outjson);
232 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
234 $langs->loadLangs(array(
"main",
"products"));
238 if (empty($htmlname)) {
239 print json_encode(array());
246 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
249 $idprod = (empty($match[0]) ?
'' : $match[0]);
251 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
252 print json_encode(array());
257 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
263 if (empty($mode) || $mode == 1) {
264 $arrayresult =
$form->select_produits_list(
"", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid,
'1', 0,
'', $hidepriceinlabel, $warehouseStatus, $status_purchase);
265 } elseif ($mode == 2) {
266 $arrayresult =
$form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice);
272 print json_encode($arrayresult);