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 (empty($_GET[
'keysearch']) && !defined(
'NOREQUIREHTML')) {
42 define(
'NOREQUIREHTML',
'1');
46 require
'../../main.inc.php';
48 $htmlname =
GETPOST(
'htmlname',
'aZ09');
49 $socid =
GETPOST(
'socid',
'int');
52 $status = ((
GETPOST(
'status',
'int') >= 0) ?
GETPOST(
'status',
'int') : - 1);
53 $status_purchase = ((
GETPOST(
'status_purchase',
'int') >= 0) ?
GETPOST(
'status_purchase',
'int') : - 1);
54 $outjson = (
GETPOST(
'outjson',
'int') ?
GETPOST(
'outjson',
'int') : 0);
55 $price_level =
GETPOST(
'price_level',
'int');
56 $action =
GETPOST(
'action',
'aZ09');
58 $price_by_qty_rowid =
GETPOST(
'pbq',
'int');
59 $finished =
GETPOST(
'finished',
'int');
60 $alsoproductwithnosupplierprice =
GETPOST(
'alsoproductwithnosupplierprice',
'int');
61 $warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
62 $hidepriceinlabel =
GETPOST(
'hidepriceinlabel',
'int');
75 if ($action ==
'fetch' && !empty($id)) {
77 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
78 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;
96 $outtva_tx_formated = 0;
98 $outdefault_vat_code =
'';
101 $mandatory_period = $object->mandatory_period;
106 $thirdpartytemp =
new Societe($db);
107 $thirdpartytemp->fetch($socid);
110 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
111 $newlang = $thirdpartytemp->default_lang;
113 if (!empty($newlang)) {
115 $outputlangs->setDefaultLang($newlang);
116 $outdesc_trans = (!empty($object->multilangs[$outputlangs->defaultlang][
"description"])) ? $object->multilangs[$outputlangs->defaultlang][
"description"] : $object->description;
117 $outlabel_trans = (!empty($object->multilangs[$outputlangs->defaultlang][
"label"])) ? $object->multilangs[$outputlangs->defaultlang][
"label"] : $object->label;
119 $outdesc_trans = $object->description;
120 $outlabel_trans = $object->label;
124 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
125 $price_level = $thirdpartytemp->price_level;
130 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))) {
131 $sql =
"SELECT price, unitprice, quantity, remise_percent";
132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
133 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
135 $result = $db->query($sql);
137 $objp = $db->fetch_object($result);
140 $outprice_ht =
price($objp->unitprice);
141 $outprice_ttc =
price($objp->unitprice * (1 + ($object->tva_tx / 100)));
143 $outpricebasetype = $object->price_base_type;
144 $outtva_tx_formated =
price($object->tva_tx);
146 $outdefault_vat_code = $object->default_vat_code;
148 $outqty = $objp->quantity;
149 $outdiscount = $objp->remise_percent;
155 if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
156 $sql =
"SELECT price, price_ttc, price_base_type,";
157 $sql .=
" tva_tx, default_vat_code";
158 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
159 $sql .=
" WHERE fk_product = ".((int) $id);
160 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
161 $sql .=
" AND price_level = ".((int) $price_level);
162 $sql .=
" ORDER BY date_price";
163 $sql .=
" DESC LIMIT 1";
165 $result = $db->query($sql);
167 $objp = $db->fetch_object($result);
170 $outprice_ht =
price($objp->price);
171 $outprice_ttc =
price($objp->price_ttc);
172 $outpricebasetype = $objp->price_base_type;
173 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
174 $outtva_tx_formated =
price($objp->tva_tx);
176 $outdefault_vat_code = $objp->default_vat_code;
179 $outtva_tx_formated =
price($object->tva_tx);
181 $outdefault_vat_code = $object->default_vat_code;
188 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
189 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
193 $filter = array(
't.fk_product' => $object->id,
't.fk_soc' => $socid);
195 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
197 if (count($prodcustprice->lines) > 0) {
199 $outprice_ht =
price($prodcustprice->lines[0]->price);
200 $outprice_ttc =
price($prodcustprice->lines[0]->price_ttc);
201 $outpricebasetype = $prodcustprice->lines[0]->price_base_type;
202 $outtva_tx_formated =
price($prodcustprice->lines[0]->tva_tx);
203 $outtva_tx =
price2num($prodcustprice->lines[0]->tva_tx);
204 $outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code;
210 $outprice_ht =
price($object->price);
211 $outprice_ttc =
price($object->price_ttc);
212 $outpricebasetype = $object->price_base_type;
213 $outtva_tx_formated =
price($object->tva_tx);
215 $outdefault_vat_code = $object->default_vat_code;
220 'label' => $outlabel,
221 'label_trans' => $outlabel_trans,
223 'desc_trans' => $outdesc_trans,
225 'price_ht' => $outprice_ht,
226 'price_ttc' => $outprice_ttc,
227 'pricebasetype' => $outpricebasetype,
228 'tva_tx_formated' => $outtva_tx_formated,
229 'tva_tx' => $outtva_tx,
230 'default_vat_code' => $outdefault_vat_code,
232 'discount' => $outdiscount,
233 'mandatory_period' => $mandatory_period,
234 'array_options'=>$object->array_options);
237 echo json_encode($outjson);
239 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
241 $langs->loadLangs(array(
"main",
"products"));
245 if (empty($htmlname)) {
246 print json_encode(array());
253 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
256 $idprod = (empty($match[0]) ?
'' : $match[0]);
258 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
259 print json_encode(array());
264 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
270 if (empty($mode) || $mode == 1) {
271 $arrayresult =
$form->select_produits_list(
"", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid,
'1', 0,
'', $hidepriceinlabel, $warehouseStatus, $status_purchase);
272 } elseif ($mode == 2) {
273 $arrayresult =
$form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice);
279 print json_encode($arrayresult);
Class to manage products or services.
File of class to manage predefined price products or services by customer.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.