27if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL', 1);
30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36if (!defined(
'NOREQUIREAJAX')) {
37 define(
'NOREQUIREAJAX',
'1');
39if (empty($_GET[
'keysearch']) && !defined(
'NOREQUIREHTML')) {
40 define(
'NOREQUIREHTML',
'1');
44require
'../../main.inc.php';
46$htmlname =
GETPOST(
'htmlname',
'aZ09');
55$action =
GETPOST(
'action',
'aZ09');
59$alsoproductwithnosupplierprice =
GETPOSTINT(
'alsoproductwithnosupplierprice');
60$warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
61$hidepriceinlabel =
GETPOSTINT(
'hidepriceinlabel');
64restrictedArea($user,
'produit|service|commande|propal|facture', 0,
'product&product');
73if ($action ==
'fetch' && !empty($id)) {
75 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
76 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
88 $outdesc =
$object->description;
93 $outpricebasetype =
null;
94 $outtva_tx_formated = 0;
96 $outdefault_vat_code =
'';
99 $mandatory_period =
$object->mandatory_period;
104 $needchangeaccordingtothirdparty = 0;
106 $needchangeaccordingtothirdparty = 1;
109 $needchangeaccordingtothirdparty = 1;
111 if ($needchangeaccordingtothirdparty) {
112 $thirdpartytemp =
new Societe($db);
113 $thirdpartytemp->fetch($socid);
117 $newlang = $thirdpartytemp->default_lang;
119 if (!empty($newlang)) {
121 $outputlangs->setDefaultLang($newlang);
122 $outdesc_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"description"])) ?
$object->multilangs[$outputlangs->defaultlang][
"description"] :
$object->
description;
123 $outlabel_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"label"])) ?
$object->multilangs[$outputlangs->defaultlang][
"label"] :
$object->label;
125 $outdesc_trans =
$object->description;
126 $outlabel_trans =
$object->label;
132 $price_level = $thirdpartytemp->price_level;
138 if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
139 $sql =
"SELECT price, unitprice, quantity, remise_percent";
140 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
141 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
143 $result = $db->query($sql);
145 $objp = $db->fetch_object($result);
148 $outprice_ht =
price($objp->unitprice);
149 $outprice_ttc =
price($objp->unitprice * (1 + (
$object->tva_tx / 100)));
151 $outpricebasetype =
$object->price_base_type;
154 $outdefault_vat_code =
$object->default_vat_code;
156 $outqty = $objp->quantity;
157 $outdiscount = $objp->remise_percent;
164 $sql =
"SELECT price, price_ttc, price_base_type,";
165 $sql .=
" tva_tx, default_vat_code";
166 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
167 $sql .=
" WHERE fk_product = ".((int) $id);
168 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
169 $sql .=
" AND price_level = ".((int) $price_level);
170 $sql .=
" ORDER BY date_price";
171 $sql .=
" DESC LIMIT 1";
173 $result = $db->query($sql);
175 $objp = $db->fetch_object($result);
178 $outprice_ht =
price($objp->price);
179 $outprice_ttc =
price($objp->price_ttc);
180 $outpricebasetype = $objp->price_base_type;
182 $outtva_tx_formated =
price($objp->tva_tx);
184 $outdefault_vat_code = $objp->default_vat_code;
189 $outdefault_vat_code =
$object->default_vat_code;
197 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
201 $filter = array(
't.fk_product' =>
$object->id,
't.fk_soc' => $socid);
203 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
205 if (count($prodcustprice->lines) > 0) {
207 $outprice_ht =
price($prodcustprice->lines[0]->price);
208 $outprice_ttc =
price($prodcustprice->lines[0]->price_ttc);
209 $outpricebasetype = $prodcustprice->lines[0]->price_base_type;
210 $outtva_tx_formated =
price($prodcustprice->lines[0]->tva_tx);
211 $outtva_tx =
price2num($prodcustprice->lines[0]->tva_tx);
212 $outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code;
220 $outpricebasetype =
$object->price_base_type;
223 $outdefault_vat_code =
$object->default_vat_code;
227 $product_outtva_tx_formated = $outtva_tx_formated;
228 $product_outtva_tx = $outtva_tx;
229 $product_outdefault_vat_code = $outdefault_vat_code;
232 if (
GETPOSTINT(
'addalsovatforthirdpartyid')) {
233 $thirdparty_buyer =
new Societe($db);
234 $thirdparty_buyer->fetch($socid);
238 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
240 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
242 $outtva_tx_formated =
price($outtva_tx);
243 $outdefault_vat_code = $reg[2];
246 $outtva_tx_formated =
price($outtva_tx);
247 $outdefault_vat_code =
'';
254 'label' => $outlabel,
255 'label_trans' => $outlabel_trans,
257 'desc_trans' => $outdesc_trans,
259 'price_ht' => $outprice_ht,
260 'price_ttc' => $outprice_ttc,
261 'pricebasetype' => $outpricebasetype,
262 'product_tva_tx_formated' => $product_outtva_tx_formated,
263 'product_tva_tx' => $product_outtva_tx,
264 'product_default_vat_code' => $product_outdefault_vat_code,
266 'tva_tx_formated' => $outtva_tx_formated,
267 'tva_tx' => $outtva_tx,
268 'default_vat_code' => $outdefault_vat_code,
271 'discount' => $outdiscount,
272 'mandatory_period' => $mandatory_period,
273 'array_options'=>
$object->array_options
277 echo json_encode($outjson);
279 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
281 $langs->loadLangs(array(
"main",
"products"));
285 if (empty($htmlname)) {
286 print json_encode(array());
293 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
296 $idprod = (empty($match[0]) ?
'' : $match[0]);
298 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
299 print json_encode(array());
304 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
306 if (!isset($form) || !is_object($form)) {
307 $form =
new Form($db);
310 if (empty($mode) || $mode == 1) {
311 $arrayresult = $form->select_produits_list(
"", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid,
'1', 0,
'', $hidepriceinlabel, $warehouseStatus, $status_purchase);
312 } elseif ($mode == 2) {
313 $arrayresult = $form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice);
319 print json_encode($arrayresult);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
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 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.