From 7c1a6a368a9ad8a24c65977aced8851fb7ae1907 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Fri, 13 Dec 2024 13:55:54 +0100 Subject: [PATCH] Clean code --- .../modules/modPayplugDolicloud.class.php | 22 +++++++------- .../modules/modStancerDolicloud.class.php | 29 +++++++++++++++++-- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/htdocs/payplugdolicloud/core/modules/modPayplugDolicloud.class.php b/htdocs/payplugdolicloud/core/modules/modPayplugDolicloud.class.php index 70bbec62c..3dec0c0b8 100644 --- a/htdocs/payplugdolicloud/core/modules/modPayplugDolicloud.class.php +++ b/htdocs/payplugdolicloud/core/modules/modPayplugDolicloud.class.php @@ -470,23 +470,23 @@ public function init($options = '') // Create bank account Payplug if not exists if (!getDolGlobalInt('PAYPLUG_DOLICLOUD_BANK_ACCOUNT_FOR_PAYMENTS')) { require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - $cashaccount = new Account($this->db); - $searchaccountid = $cashaccount->fetch(0, "PAYPLUG"); + $bankaccount = new Account($this->db); + $searchaccountid = $bankaccount->fetch(0, "PAYPLUG"); if ($searchaccountid == 0) { - $cashaccount->ref = "Payplug"; - $cashaccount->label = 'Payplug'; - $cashaccount->courant = Account::TYPE_CURRENT; // deprecated - $cashaccount->type = Account::TYPE_CURRENT; - $cashaccount->country_id = $mysoc->country_id ? $mysoc->country_id : 1; - $cashaccount->date_solde = dol_now(); + $bankaccount->ref = "Payplug"; + $bankaccount->label = 'Payplug'; + $bankaccount->type = Account::TYPE_CURRENT; + $bankaccount->country_id = $mysoc->country_id ? $mysoc->country_id : 1; + $bankaccount->date_solde = dol_now(); $idjournal = dol_getIdFromCode($this->db, 'BQ', 'accounting_journal', 'code', 'rowid'); - $cashaccount->fk_accountancy_journal = (int) $idjournal; - $searchaccountid = $cashaccount->create($user); + $bankaccount->fk_accountancy_journal = (int) $idjournal; + + $searchaccountid = $bankaccount->create($user); } if ($searchaccountid > 0) { dolibarr_set_const($this->db, "PAYPLUG_DOLICLOUD_BANK_ACCOUNT_FOR_PAYMENTS", $searchaccountid, 'chaine', 0, '', $conf->entity); } else { - setEventMessages($cashaccount->error, $cashaccount->errors, 'errors'); + setEventMessages($bankaccount->error, $bankaccount->errors, 'errors'); } } diff --git a/htdocs/stancerdolicloud/core/modules/modStancerDolicloud.class.php b/htdocs/stancerdolicloud/core/modules/modStancerDolicloud.class.php index 5ea1e4ddb..9c4eb6abf 100644 --- a/htdocs/stancerdolicloud/core/modules/modStancerDolicloud.class.php +++ b/htdocs/stancerdolicloud/core/modules/modStancerDolicloud.class.php @@ -439,8 +439,33 @@ public function __construct($db) */ public function init($options = '') { - global $conf, $langs; - + global $conf, $langs, $mysoc, $user; + + // Create bank account Payplug if not exists + if (!getDolGlobalInt('STANCER_DOLICLOUD_BANK_ACCOUNT_FOR_PAYMENTS')) { + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + $bankaccount = new Account($this->db); + $searchaccountid = $bankaccount->fetch(0, "STANCER"); + if ($searchaccountid == 0) { + $bankaccount->ref = "Stancer"; + $bankaccount->label = 'Stancer'; + $bankaccount->type = Account::TYPE_CURRENT; + $bankaccount->country_id = $mysoc->country_id ? $mysoc->country_id : 1; + $bankaccount->date_solde = dol_now(); + $idjournal = dol_getIdFromCode($this->db, 'BQ', 'accounting_journal', 'code', 'rowid'); + $bankaccount->fk_accountancy_journal = (int) $idjournal; + + $searchaccountid = $bankaccount->create($user); + } + if ($searchaccountid > 0) { + dolibarr_set_const($this->db, "STANCER_DOLICLOUD_BANK_ACCOUNT_FOR_PAYMENTS", $searchaccountid, 'chaine', 0, '', $conf->entity); + } else { + setEventMessages($bankaccount->error, $bankaccount->errors, 'errors'); + } + } + + + //$result = $this->_load_tables('/install/mysql/', 'stancerdolicloud'); $result = $this->_load_tables('/stancerdolicloud/sql/'); if ($result < 0) {