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';
55$htmlname =
GETPOST(
'htmlname',
'aZ09');
64$action =
GETPOST(
'action',
'aZ09');
68$alsoproductwithnosupplierprice =
GETPOSTINT(
'alsoproductwithnosupplierprice');
69$warehouseStatus =
GETPOST(
'warehousestatus',
'alpha');
70$hidepriceinlabel =
GETPOSTINT(
'hidepriceinlabel');
71$warehouseId =
GETPOST(
'warehouseid',
'int');
74restrictedArea($user,
'produit|service|commande|propal|facture', 0,
'product&product');
89if ($action ==
'fetch' && !empty($id)) {
91 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
92 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
103 $outlabel_trans =
'';
104 $outdesc =
$object->description;
108 $outprice_ttc =
null;
109 $outpricebasetype =
null;
110 $outtva_tx_formated = 0;
112 $outdefault_vat_code =
'';
115 $mandatory_period =
$object->mandatory_period;
120 $needchangeaccordingtothirdparty = 0;
122 $needchangeaccordingtothirdparty = 1;
125 $needchangeaccordingtothirdparty = 1;
127 if ($needchangeaccordingtothirdparty) {
128 $thirdpartytemp =
new Societe($db);
129 $thirdpartytemp->fetch($socid);
133 $newlang = $thirdpartytemp->default_lang;
135 if (!empty($newlang)) {
137 $outputlangs->setDefaultLang($newlang);
138 $outdesc_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"description"])) ?
$object->multilangs[$outputlangs->defaultlang][
"description"] :
$object->
description;
139 $outlabel_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"label"])) ?
$object->multilangs[$outputlangs->defaultlang][
"label"] :
$object->label;
141 $outdesc_trans =
$object->description;
142 $outlabel_trans =
$object->label;
148 $price_level = $thirdpartytemp->price_level;
154 if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
155 $sql =
"SELECT price, unitprice, quantity, remise_percent";
156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
157 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
159 $result = $db->query($sql);
161 $objp = $db->fetch_object($result);
164 $outprice_ht =
price($objp->unitprice);
165 $outprice_ttc =
price($objp->unitprice * (1 + (
$object->tva_tx / 100)));
167 $outpricebasetype =
$object->price_base_type;
170 $outdefault_vat_code =
$object->default_vat_code;
172 $outqty = $objp->quantity;
173 $outdiscount = $objp->remise_percent;
180 $sql =
"SELECT price, price_ttc, price_base_type,";
181 $sql .=
" tva_tx, default_vat_code";
182 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
183 $sql .=
" WHERE fk_product = ".((int) $id);
184 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
185 $sql .=
" AND price_level = ".((int) $price_level);
186 $sql .=
" ORDER BY date_price";
187 $sql .=
" DESC LIMIT 1";
189 $result = $db->query($sql);
191 $objp = $db->fetch_object($result);
194 $outprice_ht =
price($objp->price);
195 $outprice_ttc =
price($objp->price_ttc);
196 $outpricebasetype = $objp->price_base_type;
198 $outtva_tx_formated =
price($objp->tva_tx);
200 $outdefault_vat_code = $objp->default_vat_code;
205 $outdefault_vat_code =
$object->default_vat_code;
213 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
217 $filter = array(
't.fk_product' =>
$object->id,
't.fk_soc' => $socid);
219 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
221 if (count($prodcustprice->lines) > 0) {
223 $outprice_ht =
price($prodcustprice->lines[0]->price);
224 $outprice_ttc =
price($prodcustprice->lines[0]->price_ttc);
225 $outpricebasetype = $prodcustprice->lines[0]->price_base_type;
226 $outtva_tx_formated =
price($prodcustprice->lines[0]->tva_tx);
227 $outtva_tx =
price2num($prodcustprice->lines[0]->tva_tx);
228 $outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code;
236 $outpricebasetype =
$object->price_base_type;
239 $outdefault_vat_code =
$object->default_vat_code;
243 $product_outtva_tx_formated = $outtva_tx_formated;
244 $product_outtva_tx = $outtva_tx;
245 $product_outdefault_vat_code = $outdefault_vat_code;
248 if (
GETPOSTINT(
'addalsovatforthirdpartyid')) {
249 $thirdparty_buyer =
new Societe($db);
250 $thirdparty_buyer->fetch($socid);
254 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
256 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
258 $outtva_tx_formated =
price($outtva_tx);
259 $outdefault_vat_code = $reg[2];
262 $outtva_tx_formated =
price($outtva_tx);
263 $outdefault_vat_code =
'';
270 'label' => $outlabel,
271 'label_trans' => $outlabel_trans,
273 'desc_trans' => $outdesc_trans,
275 'price_ht' => $outprice_ht,
276 'price_ttc' => $outprice_ttc,
277 'pricebasetype' => $outpricebasetype,
278 'product_tva_tx_formated' => $product_outtva_tx_formated,
279 'product_tva_tx' => $product_outtva_tx,
280 'product_default_vat_code' => $product_outdefault_vat_code,
282 'tva_tx_formated' => $outtva_tx_formated,
283 'tva_tx' => $outtva_tx,
284 'default_vat_code' => $outdefault_vat_code,
287 'discount' => $outdiscount,
288 'mandatory_period' => $mandatory_period,
289 'array_options'=>
$object->array_options
293 echo json_encode($outjson);
295 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
297 $langs->loadLangs(array(
"main",
"products"));
301 if (empty($htmlname)) {
302 print json_encode(array());
309 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
312 $idprod = (empty($match[0]) ?
'' : $match[0]);
314 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
315 print json_encode(array());
320 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
322 if (!isset($form) || !is_object($form)) {
323 $form =
new Form($db);
327 if (empty($mode) || $mode == 1) {
328 $arrayresult = $form->select_produits_list(
"", $htmlname, $type,
getDolGlobalInt(
'PRODUIT_LIMIT_SIZE', 1000), $price_level, $searchkey, $status, $finished, $outjson, $socid,
'1', 0,
'', $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
329 } elseif ($mode == 2) {
330 $arrayresult = $form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson,
getDolGlobalInt(
'PRODUIT_LIMIT_SIZE', 1000), $alsoproductwithnosupplierprice);
336 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 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.