* Copyright (C) 2013-2016 Florian Henry * Copyright (C) 2013-2017 Alexandre Spangaro * * 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 . */ /** * \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 '
'; print '' . "\n"; print '' . "\n"; dol_fiche_head(); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans("NumPiece") . '' . $next_num_mvt . '
' . $langs->trans("Docdate") . ''; print $html->select_date('', 'doc_date', '', '', '', "create_mvt", 1, 1); print '
'.$langs->trans("AccountancyJournal").''; print $formaccountancy->select_journal('', 'code_journal', '', 0, '', 1, 1, 1, 1); print '
' . $langs->trans("Docref") . '
' . $langs->trans("Doctype") . '
'; dol_fiche_end(); print '
'; print '     '; print '
'; print '
'; } 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"), '' . $langs->trans('BackToList') . ''); dol_fiche_head(); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $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 ''; print ''; print ''; print ''; print '
' . $langs->trans("NumMvts") . '' . $book->piece_num . '
' . $langs->trans("Docdate") . '' . dol_print_date($book->doc_date, 'daytextshort') . '
' . $langs->trans("Codejournal") . ''; $accountingjournal = new AccountingJournal($db); $accountingjournal->fetch('',$book->code_journal); print $accountingjournal->getNomUrl(0,1,1,'',1); print '
' . $langs->trans("Docref") . '' . $book->doc_ref . '
' . $langs->trans("Doctype") . '' . $typelabel . '
'; print '
'; dol_fiche_end(); print '
'; $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 '
'; print '' . "\n"; print '' . "\n"; print '' . "\n"; print '' . "\n"; print '' . "\n"; print '' . "\n"; $var=False; print ""; if (count($book->linesmvt) > 0) { $total_debit = 0; $total_credit = 0; print ''; 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 "\n"; foreach ($book->linesmvt as $line) { print ''; $total_debit += $line->debit; $total_credit += $line->credit; if ($action == 'update' && $line->id == $id) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } else { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print "\n"; } if ($total_debit != $total_credit) { setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_credit, $total_debit)), 'warnings'); } if ($action == "" || $action == 'add') { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print '
'; print $formaccounting->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, ''); print ''; print $formaccounting->select_auxaccount($line->code_tiers, 'code_tiers', 1); print '' . price($line->montant) . '' . $line->sens . ''; print '' . "\n"; print ''; print '' . length_accountg($line->numero_compte) . '' . length_accounta($line->code_tiers) . '' . $line->label_compte . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->montant) . '' . $line->sens . ''; print ''; print img_edit(); print ' '; print ''; print img_delete(); print ''; print '
'; print $formaccounting->select_account($account_number, 'account_number', 0, array (), 1, 1, ''); print ''; print $formaccounting->select_auxaccount($code_tiers, 'code_tiers', 1); print '
'; print '
'; } } } else { print load_fiche_titre($langs->trans("NoRecords")); } } llxFooter(); $db->close();