123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- <?php
- /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
- * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
- * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
- *
- * 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
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/accountancy/bookkeeping/card.php
- * \ingroup Advanced accountancy
- * \brief Page to show book-entry
- */
- require '../../main.inc.php';
- // Class
- require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
- require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
- require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
- // Langs
- $langs->load("accountancy");
- $langs->load("bank");
- $langs->load("bills");
- $langs->load("trips");
- // Security check
- $id = GETPOST('id', 'int');
- if ($user->societe_id > 0) {
- accessforbidden();
- }
- $action = GETPOST('action','aZ09');
- $piece_num = GETPOST("piece_num");
- $mesg = '';
- $account_number = GETPOST('account_number');
- $code_tiers = GETPOST('code_tiers');
- if ($code_tiers == - 1) {
- $code_tiers = null;
- }
- $label_compte = GETPOST('label_compte');
- $debit = price2num(GETPOST('debit'));
- $credit = price2num(GETPOST('credit'));
- $save = GETPOST('save');
- if (! empty($save)) {
- $action = 'add';
- }
- $update = GETPOST('update');
- if (! empty($update)) {
- $action = 'confirm_update';
- }
- if ($action == "confirm_update") {
- $error = 0;
- if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) {
- setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
- $error ++;
- }
- if (empty($error)) {
- $book = new BookKeeping($db);
- $result = $book->fetch($id);
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- } else {
- $book->numero_compte = $account_number;
- $book->code_tiers = $code_tiers;
- $book->label_compte = $label_compte;
- $book->debit = $debit;
- $book->credit = $credit;
- if (floatval($debit) != 0.0) {
- $book->montant = $debit;
- $book->sens = 'D';
- }
- if (floatval($credit) != 0.0) {
- $book->montant = $credit;
- $book->sens = 'C';
- }
- $result = $book->update($user);
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- } else {
- setEventMessages($langs->trans('Saved'), null, 'mesgs');
- $action = '';
- }
- }
- }
- }
- else if ($action == "add") {
- $error = 0;
- if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) {
- setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
- $error ++;
- }
- if (empty($error)) {
- $book = new BookKeeping($db);
- $book->numero_compte = $account_number;
- $book->code_tiers = $code_tiers;
- $book->label_compte = $label_compte;
- $book->debit = $debit;
- $book->credit = $credit;
- $book->doc_date = GETPOST('doc_date');
- $book->doc_type = GETPOST('doc_type');
- $book->piece_num = $piece_num;
- $book->doc_ref = GETPOST('doc_ref');
- $book->code_journal = GETPOST('code_journal');
- $book->fk_doc = GETPOST('fk_doc');
- $book->fk_docdet = GETPOST('fk_docdet');
- if (floatval($debit) != 0.0) {
- $book->montant = $debit;
- $book->sens = 'D';
- }
- if (floatval($credit) != 0.0) {
- $book->montant = $credit;
- $book->sens = 'C';
- }
- $result = $book->createStd($user);
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- } else {
- setEventMessages($langs->trans('Saved'), null, 'mesgs');
- $action = '';
- }
- }
- }
- else if ($action == "confirm_delete") {
- $book = new BookKeeping($db);
- $result = $book->fetch($id);
- $piece_num = $book->piece_num;
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- } else {
- $result = $book->delete($user);
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- }
- }
- $action = '';
- }
- else if ($action == "confirm_create") {
- $error = 0;
-
- $book = new BookKeeping($db);
- if (! GETPOST('next_num_mvt'))
- {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumPiece")), null, 'errors');
- $error++;
- }
-
- if (! $error)
- {
- $book->label_compte = '';
- $book->debit = 0;
- $book->credit = 0;
- $book->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth'), GETPOST('doc_dateday'), GETPOST('doc_dateyear'));
- $book->doc_type = GETPOST('doc_type');
- $book->piece_num = GETPOST('next_num_mvt');
- $book->doc_ref = GETPOST('doc_ref');
- $book->code_journal = GETPOST('code_journal');
- $book->fk_doc = 0;
- $book->fk_docdet = 0;
-
- $book->montant = 0;
-
- $result = $book->createStd($user);
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- } else {
- setEventMessages($langs->trans('Saved'), null, 'mesgs');
- $action = '';
- $piece_num = $book->piece_num;
- }
- }
- }
- /*
- * View
- */
- llxHeader();
- $html = new Form($db);
- $formaccountancy = new FormAccounting($db);
- /*
- * Confirmation to delete the command
- */
- if ($action == 'delete') {
- $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'confirm_delete', '', 0, 1);
- print $formconfirm;
- }
- if ($action == 'create') {
- print load_fiche_titre($langs->trans("CreateMvts"));
- $book = new BookKeeping($db);
- $next_num_mvt = $book->getNextNumMvt();
- 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">';
- print '<input type="hidden" name="action" value="confirm_create">' . "\n";
- print '<input type="hidden" name="next_num_mvt" value="' . $next_num_mvt . '">' . "\n";
- dol_fiche_head();
- print '<table class="border" width="100%">';
- print '<tr>';
- print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
- print '<td>' . $next_num_mvt . '</td>';
- print '</tr>';
- print '<tr>';
- print '<td class="fieldrequired">' . $langs->trans("Docdate") . '</td>';
- print '<td>';
- print $html->select_date('', 'doc_date', '', '', '', "create_mvt", 1, 1);
- print '</td>';
- print '</tr>';
- print '<tr>';
- print '<td class="fieldrequired">'.$langs->trans("AccountancyJournal").'</td>';
- print '<td>';
- print $formaccountancy->select_journal('', 'code_journal', '', 0, '', 1, 1, 1, 1);
- print '</td></tr>';
- print '<tr>';
- print '<td>' . $langs->trans("Docref") . '</td>';
- print '<td><input type="text" class="minwidth200" name="doc_ref" value=""/></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>';
- dol_fiche_end();
- print '<div align="center"><input type="submit" class="button" value="' . $langs->trans("Create") . '">';
- print ' <input type="button" value="' . $langs->trans("Cancel") . '" class="button" onclick="history.go(-1)" />';
- print '</div>';
- print '</form>';
- } else {
- $book = new BookKeeping($db);
- $result = $book->fetchPerMvt($piece_num);
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- }
- if (! empty($book->piece_num)) {
- print load_fiche_titre($langs->trans("UpdateMvts"), '<a href="list.php">' . $langs->trans('BackToList') . '</a>');
- dol_fiche_head();
-
- print '<div class="fichecenter">';
-
- print '<table class="border" width="100%">';
- print '<tr class="pair">';
- print '<td class="titlefield">' . $langs->trans("NumMvts") . '</td>';
- print '<td>' . $book->piece_num . '</td>';
- print '</tr>';
- print '<tr class="impair">';
- print '<td>' . $langs->trans("Docdate") . '</td>';
- print '<td>' . dol_print_date($book->doc_date, 'daytextshort') . '</td>';
- print '</tr>';
- print '<tr class="pair">';
- print '<td>' . $langs->trans("Codejournal") . '</td>';
- print '<td>';
- $accountingjournal = new AccountingJournal($db);
- $accountingjournal->fetch('',$book->code_journal);
- print $accountingjournal->getNomUrl(0,1,1,'',1);
- print '</td></tr>';
-
- print '<tr class="impair">';
- print '<td>' . $langs->trans("Docref") . '</td>';
- print '<td>' . $book->doc_ref . '</td>';
- print '</tr>';
- $typelabel = $book->doc_type;
- if ($typelabel == 'bank') {
- $typelabel = $langs->trans('Bank');
- }
- if ($typelabel == 'customer_invoice') {
- $typelabel = $langs->trans('CustomerInvoice');
- }
- if ($typelabel == 'supplier_invoice') {
- $typelabel = $langs->trans('SupplierInvoice');
- }
- if ($typelabel == 'expense_report') {
- $typelabel = $langs->trans('ExpenseReport');
- }
- print '<tr class="pair">';
- print '<td>' . $langs->trans("Doctype") . '</td>';
- print '<td>' . $typelabel . '</td>';
- print '</tr>';
- print '</table>';
-
- print '</div>';
-
- dol_fiche_end();
- print '<br>';
-
- $result = $book->fetch_all_per_mvt($piece_num);
- if ($result < 0) {
- setEventMessages($book->error, $book->errors, 'errors');
- } else {
- print load_fiche_titre($langs->trans("ListeMvts"), '', '');
- print '<form action="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $book->piece_num . '" method="post">';
- print '<input type="hidden" name="doc_date" value="' . $book->doc_date . '">' . "\n";
- print '<input type="hidden" name="doc_type" value="' . $book->doc_type . '">' . "\n";
- print '<input type="hidden" name="doc_ref" value="' . $book->doc_ref . '">' . "\n";
- print '<input type="hidden" name="code_journal" value="' . $book->code_journal . '">' . "\n";
- print '<input type="hidden" name="fk_doc" value="' . $book->fk_doc . '">' . "\n";
- print '<input type="hidden" name="fk_docdet" value="' . $book->fk_docdet . '">' . "\n";
- $var=False;
-
- print "<table class=\"noborder\" width=\"100%\">";
- if (count($book->linesmvt) > 0) {
- $total_debit = 0;
- $total_credit = 0;
- print '<tr class="liste_titre">';
- print_liste_field_titre($langs->trans("AccountAccountingShort"));
- print_liste_field_titre($langs->trans("Code_tiers"));
- print_liste_field_titre($langs->trans("Labelcompte"));
- print_liste_field_titre($langs->trans("Debit"), "", "", "", "", 'align="right"');
- print_liste_field_titre($langs->trans("Credit"), "", "", "", "", 'align="right"');
- print_liste_field_titre($langs->trans("Amount"), "", "", "", "", 'align="right"');
- print_liste_field_titre($langs->trans("Sens"), "", "", "", "", 'align="center"');
- print_liste_field_titre($langs->trans("Action"), "", "", "", "", 'width="60" align="center"');
- print "</tr>\n";
- foreach ($book->linesmvt as $line) {
- print '<tr class="oddeven">';
- $total_debit += $line->debit;
- $total_credit += $line->credit;
- if ($action == 'update' && $line->id == $id) {
- print '<td>';
- print $formaccounting->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, '');
- print '</td>';
- print '<td>';
- print $formaccounting->select_auxaccount($line->code_tiers, 'code_tiers', 1);
- print '</td>';
- print '<td><input type="text" size="15" name="label_compte" value="' . $line->label_compte . '"/></td>';
- print '<td align="right"><input type="text" size="6" name="debit" value="' . price($line->debit) . '"/></td>';
- print '<td align="right"><input type="text" size="6" name="credit" value="' . price($line->credit) . '"/></td>';
- print '<td align="right">' . price($line->montant) . '</td>';
- print '<td align="center">' . $line->sens . '</td>';
- print '<td>';
- print '<input type="hidden" name="id" value="' . $line->id . '">' . "\n";
- print '<input type="submit" class="button" name="update" value="' . $langs->trans("Update") . '">';
- print '</td>';
- } else {
- print '<td>' . length_accountg($line->numero_compte) . '</td>';
- print '<td>' . length_accounta($line->code_tiers) . '</td>';
- print '<td>' . $line->label_compte . '</td>';
- print '<td align="right">' . price($line->debit) . '</td>';
- print '<td align="right">' . price($line->credit) . '</td>';
- print '<td align="right">' . price($line->montant) . '</td>';
- print '<td align="center">' . $line->sens . '</td>';
- print '<td align="center">';
- print '<a href="./card.php?action=update&id=' . $line->id . '&piece_num=' . $line->piece_num . '">';
- print img_edit();
- print '</a> ';
- print '<a href="./card.php?action=delete&id=' . $line->id . '&piece_num=' . $line->piece_num . '">';
- print img_delete();
- print '</a>';
- print '</td>';
- }
- print "</tr>\n";
- }
- if ($total_debit != $total_credit)
- {
- setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_credit, $total_debit)), 'warnings');
- }
- if ($action == "" || $action == 'add') {
- print '<tr class="oddeven">';
- print '<td>';
- print $formaccounting->select_account($account_number, 'account_number', 0, array (), 1, 1, '');
- print '</td>';
- print '<td>';
- print $formaccounting->select_auxaccount($code_tiers, 'code_tiers', 1);
- print '</td>';
- print '<td><input type="text" size="15" name="label_compte" value="' . $label_compte . '"/></td>';
- print '<td align="right"><input type="text" class="right maxwidth50" name="debit" value="' . price($debit) . '"/></td>';
- print '<td align="right"><input type="text" class="right maxwidth50" name="credit" value="' . price($credit) . '"/></td>';
- print '<td></td>';
- print '<td></td>';
- print '<td><input type="submit" class="button" name="save" value="' . $langs->trans("Add") . '"></td>';
- print '</tr>';
- }
- print '</table>';
- print '</form>';
- }
- }
- } else {
- print load_fiche_titre($langs->trans("NoRecords"));
- }
- }
- llxFooter();
- $db->close();
|