From 373449900f353d8ea3d6ec6dd845a147cb260ff4 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 15 Sep 2022 05:21:22 +0200 Subject: [PATCH 01/14] FIX Accountancy - Review reconcile function (separate manuel & auto reconcile) --- htdocs/accountancy/bookkeeping/list.php | 101 +++- .../accountancy/bookkeeping/listbyaccount.php | 97 ++- htdocs/accountancy/class/lettering.class.php | 567 +++++++++++------- .../accountancy/journal/purchasesjournal.php | 2 +- htdocs/accountancy/journal/sellsjournal.php | 2 +- htdocs/langs/en_US/accountancy.lang | 9 +- 6 files changed, 485 insertions(+), 293 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 23d33acd3b7..8e2ac22520d 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -234,7 +234,7 @@ $param = ''; if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunlettering' && $massaction != 'predeletebookkeepingwriting') { +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunletteringauto' && $massaction != 'preunletteringmanual' && $massaction != 'predeletebookkeepingwriting') { $massaction = ''; } @@ -485,44 +485,61 @@ if (empty($reshook)) { $uploaddir = $conf->societe->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->rights->accounting->mouvements->supprimer) { + if (!$error && $action == 'deletebookkeepingwritingauto' && $confirm == "yes" && $user->rights->accounting->mouvements->supprimer) { + $db->begin(); + + if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) { + $lettering = new Lettering($db); + $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true); + if ($nb_lettering < 0) { + setEventMessages('', $lettering->errors, 'errors'); + $error++; + } + } + $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $object->fetch($toselectid); - if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) { - $result = $object->deleteMvtNum($object->piece_num); - if ($result > 0) { - $nbok++; - } else { + if (!$error) { + foreach ($toselect as $toselectid) { + $result = $object->fetch($toselectid); + if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) { + $result = $object->deleteMvtNum($object->piece_num); + if ($result > 0) { + $nbok++; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + break; + } + } elseif ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; break; } - } elseif ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - break; } } - // Message for elements well deleted - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); - } elseif ($nbok > 0) { - setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); - } elseif (!$error) { - setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs'); - } - if (!$error) { + $db->commit(); + + // Message for elements well deleted + if ($nbok > 1) { + setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); + } elseif ($nbok > 0) { + setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); + } else { + setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs'); + } + header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : '')); exit; + } else { + $db->rollback(); } } // others mass actions if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) { - if ($massaction == 'lettering') { + if ($massaction == 'letteringauto') { $lettering = new Lettering($db); $nb_lettering = $lettering->bookkeepingLetteringAll($toselect); if ($nb_lettering < 0) { @@ -543,7 +560,17 @@ if (empty($reshook)) { header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); exit(); } - } elseif ($action == 'unlettering' && $confirm == "yes") { + } elseif ($massaction == 'letteringmanual') { + $lettering = new Lettering($db); + $result = $lettering->updateLettering($toselect); + if ($result < 0) { + setEventMessages('', $lettering->errors, 'errors'); + } else { + setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); + exit(); + } + } elseif ($action == 'unletteringauto' && $confirm == "yes") { $lettering = new Lettering($db); $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true); if ($nb_lettering < 0) { @@ -564,6 +591,16 @@ if (empty($reshook)) { header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); exit(); } + } elseif ($action == 'unletteringmanual' && $confirm == "yes") { + $lettering = new Lettering($db); + $nb_lettering = $lettering->deleteLettering($toselect); + if ($result < 0) { + setEventMessages('', $lettering->errors, 'errors'); + } else { + setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); + exit(); + } } } } @@ -839,16 +876,16 @@ if ($limit > 0 && $limit != $conf->liste_limit) { // List of mass actions available $arrayofmassactions = array(); -/* if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) { - $arrayofmassactions['lettering'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('Lettering'); - $arrayofmassactions['preunlettering'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('Unlettering'); + $arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringAuto'); + $arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringAuto'); + $arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringManual'); + $arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringManual'); } -*/ if ($user->rights->accounting->mouvements->supprimer) { $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); } -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunlettering', 'predeletebookkeepingwriting'))) { +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunletteringauto', 'preunletteringmanual', 'predeletebookkeepingwriting'))) { $arrayofmassactions = array(); } $massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions); @@ -898,8 +935,10 @@ if (empty($reshook)) { print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); -if ($massaction == 'preunlettering') { - print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnlettering"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unlettering", null, '', 0, 200, 500, 1); +if ($massaction == 'preunletteringauto') { + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringAuto"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringauto", null, '', 0, 200, 500, 1); +} elseif ($massaction == 'preunletteringmanual') { + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringManual"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringmanual", null, '', 0, 200, 500, 1); } elseif ($massaction == 'predeletebookkeepingwriting') { print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1); } diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 4b5f0d9bad6..cbb827d7f04 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -208,7 +208,7 @@ if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunlettering' && $massaction != 'predeletebookkeepingwriting') { +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunletteringauto' && $massaction != 'preunletteringmanual' && $massaction != 'predeletebookkeepingwriting') { $massaction = ''; } @@ -401,43 +401,60 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->rights->accounting->mouvements->supprimer) { + $db->begin(); + + if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) { + $lettering = new Lettering($db); + $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true); + if ($nb_lettering < 0) { + setEventMessages('', $lettering->errors, 'errors'); + $error++; + } + } + $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $object->fetch($toselectid); - if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) { - $result = $object->deleteMvtNum($object->piece_num); - if ($result > 0) { - $nbok++; - } else { + if (!$error) { + foreach ($toselect as $toselectid) { + $result = $object->fetch($toselectid); + if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) { + $result = $object->deleteMvtNum($object->piece_num); + if ($result > 0) { + $nbok++; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + break; + } + } elseif ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; break; } - } elseif ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - break; } } - // Message for elements well deleted - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); - } elseif ($nbok > 0) { - setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); - } elseif (!$error) { - setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs'); - } - if (!$error) { + $db->commit(); + + // Message for elements well deleted + if ($nbok > 1) { + setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); + } elseif ($nbok > 0) { + setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); + } elseif (!$error) { + setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs'); + } + header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : '')); exit; + } else { + $db->rollback(); } } // others mass actions if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) { - if ($massaction == 'lettering') { + if ($massaction == 'letteringauto') { $lettering = new Lettering($db); $nb_lettering = $lettering->bookkeepingLetteringAll($toselect); if ($nb_lettering < 0) { @@ -458,7 +475,17 @@ if (empty($reshook)) { header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); exit(); } - } elseif ($action == 'unlettering' && $confirm == "yes") { + } elseif ($massaction == 'letteringmanual') { + $lettering = new Lettering($db); + $result = $lettering->updateLettering($toselect); + if ($result < 0) { + setEventMessages('', $lettering->errors, 'errors'); + } else { + setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); + exit(); + } + } elseif ($action == 'unletteringauto' && $confirm == "yes") { $lettering = new Lettering($db); $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true); if ($nb_lettering < 0) { @@ -479,6 +506,16 @@ if (empty($reshook)) { header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); exit(); } + } elseif ($action == 'unletteringmanual' && $confirm == "yes") { + $lettering = new Lettering($db); + $nb_lettering = $lettering->deleteLettering($toselect); + if ($result < 0) { + setEventMessages('', $lettering->errors, 'errors'); + } else { + setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param); + exit(); + } } } } @@ -579,13 +616,15 @@ print $formconfirm; // List of mass actions available $arrayofmassactions = array(); if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) { - $arrayofmassactions['lettering'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('Lettering'); - $arrayofmassactions['preunlettering'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('Unlettering'); + $arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringAuto'); + $arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringAuto'); + $arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringManual'); + $arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringManual'); } if ($user->rights->accounting->mouvements->supprimer) { $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); } -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunlettering', 'predeletebookkeepingwriting'))) { +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunletteringauto', 'preunletteringmanual', 'predeletebookkeepingwriting'))) { $arrayofmassactions = array(); } $massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions); @@ -625,8 +664,10 @@ if ($limit > 0 && $limit != $conf->liste_limit) { print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $result, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); -if ($massaction == 'preunlettering') { - print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnlettering"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unlettering", null, '', 0, 200, 500, 1); +if ($massaction == 'preunletteringauto') { + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringAuto"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringauto", null, '', 0, 200, 500, 1); +} elseif ($massaction == 'preunletteringmanual') { + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringManual"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringmanual", null, '', 0, 200, 500, 1); } elseif ($massaction == 'predeletebookkeepingwriting') { print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1); } diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 405a630942e..5f3d23a72eb 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -33,11 +33,52 @@ include_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"; */ class Lettering extends BookKeeping { - /** - * @var BookKeeping[] Bookkeeping cached - */ - public static $bookkeeping_cached = array(); - + public static $doc_type_infos = array( + 'customer_invoice' => array( + 'payment_table' => 'paiement', + 'payment_table_fk_bank' => 'fk_bank', + 'doc_payment_table' => 'paiement_facture', + 'doc_payment_table_fk_payment' => 'fk_paiement', + 'doc_payment_table_fk_doc' => 'fk_facture', + 'linked_info' => array( + array( + 'table' => 'paiement_facture', + 'fk_doc' => 'fk_facture', + 'fk_link' => 'fk_paiement', + 'prefix' => 'p', + ), + array( + 'table' => 'societe_remise_except', + 'fk_doc' => 'fk_facture_source', + 'fk_link' => 'fk_facture', + 'prefix' => 'a', + 'is_fk_link_is_also_fk_doc' => true, + ), + ), + ), + 'supplier_invoice' => array( + 'payment_table' => 'paiementfourn', + 'payment_table_fk_bank' => 'fk_bank', + 'doc_payment_table' => 'paiementfourn_facturefourn', + 'doc_payment_table_fk_payment' => 'fk_paiementfourn', + 'doc_payment_table_fk_doc' => 'fk_facturefourn', + 'linked_info' => array( + array( + 'table' => 'paiementfourn_facturefourn', + 'fk_doc' => 'fk_facturefourn', + 'fk_link' => 'fk_paiementfourn', + 'prefix' => 'p', + ), + array( + 'table' => 'societe_remise_except', + 'fk_doc' => 'fk_invoice_supplier_source', + 'fk_link' => 'fk_invoice_supplier', + 'prefix' => 'a', + 'is_fk_link_is_also_fk_doc' => true, + ), + ), + ), + ); /** * letteringThirdparty @@ -250,26 +291,17 @@ class Lettering extends BookKeeping $lettre = 'AAA'; $sql = "SELECT DISTINCT ab2.lettering_code"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping As ab"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url AS bu ON bu.fk_bank = ab.fk_doc"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url AS bu2 ON bu2.url_id = bu.url_id"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab2 ON ab2.fk_doc = bu2.fk_bank"; - $sql .= " WHERE ab.rowid IN (" . $this->db->sanitize(implode(',', $ids)) . ")"; - $sql .= " AND ab.doc_type = 'bank'"; - $sql .= " AND ab2.doc_type = 'bank'"; - $sql .= " AND bu.type = 'company'"; - $sql .= " AND bu2.type = 'company'"; - $sql .= " AND ab.subledger_account != ''"; - $sql .= " AND ab2.subledger_account != ''"; - $sql .= " AND ab.lettering_code IS NULL"; - $sql .= " AND ab2.lettering_code != ''"; - $sql .= " ORDER BY ab2.lettering_code DESC"; - $sql .= " LIMIT 1 "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab2 ON ab2.subledger_account = ab.subledger_account"; + $sql .= " WHERE ab.rowid IN (" . $this->db->sanitize(implode(',', $ids)) . ")"; + $sql .= " AND ab2.lettering_code != ''"; + $sql .= " ORDER BY ab2.lettering_code DESC"; + $sql .= " LIMIT 1 "; $resqla = $this->db->query($sql); if ($resqla) { $obj = $this->db->fetch_object($resqla); - $lettre = (empty($obj->lettering_code) ? 'AAA' : $obj->lettering_code); + $lettre = (empty($obj->lettering_code) ? $lettre : $obj->lettering_code); if (!empty($obj->lettering_code)) { $lettre++; } @@ -301,7 +333,7 @@ class Lettering extends BookKeeping if (!$error) { $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping SET"; $sql .= " lettering_code='".$this->db->escape($lettre)."'"; - $sql .= " , date_lettering = '".$this->db->idate($now)."'"; // todo correct date it's false + $sql .= ", date_lettering = '".$this->db->idate($now)."'"; // todo correct date it's false $sql .= " WHERE rowid IN (".$this->db->sanitize(implode(',', $ids)).") AND lettering_code IS NULL AND subledger_account != ''"; dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -336,7 +368,7 @@ class Lettering extends BookKeeping $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping SET"; $sql .= " lettering_code = NULL"; - $sql .= " , date_lettering = NULL"; + $sql .= ", date_lettering = NULL"; $sql .= " WHERE rowid IN (".$this->db->sanitize(implode(',', $ids)).")"; $sql .= " AND subledger_account != ''"; @@ -374,16 +406,7 @@ class Lettering extends BookKeeping $errors = array(); $nb_lettering = 0; - $result = $this->bookkeepingLettering($bookkeeping_ids, 'customer_invoice', $unlettering); - if ($result < 0) { - $error++; - $errors = array_merge($errors, $this->errors); - $nb_lettering += abs($result) - 2; - } else { - $nb_lettering += $result; - } - - $result = $this->bookkeepingLettering($bookkeeping_ids, 'supplier_invoice', $unlettering); + $result = $this->bookkeepingLettering($bookkeeping_ids, $unlettering); if ($result < 0) { $error++; $errors = array_merge($errors, $this->errors); @@ -404,11 +427,10 @@ class Lettering extends BookKeeping * Lettering bookkeeping lines * * @param array $bookkeeping_ids Lettering specific list of bookkeeping id - * @param string $type Type of bookkeeping type to lettering ('customer_invoice' or 'supplier_invoice') * @param bool $unlettering Do unlettering * @return int <0 if error (nb lettered = result -1), 0 if noting to lettering, >0 if OK (nb lettered) */ - public function bookkeepingLettering($bookkeeping_ids, $type = 'customer_invoice', $unlettering = false) + public function bookkeepingLettering($bookkeeping_ids, $unlettering = false) { global $langs; @@ -416,11 +438,14 @@ class Lettering extends BookKeeping // Clean parameters $bookkeeping_ids = is_array($bookkeeping_ids) ? $bookkeeping_ids : array(); - $type = trim($type); $error = 0; $nb_lettering = 0; - $grouped_lines = $this->getLinkedLines($bookkeeping_ids, $type); + $grouped_lines = $this->getLinkedLines($bookkeeping_ids); + if (!is_array($grouped_lines)) { + return -2; + } + foreach ($grouped_lines as $lines) { $group_error = 0; $total = 0; @@ -440,7 +465,7 @@ class Lettering extends BookKeeping $group_error++; break; } - if (!isset($lettering_code)) $lettering_code = (string) $line_infos['lettering_code']; + if (!isset($lettering_code)) $lettering_code = (string)$line_infos['lettering_code']; if (!empty($line_infos['lettering_code'])) $do_it = true; } elseif (!empty($line_infos['lettering_code'])) $do_it = false; } @@ -478,52 +503,215 @@ class Lettering extends BookKeeping /** * Lettering bookkeeping lines * - * @param array $bookkeeping_ids Lettering specific list of bookkeeping id - * @param string $type Type of bookkeeping type to lettering ('customer_invoice' or 'supplier_invoice') - * @return array|int <0 if error otherwise all linked lines by block + * @param array $bookkeeping_ids Lettering specific list of bookkeeping id + * @param bool $only_has_subledger_account Get only lines who have subledger account + * @return array|int <0 if error otherwise all linked lines by block */ - public function getLinkedLines($bookkeeping_ids, $type = 'customer_invoice') + public function getLinkedLines($bookkeeping_ids, $only_has_subledger_account = true) { global $conf, $langs; $this->errors = array(); // Clean parameters $bookkeeping_ids = is_array($bookkeeping_ids) ? $bookkeeping_ids : array(); - $type = trim($type); - if ($type == 'customer_invoice') { - $doc_type = 'customer_invoice'; - $bank_url_type = 'payment'; - $payment_element = 'paiement_facture'; - $fk_payment_element = 'fk_paiement'; - $fk_element = 'fk_facture'; - $account_number = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; - } elseif ($type == 'supplier_invoice') { - $doc_type = 'supplier_invoice'; - $bank_url_type = 'payment_supplier'; - $payment_element = 'paiementfourn_facturefourn'; - $fk_payment_element = 'fk_paiementfourn'; - $fk_element = 'fk_facturefourn'; - $account_number = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; - } else { + // Get all bookkeeping lines + $sql = "SELECT DISTINCT ab.doc_type, ab.fk_doc"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; + if (!empty($bookkeeping_ids)) { + // Get all bookkeeping lines of piece number + $sql .= " LEFT JOIN ("; + $sql .= " SELECT DISTINCT piece_num"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping"; + $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND rowid IN (" . $this->db->sanitize(implode(',', $bookkeeping_ids)) . ")"; + $sql .= " ) AS pn ON pn.piece_num = ab.piece_num"; + } + $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND ab.fk_doc > 0"; + if (!empty($bookkeeping_ids)) $sql .= " AND pn.piece_num IS NOT NULL"; + if ($only_has_subledger_account) $sql .= " AND ab.subledger_account != ''"; + + dol_syslog(__METHOD__ . " - Get all bookkeeping lines", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + return -1; + } + + $bookkeeping_lines_by_type = array(); + while ($obj = $this->db->fetch_object($resql)) { + $bookkeeping_lines_by_type[$obj->doc_type][$obj->fk_doc] = $obj->fk_doc; + } + $this->db->free($resql); + + if (empty($bookkeeping_lines_by_type)) { + return array(); + } + + if (!empty($bookkeeping_lines_by_type['bank'])) { + $new_bookkeeping_lines_by_type = $this->getDocTypeAndFkDocFromBankLines($bookkeeping_lines_by_type['bank']); + if (!is_array($new_bookkeeping_lines_by_type)) { + return -1; + } + foreach ($new_bookkeeping_lines_by_type as $doc_type => $fk_docs) { + foreach ($fk_docs as $fk_doc) { + $bookkeeping_lines_by_type[$doc_type][$fk_doc] = $fk_doc; + } + } + } + + $grouped_lines = array(); + foreach (self::$doc_type_infos as $doc_type => $doc_type_info) { + if (!is_array($bookkeeping_lines_by_type[$doc_type])) { + continue; + } + + // Get all document ids grouped + $doc_grouped = $this->getLinkedDocumentByGroup($bookkeeping_lines_by_type[$doc_type], $doc_type); + if (!is_array($doc_grouped)) { + return -1; + } + + // Group all lines by document/piece number + foreach ($doc_grouped as $doc_ids) { + $bank_ids = $this->getBankLinesFromFkDocAndDocType($doc_ids, $doc_type); + if (!is_array($bank_ids)) { + return -1; + } + + // Get all bookkeeping lines linked + $sql = "SELECT DISTINCT ab.rowid, ab.piece_num, ab.debit, ab.credit, ab.lettering_code"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; + if (!empty($bank_ids)) { + $sql .= " LEFT JOIN ("; + $sql .= " SELECT DISTINCT ab.piece_num"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; + $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND ab.doc_type = 'bank'"; + $sql .= " AND ab.fk_doc IN (" . $this->db->sanitize(implode(',', $bank_ids)) . ")"; + $sql .= " ) AS bpn ON bpn.piece_num = ab.piece_num"; + } + $sql .= " LEFT JOIN ("; + $sql .= " SELECT DISTINCT ab.piece_num"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; + $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND ab.doc_type = '" . $this->db->escape($doc_type) . "'"; + $sql .= " AND ab.fk_doc IN (" . $this->db->sanitize(implode(',', $doc_ids)) . ")"; + $sql .= " ) AS dpn ON dpn.piece_num = ab.piece_num"; + $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND ("; + if (!empty($bank_ids)) { + $sql .= "bpn.piece_num IS NOT NULL OR "; + } + $sql .= "dpn.piece_num IS NOT NULL)"; + if ($only_has_subledger_account) $sql .= " AND ab.subledger_account != ''"; + + dol_syslog(__METHOD__ . " - Get all bookkeeping lines linked", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + return -1; + } + + $group = array(); + while ($obj = $this->db->fetch_object($resql)) { + $group[$obj->rowid] = array( + 'id' => $obj->rowid, + 'piece_num' => $obj->piece_num, + 'debit' => $obj->debit, + 'credit' => $obj->credit, + 'lettering_code' => $obj->lettering_code, + ); + } + $this->db->free($resql); + + if (!empty($group)) $grouped_lines[] = $group; + } + } + + return $grouped_lines; + } + + /** + * Get all fk_doc by doc_type from list of bank ids + * + * @param array $bank_ids List of bank ids + * @return array|int <0 if error otherwise all fk_doc by doc_type + */ + public function getDocTypeAndFkDocFromBankLines($bank_ids) + { + dol_syslog(__METHOD__ . " - bank_ids=".json_encode($bank_ids), LOG_DEBUG); + + // Clean parameters + $bank_ids = is_array($bank_ids) ? $bank_ids : array(); + + if (empty($bank_ids)) { + return array(); + } + + $bookkeeping_lines_by_type = array(); + foreach (self::$doc_type_infos as $doc_type => $doc_type_info) { + // Get all fk_doc by doc_type from bank ids + $sql = "SELECT DISTINCT dp." . $doc_type_info['doc_payment_table_fk_doc'] . " AS fk_doc"; + $sql .= " FROM " . MAIN_DB_PREFIX . $doc_type_info['payment_table'] . " AS p"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $doc_type_info['doc_payment_table'] . " AS dp ON dp." . $doc_type_info['doc_payment_table_fk_payment'] . " = p.rowid"; + $sql .= " WHERE p." . $doc_type_info['payment_table_fk_bank'] . " IN (" . $this->db->sanitize(implode(',', $bank_ids)) . ")"; + $sql .= " AND dp." . $doc_type_info['doc_payment_table_fk_doc'] . " > 0"; + + dol_syslog(__METHOD__ . " - Get all fk_doc by doc_type from list of bank ids for '" . $doc_type . "'", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + return -1; + } + + while ($obj = $this->db->fetch_object($resql)) { + $bookkeeping_lines_by_type[$doc_type][$obj->fk_doc] = $obj->fk_doc; + } + $this->db->free($resql); + } + + return $bookkeeping_lines_by_type; + } + + /** + * Get all bank ids from list of document ids of a type + * + * @param array $document_ids List of document id + * @param string $doc_type Type of document ('customer_invoice' or 'supplier_invoice', ...) + * @return array|int <0 if error otherwise all all bank ids from list of document ids of a type + */ + public function getBankLinesFromFkDocAndDocType($document_ids, $doc_type) + { + global $langs; + + dol_syslog(__METHOD__ . " - bank_ids=".json_encode($document_ids) . ", doc_type=$doc_type", LOG_DEBUG); + + // Clean parameters + $document_ids = is_array($document_ids) ? $document_ids : array(); + $doc_type = trim($doc_type); + + if (empty($document_ids)) { + return array(); + } + if (!is_array(self::$doc_type_infos[$doc_type])) { $langs->load('errors'); $this->errors[] = $langs->trans('ErrorBadParameters'); return -1; } - $payment_ids = array(); + $doc_type_info = self::$doc_type_infos[$doc_type]; + $bank_ids = array(); - // Get all payment id from bank lines - $sql = "SELECT DISTINCT bu.url_id AS payment_id"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url AS bu ON bu.fk_bank = ab.fk_doc"; - $sql .= " WHERE ab.doc_type = 'bank'"; - // $sql .= " AND ab.subledger_account != ''"; - // $sql .= " AND ab.numero_compte = '" . $this->db->escape($account_number) . "'"; - $sql .= " AND bu.type = '" . $this->db->escape($bank_url_type) . "'"; - if (!empty($bookkeeping_ids)) $sql .= " AND ab.rowid IN (" . $this->db->sanitize(implode(',', $bookkeeping_ids)) . ")"; + // Get all fk_doc by doc_type from bank ids + $sql = "SELECT DISTINCT p." . $doc_type_info['payment_table_fk_bank'] . " AS fk_doc"; + $sql .= " FROM " . MAIN_DB_PREFIX . $doc_type_info['payment_table'] . " AS p"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $doc_type_info['doc_payment_table'] . " AS dp ON dp." . $doc_type_info['doc_payment_table_fk_payment'] . " = p.rowid"; + $sql .= " WHERE dp." . $doc_type_info['doc_payment_table_fk_doc'] . " IN (" . $this->db->sanitize(implode(',', $document_ids)) . ")"; + $sql .= " AND p." . $doc_type_info['payment_table_fk_bank'] . " > 0"; - dol_syslog(__METHOD__ . " - Get all payment id from bank lines", LOG_DEBUG); + dol_syslog(__METHOD__ . " - Get all bank ids from list of document ids of a type '" . $doc_type . "'", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = "Error " . $this->db->lasterror(); @@ -531,218 +719,137 @@ class Lettering extends BookKeeping } while ($obj = $this->db->fetch_object($resql)) { - $payment_ids[$obj->payment_id] = $obj->payment_id; + $bank_ids[$obj->fk_doc] = $obj->fk_doc; } $this->db->free($resql); - // Get all payment id from payment lines - $sql = "SELECT DISTINCT pe.$fk_payment_element AS payment_id"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "$payment_element AS pe ON pe.$fk_element = ab.fk_doc"; - $sql .= " WHERE ab.doc_type = '" . $this->db->escape($doc_type) . "'"; - // $sql .= " AND ab.subledger_account != ''"; - // $sql .= " AND ab.numero_compte = '" . $this->db->escape($account_number) . "'"; - $sql .= " AND pe.$fk_payment_element IS NOT NULL"; - if (!empty($bookkeeping_ids)) $sql .= " AND ab.rowid IN (" . $this->db->sanitize(implode(',', $bookkeeping_ids)) . ")"; - - dol_syslog(__METHOD__ . " - Get all payment id from bank lines", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = "Error " . $this->db->lasterror(); - return -1; - } - - while ($obj = $this->db->fetch_object($resql)) { - $payment_ids[$obj->payment_id] = $obj->payment_id; - } - $this->db->free($resql); - - if (empty($payment_ids)) { - return array(); - } - - // Get all payments linked by group - $payment_by_group = $this->getLinkedPaymentByGroup($payment_ids, $type); - - $groups = array(); - foreach ($payment_by_group as $payment_list) { - $lines = array(); - - // Get bank lines - $sql = "SELECT DISTINCT ab.rowid, ab.piece_num, ab.lettering_code, ab.debit, ab.credit"; - $sql .= " FROM " . MAIN_DB_PREFIX . "bank_url AS bu"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab ON ab.fk_doc = bu.fk_bank"; - $sql .= " WHERE bu.url_id IN (" . $this->db->sanitize(implode(',', $payment_list)) . ")"; - $sql .= " AND bu.type = '" . $this->db->escape($bank_url_type) . "'"; - $sql .= " AND ab.doc_type = 'bank'"; - $sql .= " AND ab.subledger_account != ''"; - $sql .= " AND ab.numero_compte = '" . $this->db->escape($account_number) . "'"; - - dol_syslog(__METHOD__ . " - Get bank lines", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = "Error " . $this->db->lasterror(); - return -1; - } - - while ($obj = $this->db->fetch_object($resql)) { - $lines[$obj->rowid] = array('id' => $obj->rowid, 'piece_num' => $obj->piece_num, 'lettering_code' => $obj->lettering_code, 'debit' => $obj->debit, 'credit' => $obj->credit); - } - $this->db->free($resql); - - // Get payment lines - $sql = "SELECT DISTINCT ab.rowid, ab.piece_num, ab.lettering_code, ab.debit, ab.credit"; - $sql .= " FROM " . MAIN_DB_PREFIX . "$payment_element AS pe"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab ON ab.fk_doc = pe.$fk_element"; - $sql .= " WHERE pe.$fk_payment_element IN (" . $this->db->sanitize(implode(',', $payment_list)) . ")"; - $sql .= " AND ab.doc_type = '" . $this->db->escape($doc_type) . "'"; - $sql .= " AND ab.subledger_account != ''"; - $sql .= " AND ab.numero_compte = '" . $this->db->escape($account_number) . "'"; - - dol_syslog(__METHOD__ . " - Get payment lines", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = "Error " . $this->db->lasterror(); - return -1; - } - - while ($obj = $this->db->fetch_object($resql)) { - $lines[$obj->rowid] = array('id' => $obj->rowid, 'piece_num' => $obj->piece_num, 'lettering_code' => $obj->lettering_code, 'debit' => $obj->debit, 'credit' => $obj->credit); - } - $this->db->free($resql); - - if (!empty($lines)) { - $groups[] = $lines; - } - } - - return $groups; + return $bank_ids; } /** - * Linked payment by group + * Get all linked document ids by group and type * - * @param array $payment_ids list of payment id - * @param string $type Type of bookkeeping type to lettering ('customer_invoice' or 'supplier_invoice') - * @return array|int <0 if error otherwise all linked lines by block + * @param array $document_ids List of document id + * @param string $doc_type Type of document ('customer_invoice' or 'supplier_invoice', ...) + * @return array|int <0 if error otherwise all linked document ids by group and type [ [ 'doc_type' => [ doc_id, ... ], ... ], ... ] */ - public function getLinkedPaymentByGroup($payment_ids, $type) + public function getLinkedDocumentByGroup($document_ids, $doc_type) { global $langs; // Clean parameters - $payment_ids = is_array($payment_ids) ? $payment_ids : array(); - $type = trim($type); + $document_ids = is_array($document_ids) ? $document_ids : array(); + $doc_type = trim($doc_type); - if (empty($payment_ids)) { + if (empty($document_ids)) { return array(); } - - if ($type == 'customer_invoice') { - $payment_element = 'paiement_facture'; - $fk_payment_element = 'fk_paiement'; - $fk_element = 'fk_facture'; - } elseif ($type == 'supplier_invoice') { - $payment_element = 'paiementfourn_facturefourn'; - $fk_payment_element = 'fk_paiementfourn'; - $fk_element = 'fk_facturefourn'; - } else { + if (!is_array(self::$doc_type_infos[$doc_type])) { $langs->load('errors'); $this->errors[] = $langs->trans('ErrorBadParameters'); return -1; } - // Get payment lines - $sql = "SELECT DISTINCT pe2.$fk_payment_element, pe2.$fk_element"; - $sql .= " FROM " . MAIN_DB_PREFIX . "$payment_element AS pe"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "$payment_element AS pe2 ON pe2.$fk_element = pe.$fk_element"; - $sql .= " WHERE pe.$fk_payment_element IN (" . $this->db->sanitize(implode(',', $payment_ids)) . ")"; + $doc_type_info = self::$doc_type_infos[$doc_type]; - dol_syslog(__METHOD__ . " - Get payment lines", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = "Error " . $this->db->lasterror(); - return -1; + // Get document lines + $current_document_ids = array(); + $link_by_element = array(); + $element_by_link = array(); + foreach ($doc_type_info['linked_info'] as $linked_info) { + $sql = "SELECT DISTINCT tl2." . $linked_info['fk_link'] . " AS fk_link, tl2." . $linked_info['fk_doc'] . " AS fk_doc"; + $sql .= " FROM " . MAIN_DB_PREFIX . $linked_info['table'] . " AS tl"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $linked_info['table'] . " AS tl2 ON tl2." . $linked_info['fk_link'] . " = tl." . $linked_info['fk_link']; + $sql .= " WHERE tl." . $linked_info['fk_doc'] . " IN (" . $this->db->sanitize(implode(',', $document_ids)) . ")"; + + dol_syslog(__METHOD__ . " - Get document lines", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + return -1; + } + + $is_fk_link_is_also_fk_doc = !empty($linked_info['is_fk_link_is_also_fk_doc']); + while ($obj = $this->db->fetch_object($resql)) { + $current_document_ids[$obj->fk_doc] = $obj->fk_doc; + + $link_key = $linked_info['prefix'] . $obj->fk_link; + $element_by_link[$link_key][$obj->fk_doc] = $obj->fk_doc; + $link_by_element[$obj->fk_doc][$link_key] = $link_key; + if ($is_fk_link_is_also_fk_doc) { + $element_by_link[$link_key][$obj->fk_link] = $obj->fk_link; + $link_by_element[$obj->fk_link][$link_key] = $link_key; + } + } + $this->db->free($resql); } - $current_payment_ids = array(); - $payment_by_element = array(); - $element_by_payment = array(); - while ($obj = $this->db->fetch_object($resql)) { - $current_payment_ids[$obj->$fk_payment_element] = $obj->$fk_payment_element; - $element_by_payment[$obj->$fk_payment_element][$obj->$fk_element] = $obj->$fk_element; - $payment_by_element[$obj->$fk_element][$obj->$fk_payment_element] = $obj->$fk_payment_element; - } - $this->db->free($resql); - - if (count(array_diff($payment_ids, $current_payment_ids))) { - return $this->getLinkedPaymentByGroup($current_payment_ids, $type); + if (count(array_diff($document_ids, $current_document_ids))) { + return $this->getLinkedDocumentByGroup($current_document_ids, $doc_type); } - return $this->getGroupElements($payment_by_element, $element_by_payment); + return $this->getGroupElements($link_by_element, $element_by_link); } /** - * Get payment ids grouped by payment id and element id in common + * Get element ids grouped by link or element in common * - * @param array $payment_by_element List of payment ids by element id - * @param array $element_by_payment List of element ids by payment id - * @param int $element_id Element Id (used for recursive function) - * @param array $current_group Current group (used for recursive function) - * @return array List of payment ids grouped by payment id and element id in common + * @param array &$link_by_element List of payment ids by link key + * @param array &$element_by_link List of element ids by link key + * @param string $link_key Link key (used for recursive function) + * @param array &$current_group Current group (used for recursive function) + * @return array List of element ids grouped by link or element in common */ - public function getGroupElements(&$payment_by_element, &$element_by_payment, $element_id = 0, &$current_group = array()) + public function getGroupElements(&$link_by_element, &$element_by_link, $link_key = '', &$current_group = array()) { - $grouped_payments = array(); - if ($element_id > 0 && !isset($payment_by_element[$element_id])) { - // Return if specific element id not found - return $grouped_payments; + $grouped_elements = array(); + if (!empty($link_key) && !isset($element_by_link[$link_key])) { + // Return if specific link key not found + return $grouped_elements; } - $save_payment_by_element = null; - $save_element_by_payment = null; - if ($element_id == 0) { + if (empty($link_key)) { // Save list when is the begin of recursive function - $save_payment_by_element = $payment_by_element; - $save_element_by_payment = $element_by_payment; + $save_link_by_element = $link_by_element; + $save_element_by_link = $element_by_link; } do { // Get current element id, get this payment id list and delete the entry - $current_element_id = $element_id > 0 ? $element_id : array_keys($payment_by_element)[0]; - $payment_ids = $payment_by_element[$current_element_id]; - unset($payment_by_element[$current_element_id]); + $current_link_key = !empty($link_key) ? $link_key : array_keys($element_by_link)[0]; + $element_ids = $element_by_link[$current_link_key]; + unset($element_by_link[$current_link_key]); - foreach ($payment_ids as $payment_id) { - // Continue if payment id in not found - if (!isset($element_by_payment[$payment_id])) continue; + foreach ($element_ids as $element_id) { + // Continue if element id in not found + if (!isset($link_by_element[$element_id])) continue; - // Set the payment in the current group - $current_group[$payment_id] = $payment_id; + // Set the element in the current group + $current_group[$element_id] = $element_id; - // Get current element ids, get this payment id list and delete the entry - $element_ids = $element_by_payment[$payment_id]; - unset($element_by_payment[$payment_id]); + // Get current link keys, get this element id list and delete the entry + $link_keys = $link_by_element[$element_id]; + unset($link_by_element[$element_id]); - // Set payment id on the current group for each element id of the payment - foreach ($element_ids as $id) { - $this->getGroupElements($payment_by_element, $element_by_payment, $id, $current_group); + // Set element id on the current group for each link key of the element + foreach ($link_keys as $key) { + $this->getGroupElements($link_by_element, $element_by_link, $key, $current_group); } } - if ($element_id == 0) { + if (empty($link_key)) { // Save current group and reset the current group when is the begin of recursive function - $grouped_payments[] = $current_group; + $grouped_elements[] = $current_group; $current_group = array(); } - } while (!empty($payment_by_element) && $element_id == 0); + } while(!empty($element_by_link) && empty($link_key)); - if ($element_id == 0) { + if (empty($link_key)) { // Restore list when is the begin of recursive function - $payment_by_element = $save_payment_by_element; - $element_by_payment = $save_element_by_payment; + $link_by_element = $save_link_by_element; + $element_by_link = $save_element_by_link; } - return $grouped_payments; + return $grouped_elements; } } diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 70741aca5d1..3e96804c99f 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -381,7 +381,7 @@ if ($action == 'writebookkeeping') { if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) { require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; $lettering_static = new Lettering($db); - $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id), 'supplier_invoice'); + $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id)); } } } diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 107dda05f4a..ca0dd5089a4 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -394,7 +394,7 @@ if ($action == 'writebookkeeping') { if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) { require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; $lettering_static = new Lettering($db); - $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id), 'customer_invoice'); + $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id)); } } } diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index fcdbca76d5c..d186027ff22 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -398,7 +398,11 @@ Calculated=Calculated Formula=Formula ## Reconcile +LetteringAuto=Reconcile auto +LetteringManual=Reconcile manual Unlettering=Unreconcile +UnletteringAuto=Unreconcile auto +UnletteringManual=Unreconcile manual AccountancyNoLetteringModified=No reconcile modified AccountancyOneLetteringModifiedSuccessfully=One reconcile successfully modified AccountancyLetteringModifiedSuccessfully=%s reconcile successfully modified @@ -407,8 +411,9 @@ AccountancyOneUnletteringModifiedSuccessfully=One unreconcile successfully modif AccountancyUnletteringModifiedSuccessfully=%s unreconcile successfully modified ## Confirm box -ConfirmMassUnlettering=Bulk Unreconcile confirmation -ConfirmMassUnletteringQuestion=Are you sure you want to Unreconcile the %s selected record(s)? +ConfirmMassUnletteringAuto=Bulk auto unreconcile confirmation +ConfirmMassUnletteringManual=Bulk manual unreconcile confirmation +ConfirmMassUnletteringQuestion=Are you sure you want to unreconcile the %s selected record(s)? ConfirmMassDeleteBookkeepingWriting=Bulk Delete confirmation ConfirmMassDeleteBookkeepingWritingQuestion=This will delete the transaction from the accounting (all lines related to the same transaction will be deleted) Are you sure you want to delete the %s selected record(s)? From 1cd4f4ed8dd57a5d68f04177f405dd7124912955 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 15 Sep 2022 04:36:08 +0000 Subject: [PATCH 02/14] Fixing style errors. --- htdocs/accountancy/class/lettering.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 5f3d23a72eb..fdbb3b85ebb 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -465,7 +465,7 @@ class Lettering extends BookKeeping $group_error++; break; } - if (!isset($lettering_code)) $lettering_code = (string)$line_infos['lettering_code']; + if (!isset($lettering_code)) $lettering_code = (string) $line_infos['lettering_code']; if (!empty($line_infos['lettering_code'])) $do_it = true; } elseif (!empty($line_infos['lettering_code'])) $do_it = false; } @@ -842,7 +842,7 @@ class Lettering extends BookKeeping $grouped_elements[] = $current_group; $current_group = array(); } - } while(!empty($element_by_link) && empty($link_key)); + } while (!empty($element_by_link) && empty($link_key)); if (empty($link_key)) { // Restore list when is the begin of recursive function From 6fa428df41eb5ae5fae4402553b1110afe068112 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 15 Sep 2022 09:30:01 +0200 Subject: [PATCH 03/14] Fix comment for parameter --- htdocs/accountancy/class/lettering.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index fdbb3b85ebb..989d591e403 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -794,10 +794,10 @@ class Lettering extends BookKeeping /** * Get element ids grouped by link or element in common * - * @param array &$link_by_element List of payment ids by link key - * @param array &$element_by_link List of element ids by link key + * @param array $link_by_element List of payment ids by link key + * @param array $element_by_link List of element ids by link key * @param string $link_key Link key (used for recursive function) - * @param array &$current_group Current group (used for recursive function) + * @param array $current_group Current group (used for recursive function) * @return array List of element ids grouped by link or element in common */ public function getGroupElements(&$link_by_element, &$element_by_link, $link_key = '', &$current_group = array()) From 4ef080dbe0602c3abc458fd7eb9bdae754bb570e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 1 Oct 2022 08:15:14 +0200 Subject: [PATCH 04/14] Update SQL with EXISTS --- htdocs/accountancy/class/lettering.class.php | 55 ++++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 989d591e403..857cd12115e 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -518,18 +518,18 @@ class Lettering extends BookKeeping // Get all bookkeeping lines $sql = "SELECT DISTINCT ab.doc_type, ab.fk_doc"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; - if (!empty($bookkeeping_ids)) { - // Get all bookkeeping lines of piece number - $sql .= " LEFT JOIN ("; - $sql .= " SELECT DISTINCT piece_num"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping"; - $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")"; - $sql .= " AND rowid IN (" . $this->db->sanitize(implode(',', $bookkeeping_ids)) . ")"; - $sql .= " ) AS pn ON pn.piece_num = ab.piece_num"; - } $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; $sql .= " AND ab.fk_doc > 0"; - if (!empty($bookkeeping_ids)) $sql .= " AND pn.piece_num IS NOT NULL"; + if (!empty($bookkeeping_ids)) { + // Get all bookkeeping lines of piece number + $sql .= " AND EXISTS ("; + $sql .= " SELECT rowid"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS pn"; + $sql .= " WHERE pn.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND pn.rowid IN (" . $this->db->sanitize(implode(',', $bookkeeping_ids)) . ")"; + $sql .= " AND pn.piece_num = ab.piece_num"; + $sql .= " )"; + } if ($only_has_subledger_account) $sql .= " AND ab.subledger_account != ''"; dol_syslog(__METHOD__ . " - Get all bookkeeping lines", LOG_DEBUG); @@ -583,28 +583,27 @@ class Lettering extends BookKeeping // Get all bookkeeping lines linked $sql = "SELECT DISTINCT ab.rowid, ab.piece_num, ab.debit, ab.credit, ab.lettering_code"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; - if (!empty($bank_ids)) { - $sql .= " LEFT JOIN ("; - $sql .= " SELECT DISTINCT ab.piece_num"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; - $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; - $sql .= " AND ab.doc_type = 'bank'"; - $sql .= " AND ab.fk_doc IN (" . $this->db->sanitize(implode(',', $bank_ids)) . ")"; - $sql .= " ) AS bpn ON bpn.piece_num = ab.piece_num"; - } - $sql .= " LEFT JOIN ("; - $sql .= " SELECT DISTINCT ab.piece_num"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS ab"; - $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; - $sql .= " AND ab.doc_type = '" . $this->db->escape($doc_type) . "'"; - $sql .= " AND ab.fk_doc IN (" . $this->db->sanitize(implode(',', $doc_ids)) . ")"; - $sql .= " ) AS dpn ON dpn.piece_num = ab.piece_num"; $sql .= " WHERE ab.entity IN (" . getEntity('accountancy') . ")"; $sql .= " AND ("; if (!empty($bank_ids)) { - $sql .= "bpn.piece_num IS NOT NULL OR "; + $sql .= " EXISTS ("; + $sql .= " SELECT bpn.rowid"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS bpn"; + $sql .= " WHERE bpn.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND bpn.doc_type = 'bank'"; + $sql .= " AND bpn.fk_doc IN (" . $this->db->sanitize(implode(',', $bank_ids)) . ")"; + $sql .= " AND bpn ON bpn.piece_num = ab.piece_num"; + $sql .= " ) OR "; } - $sql .= "dpn.piece_num IS NOT NULL)"; + $sql .= " EXISTS ("; + $sql .= " SELECT dpn.rowid"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping AS dpn"; + $sql .= " WHERE dpn.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " AND dpn.doc_type = '" . $this->db->escape($doc_type) . "'"; + $sql .= " AND dpn.fk_doc IN (" . $this->db->sanitize(implode(',', $doc_ids)) . ")"; + $sql .= " AND dpn.piece_num = ab.piece_num"; + $sql .= " )"; + $sql .= ")"; if ($only_has_subledger_account) $sql .= " AND ab.subledger_account != ''"; dol_syslog(__METHOD__ . " - Get all bookkeeping lines linked", LOG_DEBUG); From 07aa117e2aa7c3c506fcca8a61b0405ae1743617 Mon Sep 17 00:00:00 2001 From: Christian Foellmann Date: Thu, 6 Oct 2022 13:51:40 +0200 Subject: [PATCH 05/14] add bug icon to Bug link in leftMenu --- htdocs/main.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index c8187551ea7..74ba7f97996 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -3004,7 +3004,7 @@ function left_menu($menu_array_before, $helppagename = '', $notused = '', $menu_ } print ''; } From 9d35e3aabe55de06c7d14dccf8f5c3d3bc5281dc Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:41:56 +0200 Subject: [PATCH 06/14] update code towards php8 compliance --- htdocs/core/actions_linkedfiles.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index f11058312d1..b89d5bf6cb0 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -79,7 +79,7 @@ if (GETPOST('sendit', 'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC) && !emp } $allowoverwrite = (GETPOST('overwritefile', 'int') ? 1 : 0); - if (!empty($upload_dirold) && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (!empty($upload_dirold) && getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $result = dol_add_file_process($upload_dirold, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs, $object); } elseif (!empty($upload_dir)) { $result = dol_add_file_process($upload_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs, $object); From 06d787713abd1d37ccf502b27b874f7935562acd Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:43:57 +0200 Subject: [PATCH 07/14] update code towards php8 compliance --- htdocs/core/class/commonobject.class.php | 4 ++-- htdocs/core/class/html.formfile.class.php | 2 +- htdocs/core/lib/files.lib.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f9a64330ce6..b9cee6b4254 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8568,7 +8568,7 @@ abstract class CommonObject // For backward compatibility if ($modulepart == 'product') { - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; $pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; } @@ -8590,7 +8590,7 @@ abstract class CommonObject $filearray = dol_dir_list($dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); - /*if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs + /*if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) // For backward compatiblity, we scan also old dirs { $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); $filearray=array_merge($filearray, $filearrayold); diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index a0067925334..a583f07cdb1 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1146,7 +1146,7 @@ class FormFile } } // For backward compatiblity, we detect file stored into an old path - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos') { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO') && $filearray[0]['level1name'] == 'photos') { $relativepath = preg_replace('/^.*\/produit\//', '', $filearray[0]['path']).'/'; } diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 3be3c4c24f7..a9a4459def8 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -319,7 +319,7 @@ function completeFileArrayWithDatabaseInfo(&$filearray, $relativedir) // TODO Remove this when PRODUCT_USE_OLD_PATH_FOR_PHOTO will be removed global $modulepart; - if ($modulepart == 'produit' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if ($modulepart == 'produit' && getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { global $object; if (!empty($object->id)) { if (isModEnabled("product")) { From d6e12d3589050859cd0c9e3bcc9ac98717deb69c Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:44:52 +0200 Subject: [PATCH 08/14] update code towards php8 compliance --- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/lib/product.lib.php | 2 +- htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 409bf47d715..2262e3dd6ff 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6581,7 +6581,7 @@ function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart = ' $path = ''; $arrayforoldpath = array('cheque', 'category', 'holiday', 'supplier_invoice', 'invoice_supplier', 'mailing', 'supplier_payment'); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $arrayforoldpath[] = 'product'; } if (!empty($level) && in_array($modulepart, $arrayforoldpath)) { diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 87291071162..e2973bef0ba 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -183,7 +183,7 @@ function product_prepare_head($object) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); } $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { if (isModEnabled("product") && ($object->type == Product::TYPE_PRODUCT)) { $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id.'/photos'; } diff --git a/htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php b/htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php index 3853b7ae6e2..4b7c2bb0104 100644 --- a/htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php +++ b/htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php @@ -241,7 +241,7 @@ class pdf_standard_asset extends ModelePDFAsset if (empty($object->lines[$i]->fk_product)) continue; //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { From cb1b4b82af4a62819bea2ddad8da2b38271b3d5b Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:45:30 +0200 Subject: [PATCH 09/14] update code towards php8 compliance --- htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php | 2 +- htdocs/core/modules/delivery/doc/pdf_storm.modules.php | 2 +- htdocs/core/modules/expedition/doc/pdf_espadon.modules.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 1397d46eac9..d1683f91ee7 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -253,7 +253,7 @@ class pdf_eratosthene extends ModelePDFCommandes $objphoto->fetch($object->lines[$i]->fk_product); //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { diff --git a/htdocs/core/modules/delivery/doc/pdf_storm.modules.php b/htdocs/core/modules/delivery/doc/pdf_storm.modules.php index 735b247f73a..bd47360d85d 100644 --- a/htdocs/core/modules/delivery/doc/pdf_storm.modules.php +++ b/htdocs/core/modules/delivery/doc/pdf_storm.modules.php @@ -238,7 +238,7 @@ class pdf_storm extends ModelePDFDeliveryOrder $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { diff --git a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php index 67de0bd12ac..ee99d38ae2b 100644 --- a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php @@ -210,7 +210,7 @@ class pdf_espadon extends ModelePdfExpedition $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { From d418968dd87e9808cb1b756393dada6ab29802e9 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:46:18 +0200 Subject: [PATCH 10/14] update code towards php8 compliance --- htdocs/core/modules/expedition/doc/pdf_rouget.modules.php | 2 +- htdocs/core/modules/facture/doc/pdf_sponge.modules.php | 2 +- htdocs/core/modules/propale/doc/pdf_azur.modules.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index 983380b277d..9321e1ecf00 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -235,7 +235,7 @@ class pdf_rouget extends ModelePdfExpedition $objphoto = new Product($this->db); $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 2e5854b8534..e8269039aa8 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -285,7 +285,7 @@ class pdf_sponge extends ModelePDFFactures $objphoto->fetch($object->lines[$i]->fk_product); //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 3113468bf2e..3d507f816dc 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -262,7 +262,7 @@ class pdf_azur extends ModelePDFPropales $objphoto->fetch($object->lines[$i]->fk_product); //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { @@ -814,7 +814,7 @@ class pdf_azur extends ModelePDFPropales if (count($filetomerge->lines) > 0) { foreach ($filetomerge->lines as $linefile) { if (!empty($linefile->id) && !empty($linefile->file_name)) { - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { if (isModEnabled("product")) { $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos"; } elseif (isModEnabled("service")) { From 7dfd7d73ccdd377c6b81e2edc4261c41303871ee Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:47:29 +0200 Subject: [PATCH 11/14] update code towards php8 compliance --- htdocs/core/modules/propale/doc/pdf_cyan.modules.php | 4 ++-- htdocs/core/modules/reception/doc/pdf_squille.modules.php | 2 +- .../modules/stocktransfer/doc/pdf_eagle_proforma.modules.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index 8698f370d31..0da947cdd95 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -249,7 +249,7 @@ class pdf_cyan extends ModelePDFPropales $objphoto->fetch($object->lines[$i]->fk_product); //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { @@ -939,7 +939,7 @@ class pdf_cyan extends ModelePDFPropales if (count($filetomerge->lines) > 0) { foreach ($filetomerge->lines as $linefile) { if (!empty($linefile->id) && !empty($linefile->file_name)) { - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { if (isModEnabled("product")) { $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos"; } elseif (isModEnabled("service")) { diff --git a/htdocs/core/modules/reception/doc/pdf_squille.modules.php b/htdocs/core/modules/reception/doc/pdf_squille.modules.php index 6e970f198be..cc24bda817d 100644 --- a/htdocs/core/modules/reception/doc/pdf_squille.modules.php +++ b/htdocs/core/modules/reception/doc/pdf_squille.modules.php @@ -152,7 +152,7 @@ class pdf_squille extends ModelePdfReception $objphoto = new Product($this->db); $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { diff --git a/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php b/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php index 925813a1036..381710e2697 100644 --- a/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php +++ b/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php @@ -227,7 +227,7 @@ class pdf_eagle_proforma extends ModelePDFCommandes $objphoto->fetch($object->lines[$i]->fk_product); //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { From c6484b1df0c505d575934637635ac544868b8ded Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:48:18 +0200 Subject: [PATCH 12/14] update code towards php8 compliance --- htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php | 2 +- htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php | 2 +- htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php b/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php index 593966f4f80..70222be674e 100644 --- a/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php +++ b/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php @@ -219,7 +219,7 @@ class pdf_eagle extends ModelePdfStockTransfer $objphoto = new Product($this->db); $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { diff --git a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php index 78ea731bb42..5e4b75a183e 100644 --- a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php +++ b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php @@ -230,7 +230,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders $objphoto = new Product($this->db); $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { diff --git a/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php index 32295bdd562..8863aeffe47 100644 --- a/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php +++ b/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php @@ -245,7 +245,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders $objphoto = new Product($this->db); $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { From 82c7a6e9f005a392cb845da600e8c2c062593dd2 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:57:43 +0200 Subject: [PATCH 13/14] update code towards php8 compliance --- .../modules/supplier_proposal/doc/pdf_aurore.modules.php | 2 +- .../modules/mymodule/doc/pdf_standard_myobject.modules.php | 2 +- htdocs/product/card.php | 2 +- htdocs/product/document.php | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php index afa8ee7d285..5ed82f597fb 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -241,7 +241,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $objphoto = new Product($this->db); $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php index 9bb21dd7322..66e2b4dfa82 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php @@ -206,7 +206,7 @@ class pdf_standard_myobject extends ModelePDFMyObject if (empty($object->lines[$i]->fk_product)) continue; //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else { diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 25cbf623c8d..2071171feba 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -147,7 +147,7 @@ if ($id > 0 || !empty($ref)) { $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); } - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { // For backward compatiblity, we scan also old dirs if (isModEnabled("product")) { $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; } else { diff --git a/htdocs/product/document.php b/htdocs/product/document.php index bfb5978406d..c24082ae6e6 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -90,7 +90,7 @@ if ($id > 0 || !empty($ref)) { $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product'); } - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { // For backward compatiblity, we scan also old dirs if (isModEnabled("product")) { $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; } else { @@ -228,7 +228,7 @@ if ($object->id) { // Build file list $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { // For backward compatiblity, we scan also old dirs $filearrayold = dol_dir_list($upload_dirold, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $filearray = array_merge($filearray, $filearrayold); } @@ -283,7 +283,7 @@ if ($object->id) { $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', 'name', SORT_ASC, 1); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { // For backward compatiblity, we scan also old dirs $filearray = array_merge($filearray, dol_dir_list($upload_dirold, "files", 0, '', '\.meta$', 'name', SORT_ASC, 1)); } From 016ede5b6b500558e00a5f941dc0e4255ac00746 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 6 Oct 2022 16:58:40 +0200 Subject: [PATCH 14/14] update code towards php8 compliance --- htdocs/product/class/product.class.php | 4 ++-- .../doc/pdf_standard_recruitmentjobposition.modules.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index fc8b852edf6..a344b5b5f44 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5630,7 +5630,7 @@ class Product extends CommonObject $result = 0; $dir = $sdir; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $dir .= '/'.get_exdir($this->id, 2, 0, 0, $this, 'product').$this->id."/photos"; } else { $dir .= '/'.get_exdir(0, 0, 0, 0, $this, 'product').dol_sanitizeFileName($this->ref); @@ -5675,7 +5675,7 @@ class Product extends CommonObject global $conf; $dir = $sdir; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $dir .= '/'.get_exdir($this->id, 2, 0, 0, $this, 'product').$this->id."/photos/"; } else { $dir .= '/'.get_exdir(0, 0, 0, 0, $this, 'product'); diff --git a/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php b/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php index a883cf8c144..199513993f2 100644 --- a/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php +++ b/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php @@ -217,7 +217,7 @@ class pdf_standard_recruitmentjobposition extends ModelePDFRecruitmentJobPositio $objphoto->fetch($object->lines[$i]->fk_product); //var_dump($objphoto->ref);exit; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { + if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; } else {