Revert bugged enhancement. Too many critical bugs introduced.

This commit is contained in:
Laurent Destailleur 2023-03-18 16:04:59 +01:00
parent ec43a8626e
commit 84cb791dae

View File

@ -4,7 +4,6 @@
* Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr> * Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2022 Waël Almoman <info@almoman.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -45,7 +44,7 @@ $cancel = GETPOST('cancel', 'aZ09');
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
$id = GETPOST('id', 'int'); // id of record $id = GETPOST('id', 'int'); // id of record
$mode = $mode = $action == 'create' ? "_tmp" : GETPOST('mode', 'aZ09'); // '' or '_tmp' $mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
$piece_num = GETPOST("piece_num", 'int'); // id of transaction (several lines share the same transaction id) $piece_num = GETPOST("piece_num", 'int'); // id of transaction (several lines share the same transaction id)
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
@ -55,15 +54,10 @@ $accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml');
$accountingaccount->fetch(null, $accountingaccount_number, true); $accountingaccount->fetch(null, $accountingaccount_number, true);
$accountingaccount_label = $accountingaccount->label; $accountingaccount_label = $accountingaccount->label;
$journal_code = GETPOST('code_journal', 'alpha') ? GETPOST('code_journal', 'alpha') : "NULL"; $journal_code = GETPOST('code_journal', 'alpha');
$accountingjournal->fetch(null, $journal_code); $accountingjournal->fetch(null, $journal_code);
$journal_label = $accountingjournal->label; $journal_label = $accountingjournal->label;
$next_num_mvt = (int) GETPOST('next_num_mvt', 'alpha');
$doc_ref = (string) GETPOST('doc_ref', 'alpha');
$doc_date = (string) GETPOST('doc_date', 'alpha');
$doc_date = $doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
$subledger_account = GETPOST('subledger_account', 'alphanohtml'); $subledger_account = GETPOST('subledger_account', 'alphanohtml');
if ($subledger_account == -1) { if ($subledger_account == -1) {
$subledger_account = null; $subledger_account = null;
@ -78,10 +72,6 @@ $save = GETPOST('save', 'alpha');
if (!empty($save)) { if (!empty($save)) {
$action = 'add'; $action = 'add';
} }
$valid = GETPOST('validate', 'alpha');
if (!empty($valid)) {
$action = 'valid';
}
$update = GETPOST('update', 'alpha'); $update = GETPOST('update', 'alpha');
if (!empty($update)) { if (!empty($update)) {
$action = 'confirm_update'; $action = 'confirm_update';
@ -166,29 +156,15 @@ if ($action == "confirm_update") {
} }
} }
} }
} elseif ($action == 'add' || $action == 'valid') { } elseif ($action == "add") {
$error = 0; $error = 0;
if (array_sum($debit) != array_sum($credit)) { if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) {
$action = 'add';
}
foreach ($accountingaccount_number as $key => $value) {
$accountingaccount->fetch(null, $accountingaccount_number[$key], true);
$accountingaccount_label[$key] = $accountingaccount->label[$key];
// if one added row is empty remove it before continue
if ($key < 1 && (empty($accountingaccount_number[$key]) || $accountingaccount_number[$key] == '-1') || (floatval($debit[$key]) == 0.0) && (floatval($credit[$key]) == 0.0)) {
continue;
}
if ((floatval($debit[$key]) != 0.0) && (floatval($credit[$key]) != 0.0)) {
$error++; $error++;
setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
$action = ''; $action = '';
} }
if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
if (empty($accountingaccount_number[$key]) || $accountingaccount_number[$key] == '-1') {
$error++; $error++;
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
$action = ''; $action = '';
@ -196,49 +172,48 @@ if ($action == "confirm_update") {
if (!$error) { if (!$error) {
$object = new BookKeeping($db); $object = new BookKeeping($db);
$object->numero_compte = $accountingaccount_number[$key];
$object->subledger_account = $subledger_account[$key]; $object->numero_compte = $accountingaccount_number;
$object->subledger_label = $subledger_label[$key]; $object->subledger_account = $subledger_account;
$object->label_compte = $accountingaccount_label[$key]; $object->subledger_label = $subledger_label;
$object->label_operation = $label_operation[$key]; $object->label_compte = $accountingaccount_label;
$object->debit = price2num($debit[$key]); $object->label_operation = $label_operation;
$object->credit = price2num($credit[$key]); $object->debit = $debit;
$object->doc_date = $doc_date; $object->credit = $credit;
$object->doc_date = (string) GETPOST('doc_date', 'alpha');
$object->doc_type = (string) GETPOST('doc_type', 'alpha'); $object->doc_type = (string) GETPOST('doc_type', 'alpha');
$object->piece_num = $piece_num; $object->piece_num = $piece_num;
$object->doc_ref = $doc_ref; $object->doc_ref = (string) GETPOST('doc_ref', 'alpha');
$object->code_journal = $journal_code; $object->code_journal = $journal_code;
$object->journal_label = $journal_label; $object->journal_label = $journal_label;
$object->fk_doc = GETPOSTINT('fk_doc'); $object->fk_doc = GETPOSTINT('fk_doc');
$object->fk_docdet = GETPOSTINT('fk_docdet'); $object->fk_docdet = GETPOSTINT('fk_docdet');
if (floatval($debit[$key]) != 0.0) { if (floatval($debit) != 0.0) {
$object->montant = $object->debit; // deprecated $object->montant = $debit; // deprecated
$object->amount = $object->debit; $object->amount = $debit;
$object->sens = 'D'; $object->sens = 'D';
} }
if (floatval($credit[$key]) != 0.0) { if (floatval($credit) != 0.0) {
$object->montant = $object->credit; // deprecated $object->montant = $credit; // deprecated
$object->amount = $object->credit; $object->amount = $credit;
$object->sens = 'C'; $object->sens = 'C';
} }
$result = $object->createStd($user, false, $mode); $result = $object->createStd($user, false, $mode);
if ($result < 0) { if ($result < 0) {
$error++;
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} } else {
}
}
if (empty($error)) {
if ($mode != '_tmp') { if ($mode != '_tmp') {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
} }
$debit = 0; $debit = 0;
$credit = 0; $credit = 0;
$action = $action == 'add' ? '' : $action ; // stay in valid mode when not adding line $action = '';
}
} }
} elseif ($action == "confirm_delete") { } elseif ($action == "confirm_delete") {
$object = new BookKeeping($db); $object = new BookKeeping($db);
@ -255,28 +230,17 @@ if ($action == "confirm_update") {
} }
} }
$action = ''; $action = '';
} elseif ($action == 'create') { } elseif ($action == "confirm_create") {
$error = 0; $error = 0;
$object = new BookKeeping($db); $object = new BookKeeping($db);
$next_num_mvt = !empty($next_num_mvt) ? $next_num_mvt : $object->getNextNumMvt('_tmp');
$doc_ref = !empty($doc_ref) ? $doc_ref : $next_num_mvt;
if (empty($doc_date)) {
$tmp_date = dol_getdate(dol_now());
$_POST['doc_dateday'] = $tmp_date['mday'];
$_POST['doc_datemonth'] = $tmp_date['mon'];
$_POST['doc_dateyear'] = $tmp_date['year'];
unset($tmp_date);
}
if (!$journal_code || $journal_code == '-1') { if (!$journal_code || $journal_code == '-1') {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
$action = 'create'; $action = 'create';
$error++; $error++;
} }
if (empty($doc_ref)) { if (!GETPOST('doc_ref', 'alpha')) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
$action = 'create'; $action = 'create';
$error++; $error++;
@ -288,8 +252,8 @@ if ($action == "confirm_update") {
$object->credit = 0; $object->credit = 0;
$object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
$object->doc_type = GETPOST('doc_type', 'alpha'); $object->doc_type = GETPOST('doc_type', 'alpha');
$object->piece_num = $next_num_mvt; $object->piece_num = GETPOST('next_num_mvt', 'alpha');
$object->doc_ref = $doc_ref; $object->doc_ref = GETPOST('doc_ref', 'alpha');
$object->code_journal = $journal_code; $object->code_journal = $journal_code;
$object->journal_label = $journal_label; $object->journal_label = $journal_label;
$object->fk_doc = 0; $object->fk_doc = 0;
@ -338,7 +302,7 @@ if ($action == 'setjournal') {
} }
if ($action == 'setdocref') { if ($action == 'setdocref') {
$refdoc = $doc_ref; $refdoc = GETPOST('doc_ref', 'alpha');
$result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode); $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
if ($result < 0) { if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
@ -369,7 +333,7 @@ if ($action == 'valid') {
$html = new Form($db); $html = new Form($db);
$formaccounting = new FormAccounting($db); $formaccounting = new FormAccounting($db);
$title = $langs->trans($mode =="_tmp" ? "CreateMvts": "UpdateMvts"); $title = $langs->trans("CreateMvts");
llxHeader('', $title); llxHeader('', $title);
@ -379,21 +343,77 @@ if ($action == 'delete') {
print $formconfirm; print $formconfirm;
} }
if ($action == 'create') {
print load_fiche_titre($title);
$object = new BookKeeping($db); $object = new BookKeeping($db);
$result = $object->fetchPerMvt($piece_num, $mode); $next_num_mvt = $object->getNextNumMvt('_tmp');
if ($result < 0) {
if (empty($next_num_mvt)) {
dol_print_error('', 'Failed to get next piece number');
}
print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="confirm_create">'."\n";
print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
print '<input type="hidden" name="mode" value="_tmp">'."\n";
print dol_get_fiche_head();
print '<table class="border centpercent">';
/*print '<tr>';
print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
print '<td>' . $next_num_mvt . '</td>';
print '</tr>';*/
print '<tr>';
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>';
print '<td>';
print $html->selectDate('', 'doc_date', '', '', '', "create_mvt", 1, 1);
print '</td>';
print '</tr>';
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
print '</tr>';
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("Piece").'</td>';
print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
print '</tr>';
/*
print '<tr>';
print '<td>' . $langs->trans("Doctype") . '</td>';
print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>';
print '</tr>';
*/
print '</table>';
print dol_get_fiche_end();
print $form->buttonsSaveCancel("Create");
print '</form>';
} else {
$object = new BookKeeping($db);
$result = $object->fetchPerMvt($piece_num, $mode);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
if (!empty($object->piece_num)) { if (!empty($object->piece_num)) {
$backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>'; $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
print load_fiche_titre($langs->trans($mode =="_tmp" ? "CreateMvts": "UpdateMvts"), $backlink); print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">'; if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'" />';
}
$head = array(); $head = array();
$h = 0; $h = 0;
$head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$object->piece_num.($mode ? '&mode='.$mode : ''); $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$object->piece_num.($mode ? '&mode='.$mode : '');
@ -411,35 +431,93 @@ if (!empty($object->piece_num)) {
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield" width="100%">'; print '<table class="border tableforfield" width="100%">';
/*print '<tr>'; // Account movement
print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
print '<td>' . $next_num_mvt . '</td>';
print '</tr>';*/
print '<tr>'; print '<tr>';
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>'; print '<td class="titlefield">'.$langs->trans("NumMvts").'</td>';
print '<td>'; print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
print $html->selectDate($doc_date, 'doc_date', '', '', '', "create_mvt", 1, 1); print '</tr>';
// Date
print '<tr><td>';
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans('Docdate');
print '</td>';
if ($action != 'editdate') {
print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdate&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('SetDate'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'editdate') {
print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdate">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', '', '', '', "setdate");
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
}
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
print '<tr>'; // Journal
print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>'; print '<tr><td>';
print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Codejournal');
print '</td>';
if ($action != 'editjournal') {
print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editjournal&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td>';
if ($action == 'editjournal') {
print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setjournal">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, array(), 1, 1);
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
print $object->code_journal;
}
print '</td>';
print '</tr>'; print '</tr>';
print '<tr>'; // Ref document
print '<td class="fieldrequired">'.$langs->trans("Piece").'</td>'; print '<tr><td>';
print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.$doc_ref.'" /></td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Piece');
print '</td>';
if ($action != 'editdocref') {
print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdocref&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td>';
if ($action == 'editdocref') {
print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdocref">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
print $object->doc_ref;
}
print '</td>';
print '</tr>'; print '</tr>';
/*
print '<tr>';
print '<td>' . $langs->trans("Doctype") . '</td>';
print '<td><input type="text" class="minwidth200 name="doc_type" value="" /></td>';
print '</tr>';
*/
print '</table>'; print '</table>';
print '</div>'; print '</div>';
@ -469,7 +547,7 @@ if (!empty($object->piece_num)) {
if ($mode != "_tmp") { if ($mode != "_tmp") {
// Date document export // Date document export
print '<tr>'; print '<tr>';
print '<td class="titlefield">'.$langs->trans("DateExport").'</td>'; print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>';
print '<td>'; print '<td>';
print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : '&nbsp;'; print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
print '</td>'; print '</td>';
@ -477,12 +555,13 @@ if (!empty($object->piece_num)) {
// Date document validation // Date document validation
print '<tr>'; print '<tr>';
print '<td class="titlefield">'.$langs->trans("DateValidation").'</td>'; print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>';
print '<td>'; print '<td>';
print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : '&nbsp;'; print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }
// Validate // Validate
/* /*
print '<tr>'; print '<tr>';
@ -505,7 +584,8 @@ if (!empty($object->piece_num)) {
/* /*
print '<tr>'; print '<tr>';
print '<td class="titlefield">' . $langs->trans("Control") . '</td>'; print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
if ($object->doc_type == 'customer_invoice') { if ($object->doc_type == 'customer_invoice')
{
$sqlmid = 'SELECT rowid as ref'; $sqlmid = 'SELECT rowid as ref';
$sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac"; $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
$sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc); $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
@ -516,15 +596,16 @@ if (!empty($object->piece_num)) {
$invoicestatic = new Facture($db); $invoicestatic = new Facture($db);
$invoicestatic->fetch($objmid->ref); $invoicestatic->fetch($objmid->ref);
$ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1); $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
} else {
dol_print_error($db);
} }
else dol_print_error($db);
} }
print '<td>' . $ref .'</td>'; print '<td>' . $ref .'</td>';
print '</tr>'; print '</tr>';
*/ */
print "</table>\n"; print "</table>\n";
print '</div>';
print dol_get_fiche_end(); print dol_get_fiche_end();
print '<div class="clearboth"></div>'; print '<div class="clearboth"></div>';
@ -532,21 +613,25 @@ if (!empty($object->piece_num)) {
print '<br>'; print '<br>';
$result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
if ($result < 0) { if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} else { } else {
// List of movements // List of movements
print load_fiche_titre($langs->trans("ListeMvts"), '', ''); print load_fiche_titre($langs->trans("ListeMvts"), '', '');
print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
if ($optioncss != '') { if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'" />'; print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
} }
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="token" value="'.newToken().'" />'; print '<input type="hidden" name="doc_date" value="'.$object->doc_date.'">'."\n";
print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'" />'."\n"; print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'">'."\n";
print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'" />'."\n"; print '<input type="hidden" name="doc_ref" value="'.$object->doc_ref.'">'."\n";
print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'" />'."\n"; print '<input type="hidden" name="code_journal" value="'.$object->code_journal.'">'."\n";
print '<input type="hidden" name="mode" value="'.$mode.'" />'."\n"; print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'">'."\n";
print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'">'."\n";
print '<input type="hidden" name="mode" value="'.$mode.'">'."\n";
if (count($object->linesmvt) > 0) { if (count($object->linesmvt) > 0) {
print '<div class="div-table-responsive-no-min">'; print '<div class="div-table-responsive-no-min">';
@ -555,25 +640,6 @@ if (!empty($object->piece_num)) {
$total_debit = 0; $total_debit = 0;
$total_credit = 0; $total_credit = 0;
// Don't show in tmp mode, inevitably empty
if ($mode != "_tmp") {
// Date document export
print '<tr>';
print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>';
print '<td>';
print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
print '</td>';
print '</tr>';
// Date document validation
print '<tr>';
print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>';
print '<td>';
print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
print '</td>';
print '</tr>';
}
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre("AccountAccountingShort"); print_liste_field_titre("AccountAccountingShort");
@ -589,25 +655,16 @@ if (!empty($object->piece_num)) {
print "</tr>\n"; print "</tr>\n";
// In _tmp mode the first line is empty so we remove it // Add an empty line if there is not yet
if ($mode == "_tmp") { if (!empty($object->linesmvt[0])) {
array_shift($object->linesmvt); $tmpline = $object->linesmvt[0];
} if (!empty($tmpline->numero_compte)) {
// Add an empty line at the end to be able to add transaction
$line = new BookKeepingLine();
$object->linesmvt[] = $line;
// Add a second line empty line if there is not yet
if (empty($object->linesmvt[1])) {
$line = new BookKeepingLine(); $line = new BookKeepingLine();
$object->linesmvt[] = $line; $object->linesmvt[] = $line;
} }
}
$count_line = count($object->linesmvt); foreach ($object->linesmvt as $line) {
$num_line = 0;
foreach ($object->linesmvt as $key => $line) {
$num_line++;
print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">'; print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
$total_debit += $line->debit; $total_debit += $line->debit;
$total_credit += $line->credit; $total_credit += $line->credit;
@ -615,7 +672,7 @@ if (!empty($object->piece_num)) {
if ($action == 'update' && $line->id == $id) { if ($action == 'update' && $line->id == $id) {
print '<!-- td columns in edit mode -->'; print '<!-- td columns in edit mode -->';
print '<td>'; print '<td>';
print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, ''); print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
print '</td>'; print '</td>';
print '<td>'; print '<td>';
// TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because: // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
@ -625,23 +682,23 @@ if (!empty($object->piece_num)) {
if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label'); print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
} else { } else {
print '<input type="text" class="maxwidth150" name="subledger_account" value="'.(GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccount")).'" />'; print '<input type="text" class="maxwidth150" name="subledger_account" value="'.(GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccount")).'">';
} }
// Add also input for subledger label // Add also input for subledger label
print '<br><input type="text" class="maxwidth150" name="subledger_label" value="'.(GETPOSTISSET("subledger_label") ? GETPOST("subledger_label", "alpha") : $line->subledger_label).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccountLabel")).'" />'; print '<br><input type="text" class="maxwidth150" name="subledger_label" value="'.(GETPOSTISSET("subledger_label") ? GETPOST("subledger_label", "alpha") : $line->subledger_label).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccountLabel")).'">';
print '</td>'; print '</td>';
print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'" /></td>'; print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
print '<td class="right"><input type="text" size="6" class="right" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'" /></td>'; print '<td class="right"><input type="text" size="6" class="right" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
print '<td class="right"><input type="text" size="6" class="right" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'" /></td>'; print '<td class="right"><input type="text" size="6" class="right" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
print '<td>'; print '<td>';
print '<input type="hidden" name="id" value="'.$line->id.'" />'."\n"; print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'" />'; print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
print '</td>'; print '</td>';
} elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) { } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) {
if ($action == "" || $action == 'add') { if ($action == "" || $action == 'add') {
print '<!-- td columns in add mode -->'; print '<!-- td columns in add mode -->';
print '<td>'; print '<td>';
print $formaccounting->select_account((is_array($accountingaccount_number) ? $accountingaccount_number[$key] : $accountingaccount_number ), 'accountingaccount_number['.$key.']', 1, array(), 1, 1, ''); print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
print '</td>'; print '</td>';
print '<td>'; print '<td>';
// TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because: // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
@ -649,21 +706,16 @@ if (!empty($object->piece_num)) {
// Also, it is not possible to use a value that is not in the list. // Also, it is not possible to use a value that is not in the list.
// Also, the label is not automatically filled when a value is selected. // Also, the label is not automatically filled when a value is selected.
if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
print $formaccounting->select_auxaccount((is_array($subledger_account) ? $subledger_account[$key] : $subledger_account ), 'subledger_account['.$key.']', 1, 'maxwidth250', '', 'subledger_label'); print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
} else { } else {
print '<input type="text" class="maxwidth150" name="subledger_account['.$key.']" value="' . (is_array($subledger_account) ? $subledger_account[$key] : $subledger_account ) . '" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '" />'; print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">';
} }
print '<br><input type="text" class="maxwidth150" name="subledger_label['.$key.']" value="' . (is_array($subledger_label) ? $subledger_label[$key] : $subledger_label ) . '" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '" />'; print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
print '</td>'; print '</td>';
print '<td><input type="text" class="minwidth200" name="label_operation['.$key.']" value="' . (is_array($label_operation) ? $label_operation[$key] : $label_operation ) . '"/></td>'; print '<td><input type="text" class="minwidth200" name="label_operation" value="' . $label_operation . '"/></td>';
print '<td class="right"><input type="text" size="6" class="right" name="debit['.$key.']" value="' . (is_array($debit) ? $debit[$key] : $debit ) . '" /></td>'; print '<td class="right"><input type="text" size="6" class="right" name="debit" value=""/></td>';
print '<td class="right"><input type="text" size="6" class="right" name="credit['.$key.']" value="' . (is_array($credit) ? $credit[$key] : $credit ) . '" /></td>'; print '<td class="right"><input type="text" size="6" class="right" name="credit" value=""/></td>';
// Add button should not appear twice print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>';
if ($num_line === $count_line) {
print '<td><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '" /></td>';
} else {
print '<td class="right"></td>';
}
} }
} else { } else {
print '<!-- td columns in display mode -->'; print '<!-- td columns in display mode -->';
@ -729,9 +781,9 @@ if (!empty($object->piece_num)) {
print '<br>'; print '<br>';
print '<div class="center">'; print '<div class="center">';
if ($total_debit == $total_credit) { if ($total_debit == $total_credit) {
print '<input type="submit" class="button" name="validate" value="' . $langs->trans("ValidTransaction") . '" />'; print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'&action=valid">'.$langs->trans("ValidTransaction").'</a>';
} else { } else {
print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $debit, $credit)).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'" />'; print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $debit, $credit)).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'">';
} }
print ' &nbsp; '; print ' &nbsp; ';
@ -743,8 +795,9 @@ if (!empty($object->piece_num)) {
print '</form>'; print '</form>';
} }
} else { } else {
print load_fiche_titre($langs->trans("NoRecords")); print load_fiche_titre($langs->trans("NoRecords"));
}
} }
print dol_get_fiche_end(); print dol_get_fiche_end();