diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index ce0bd4d3aa2982025a0b6096a61bbb134743c5f9..055451016e99cad66f3918e9aa5b89d6567e9d24 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -1,7 +1,7 @@ <?php /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com> * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro> - * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> + * 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 @@ -18,9 +18,9 @@ */ /** - * \file htdocs/accountancy/bookkeeping/card.php + * \file htdocs/accountancy/bookkeeping/card.php * \ingroup Advanced accountancy - * \brief Page to show book-entry + * \brief Page to show book-entry */ require '../../main.inc.php'; @@ -28,9 +28,14 @@ require '../../main.inc.php'; 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/html.formventilation.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; // Langs $langs->load("accountancy"); +$langs->load("bank"); +$langs->load("bills"); +$langs->load("trips"); // Security check $id = GETPOST('id', 'int'); @@ -211,6 +216,7 @@ llxHeader(); $html = new Form($db); $formventilation = new FormVentilation($db); +$formaccountancy = new FormAccounting($db); /* * Confirmation to delete the command @@ -223,26 +229,6 @@ if ($action == 'delete') { if ($action == 'create') { print load_fiche_titre($langs->trans("CreateMvts")); - $code_journal_array = array ( - $conf->global->ACCOUNTING_SELL_JOURNAL => $conf->global->ACCOUNTING_SELL_JOURNAL, - $conf->global->ACCOUNTING_PURCHASE_JOURNAL => $conf->global->ACCOUNTING_PURCHASE_JOURNAL, - $conf->global->ACCOUNTING_SOCIAL_JOURNAL => $conf->global->ACCOUNTING_SOCIAL_JOURNAL, - $conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL => $conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL, - $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL => $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL - ); - - $sql = 'SELECT DISTINCT accountancy_journal FROM ' . MAIN_DB_PREFIX . 'bank_account WHERE clos=0'; - $resql = $db->query($sql); - if (! $resql) { - setEventMessages($db->lasterror, null, 'errors'); - } else { - while ( $obj_bank = $db->fetch_object($resql) ) { - if (! empty($obj_bank->accountancy_journal)) { - $code_journal_array[$obj_bank->accountancy_journal] = $obj_bank->accountancy_journal; - } - } - } - $book = new BookKeeping($db); $next_num_mvt = $book->getNextNumMvt(); if (empty($next_num_mvt)) @@ -270,9 +256,10 @@ if ($action == 'create') { print '</tr>'; print '<tr>'; - print '<td class="fieldrequired">' . $langs->trans("Codejournal") . '</td>'; - print '<td>' . $html->selectarray('code_journal', $code_journal_array) . '</td>'; - 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>'; @@ -308,25 +295,46 @@ if ($action == 'create') { 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>' . $book->code_journal . '</td>'; - print '</tr>'; + 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>' . $book->doc_type . '</td>'; + print '<td>' . $typelabel . '</td>'; print '</tr>'; print '</table>'; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 75d0a63bf3946b1eca615fb42051cbee2ae4a7f2..b382d8559942c968b2d10c1d3899fba7a8ff1e41 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -1,7 +1,7 @@ <?php /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com> * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro> - * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> + * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com> * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; // Langs $langs->load("accountancy"); @@ -443,7 +444,11 @@ foreach ($object->lines as $line ) { 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="center">' . $line->code_journal . '</td>'; + + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch('',$line->code_journal); + print '<td align="center">' . $accountingjournal->getNomUrl(0,0,0,'',0) . '</td>'; + print '<td align="center">'; print '<a href="./card.php?piece_num=' . $line->piece_num . '">' . img_edit() . '</a> '; print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delmouv&mvt_num=' . $line->piece_num . $param . '&page=' . $page . '">' . img_delete() . '</a>'; diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php index 91924f08592f226ab59427b187b9d00d70a4346c..168934ee5a5957a5f16c9e2fb285c64900660212 100644 --- a/htdocs/accountancy/class/accountingjournal.class.php +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -48,45 +48,60 @@ class AccountingJournal extends CommonObject } /** - * Load an object from database - * - * @param int $id Id of record to load - * @return int <0 if KO, >0 if OK - */ - function fetch($id) + * Load an object from database + * + * @param int $rowid Id of record to load + * @param string $journal_code Journal code + * @return int <0 if KO, Id of record if OK and found + */ + function fetch($rowid = null, $journal_code = null) { - $sql = "SELECT rowid, code, label, nature, active"; - $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; - $sql.= " WHERE rowid = ".$id; - - dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG); - $result = $this->db->query($sql); - if ( $result ) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - - $this->code = $obj->code; - $this->ref = $obj->code; - $this->label = $obj->label; - $this->nature = $obj->nature; - $this->active = $obj->active; - - return 1; - } - else + if ($rowid || $journal_code) { - $this->error=$this->db->lasterror(); - return -1; + $sql = "SELECT rowid, code, label, nature, active"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; + $sql .= " WHERE"; + if ($rowid) { + $sql .= " rowid = '" . $rowid . "'"; + } elseif ($journal_code) { + $sql .= " code = '" . $journal_code . "'"; + } + + dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $obj = $this->db->fetch_object($result); + + if ($obj) { + $this->id = $obj->rowid; + $this->rowid = $obj->rowid; + + $this->code = $obj->code; + $this->ref = $obj->code; + $this->label = $obj->label; + $this->nature = $obj->nature; + $this->active = $obj->active; + + return $this->id; + } else { + return 0; + } + } + else + { + $this->error = "Error " . $this->db->lasterror(); + $this->errors[] = "Error " . $this->db->lasterror(); + } } + return -1; } /** * Return clicable name (with picto eventually) * * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $withlabel 0=No label, 1=Include label of account + * @param int $withlabel 0=No label, 1=Include label of journal * @param int $nourl 1=Disable url * @param string $moretitle Add more text to title tooltip * @param int $notooltip 1=Disable tooltip @@ -100,7 +115,7 @@ class AccountingJournal extends CommonObject $result = ''; - $url = DOL_URL_ROOT . '/accountancy/admin/journals_list.php'; + $url = DOL_URL_ROOT . '/accountancy/admin/journals_list.php?id=35'; $picto = 'billr'; $label=''; diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index 1a33f0fce604bb4d6c77de3c1ebc905ad619bc53..a87b566d0d620cdd4f9725f6a56fbfcd4638bc5b 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -51,12 +51,14 @@ class FormAccounting extends Form * @param int $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new) * @param int $showempty Add an empty field * @param array $event Event options + * @param int $select_in 0=selectid value is the journal rowid (default) or 1=selectid is journal code + * @param int $select_out Set value returned by select. 0=rowid (default), 1=code * @param string $morecss More css non HTML object * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache. * * @return string String with HTML select */ - function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $event = array(), $morecss='maxwidth300 maxwidthonsmartphone', $usecache='') + function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='') { global $conf; @@ -88,11 +90,27 @@ class FormAccounting extends Form $out = ajax_combobox($htmlname, $event); + $selected = 0; while ($obj = $this->db->fetch_object($resql)) { $label = $obj->code . ' - ' . $obj->label; + + $select_value_in = $obj->rowid; $select_value_out = $obj->rowid; + // Try to guess if we have found default value + if ($select_in == 1) { + $select_value_in = $obj->code; + } + if ($select_out == 1) { + $select_value_out = $obj->code; + } + // Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid + if ($selectid != '' && $selectid == $select_value_in) { + //var_dump("Found ".$selectid." ".$select_value_in); + $selected = $select_value_out; + } + $options[$select_value_out] = $label; } $this->db->free($resql); @@ -103,7 +121,7 @@ class FormAccounting extends Form } } - $out .= Form::selectarray($htmlname, $options, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1); + $out .= Form::selectarray($htmlname, $options, $select, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1); return $out; }