From dcde7773a3e788772dd4eab1208fd45c1db77fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 2 Mar 2016 11:04:52 +0100 Subject: [PATCH 1/3] Started using Account TYPE and STATUS constants --- htdocs/compta/bank/card.php | 6 +++--- htdocs/compta/bank/class/account.class.php | 17 ++++++++++++++--- .../societe/class/companybankaccount.class.php | 4 +--- htdocs/user/class/userbankaccount.class.php | 4 +--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index cccf16f0467..12dfe51ab59 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -302,7 +302,7 @@ if ($action == 'create') // Status print ''.$langs->trans("Status").''; print ''; - print $form->selectarray("clos",array(0=>$account->status[0],1=>$account->status[1]),(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); + print $form->selectarray("clos", $account->status,(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); print ''; // Country @@ -643,7 +643,7 @@ else print '
'; - if ($account->type == 0 || $account->type == 1) + if ($account->type == Account::TYPE_SAVINGS || $account->type == Account::TYPE_CURRENT) { print ''; @@ -861,7 +861,7 @@ else // Status print ''; print ''; // Country diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index a5e108a2c96..ca6ad0c37ce 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -139,7 +139,19 @@ class Account extends CommonObject public $state_code; public $state; - public $type_lib=array(); + /** + * Variable containing all account types with their respective translated label. + * Defined in __construct + * @var array + */ + public $type_lib = array(); + + /** + * Variable containing all account statuses with their respective translated label. + * Defined in __construct + * @var array + */ + public $status = array(); /** * Accountancy code @@ -205,7 +217,6 @@ class Account extends CommonObject $this->db = $db; - $this->clos = 0; $this->solde = 0; $this->type_lib = array( @@ -1230,7 +1241,7 @@ class Account extends CommonObject $this->label = 'My Bank account'; $this->bank = 'MyBank'; $this->courant = 1; - $this->clos = 0; + $this->clos = Account::STATUS_OPEN; $this->code_banque = '123'; $this->code_guichet = '456'; $this->number = 'ABC12345'; diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index 3924e8a9174..f71b04b7730 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -46,16 +46,14 @@ class CompanyBankAccount extends Account * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct(DoliDB $db) { $this->db = $db; $this->socid = 0; - $this->clos = 0; $this->solde = 0; $this->error_number = 0; $this->default_rib = 0; - return 1; } diff --git a/htdocs/user/class/userbankaccount.class.php b/htdocs/user/class/userbankaccount.class.php index 30c795bbd72..a91d064c7f8 100644 --- a/htdocs/user/class/userbankaccount.class.php +++ b/htdocs/user/class/userbankaccount.class.php @@ -44,15 +44,13 @@ class UserBankAccount extends Account * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct(DoliDB $db) { $this->db = $db; $this->socid = 0; - $this->clos = 0; $this->solde = 0; $this->error_number = 0; - return 1; } From ff83dd9afeffda4c41328b27ade5ec20a0222bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 2 Mar 2016 11:08:57 +0100 Subject: [PATCH 2/3] Replaced account type comparisons with TYPE constants --- htdocs/compta/bank/account.php | 2 +- htdocs/compta/bank/class/account.class.php | 6 +++--- htdocs/compta/bank/ligne.php | 2 +- htdocs/compta/bank/virement.php | 2 +- htdocs/core/lib/bank.lib.php | 2 +- htdocs/core/menus/standard/auguria.lib.php | 2 +- htdocs/core/menus/standard/eldy.lib.php | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index 0973ece78d3..880ff92d3d5 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -489,7 +489,7 @@ if ($id > 0 || ! empty($ref)) $form->select_date($dateop,'op',0,0,0,'transaction'); print ''; print ''; print '
'.$langs->trans("Status").''; - print $form->selectarray("clos",array(0=>$account->status[0],1=>$account->status[1]),(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); + print $form->selectarray("clos", $account->status,(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); print '
'; - $form->select_types_paiements((GETPOST('operation')?GETPOST('operation'):($object->courant == 2 ? 'LIQ' : '')),'operation','1,2',2,1); + $form->select_types_paiements((GETPOST('operation')?GETPOST('operation'):($object->courant == Account::TYPE_CASH ? 'LIQ' : '')),'operation','1,2',2,1); print ''; print ''; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index ca6ad0c37ce..a3f8ea61274 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -242,7 +242,7 @@ class Account extends CommonObject global $conf; if (empty($this->rappro)) return -1; - if ($this->courant == 2 && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) return -2; + if ($this->courant == Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) return -2; if ($this->clos) return -3; return 1; } @@ -399,7 +399,7 @@ class Account extends CommonObject $this->error="this->rowid not defined"; return -2; } - if ($this->courant == 2 && $oper != 'LIQ') + if ($this->courant == Account::TYPE_CASH && $oper != 'LIQ') { $this->error="ErrorCashAccountAcceptsOnlyCashMoney"; return -3; @@ -1240,7 +1240,7 @@ class Account extends CommonObject $this->ref = 'MBA'; $this->label = 'My Bank account'; $this->bank = 'MyBank'; - $this->courant = 1; + $this->courant = Account::TYPE_CURRENT; $this->clos = Account::STATUS_OPEN; $this->code_banque = '123'; $this->code_guichet = '456'; diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php index 13b65f0baf1..a01d7d0684b 100644 --- a/htdocs/compta/bank/ligne.php +++ b/htdocs/compta/bank/ligne.php @@ -102,7 +102,7 @@ if ($user->rights->banque->modifier && $action == "update") $ac = new Account($db); $ac->fetch($id); - if ($ac->courant == 2 && $_POST['value'] != 'LIQ') + if ($ac->courant == Account::TYPE_CASH && $_POST['value'] != 'LIQ') { setEventMessages($langs->trans("ErrorCashAccountAcceptsOnlyCashMoney"), null, 'errors'); $error++; diff --git a/htdocs/compta/bank/virement.php b/htdocs/compta/bank/virement.php index 1a3294a2f15..146ed4759c4 100644 --- a/htdocs/compta/bank/virement.php +++ b/htdocs/compta/bank/virement.php @@ -93,7 +93,7 @@ if ($action == 'add') // By default, electronic transfert from bank to bank $typefrom='PRE'; $typeto='VIR'; - if ($accountto->courant == 2 || $accountfrom->courant == 2) + if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH) { // This is transfert of change $typefrom='LIQ'; diff --git a/htdocs/core/lib/bank.lib.php b/htdocs/core/lib/bank.lib.php index 3c5d57fdaf6..ceb8a87bb30 100644 --- a/htdocs/core/lib/bank.lib.php +++ b/htdocs/core/lib/bank.lib.php @@ -64,7 +64,7 @@ function bank_prepare_head(Account $object) $head[$h][2] = 'graph'; $h++; - if ($object->courant != 2) + if ($object->courant != Account::TYPE_CASH) { $head[$h][0] = DOL_URL_ROOT."/compta/bank/releve.php?account=".$object->id; $head[$h][1] = $langs->trans("AccountStatements"); diff --git a/htdocs/core/menus/standard/auguria.lib.php b/htdocs/core/menus/standard/auguria.lib.php index a24a2d32baa..cbd4b035c4e 100644 --- a/htdocs/core/menus/standard/auguria.lib.php +++ b/htdocs/core/menus/standard/auguria.lib.php @@ -281,7 +281,7 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM { $objp = $db->fetch_object($resql); $newmenu->add('/compta/bank/card.php?id='.$objp->rowid,$objp->label,1,$user->rights->banque->lire); - if ($objp->rappro && $objp->courant != 2 && empty($objp->clos)) // If not cash account and not closed and can be reconciliate + if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) // If not cash account and not closed and can be reconciliate { $newmenu->add('/compta/bank/rappro.php?account='.$objp->rowid,$langs->trans("Conciliate"),2,$user->rights->banque->consolidate); } diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index a849d9ac40a..d3666031839 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1342,7 +1342,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu { $objp = $db->fetch_object($resql); $newmenu->add('/compta/bank/card.php?id='.$objp->rowid,$objp->label,1,$user->rights->banque->lire); - if ($objp->rappro && $objp->courant != 2 && empty($objp->clos)) // If not cash account and not closed and can be reconciliate + if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) // If not cash account and not closed and can be reconciliate { $newmenu->add('/compta/bank/rappro.php?account='.$objp->rowid,$langs->trans("Conciliate"),2,$user->rights->banque->consolidate); } From b41016da7044637571957b2f1abfc57db301bd11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 2 Mar 2016 11:12:19 +0100 Subject: [PATCH 3/3] Little refactor of FormBank::select_type_comptes_financiers --- htdocs/core/class/html.formbank.class.php | 27 +++-------------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/htdocs/core/class/html.formbank.class.php b/htdocs/core/class/html.formbank.class.php index ad74b465f27..48ec0764c09 100644 --- a/htdocs/core/class/html.formbank.class.php +++ b/htdocs/core/class/html.formbank.class.php @@ -49,32 +49,11 @@ class FormBank * @param string $htmlname Nom champ formulaire * @return void */ - function select_type_comptes_financiers($selected=1,$htmlname='type') + public function select_type_comptes_financiers($selected = Account::TYPE_CURRENT, $htmlname = 'type') { - global $langs; - $langs->load("banks"); + $account = new Account($this->db); - $type_available=array(0,1,2); - - print ''; + print Form::selectarray($htmlname, $account->type_lib, $selected); } }