mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-03 23:52:24 +01:00
PERF Reduce number of SQL call to get local tax.
This commit is contained in:
@@ -10577,9 +10577,10 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((empty($exclude) || !in_array('objectamount', $exclude)) && (empty($include) || in_array('objectamount', $include))) {
|
if ((empty($exclude) || !in_array('objectamount', $exclude)) && (empty($include) || in_array('objectamount', $include))) {
|
||||||
'@phan-var-force Facture|FactureRec $object';
|
'@phan-var-force Facture|FactureRec $object';
|
||||||
/** @var Facture|FactureRec|null $object */
|
/** @var Propal|Commande|Facture|FactureRec|null $object */
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/lib/functionsnumtoword.lib.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/functionsnumtoword.lib.php';
|
||||||
|
|
||||||
$substitutionarray['__DATE_YMD__'] = is_object($object) ? (isset($object->date) ? dol_print_date($object->date, 'day', false, $outputlangs) : null) : '';
|
$substitutionarray['__DATE_YMD__'] = is_object($object) ? (isset($object->date) ? dol_print_date($object->date, 'day', false, $outputlangs) : null) : '';
|
||||||
@@ -10606,10 +10607,19 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
|
|||||||
$substitutionarray['__AMOUNT_VAT_TEXT__'] = is_object($object) ? (isset($object->total_vat) ? dol_convertToWord($object->total_vat, $outputlangs, '', true) : dol_convertToWord($object->total_tva, $outputlangs, '', true)) : '';
|
$substitutionarray['__AMOUNT_VAT_TEXT__'] = is_object($object) ? (isset($object->total_vat) ? dol_convertToWord($object->total_vat, $outputlangs, '', true) : dol_convertToWord($object->total_tva, $outputlangs, '', true)) : '';
|
||||||
$substitutionarray['__AMOUNT_VAT_TEXTCURRENCY__'] = is_object($object) ? (isset($object->total_vat) ? dol_convertToWord($object->total_vat, $outputlangs, $conf->currency, true) : dol_convertToWord($object->total_tva, $outputlangs, $conf->currency, true)) : '';
|
$substitutionarray['__AMOUNT_VAT_TEXTCURRENCY__'] = is_object($object) ? (isset($object->total_vat) ? dol_convertToWord($object->total_vat, $outputlangs, $conf->currency, true) : dol_convertToWord($object->total_tva, $outputlangs, $conf->currency, true)) : '';
|
||||||
|
|
||||||
if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
|
$mysocuselocaltax1 = false;
|
||||||
|
$mysocuselocaltax2 = false;
|
||||||
|
if ($mysoc instanceof Societe && !empty(country_code)) {
|
||||||
|
$tmparray = $mysoc->useLocalTax(-1);
|
||||||
|
$mysocuselocaltax1 = $tmparray[1];
|
||||||
|
$mysocuselocaltax2 = $tmparray[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local taxes
|
||||||
|
if ($onlykey != 2 || $mysocuselocaltax1) {
|
||||||
$substitutionarray['__AMOUNT_TAX2__'] = is_object($object) ? $object->total_localtax1 : '';
|
$substitutionarray['__AMOUNT_TAX2__'] = is_object($object) ? $object->total_localtax1 : '';
|
||||||
}
|
}
|
||||||
if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
|
if ($onlykey != 2 || $mysocuselocaltax2) {
|
||||||
$substitutionarray['__AMOUNT_TAX3__'] = is_object($object) ? $object->total_localtax2 : '';
|
$substitutionarray['__AMOUNT_TAX3__'] = is_object($object) ? $object->total_localtax2 : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10618,10 +10628,10 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
|
|||||||
$substitutionarray['__AMOUNT_FORMATTED__'] = is_object($object) ? ($object->total_ttc ? price($object->total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
$substitutionarray['__AMOUNT_FORMATTED__'] = is_object($object) ? ($object->total_ttc ? price($object->total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
||||||
$substitutionarray['__AMOUNT_REMAIN_FORMATTED__'] = is_object($object) ? ($object->total_ttc ? price($object->total_ttc - $already_payed_all, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
$substitutionarray['__AMOUNT_REMAIN_FORMATTED__'] = is_object($object) ? ($object->total_ttc ? price($object->total_ttc - $already_payed_all, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
||||||
$substitutionarray['__AMOUNT_VAT_FORMATTED__'] = is_object($object) ? (isset($object->total_vat) ? price($object->total_vat, 0, $outputlangs, 0, -1, -1, $conf->currency) : ($object->total_tva ? price($object->total_tva, 0, $outputlangs, 0, -1, -1, $conf->currency) : null)) : '';
|
$substitutionarray['__AMOUNT_VAT_FORMATTED__'] = is_object($object) ? (isset($object->total_vat) ? price($object->total_vat, 0, $outputlangs, 0, -1, -1, $conf->currency) : ($object->total_tva ? price($object->total_tva, 0, $outputlangs, 0, -1, -1, $conf->currency) : null)) : '';
|
||||||
if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
|
if ($onlykey != 2 || $mysocuselocaltax1) {
|
||||||
$substitutionarray['__AMOUNT_TAX2_FORMATTED__'] = is_object($object) ? ($object->total_localtax1 ? price($object->total_localtax1, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
$substitutionarray['__AMOUNT_TAX2_FORMATTED__'] = is_object($object) ? ($object->total_localtax1 ? price($object->total_localtax1, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
||||||
}
|
}
|
||||||
if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
|
if ($onlykey != 2 || $mysocuselocaltax2) {
|
||||||
$substitutionarray['__AMOUNT_TAX3_FORMATTED__'] = is_object($object) ? ($object->total_localtax2 ? price($object->total_localtax2, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
$substitutionarray['__AMOUNT_TAX3_FORMATTED__'] = is_object($object) ? ($object->total_localtax2 ? price($object->total_localtax2, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) : '';
|
||||||
}
|
}
|
||||||
// Amount keys formatted in a currency (with the typo error for backward compatibility)
|
// Amount keys formatted in a currency (with the typo error for backward compatibility)
|
||||||
@@ -10630,10 +10640,10 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
|
|||||||
$substitutionarray['__AMOUNT_FORMATED__'] = $substitutionarray['__AMOUNT_FORMATTED__'];
|
$substitutionarray['__AMOUNT_FORMATED__'] = $substitutionarray['__AMOUNT_FORMATTED__'];
|
||||||
$substitutionarray['__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray['__AMOUNT_REMAIN_FORMATTED__'];
|
$substitutionarray['__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray['__AMOUNT_REMAIN_FORMATTED__'];
|
||||||
$substitutionarray['__AMOUNT_VAT_FORMATED__'] = $substitutionarray['__AMOUNT_VAT_FORMATTED__'];
|
$substitutionarray['__AMOUNT_VAT_FORMATED__'] = $substitutionarray['__AMOUNT_VAT_FORMATTED__'];
|
||||||
if ($mysoc instanceof Societe && $mysoc->useLocalTax(1)) {
|
if ($mysocuselocaltax1) {
|
||||||
$substitutionarray['__AMOUNT_TAX2_FORMATED__'] = $substitutionarray['__AMOUNT_TAX2_FORMATTED__'];
|
$substitutionarray['__AMOUNT_TAX2_FORMATED__'] = $substitutionarray['__AMOUNT_TAX2_FORMATTED__'];
|
||||||
}
|
}
|
||||||
if ($mysoc instanceof Societe && $mysoc->useLocalTax(2)) {
|
if ($mysoc->useLocalTax2) {
|
||||||
$substitutionarray['__AMOUNT_TAX3_FORMATED__'] = $substitutionarray['__AMOUNT_TAX3_FORMATTED__'];
|
$substitutionarray['__AMOUNT_TAX3_FORMATED__'] = $substitutionarray['__AMOUNT_TAX3_FORMATTED__'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4948,8 +4948,8 @@ class Societe extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
|
* Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
|
||||||
*
|
*
|
||||||
* @param int $localTaxNum To get info for only localtax1 or localtax2
|
* @param int<-1,2> $localTaxNum Use 1 or 2 to get info for only localtax1 or localtax2, 0 to get both a boolean using a OR, -1 to get array for each case.
|
||||||
* @return boolean true or false
|
* @return boolean|array<int,boolean> true or false or array of 2 booleans if $localTaxNum == -1
|
||||||
*/
|
*/
|
||||||
public function useLocalTax($localTaxNum = 0)
|
public function useLocalTax($localTaxNum = 0)
|
||||||
{
|
{
|
||||||
@@ -4958,7 +4958,7 @@ class Societe extends CommonObject
|
|||||||
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
|
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
|
||||||
$sql .= " AND t.active = 1";
|
$sql .= " AND t.active = 1";
|
||||||
$sql .= " AND t.entity IN (".getEntity('c_tva').")";
|
$sql .= " AND t.entity IN (".getEntity('c_tva').")";
|
||||||
if (empty($localTaxNum)) {
|
if (empty($localTaxNum) || $localTaxNum == -1) {
|
||||||
$sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
|
$sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
|
||||||
} elseif ($localTaxNum == 1) {
|
} elseif ($localTaxNum == 1) {
|
||||||
$sql .= " AND t.localtax1_type <> '0'";
|
$sql .= " AND t.localtax1_type <> '0'";
|
||||||
@@ -4968,7 +4968,15 @@ class Societe extends CommonObject
|
|||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
return ($this->db->num_rows($resql) > 0);
|
if ($localTaxNum == -1) {
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
if ($obj) {
|
||||||
|
return array(1 => ($obj->localtax1 ? true : false), 2 => ($obj->localtax2 ? true : false));
|
||||||
|
}
|
||||||
|
return array(1 => false, 2 => false);
|
||||||
|
} else {
|
||||||
|
return ($this->db->num_rows($resql) > 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user