diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 053742aee5d4c..84ef7f2a272e5 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1129,19 +1129,25 @@ if ($result) { // If there is some prices specific to the customer if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines[0]->price); - $pu_ttc = price($prodcustprice->lines[0]->price_ttc); - $price_min = price($prodcustprice->lines[0]->price_min); - $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc); - $price_base_type = $prodcustprice->lines[0]->price_base_type; - /*$tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx); - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { - $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($prodcustprice->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $pu_ht = price($custprice_line->price); + $pu_ttc = price($custprice_line->price_ttc); + $price_min = price($custprice_line->price_min); + $price_min_ttc = price($custprice_line->price_min_ttc); + $price_base_type = $custprice_line->price_base_type; + /*$tva_tx = ($custprice_line->default_vat_code ? $custprice_line->tva_tx.' ('.$custprice_line->default_vat_code.' )' : $custprice_line->tva_tx); + if ($custprice_line->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + $tva_tx .= ' ('.$custprice_line->default_vat_code.')'; + } + $tva_npr = $custprice_line->recuperableonly; + if (empty($tva_tx)) { + $tva_npr = 0; + }*/ + break; + } } - $tva_npr = $prodcustprice->lines[0]->recuperableonly; - if (empty($tva_tx)) { - $tva_npr = 0; - }*/ } } } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index c2825ff18300b..cc4df5c985479 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1458,10 +1458,17 @@ public function createFromClone(User $user, $socid = 0, $forceentity = null, $up if ($result) { // If there is some prices specific to the customer if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines[0]->price); - $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx); - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { - $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($prodcustprice->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $pu_ht = price($custprice_line->price); + $tva_tx = ($custprice_line->default_vat_code ? $custprice_line->tva_tx . ' (' . $custprice_line->default_vat_code . ' )' : $custprice_line->tva_tx); + if ($custprice_line->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + $tva_tx .= ' (' . $custprice_line->default_vat_code . ')'; + } + $remise_percent = $custprice_line->discount_percent; + break; + } } } } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index b91f714c6048b..2ba13e97ca857 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -831,18 +831,24 @@ $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); if ($result >= 0) { if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines[0]->price); - $pu_ttc = price($prodcustprice->lines[0]->price_ttc); - $price_min = price($prodcustprice->lines[0]->price_min); - $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc); - $price_base_type = $prodcustprice->lines[0]->price_base_type; - $tva_tx = $prodcustprice->lines[0]->tva_tx; - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { - $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; - } - $tva_npr = $prodcustprice->lines[0]->recuperableonly; - if (empty($tva_tx)) { - $tva_npr = 0; + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($prodcustprice->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $pu_ht = price($custprice_line->price); + $pu_ttc = price($custprice_line->price_ttc); + $price_min = price($custprice_line->price_min); + $price_min_ttc = price($custprice_line->price_min_ttc); + $price_base_type = $custprice_line->price_base_type; + $tva_tx = $custprice_line->tva_tx; + if ($custprice_line->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + $tva_tx .= ' (' . $custprice_line->default_vat_code . ')'; + } + $tva_npr = $custprice_line->recuperableonly; + if (empty($tva_tx)) { + $tva_npr = 0; + } + break; + } } } } else { diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 6ccb874e870d2..057e8273d4b26 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -519,16 +519,22 @@ $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { - $price_min = price($prodcustprice->lines[0]->price_min); - $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc); - /*$tva_tx = $prodcustprice->lines[0]->tva_tx; - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { - $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($prodcustprice->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $price_min = price($custprice_line->price_min); + $price_min_ttc = price($custprice_line->price_min_ttc); + /*$tva_tx = $custprice_line->tva_tx; + if ($custprice_line->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + $tva_tx .= ' ('.$custprice_line->default_vat_code.')'; + } + $tva_npr = $custprice_line->recuperableonly; + if (empty($tva_tx)) { + $tva_npr = 0; + }*/ + break; + } } - $tva_npr = $prodcustprice->lines[0]->recuperableonly; - if (empty($tva_tx)) { - $tva_npr = 0; - }*/ } } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f66dabcabeb18..e28cfe5dc1cba 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2698,8 +2698,8 @@ public function select_produits_list($selected = '', $htmlname = 'productid', $f //Price by customer if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { $sql .= ', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,'; - $sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref'; - $selectFields .= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref"; + $sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref, pcp.discount_percent as custdiscount_percent'; + $selectFields .= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent"; } // Units if (getDolGlobalInt('PRODUCT_USE_UNITS')) { @@ -2750,7 +2750,20 @@ public function select_produits_list($selected = '', $htmlname = 'productid', $f //Price by customer if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { - $sql .= " LEFT JOIN " . $this->db->prefix() . "product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) . " AND pcp.fk_product=p.rowid"; + $now = dol_now(); + $sql .= " LEFT JOIN ("; + $sql .= " SELECT pcp1.*"; + $sql .= " FROM " . $this->db->prefix() . "product_customer_price AS pcp1"; + $sql .= " LEFT JOIN ("; + $sql .= " SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin"; + $sql .= " FROM " . $this->db->prefix() . "product_customer_price"; + $sql .= " WHERE fk_soc = " . ((int) $socid); + $sql .= " AND date_begin <= '" . $this->db->idate($now) . "'"; + $sql .= " AND (date_end IS NULL OR '" . $this->db->idate($now) . "' <= date_end)"; + $sql .= " GROUP BY fk_soc, fk_product"; + $sql .= " ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin"; + $sql .= " WHERE pcp2.fk_soc IS NOT NULL"; + $sql .= " ) AS pcp ON pcp.fk_soc = " . ((int) $socid) . " AND pcp.fk_product = p.rowid"; } // Units if (getDolGlobalInt('PRODUCT_USE_UNITS')) { @@ -3238,6 +3251,7 @@ protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_l $outpricebasetype = $objp->custprice_base_type; $outtva_tx = $objp->custtva_tx; $outdefault_vat_code = $objp->custdefault_vat_code; + $outdiscount = $objp->custdiscount_percent; } } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index cb7114032dc2c..370798cb7c2be 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1640,9 +1640,18 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $nbCustomerPrices = $productCustomerPriceStatic->fetchAll('', '', 1, 0, $filter); if ($nbCustomerPrices > 0) { - $productCustomerPrice = $productCustomerPriceStatic->lines[0]; + $productCustomerPrice = null; + if (count($productCustomerPriceStatic->lines) > 0) { + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($productCustomerPriceStatic->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $productCustomerPrice = $custprice_line; + break; + } + } + } - if (!empty($productCustomerPrice->ref_customer)) { + if (isset($productCustomerPrice) && !empty($productCustomerPrice->ref_customer)) { switch ($conf->global->PRODUIT_CUSTOMER_PRICES_PDF_REF_MODE) { case 1: $ref_prodserv = $productCustomerPrice->ref_customer; diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index d8192a37df452..ff09c7c39bfe3 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -368,22 +368,28 @@ public function __construct($db) $this->export_permission[$r] = array(array("produit", "export")); $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 's.nom'=>'ThirdParty', + 'pr.date_begin' => "AppliedPricesFrom", + 'pr.date_end' => "AppliedPricesTo", 'pr.price_base_type'=>"PriceBase", 'pr.price'=>"PriceUnitPriceHT", 'pr.price_ttc'=>"PriceUnitPriceTTC", 'pr.price_min'=>"MinPriceUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceUnitPriceTTC", 'pr.tva_tx'=>'PriceVATRate', 'pr.default_vat_code'=>'PriceVATCode', + 'pr.discount_percent' => 'Discount', 'pr.datec'=>'DateCreation'); if (is_object($mysoc) && $usenpr) { $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR'; } $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product", 'p.label'=>"Label", 's.nom'=>'company', + 'pr.date_begin' => "product", + 'pr.date_end' => "product", 'pr.price_base_type'=>"product", 'pr.price'=>"product", 'pr.price_ttc'=>"product", 'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product", 'pr.tva_tx'=>'product', 'pr.default_vat_code'=>'product', + 'pr.discount_percent' => 'product', 'pr.recuperableonly'=>'product', 'pr.datec'=>"product"); $this->export_sql_start[$r] = 'SELECT DISTINCT '; diff --git a/htdocs/core/modules/modService.class.php b/htdocs/core/modules/modService.class.php index 4828513a8ff00..a580eede404e1 100644 --- a/htdocs/core/modules/modService.class.php +++ b/htdocs/core/modules/modService.class.php @@ -327,22 +327,28 @@ public function __construct($db) $this->export_permission[$r] = array(array("service", "export")); $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref", 's.nom'=>'ThirdParty', + 'pr.date_begin' => "AppliedPricesFrom", + 'pr.date_end' => "AppliedPricesTo", 'pr.price_base_type'=>"PriceBase", 'pr.price'=>"PriceUnitPriceHT", 'pr.price_ttc'=>"PriceUnitPriceTTC", 'pr.price_min'=>"MinPriceUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceUnitPriceTTC", 'pr.tva_tx'=>'PriceVATRate', 'pr.default_vat_code'=>'PriceVATCode', + 'pr.discount_percent' => 'Discount', 'pr.datec'=>'DateCreation'); if (is_object($mysoc) && $usenpr) { $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR'; } $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product", 's.nom'=>'company', + 'pr.date_begin' => "product", + 'pr.date_end' => "product", 'pr.price_base_type'=>"product", 'pr.price'=>"product", 'pr.price_ttc'=>"product", 'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product", 'pr.tva_tx'=>'product', 'pr.default_vat_code'=>'product', + 'pr.discount_percent' => 'product', 'pr.recuperableonly'=>'product', 'pr.datec'=>"product"); $this->export_sql_start[$r] = 'SELECT DISTINCT '; diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 7a5f36af59299..2a58a9ff6ffb6 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -818,6 +818,13 @@ function(data) { $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true); global->PRODUIT_CUSTOMER_PRICES) && !empty($object->socid)) { + ?> + $("#remise_percent").val(data.discount); + global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) { if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { ?> var proddesc = data.desc_trans; diff --git a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql index 732cebfb3c353..34fd5d76f09d7 100644 --- a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql +++ b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql @@ -654,3 +654,21 @@ ALTER TABLE llx_c_type_contact MODIFY COLUMN element VARCHAR(64) NOT NULL; -- delete a constant that should not be set DELETE FROM llx_const WHERE name = 'INVOICE_USE_RETAINED_WARRANTY' AND value = -1; + +-- Customer price - add discount and validate period +ALTER TABLE llx_product_customer_price ADD COLUMN date_begin date AFTER ref_customer; +ALTER TABLE llx_product_customer_price ADD COLUMN date_end date AFTER date_begin; +ALTER TABLE llx_product_customer_price ADD COLUMN remise_percent real DEFAULT 0 AFTER localtax2_type; +ALTER TABLE llx_product_customer_price_log ADD COLUMN date_begin date AFTER ref_customer; +ALTER TABLE llx_product_customer_price_log ADD COLUMN date_end date AFTER date_begin; +ALTER TABLE llx_product_customer_price_log ADD COLUMN remise_percent real DEFAULT 0 AFTER localtax2_type; +ALTER TABLE llx_product_customer_price DROP CONSTRAINT fk_product_customer_price_fk_product; +ALTER TABLE llx_product_customer_price DROP CONSTRAINT fk_product_customer_price_fk_soc; +ALTER TABLE llx_product_customer_price DROP INDEX uk_customer_price_fk_product_fk_soc; +ALTER TABLE llx_product_customer_price ADD UNIQUE INDEX uk_customer_price_fk_product_fk_soc (fk_product, fk_soc, date_begin); +ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_product_customer_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product(rowid); +ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_product_customer_price_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); +UPDATE llx_product_customer_price SET date_begin = datec WHERE date_begin IS NULL; +UPDATE llx_product_customer_price_log SET date_begin = datec WHERE date_begin IS NULL; +ALTER TABLE llx_product_customer_price CHANGE COLUMN remise_percent discount_percent real DEFAULT 0; +ALTER TABLE llx_product_customer_price_log CHANGE COLUMN remise_percent discount_percent real DEFAULT 0; diff --git a/htdocs/install/mysql/tables/llx_product_customer_price.key.sql b/htdocs/install/mysql/tables/llx_product_customer_price.key.sql index 2b827740b6051..afb4300856930 100644 --- a/htdocs/install/mysql/tables/llx_product_customer_price.key.sql +++ b/htdocs/install/mysql/tables/llx_product_customer_price.key.sql @@ -20,7 +20,7 @@ ALTER TABLE llx_product_customer_price ADD INDEX idx_product_customer_price_fk_user (fk_user); ALTER TABLE llx_product_customer_price ADD INDEX idx_product_customer_price_fk_soc (fk_soc); -ALTER TABLE llx_product_customer_price ADD UNIQUE INDEX uk_customer_price_fk_product_fk_soc (fk_product, fk_soc); +ALTER TABLE llx_product_customer_price ADD UNIQUE INDEX uk_customer_price_fk_product_fk_soc (fk_product, fk_soc, date_begin); ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_product_customer_price_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_product_customer_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product(rowid); diff --git a/htdocs/install/mysql/tables/llx_product_customer_price.sql b/htdocs/install/mysql/tables/llx_product_customer_price.sql index 7f843a8784eb2..8edfc1bd4489a 100644 --- a/htdocs/install/mysql/tables/llx_product_customer_price.sql +++ b/htdocs/install/mysql/tables/llx_product_customer_price.sql @@ -29,6 +29,8 @@ create table llx_product_customer_price fk_product integer NOT NULL, fk_soc integer NOT NULL, ref_customer varchar(128), + date_begin date, + date_end date, price double(24,8) DEFAULT 0, price_ttc double(24,8) DEFAULT 0, price_min double(24,8) DEFAULT 0, @@ -41,6 +43,7 @@ create table llx_product_customer_price localtax1_type varchar(10) NOT NULL DEFAULT '0', localtax2_tx double(7,4) DEFAULT 0, -- Other local VAT 2 localtax2_type varchar(10) NOT NULL DEFAULT '0', + discount_percent real DEFAULT 0, fk_user integer, import_key varchar(14) -- Import key )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_product_customer_price_log.sql b/htdocs/install/mysql/tables/llx_product_customer_price_log.sql index cd591b410997c..ee5c368001388 100644 --- a/htdocs/install/mysql/tables/llx_product_customer_price_log.sql +++ b/htdocs/install/mysql/tables/llx_product_customer_price_log.sql @@ -28,6 +28,8 @@ create table llx_product_customer_price_log fk_product integer NOT NULL, fk_soc integer DEFAULT 0 NOT NULL, ref_customer varchar(30), + date_begin date, + date_end date, price double(24,8) DEFAULT 0, price_ttc double(24,8) DEFAULT 0, price_min double(24,8) DEFAULT 0, @@ -40,6 +42,7 @@ create table llx_product_customer_price_log localtax1_type varchar(10) NOT NULL DEFAULT '0', localtax2_tx double(7,4) DEFAULT 0, -- Other local VAT 2 localtax2_type varchar(10) NOT NULL DEFAULT '0', + discount_percent real DEFAULT 0, fk_user integer, import_key varchar(14) -- Import key )ENGINE=innodb; diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 296208b654c61..dd5fd65117727 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -69,6 +69,8 @@ UpdateVAT=Update vat UpdateDefaultPrice=Update default price UpdateLevelPrices=Update prices for each level AppliedPricesFrom=Applied from +AppliedPricesTo=Applied to +ErrorAppliedPricesIntersectAnotherPeriod=The begin or end date intersect to another existing period. SellingPrice=Selling price SellingPriceHT=Selling price (excl. tax) SellingPriceTTC=Selling price (inc. tax) diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 6be07f57f4226..97f339f37c1c6 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -69,6 +69,8 @@ UpdateVAT=Modifier TVA UpdateDefaultPrice=Modifier prix par défaut UpdateLevelPrices=Modifier prix pour chaque niveau AppliedPricesFrom=Pratiqués à partir du +AppliedPricesTo=Pratiqués jusqu'au +ErrorAppliedPricesIntersectAnotherPeriod=La date de début ou de fin rentre en conflit avec une période de dates existante. SellingPrice=Prix de vente SellingPriceHT=Prix de vente HT SellingPriceTTC=Prix de vente TTC diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index 3f60355301f24..02affa9650365 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -202,13 +202,20 @@ $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { - $found = true; - $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; + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($prodcustprice->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $found = true; + $outprice_ht = price($custprice_line->price); + $outprice_ttc = price($custprice_line->price_ttc); + $outpricebasetype = $custprice_line->price_base_type; + $outtva_tx_formated = price($custprice_line->tva_tx); + $outtva_tx = price2num($custprice_line->tva_tx); + $outdefault_vat_code = $custprice_line->default_vat_code; + $outdiscount = $custprice_line->discount_percent; + break; + } + } } } } diff --git a/htdocs/product/card.php b/htdocs/product/card.php index c5341503d7b3c..53845b6dc2ae8 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1125,10 +1125,16 @@ $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines [0]->price); - $pu_ttc = price($prodcustprice->lines [0]->price_ttc); - $price_base_type = $prodcustprice->lines [0]->price_base_type; - $tva_tx = $prodcustprice->lines [0]->tva_tx; + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($prodcustprice->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $pu_ht = price($custprice_line->price); + $pu_ttc = price($custprice_line->price_ttc); + $price_base_type = $custprice_line->price_base_type; + $tva_tx = $custprice_line->tva_tx; + break; + } + } } } } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 6ec0c2535710a..50cd3d6a224af 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2026,17 +2026,23 @@ public function getSellPrice($thirdparty_seller, $thirdparty_buyer, $pqp = 0) $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines[0]->price); - $price_min = price($prodcustprice->lines[0]->price_min); - $pu_ttc = price($prodcustprice->lines[0]->price_ttc); - $price_base_type = $prodcustprice->lines[0]->price_base_type; - $tva_tx = $prodcustprice->lines[0]->tva_tx; - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { - $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; - } - $tva_npr = $prodcustprice->lines[0]->recuperableonly; - if (empty($tva_tx)) { - $tva_npr = 0; + $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours + foreach ($prodcustprice->lines as $k => $custprice_line) { + if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) { + $pu_ht = price($custprice_line->price); + $price_min = price($custprice_line->price_min); + $pu_ttc = price($custprice_line->price_ttc); + $price_base_type = $custprice_line->price_base_type; + $tva_tx = $custprice_line->tva_tx; + if ($custprice_line->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + $tva_tx .= ' (' . $custprice_line->default_vat_code . ')'; + } + $tva_npr = $custprice_line->recuperableonly; + if (empty($tva_tx)) { + $tva_npr = 0; + } + break; + } } } } diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index 4e40ce28deaf7..5617642132110 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -73,6 +73,18 @@ class Productcustomerprice extends CommonObject public $localtax1_tx; public $localtax2_type; public $localtax2_tx; + /** + * @var float|string|'' + */ + public $discount_percent; + /** + * @var string + */ + public $date_begin = ''; + /** + * @var string + */ + public $date_end = ''; /** * @var int User ID @@ -95,6 +107,46 @@ public function __construct($db) $this->db = $db; } + /** + * Check if begin and end dates intersect other dates periods + * + * @return int Result <0 if KO, >0 if OK + */ + public function verifyDates() + { + global $langs; + + $sql = "SELECT COUNT(*) AS nb"; + $sql .= " FROM " . $this->db->prefix() . "product_customer_price as t"; + $sql .= " WHERE (t.date_begin = '" . $this->db->idate($this->date_begin) . "' OR t.date_end = '" . $this->db->idate($this->date_begin) . "'"; + $sql .= " OR t.date_begin = '" . $this->db->idate($this->date_end) . "' OR t.date_end = '" . $this->db->idate($this->date_end) . "'"; + $sql .= " OR (t.date_begin <= '" . $this->db->idate($this->date_begin) . "' AND '" . $this->db->idate($this->date_begin) . "' <= t.date_end)"; + $sql .= " OR (t.date_begin <= '" . $this->db->idate($this->date_end) . "' AND '" . $this->db->idate($this->date_end) . "' <= t.date_end))"; + if ($this->fk_product > 0) $sql .= " AND t.fk_product = " . ((int) $this->fk_product); + if ($this->fk_soc > 0) $sql .= " AND t.fk_soc = " . ((int) $this->fk_soc); + if ($this->id > 0) $sql .= " AND t.rowid != " . ((int) $this->id); + + dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + return -1; + } + + $nb = 0; + if ($obj = $this->db->fetch_object($resql)) { + $nb = (int) $obj->nb; + } + $this->db->free($resql); + + if ($nb > 0) { + $this->errors[] = $langs->trans('ErrorAppliedPricesIntersectAnotherPeriod'); + return -1; + } + + return 1; + } + /** * Create object into database * @@ -108,6 +160,7 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0) global $conf, $langs; $error = 0; + $now = dol_now(); // Clean parameters @@ -150,6 +203,12 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0) if (isset($this->localtax2_tx)) { $this->localtax2_tx = trim($this->localtax2_tx); } + if (empty($this->discount_percent) || !is_numeric($this->discount_percent)) { + $this->discount_percent = 0; + } + if (empty($this->date_begin)) { + $this->date_begin = $now; + } if (isset($this->fk_user)) { $this->fk_user = trim($this->fk_user); } @@ -157,8 +216,12 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0) $this->import_key = trim($this->import_key); } - // Check parameters - // Put here code to add control on parameters values + // Check parameters + // Put here code to add control on parameters values + $result = $this->verifyDates(); + if ($result < 0) { + return -1; + } if ($this->price != '' || $this->price == 0) { if ($this->price_base_type == 'TTC') { @@ -210,11 +273,14 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0) $sql .= "localtax1_tx,"; $sql .= "localtax2_type,"; $sql .= "localtax2_tx,"; + $sql .= "discount_percent,"; + $sql .= "date_begin,"; + $sql .= "date_end,"; $sql .= "fk_user,"; $sql .= "import_key"; $sql .= ") VALUES ("; $sql .= " ".((int) $conf->entity).","; - $sql .= " '".$this->db->idate(dol_now())."',"; + $sql .= " '".$this->db->idate($now)."',"; $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").","; $sql .= " ".(!isset($this->fk_soc) ? 'NULL' : "'".$this->db->escape($this->fk_soc)."'").","; $sql .= " ".(!isset($this->ref_customer) ? 'NULL' : "'".$this->db->escape($this->ref_customer)."'").","; @@ -230,6 +296,9 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0) $sql .= " ".(!isset($this->localtax1_tx) ? 'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)).","; $sql .= " ".(empty($this->localtax2_type) ? "'0'" : "'".$this->db->escape($this->localtax2_type)."'").","; $sql .= " ".(!isset($this->localtax2_tx) ? 'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).","; + $sql .= " ".(empty($this->discount_percent) ? '0' : "'".$this->db->escape(price2num($this->discount_percent))."'").","; + $sql .= " '".$this->db->idate($this->date_begin)."',"; + $sql .= " ".(empty($this->date_end) ? 'NULL' : "'".$this->db->idate($this->date_end)."'").","; $sql .= " ".((int) $user->id).","; $sql .= " ".(!isset($this->import_key) ? 'NULL' : "'".$this->db->escape($this->import_key)."'"); $sql .= ")"; @@ -303,6 +372,9 @@ public function fetch($id) $sql .= " t.recuperableonly,"; $sql .= " t.localtax1_tx,"; $sql .= " t.localtax2_tx,"; + $sql .= " t.discount_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.import_key"; $sql .= " FROM ".$this->db->prefix()."product_customer_price as t"; @@ -332,6 +404,9 @@ public function fetch($id) $this->recuperableonly = $obj->recuperableonly; $this->localtax1_tx = $obj->localtax1_tx; $this->localtax2_tx = $obj->localtax2_tx; + $this->discount_percent = $obj->discount_percent; + $this->date_begin = $this->db->jdate($obj->date_begin); + $this->date_end = $this->db->jdate($obj->date_end); $this->fk_user = $obj->fk_user; $this->import_key = $obj->import_key; @@ -386,7 +461,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = global $langs; if (empty($sortfield)) { - $sortfield = "t.rowid"; + $sortfield = "t.date_begin"; } if (empty($sortorder)) { $sortorder = "DESC"; @@ -412,6 +487,9 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = $sql .= " t.localtax2_tx,"; $sql .= " t.localtax1_type,"; $sql .= " t.localtax2_type,"; + $sql .= " t.discount_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.import_key,"; $sql .= " soc.nom as socname,"; @@ -433,7 +511,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = $sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'"; } elseif ($key == 'prod.ref' || $key == 'prod.label') { $sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'"; - } elseif ($key == 't.price' || $key == 't.price_ttc') { + } elseif ($key == 't.price' || $key == 't.price_ttc' || $key == 't.discount_percent') { $sql .= " AND ".$key." LIKE '%".price2num($value)."%'"; } else { $sql .= " AND ".$key." = ".((int) $value); @@ -474,6 +552,9 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = $line->localtax2_tx = $obj->localtax2_tx; $line->localtax1_type = $obj->localtax1_type; $line->localtax2_type = $obj->localtax2_type; + $line->discount_percent = $obj->discount_percent; + $line->date_begin = $this->db->jdate($obj->date_begin); + $line->date_end = $this->db->jdate($obj->date_end); $line->fk_user = $obj->fk_user; $line->import_key = $obj->import_key; $line->socname = $obj->socname; @@ -506,10 +587,10 @@ public function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = // phpcs:enable global $langs; - if (!empty($sortfield)) { - $sortfield = "t.rowid"; + if (empty($sortfield)) { + $sortfield = "t.date_begin"; } - if (!empty($sortorder)) { + if (empty($sortorder)) { $sortorder = "DESC"; } @@ -530,6 +611,9 @@ public function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = $sql .= " t.recuperableonly,"; $sql .= " t.localtax1_tx,"; $sql .= " t.localtax2_tx,"; + $sql .= " t.discount_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.import_key,"; $sql .= " soc.nom as socname,"; @@ -585,6 +669,9 @@ public function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = $line->recuperableonly = $obj->recuperableonly; $line->localtax1_tx = $obj->localtax1_tx; $line->localtax2_tx = $obj->localtax2_tx; + $line->discount_percent = $obj->discount_percent; + $line->date_begin = $this->db->jdate($obj->date_begin); + $line->date_end = $this->db->jdate($obj->date_end); $line->fk_user = $obj->fk_user; $line->import_key = $obj->import_key; $line->socname = $obj->socname; @@ -614,6 +701,7 @@ public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) global $conf, $langs; $error = 0; + $now = dol_now(); // Clean parameters @@ -656,6 +744,12 @@ public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) if (isset($this->localtax2_tx)) { $this->localtax2_tx = trim($this->localtax2_tx); } + if (empty($this->discount_percent) || !is_numeric($this->discount_percent)) { + $this->discount_percent = 0; + } + if (empty($this->date_begin)) { + $this->date_begin = $now; + } if (isset($this->fk_user)) { $this->fk_user = trim($this->fk_user); } @@ -663,8 +757,12 @@ public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) $this->import_key = trim($this->import_key); } - // Check parameters - // Put here code to add a control on parameters values + // Check parameters + // Put here code to add a control on parameters values + $result = $this->verifyDates(); + if ($result < 0) { + return -1; + } if ($this->price != '' || $this->price == 0) { if ($this->price_base_type == 'TTC') { @@ -718,6 +816,9 @@ public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) $sql .= "localtax2_tx,"; $sql .= "localtax1_type,"; $sql .= "localtax2_type,"; + $sql .= "discount_percent,"; + $sql .= "date_begin,"; + $sql .= "date_end,"; $sql .= "fk_user,"; $sql .= "import_key"; @@ -741,6 +842,9 @@ public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) $sql .= " t.localtax2_tx,"; $sql .= " t.localtax1_type,"; $sql .= " t.localtax2_type,"; + $sql .= " t.discount_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.import_key"; @@ -759,7 +863,7 @@ public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) $sql = "UPDATE ".$this->db->prefix()."product_customer_price SET"; $sql .= " entity=".$conf->entity.","; - $sql .= " datec='".$this->db->idate(dol_now())."',"; + $sql .= " datec='".$this->db->idate($now)."',"; $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; $sql .= " fk_soc=".(isset($this->fk_soc) ? $this->fk_soc : "null").","; @@ -776,6 +880,9 @@ public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) $sql .= " localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) : "null").","; $sql .= " localtax1_type=".(!empty($this->localtax1_type) ? "'".$this->db->escape($this->localtax1_type)."'" : "'0'").","; $sql .= " localtax2_type=".(!empty($this->localtax2_type) ? "'".$this->db->escape($this->localtax2_type)."'" : "'0'").","; + $sql .= " discount_percent=".(isset($this->discount_percent) ? price2num($this->discount_percent) : "null").","; + $sql .= " date_begin='".$this->db->idate($this->date_begin)."',"; + $sql .= " date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null").","; $sql .= " fk_user=".$user->id.","; $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); @@ -873,6 +980,9 @@ public function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate) $prodsocpriceupd->price_base_type = $this->price_base_type; $prodsocpriceupd->tva_tx = $this->tva_tx; $prodsocpriceupd->recuperableonly = $this->recuperableonly; + $prodsocpriceupd->discount_percent = $this->discount_percent; + $prodsocpriceupd->date_begin = $this->date_begin; + $prodsocpriceupd->date_end = $this->date_end; $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate); if ($resultupd < 0) { @@ -891,6 +1001,9 @@ public function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate) $prodsocpricenew->price_base_type = $this->price_base_type; $prodsocpricenew->tva_tx = $this->tva_tx; $prodsocpricenew->recuperableonly = $this->recuperableonly; + $prodsocpricenew->discount_percent = $this->discount_percent; + $prodsocpricenew->date_begin = $this->date_begin; + $prodsocpricenew->date_end = $this->date_end; $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate); if ($resultupd < 0) { @@ -1036,6 +1149,9 @@ public function initAsSpecimen() $this->recuperableonly = ''; $this->localtax1_tx = ''; $this->localtax2_tx = ''; + $this->discount_percent = ''; + $this->date_begin = ''; + $this->date_end = ''; $this->fk_user = ''; $this->import_key = ''; } @@ -1084,6 +1200,18 @@ class PriceByCustomerLine public $recuperableonly; public $localtax1_tx; public $localtax2_tx; + /** + * @var float + */ + public $discount_percent; + /** + * @var string|int + */ + public $date_begin = ''; + /** + * @var string|int + */ + public $date_end = ''; /** * @var int User ID diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 3d31a8ee40eee..72befe05503ec 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -635,6 +635,9 @@ $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); + $prodcustprice->discount_percent = price2num(GETPOST("discount_percent")); + $prodcustprice->date_begin = dol_mktime(0, 0, 0, GETPOST('date_beginmonth', 'int'), GETPOST('date_beginday', 'int'), GETPOST('date_beginyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server; + $prodcustprice->date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server $tva_tx_txt = GETPOST("tva_tx", 'alpha'); @@ -722,11 +725,11 @@ if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); + $action = 'add_customer_price'; } else { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + $action = ''; } - - $action = ''; } } @@ -755,6 +758,9 @@ $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); + $prodcustprice->discount_percent = price2num(GETPOST("discount_percent")); + $prodcustprice->date_begin = dol_mktime(0, 0, 0, GETPOST('date_beginmonth', 'int'), GETPOST('date_beginday', 'int'), GETPOST('date_beginyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server; + $prodcustprice->date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server $tva_tx_txt = GETPOST("tva_tx"); @@ -835,11 +841,11 @@ if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); + $action = 'update_customer_price'; } else { setEventMessages($langs->trans("Save"), null, 'mesgs'); + $action = ''; } - - $action = ''; } } } @@ -1923,10 +1929,10 @@ function on_change() { $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { - $sortorder = "ASC"; + $sortorder = "ASC,ASC"; } if (!$sortfield) { - $sortfield = "soc.nom"; + $sortfield = "soc.nom,t.date_begin"; } // Build filter to diplay only concerned lines @@ -1955,7 +1961,7 @@ function on_change() { print ''.$langs->trans('ThirdParty').''; print ''; $filter = '(s.client:IN:1,2,3)'; - print img_picto('', 'company').$form->select_company('', 'socid', $filter, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300'); + print img_picto('', 'company').$form->select_company(GETPOSTINT('socid'), 'socid', $filter, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300'); print ''; print ''; @@ -1963,6 +1969,18 @@ function on_change() { print '' . $langs->trans('RefCustomer') . ''; print ''; + // Applied Prices From + $date_begin = dol_mktime(0, 0, 0, GETPOST('date_beginmonth', 'int'), GETPOST('date_beginday', 'int'), GETPOST('date_beginyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server; + print ''.$langs->trans("AppliedPricesFrom").''; + print $form->selectDate(!empty($date_begin) ? $date_begin : dol_now(), "date_begin", 0, 0, 1, "date_begin"); + print ''; + + // Applied Prices To + $date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server + print ''.$langs->trans("AppliedPricesTo").''; + print $form->selectDate($date_end, "date_end", 0, 0, 1, "date_end"); + print ''; + // VAT print ''.$langs->trans("DefaultTaxRate").''; print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1); @@ -2003,6 +2021,12 @@ function on_change() { } print ''; + // Discount + $discount_percent = price2num(GETPOST("discount_percent")); + print ''.$langs->trans("Discount").''; + print ''; + print ''; + print ''; print ''; @@ -2048,6 +2072,16 @@ function on_change() { print '' . $langs->trans('RefCustomer') . ''; print ''; + // Applied Prices From + print ''.$langs->trans("AppliedPricesFrom").''; + print $form->selectDate($prodcustprice->date_begin, "date_begin", 0, 0, 1, "date_begin"); + print ''; + + // Applied Prices To + print ''.$langs->trans("AppliedPricesTo").''; + print $form->selectDate($prodcustprice->date_end, "date_end", 0, 0, 1, "date_end"); + print ''; + // VAT print ''.$langs->trans("DefaultTaxRate").''; print $form->load_tva("tva_tx", $prodcustprice->default_vat_code ? $prodcustprice->tva_tx.' ('.$prodcustprice->default_vat_code.')' : $prodcustprice->tva_tx, $mysoc, '', $object->id, $prodcustprice->recuperableonly, $object->type, false, 1); @@ -2090,6 +2124,11 @@ function on_change() { } print ''; + // Discount + print ''.$langs->trans("Discount").''; + print ''; + print ''; + print ''; @@ -2106,6 +2145,7 @@ function on_change() { // List of all log of prices by customers print ''."\n"; + $sortfield = 't.datec'; $filter = array('t.fk_product' => $object->id, 't.fk_soc' => GETPOST('socid', 'int')); // Count total nb of records @@ -2143,6 +2183,7 @@ function on_change() { print ''.$langs->trans("ThirdParty").''; print ''.$langs->trans('RefCustomer').''; print ''.$langs->trans("AppliedPricesFrom").''; + print ''.$langs->trans("AppliedPricesTo").''; print ''.$langs->trans("PriceBase").''; print ''.$langs->trans("DefaultTaxRate").''; print ''.$langs->trans("HT").''; @@ -2152,8 +2193,9 @@ function on_change() { } print ''.$langs->trans("MinPrice").' '.$langs->trans("HT").''; print ''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''; + print ''.$langs->trans("Discount").''; print ''.$langs->trans("ChangedBy").''; - print ' '; + print ''.$langs->trans("DateCreation").''; print ''; foreach ($prodcustprice->lines as $line) { @@ -2185,7 +2227,8 @@ function on_change() { print "".$staticsoc->getNomUrl(1).""; print ''.$line->ref_customer.''; - print "".dol_print_date($line->datec, "dayhour", 'tzuserrel').""; + print "".dol_print_date($line->date_begin, "day", 'tzuserrel').""; + print "".dol_print_date($line->date_end, "day", 'tzuserrel').""; print ''.$langs->trans($line->price_base_type).""; print ''; @@ -2216,6 +2259,7 @@ function on_change() { print ''.price($line->price_min).''; print ''.price($line->price_min_ttc).''; + print ''.price($line->discount_percent).''; // User $userstatic = new User($db); @@ -2224,6 +2268,7 @@ function on_change() { print $userstatic->getNomUrl(1, '', 0, 0, 24, 0, 'login'); //print $userstatic->getLoginUrl(1); print ''; + print "".dol_print_date($line->datec, "dayhour", 'tzuserrel').""; print ''; } print ""; @@ -2259,7 +2304,7 @@ function on_change() { print ''."\n"; if (count($prodcustprice->lines) > 0 || $search_soc) { - $colspan = 9; + $colspan = 11; if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { $colspan++; } @@ -2279,6 +2324,7 @@ function on_change() { print ''; print ''; print ''; + print ''; print ''; print ''; print ''; @@ -2288,6 +2334,7 @@ function on_change() { } print ''; print ''; + print ''; print ''; print ''; print ''; @@ -2311,7 +2358,7 @@ function on_change() { $total_ttc = $resultarray[2]; print ''; - print ''; + print ''; print '"; @@ -2349,6 +2396,7 @@ function on_change() { print ''; print ''; + print ''; if ($user->hasRight('produit', 'supprimer') || $user->hasRight('service', 'supprimer')) { print '"; print ''; - print ""; + print ""; + print ""; print '"; // VAT Rate print ''; print ''; + print ''; // User $userstatic = new User($db); diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php index c85286dbead44..5cb5c2c959c6e 100644 --- a/htdocs/societe/price.php +++ b/htdocs/societe/price.php @@ -102,6 +102,9 @@ $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); + $prodcustprice->discount_percent = price2num(GETPOST("discount_percent")); + $prodcustprice->date_begin = dol_mktime(0, 0, 0, GETPOST('date_beginmonth', 'int'), GETPOST('date_beginday', 'int'), GETPOST('date_beginyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server; + $prodcustprice->date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' @@ -144,11 +147,11 @@ if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); + $action = 'add_customer_price'; } else { setEventMessages($langs->trans("Save"), null, 'mesgs'); + $action = ''; } - - $action = ''; } } @@ -177,15 +180,18 @@ $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0); + $prodcustprice->discount_percent = price2num(GETPOST("discount_percent")); + $prodcustprice->date_begin = dol_mktime(0, 0, 0, GETPOST('date_beginmonth', 'int'), GETPOST('date_beginday', 'int'), GETPOST('date_beginyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server; + $prodcustprice->date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server $result = $prodcustprice->update($user, 0, $update_child_soc); if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); + $action = 'edit_customer_price'; } else { setEventMessages($langs->trans("Save"), null, 'mesgs'); + $action = ''; } - - $action = ''; } } @@ -270,10 +276,10 @@ $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { - $sortorder = "ASC"; + $sortorder = "ASC,ASC"; } if (!$sortfield) { - $sortfield = "soc.nom"; + $sortfield = "soc.nom,t.date_begin"; } // Build filter to display only concerned lines @@ -313,7 +319,7 @@ print ''; print ''; print ''; print ''; @@ -321,6 +327,18 @@ print ''; print ''; + // Applied Prices From + $date_begin = dol_mktime(0, 0, 0, GETPOST('date_beginmonth', 'int'), GETPOST('date_beginday', 'int'), GETPOST('date_beginyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server; + print ''; + + // Applied Prices To + $date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server + print ''; + // VAT print ''; + // Discount + $discount_percent = price2num(GETPOST("discount_percent")); + print ''; + // Update all child soc print ''; print ''; + // Applied Prices From + print ''; + + // Applied Prices To + print ''; + // VAT print ''; + // Discount + print ''; + // Update all child soc print ''; print ''; print ''; + print ''; print ''; print ''; print ''; print ''; print ''; print ''; + print ''; print ''; - print ''; + print ''; print ''; foreach ($prodcustprice->lines as $line) { @@ -499,7 +541,8 @@ print ""; print ''; - print ""; + print ""; + print ""; print '"; print '"; @@ -507,12 +550,13 @@ print '"; print ''; print ''; + print ''; // User print ''; - print ''; + print ""; } print "
'.$langs->trans("ThirdParty").''.$langs->trans('RefCustomer').''.$langs->trans("AppliedPricesFrom").''.$langs->trans("AppliedPricesTo").''.$langs->trans("PriceBase").''.$langs->trans("DefaultTaxRate").''.$langs->trans("HT").''.$langs->trans("MinPrice").' '.$langs->trans("HT").''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''.$langs->trans("Discount").''.$langs->trans("ChangedBy").'
' . $langs->trans('Default') . '' . $langs->trans('Default') . ''.$langs->trans($object->price_base_type)."'.price($object->price_min_ttc).''; print ''; print 'id.'">'; @@ -2392,7 +2440,8 @@ function on_change() { print "".$staticsoc->getNomUrl(1)."'.dol_escape_htmltag($line->ref_customer).'".dol_print_date($line->datec, "dayhour", 'tzuserrel')."".dol_print_date($line->date_begin, "day", 'tzuserrel')."".dol_print_date($line->date_end, "day", 'tzuserrel')."'.$langs->trans($line->price_base_type)."'; @@ -2425,6 +2474,7 @@ function on_change() { print ''.price($line->price_min).''.price($line->price_min_ttc).''.price($line->discount_percent).'
'.$langs->trans('Product').''; - $form->select_produits('', 'prodid', '', 0); + $form->select_produits(GETPOSTINT('prodid'), 'prodid', '', 0); print '
'.$langs->trans('RefCustomer').'
'.$langs->trans("AppliedPricesFrom").''; + print $form->selectDate(!empty($date_begin) ? $date_begin : dol_now(), "date_begin", 0, 0, 1, "date_begin"); + print '
'.$langs->trans("AppliedPricesTo").''; + print $form->selectDate($date_end, "date_end", 0, 0, 1, "date_end"); + print '
'.$langs->trans("VATRate").''; print $form->load_tva("tva_tx", GETPOST("tva_tx", "alpha"), $mysoc, '', $object->id, 0, '', false, 1); @@ -350,6 +368,12 @@ print ''; print '
'.$langs->trans("Discount").''; + print ''; + print '
'; print $langs->trans('ForceUpdateChildPriceSoc'); @@ -390,6 +414,16 @@ print '
'.$langs->trans('RefCustomer').'
'.$langs->trans("AppliedPricesFrom").''; + print $form->selectDate($prodcustprice->date_begin, "date_begin", 0, 0, 1, "date_begin"); + print '
'.$langs->trans("AppliedPricesTo").''; + print $form->selectDate($prodcustprice->date_end, "date_end", 0, 0, 1, "date_end"); + print '
'.$langs->trans("VATRate").''; print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, '', $staticprod->id, $prodcustprice->recuperableonly); @@ -428,6 +462,11 @@ } print '
'.$langs->trans("Discount").''; + print ''; + print '
'; print $langs->trans('ForceUpdateChildPriceSoc'); @@ -447,6 +486,7 @@ print '
'; print ''."\n"; + $sortfield = 't.datec'; $filter = array( 't.fk_product' => GETPOST('prodid', 'int'), 't.fk_soc' => $socid @@ -478,14 +518,16 @@ print '
'.$langs->trans("Product").''.$langs->trans('RefCustomer').''.$langs->trans("AppliedPricesFrom").''.$langs->trans("AppliedPricesTo").''.$langs->trans("PriceBase").''.$langs->trans("VAT").''.$langs->trans("HT").''.$langs->trans("TTC").''.$langs->trans("MinPrice").' '.$langs->trans("HT").''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''.$langs->trans("Discount").''.$langs->trans("ChangedBy").''.$langs->trans("DateCreation").'
".$staticprod->getNomUrl(1)."'.$line->ref_customer.'".dol_print_date($line->datec, "dayhour")."".dol_print_date($line->date_begin, "day", 'tzuserrel')."".dol_print_date($line->date_end, "day", 'tzuserrel')."'.$langs->trans($line->price_base_type)."'.vatrate($line->tva_tx, true, $line->recuperableonly)."'.price($line->price_ttc)."'.price($line->price_min).''.price($line->price_min_ttc).''.price($line->discount_percent).''; print $userstatic->getNomUrl(-1); print '".dol_print_date($line->datec, "dayhour", 'tzuserrel')."
"; } else { @@ -565,12 +609,14 @@ print ''.$langs->trans("Product").''; print ''.$langs->trans('RefCustomer').''; print ''.$langs->trans("AppliedPricesFrom").''; + print ''.$langs->trans("AppliedPricesTo").''; print ''.$langs->trans("PriceBase").''; print ''.$langs->trans("VAT").''; print ''.$langs->trans("HT").''; print ''.$langs->trans("TTC").''; print ''.$langs->trans("MinPrice").' '.$langs->trans("HT").''; print ''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''; + print ''.$langs->trans("Discount").''; print ''.$langs->trans("ChangedBy").''; print ''; print ''; @@ -583,11 +629,13 @@ print ''; print ''; print ''; + print ''; print ''; print ''; print ''; print ''; print ''; + print ''; // Print the search button print ''; $searchpicto = $form->showFilterAndCheckAddButtons(0); @@ -609,13 +657,15 @@ print "".$staticprod->getNomUrl(1).""; print "".$staticprod->label.""; print ''.$line->ref_customer.''; - print "".dol_print_date($line->datec, "dayhour").""; + print ''.dol_print_date($line->date_begin, "day", 'tzuserrel').""; + print ''.dol_print_date($line->date_end, "day", 'tzuserrel').""; print ''.$langs->trans($line->price_base_type).""; print ''.vatrate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), true, $line->recuperableonly).""; print ''.price($line->price).""; print ''.price($line->price_ttc).""; print ''.price($line->price_min).''; print ''.price($line->price_min_ttc).''; + print ''.price($line->discount_percent).''; // User print ''; print $userstatic->getNomUrl(-1);