From 7ba21bd23d38ef13e7a34693e8e619df03da3e2f Mon Sep 17 00:00:00 2001 From: Kamel Khelifa Date: Tue, 25 Feb 2025 15:09:05 +0100 Subject: [PATCH] NEW: Add management of date begin/end and discount for a customer price (Code) --- htdocs/comm/propal/card.php | 62 +++++++----- htdocs/comm/propal/class/propal.class.php | 15 ++- htdocs/commande/card.php | 62 +++++++----- htdocs/contrat/card.php | 24 +++-- htdocs/core/class/html.form.class.php | 20 +++- htdocs/core/lib/pdf.lib.php | 13 ++- htdocs/core/modules/modProduct.class.php | 6 ++ htdocs/core/modules/modService.class.php | 6 ++ htdocs/core/tpl/objectline_create.tpl.php | 7 ++ htdocs/langs/en_US/products.lang | 1 + htdocs/langs/fr_FR/products.lang | 1 + htdocs/product/ajax/products.php | 21 +++-- htdocs/product/card.php | 14 ++- htdocs/product/class/product.class.php | 58 +++++++----- .../class/productcustomerprice.class.php | 94 +++++++++++++++++-- htdocs/product/price.php | 68 ++++++++++++-- htdocs/societe/price.php | 60 ++++++++++-- 17 files changed, 406 insertions(+), 126 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index fbdb640bf5d..3ffddeb50cb 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1169,20 +1169,26 @@ if (empty($reshook)) { if ($result) { // If there is some prices specific to the customer if (count($prodcustprice->lines) > 0) { - $pricebycustomerexist = true; - $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)) { + $pricebycustomerexist = true; + $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; - }*/ } } @@ -1227,19 +1233,25 @@ if (empty($reshook)) { 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 (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY')) { diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 07bdd50e7a5..ab667686493 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1541,10 +1541,17 @@ class Propal extends CommonObject 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->remise_percent; + break; + } } } } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index f10e6e3aa6c..9157b6d01fe 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -877,19 +877,25 @@ if (empty($reshook)) { $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); if ($result >= 0) { if (count($prodcustprice->lines) > 0) { - $pricebycustomerexist = true; - $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('/\(.*\)/', (string) $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)) { + $pricebycustomerexist = true; + $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('/\(.*\)/', (string)$tva_tx)) { + $tva_tx .= ' (' . $custprice_line->default_vat_code . ')'; + } + $tva_npr = $custprice_line->recuperableonly; + if (empty($tva_tx)) { + $tva_npr = 0; + } + break; + } } } } else { @@ -938,18 +944,24 @@ if (empty($reshook)) { $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 86a46a1919a..0fe433831a4 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -567,16 +567,22 @@ if (empty($reshook)) { $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 77c8eb3e137..b7efd69ea7c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2995,8 +2995,8 @@ class Form //Price by customer if ((getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !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.remise_percent as custremise_percent'; + $selectFields .= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custremise_percent"; } // Units if (getDolGlobalInt('PRODUCT_USE_UNITS')) { @@ -3047,7 +3047,20 @@ class Form //Price by customer if ((getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !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')) { @@ -3588,6 +3601,7 @@ class Form $outpricebasetype = $objp->custprice_base_type; $outtva_tx = $objp->custtva_tx; $outdefault_vat_code = $objp->custdefault_vat_code; + $outdiscount = $objp->custremise_percent; } } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 4b11ccc758d..8a2fdc2f978 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1747,9 +1747,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 384692a0bf9..cad7f5490de 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -380,11 +380,14 @@ class modProduct extends DolibarrModules $this->export_fields_array[$r] = array('p.rowid' => "Id", 'p.ref' => "Ref", 'p.label' => "Label", 's.nom' => 'ThirdParty', 's.code_client' => 'CodeClient', + '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.remise_percent' => 'Discount', 'pr.datec' => 'DateCreation'); if (is_object($mysoc) && $usenpr) { $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR'; @@ -392,11 +395,14 @@ class modProduct extends DolibarrModules $this->export_entities_array[$r] = array('p.rowid' => "product", 'p.ref' => "product", 'p.label' => "Label", 's.nom' => 'company', 's.code_client' => '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.remise_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 ea16a72ff63..4335b25638a 100644 --- a/htdocs/core/modules/modService.class.php +++ b/htdocs/core/modules/modService.class.php @@ -327,22 +327,28 @@ class modService extends DolibarrModules $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.remise_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.remise_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 df96090135a..15e20798a3f 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -938,6 +938,13 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) { $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true); socid)) { + ?> + $("#remise_percent").val(data.discount); + var proddesc = data.desc_trans; diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 84cfffe0780..8a69f7c1a9a 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -69,6 +69,7 @@ UpdateVAT=Update VAT UpdateDefaultPrice=Update default price UpdateLevelPrices=Update prices for each level AppliedPricesFrom=Applied from +AppliedPricesTo=Applied to 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 0b5954b3394..6c6159220be 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -69,6 +69,7 @@ UpdateVAT=Mettre à jour la TVA UpdateDefaultPrice=Modifier prix par défaut UpdateLevelPrices=Modifier prix pour chaque niveau AppliedPricesFrom=Pratiqués à partir du +AppliedPricesTo=Pratiqués jusqu'au 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 274de7cce07..71caa109c1e 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -220,13 +220,20 @@ if ($action == 'fetch' && !empty($id)) { $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->remise_percent; + break; + } + } } } } diff --git a/htdocs/product/card.php b/htdocs/product/card.php index f685f012a5b..63bf5565aed 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1156,10 +1156,16 @@ if (empty($reshook)) { $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 b7d714b1722..f06a8fd29ec 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2354,18 +2354,24 @@ class Product extends CommonObject $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { - $pricebycustomerexist = true; - $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)) { + $pricebycustomerexist = true; + $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; + } } } } @@ -2415,17 +2421,23 @@ class Product extends CommonObject $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 4838885cb07..a4883362f8f 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -38,7 +38,8 @@ class ProductCustomerPrice extends CommonObject 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 4, 'position' => 10, 'notnull' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'comment' => "Reference of object", 'showoncombobox' => 1, 'noteditable' => 1), 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php:0', 'label' => 'Product', 'enabled' => '$conf->product->enabled', 'visible' => 1, 'position' => 35, 'notnull' => 1, 'index' => 1, 'comment' => "Product to produce", 'css' => 'maxwidth300', 'csslist' => 'tdoverflowmax100', 'picto' => 'product'), 'ref_customer' => array('type' => 'varchar(128)', 'label' => 'RefCustomer', 'enabled' => 1, 'visible' => 4, 'position' => 10, 'notnull' => 1,), - 'datec' => array('type' => 'datetime', 'label' => 'AppliedPricesFrom', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'notnull' => 1,), + 'date_begin' => array('type' => 'date', 'label' => 'AppliedPricesFrom', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'notnull' => 1,), + 'date_end' => array('type' => 'date', 'label' => 'AppliedPricesTo', 'enabled' => 1, 'visible' => 1, 'position' => 501, 'notnull' => 1,), 'price_base_type' => array('type' => 'varchar(255)', 'label' => 'PriceBase', 'enabled' => 1, 'visible' => 1, 'position' => 11, 'notnull' => -1, 'comment' => 'Price Base Type'), 'tva_tx' => array('type' => 'decimal(20,6)', 'label' => 'VAT', 'enabled' => 1, 'visible' => 1, 'position' => 12, 'notnull' => -1, 'comment' => 'TVA Tax Rate'), 'price' => array('type' => 'decimal(20,6)', 'label' => 'HT', 'enabled' => 1, 'visible' => 1, 'position' => 8, 'notnull' => -1, 'comment' => 'Price HT'), @@ -46,6 +47,7 @@ class ProductCustomerPrice extends CommonObject 'price_min' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceHT', 'enabled' => 1, 'visible' => 1, 'position' => 9, 'notnull' => -1, 'comment' => 'Minimum Price'), 'price_min_ttc' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceTTC', 'enabled' => 1, 'visible' => 1, 'position' => 10, 'notnull' => -1, 'comment' => 'Minimum Price TTC'), 'price_label' => array('type' => 'varchar(255)', 'label' => 'PriceLabel', 'enabled' => 1, 'visible' => 1, 'position' => 20, 'notnull' => -1, 'comment' => 'Price Label'), + 'remise_percent' => array('type' => 'decimal(20,6)', 'label' => 'Discount', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'notnull' => -1, 'comment' => 'Discount'), 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => 1, 'position' => 510, 'notnull' => 1, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax100'), ); @@ -136,6 +138,18 @@ class ProductCustomerPrice extends CommonObject * @var string */ public $price_label; + /** + * @var float|string|'' + */ + public $remise_percent; + /** + * @var string + */ + public $date_begin = ''; + /** + * @var string + */ + public $date_end = ''; /** * @var int User ID @@ -212,6 +226,9 @@ class ProductCustomerPrice extends CommonObject if (isset($this->localtax2_tx)) { $this->localtax2_tx = trim($this->localtax2_tx); } + if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) { + $this->remise_percent = 0; + } if (isset($this->fk_user)) { $this->fk_user = (int) $this->fk_user; } @@ -257,6 +274,8 @@ class ProductCustomerPrice extends CommonObject } } + $now = dol_now(); + // Insert request $sql = "INSERT INTO ".$this->db->prefix()."product_customer_price("; $sql .= "entity,"; @@ -276,12 +295,15 @@ class ProductCustomerPrice extends CommonObject $sql .= "localtax1_tx,"; $sql .= "localtax2_type,"; $sql .= "localtax2_tx,"; + $sql .= "remise_percent,"; + $sql .= "date_begin,"; + $sql .= "date_end,"; $sql .= "fk_user,"; $sql .= "price_label,"; $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' : ((int) $this->fk_product)).","; $sql .= " ".(!isset($this->fk_soc) ? 'NULL' : ((int) $this->fk_soc)).","; $sql .= " ".(!isset($this->ref_customer) ? 'NULL' : "'".$this->db->escape($this->ref_customer)."'").","; @@ -297,6 +319,9 @@ class ProductCustomerPrice extends CommonObject $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->remise_percent) ? '0' : "'".$this->db->escape(price2num($this->remise_percent))."'").","; + $sql .= " '".$this->db->idate(empty($this->date_begin) ? $now : $this->date_begin)."',"; + $sql .= " ".(empty($this->date_end) ? 'NULL' : "'".$this->db->idate($this->date_end)."'").","; $sql .= " ".((int) $user->id).","; $sql .= " ".(!isset($this->price_label) ? 'NULL' : "'".$this->db->escape($this->price_label)."'").","; $sql .= " ".(!isset($this->import_key) ? 'NULL' : "'".$this->db->escape($this->import_key)."'"); @@ -371,6 +396,9 @@ class ProductCustomerPrice extends CommonObject $sql .= " t.recuperableonly,"; $sql .= " t.localtax1_tx,"; $sql .= " t.localtax2_tx,"; + $sql .= " t.remise_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.price_label,"; $sql .= " t.import_key"; @@ -401,6 +429,9 @@ class ProductCustomerPrice extends CommonObject $this->recuperableonly = $obj->recuperableonly; $this->localtax1_tx = $obj->localtax1_tx; $this->localtax2_tx = $obj->localtax2_tx; + $this->remise_percent = $obj->remise_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->price_label = $obj->price_label; $this->import_key = $obj->import_key; @@ -433,7 +464,7 @@ class ProductCustomerPrice extends CommonObject public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '') { if (empty($sortfield)) { - $sortfield = "t.rowid"; + $sortfield = "t.date_begin"; } if (empty($sortorder)) { $sortorder = "DESC"; @@ -459,6 +490,9 @@ class ProductCustomerPrice extends CommonObject $sql .= " t.localtax2_tx,"; $sql .= " t.localtax1_type,"; $sql .= " t.localtax2_type,"; + $sql .= " t.remise_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.price_label,"; $sql .= " t.import_key,"; @@ -482,7 +516,7 @@ class ProductCustomerPrice extends CommonObject $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'"; } elseif ($key == 'prod.ref' || $key == 'prod.label') { $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'"; - } elseif ($key == 't.price' || $key == 't.price_ttc') { + } elseif ($key == 't.price' || $key == 't.price_ttc' || $key == 't.remise_percent') { $sql .= " AND ".$this->db->sanitize($key)." = ".((float) price2num($value)); } else { $sql .= " AND ".$this->db->sanitize($key)." = ".((int) $value); @@ -536,6 +570,9 @@ class ProductCustomerPrice extends CommonObject $line->localtax2_tx = $obj->localtax2_tx; $line->localtax1_type = $obj->localtax1_type; $line->localtax2_type = $obj->localtax2_type; + $line->remise_percent = $obj->remise_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->price_label = $obj->price_label; $line->import_key = $obj->import_key; @@ -565,10 +602,10 @@ class ProductCustomerPrice extends CommonObject */ public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = array()) { - if (!empty($sortfield)) { - $sortfield = "t.rowid"; + if (empty($sortfield)) { + $sortfield = "t.date_begin"; } - if (!empty($sortorder)) { + if (empty($sortorder)) { $sortorder = "DESC"; } @@ -589,6 +626,9 @@ class ProductCustomerPrice extends CommonObject $sql .= " t.recuperableonly,"; $sql .= " t.localtax1_tx,"; $sql .= " t.localtax2_tx,"; + $sql .= " t.remise_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.price_label,"; $sql .= " t.import_key,"; @@ -645,6 +685,9 @@ class ProductCustomerPrice extends CommonObject $line->recuperableonly = $obj->recuperableonly; $line->localtax1_tx = $obj->localtax1_tx; $line->localtax2_tx = $obj->localtax2_tx; + $line->remise_percent = $obj->remise_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->price_label = $obj->price_label; $line->import_key = $obj->import_key; @@ -716,6 +759,9 @@ class ProductCustomerPrice extends CommonObject if (isset($this->localtax2_tx)) { $this->localtax2_tx = trim((string) $this->localtax2_tx); } + if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) { + $this->remise_percent = 0; + } if (isset($this->fk_user)) { $this->fk_user = (int) $this->fk_user; } @@ -782,6 +828,9 @@ class ProductCustomerPrice extends CommonObject $sql .= "localtax2_tx,"; $sql .= "localtax1_type,"; $sql .= "localtax2_type,"; + $sql .= "remise_percent,"; + $sql .= "date_begin,"; + $sql .= "date_end,"; $sql .= "fk_user,"; $sql .= "price_label,"; $sql .= "import_key"; @@ -806,6 +855,9 @@ class ProductCustomerPrice extends CommonObject $sql .= " t.localtax2_tx,"; $sql .= " t.localtax1_type,"; $sql .= " t.localtax2_type,"; + $sql .= " t.remise_percent,"; + $sql .= " t.date_begin,"; + $sql .= " t.date_end,"; $sql .= " t.fk_user,"; $sql .= " t.price_label,"; $sql .= " t.import_key"; @@ -821,11 +873,13 @@ class ProductCustomerPrice extends CommonObject $this->errors [] = "Error ".$this->db->lasterror(); } + $now = dol_now(); + // Update request $sql = "UPDATE ".$this->db->prefix()."product_customer_price SET"; $sql .= " entity=".((int) $conf->entity).","; - $sql .= " datec='".$this->db->idate(dol_now())."',"; + $sql .= " datec='".$this->db->idate($now)."',"; $sql .= " tms=".(dol_strlen((string) $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").","; @@ -842,6 +896,9 @@ class ProductCustomerPrice extends CommonObject $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 .= " remise_percent=".(isset($this->remise_percent) ? price2num($this->remise_percent) : "null").","; + $sql .= " date_begin='".$this->db->idate(!empty($this->date_begin) ? $this->date_begin : $now)."',"; + $sql .= " date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null").","; $sql .= " fk_user=".((int) $user->id).","; $sql .= " price_label=".(isset($this->price_label) ? "'".$this->db->escape($this->price_label)."'" : "null").","; $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); @@ -939,6 +996,9 @@ class ProductCustomerPrice extends CommonObject $prodsocpriceupd->tva_tx = $this->tva_tx; $prodsocpriceupd->recuperableonly = $this->recuperableonly; $prodsocpriceupd->price_label = $this->price_label; + $prodsocpriceupd->remise_percent = $this->remise_percent; + $prodsocpriceupd->date_begin = $this->date_begin; + $prodsocpriceupd->date_end = $this->date_end; $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate); if ($resultupd < 0) { @@ -958,6 +1018,9 @@ class ProductCustomerPrice extends CommonObject $prodsocpricenew->tva_tx = $this->tva_tx; $prodsocpricenew->recuperableonly = $this->recuperableonly; $prodsocpricenew->price_label = $this->price_label; + $prodsocpricenew->remise_percent = $this->remise_percent; + $prodsocpricenew->date_begin = $this->date_begin; + $prodsocpricenew->date_end = $this->date_end; $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate); if ($resultupd < 0) { @@ -1102,6 +1165,9 @@ class ProductCustomerPrice extends CommonObject $this->recuperableonly = ''; $this->localtax1_tx = ''; $this->localtax2_tx = ''; + $this->remise_percent = ''; + $this->date_begin = ''; + $this->date_end = ''; $this->fk_user = 0; $this->price_label = ''; $this->import_key = ''; @@ -1185,6 +1251,18 @@ class PriceByCustomerLine extends CommonObjectLine * @var float */ public $localtax2_tx; + /** + * @var float + */ + public $remise_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 6c6a98b126e..eff87f5f275 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -754,6 +754,9 @@ if (empty($reshook)) { $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); $prodcustprice->price_label = GETPOST("price_label", 'alpha'); + $prodcustprice->remise_percent = price2num(GETPOST("remise_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 $extralabels = $extrafields->fetch_name_optionals_label("product_customer_price"); $extrafield_values = $extrafields->getOptionalsFromPost("product_customer_price"); @@ -906,6 +909,9 @@ if (empty($reshook)) { $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); $prodcustprice->price_label = GETPOST("price_label", 'alpha'); + $prodcustprice->remise_percent = price2num(GETPOST("remise_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 $extralabels = $extrafields->fetch_name_optionals_label("product_customer_price"); $extrafield_values = $extrafields->getOptionalsFromPost("product_customer_price"); @@ -2002,10 +2008,10 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT $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 @@ -2042,6 +2048,18 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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, null, $object->id, $object->tva_npr, $object->type, false, 1); @@ -2090,6 +2108,12 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''; print ''; + // Discount + $remise_percent = price2num(GETPOST("remise_percent")); + print ''.$langs->trans("Discount").''; + print ''; + print ''; + // Extrafields $extrafields->fetch_name_optionals_label("product_customer_price"); $extralabels = !empty($extrafields->attributes["product_customer_price"]['label']) ? $extrafields->attributes["product_customer_price"]['label'] : ''; @@ -2159,6 +2183,16 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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, null, $object->id, $prodcustprice->recuperableonly, $object->type, false, 1); @@ -2201,8 +2235,6 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT } print ''; - - // Price Label print ''; print $langs->trans('PriceLabel'); @@ -2211,6 +2243,11 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''; print ''; + // Discount + print ''.$langs->trans("Discount").''; + print ''; + print ''; + // Extrafields $extrafields->fetch_name_optionals_label("product_customer_price"); $extralabels = !empty($extrafields->attributes["product_customer_price"]['label']) ? $extrafields->attributes["product_customer_price"]['label'] : ''; @@ -2280,6 +2317,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT // List of all log of prices by customers print ''."\n"; + $sortfield = 't.datec'; $filter = array('t.fk_product' => (string) $object->id, 't.fk_soc' => (string) GETPOSTINT('socid')); // Count total nb of records @@ -2318,6 +2356,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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").''; @@ -2328,8 +2367,9 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.$langs->trans("MinPrice").' '.$langs->trans("HT").''; print ''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''; print ''.$langs->trans("PriceLabel").''; + print ''.$langs->trans("Discount").''; print ''.$langs->trans("ChangedBy").''; - print ' '; + print ''.$langs->trans("DateCreation").''; print ''; foreach ($prodcustprice->lines as $line) { @@ -2361,7 +2401,8 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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 ''; @@ -2393,6 +2434,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.price($line->price_min).''; print ''.price($line->price_min_ttc).''; print ''.$line->price_label.''; + print ''.price($line->remise_percent).''; // User $userstatic = new User($db); @@ -2401,6 +2443,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print $userstatic->getNomUrl(1, '', 0, 0, 24, 0, 'login'); //print $userstatic->getLoginUrl(1); print ''; + print "".dol_print_date($line->datec, "dayhour", 'tzuserrel').""; print ''; } print ""; @@ -2440,9 +2483,9 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT $extrafields->fetch_name_optionals_label("product_customer_price"); $custom_price_extralabels = !empty($extrafields->attributes["product_customer_price"]['label']) ? $extrafields->attributes["product_customer_price"]['label'] : ''; if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { - $colspan = 10; - } else { $colspan = 11; + } else { + $colspan = 12; } if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { $colspan++; @@ -2466,6 +2509,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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").''; @@ -2476,6 +2520,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.$langs->trans("MinPrice").' '.$langs->trans("HT").''; print ''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''; print ''.$langs->trans("PriceLabel").''; + print ''.$langs->trans("Discount").''; // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label("product_customer_price"); if ($extrafields->attributes["product_customer_price"] && array_key_exists('label', $extrafields->attributes["product_customer_price"])) { @@ -2522,7 +2567,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT if (!getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { print ''."\n"; print ''; - print '' . $langs->trans('Default') . ''; + print '' . $langs->trans('Default') . ''; print ''.$langs->trans($object->price_base_type).""; @@ -2560,6 +2605,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.price($object->price_min_ttc).''; print ''.$object->price_label.''; print ''; + print ''; if (!empty($extralabels)) { foreach ($extralabels as $key) { // Show field if not hidden @@ -2612,7 +2658,8 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.$staticsoc->getNomUrl(1).""; print ''.dol_escape_htmltag($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).""; // VAT Rate print ''; @@ -2646,6 +2693,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.price($line->price_min).''; print ''.price($line->price_min_ttc).''; print ''.$line->price_label.''; + print ''.price($line->remise_percent).''; // Extrafields $extrafields->fetch_name_optionals_label("product_customer_price"); diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php index 865b774e30c..d8365b8640c 100644 --- a/htdocs/societe/price.php +++ b/htdocs/societe/price.php @@ -115,6 +115,9 @@ if (empty($reshook)) { $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); + $prodcustprice->remise_percent = price2num(GETPOST("remise_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)' @@ -213,6 +216,9 @@ if (empty($reshook)) { $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->remise_percent = price2num(GETPOST("remise_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) { @@ -323,10 +329,10 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT $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 related lines @@ -376,6 +382,18 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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("VATRate").''; print $form->load_tva("tva_tx", GETPOST("tva_tx", "alpha"), $mysoc, null, $object->id, 0, '', false, 1); @@ -405,6 +423,12 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''; print ''; + // Discount + $remise_percent = price2num(GETPOST("remise_percent")); + print ''.$langs->trans("Discount").''; + print ''; + print ''; + // Update all child soc print ''; print $langs->trans('ForceUpdateChildPriceSoc'); @@ -469,6 +493,16 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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("VATRate").''; print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, null, $staticprod->id, $prodcustprice->recuperableonly); @@ -507,6 +541,11 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT } print ''; + // Discount + print ''.$langs->trans("Discount").''; + print ''; + print ''; + // Extrafields $extrafields->fetch_name_optionals_label("product_customer_price"); $extralabels = !empty($extrafields->attributes["product_customer_price"]['label']) ? $extrafields->attributes["product_customer_price"]['label'] : ''; @@ -577,6 +616,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print '
'; print ''."\n"; + $sortfield = 't.datec'; $filter = array( 't.fk_product' => (string) GETPOSTINT('prodid'), 't.fk_soc' => (string) $socid @@ -609,14 +649,16 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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 ''.$langs->trans("DateCreation").''; print ''; foreach ($prodcustprice->lines as $line) { @@ -630,7 +672,8 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print "".$staticprod->getNomUrl(1).""; 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, true, $line->recuperableonly).""; @@ -638,12 +681,13 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.price($line->price_ttc).""; print ''.price($line->price_min).''; print ''.price($line->price_min_ttc).''; + print ''.price($line->remise_percent).''; // User print ''; print $userstatic->getNomUrl(-1); print ''; - print ''; + print "".dol_print_date($line->datec, "dayhour", 'tzuserrel').""; } print ""; } else { @@ -786,12 +830,14 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''; print ''; print ''; + print ''; print ''; print ''; print ''; print ''; print ''; print ''; + print ''; if (!empty($extralabels)) { foreach ($extralabels as $key) { print ''; @@ -818,7 +864,8 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT 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).""; @@ -826,6 +873,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''.price($line->price_min).''; print ''.price($line->price_min_ttc).''; print ''.$line->price_label.''; + print ''.price($line->remise_percent).''; // User print ''; print $userstatic->getNomUrl(-1);