2
0
forked from Wavyzz/dolibarr

Merge branch '15.0' of git@github.com:Dolibarr/dolibarr.git into 16.0

This commit is contained in:
Laurent Destailleur
2023-03-19 19:05:47 +01:00
6 changed files with 49 additions and 22 deletions

View File

@@ -5969,30 +5969,30 @@ function isOnlyOneLocalTax($local)
/**
* Get values of localtaxes (1 or 2) for company country for the common vat with the highest value
*
* @param int $local LocalTax to get
* @return number Values of localtax
* @param int $local LocalTax to get
* @return string Values of localtax (Can be '20', '-19:-15:-9')
*/
function get_localtax_by_third($local)
{
global $db, $mysoc;
$sql = "SELECT t.localtax1, t.localtax2 ";
$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 = " 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 .= " AND t.localtax".$local."_type <> '0'";
$sql .= " ORDER BY t.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;
} else {
return 'Error';
}
return 0;
return '0';
}
@@ -6101,7 +6101,7 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisi
}
$sql .= ", ".MAIN_DB_PREFIX."c_country as c";
if ($mysoc->country_code == 'ES') {
if (!empty($mysoc) && $mysoc->country_code == 'ES') {
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($buyer->country_code)."'"; // local tax in spain use the buyer country ??
} else {
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape(empty($seller->country_code) ? $mysoc->country_code : $seller->country_code)."'";