diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 3e661958931..6c1ec86c6f2 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -276,31 +276,25 @@ class AccountancyCategory * * @return array Result in table */ - public function getCatsCpts() { + public function getCatsCpts() + { global $mysoc; + $sql = ""; - if (empty($mysoc->country_id) && empty($mysoc->country_code)) { + if (empty($mysoc->country_id)) { dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined'); exit(); } - if (! empty($mysoc->country_id)) { - $sql = "SELECT t.rowid, t.account_number, t.label as account_label, cat.code, cat.position, cat.label as name_cat, cat.sens "; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t, " . MAIN_DB_PREFIX . "c_accounting_category as cat"; - $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.fk_country = " . $mysoc->country_id . ")"; - $sql .= " AND cat.rowid = t.fk_accounting_category"; - $sql .= " ORDER BY cat.position ASC"; - } else { - $sql = "SELECT c.rowid, c.code, c.label, c.category_type "; - $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.position ASC"; - } + $sql = "SELECT t.rowid, t.account_number, t.label as account_label, cat.code, cat.position, cat.label as name_cat, cat.sens "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t, " . MAIN_DB_PREFIX . "c_accounting_category as cat"; + $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.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)"; + $sql .= " AND cat.rowid = t.fk_accounting_category"; + $sql .= " ORDER BY cat.position ASC"; $resql = $this->db->query($sql); if ($resql) { @@ -390,26 +384,17 @@ class AccountancyCategory { global $db, $langs, $user, $mysoc; - if (empty($mysoc->country_id) && empty($mysoc->country_code)) { + if (empty($mysoc->country_id)) { 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.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 "; - if ($categorytype >= 0) $sql.=" AND c.category_type = 1"; - $sql .= " AND c.fk_country = " . $mysoc->country_id; - $sql .= " ORDER BY c.position ASC"; - } else { // Note: this should not happen - $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, " . MAIN_DB_PREFIX . "c_country as co"; - $sql .= " WHERE c.active = 1 AND c.fk_country = co.rowid"; - if ($categorytype >= 0) $sql.=" AND c.category_type = 1"; - $sql .= " AND co.code = '" . $mysoc->country_code . "'"; - $sql .= " ORDER BY c.position ASC"; - } + $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 "; + 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"; $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index 8b9cba79b0c..7b52c5b3cbd 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -373,7 +373,10 @@ else if ($modecompta=="BOOKKEEPING") // Column group print ''; print $cat['code']; - print ''; + print ''; + + // Label of group + print ''; print $cat['label']; if (count($cpts) > 0) // Show example of 5 first accounting accounts { diff --git a/htdocs/install/mysql/data/llx_accounting_category.sql b/htdocs/install/mysql/data/llx_accounting_category.sql index 4954ed3f0fc..3d96ea205eb 100644 --- a/htdocs/install/mysql/data/llx_accounting_category.sql +++ b/htdocs/install/mysql/data/llx_accounting_category.sql @@ -17,8 +17,8 @@ -- --- Group of accounting account for French result. This is a minimal default setup. -INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1, 'VENTES', 'Income of products/services', 'Example: 7xxxxx', 0, 0, '', '10', 1, 1); -INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2, 'DEPENSES', 'Expenses of products/services', 'Example: 6xxxxx', 0, 0, '', '20', 1, 1); -INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 3, 'PROFIT', 'Balance', '', 0, 1, 'VENTES+DEPENSES', '30', 1, 1); +-- Group of accounting accounts for report. This is a minimal default setup. +INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1, 'INCOMES', 'Income of products/services', 'Example: 7xxxxx', 0, 0, '', '10', 0, 1); +INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2, 'EXPENSES', 'Expenses of products/services', 'Example: 6xxxxx', 0, 0, '', '20', 0, 1); +INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 3, 'PROFIT', 'Balance', '', 0, 1, 'INCOMES+EXPENSES', '30', 0, 1);