From f3a630fd3090a701a344b7ccee62e243074f9d72 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 May 2022 05:08:54 +0200 Subject: [PATCH 1/2] Clean code --- htdocs/install/mysql/tables/llx_product.sql | 4 +- .../mysql/tables/llx_product_price.sql | 4 +- htdocs/langs/fr_FR/main.lang | 2 +- htdocs/product/price.php | 65 ++++++++++++++----- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 4aad3393137..809ef5fbd65 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -40,8 +40,8 @@ create table llx_product customcode varchar(32), -- Optionnal custom code fk_country integer DEFAULT NULL, -- Optionnal id of original country fk_state integer DEFAULT NULL, -- Optionnal id of original state/province - price double(24,8) DEFAULT 0, - price_ttc double(24,8) DEFAULT 0, + price double(24,8) DEFAULT 0, -- price without tax + price_ttc double(24,8) DEFAULT 0, -- price inc vat (but not localtax1 nor localtax2) price_min double(24,8) DEFAULT 0, price_min_ttc double(24,8) DEFAULT 0, price_base_type varchar(3) DEFAULT 'HT', diff --git a/htdocs/install/mysql/tables/llx_product_price.sql b/htdocs/install/mysql/tables/llx_product_price.sql index ff862e427e0..690476e17b7 100644 --- a/htdocs/install/mysql/tables/llx_product_price.sql +++ b/htdocs/install/mysql/tables/llx_product_price.sql @@ -29,8 +29,8 @@ create table llx_product_price fk_product integer NOT NULL, date_price datetime NOT NULL, price_level smallint NULL DEFAULT 1, - price double(24,8) DEFAULT NULL, - price_ttc double(24,8) DEFAULT NULL, + price double(24,8) DEFAULT NULL, -- price without tax + price_ttc double(24,8) DEFAULT NULL, -- price inc vat (but not localtax1 nor localtax2) price_min double(24,8) default NULL, price_min_ttc double(24,8) default NULL, price_base_type varchar(3) DEFAULT 'HT', diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 448cc597a48..3b427a05341 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -415,7 +415,7 @@ TotalLT2IN=Total SGST HT=HT TTC=TTC INCVATONLY=TVA incluse -INCT=TTC +INCT=TVA+Taxes locales incluses VAT=TVA VATIN=IGST VATs=TVA diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 674b0a19cab..226ace2df9d 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -1482,6 +1482,7 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul } $sql .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC"; // $sql .= $db->plimit(); + //print $sql; $result = $db->query($sql); if ($result) { @@ -1520,8 +1521,9 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul print_barre_liste($langs->trans("PriceByCustomerLog"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, $num, 'title_accountancy.png'); } - print '
'; - print ''; + print ''."\n"; + print '
'."\n"; + print '
'."\n"; print ''; print ''; @@ -1539,6 +1541,9 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul } print ''; print ''; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { + print ''; + } if (!empty($conf->dynamicprices->enabled)) { print ''; } @@ -1605,6 +1610,24 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul print ""; } + // Line for default price + if ($object->price_base_type == 'HT') { + $pu = $objp->price; + } else { + $pu = $objp->price_ttc; + } + + // Local tax was not saved into table llx_product on old version. So we will use value linked to VAT code. + $localtaxarray = getLocalTaxesFromRate($objp->tva_tx.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), 0, $mysoc, $mysoc); + // Define part of HT, VAT, TTC + $resultarray = calcul_price_total(1, $pu, 0, $objp->tva_tx, 1, 1, 0, $objp->price_base_type, $objp->recuperableonly, $object->type, $mysoc, $localtaxarray); + // Calcul du total ht sans remise + $total_ht = $resultarray[0]; + $total_vat = $resultarray[1]; + $total_localtax1 = $resultarray[9]; + $total_localtax2 = $resultarray[10]; + $total_ttc = $resultarray[2]; + // Price if (!empty($objp->fk_price_expression) && !empty($conf->dynamicprices->enabled)) { $price_expression = new PriceExpression($db); @@ -1612,32 +1635,46 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul $title = $price_expression->title; print ''; print ''; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { + print ''; + } print '"; } else { + // Price HT print '"; + // Price TTC print '"; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { + print ''; + } if (!empty($conf->dynamicprices->enabled)) { //Only if module is enabled print ''; } } + // Price min print ''; + // Price min inc tax print ''; @@ -2040,12 +2077,15 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print ''; print ''; - print '
'; - print '
'.$langs->trans("AppliedPricesFrom").''.$langs->trans("HT").''.$langs->trans("TTC").''.$langs->trans("INCT").''.$langs->trans("PriceExpressionSelected").''.$title."'; if (empty($objp->price_by_qty)) { print price($objp->price); } print "'; if (empty($objp->price_by_qty)) { - print price($objp->price_ttc); + $price_ttc = $objp->price_ttc; + print price($price_ttc); } print "'; + print $resultarray[2]; + print ''; if (empty($objp->price_by_qty)) { print price($objp->price_min); } print ''; if (empty($objp->price_by_qty)) { - print price($objp->price_min_ttc); + $price_min_ttc = $objp->price_min_ttc; + print price($price_min_ttc); } print '
'; + print ''."\n"; + print '
'."\n"; + print '
'."\n"; if (count($prodcustprice->lines) > 0 || $search_soc) { $colspan = 9; - //if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") $colspan++; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { + $colspan++; + } print ''; print ''; @@ -2065,13 +2105,10 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print ''; print ''; print ''; + print ''; if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { - //print ''; print ''; - } else { - print ''; } - print ''; print ''; print ''; @@ -2085,7 +2122,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { $pu = $object->price_ttc; } - // Local tax is not saved into table of product. We use value linked to VAT code. + // Local tax was not saved into table llx_product on old version. So we will use value linked to VAT code. $localtaxarray = getLocalTaxesFromRate($object->tva_tx.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), 0, $mysoc, $mysoc); // Define part of HT, VAT, TTC $resultarray = calcul_price_total(1, $pu, 0, $object->tva_tx, 1, 1, 0, $object->price_base_type, $object->recuperableonly, $object->type, $mysoc, $localtaxarray); @@ -2123,14 +2160,12 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print '"; + print '"; if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { //print '"; print ''; - } else { - print '"; } - print ''; print ''; print '
'.$langs->trans("PriceBase").''.$langs->trans("DefaultTaxRate").''.$langs->trans("HT").''.$langs->trans("TTC").'' . $langs->trans("INCVATONLY") . ''.$langs->trans("INCT").''.$langs->trans("TTC").''.$langs->trans("MinPrice").' '.$langs->trans("HT").''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''.$langs->trans("ChangedBy").''.price($object->price)."'.price($object->price_ttc)."' . price($object->price_ttc) . "'.price($resultarray[2]).''.price($object->price_ttc)."'.price($object->price_min).''.price($object->price_min_ttc).''; From 203c4e808282cdd11f0813f14cce0c5c29fe91a4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 May 2022 11:48:15 +0200 Subject: [PATCH 2/2] Fix bad test --- htdocs/product/price.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 226ace2df9d..565240743d7 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -1611,7 +1611,7 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul } // Line for default price - if ($object->price_base_type == 'HT') { + if ($objp->price_base_type == 'HT') { $pu = $objp->price; } else { $pu = $objp->price_ttc;