2
0
forked from Wavyzz/dolibarr

Fix the localtax were not saved on price when no code was set

This commit is contained in:
Laurent Destailleur
2022-01-20 18:09:30 +01:00
parent de30b68f9e
commit b2f6de06d5
4 changed files with 154 additions and 34 deletions

View File

@@ -1897,7 +1897,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
if ($object->element == 'product') { if ($object->element == 'product') {
$width = 80; $width = 80;
$cssclass = 'photoref'; $cssclass = 'photowithmargin photoref';
$showimage = $object->is_photo_available($conf->product->multidir_output[$entity]); $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
$maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5); $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
if ($conf->browser->layout == 'phone') { if ($conf->browser->layout == 'phone') {

View File

@@ -143,10 +143,11 @@ if (empty($reshook)) {
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'"; $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
$sql .= " AND t.code ='".$db->escape($vatratecode)."'"; $sql .= " AND t.code = '".$db->escape($vatratecode)."'";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly; $npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1; $localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2; $localtax2 = $obj->localtax2;
@@ -154,6 +155,25 @@ if (empty($reshook)) {
$localtax2_type = $obj->localtax2_type; $localtax2_type = $obj->localtax2_type;
} }
} }
} else {
// Get record with empty code
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
$sql .= " AND t.code = ''";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type;
}
}
}
$object->default_vat_code = $vatratecode; $object->default_vat_code = $vatratecode;
$object->tva_tx = $tva_tx; $object->tva_tx = $tva_tx;
@@ -258,12 +278,38 @@ if (empty($reshook)) {
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly; $npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1; $localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2; $localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type; $localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type; $localtax2_type = $obj->localtax2_type;
} }
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
if (in_array($mysoc->country_code, array('ES'))) {
$localtax1 = get_localtax($tva_tx, 1);
$localtax2 = get_localtax($tva_tx, 2);
}
}
} else {
// Get record with empty code
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
$sql .= " AND t.code = ''";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type;
}
}
} }
$pricestoupdate[$i] = array( $pricestoupdate[$i] = array(
@@ -311,19 +357,40 @@ if (empty($reshook)) {
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly; $npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1; $localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2; $localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type; $localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type; $localtax2_type = $obj->localtax2_type;
}
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
if (in_array($mysoc->country_code, array('ES'))) { if (in_array($mysoc->country_code, array('ES'))) {
$localtax1 = get_localtax($tva_tx, 1); $localtax1 = get_localtax($tva_tx, 1);
$localtax2 = get_localtax($tva_tx, 2); $localtax2 = get_localtax($tva_tx, 2);
} }
} }
} else {
// Get record with empty code
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
$sql .= " AND t.code = ''";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type;
} }
}
}
$pricestoupdate[0] = array( $pricestoupdate[0] = array(
'price' => $newprice, 'price' => $newprice,
'price_min' => $newprice_min, 'price_min' => $newprice_min,
@@ -534,12 +601,38 @@ if (empty($reshook)) {
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly; $npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1; $localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2; $localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type; $localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type; $localtax2_type = $obj->localtax2_type;
} }
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
if (in_array($mysoc->country_code, array('ES'))) {
$localtax1 = get_localtax($tva_tx, 1);
$localtax2 = get_localtax($tva_tx, 2);
}
}
} else {
// Get record with empty code
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
$sql .= " AND t.code = ''";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type;
}
}
} }
$prodcustprice->default_vat_code = $vatratecode; $prodcustprice->default_vat_code = $vatratecode;
@@ -627,12 +720,38 @@ if (empty($reshook)) {
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly; $npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1; $localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2; $localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type; $localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type; $localtax2_type = $obj->localtax2_type;
} }
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
if (in_array($mysoc->country_code, array('ES'))) {
$localtax1 = get_localtax($tva_tx, 1);
$localtax2 = get_localtax($tva_tx, 2);
}
}
} else {
// Get record with empty code
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
$sql .= " AND t.code = ''";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$npr = $obj->recuperableonly;
$localtax1 = $obj->localtax1;
$localtax2 = $obj->localtax2;
$localtax1_type = $obj->localtax1_type;
$localtax2_type = $obj->localtax2_type;
}
}
} }
$prodcustprice->default_vat_code = $vatratecode; $prodcustprice->default_vat_code = $vatratecode;
@@ -829,22 +948,23 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_
} }
// TVA // TVA
print '<!-- Default VAT Rate -->';
print '<tr><td class="titlefieldcreate">'.$langs->trans("DefaultTaxRate").'</td><td>'; print '<tr><td class="titlefieldcreate">'.$langs->trans("DefaultTaxRate").'</td><td>';
$positiverates = ''; $positiverates = '';
if (price2num($object->tva_tx)) { if (price2num($object->tva_tx)) {
$positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->tva_tx);
} }
if (price2num($object->localtax1_type)) { if (price2num($object->localtax1_type)) {
$positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->localtax1_tx);
} }
if (price2num($object->localtax2_type)) { if (price2num($object->localtax2_type)) {
$positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->localtax2_tx);
} }
if (empty($positiverates)) { if (empty($positiverates)) {
$positiverates = '0'; $positiverates = '0';
} }
echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr); print vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), true, $object->tva_npr, 1);
/* /*
if ($object->default_vat_code) if ($object->default_vat_code)
{ {

View File

@@ -4558,7 +4558,7 @@ label.radioprivate {
/* margin-bottom: 2px; /* margin-bottom: 2px;
margin-top: 2px; */ margin-top: 2px; */
} }
div.divphotoref > a > .photowithmargin { /* Margin right for photo not inside a div.photoref frame only */ div.divphotoref > img.photowithmargin, div.divphotoref > a > .photowithmargin { /* Margin right for photo not inside a div.photoref frame only */
margin-right: 15px; margin-right: 15px;
} }
.photowithborder { .photowithborder {

View File

@@ -4492,7 +4492,7 @@ label.radioprivate {
/* margin-bottom: 2px; /* margin-bottom: 2px;
margin-top: 2px; */ margin-top: 2px; */
} }
div.divphotoref > a > .photowithmargin { /* Margin right for photo not inside a div.photoref frame only */ div.divphotoref > img.photowithmargin, div.divphotoref > a > .photowithmargin { /* Margin right for photo not inside a div.photoref frame only */
margin-right: 15px; margin-right: 15px;
} }
.photowithborder { .photowithborder {