Repair recalculateinvoicetotal (#35381)
* PHPStan > Update baseline * FIX#33963 - Enabling foreign key field to allow mandatory parameter saving * Added author to copyright * Correction calcul du total des taxes * Travis * code format * espaces superflus * bis * Update repair.php * Update repair.php * PHPStan > Update baseline * set paid = 1 when total_ttc equals sum of payments * current upstream file --------- Co-authored-by: Dolibot <dolibarr-bot@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
parent
8037974241
commit
2d76f12dae
2 changed files with 25 additions and 12 deletions
|
|
@ -19618,4 +19618,4 @@ parameters:
|
|||
message: '#^Loose comparison using \=\= between ''user'' and ''user'' will always evaluate to true\.$#'
|
||||
identifier: equal.alwaysTrue
|
||||
count: 1
|
||||
path: ../../../scripts/user/migrate_picture_path.php
|
||||
path: ../../../scripts/user/migrate_picture_path.php
|
||||
|
|
@ -1987,12 +1987,15 @@ if ($ok && GETPOST('repair_supplier_order_duplicate_ref')) {
|
|||
if ($ok && GETPOST('recalculateinvoicetotal') == 'confirmed') {
|
||||
$err = 0;
|
||||
$db->begin();
|
||||
$sql = "SELECT f.rowid, SUM(fd.total_ht) as total_ht";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture f";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet fd ON fd.fk_facture = f.rowid";
|
||||
$sql .= " WHERE f.total_ht = 0";
|
||||
$sql .= " GROUP BY fd.fk_facture HAVING SUM(fd.total_ht) <> 0";
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
f.rowid,
|
||||
SUM(fd.total_ht) as total_ht
|
||||
FROM ".MAIN_DB_PREFIX."facture f
|
||||
LEFT JOIN ".MAIN_DB_PREFIX."facturedet fd
|
||||
ON fd.fk_facture = f.rowid
|
||||
WHERE f.total_ht = 0
|
||||
GROUP BY fd.fk_facture HAVING SUM(fd.total_ht) <> 0";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
|
|
@ -2016,14 +2019,24 @@ if ($ok && GETPOST('recalculateinvoicetotal') == 'confirmed') {
|
|||
fd.fk_facture = $obj->rowid";
|
||||
$ressql_calculs = $db->query($sql_calculs);
|
||||
while ($obj_calcul = $db->fetch_object($ressql_calculs)) {
|
||||
// Calcul de la somme des paiements reçus
|
||||
$sql_paiements = "SELECT SUM(amount) as somme from ".MAIN_DB_PREFIX."paiement_facture WHERE fk_facture = $obj->rowid";
|
||||
$montantPaiements = $db->fetch_object($db->query($sql_paiements))->somme;
|
||||
$totHt= ($obj_calcul->total_ht ? price2num($obj_calcul->total_ht, 'MT') : 0);
|
||||
$totTva = ($obj_calcul->total_tva ? price2num($obj_calcul->total_tva, 'MT') : 0);
|
||||
$totLocal1 = ($obj_calcul->localtax1 ? price2num($obj_calcul->localtax1, 'MT') : 0);
|
||||
$totLocal2 = ($obj_calcul->localtax2 ? price2num($obj_calcul->localtax2, 'MT') : 0);
|
||||
$totTtc = $totHt + $totTva + $totLocal1 + $totLocal2;
|
||||
$sql_maj = "
|
||||
UPDATE ".MAIN_DB_PREFIX."facture
|
||||
SET
|
||||
total_ht = ".($obj_calcul->total_ht ? price2num($obj_calcul->total_ht, 'MT') : 0).",
|
||||
total_tva = ".($obj_calcul->total_tva ? price2num($obj_calcul->total_tva, 'MT') : 0).",
|
||||
localtax1 = ".($obj_calcul->localtax1 ? price2num($obj_calcul->localtax1, 'MT') : 0).",
|
||||
localtax2 = ".($obj_calcul->localtax2 ? price2num($obj_calcul->localtax2, 'MT') : 0).",
|
||||
total_ttc = ".($obj_calcul->total_ttc ? price2num($obj_calcul->total_ttc, 'MT') : 0)."
|
||||
total_ht = $totHt,
|
||||
total_tva = $totTva,
|
||||
localtax1 = $totLocal1,
|
||||
localtax2 = $totLocal2,
|
||||
total_ttc = $totTtc,
|
||||
fk_statut = ".($totTtc == price2num($montantPaiements, 'MT') ? 2 : 1 ).",
|
||||
paid = ".($totTtc == price2num($montantPaiements, 'MT') ? 1 : 0 )."
|
||||
WHERE
|
||||
rowid = $obj->rowid";
|
||||
$db->query($sql_maj);
|
||||
|
|
|
|||
Loading…
Reference in a new issue