From 368f5e57a97c7ad9686453217e957ab564bd009c Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 2 Oct 2022 20:03:42 +0200 Subject: [PATCH 01/15] Add a global constant to allow a negative quantity in propal's line --- htdocs/comm/propal/card.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index c737ea63ebe..dfe6cae29d2 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -874,7 +874,8 @@ if (empty($reshook)) { } } - if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) { + $propal_qty_requirement = (!empty($conf->global->PROPAL_ENABLE_NEGATIVE_QTY) ? ($qty >= 0 || $qty <= 0) : $qty >= 0); + if (!$error && $propal_qty_requirement && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) { $pu_ht = 0; $pu_ttc = 0; $price_min = 0; From 49d084721b6a8f187702f51342e36c9570648f3b Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Tue, 3 Oct 2023 09:17:32 +0200 Subject: [PATCH 02/15] FIX regression on rounding stocks fields on product list --- htdocs/product/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index e477d1a698c..20b812902d0 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -1703,7 +1703,7 @@ if ($resql) { if ($obj->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $obj->seuil_stock_alerte) { print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; } - print price(price2num($product_static->stock_reel, 'MS')); + print price(price2num($product_static->stock_reel, 'MS'), 0, $langs, 1, 0); } print ''; if (!$i) { @@ -1717,7 +1717,7 @@ if ($resql) { if ($obj->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $obj->seuil_stock_alerte) { print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; } - print price(price2num($product_static->stock_theorique, 'MS')); + print price(price2num($product_static->stock_theorique, 'MS'), 0, $langs, 1, 0); } print ''; if (!$i) { From 95a15ae6f99e18ee88e2ef3e30e419a7fbf0ea76 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 16 Oct 2023 13:13:32 +0200 Subject: [PATCH 03/15] FIX #26195 - Various payment - List of project excluded those assigned to third parties (#26222) --- htdocs/compta/bank/various_payment/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index a2c6c2b21ae..5ca1b0d4d40 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -570,7 +570,7 @@ if ($id) { $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects(0, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
'; } else { From e4987c8f3bc22f64eac05e7bcb0fbaf7fa245670 Mon Sep 17 00:00:00 2001 From: Eric <1468823+rycks@users.noreply.github.com> Date: Wed, 18 Oct 2023 03:05:05 +0200 Subject: [PATCH 04/15] fix #26244 todelete could contains dupplicate val (#26245) --- htdocs/core/actions_massactions.inc.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 225e118b2a0..b2cd79f2c9b 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1291,7 +1291,9 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' $objecttmp = new $objectclass($db); $nbok = 0; - foreach ($toselect as $toselectid) { + //$toselect could contain duplicate entries, cf https://github.com/Dolibarr/dolibarr/issues/26244 + $unique_arr = array_unique($toselect); + foreach ($unique_arr as $toselectid) { $result = $objecttmp->fetch($toselectid); if ($result > 0) { // Refuse deletion for some objects/status From 0975b2bbb8ccdc671cfce49a0fa6a37b2eae8a9f Mon Sep 17 00:00:00 2001 From: Eric <1468823+rycks@users.noreply.github.com> Date: Fri, 20 Oct 2023 02:30:15 +0200 Subject: [PATCH 05/15] check if $_FILES['userfile'] is an array before getting values (#26269) --- htdocs/core/actions_linkedfiles.inc.php | 2 +- htdocs/ecm/index.php | 11 +++++++---- .../tpl/expensereport_linktofile.tpl.php | 2 +- htdocs/website/index.php | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 3e2438f63d3..9a37eb17e12 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -38,7 +38,7 @@ if (GETPOST('uploadform', 'int') && empty($_POST) && empty($_FILES)) { // Submit file/link if (GETPOST('sendit', 'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC) && (!isset($permissiontoadd) || $permissiontoadd)) { - if (!empty($_FILES)) { + if (!empty($_FILES) && is_array($_FILES['userfile'])) { if (is_array($_FILES['userfile']['tmp_name'])) { $userfiles = $_FILES['userfile']['tmp_name']; } else { diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index 813ee69b6fb..d9e5291c2dc 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -102,10 +102,13 @@ if (GETPOST("sendit", 'alphanohtml') && !empty($conf->global->MAIN_UPLOAD_DOC)) } $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; - if (is_array($_FILES['userfile']['tmp_name'])) { - $userfiles = $_FILES['userfile']['tmp_name']; - } else { - $userfiles = array($_FILES['userfile']['tmp_name']); + $userfiles = []; + if (is_array($_FILES['userfile'])) { + if (is_array($_FILES['userfile']['tmp_name'])) { + $userfiles = $_FILES['userfile']['tmp_name']; + } else { + $userfiles = array($_FILES['userfile']['tmp_name']); + } } foreach ($userfiles as $key => $userfile) { diff --git a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php index 9264400a71f..8b158f86dc4 100644 --- a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php +++ b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php @@ -97,7 +97,7 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) { $checked = ''; //var_dump(GETPOST($file['relativename'])); var_dump($file['relativename']); var_dump($_FILES['userfile']['name']); // If a file was just uploaded, we check to preselect it - if (is_array($_FILES['userfile']['name'])) { + if (is_array($_FILES['userfile']) && is_array($_FILES['userfile']['name'])) { foreach ($_FILES['userfile']['name'] as $tmpfile) { if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) { $checked = ' checked'; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index b7062b4f599..772832ea2cc 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -2221,7 +2221,7 @@ if ($action == 'importsiteconfirm' && $usercanedit) { $fileofzip = ''; if (GETPOSTISSET('templateuserfile')) { $fileofzip = DOL_DATA_ROOT.'/doctemplates/websites/'.GETPOST('templateuserfile', 'alpha'); - } elseif (!empty($_FILES)) { + } elseif (!empty($_FILES) && is_array($_FILES['userfile'])) { if (is_array($_FILES['userfile']['tmp_name'])) { $userfiles = $_FILES['userfile']['tmp_name']; } else { From a17447cd0740b2484a30413488cdcb26b1aff7f1 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 20 Oct 2023 04:08:14 +0200 Subject: [PATCH 06/15] FIX #26100 - Ticket - On edit, list of closed project must be excluded (#26223) * FIX #26100 - Ticket - On creation, list of closed project are excluded * In project list, discard closed projects on ticket creation/edit --- htdocs/ticket/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 334dcdf6aa4..7728feaf98a 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -924,7 +924,7 @@ if ($action == 'create' || $action == 'presend') { $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1, 0, 'maxwidth500'); + $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1, 1, 0, 0, '', 1, 0, 'maxwidth500'); $morehtmlref .= ''; $morehtmlref .= '
'; } else { From e79f7706ade7a8a3ec649d615ae4b515025a569f Mon Sep 17 00:00:00 2001 From: Thibault Fiacre <57494317+atm-thibaultf@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:49:55 +0200 Subject: [PATCH 07/15] FIX_add_customer_ref_on_linked_shipment (#26349) Adding missing customer reference for shipment on linked object block --- htdocs/expedition/tpl/linkedobjectblock.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expedition/tpl/linkedobjectblock.tpl.php b/htdocs/expedition/tpl/linkedobjectblock.tpl.php index b00d63eaba1..8c2b03ef085 100644 --- a/htdocs/expedition/tpl/linkedobjectblock.tpl.php +++ b/htdocs/expedition/tpl/linkedobjectblock.tpl.php @@ -47,7 +47,7 @@ foreach ($linkedObjectBlock as $key => $objectlink) { trans("Shipment"); ?> getNomUrl(1); ?> - + ref_customer; ?> date_delivery, 'day'); ?> rights->expedition->lire) { From 9bfeb5e4245243539bcc3f4794e6712938b2601d Mon Sep 17 00:00:00 2001 From: atm-lena <52402938+atm-lena@users.noreply.github.com> Date: Thu, 26 Oct 2023 17:13:36 +0200 Subject: [PATCH 08/15] Add Hook "printFieldListFrom" in supplier order list (#26376) Co-authored-by: atm-lena --- htdocs/fourn/commande/list.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 4b2d08f18d8..7c8cdeb2dfd 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -531,6 +531,9 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet"; // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; $sql .= ' WHERE cf.fk_soc = s.rowid'; $sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')'; if ($socid > 0) $sql .= " AND s.rowid = ".$socid; From 35a25599e58c0c48861d813b368e3fbd1a18da3c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 5 Nov 2023 19:28:04 +0100 Subject: [PATCH 09/15] FIX Backport memory fix for fatal error when +100000 products --- htdocs/product/list.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index b3b4e3be2dd..30131312903 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -328,10 +328,14 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) { $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; + +$sqlfields = $sql; // $sql fields to remove for count total + $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; if (!empty($searchCategoryProductList) || !empty($catid)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; +$linktopfp = " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; +$sql .= $linktopfp; // multilang if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$langs->getDefaultLang()."'"; @@ -426,8 +430,24 @@ $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + /* The fast and low memory method to get and count full list converts the sql into a sql count */ + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); + + $resql = $db->query($sqlforcount); + if ($resql) { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + } else { + dol_print_error($db); + } + + /* $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); + */ + if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 { $page = 0; From 9c7381601fa4b2a63de38e32ce657f9eb9094cea Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 5 Nov 2023 19:35:34 +0100 Subject: [PATCH 10/15] Backport or better module compatibility --- htdocs/core/lib/functions.lib.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 0084a4a33c8..ab396c5ed26 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -64,6 +64,17 @@ function getDolGlobalInt($key) return (int) (empty($conf->global->$key) ? 0 : $conf->global->$key); } +/** + * Is Dolibarr module enabled + * @param string $module module name to check + * @return int + */ +function isModEnabled($module) +{ + global $conf; + return !empty($conf->$module->enabled); +} + /** * Return a DoliDB instance (database handler). * From e64d1f6e468d0727147ad3d296a90de255979f59 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 6 Nov 2023 00:16:26 +0100 Subject: [PATCH 11/15] Fix phpcs --- htdocs/product/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 7dc9483b00a..4f30e146f56 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -589,7 +589,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); */ - + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; From 7a7869aeb346b3dab6ca0160c1aec02b1b9eb567 Mon Sep 17 00:00:00 2001 From: Pichi1966 <57623859+josett225@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:10:37 +0100 Subject: [PATCH 12/15] FIX # Bug Estimated Stock at date value in V14 (#26479) In stockatdate page, the estimatedvalue is wrong. Backport of V17 solution as explained in #23782 --- htdocs/product/stock/stockatdate.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index 4892004db72..f8c9437b928 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -242,7 +242,7 @@ $num = 0; $title = $langs->trans('StockAtDate'); -$sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,'; +$sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price, p.pmp,'; $sql .= ' p.price_ttc, p.price_base_type, p.fk_product_type, p.desiredstock, p.seuil_stock_alerte,'; $sql .= ' p.tms as datem, p.duration, p.tobuy, p.stock, '; if ($fk_warehouse > 0) { @@ -562,8 +562,8 @@ while ($i < ($limit ? min($num, $limit) : $num)) { // PMP value print ''; - if (price2num($objp->estimatedvalue, 'MT')) { - print price(price2num($objp->estimatedvalue, 'MT'), 1); + if (price2num($stock * $objp->pmp, 'MT')) { + print ''.price(price2num($stock * $objp->pmp, 'MT'), 1).''; } else { print ''; } From 05f42d1341fb4166295f97f6609ca2b324fb32d6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 Nov 2023 11:15:23 +0100 Subject: [PATCH 13/15] Fix phpcs --- htdocs/product/stock/stockatdate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index f8c9437b928..86c1b89eb95 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -563,7 +563,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) { // PMP value print ''; if (price2num($stock * $objp->pmp, 'MT')) { - print ''.price(price2num($stock * $objp->pmp, 'MT'), 1).''; + print ''.price(price2num($stock * $objp->pmp, 'MT'), 1).''; } else { print ''; } From 785c85205bf3860473044602ffc73086ac1c7165 Mon Sep 17 00:00:00 2001 From: lvessiller-opendsi Date: Wed, 8 Nov 2023 17:32:23 +0100 Subject: [PATCH 14/15] FIX substitute project variables in invoice documents (#26445) * FIX substitute project variables in invoice documents * Keep key to substitute if no link with project --- htdocs/compta/facture/card.php | 3 +++ htdocs/core/lib/functions.lib.php | 15 ++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 69155ecd8c7..7fc8ba9721e 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -118,6 +118,9 @@ if ($id > 0 || !empty($ref)) { $fetch_situation = true; } $ret = $object->fetch($id, $ref, '', '', $fetch_situation); + if ($ret > 0 && isset($object->fk_project)) { + $ret = $object->fetch_project(); + } } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c95c93b67d4..7c0583519bd 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7116,15 +7116,16 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__CANDIDATE_LASTNAME__'] = $object->lastname; } + $project = null; if (is_object($object->project)) { - $substitutionarray['__PROJECT_ID__'] = (is_object($object->project) ? $object->project->id : ''); - $substitutionarray['__PROJECT_REF__'] = (is_object($object->project) ? $object->project->ref : ''); - $substitutionarray['__PROJECT_NAME__'] = (is_object($object->project) ? $object->project->title : ''); + $project = $object->project; + } elseif (is_object($object->projet)) { // Deprecated, for backward compatibility + $project = $object->projet; } - if (is_object($object->projet)) { // Deprecated, for backward compatibility - $substitutionarray['__PROJECT_ID__'] = (is_object($object->projet) ? $object->projet->id : ''); - $substitutionarray['__PROJECT_REF__'] = (is_object($object->projet) ? $object->projet->ref : ''); - $substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet) ? $object->projet->title : ''); + if ($project) { + $substitutionarray['__PROJECT_ID__'] = $project->id; + $substitutionarray['__PROJECT_REF__'] = $project->ref; + $substitutionarray['__PROJECT_NAME__'] = $project->title; } if (is_object($object) && $object->element == 'project') { $substitutionarray['__PROJECT_NAME__'] = $object->title; From cc452f2136cf85e4ec3c3c68f598465d7819b194 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 12 Nov 2023 22:16:47 +0100 Subject: [PATCH 15/15] FIX Accountancy - Possibility to write in bookkeeping expense report operation with some line not bound (#26545) * FIX Accountancy - Possibility to write in bookkeeping expense report operation with some line not bound * Update expensereportsjournal.php --------- Co-authored-by: Laurent Destailleur --- .../journal/expensereportsjournal.php | 85 ++++++++++++++++--- 1 file changed, 75 insertions(+), 10 deletions(-) diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index 8a2bbcdf81c..16435e10d50 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -3,11 +3,11 @@ * Copyright (C) 2007-2010 Jean Heimburger * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013-2021 Alexandre Spangaro + * Copyright (C) 2013-2023 Alexandre Spangaro * Copyright (C) 2013-2016 Olivier Geffroy * Copyright (C) 2013-2016 Florian Henry * Copyright (C) 2018 Frédéric France - * Copyright (C) 2018 Eric Seigne + * Copyright (C) 2018 Eric Seigne * * 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 @@ -68,6 +68,7 @@ if (empty($user->rights->accounting->mouvements->lire)) { accessforbidden(); } +$error = 0; /* * Actions @@ -201,8 +202,27 @@ if ($result) { dol_print_error($db); } +// Load all unbound lines +$sql = "SELECT fk_expensereport, COUNT(erd.rowid) as nb"; +$sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd"; +$sql .= " WHERE erd.fk_code_ventilation <= 0"; +$sql .= " AND erd.total_ttc <> 0"; +$sql .= " AND fk_expensereport IN (".$db->sanitize(join(",", array_keys($taber))).")"; +$sql .= " GROUP BY fk_expensereport"; +$resql = $db->query($sql); + +$num = $db->num_rows($resql); +$i = 0; +while ($i < $num) { + $obj = $db->fetch_object($resql); + if ($obj->nb > 0) { + $errorforinvoice[$obj->fk_expensereport] = 'somelinesarenotbound'; + } + $i++; +} + // Bookkeeping Write -if ($action == 'writebookkeeping') { +if ($action == 'writebookkeeping' && !$error) { $now = dol_now(); $error = 0; @@ -217,6 +237,13 @@ if ($action == 'writebookkeeping') { $db->begin(); + // Error if some lines are not binded/ready to be journalized + if ($errorforinvoice[$key] == 'somelinesarenotbound') { + $error++; + $errorforline++; + setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors'); + } + // Thirdparty if (!$errorforline) { foreach ($tabttc[$key] as $k => $mt) { @@ -253,10 +280,12 @@ if ($action == 'writebookkeeping') { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists $error++; $errorforline++; + $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { $error++; $errorforline++; + $errorforinvoice[$key] = 'other'; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } @@ -302,10 +331,12 @@ if ($action == 'writebookkeeping') { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists $error++; $errorforline++; + $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { $error++; $errorforline++; + $errorforinvoice[$key] = 'other'; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } @@ -364,10 +395,12 @@ if ($action == 'writebookkeeping') { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists $error++; $errorforline++; + $errorforinvoice[$key] = 'alreadyjournalized'; //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { $error++; $errorforline++; + $errorforinvoice[$key] = 'other'; setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } @@ -376,10 +409,11 @@ if ($action == 'writebookkeeping') { } } - // Protection against a bug on line before - if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) { + // Protection against a bug on lines before + if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) { $error++; $errorforline++; + $errorforinvoice[$key] = 'amountsnotbalanced'; setEventMessages('Try to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors'); } @@ -433,7 +467,7 @@ $form = new Form($db); $userstatic = new User($db); // Export -if ($action == 'exportcsv') { // ISO and not UTF8 ! +if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 ! $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $filename = 'journal'; @@ -503,7 +537,7 @@ if (empty($action) || $action == 'view') { $periodlink = ''; $exportlink = ''; $builddate = dol_now(); - $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; + $description = $langs->trans("DescJournalOnlyBindedVisible").'
'; $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger")); $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); @@ -567,11 +601,11 @@ if (empty($action) || $action == 'view') { print "".$langs->trans("AccountAccounting").""; print "".$langs->trans("SubledgerAccount").""; print "".$langs->trans("LabelOperation").""; - print ''.$langs->trans("Debit").""; - print ''.$langs->trans("Credit").""; + print ''.$langs->trans("Debit").""; + print ''.$langs->trans("Credit").""; print "\n"; - $r = ''; + $i = 0; $expensereportstatic = new ExpenseReport($db); $expensereportlinestatic = new ExpenseReportLine($db); @@ -583,6 +617,27 @@ if (empty($action) || $action == 'view') { $date = dol_print_date($val["date"], 'day'); + if ($errorforinvoice[$key] == 'somelinesarenotbound') { + print ''; + print ""; + print "".$date.""; + print "".$expensereportstatic->getNomUrl(1).""; + // Account + print ""; + print ''.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).''; + print ''; + // Subledger account + print ""; + print ''; + print ""; + print ""; + print ''; + print ''; + print ""; + + $i++; + } + // Fees foreach ($tabht[$key] as $k => $mt) { $accountingaccount = new AccountingAccount($db); @@ -613,6 +668,8 @@ if (empty($action) || $action == 'view') { print ''.($mt >= 0 ? price($mt) : '').""; print ''.($mt < 0 ? price(-$mt) : '').""; print ""; + + $i++; } } @@ -647,6 +704,8 @@ if (empty($action) || $action == 'view') { print ''.($mt < 0 ? price(-$mt) : '').""; print ''.($mt >= 0 ? price($mt) : '').""; print ""; + + $i++; } // VAT @@ -683,11 +742,17 @@ if (empty($action) || $action == 'view') { print ''.($mt >= 0 ? price($mt) : '').""; print ''.($mt < 0 ? price(-$mt) : '').""; print ""; + + $i++; } } } } + if (!$i) { + print ''.$langs->trans("NoRecordFound").''; + } + print ""; print '';