Skip to content

Commit

Permalink
Fix report when group is not dedicated to a country
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 15, 2018
1 parent 73005d8 commit 85e307d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
53 changes: 19 additions & 34 deletions htdocs/accountancy/class/accountancycategory.class.php
Expand Up @@ -276,31 +276,25 @@ public function deleteCptCat($cpt_id) {
*
* @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) {
Expand Down Expand Up @@ -390,26 +384,17 @@ public function getCats($categorytype=-1)
{
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) {
Expand Down
5 changes: 4 additions & 1 deletion htdocs/compta/resultat/result.php
Expand Up @@ -373,7 +373,10 @@
// Column group
print '<td class="width200">';
print $cat['code'];
print '</td><td>';
print '</td>';

// Label of group
print '<td>';
print $cat['label'];
if (count($cpts) > 0) // Show example of 5 first accounting accounts
{
Expand Down
8 changes: 4 additions & 4 deletions htdocs/install/mysql/data/llx_accounting_category.sql
Expand Up @@ -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);

0 comments on commit 85e307d

Please sign in to comment.