Merge pull request #24070 from Daviid-P/ignore_localtaxes_if_localtax_type_zero

Ignore localtaxes if localtax1_type or localtax2_type is 0
This commit is contained in:
Laurent Destailleur 2023-03-18 10:48:23 +01:00 committed by GitHub
commit b81cb7e963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5688,21 +5688,20 @@ function isOnlyOneLocalTax($local)
function get_localtax_by_third($local)
{
global $db, $mysoc;
$sql = "SELECT t.localtax1, t.localtax2 ";
$sql = " SELECT t.localtax".$local." as localtax";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays";
$sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND t.active = 1 AND t.taux=(";
$sql .= " SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays";
$sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND tt.active = 1";
$sql .= " )";
$sql .= " ) ";
$sql .= " AND t.localtax".$local."_type > 0";
$sql .= " ORDER BY rowid DESC";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($local == 1) {
return $obj->localtax1;
} elseif ($local == 2) {
return $obj->localtax2;
}
return $obj->localtax;
}
return 0;