26if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL', 1);
29if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
35if (!defined(
'NOREQUIREAJAX')) {
36 define(
'NOREQUIREAJAX',
'1');
38if (empty($_GET[
'keysearch']) && !defined(
'NOREQUIREHTML')) {
39 define(
'NOREQUIREHTML',
'1');
43require
'../../main.inc.php';
45$htmlname =
GETPOST(
'htmlname',
'aZ09');
46$socid =
GETPOST(
'socid',
'int');
49$status = ((
GETPOST(
'status',
'int') >= 0) ?
GETPOST(
'status',
'int') : - 1);
50$status_purchase = ((
GETPOST(
'status_purchase',
'int') >= 0) ?
GETPOST(
'status_purchase',
'int') : - 1);
51$outjson = (
GETPOST(
'outjson',
'int') ?
GETPOST(
'outjson',
'int') : 0);
52$price_level =
GETPOST(
'price_level',
'int');
53$action =
GETPOST(
'action',
'aZ09');
55$price_by_qty_rowid =
GETPOST(
'pbq',
'int');
56$finished =
GETPOST(
'finished',
'int');
57$alsoproductwithnosupplierprice =
GETPOST(
'alsoproductwithnosupplierprice',
'int');
58$warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
59$hidepriceinlabel =
GETPOST(
'hidepriceinlabel',
'int');
72if ($action ==
'fetch' && !empty($id)) {
74 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
75 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
82 $ret = $object->fetch($id);
84 $outref = $object->ref;
85 $outlabel = $object->label;
87 $outdesc = $object->description;
89 $outtype = $object->type;
92 $outpricebasetype =
null;
93 $outtva_tx_formated = 0;
95 $outdefault_vat_code =
'';
98 $mandatory_period = $object->mandatory_period;
103 $needchangeaccordingtothirdparty = 0;
105 $needchangeaccordingtothirdparty = 1;
108 $needchangeaccordingtothirdparty = 1;
110 if ($needchangeaccordingtothirdparty) {
111 $thirdpartytemp =
new Societe($db);
112 $thirdpartytemp->fetch($socid);
116 $newlang = $thirdpartytemp->default_lang;
118 if (!empty($newlang)) {
120 $outputlangs->setDefaultLang($newlang);
121 $outdesc_trans = (!empty($object->multilangs[$outputlangs->defaultlang][
"description"])) ? $object->multilangs[$outputlangs->defaultlang][
"description"] : $object->
description;
122 $outlabel_trans = (!empty($object->multilangs[$outputlangs->defaultlang][
"label"])) ? $object->multilangs[$outputlangs->defaultlang][
"label"] : $object->label;
124 $outdesc_trans = $object->description;
125 $outlabel_trans = $object->label;
131 $price_level = $thirdpartytemp->price_level;
137 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))) {
138 $sql =
"SELECT price, unitprice, quantity, remise_percent";
139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
140 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
142 $result = $db->query($sql);
144 $objp = $db->fetch_object($result);
147 $outprice_ht =
price($objp->unitprice);
148 $outprice_ttc =
price($objp->unitprice * (1 + ($object->tva_tx / 100)));
150 $outpricebasetype = $object->price_base_type;
151 $outtva_tx_formated =
price($object->tva_tx);
153 $outdefault_vat_code = $object->default_vat_code;
155 $outqty = $objp->quantity;
156 $outdiscount = $objp->remise_percent;
162 if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
163 $sql =
"SELECT price, price_ttc, price_base_type,";
164 $sql .=
" tva_tx, default_vat_code";
165 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
166 $sql .=
" WHERE fk_product = ".((int) $id);
167 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
168 $sql .=
" AND price_level = ".((int) $price_level);
169 $sql .=
" ORDER BY date_price";
170 $sql .=
" DESC LIMIT 1";
172 $result = $db->query($sql);
174 $objp = $db->fetch_object($result);
177 $outprice_ht =
price($objp->price);
178 $outprice_ttc =
price($objp->price_ttc);
179 $outpricebasetype = $objp->price_base_type;
180 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
181 $outtva_tx_formated =
price($objp->tva_tx);
183 $outdefault_vat_code = $objp->default_vat_code;
186 $outtva_tx_formated =
price($object->tva_tx);
188 $outdefault_vat_code = $object->default_vat_code;
196 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
200 $filter = array(
't.fk_product' => $object->id,
't.fk_soc' => $socid);
202 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
204 if (count($prodcustprice->lines) > 0) {
206 $outprice_ht =
price($prodcustprice->lines[0]->price);
207 $outprice_ttc =
price($prodcustprice->lines[0]->price_ttc);
208 $outpricebasetype = $prodcustprice->lines[0]->price_base_type;
209 $outtva_tx_formated =
price($prodcustprice->lines[0]->tva_tx);
210 $outtva_tx =
price2num($prodcustprice->lines[0]->tva_tx);
211 $outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code;
217 $outprice_ht =
price($object->price);
218 $outprice_ttc =
price($object->price_ttc);
219 $outpricebasetype = $object->price_base_type;
220 $outtva_tx_formated =
price($object->tva_tx);
222 $outdefault_vat_code = $object->default_vat_code;
226 $product_outtva_tx_formated = $outtva_tx_formated;
227 $product_outtva_tx = $outtva_tx;
228 $product_outdefault_vat_code = $outdefault_vat_code;
231 if (
GETPOST(
'addalsovatforthirdpartyid',
'int')) {
232 $thirdparty_buyer =
new Societe($db);
233 $thirdparty_buyer->fetch($socid);
237 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
239 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
241 $outtva_tx_formated =
price($outtva_tx);
242 $outdefault_vat_code = $reg[2];
245 $outtva_tx_formated =
price($outtva_tx);
246 $outdefault_vat_code =
'';
253 'label' => $outlabel,
254 'label_trans' => $outlabel_trans,
256 'desc_trans' => $outdesc_trans,
258 'price_ht' => $outprice_ht,
259 'price_ttc' => $outprice_ttc,
260 'pricebasetype' => $outpricebasetype,
261 'product_tva_tx_formated' => $product_outtva_tx_formated,
262 'product_tva_tx' => $product_outtva_tx,
263 'product_default_vat_code' => $product_outdefault_vat_code,
265 'tva_tx_formated' => $outtva_tx_formated,
266 'tva_tx' => $outtva_tx,
267 'default_vat_code' => $outdefault_vat_code,
270 'discount' => $outdiscount,
271 'mandatory_period' => $mandatory_period,
272 'array_options'=>$object->array_options
276 echo json_encode($outjson);
278 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
280 $langs->loadLangs(array(
"main",
"products"));
284 if (empty($htmlname)) {
285 print json_encode(array());
292 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
295 $idprod = (empty($match[0]) ?
'' : $match[0]);
297 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
298 print json_encode(array());
303 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
305 if (!isset($form) || !is_object($form)) {
306 $form =
new Form($db);
309 if (empty($mode) || $mode == 1) {
310 $arrayresult = $form->select_produits_list(
"", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid,
'1', 0,
'', $hidepriceinlabel, $warehouseStatus, $status_purchase);
311 } elseif ($mode == 2) {
312 $arrayresult = $form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice);
318 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.
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.
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.
getDolGlobalString($key, $default='')
Return 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.