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';
104 $outlabel_trans =
'';
105 $default_unit =
$object->fk_unit;
106 $outdesc =
$object->description;
110 $outprice_ttc =
null;
111 $outpricebasetype =
null;
112 $outtva_tx_formated = 0;
114 $outdefault_vat_code =
'';
117 $mandatory_period =
$object->mandatory_period;
122 $needchangeaccordingtothirdparty = 0;
124 $needchangeaccordingtothirdparty = 1;
127 $needchangeaccordingtothirdparty = 1;
129 if ($needchangeaccordingtothirdparty) {
131 $thirdpartytemp->fetch($socid);
135 $newlang = $thirdpartytemp->default_lang;
137 if (!empty($newlang)) {
139 $outputlangs->setDefaultLang($newlang);
140 $outdesc_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"description"])) ?
$object->multilangs[$outputlangs->defaultlang][
"description"] :
$object->
description;
141 $outlabel_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"label"])) ?
$object->multilangs[$outputlangs->defaultlang][
"label"] :
$object->label;
143 $outdesc_trans =
$object->description;
144 $outlabel_trans =
$object->label;
150 $price_level = $thirdpartytemp->price_level;
156 if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
157 $sql =
"SELECT price, unitprice, quantity, remise_percent";
158 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
159 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
161 $sql .=
" AND fk_product_price IN (SELECT pp.rowid FROM ".MAIN_DB_PREFIX.
"product_price as pp WHERE pp.fk_product = ".((int) $id).
")";
163 $result =
$db->query($sql);
165 $objp =
$db->fetch_object($result);
168 $outprice_ht =
price($objp->unitprice);
169 $outprice_ttc =
price($objp->unitprice * (1 + (
$object->tva_tx / 100)));
171 $outpricebasetype =
$object->price_base_type;
174 $outdefault_vat_code =
$object->default_vat_code;
176 $outqty = $objp->quantity;
177 $outdiscount = $objp->remise_percent;
184 $sql =
"SELECT price, price_ttc, price_base_type,";
185 $sql .=
" tva_tx, default_vat_code";
186 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
187 $sql .=
" WHERE fk_product = ".((int) $id);
188 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
189 $sql .=
" AND price_level = ".((int) $price_level);
190 $sql .=
" ORDER BY date_price DESC, rowid";
191 $sql .=
" DESC LIMIT 1";
193 $result =
$db->query($sql);
195 $objp =
$db->fetch_object($result);
198 $outprice_ht =
price($objp->price);
199 $outprice_ttc =
price($objp->price_ttc);
200 $outpricebasetype = $objp->price_base_type;
202 $outtva_tx_formated =
price($objp->tva_tx);
204 $outdefault_vat_code = $objp->default_vat_code;
209 $outdefault_vat_code =
$object->default_vat_code;
217 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
221 $filter = array(
't.fk_product' => (
string)
$object->id,
't.fk_soc' => (
string) $socid);
223 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
225 if (count($prodcustprice->lines) > 0) {
226 $date_now = (int) floor(
dol_now() / 86400) * 86400;
227 foreach ($prodcustprice->lines as $k => $custprice_line) {
228 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
230 $outprice_ht =
price($custprice_line->price);
231 $outprice_ttc =
price($custprice_line->price_ttc);
232 $outpricebasetype = $custprice_line->price_base_type;
233 $outtva_tx_formated =
price($custprice_line->tva_tx);
234 $outtva_tx =
price2num($custprice_line->tva_tx);
235 $outdefault_vat_code = $custprice_line->default_vat_code;
236 $outdiscount = $custprice_line->discount_percent;
247 $outpricebasetype =
$object->price_base_type;
250 $outdefault_vat_code =
$object->default_vat_code;
257 if (empty($outtva_tx) && empty($outdefault_vat_code)) {
258 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
260 if ($combination->fetchByFkProductChild(
$object->id, 1) > 0) {
262 if ($parent->fetch($combination->fk_product_parent) > 0) {
263 $outtva_tx_formated =
price($parent->tva_tx);
265 $outdefault_vat_code = $parent->default_vat_code;
266 $product_outtva_tx_formated = $outtva_tx_formated;
267 $product_outtva_tx = $outtva_tx;
268 $product_outdefault_vat_code = $outdefault_vat_code;
275 $product_outtva_tx_formated = $outtva_tx_formated;
276 $product_outtva_tx = $outtva_tx;
277 $product_outdefault_vat_code = $outdefault_vat_code;
280 if (
GETPOSTINT(
'addalsovatforthirdpartyid')) {
282 $thirdparty_buyer->fetch($socid);
286 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
288 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
290 $outtva_tx_formated =
price($outtva_tx);
291 $outdefault_vat_code = $reg[2];
294 $outtva_tx_formated =
price($outtva_tx);
295 $outdefault_vat_code =
'';
302 'label' => $outlabel,
303 'label_trans' => $outlabel_trans,
305 'desc_trans' => $outdesc_trans,
307 'price_ht' => $outprice_ht,
308 'price_ttc' => $outprice_ttc,
309 'pricebasetype' => $outpricebasetype,
310 'product_tva_tx_formated' => $product_outtva_tx_formated,
311 'product_tva_tx' => $product_outtva_tx,
312 'product_default_vat_code' => $product_outdefault_vat_code,
314 'tva_tx_formated' => $outtva_tx_formated,
315 'tva_tx' => $outtva_tx,
316 'default_vat_code' => $outdefault_vat_code,
319 'discount' => $outdiscount,
320 'mandatory_period' => $mandatory_period,
322 'array_options' =>
$object->array_options,
324 'default_unit' => $default_unit
328 echo json_encode($outjson);
330 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
331 if (!isset($form) || !is_object($form)) {
335 $langs->loadLangs(array(
"main",
"products"));
339 if (empty($htmlname)) {
340 print json_encode(array());
347 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
350 $idprod = (empty($match[0]) ?
'' : $match[0]);
352 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
353 print json_encode(array());
358 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
361 if (empty($mode) || $mode == 1) {
362 $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);
363 } elseif ($mode == 2) {
364 $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'));
370 print json_encode($arrayresult);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
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)
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.
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.