--- /tmp/dsg/dolibarr/htdocs/product/ajax/github_19.0.3_products.php +++ /tmp/dsg/dolibarr/htdocs/product/ajax/client_products.php @@ -5 +4,0 @@ - * Copyright (C) 2020 Josep LluĂ­s Amador @@ -23 +22 @@ - * \brief File to return Ajax response on product list request, with default VAT rate. + * \brief File to return Ajax response on product list request. @@ -26,17 +25,8 @@ -if (!defined('NOTOKENRENEWAL')) { - define('NOTOKENRENEWAL', 1); // Disables token renewal -} -if (!defined('NOREQUIREMENU')) { - define('NOREQUIREMENU', '1'); -} -if (!defined('NOREQUIREHTML')) { - define('NOREQUIREHTML', '1'); -} -if (!defined('NOREQUIREAJAX')) { - define('NOREQUIREAJAX', '1'); -} -if (empty($_GET['keysearch']) && !defined('NOREQUIREHTML')) { - define('NOREQUIREHTML', '1'); -} - -// Load Dolibarr environment +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); +if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); +if (empty($_GET['keysearch']) && !defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); + @@ -45 +35 @@ -$htmlname = GETPOST('htmlname', 'aZ09'); +$htmlname = GETPOST('htmlname', 'alpha'); @@ -49,2 +39 @@ -$status = ((GETPOST('status', 'int') >= 0) ? GETPOST('status', 'int') : - 1); // status buy when mode = customer , status purchase when mode = supplier -$status_purchase = ((GETPOST('status_purchase', 'int') >= 0) ? GETPOST('status_purchase', 'int') : - 1); // status purchase when mode = customer +$status = ((GETPOST('status', 'int') >= 0) ? GETPOST('status', 'int') : - 1); @@ -53 +42 @@ -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); @@ -61,3 +49,0 @@ -// Security check -restrictedArea($user, 'produit|service|commande|propal|facture', 0, 'product&product'); - @@ -69,0 +56,2 @@ + +dol_syslog(join(',', $_GET)); @@ -72 +60,2 @@ -if ($action == 'fetch' && !empty($id)) { +if (!empty($action) && $action == 'fetch' && !empty($id)) +{ @@ -77,2 +65,0 @@ - top_httphead('application/json'); - @@ -83 +70,2 @@ - if ($ret > 0) { + if ($ret > 0) + { @@ -86 +73,0 @@ - $outlabel_trans = ''; @@ -88 +74,0 @@ - $outdesc_trans = ''; @@ -90,6 +75,0 @@ - $outprice_ht = null; - $outprice_ttc = null; - $outpricebasetype = null; - $outtva_tx_formated = 0; - $outtva_tx = 0; - $outdefault_vat_code = ''; @@ -98 +78 @@ - $mandatory_period = $object->mandatory_period; + @@ -102,32 +82,4 @@ - if ($socid > 0) { - $needchangeaccordingtothirdparty = 0; - if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { - $needchangeaccordingtothirdparty = 1; - } - if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { - $needchangeaccordingtothirdparty = 1; - } - if ($needchangeaccordingtothirdparty) { - $thirdpartytemp = new Societe($db); - $thirdpartytemp->fetch($socid); - - //Load translation description and label according to thirdparty language - if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { - $newlang = $thirdpartytemp->default_lang; - - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - $outdesc_trans = (!empty($object->multilangs[$outputlangs->defaultlang]["description"])) ? $object->multilangs[$outputlangs->defaultlang]["description"] : $object->description; - $outlabel_trans = (!empty($object->multilangs[$outputlangs->defaultlang]["label"])) ? $object->multilangs[$outputlangs->defaultlang]["label"] : $object->label; - } else { - $outdesc_trans = $object->description; - $outlabel_trans = $object->label; - } - } - - //Set price level according to thirdparty - if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { - $price_level = $thirdpartytemp->price_level; - } - } + if ($socid > 0 && !empty($conf->global->PRODUIT_MULTIPRICES)) { + $thirdpartytemp = new Societe($db); + $thirdpartytemp->fetch($socid); + $price_level = $thirdpartytemp->price_level; @@ -137 +89,2 @@ - if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) { // If we need a particular price related to qty + if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))) // If we need a particular price related to qty + { @@ -139,2 +92,2 @@ - $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; - $sql .= " WHERE rowid = ".((int) $price_by_qty_rowid); + $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty "; + $sql .= " WHERE rowid=".$price_by_qty_rowid.""; @@ -149 +101,0 @@ - @@ -151,4 +103 @@ - $outtva_tx_formated = price($object->tva_tx); - $outtva_tx = price2num($object->tva_tx); - $outdefault_vat_code = $object->default_vat_code; - + $outtva_tx = $object->tva_tx; @@ -161,4 +110,4 @@ - // Multiprice (1 price per level) - if (!$found && isset($price_level) && $price_level >= 1 && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) { // If we need a particular price level (from 1 to 6) - $sql = "SELECT price, price_ttc, price_base_type,"; - $sql .= " tva_tx, default_vat_code"; // Vat rate and code will be used if PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL is on. + // Multiprice + if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES))) // If we need a particular price level (from 1 to 6) + { + $sql = "SELECT price, price_ttc, price_base_type, tva_tx"; @@ -166 +115 @@ - $sql .= " WHERE fk_product = ".((int) $id); + $sql .= " WHERE fk_product = '".$id."'"; @@ -177,2 +126,2 @@ - $outprice_ht = price($objp->price); // formated for langage user because is inserted into input field - $outprice_ttc = price($objp->price_ttc); // formated for langage user because is inserted into input field + $outprice_ht = price($objp->price); + $outprice_ttc = price($objp->price_ttc); @@ -180,10 +129 @@ - if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { - $outtva_tx_formated = price($objp->tva_tx); // formated for langage user because is inserted into input field - $outtva_tx = price2num($objp->tva_tx); // international numeric - $outdefault_vat_code = $objp->default_vat_code; - } else { - // The common and default behaviour. - $outtva_tx_formated = price($object->tva_tx); - $outtva_tx = price2num($object->tva_tx); - $outdefault_vat_code = $object->default_vat_code; - } + $outtva_tx = $objp->tva_tx; @@ -195 +135 @@ - if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') && !empty($socid)) { + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { @@ -198 +138 @@ - $prodcustprice = new ProductCustomerPrice($db); + $prodcustprice = new Productcustomerprice($db); @@ -202 +142 @@ - $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); + $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); @@ -206,6 +146,4 @@ - $outprice_ht = price($prodcustprice->lines[0]->price); - $outprice_ttc = price($prodcustprice->lines[0]->price_ttc); - $outpricebasetype = $prodcustprice->lines[0]->price_base_type; - $outtva_tx_formated = price($prodcustprice->lines[0]->tva_tx); - $outtva_tx = price2num($prodcustprice->lines[0]->tva_tx); - $outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code; + $outprice_ht = price($prodcustprice->lines [0]->price); + $outprice_ttc = price($prodcustprice->lines [0]->price_ttc); + $outpricebasetype = $prodcustprice->lines [0]->price_base_type; + $outtva_tx = $prodcustprice->lines [0]->tva_tx; @@ -220,54 +158,4 @@ - $outtva_tx_formated = price($object->tva_tx); - $outtva_tx = price2num($object->tva_tx); - $outdefault_vat_code = $object->default_vat_code; - } - - // VAT to use and default VAT for product are set to same value by default - $product_outtva_tx_formated = $outtva_tx_formated; - $product_outtva_tx = $outtva_tx; - $product_outdefault_vat_code = $outdefault_vat_code; - - // If we ask the price according to buyer, we change it. - if (GETPOST('addalsovatforthirdpartyid', 'int')) { - $thirdparty_buyer = new Societe($db); - $thirdparty_buyer->fetch($socid); - - $tmpvatwithcode = get_default_tva($mysoc, $thirdparty_buyer, $id, 0); - - if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) { - $reg =array(); - if (preg_match('/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) { - $outtva_tx = price2num($reg[1]); - $outtva_tx_formated = price($outtva_tx); - $outdefault_vat_code = $reg[2]; - } else { - $outtva_tx = price2num($tmpvatwithcode); - $outtva_tx_formated = price($outtva_tx); - $outdefault_vat_code = ''; - } - } - } - - $outjson = array( - 'ref' => $outref, - 'label' => $outlabel, - 'label_trans' => $outlabel_trans, - 'desc' => $outdesc, - 'desc_trans' => $outdesc_trans, - 'type' => $outtype, - 'price_ht' => $outprice_ht, - 'price_ttc' => $outprice_ttc, - 'pricebasetype' => $outpricebasetype, - 'product_tva_tx_formated' => $product_outtva_tx_formated, - 'product_tva_tx' => $product_outtva_tx, - 'product_default_vat_code' => $product_outdefault_vat_code, - - 'tva_tx_formated' => $outtva_tx_formated, - 'tva_tx' => $outtva_tx, - 'default_vat_code' => $outdefault_vat_code, - - 'qty' => $outqty, - 'discount' => $outdiscount, - 'mandatory_period' => $mandatory_period, - 'array_options'=>$object->array_options - ); + $outtva_tx = $object->tva_tx; + } + + $outjson = array('ref' => $outref, 'label' => $outlabel, 'desc' => $outdesc, 'type' => $outtype, 'price_ht' => $outprice_ht, 'price_ttc' => $outprice_ttc, 'pricebasetype' => $outpricebasetype, 'tva_tx' => $outtva_tx, 'qty' => $outqty, 'discount' => $outdiscount); @@ -277 +165,3 @@ -} else { +} +else +{ @@ -284 +174,2 @@ - if (empty($htmlname)) { + if (empty($htmlname)) + { @@ -286,7 +177,4 @@ - return; - } - - // Filter on the product to search can be: - // Into an array with key $htmlname123 (we take first one found). Which page use this ? - // Into a var with name $htmlname can be 'prodid', 'productid', ... - $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET)); + return; + } + + $match = preg_grep('/('.$htmlname.'[0-9]+)/', array_keys($_GET)); @@ -295,3 +183,4 @@ - $idprod = (empty($match[0]) ? '' : $match[0]); // Take first key found into GET array with matching $htmlname123 - - if (GETPOST($htmlname, 'alpha') == '' && (!$idprod || !GETPOST($idprod, 'alpha'))) { + $idprod = (!empty($match[0]) ? $match[0] : ''); + + if (GETPOST($htmlname, 'alpha') == '' && (!$idprod || !GETPOST($idprod, 'alpha'))) + { @@ -299 +188 @@ - return; + return; @@ -305,3 +194 @@ - if (!isset($form) || !is_object($form)) { - $form = new Form($db); - } + $form = new Form($db); @@ -310 +197 @@ - $arrayresult = $form->select_produits_list("", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid, '1', 0, '', $hidepriceinlabel, $warehouseStatus, $status_purchase); + $arrayresult = $form->select_produits_list("", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid, '1', 0, '', $hidepriceinlabel, $warehouseStatus); @@ -317 +204 @@ - if ($outjson) { + if ($outjson) @@ -319 +205,0 @@ - }