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';
56$htmlname =
GETPOST(
'htmlname',
'aZ09');
65$action =
GETPOST(
'action',
'aZ09');
69$alsoproductwithnosupplierprice =
GETPOSTINT(
'alsoproductwithnosupplierprice');
70$warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
71$hidepriceinlabel =
GETPOSTINT(
'hidepriceinlabel');
75restrictedArea($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 $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;
252 $product_outtva_tx_formated = $outtva_tx_formated;
253 $product_outtva_tx = $outtva_tx;
254 $product_outdefault_vat_code = $outdefault_vat_code;
257 if (
GETPOSTINT(
'addalsovatforthirdpartyid')) {
259 $thirdparty_buyer->fetch($socid);
263 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
265 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
267 $outtva_tx_formated =
price($outtva_tx);
268 $outdefault_vat_code = $reg[2];
271 $outtva_tx_formated =
price($outtva_tx);
272 $outdefault_vat_code =
'';
279 'label' => $outlabel,
280 'label_trans' => $outlabel_trans,
282 'desc_trans' => $outdesc_trans,
284 'price_ht' => $outprice_ht,
285 'price_ttc' => $outprice_ttc,
286 'pricebasetype' => $outpricebasetype,
287 'product_tva_tx_formated' => $product_outtva_tx_formated,
288 'product_tva_tx' => $product_outtva_tx,
289 'product_default_vat_code' => $product_outdefault_vat_code,
291 'tva_tx_formated' => $outtva_tx_formated,
292 'tva_tx' => $outtva_tx,
293 'default_vat_code' => $outdefault_vat_code,
296 'discount' => $outdiscount,
297 'mandatory_period' => $mandatory_period,
299 'array_options' =>
$object->array_options,
301 'default_unit' => $default_unit
305 echo json_encode($outjson);
307 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
309 $langs->loadLangs(array(
"main",
"products"));
313 if (empty($htmlname)) {
314 print json_encode(array());
321 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
324 $idprod = (empty($match[0]) ?
'' : $match[0]);
326 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
327 print json_encode(array());
332 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
334 if (!isset($form) || !is_object($form)) {
339 if (empty($mode) || $mode == 1) {
340 $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);
341 } elseif ($mode == 2) {
342 $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'));
348 print json_encode($arrayresult);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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)
Return value of a param into GET or POST supervariable.
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, $mode=0)
Check permissions of a user to show a page and an object.