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) {
130 $thirdpartytemp =
new Societe($db);
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 $result = $db->query($sql);
163 $objp = $db->fetch_object($result);
166 $outprice_ht =
price($objp->unitprice);
167 $outprice_ttc =
price($objp->unitprice * (1 + (
$object->tva_tx / 100)));
169 $outpricebasetype =
$object->price_base_type;
172 $outdefault_vat_code =
$object->default_vat_code;
174 $outqty = $objp->quantity;
175 $outdiscount = $objp->remise_percent;
182 $sql =
"SELECT price, price_ttc, price_base_type,";
183 $sql .=
" tva_tx, default_vat_code";
184 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
185 $sql .=
" WHERE fk_product = ".((int) $id);
186 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
187 $sql .=
" AND price_level = ".((int) $price_level);
188 $sql .=
" ORDER BY date_price DESC, rowid";
189 $sql .=
" DESC LIMIT 1";
191 $result = $db->query($sql);
193 $objp = $db->fetch_object($result);
196 $outprice_ht =
price($objp->price);
197 $outprice_ttc =
price($objp->price_ttc);
198 $outpricebasetype = $objp->price_base_type;
200 $outtva_tx_formated =
price($objp->tva_tx);
202 $outdefault_vat_code = $objp->default_vat_code;
207 $outdefault_vat_code =
$object->default_vat_code;
215 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
219 $filter = array(
't.fk_product' => (
string)
$object->id,
't.fk_soc' => (
string) $socid);
221 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
223 if (count($prodcustprice->lines) > 0) {
224 $date_now = (int) floor(
dol_now() / 86400) * 86400;
225 foreach ($prodcustprice->lines as $k => $custprice_line) {
226 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
228 $outprice_ht =
price($custprice_line->price);
229 $outprice_ttc =
price($custprice_line->price_ttc);
230 $outpricebasetype = $custprice_line->price_base_type;
231 $outtva_tx_formated =
price($custprice_line->tva_tx);
232 $outtva_tx =
price2num($custprice_line->tva_tx);
233 $outdefault_vat_code = $custprice_line->default_vat_code;
234 $outdiscount = $custprice_line->discount_percent;
245 $outpricebasetype =
$object->price_base_type;
248 $outdefault_vat_code =
$object->default_vat_code;
255 if (empty($outtva_tx) && empty($outdefault_vat_code)) {
256 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
258 if ($combination->fetchByFkProductChild(
$object->id, 1) > 0) {
260 if ($parent->fetch($combination->fk_product_parent) > 0) {
261 $outtva_tx_formated =
price($parent->tva_tx);
263 $outdefault_vat_code = $parent->default_vat_code;
264 $product_outtva_tx_formated = $outtva_tx_formated;
265 $product_outtva_tx = $outtva_tx;
266 $product_outdefault_vat_code = $outdefault_vat_code;
273 $product_outtva_tx_formated = $outtva_tx_formated;
274 $product_outtva_tx = $outtva_tx;
275 $product_outdefault_vat_code = $outdefault_vat_code;
278 if (
GETPOSTINT(
'addalsovatforthirdpartyid')) {
279 $thirdparty_buyer =
new Societe($db);
280 $thirdparty_buyer->fetch($socid);
284 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
286 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
288 $outtva_tx_formated =
price($outtva_tx);
289 $outdefault_vat_code = $reg[2];
292 $outtva_tx_formated =
price($outtva_tx);
293 $outdefault_vat_code =
'';
304 if (
getDolGlobalString(
'PRODUIT_RECALCULATE_TTC_ACCORDING_TO_BUYER_VAT') && isset($outprice_ht)) {
305 $outprice_ttc =
price((
float)
price2num($outprice_ht) * (1 + ($outtva_tx / 100)));
311 'label' => $outlabel,
312 'label_trans' => $outlabel_trans,
314 'desc_trans' => $outdesc_trans,
316 'price_ht' => $outprice_ht,
317 'price_ttc' => $outprice_ttc,
318 'pricebasetype' => $outpricebasetype,
319 'product_tva_tx_formated' => $product_outtva_tx_formated,
320 'product_tva_tx' => $product_outtva_tx,
321 'product_default_vat_code' => $product_outdefault_vat_code,
323 'tva_tx_formated' => $outtva_tx_formated,
324 'tva_tx' => $outtva_tx,
325 'default_vat_code' => $outdefault_vat_code,
328 'discount' => $outdiscount,
329 'mandatory_period' => $mandatory_period,
331 'array_options' =>
$object->array_options,
333 'default_unit' => $default_unit
337 echo json_encode($outjson);
339 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
340 if (!isset($form) || !is_object($form)) {
341 $form =
new Form($db);
344 $langs->loadLangs(array(
"main",
"products"));
348 if (empty($htmlname)) {
349 print json_encode(array());
356 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
359 $idprod = (empty($match[0]) ?
'' : $match[0]);
361 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
362 print json_encode(array());
367 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
370 if (empty($mode) || $mode == 1) {
371 $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);
372 } elseif ($mode == 2) {
373 $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'));
379 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.