28if (!defined(
'NOTOKENRENEWAL')) {
29 define(
'NOTOKENRENEWAL', 1);
31if (!defined(
'NOREQUIREMENU')) {
32 define(
'NOREQUIREMENU',
'1');
34if (!defined(
'NOREQUIREHTML')) {
35 define(
'NOREQUIREHTML',
'1');
37if (!defined(
'NOREQUIREAJAX')) {
38 define(
'NOREQUIREAJAX',
'1');
40if (empty($_GET[
'keysearch']) && !defined(
'NOREQUIREHTML')) {
41 define(
'NOREQUIREHTML',
'1');
45require
'../../main.inc.php';
55$htmlname =
GETPOST(
'htmlname',
'aZ09');
64$action =
GETPOST(
'action',
'aZ09');
68$alsoproductwithnosupplierprice =
GETPOSTINT(
'alsoproductwithnosupplierprice');
69$warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
70$hidepriceinlabel =
GETPOSTINT(
'hidepriceinlabel');
74restrictedArea($user,
'produit|service|commande|propal|facture', 0,
'product&product');
90if ($action ==
'fetch' && !empty($id)) {
92 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
93 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
95 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
104 $combinations =
GETPOST(
'combinations',
'array:alphanohtml');
105 if (!empty($combinations)) {
107 $combination = $prodcomb->fetchByProductCombination2ValuePairs($id, $combinations);
110 $id = (int) $combination->fk_product_child;
119 $outlabel_trans =
'';
120 $default_unit =
$object->fk_unit;
121 $outdesc =
$object->description;
125 $outprice_ttc =
null;
126 $outpricebasetype =
null;
127 $outtva_tx_formated = 0;
129 $outdefault_vat_code =
'';
132 $mandatory_period =
$object->mandatory_period;
137 $needchangeaccordingtothirdparty = 0;
139 $needchangeaccordingtothirdparty = 1;
142 $needchangeaccordingtothirdparty = 1;
144 if ($needchangeaccordingtothirdparty) {
145 $thirdpartytemp =
new Societe($db);
146 $thirdpartytemp->fetch($socid);
150 $newlang = $thirdpartytemp->default_lang;
152 if (!empty($newlang)) {
154 $outputlangs->setDefaultLang($newlang);
155 $outdesc_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"description"])) ?
$object->multilangs[$outputlangs->defaultlang][
"description"] :
$object->
description;
156 $outlabel_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"label"])) ?
$object->multilangs[$outputlangs->defaultlang][
"label"] :
$object->label;
158 $outdesc_trans =
$object->description;
159 $outlabel_trans =
$object->label;
165 $price_level = $thirdpartytemp->price_level;
171 if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
172 $sql =
"SELECT price, unitprice, quantity, remise_percent";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
174 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
176 $sql .=
" AND fk_product_price IN (SELECT pp.rowid FROM ".MAIN_DB_PREFIX.
"product_price as pp WHERE pp.fk_product = ".((int) $id).
")";
178 $result = $db->query($sql);
180 $objp = $db->fetch_object($result);
183 $outprice_ht =
price($objp->unitprice);
184 $outprice_ttc =
price($objp->unitprice * (1 + (
$object->tva_tx / 100)));
186 $outpricebasetype =
$object->price_base_type;
189 $outdefault_vat_code =
$object->default_vat_code;
191 $outqty = $objp->quantity;
192 $outdiscount = $objp->remise_percent;
199 $sql =
"SELECT price, price_ttc, price_base_type,";
200 $sql .=
" tva_tx, default_vat_code";
201 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
202 $sql .=
" WHERE fk_product = ".((int) $id);
203 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
204 $sql .=
" AND price_level = ".((int) $price_level);
205 $sql .=
" ORDER BY date_price DESC, rowid";
206 $sql .=
" DESC LIMIT 1";
208 $result = $db->query($sql);
210 $objp = $db->fetch_object($result);
213 $outprice_ht =
price($objp->price);
214 $outprice_ttc =
price($objp->price_ttc);
215 $outpricebasetype = $objp->price_base_type;
217 $outtva_tx_formated =
price($objp->tva_tx);
219 $outdefault_vat_code = $objp->default_vat_code;
224 $outdefault_vat_code =
$object->default_vat_code;
232 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
236 $filter = array(
't.fk_product' => (
string)
$object->id,
't.fk_soc' => (
string) $socid);
238 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
240 if (count($prodcustprice->lines) > 0) {
241 $date_now = (int) floor(
dol_now() / 86400) * 86400;
242 foreach ($prodcustprice->lines as $k => $custprice_line) {
243 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
245 $outprice_ht =
price($custprice_line->price);
246 $outprice_ttc =
price($custprice_line->price_ttc);
247 $outpricebasetype = $custprice_line->price_base_type;
248 $outtva_tx_formated =
price($custprice_line->tva_tx);
249 $outtva_tx =
price2num($custprice_line->tva_tx);
250 $outdefault_vat_code = $custprice_line->default_vat_code;
251 $outdiscount = $custprice_line->discount_percent;
262 $outpricebasetype =
$object->price_base_type;
265 $outdefault_vat_code =
$object->default_vat_code;
272 if (empty($outtva_tx) && empty($outdefault_vat_code)) {
273 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
275 if ($combination->fetchByFkProductChild(
$object->id, 1) > 0) {
277 if ($parent->fetch($combination->fk_product_parent) > 0) {
278 $outtva_tx_formated =
price($parent->tva_tx);
280 $outdefault_vat_code = $parent->default_vat_code;
281 $product_outtva_tx_formated = $outtva_tx_formated;
282 $product_outtva_tx = $outtva_tx;
283 $product_outdefault_vat_code = $outdefault_vat_code;
290 $product_outtva_tx_formated = $outtva_tx_formated;
291 $product_outtva_tx = $outtva_tx;
292 $product_outdefault_vat_code = $outdefault_vat_code;
295 if (
GETPOSTINT(
'addalsovatforthirdpartyid')) {
296 $thirdparty_buyer =
new Societe($db);
297 $thirdparty_buyer->fetch($socid);
301 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
303 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
305 $outtva_tx_formated =
price($outtva_tx);
306 $outdefault_vat_code = $reg[2];
309 $outtva_tx_formated =
price($outtva_tx);
310 $outdefault_vat_code =
'';
321 if (
getDolGlobalString(
'PRODUIT_RECALCULATE_TTC_ACCORDING_TO_BUYER_VAT') && isset($outprice_ht)) {
322 $outprice_ttc =
price((
float)
price2num($outprice_ht) * (1 + ($outtva_tx / 100)));
328 'label' => $outlabel,
329 'label_trans' => $outlabel_trans,
331 'desc_trans' => $outdesc_trans,
333 'price_ht' => $outprice_ht,
334 'price_ttc' => $outprice_ttc,
335 'pricebasetype' => $outpricebasetype,
336 'product_tva_tx_formated' => $product_outtva_tx_formated,
337 'product_tva_tx' => $product_outtva_tx,
338 'product_default_vat_code' => $product_outdefault_vat_code,
340 'tva_tx_formated' => $outtva_tx_formated,
341 'tva_tx' => $outtva_tx,
342 'default_vat_code' => $outdefault_vat_code,
345 'discount' => $outdiscount,
346 'mandatory_period' => $mandatory_period,
348 'array_options' =>
$object->array_options,
350 'default_unit' => $default_unit
354 echo json_encode($outjson);
356 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
357 if (!isset($form) || !is_object($form)) {
358 $form =
new Form($db);
361 $langs->loadLangs(array(
"main",
"products"));
365 if (empty($htmlname)) {
366 print json_encode(array());
373 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
376 $idprod = (empty($match[0]) ?
'' : $match[0]);
378 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
379 print json_encode(array());
384 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
387 if (empty($mode) || $mode == 1) {
388 $arrayresult = $form->select_produits_list(0, $htmlname, $type,
getDolGlobalInt(
'PRODUIT_LIMIT_SIZE', 1000), $price_level, $searchkey, $status, $finished, $outjson, $socid,
'1', 0,
'', $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
389 } elseif ($mode == 2) {
390 $arrayresult = $form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson,
getDolGlobalInt(
'PRODUIT_LIMIT_SIZE', 1000), $alsoproductwithnosupplierprice,
'',
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'));
396 print json_encode($arrayresult);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class ProductCombination Used to represent the relation between a product and one of its variants.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
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 a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) 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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.