diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index d38e49c390e..fcadaf2a25b 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 ''; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 7b7389b5f79..d765fb82253 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -971,7 +971,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; diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 64bcb9787f5..9bb35d6b304 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -565,7 +565,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 { diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index e426087a0e0..7c3767c9932 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -122,6 +122,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/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 86d4e923131..d450f8d9dd1 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -49,7 +49,7 @@ if ((GETPOST('sendit', 'alpha') // Submit file/link if (GETPOST('sendit', 'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC) && !empty($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/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 5a27aaa4306..ca8232c584b 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1021,7 +1021,10 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' $objecttmp = new $objectclass($db); $nbok = 0; $TMsg = array(); - 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 diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9827414c3ff..1befecf65c2 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7526,15 +7526,16 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__CANDIDATE_LASTNAME__'] = isset($object->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; diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index aec4b54bc6c..528b08c035d 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/expedition/tpl/linkedobjectblock.tpl.php b/htdocs/expedition/tpl/linkedobjectblock.tpl.php index 2305b0d4fac..cc4fff39097 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) { diff --git a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php index 3835740dd40..5adf0a4a55c 100644 --- a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php +++ b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php @@ -106,7 +106,7 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) { //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/product/list.php b/htdocs/product/list.php index ee1b0d4cd3b..8507026d302 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -427,6 +427,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) { $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // 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 (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); @@ -437,7 +440,8 @@ if (!empty($extrafields->attributes[$object->table_element]['label']) && is_arra 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 = '".$db->escape($langs->getDefaultLang())."'"; @@ -593,8 +597,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; $offset = 0; @@ -1760,7 +1780,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) { @@ -1774,7 +1794,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) { diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index 4fe9632054d..2718cb27f6e 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -257,7 +257,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) { @@ -589,8 +589,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 ''; } diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 9780028a36d..16134ca2d7a 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -967,7 +967,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 { diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 65a4bdc92a6..d225e327864 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -2271,7 +2271,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 {