Merge branch '15.0' of git@github.com:Dolibarr/dolibarr.git into 16.0

Conflicts:
	htdocs/product/stock/stockatdate.php
This commit is contained in:
Laurent Destailleur 2023-11-12 22:58:23 +01:00
commit 1dbb3f1f34
14 changed files with 131 additions and 35 deletions

View file

@ -3,11 +3,11 @@
* Copyright (C) 2007-2010 Jean Heimburger <jean@tiaris.info>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2013-2023 Alexandre Spangaro <aspangaro@easya.solutions>
* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 Eric Seigne <eric.seigne@cap-rel.fr>
* Copyright (C) 2018 Eric Seigne <eric.seigne@cap-rel.fr>
*
* 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").'<br>';
$description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
$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 "<td>".$langs->trans("AccountAccounting")."</td>";
print "<td>".$langs->trans("SubledgerAccount")."</td>";
print "<td>".$langs->trans("LabelOperation")."</td>";
print '<td class="right">'.$langs->trans("Debit")."</td>";
print '<td class="right">'.$langs->trans("Credit")."</td>";
print '<td class="center">'.$langs->trans("Debit")."</td>";
print '<td class="center">'.$langs->trans("Credit")."</td>";
print "</tr>\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 '<tr class="oddeven">';
print "<!-- Some lines are not bound -->";
print "<td>".$date."</td>";
print "<td>".$expensereportstatic->getNomUrl(1)."</td>";
// Account
print "<td>";
print '<span class="error">'.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).'</span>';
print '</td>';
// Subledger account
print "<td>";
print '</td>';
print "<td>";
print "</td>";
print '<td class="right"></td>';
print '<td class="right"></td>';
print "</tr>";
$i++;
}
// Fees
foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db);
@ -613,6 +668,8 @@ if (empty($action) || $action == 'view') {
print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
print "</tr>";
$i++;
}
}
@ -647,6 +704,8 @@ if (empty($action) || $action == 'view') {
print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
print "</tr>";
$i++;
}
// VAT
@ -683,11 +742,17 @@ if (empty($action) || $action == 'view') {
print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
print "</tr>";
$i++;
}
}
}
}
if (!$i) {
print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
}
print "</table>";
print '</div>';

View file

@ -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;

View file

@ -565,7 +565,7 @@ if ($id) {
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$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 .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>';
} else {

View file

@ -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();
}
}
}

View file

@ -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 {

View file

@ -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

View file

@ -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;

View file

@ -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) {

View file

@ -47,7 +47,7 @@ foreach ($linkedObjectBlock as $key => $objectlink) {
<tr class="<?php echo $trclass; ?>">
<td><?php echo $langs->trans("Shipment"); ?></td>
<td><?php echo $objectlink->getNomUrl(1); ?></td>
<td></td>
<td><?php echo $objectlink->ref_customer; ?></td>
<td class="center"><?php echo dol_print_date($objectlink->date_delivery, 'day'); ?></td>
<td class="right"><?php
if ($user->rights->expedition->lire) {

View file

@ -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';

View file

@ -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 '</td>';
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 '</td>';
if (!$i) {

View file

@ -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 '<td class="right">';
if (price2num($objp->estimatedvalue, 'MT')) {
print '<span class="amount">'.price(price2num($objp->estimatedvalue, 'MT'), 1).'</span>';
if (price2num($stock * $objp->pmp, 'MT')) {
print '<span class="amount">'.price(price2num($stock * $objp->pmp, 'MT'), 1).'</span>';
} else {
print '';
}

View file

@ -967,7 +967,7 @@ if ($action == 'create' || $action == 'presend') {
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$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 .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>';
} else {

View file

@ -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 {