From 288663be3682dbd9bdab5600ce45338a4b082abc Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Wed, 2 Mar 2022 10:16:48 +0100 Subject: [PATCH] Facture mass validation: sort by date to avoid conflicts --- htdocs/core/actions_massactions.inc.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 5a4ec3bf02f..4a5fe519acb 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1209,6 +1209,26 @@ if (!$error && $massaction == 'validate' && $permissiontoadd) { setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors'); $error++; } + if ($objecttmp->element == 'facture') { + if (!empty($toselect) && !empty($conf->global->INVOICE_CHECK_POSTERIOR_DATE)) { + // order $toselect by date + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture'; + $sql .= ' WHERE rowid IN ('.$db->escape(implode(', ', $toselect)).')'; + $sql .= ' ORDER BY datef'; + + $resql = $db->query($sql); + if ($resql) { + $toselectnew = []; + while ( !empty($arr = $db->fetch_row($resql))) { + $toselectnew[] = $arr[0]; + } + $toselect = (empty($toselectnew)) ? $toselect : $toselectnew; + } else { + dol_print_error($db); + $error++; + } + } + } if (!$error) { $db->begin();