2
0
forked from Wavyzz/dolibarr

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

Conflicts:
	htdocs/accountancy/journal/expensereportsjournal.php
This commit is contained in:
Laurent Destailleur
2023-11-12 23:02:18 +01:00
3 changed files with 83 additions and 14 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';
@@ -573,7 +607,7 @@ if (empty($action) || $action == 'view') {
print '<td class="right">'.$langs->trans("AccountingCredit")."</td>";
print "</tr>\n";
$r = '';
$i = 0;
$expensereportstatic = new ExpenseReport($db);
$expensereportlinestatic = new ExpenseReportLine($db);
@@ -585,6 +619,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);
@@ -615,6 +670,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++;
}
}
@@ -649,6 +706,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
@@ -685,11 +744,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

@@ -125,6 +125,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

@@ -7847,15 +7847,16 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
$substitutionarray['__ATTENDEE_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;