';
diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php
index df45f027259..d01fda8fee9 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)
@@ -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
*/
/**
@@ -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;
@@ -58,25 +59,29 @@ class AccountingAccount extends CommonObject
/**
* Load record in memory
*
- * @param int $rowid Id
- * @param string $account_number Account number
- * @param int $limittocurentchart 1=Do not load record if it is into another accounting system
- * @return int <0 if KO, >0 if OK
+ * @param int $rowid Id
+ * @param string $account_number Account number
+ * @param int $limittocurrentchart 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 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 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 .= ", 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 .= " rowid = '" . $rowid . "'";
+ $sql .= " a.rowid = '" . $rowid . "'";
} elseif ($account_number) {
- $sql .= " 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 . ')';
+ 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);
$result = $this->db->query($sql);
if ($result) {
@@ -93,6 +98,8 @@ class AccountingAccount extends CommonObject
$this->account_number = $obj->account_number;
$this->account_parent = $obj->account_parent;
$this->label = $obj->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;
@@ -134,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))
@@ -153,6 +162,7 @@ class AccountingAccount extends CommonObject
$sql .= ", account_number";
$sql .= ", account_parent";
$sql .= ", label";
+ $sql .= ", fk_accounting_category";
$sql .= ", fk_user_author";
$sql .= ", active";
@@ -166,6 +176,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 +237,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/admin/dict.php b/htdocs/admin/dict.php
index 01b379abf0d..d88df512b8c 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -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
new file mode 100644
index 00000000000..e8664e3166d
--- /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 Advanced accountancy
+ * \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='account_category', $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_accounting_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_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";
+ }
+
+ 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 ab71e70e863..78dfbf95be9 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
@@ -21,6 +21,9 @@
-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user);
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
+-- Drop old table not used (Informations are already presents in llx_accounting_bookkeeping)
+DROP TABLE llx_accountingtransaction;
+DROP TABLE llx_accountingdebcred;
-- Already into 3.9 but we do it again to be sure
ALTER TABLE llx_product ADD COLUMN localtax1_type varchar(10) NOT NULL DEFAULT '0' after localtax1_tx;
@@ -326,6 +329,8 @@ ALTER TABLE llx_actioncomm MODIFY COLUMN elementtype varchar(255) DEFAULT NULL;
DELETE FROM llx_menu where module='expensereport';
+ALTER TABLE llx_accounting_account ADD COLUMN fk_accounting_category integer DEFAULT 0 after label;
+
CREATE TABLE llx_c_accounting_category (
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
code varchar(16) NOT NULL,
@@ -336,4 +341,4 @@ CREATE TABLE llx_c_accounting_category (
active integer DEFAULT 1
) ENGINE=innodb;
-ALTER TABLE llx_c_accounting_category ADD UNIQUE INDEX uk_c_accounting_category(code);
\ No newline at end of file
+ALTER TABLE llx_c_accounting_category ADD UNIQUE INDEX uk_c_accounting_category(code);
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/install/mysql/tables/llx_accountingdebcred.sql b/htdocs/install/mysql/tables/llx_accountingdebcred.sql
deleted file mode 100644
index f7ea28b127a..00000000000
--- a/htdocs/install/mysql/tables/llx_accountingdebcred.sql
+++ /dev/null
@@ -1,26 +0,0 @@
--- ============================================================================
--- Copyright (C) 2004-2006 Laurent Destailleur
---
--- 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 .
---
--- Table of "records" for accountancy expert module
--- ============================================================================
-
-create table llx_accountingdebcred
-(
- fk_transaction integer NOT NULL,
- account_number varchar(32) NOT NULL,
- amount real NOT NULL,
- direction varchar(1) NOT NULL
-)ENGINE=innodb;
diff --git a/htdocs/install/mysql/tables/llx_accountingtransaction.sql b/htdocs/install/mysql/tables/llx_accountingtransaction.sql
deleted file mode 100644
index 2b1e595c175..00000000000
--- a/htdocs/install/mysql/tables/llx_accountingtransaction.sql
+++ /dev/null
@@ -1,30 +0,0 @@
--- ============================================================================
--- Copyright (C) 2004-2006 Laurent Destailleur
---
--- 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 .
---
--- Table of "transactions" for accountancy expert module (1 transaction = 2+ records)
--- ============================================================================
-
-create table llx_accountingtransaction
-(
- rowid integer AUTO_INCREMENT PRIMARY KEY,
- label varchar(128) NOT NULL,
- datec date NOT NULL,
- fk_author varchar(20) NOT NULL,
- tms timestamp,
- fk_source integer NOT NULL,
- sourcetype varchar(16) NOT NULL,
- url varchar(255)
-)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