From 5fed6de5b8a7697432c46dfe92b077ef532a7f16 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Dec 2021 22:53:30 +0100 Subject: [PATCH] Fix feature to close record in accounting --- .../accountancy/class/bookkeeping.class.php | 2 +- htdocs/accountancy/closure/index.php | 64 +++++++++---------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 9cda04f6155..42fb42b89fa 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1013,7 +1013,7 @@ class BookKeeping extends CommonObject } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') { $sqlwhere[] = $key.'\''.$this->db->escape($value).'\''; } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { - $sqlwhere[] = $key.'='.$value; + $sqlwhere[] = $key.'='.((int) $value); } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') { $sqlwhere[] = $key.' LIKE \''.$this->db->escape($value).'%\''; } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') { diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index fdcc6f54ab3..6b578bcab71 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -31,7 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; // Load translation files required by the page $langs->loadLangs(array("compta", "bills", "other", "accountancy")); -$socid = GETPOST('socid', 'int'); +$validatemonth = GETPOST('validatemonth', 'int'); +$validateyear = GETPOST('validateyear', 'int'); $action = GETPOST('action', 'aZ09'); @@ -68,52 +69,47 @@ if (empty($user->rights->accounting->fiscalyear->write)) { } + /* * Actions */ +$now = dol_now(); + if ($action == 'validate_movements_confirm' && !empty($user->rights->accounting->fiscalyear->write)) { - $result = $object->fetchAll(); + $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); + $date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - // Specify as export : update field date_validated on selected month/year - $error = 0; - $db->begin(); + $error = 0; - $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); - $date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); + $db->begin(); - if (is_array($object->lines)) { - foreach ($object->lines as $movement) { - $now = dol_now(); + // Specify as export : update field date_validated on selected month/year + $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " SET date_validated = '".$db->idate($now)."'"; + $sql .= " WHERE entity = " . ((int) $conf->entity); + $sql .= " AND doc_date >= '" . $db->idate($date_start) . "'"; + $sql .= " AND doc_date <= '" . $db->idate($date_end) . "'"; + $sql .= " AND date_validated IS NULL"; - $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping"; - $sql .= " SET date_validated = '".$db->idate($now)."'"; - $sql .= " WHERE rowid = ".((int) $movement->id); - $sql .= " AND doc_date >= '" . $db->idate($date_start) . "'"; - $sql .= " AND doc_date <= '" . $db->idate($date_end) . "'"; + dol_syslog("/accountancy/closure/index.php action=validate_movement_confirm -> Set movements as validated", LOG_DEBUG); + $result = $db->query($sql); + if (!$result) { + $error++; + } - dol_syslog("/accountancy/closure/index.php :: Function validate_movement_confirm Specify movements as validated", LOG_DEBUG); - $result = $db->query($sql); - if (!$result) { - $error++; - break; - } - } - } + if (!$error) { + $db->commit(); + + setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs'); - if (!$error) { - $db->commit(); - setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs'); - } else { - $error++; - $db->rollback(); - setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors'); - } header("Location: ".$_SERVER['PHP_SELF']."?year=".$year_start); exit; + } else { + $db->rollback(); + + setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors'); + $action = ''; } }