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');
62$warehouseId =
GETPOST(
'warehouseid',
'int');
65restrictedArea($user,
'produit|service|commande|propal|facture', 0,
'product&product');
80if ($action ==
'fetch' && !empty($id)) {
82 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
83 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
95 $outdesc =
$object->description;
100 $outpricebasetype =
null;
101 $outtva_tx_formated = 0;
103 $outdefault_vat_code =
'';
106 $mandatory_period =
$object->mandatory_period;
111 $needchangeaccordingtothirdparty = 0;
113 $needchangeaccordingtothirdparty = 1;
116 $needchangeaccordingtothirdparty = 1;
118 if ($needchangeaccordingtothirdparty) {
119 $thirdpartytemp =
new Societe($db);
120 $thirdpartytemp->fetch($socid);
124 $newlang = $thirdpartytemp->default_lang;
126 if (!empty($newlang)) {
128 $outputlangs->setDefaultLang($newlang);
129 $outdesc_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"description"])) ?
$object->multilangs[$outputlangs->defaultlang][
"description"] :
$object->
description;
130 $outlabel_trans = (!empty(
$object->multilangs[$outputlangs->defaultlang][
"label"])) ?
$object->multilangs[$outputlangs->defaultlang][
"label"] :
$object->label;
132 $outdesc_trans =
$object->description;
133 $outlabel_trans =
$object->label;
139 $price_level = $thirdpartytemp->price_level;
145 if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
146 $sql =
"SELECT price, unitprice, quantity, remise_percent";
147 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
148 $sql .=
" WHERE rowid = ".((int) $price_by_qty_rowid);
150 $result = $db->query($sql);
152 $objp = $db->fetch_object($result);
155 $outprice_ht =
price($objp->unitprice);
156 $outprice_ttc =
price($objp->unitprice * (1 + (
$object->tva_tx / 100)));
158 $outpricebasetype =
$object->price_base_type;
161 $outdefault_vat_code =
$object->default_vat_code;
163 $outqty = $objp->quantity;
164 $outdiscount = $objp->remise_percent;
171 $sql =
"SELECT price, price_ttc, price_base_type,";
172 $sql .=
" tva_tx, default_vat_code";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price ";
174 $sql .=
" WHERE fk_product = ".((int) $id);
175 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
176 $sql .=
" AND price_level = ".((int) $price_level);
177 $sql .=
" ORDER BY date_price";
178 $sql .=
" DESC LIMIT 1";
180 $result = $db->query($sql);
182 $objp = $db->fetch_object($result);
185 $outprice_ht =
price($objp->price);
186 $outprice_ttc =
price($objp->price_ttc);
187 $outpricebasetype = $objp->price_base_type;
189 $outtva_tx_formated =
price($objp->tva_tx);
191 $outdefault_vat_code = $objp->default_vat_code;
196 $outdefault_vat_code =
$object->default_vat_code;
204 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
208 $filter = array(
't.fk_product' =>
$object->id,
't.fk_soc' => $socid);
210 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
212 if (count($prodcustprice->lines) > 0) {
214 $outprice_ht =
price($prodcustprice->lines[0]->price);
215 $outprice_ttc =
price($prodcustprice->lines[0]->price_ttc);
216 $outpricebasetype = $prodcustprice->lines[0]->price_base_type;
217 $outtva_tx_formated =
price($prodcustprice->lines[0]->tva_tx);
218 $outtva_tx =
price2num($prodcustprice->lines[0]->tva_tx);
219 $outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code;
227 $outpricebasetype =
$object->price_base_type;
230 $outdefault_vat_code =
$object->default_vat_code;
234 $product_outtva_tx_formated = $outtva_tx_formated;
235 $product_outtva_tx = $outtva_tx;
236 $product_outdefault_vat_code = $outdefault_vat_code;
239 if (
GETPOSTINT(
'addalsovatforthirdpartyid')) {
240 $thirdparty_buyer =
new Societe($db);
241 $thirdparty_buyer->fetch($socid);
245 if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
247 if (preg_match(
'/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
249 $outtva_tx_formated =
price($outtva_tx);
250 $outdefault_vat_code = $reg[2];
253 $outtva_tx_formated =
price($outtva_tx);
254 $outdefault_vat_code =
'';
261 'label' => $outlabel,
262 'label_trans' => $outlabel_trans,
264 'desc_trans' => $outdesc_trans,
266 'price_ht' => $outprice_ht,
267 'price_ttc' => $outprice_ttc,
268 'pricebasetype' => $outpricebasetype,
269 'product_tva_tx_formated' => $product_outtva_tx_formated,
270 'product_tva_tx' => $product_outtva_tx,
271 'product_default_vat_code' => $product_outdefault_vat_code,
273 'tva_tx_formated' => $outtva_tx_formated,
274 'tva_tx' => $outtva_tx,
275 'default_vat_code' => $outdefault_vat_code,
278 'discount' => $outdiscount,
279 'mandatory_period' => $mandatory_period,
280 'array_options'=>
$object->array_options
284 echo json_encode($outjson);
286 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
288 $langs->loadLangs(array(
"main",
"products"));
292 if (empty($htmlname)) {
293 print json_encode(array());
300 $match = preg_grep(
'/('.preg_quote($htmlname,
'/').
'[0-9]+)/', array_keys($_GET));
303 $idprod = (empty($match[0]) ?
'' : $match[0]);
305 if (
GETPOST($htmlname,
'alpha') ==
'' && (!$idprod || !
GETPOST($idprod,
'alpha'))) {
306 print json_encode(array());
311 $searchkey = (($idprod &&
GETPOST($idprod,
'alpha')) ?
GETPOST($idprod,
'alpha') : (
GETPOST($htmlname,
'alpha') ?
GETPOST($htmlname,
'alpha') :
''));
313 if (!isset($form) || !is_object($form)) {
314 $form =
new Form($db);
317 if (empty($mode) || $mode == 1) {
318 $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);
319 } elseif ($mode == 2) {
320 $arrayresult = $form->select_produits_fournisseurs_list($socid,
"", $htmlname, $type,
"", $searchkey, $status, $outjson,
getDolGlobalInt(
'PRODUIT_LIMIT_SIZE', 1000), $alsoproductwithnosupplierprice);
326 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.
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.