mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-06 09:02:59 +01:00
Close #26542. The PR was not atomic and contains both a fix for a
control and a change in priority of lines processed. This generated conflicts in merge process with old version. So I try to report the most important (the fix) manually.
This commit is contained in:
@@ -71,6 +71,9 @@ if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
$error = 0;
|
||||
$errorforinvoice = array();
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
@@ -213,8 +216,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;
|
||||
|
||||
@@ -229,6 +251,13 @@ if ($action == 'writebookkeeping') {
|
||||
|
||||
$db->begin();
|
||||
|
||||
// Error if some lines are not binded/ready to be journalized
|
||||
if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') {
|
||||
$error++;
|
||||
$errorforline++;
|
||||
setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors');
|
||||
}
|
||||
|
||||
// Thirdparty
|
||||
if (!$errorforline) {
|
||||
foreach ($tabttc[$key] as $k => $mt) {
|
||||
@@ -265,10 +294,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');
|
||||
}
|
||||
}
|
||||
@@ -314,10 +345,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,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');
|
||||
}
|
||||
}
|
||||
@@ -389,9 +424,10 @@ if ($action == 'writebookkeeping') {
|
||||
}
|
||||
|
||||
// Protection against a bug on line before
|
||||
if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) {
|
||||
if (!$errorforline && price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) {
|
||||
$error++;
|
||||
$errorforline++;
|
||||
$errorforinvoice[$key] = 'amountsnotbalanced';
|
||||
setEventMessages('We tried to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors');
|
||||
}
|
||||
|
||||
@@ -445,7 +481,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';
|
||||
|
||||
Reference in New Issue
Block a user