From c84f44a508d2a1a5b60c5468fe18c3340b506a19 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 1 May 2018 12:30:22 +0200 Subject: [PATCH] fix accountanty in multientity --- .../class/accountancycategory.class.php | 16 ++++++++++++---- htdocs/install/mysql/migration/7.0.0-8.0.0.sql | 13 +++++++++++-- .../mysql/tables/llx_accounting_journal.key.sql | 2 +- .../tables/llx_c_accounting_category.key.sql | 2 +- .../mysql/tables/llx_c_accounting_category.sql | 1 + 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 0a538f0a6ae..27254ef31d1 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -360,9 +360,11 @@ class AccountancyCategory // extends CommonObject * @return int <0 if KO, 0 if not found, >0 if OK */ public function display($id) { + global $conf; $sql = "SELECT t.rowid, t.account_number, t.label"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; $sql .= " WHERE t.fk_accounting_category = " . $id; + $sql .= " AND t.entity = " . $conf->entity; $this->lines_display = array(); @@ -400,13 +402,14 @@ class AccountancyCategory // extends CommonObject $sql .= " WHERE t.numero_compte NOT IN ("; $sql .= " SELECT t.account_number"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; - $sql .= " WHERE t.fk_accounting_category = " . $id . ")"; + $sql .= " WHERE t.fk_accounting_category = " . $id . " AND t.entity = " . $conf->entity.")"; $sql .= " AND t.numero_compte IN ("; $sql .= " SELECT DISTINCT aa.account_number"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; - $sql .= " AND aa.active = 1)"; + $sql .= " AND aa.active = 1"; + $sql .= " AND aa.entity = = " . $conf->entity . ")"; $sql .= " GROUP BY t.numero_compte, t.label_operation, t.doc_ref"; $sql .= " ORDER BY t.numero_compte"; @@ -448,6 +451,7 @@ class AccountancyCategory // extends CommonObject $sql .= " WHERE (aa.fk_accounting_category != ".$id." OR aa.fk_accounting_category IS NULL)"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " AND aa.active = 1"; + $sql .= " AND aa.entity = " . $conf->entity; $sql .= " GROUP BY aa.account_number, aa.label"; $sql .= " ORDER BY aa.account_number, aa.label"; @@ -492,6 +496,7 @@ class AccountancyCategory // extends CommonObject $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " AND aa.active = 1"; + $sql .= " AND aa.entity = " . $conf->entity; $this->db->begin(); @@ -581,7 +586,7 @@ class AccountancyCategory // extends CommonObject */ public function getCatsCpts() { - global $mysoc; + global $mysoc,$conf; $sql = ""; @@ -595,8 +600,10 @@ class AccountancyCategory // extends CommonObject $sql .= " WHERE t.fk_accounting_category IN ( SELECT c.rowid "; $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c"; $sql .= " WHERE c.active = 1"; + $sql .= " AND c.entity = " . $conf->entity; $sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)"; $sql .= " AND cat.rowid = t.fk_accounting_category"; + $sql .= " AND t.entity = " . $conf->entity; $sql .= " ORDER BY cat.position ASC"; $resql = $this->db->query($sql); @@ -685,7 +692,7 @@ class AccountancyCategory // extends CommonObject */ public function getCats($categorytype=-1) { - global $db, $langs, $user, $mysoc; + global $db, $langs, $user, $mysoc, $conf; if (empty($mysoc->country_id)) { dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined'); @@ -695,6 +702,7 @@ class AccountancyCategory // extends CommonObject $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c"; $sql .= " WHERE c.active = 1 "; + $sql .= " AND c.entity = " . $conf->entity; if ($categorytype >= 0) $sql.=" AND c.category_type = 1"; $sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)"; $sql .= " ORDER BY c.position ASC"; diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 70cbaeb7e04..9fa2849b757 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -9,8 +9,8 @@ -- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; -- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); -- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; --- To drop an index: -- VMYSQL4.0 DROP INDEX nomindex on llx_table --- To drop an index: -- VPGSQL8.0 DROP INDEX nomindex +-- To drop an index: -- VMYSQL4.1 DROP INDEX nomindex on llx_table +-- To drop an index: -- VPGSQL8.2 DROP INDEX nomindex -- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y -- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y -- To make pk to be auto increment (mysql): -- VMYSQL4.3 ALTER TABLE llx_table CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; @@ -441,3 +441,12 @@ ALTER TABLE llx_extrafields MODIFY COLUMN list VARCHAR(128); UPDATE llx_rights_def set module = 'asset' where module = 'assets'; + +ALTER TABLE llx_c_accounting_category ADD COLUMN entity integer NOT NULL DEFAULT 1 AFTER rowid; +-- VMYSQL4.1 DROP INDEX uk_c_accounting_category on llx_c_accounting_category +-- VPGSQL8.2 DROP INDEX uk_c_accounting_category +ALTER TABLE llx_c_accounting_category ADD UNIQUE INDEX uk_c_accounting_category(code,entity); +-- VMYSQL4.1 DROP INDEX uk_accounting_journal_code on llx_accounting_journal +-- VPGSQL8.2 DROP INDEX uk_accounting_journal_code +ALTER TABLE llx_accounting_journal ADD UNIQUE INDEX uk_accounting_journal_code (code,entity); + diff --git a/htdocs/install/mysql/tables/llx_accounting_journal.key.sql b/htdocs/install/mysql/tables/llx_accounting_journal.key.sql index e5083aa83d7..701c39e06a2 100644 --- a/htdocs/install/mysql/tables/llx_accounting_journal.key.sql +++ b/htdocs/install/mysql/tables/llx_accounting_journal.key.sql @@ -17,4 +17,4 @@ -- =========================================================================== -ALTER TABLE llx_accounting_journal ADD UNIQUE INDEX uk_accounting_journal_code (code); +ALTER TABLE llx_accounting_journal ADD UNIQUE INDEX uk_accounting_journal_code (code,entity); diff --git a/htdocs/install/mysql/tables/llx_c_accounting_category.key.sql b/htdocs/install/mysql/tables/llx_c_accounting_category.key.sql index 6b2d520a156..be927f6e761 100644 --- a/htdocs/install/mysql/tables/llx_c_accounting_category.key.sql +++ b/htdocs/install/mysql/tables/llx_c_accounting_category.key.sql @@ -17,5 +17,5 @@ -- Table with category for accounting account -- =================================================================== -ALTER TABLE llx_c_accounting_category ADD UNIQUE INDEX uk_c_accounting_category(code); +ALTER TABLE llx_c_accounting_category ADD UNIQUE INDEX uk_c_accounting_category(code,entity); diff --git a/htdocs/install/mysql/tables/llx_c_accounting_category.sql b/htdocs/install/mysql/tables/llx_c_accounting_category.sql index 253ff6aef46..9df9a9d6ab0 100644 --- a/htdocs/install/mysql/tables/llx_c_accounting_category.sql +++ b/htdocs/install/mysql/tables/llx_c_accounting_category.sql @@ -22,6 +22,7 @@ CREATE TABLE llx_c_accounting_category ( rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, + entity integer NOT NULL DEFAULT 1, code varchar(16) NOT NULL, label varchar(255) NOT NULL, range_account varchar(255) NOT NULL, -- Comment