From 432cc44ab635a721b047b652c1f7fb27cc0c274e Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 28 Mar 2016 13:51:19 +0200 Subject: [PATCH 1/7] NEW: Accountancy - Add category --- htdocs/accountancy/admin/card.php | 64 ++++++++-- .../class/accountingaccount.class.php | 18 ++- .../core/class/html.formaccounting.class.php | 116 ++++++++++++++++++ .../install/mysql/migration/3.9.0-4.0.0.sql | 2 + .../mysql/tables/llx_accounting_account.sql | 28 +++-- htdocs/langs/en_US/accountancy.lang | 6 +- 6 files changed, 206 insertions(+), 28 deletions(-) create mode 100644 htdocs/core/class/html.formaccounting.class.php diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 7810ad4f3ef..a11c036dafe 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -1,6 +1,6 @@ - - * Copyright (C) 2013-2015 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -28,6 +28,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; $error = 0; @@ -61,6 +62,7 @@ if ($action == 'add') { $accounting->pcg_subtype = GETPOST('pcg_subtype'); $accounting->account_number = GETPOST('account_number'); $accounting->account_parent = GETPOST('account_parent', 'int'); + $accounting->account_category = GETPOST('account_category', 'int'); $accounting->label = GETPOST('label', 'alpha'); $accounting->active = 1; @@ -94,6 +96,7 @@ if ($action == 'add') { $accounting->pcg_subtype = GETPOST('pcg_subtype'); $accounting->account_number = GETPOST('account_number'); $accounting->account_parent = GETPOST('account_parent', 'int'); + $accounting->account_category = GETPOST('account_category', 'int'); $accounting->label = GETPOST('label', 'alpha'); $result = $accounting->update($user); @@ -131,7 +134,9 @@ llxheader('', $langs->trans('AccountAccounting')); $form = new Form($db); $htmlacc = new FormVentilation($db); +$formaccounting = new FormAccounting($db); +// Create mode if ($action == 'create') { print load_fiche_titre($langs->trans('NewAccount')); @@ -142,19 +147,34 @@ if ($action == 'create') { dol_fiche_head(); print ''; - + + // Account number print ''; print ''; + + // Label print ''; print ''; + + // Account parent print ''; print ''; + + // Category + print ''; + print ''; + + // Chart of accounts type print ''; print ''; + + // Chart of acounts subtype print ''; print ''; - print ''; + print ''; // Label print ''; - print ''; + print ''; // Account parent print ''; print ''; // Category print ''; print ''; // Chart of accounts type print ''; print ''; // Chart of accounts subtype print ''; print ''; print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . '
' . $langs->trans("Accountparent") . ''; print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1); print '
' . $langs->trans("AccountingCategory") . ''; + $formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1); + print '
' . $langs->trans("Pcgtype") . ''; print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); print '
' . $langs->trans("Pcgsubtype") . ''; print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); @@ -180,6 +200,7 @@ if ($action == 'create') { $head = accounting_prepare_head($accounting); + // Edit mode if ($action == 'update') { $soc = new Societe($db); if ($object->socid) { @@ -195,18 +216,33 @@ if ($action == 'create') { print ''; + // Account number print ''; print ''; + + // Label print ''; print ''; + + // Account parent print ''; print ''; + + // Category + print ''; + print ''; + + // Chart of accounts type print ''; print ''; + + // Chart of accounts subtype print ''; print ''; print ''; print ''; - + + // Label print ''; print ''; - + + // Account parent $accp = new AccountingAccount($db); if (! empty($accounting->account_parent)) { $accp->fetch($accounting->account_parent, ''); } print ''; print ''; - + + // Category + print ""; + + // Chart of accounts type print ''; print ''; - + + // Chart of accounts subtype print ''; print ''; - + + // Active print ''; print ''; - print ''; + print ''; // Label print ''; - print ''; + print ''; // Account parent print ''; print ''; // Category print ''; print ''; // Chart of accounts type print ''; print ''; // Chart of acounts subtype print ''; print ''; print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . '
' . $langs->trans("Accountparent") . ''; print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1); print '
'.$langs->trans("AccountingCategory").''; + $formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1); + print '
' . $langs->trans("Pcgtype") . ''; print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); print '
' . $langs->trans("Pcgsubtype") . ''; print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); @@ -224,6 +260,8 @@ if ($action == 'create') { print ''; } else { + + // View mode $linkback = '' . $langs->trans("BackToChartofaccounts") . ''; dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr'); @@ -234,23 +272,31 @@ if ($action == 'create') { print '
' . $langs->trans("AccountNumber") . '' . $accounting->account_number . '' . $linkback . '
' . $langs->trans("Label") . '' . $accounting->label . '
' . $langs->trans("Accountparent") . '' . $accp->account_number . ' - ' . $accp->label . '
".$langs->trans("AccountingCategory")."".$accounting->accounting_category_label."
' . $langs->trans("Pcgtype") . '' . $accounting->pcg_type . '
' . $langs->trans("Pcgsubtype") . '' . $accounting->pcg_subtype . '
' . $langs->trans("Activated") . ''; @@ -267,7 +313,7 @@ if ($action == 'create') { dol_fiche_end(); /* - * Barre d'actions + * Actions buttons */ print '
'; diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index df45f027259..b2bd4a1af93 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2015 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Ari Elbaz (elarifr) @@ -41,6 +41,7 @@ class AccountingAccount extends CommonObject var $pcg_subtype; var $account_number; var $account_parent; + var $account_category; var $label; var $fk_user_author; var $fk_user_modif; @@ -67,12 +68,14 @@ class AccountingAccount extends CommonObject global $conf; if ($rowid || $account_number) { - $sql = "SELECT rowid, datec, tms, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, fk_user_author, fk_user_modif, active"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account WHERE"; + $sql = "SELECT a.rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; + $sql .= ", ac.label as category_label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a, ".MAIN_DB_PREFIX."c_accounting_category as ac"; + $sql .= " WHERE a.fk_accounting_category = ac.rowid"; if ($rowid) { - $sql .= " rowid = '" . $rowid . "'"; + $sql .= " AND rowid = '" . $rowid . "'"; } elseif ($account_number) { - $sql .= " account_number = '" . $account_number . "'"; + $sql .= " AND account_number = '" . $account_number . "'"; } if (! empty($limittocurentchart)) { $sql .= ' AND fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; @@ -93,6 +96,8 @@ class AccountingAccount extends CommonObject $this->account_number = $obj->account_number; $this->account_parent = $obj->account_parent; $this->label = $obj->label; + $this->fk_accounting_category = $obj->fk_accounting_category; + $this->accounting_category_label = $obj->category_label; $this->fk_user_author = $obj->fk_user_author; $this->fk_user_modif = $obj->fk_user_modif; $this->active = $obj->active; @@ -153,6 +158,7 @@ class AccountingAccount extends CommonObject $sql .= ", account_number"; $sql .= ", account_parent"; $sql .= ", label"; + $sql .= ", fk_accounting_account"; $sql .= ", fk_user_author"; $sql .= ", active"; @@ -166,6 +172,7 @@ class AccountingAccount extends CommonObject $sql .= ", " . (! isset($this->account_number) ? 'NULL' : "'" . $this->account_number . "'"); $sql .= ", " . (! isset($this->account_parent) ? 'NULL' : "'" . $this->db->escape($this->account_parent) . "'"); $sql .= ", " . (! isset($this->label) ? 'NULL' : "'" . $this->db->escape($this->label) . "'"); + $sql .= ", " . (! isset($this->account_category) ? 'NULL' : "'" . $this->db->escape($this->account_category) . "'"); $sql .= ", " . $user->id; $sql .= ", " . (! isset($this->active) ? 'NULL' : "'" . $this->db->escape($this->active) . "'"); @@ -226,6 +233,7 @@ class AccountingAccount extends CommonObject $sql .= " , account_number = '" . $this->account_number . "'"; $sql .= " , account_parent = '" . $this->account_parent . "'"; $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "null"); + $sql .= " , fk_accounting_category = '" . $this->account_category . "'"; $sql .= " , fk_user_modif = " . $user->id; $sql .= " , active = '" . $this->active . "'"; diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php new file mode 100644 index 00000000000..4120a4f74b6 --- /dev/null +++ b/htdocs/core/class/html.formaccounting.class.php @@ -0,0 +1,116 @@ + + * + * 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/core/class/html.formaccounting.class.php + * \ingroup core + * \brief File of class with all html predefined components + */ + + +/** + * Class to manage generation of HTML components for accounting management + */ +class FormAccounting +{ + var $db; + var $error; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + + /** + * Return list of accounting category. + * Use mysoc->country_id or mysoc->country_code so they must be defined. + * + * @param string $selected Preselected type + * @param string $htmlname Name of field in form + * @param int $useempty Set to 1 if we want an empty value + * @param int $maxlen Max length of text in combo box + * @param int $help Add or not the admin help picto + * @return void + */ + function select_accounting_category($selected='',$htmlname='actioncode', $useempty=0, $maxlen=64, $help=1) + { + global $db,$langs,$user,$mysoc; + + if (empty($mysoc->country_id) && empty($mysoc->country_code)) + { + dol_print_error('','Call to select_accounting_account with mysoc country not yet defined'); + exit; + } + + if (! empty($mysoc->country_id)) + { + $sql = "SELECT c.rowid, c.label as type, c.range"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_accountancy_category as c"; + $sql.= " WHERE c.active = 1"; + $sql.= " AND c.fk_country = ".$mysoc->country_id; + $sql.= " ORDER BY c.label ASC"; + } + else + { + $sql = "SELECT c.rowid, c.label as type, c.range"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_accountancy_category, ".MAIN_DB_PREFIX."c_country as co"; + $sql.= " WHERE c.active = 1 AND c.fk_country = co.rowid"; + $sql.= " AND co.code = '".$mysoc->country_code."'"; + $sql.= " ORDER BY c.label ASC"; + } + + dol_syslog("Form::select_accounting_category", LOG_DEBUG); + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + print ''; + if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); + } + else + { + print $langs->trans("ErrorNoAccountingCategoryForThisCountry",$mysoc->country_code); + } + } + else + { + dol_print_error($db,$db->lasterror()); + } + } +} + diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index f20f784ac0d..caab5ca8d35 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -323,3 +323,5 @@ ALTER TABLE llx_expensereport_det ADD COLUMN multicurrency_total_ttc double(24,8 ALTER TABLE llx_product_lang ADD COLUMN import_key varchar(14) DEFAULT NULL; ALTER TABLE llx_actioncomm MODIFY COLUMN elementtype varchar(255) DEFAULT NULL; + +ALTER TABLE llx_accounting_account ADD COLUMN fk_accounting_category integer DEFAULT 0 after label; diff --git a/htdocs/install/mysql/tables/llx_accounting_account.sql b/htdocs/install/mysql/tables/llx_accounting_account.sql index 4734cb18f4c..e8927cdfda5 100644 --- a/htdocs/install/mysql/tables/llx_accounting_account.sql +++ b/htdocs/install/mysql/tables/llx_accounting_account.sql @@ -1,6 +1,7 @@ -- ============================================================================ -- Copyright (C) 2004-2006 Laurent Destailleur -- Copyright (C) 2014 Juanjo Menent +-- Copyright (C) 2016 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 @@ -20,17 +21,18 @@ create table llx_accounting_account ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - entity integer DEFAULT 1 NOT NULL, - datec datetime, - tms timestamp, - fk_pcg_version varchar(32) NOT NULL, - pcg_type varchar(20) NOT NULL, - pcg_subtype varchar(20) NOT NULL, - account_number varchar(32) NOT NULL, - account_parent varchar(32), - label varchar(255) NOT NULL, - fk_user_author integer DEFAULT NULL, - fk_user_modif integer DEFAULT NULL, - active tinyint DEFAULT 1 NOT NULL + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, + datec datetime, + tms timestamp, + fk_pcg_version varchar(32) NOT NULL, + pcg_type varchar(20) NOT NULL, + pcg_subtype varchar(20) NOT NULL, + account_number varchar(32) NOT NULL, + account_parent varchar(32), + label varchar(255) NOT NULL, + fk_accounting_category integer DEFAULT 0, + fk_user_author integer DEFAULT NULL, + fk_user_modif integer DEFAULT NULL, + active tinyint DEFAULT 1 NOT NULL )ENGINE=innodb; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index cb3e19dbf79..a0cbb0a5fb9 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -105,6 +105,7 @@ Labelcompte=Label account Sens=Sens Codejournal=Journal NumPiece=Piece number +AccountingCategory=Accounting category DelBookKeeping=Delete the records of the general ledger @@ -179,4 +180,7 @@ OptionModeProductSellDesc=Show all products with no accounting account defined f OptionModeProductBuyDesc=Show all products with no accounting account defined for purchases. ## Dictionary -Range=Range of accounting account \ No newline at end of file +Range=Range of accounting account + +## Error +ErrorNoAccountingCategoryForThisCountry=No accounting category are available for this country \ No newline at end of file From 436fb91901f6cce57a4f5a0ea5c27f057b414b8b Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 28 Mar 2016 14:50:51 +0200 Subject: [PATCH 2/7] Uniformize name of table --- htdocs/accountancy/class/accountingaccount.class.php | 12 ++++++------ htdocs/admin/dict.php | 6 +++--- htdocs/core/class/html.formaccounting.class.php | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index b2bd4a1af93..5a9b5e3788c 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -69,16 +69,16 @@ class AccountingAccount extends CommonObject if ($rowid || $account_number) { $sql = "SELECT a.rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; - $sql .= ", ac.label as category_label"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a, ".MAIN_DB_PREFIX."c_accounting_category as ac"; - $sql .= " WHERE a.fk_accounting_category = ac.rowid"; + $sql .= ", ac.rowid, ac.label as category_label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a, " . MAIN_DB_PREFIX . "c_accounting_category as ac"; + $sql .= " WHERE "; if ($rowid) { - $sql .= " AND rowid = '" . $rowid . "'"; + $sql .= " a.rowid = '" . $rowid . "'"; } elseif ($account_number) { - $sql .= " AND account_number = '" . $account_number . "'"; + $sql .= " a.account_number = '" . $account_number . "'"; } if (! empty($limittocurentchart)) { - $sql .= ' AND fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; + $sql .= ' AND a.fk_pcg_version IN (SELECT a.pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system as as WHERE as.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; } dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index e1fe67518bc..d88df512b8c 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -80,7 +80,7 @@ $hookmanager->initHooks(array('admin')); // Put here declaration of dictionaries properties // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this. -$taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,33,34,0,6,0,29,0,7,17,24,28,0,10,23,12,13,0,14,0,22,20,18,21,0,15,30,0,25,0,26,0,31,0); +$taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,33,34,0,6,0,29,0,7,17,24,28,0,10,23,12,13,0,14,0,22,20,18,21,0,15,30,0,25,0,26,0,31,32,0); // Name of SQL tables of dictionaries $tabname=array(); @@ -115,7 +115,7 @@ $tabname[28]= MAIN_DB_PREFIX."c_holiday_types"; $tabname[29]= MAIN_DB_PREFIX."c_lead_status"; $tabname[30]= MAIN_DB_PREFIX."c_format_cards"; $tabname[31]= MAIN_DB_PREFIX."accounting_system"; -$tabname[32]= MAIN_DB_PREFIX."c_accountancy_category"; +$tabname[32]= MAIN_DB_PREFIX."c_accounting_category"; $tabname[33]= MAIN_DB_PREFIX."c_hrm_department"; $tabname[34]= MAIN_DB_PREFIX."c_hrm_function"; @@ -189,7 +189,7 @@ $tabsql[28]= "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.new $tabsql[29]= "SELECT rowid as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status"; $tabsql[30]= "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM ".MAIN_DB_PREFIX."c_format_cards"; $tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.fk_pays as country_id, c.code as country_code, c.label as country, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_country as c WHERE s.fk_pays=c.rowid and c.active=1"; -$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range, a.position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accountancy_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1"; +$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range, a.position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1"; $tabsql[33]= "SELECT rowid, pos, code, label, active FROM ".MAIN_DB_PREFIX."c_hrm_department"; $tabsql[34]= "SELECT rowid, pos, code, label, c_level, active FROM ".MAIN_DB_PREFIX."c_hrm_function"; diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index 4120a4f74b6..dc01907ad15 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -65,7 +65,7 @@ class FormAccounting if (! empty($mysoc->country_id)) { $sql = "SELECT c.rowid, c.label as type, c.range"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_accountancy_category as c"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c"; $sql.= " WHERE c.active = 1"; $sql.= " AND c.fk_country = ".$mysoc->country_id; $sql.= " ORDER BY c.label ASC"; @@ -73,7 +73,7 @@ class FormAccounting else { $sql = "SELECT c.rowid, c.label as type, c.range"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_accountancy_category, ".MAIN_DB_PREFIX."c_country as co"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co"; $sql.= " WHERE c.active = 1 AND c.fk_country = co.rowid"; $sql.= " AND co.code = '".$mysoc->country_code."'"; $sql.= " ORDER BY c.label ASC"; From cbecb37c59e395708bbc097a0bdcd1944ee55259 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 28 Mar 2016 15:32:57 +0200 Subject: [PATCH 3/7] debug --- htdocs/accountancy/class/accountingaccount.class.php | 9 +++++---- htdocs/core/class/html.formaccounting.class.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 5a9b5e3788c..2f2cf023db0 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -68,18 +68,19 @@ class AccountingAccount extends CommonObject global $conf; if ($rowid || $account_number) { - $sql = "SELECT a.rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; + $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; $sql .= ", ac.rowid, ac.label as category_label"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a, " . MAIN_DB_PREFIX . "c_accounting_category as ac"; - $sql .= " WHERE "; + $sql .= " WHERE a.fk_accounting_category = ac.rowid"; if ($rowid) { - $sql .= " a.rowid = '" . $rowid . "'"; + $sql .= " AND a.rowid = '" . $rowid . "'"; } elseif ($account_number) { - $sql .= " a.account_number = '" . $account_number . "'"; + $sql .= " AND a.account_number = '" . $account_number . "'"; } if (! empty($limittocurentchart)) { $sql .= ' AND a.fk_pcg_version IN (SELECT a.pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system as as WHERE as.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; } + dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index dc01907ad15..8103575d2c9 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -52,7 +52,7 @@ class FormAccounting * @param int $help Add or not the admin help picto * @return void */ - function select_accounting_category($selected='',$htmlname='actioncode', $useempty=0, $maxlen=64, $help=1) + function select_accounting_category($selected='',$htmlname='account_category', $useempty=0, $maxlen=64, $help=1) { global $db,$langs,$user,$mysoc; From 2be979569d0ca6993d64ccc3832e10ecd5e151b9 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 28 Mar 2016 21:03:47 +0200 Subject: [PATCH 4/7] Debug II --- htdocs/accountancy/admin/card.php | 93 +++++++++---------- .../class/accountingaccount.class.php | 31 ++++--- .../core/class/html.formaccounting.class.php | 6 +- 3 files changed, 66 insertions(+), 64 deletions(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index a11c036dafe..52d0868ae5c 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -46,7 +46,7 @@ $cancel = GETPOST('cancel'); if (! $user->admin) accessforbidden(); -$accounting = new AccountingAccount($db); +$object = new AccountingAccount($db); // Action if ($action == 'add') { @@ -57,16 +57,16 @@ if ($action == 'add') { $result = $db->query($sql); $obj = $db->fetch_object($result); - $accounting->fk_pcg_version = $obj->pcg_version; - $accounting->pcg_type = GETPOST('pcg_type'); - $accounting->pcg_subtype = GETPOST('pcg_subtype'); - $accounting->account_number = GETPOST('account_number'); - $accounting->account_parent = GETPOST('account_parent', 'int'); - $accounting->account_category = GETPOST('account_category', 'int'); - $accounting->label = GETPOST('label', 'alpha'); - $accounting->active = 1; + $object->fk_pcg_version = $obj->pcg_version; + $object->pcg_type = GETPOST('pcg_type'); + $object->pcg_subtype = GETPOST('pcg_subtype'); + $object->account_number = GETPOST('account_number'); + $object->account_parent = GETPOST('account_parent', 'int'); + $object->account_category = GETPOST('account_category'); + $object->label = GETPOST('label', 'alpha'); + $object->active = 1; - $res = $accounting->create($user); + $res = $object->create($user); if ($res == 0) { } else { @@ -83,7 +83,7 @@ if ($action == 'add') { Header("Location: account.php"); } else if ($action == 'edit') { if (! GETPOST('cancel', 'alpha')) { - $result = $accounting->fetch($id); + $result = $object->fetch($id); $sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS; @@ -91,15 +91,15 @@ if ($action == 'add') { $result2 = $db->query($sql); $obj = $db->fetch_object($result2); - $accounting->fk_pcg_version = $obj->pcg_version; - $accounting->pcg_type = GETPOST('pcg_type'); - $accounting->pcg_subtype = GETPOST('pcg_subtype'); - $accounting->account_number = GETPOST('account_number'); - $accounting->account_parent = GETPOST('account_parent', 'int'); - $accounting->account_category = GETPOST('account_category', 'int'); - $accounting->label = GETPOST('label', 'alpha'); + $object->fk_pcg_version = $obj->pcg_version; + $object->pcg_type = GETPOST('pcg_type'); + $object->pcg_subtype = GETPOST('pcg_subtype'); + $object->account_number = GETPOST('account_number'); + $object->account_parent = GETPOST('account_parent', 'int'); + $object->account_category = GETPOST('account_category'); + $object->label = GETPOST('label', 'alpha'); - $result = $accounting->update($user); + $result = $object->update($user); if ($result > 0) { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); @@ -112,10 +112,10 @@ if ($action == 'add') { exit(); } } else if ($action == 'delete') { - $result = $accounting->fetch($id); + $result = $object->fetch($id); - if (! empty($accounting->id)) { - $result = $accounting->delete($user); + if (! empty($object->id)) { + $result = $object->delete($user); if ($result > 0) { Header("Location: account.php"); @@ -123,7 +123,7 @@ if ($action == 'add') { } if ($result < 0) { - setEventMessages($accounting->error, $accounting->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -150,34 +150,34 @@ if ($action == 'create') { // Account number print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . '
' . $langs->trans("Accountparent") . ''; - print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1); + print $htmlacc->select_account($object->account_parent, 'account_parent', 1); print '
' . $langs->trans("AccountingCategory") . ''; - $formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1); + $formaccounting->select_accounting_category($object->account_category, 'account_category', 1); print '
' . $langs->trans("Pcgtype") . ''; - print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); + print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type'); print '
' . $langs->trans("Pcgsubtype") . ''; - print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); + print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype'); print '
'; @@ -192,13 +192,12 @@ if ($action == 'create') { print ''; } else if ($id) { - $rowid = $id; - $account = $accounting->fetch($rowid); + $result = $object->fetch($id); - if ($account > 0) { + if ($result > 0) { dol_htmloutput_mesg($mesg); - $head = accounting_prepare_head($accounting); + $head = accounting_prepare_head($object); // Edit mode if ($action == 'update') { @@ -218,34 +217,34 @@ if ($action == 'create') { // Account number print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . '
' . $langs->trans("Accountparent") . ''; - print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1); + print $htmlacc->select_account($object->account_parent, 'account_parent', 1); print '
'.$langs->trans("AccountingCategory").''; - $formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1); + $formaccounting->select_accounting_category($object->account_category, 'account_category', 1); print '
' . $langs->trans("Pcgtype") . ''; - print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); + print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type'); print '
' . $langs->trans("Pcgsubtype") . ''; - print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); + print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype'); print '
'; @@ -270,37 +269,37 @@ if ($action == 'create') { // Account number print '' . $langs->trans("AccountNumber") . ''; - print '' . $accounting->account_number . ''; + print '' . $object->account_number . ''; print '' . $linkback . ''; // Label print '' . $langs->trans("Label") . ''; - print '' . $accounting->label . ''; + print '' . $object->label . ''; // Account parent $accp = new AccountingAccount($db); - if (! empty($accounting->account_parent)) { - $accp->fetch($accounting->account_parent, ''); + if (! empty($object->account_parent)) { + $accp->fetch($object->account_parent, ''); } print '' . $langs->trans("Accountparent") . ''; print '' . $accp->account_number . ' - ' . $accp->label . ''; // Category - print "".$langs->trans("AccountingCategory")."".$accounting->accounting_category_label.""; + print "".$langs->trans("AccountingCategory")."".$object->account_category_label.""; // Chart of accounts type print '' . $langs->trans("Pcgtype") . ''; - print '' . $accounting->pcg_type . ''; + print '' . $object->pcg_type . ''; // Chart of accounts subtype print '' . $langs->trans("Pcgsubtype") . ''; - print '' . $accounting->pcg_subtype . ''; + print '' . $object->pcg_subtype . ''; // Active print '' . $langs->trans("Activated") . ''; print ''; - if (empty($accounting->active)) { + if (empty($object->active)) { print img_picto($langs->trans("Disabled"), 'switch_off'); } else { print img_picto($langs->trans("Activated"), 'switch_on'); diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 2f2cf023db0..7ee43999736 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -20,9 +20,9 @@ */ /** - * \file htdocs/accountancy/class/accountingaccount.class.php - * \ingroup Accounting Expert - * \brief Fichier de la classe des comptes comptable + * \file htdocs/accountancy/class/accountingaccount.class.php + * \ingroup Accounting Expert + * \brief Fichier de la classe des comptes comptable */ /** @@ -64,21 +64,22 @@ class AccountingAccount extends CommonObject * @param int $limittocurentchart 1=Do not load record if it is into another accounting system * @return int <0 if KO, >0 if OK */ - function fetch($rowid = null, $account_number = null, $limittocurentchart = 0) { + function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0) { global $conf; if ($rowid || $account_number) { $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; - $sql .= ", ac.rowid, ac.label as category_label"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a, " . MAIN_DB_PREFIX . "c_accounting_category as ac"; - $sql .= " WHERE a.fk_accounting_category = ac.rowid"; + $sql .= ", ca.label as category_label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; + $sql .= " WHERE"; if ($rowid) { - $sql .= " AND a.rowid = '" . $rowid . "'"; + $sql .= " a.rowid = '" . $rowid . "'"; } elseif ($account_number) { - $sql .= " AND a.account_number = '" . $account_number . "'"; + $sql .= " a.account_number = '" . $account_number . "'"; } - if (! empty($limittocurentchart)) { - $sql .= ' AND a.fk_pcg_version IN (SELECT a.pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system as as WHERE as.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; + if (! empty($limittocurrentchart)) { + $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; } dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); @@ -97,8 +98,8 @@ class AccountingAccount extends CommonObject $this->account_number = $obj->account_number; $this->account_parent = $obj->account_parent; $this->label = $obj->label; - $this->fk_accounting_category = $obj->fk_accounting_category; - $this->accounting_category_label = $obj->category_label; + $this->account_category = $obj->fk_accounting_category; + $this->account_category_label = $obj->category_label; $this->fk_user_author = $obj->fk_user_author; $this->fk_user_modif = $obj->fk_user_modif; $this->active = $obj->active; @@ -140,6 +141,8 @@ class AccountingAccount extends CommonObject $this->account_parent = trim($this->account_parent); if (isset($this->label)) $this->label = trim($this->label); + if (isset($this->account_category)) + $this->account_category = trim($this->account_category); if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author); if (isset($this->active)) @@ -159,7 +162,7 @@ class AccountingAccount extends CommonObject $sql .= ", account_number"; $sql .= ", account_parent"; $sql .= ", label"; - $sql .= ", fk_accounting_account"; + $sql .= ", fk_accounting_category"; $sql .= ", fk_user_author"; $sql .= ", active"; diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index 8103575d2c9..e8664e3166d 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -17,7 +17,7 @@ /** * \file htdocs/core/class/html.formaccounting.class.php - * \ingroup core + * \ingroup Advanced accountancy * \brief File of class with all html predefined components */ @@ -93,8 +93,8 @@ class FormAccounting while ($i < $num) { $obj = $db->fetch_object($resql); - print '