2
0
forked from Wavyzz/dolibarr

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

This commit is contained in:
Laurent Destailleur
2024-05-03 15:34:44 +02:00
3 changed files with 73 additions and 4 deletions

View File

@@ -316,3 +316,5 @@ DELETE FROM llx_c_action_trigger WHERE code = 'BILLREC_AUTOCREATEBILL';
-- element_element, see https://github.com/Dolibarr/dolibarr/pull/29329 -- element_element, see https://github.com/Dolibarr/dolibarr/pull/29329
ALTER TABLE element_element ADD COLUMN relationtype varchar(64) DEFAULT NULL AFTER targettype; ALTER TABLE element_element ADD COLUMN relationtype varchar(64) DEFAULT NULL AFTER targettype;
ALTER TABLE llx_expedition ADD COLUMN signed_status smallint DEFAULT 0 AFTER billed;

View File

@@ -44,7 +44,7 @@ create table llx_expedition
tracking_number varchar(50), tracking_number varchar(50),
fk_statut smallint DEFAULT 0, -- 0 = draft, 1 = validated, 2 = billed or closed depending on WORKFLOW_BILL_ON_SHIPMENT option fk_statut smallint DEFAULT 0, -- 0 = draft, 1 = validated, 2 = billed or closed depending on WORKFLOW_BILL_ON_SHIPMENT option
billed smallint DEFAULT 0, billed smallint DEFAULT 0,
signed_status smallint DEFAULT 0, --0 = not signed, 1 = signed
height float, -- height height float, -- height
width float, -- with width float, -- with
size_units integer, -- unit of all sizes (height, width, depth) size_units integer, -- unit of all sizes (height, width, depth)

View File

@@ -6,6 +6,7 @@
* Copyright (C) 2021 Frédéric France <frederic.france@free.fr> * Copyright (C) 2021 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr> * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com> * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Vincent de Grandpré <vincent@de-grandpre.quebec>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -181,7 +182,7 @@ $oneoptionset = (GETPOST('standard', 'alpha') || GETPOST('restore_thirdparties_l
|| GETPOST('clean_perm_table', 'alpha') || GETPOST('clean_perm_table', 'alpha')
|| GETPOST('force_disable_of_modules_not_found', 'alpha') || GETPOST('force_disable_of_modules_not_found', 'alpha')
|| GETPOST('force_utf8_on_tables', 'alpha') || GETPOST('force_utf8mb4_on_tables', 'alpha') || GETPOST('force_collation_from_conf_on_tables', 'alpha') || GETPOST('force_utf8_on_tables', 'alpha') || GETPOST('force_utf8mb4_on_tables', 'alpha') || GETPOST('force_collation_from_conf_on_tables', 'alpha')
|| GETPOST('rebuild_sequences', 'alpha')); || GETPOST('rebuild_sequences', 'alpha') || GETPOST('recalculateinvoicetotal', 'alpha'));
if ($ok && $oneoptionset) { if ($ok && $oneoptionset) {
// Show wait message // Show wait message
@@ -1648,10 +1649,76 @@ if ($ok && GETPOST('repair_supplier_order_duplicate_ref')) {
} }
} }
// Repair llx_invoice to calculate totals from line items
// WARNING : The process can be long on production environments due to restrictions.
// consider raising php_max_execution time if failing to execute completely.
if ($ok && GETPOST('recalculateinvoicetotal') == 'confirmed') {
$err = 0;
$db->begin();
$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);
print "We found ".$num." factures qualified that will have their total recalculated because they are at zero and line items not at zero\n";
dol_syslog("We found ".$num." factures qualified that will have their total recalculated because they are at zero and line items not at zero");
if ($num) {
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql_calculs = "
SELECT
SUM(fd.total_ht) as 'total_ht',
SUM(fd.total_tva) as 'total_tva',
SUM(fd.total_localtax1) as 'localtax1',
SUM(fd.total_localtax2) as 'localtax2',
SUM(fd.total_ttc) as 'total_ttc'
FROM
".MAIN_DB_PREFIX."facturedet fd
WHERE
fd.fk_facture = $obj->rowid";
$ressql_calculs = $db->query($sql_calculs);
while ($obj_calcul = $db->fetch_object($ressql_calculs)) {
$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)."
WHERE
rowid = $obj->rowid";
$db->query($sql_maj);
}
$i++;
}
} else {
print "Pas de factures à traiter\n";
}
} else {
dol_print_error($db);
dol_syslog("calculate_total_and_taxes.php: Error");
$err++;
}
if ($err == 0) {
$db->commit();
} else {
$db->rollback();
}
}
print '</table>'; print '</table>';
if (empty($actiondone)) { if (empty($actiondone)) {
print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>'; print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>';
} }