From bc717bc6ae14765708bf28c2eb7dc737a6c25333 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 15 Mar 2020 07:49:24 +0100 Subject: [PATCH 1/6] Work on reconciliation of accouting account --- htdocs/accountancy/admin/account.php | 41 +++++++++++++++--- htdocs/accountancy/bookkeeping/balance.php | 2 +- .../class/accountingaccount.class.php | 43 ++++++++++++++++--- .../install/mysql/migration/11.0.0-12.0.0.sql | 2 + .../mysql/tables/llx_accounting_account.sql | 1 + 5 files changed, 74 insertions(+), 15 deletions(-) diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 39cf8aaea1d..7da6de23725 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -70,9 +70,12 @@ $arrayfields = array( 'aa.labelshort'=>array('label'=>$langs->trans("LabelToShow"), 'checked'=>1), 'aa.account_parent'=>array('label'=>$langs->trans("Accountparent"), 'checked'=>1), 'aa.pcg_type'=>array('label'=>$langs->trans("Pcgtype"), 'checked'=>1, 'help'=>'PcgtypeDesc'), - 'aa.active'=>array('label'=>$langs->trans("Activated"), 'checked'=>1) + 'aa.reconciliable'=>array('label'=>$langs->trans("Reconciliable"), 'checked'=>1), + 'aa.active'=>array('label'=>$langs->trans("Activated"), 'checked'=>1) ); +if ($conf->global->MAIN_FEATURES_LEVEL < 2) unset($arrayfields['aa.reconciliable']); + $accounting = new AccountingAccount($db); @@ -157,7 +160,8 @@ if (empty($reshook)) if ($action == 'disable') { if ($accounting->fetch($id)) { - $result = $accounting->account_desactivate($id); + $mode = GETPOST('mode', 'int'); + $result = $accounting->account_desactivate($id, $mode); } $action = 'update'; @@ -166,7 +170,8 @@ if (empty($reshook)) } } elseif ($action == 'enable') { if ($accounting->fetch($id)) { - $result = $accounting->account_activate($id); + $mode = GETPOST('mode', 'int'); + $result = $accounting->account_activate($id, $mode); } $action = 'update'; if ($result < 0) { @@ -192,7 +197,7 @@ if ($action == 'delete') { $pcgver = $conf->global->CHARTOFACCOUNTS; -$sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.account_number, aa.account_parent , aa.label, aa.labelshort, aa.active, "; +$sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.account_number, aa.account_parent , aa.label, aa.labelshort, aa.reconciliable, aa.active, "; $sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".$conf->entity; @@ -352,6 +357,7 @@ if ($resql) print ''; } if (!empty($arrayfields['aa.pcg_type']['checked'])) print ''; + if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { if (! empty($arrayfields['aa.reconciliable']['checked'])) print ' '; } if (!empty($arrayfields['aa.active']['checked'])) print ' '; print ''; $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1); @@ -365,6 +371,7 @@ if ($resql) if (!empty($arrayfields['aa.labelshort']['checked'])) print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['aa.account_parent']['checked'])) print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left '); if (!empty($arrayfields['aa.pcg_type']['checked'])) print_liste_field_titre($arrayfields['aa.pcg_type']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_type', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.pcg_type']['help']); + if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { if (! empty($arrayfields['aa.reconciliable']['checked'])) print_liste_field_titre($arrayfields['aa.reconciliable']['label'], $_SERVER["PHP_SELF"], 'aa.reconciliable', '', $param, '', $sortfield, $sortorder); } if (!empty($arrayfields['aa.active']['checked'])) print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print "\n"; @@ -441,16 +448,36 @@ if ($resql) if (!$i) $totalarray['nbfield']++; } + if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { + // Activated or not reconciliation on accounting account + if (!empty($arrayfields['aa.reconciliable']['checked'])) { + print ''; + if (empty($obj->reconciliable)) { + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; + } else { + print ''; + print img_picto($langs->trans("Activated"), 'switch_on'); + print ''; + } + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + } + // Activated or not if (!empty($arrayfields['aa.active']['checked'])) { - print ''; + print ''; if (empty($obj->active)) { - print ''; + print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } else { - print ''; + print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 7ee11c42ca3..b2a25b00ce2 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -254,7 +254,7 @@ if ($action != 'export_csv') print ''; print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); - print_liste_field_titre("Opening Balance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); + print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Balance", $_SERVER["PHP_SELF"], "", $param, "", 'class="right"', $sortfield, $sortorder); diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 21f7c1cb210..f552070e0d7 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -135,6 +135,11 @@ class AccountingAccount extends CommonObject */ public $active; + /** + * @var int reconciliable + */ + public $reconciliable; + /** * Constructor * @@ -162,7 +167,7 @@ class AccountingAccount extends CommonObject global $conf; if ($rowid || $account_number) { - $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, 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.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconciliable"; $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"; @@ -203,6 +208,7 @@ class AccountingAccount extends CommonObject $this->fk_user_modif = $obj->fk_user_modif; $this->active = $obj->active; $this->status = $obj->active; + $this->reconciliable = $obj->reconciliable; return $this->id; } else { @@ -261,6 +267,7 @@ class AccountingAccount extends CommonObject $sql .= ", fk_accounting_category"; $sql .= ", fk_user_author"; $sql .= ", active"; + $sql .= ", reconciliable"; $sql .= ") VALUES ("; $sql .= " '" . $this->db->idate($now) . "'"; $sql .= ", " . $conf->entity; @@ -273,6 +280,7 @@ class AccountingAccount extends CommonObject $sql .= ", " . (empty($this->account_category) ? 0 : (int) $this->account_category); $sql .= ", " . $user->id; $sql .= ", " . (int) $this->active; + $sql .= ", " . (int) $this->reconciliable; $sql .= ")"; $this->db->begin(); @@ -340,6 +348,7 @@ class AccountingAccount extends CommonObject $sql .= " , fk_accounting_category = " . (empty($this->account_category) ? 0 : (int) $this->account_category); $sql .= " , fk_user_modif = " . $user->id; $sql .= " , active = " . (int) $this->active; + $sql .= " , reconciliable = " . (int) $this->reconciliable; $sql .= " WHERE rowid = " . $this->id; dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); @@ -565,21 +574,31 @@ class AccountingAccount extends CommonObject * Account deactivated * * @param int $id Id + * @param int $mode 0=field active, 1=field active_customer_list, 2=field_active_supplier_list * @return int <0 if KO, >0 if OK */ - public function account_desactivate($id) + public function account_desactivate($id, $mode = 0) { // phpcs:enable $result = $this->checkUsage(); + if ($mode == 0) + { + $fieldtouse = 'active'; + } + else if ($mode == 1) + { + $fieldtouse = 'reconciliable'; + } + if ($result > 0) { $this->db->begin(); $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; - $sql .= "SET active = '0'"; + $sql .= "SET " . $fieldtouse . " = '0'"; $sql .= " WHERE rowid = " . $this->db->escape($id); - dol_syslog(get_class($this) . "::desactivate sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::" . $fieldtouse . " sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -600,18 +619,28 @@ class AccountingAccount extends CommonObject * Account activated * * @param int $id Id + * @param int $mode 0=field active, 1=field reconciliable, 2=field active_customer_list, 3=field_active_supplier_list * @return int <0 if KO, >0 if OK */ - public function account_activate($id) + public function account_activate($id, $mode = 0) { // phpcs:enable $this->db->begin(); + if ($mode == 0) + { + $fieldtouse = 'active'; + } + else if ($mode == 1) + { + $fieldtouse = 'reconciliable'; + } + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; - $sql .= "SET active = '1'"; + $sql .= "SET " . $fieldtouse . " = '1'"; $sql .= " WHERE rowid = " . $this->db->escape($id); - dol_syslog(get_class($this) . "::activate sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::" . $fieldtouse . " sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $this->db->commit(); diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index 645f0673ca0..0a61a6d9c58 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -192,3 +192,5 @@ ALTER TABLE llx_accounting_account DROP COLUMN pcg_subtype; ALTER TABLE llx_product ADD COLUMN accountancy_code_buy_intra varchar(32) AFTER accountancy_code_buy; ALTER TABLE llx_product ADD COLUMN accountancy_code_buy_export varchar(32) AFTER accountancy_code_buy_intra; + +ALTER TABLE llx_accounting_account ADD COLUMN reconciliable tinyint DEFAULT 0 NOT NULL after active; diff --git a/htdocs/install/mysql/tables/llx_accounting_account.sql b/htdocs/install/mysql/tables/llx_accounting_account.sql index d93bb719b68..a3bf8b90b79 100644 --- a/htdocs/install/mysql/tables/llx_accounting_account.sql +++ b/htdocs/install/mysql/tables/llx_accounting_account.sql @@ -35,6 +35,7 @@ create table llx_accounting_account fk_user_author integer DEFAULT NULL, fk_user_modif integer DEFAULT NULL, active tinyint DEFAULT 1 NOT NULL, + reconciliable tinyint DEFAULT 0 NOT NULL, import_key varchar(14), extraparams varchar(255) -- for other parameters with json format )ENGINE=innodb; From 789529c0e060d2edbf77e9b508c44438346c70e5 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 15 Mar 2020 07:55:35 +0100 Subject: [PATCH 2/6] Work on reconciliation of accouting account --- htdocs/langs/en_US/accountancy.lang | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 1bfceb4e21c..5c8f78d385f 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -239,6 +239,8 @@ HideOpeningBalance=Hide opening balance Pcgtype=Group of account PcgtypeDesc=Group of account are used as predefined 'filter' and 'grouping' criteria for some accounting reports. For example, 'INCOME' or 'EXPENSE' are used as groups for accounting accounts of products to build the expense/income report. +Reconciliable=Reconciliable + TotalVente=Total turnover before tax TotalMarge=Total sales margin From 375bcf87208d461ac2cd837c01951663291d97f9 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 15 Mar 2020 07:01:36 +0000 Subject: [PATCH 3/6] Fixing style errors. --- htdocs/accountancy/class/accountingaccount.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index f552070e0d7..5d3f9d7e46a 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -586,7 +586,7 @@ class AccountingAccount extends CommonObject { $fieldtouse = 'active'; } - else if ($mode == 1) + elseif ($mode == 1) { $fieldtouse = 'reconciliable'; } @@ -631,7 +631,7 @@ class AccountingAccount extends CommonObject { $fieldtouse = 'active'; } - else if ($mode == 1) + elseif ($mode == 1) { $fieldtouse = 'reconciliable'; } From 1a273551be8606b2faed2cabf1aa5f09f667d3fe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 15 Mar 2020 11:11:12 +0100 Subject: [PATCH 4/6] Update accountingaccount.class.php --- htdocs/accountancy/class/accountingaccount.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 5d3f9d7e46a..4ced7e34a67 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -598,7 +598,7 @@ class AccountingAccount extends CommonObject $sql .= "SET " . $fieldtouse . " = '0'"; $sql .= " WHERE rowid = " . $this->db->escape($id); - dol_syslog(get_class($this) . "::" . $fieldtouse . " sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::account_desactivate " . $fieldtouse . " sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { From 891bc525321db876f584e3fae1c161bf95c74b38 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 15 Mar 2020 11:12:10 +0100 Subject: [PATCH 5/6] Update accountingaccount.class.php --- htdocs/accountancy/class/accountingaccount.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 4ced7e34a67..0178f87a32d 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -640,7 +640,7 @@ class AccountingAccount extends CommonObject $sql .= "SET " . $fieldtouse . " = '1'"; $sql .= " WHERE rowid = " . $this->db->escape($id); - dol_syslog(get_class($this) . "::" . $fieldtouse . " sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::account_activate " . $fieldtouse . " sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $this->db->commit(); From 2cc68fec26351e756bb2110382c7fa31a5f7ee72 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 15 Mar 2020 11:13:46 +0100 Subject: [PATCH 6/6] Update accountancy.lang --- htdocs/langs/en_US/accountancy.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 5c8f78d385f..36b5fbcf55c 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -239,7 +239,7 @@ HideOpeningBalance=Hide opening balance Pcgtype=Group of account PcgtypeDesc=Group of account are used as predefined 'filter' and 'grouping' criteria for some accounting reports. For example, 'INCOME' or 'EXPENSE' are used as groups for accounting accounts of products to build the expense/income report. -Reconciliable=Reconciliable +Reconciliable=Reconcilable TotalVente=Total turnover before tax TotalMarge=Total sales margin