Clean code

This commit is contained in:
Laurent Destailleur 2022-05-06 05:08:54 +02:00
parent 82ab41a7f3
commit 583343a171
3 changed files with 54 additions and 19 deletions

View File

@ -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',

View File

@ -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',

View File

@ -1602,6 +1602,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) {
@ -1640,8 +1641,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 '<div class="div-table-responsive">';
print '<table class="liste centpercent">';
print '<!-- List of log prices -->'."\n";
print '<div class="div-table-responsive">'."\n";
print '<table class="liste centpercent">'."\n";
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
@ -1659,6 +1661,9 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul
}
print '<td class="right">'.$langs->trans("HT").'</td>';
print '<td class="right">'.$langs->trans("TTC").'</td>';
if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
print '<td class="right">'.$langs->trans("INCT").'</td>';
}
if (!empty($conf->dynamicprices->enabled)) {
print '<td class="right">'.$langs->trans("PriceExpressionSelected").'</td>';
}
@ -1725,6 +1730,24 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul
print "</td>";
}
// 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);
@ -1732,32 +1755,46 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul
$title = $price_expression->title;
print '<td class="right"></td>';
print '<td class="right"></td>';
if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
print '<td class="right"></td>';
}
print '<td class="right">'.$title."</td>";
} else {
// Price HT
print '<td class="right">';
if (empty($objp->price_by_qty)) {
print price($objp->price);
}
print "</td>";
// Price TTC
print '<td class="right">';
if (empty($objp->price_by_qty)) {
print price($objp->price_ttc);
$price_ttc = $objp->price_ttc;
print price($price_ttc);
}
print "</td>";
if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
print '<td class="right">';
print $resultarray[2];
print '</td>';
}
if (!empty($conf->dynamicprices->enabled)) { //Only if module is enabled
print '<td class="right"></td>';
}
}
// Price min
print '<td class="right">';
if (empty($objp->price_by_qty)) {
print price($objp->price_min);
}
print '</td>';
// Price min inc tax
print '<td class="right">';
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 '</td>';
@ -2154,12 +2191,15 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<div class="div-table-responsive-no-min">';
print '<table class="liste centpercent">';
print '<!-- List of prices per customer -->'."\n";
print '<div class="div-table-responsive-no-min">'."\n";
print '<table class="liste centpercent">'."\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 '<tr class="liste_titre">';
print '<td class="liste_titre"><input type="text" class="flat" name="search_soc" value="'.$search_soc.'" size="20"></td>';
@ -2179,13 +2219,10 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
print '<td class="center">'.$langs->trans("PriceBase").'</td>';
print '<td class="right">'.$langs->trans("DefaultTaxRate").'</td>';
print '<td class="right">'.$langs->trans("HT").'</td>';
print '<td class="right">'.$langs->trans("TTC").'</td>';
if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
//print '<td class="right">' . $langs->trans("INCVATONLY") . '</td>';
print '<td class="right">'.$langs->trans("INCT").'</td>';
} else {
print '<td class="right">'.$langs->trans("TTC").'</td>';
}
print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
@ -2199,7 +2236,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);
@ -2237,14 +2274,12 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
print '<td class="right">'.price($object->price)."</td>";
print '<td class="right">'.price($object->price_ttc)."</td>";
if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
//print '<td class="right">' . price($object->price_ttc) . "</td>";
print '<td class="right">'.price($resultarray[2]).'</td>';
} else {
print '<td class="right">'.price($object->price_ttc)."</td>";
}
print '<td class="right">'.price($object->price_min).'</td>';
print '<td class="right">'.price($object->price_min_ttc).'</td>';
print '<td class="right">';