From 7bcaae86f4b9656302a544805a316282e6591805 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 11 Jan 2023 13:33:29 +0100 Subject: [PATCH 1/4] Fix php 8 warning --- htdocs/admin/dict.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index d928931c9ab..e5c9dcb3127 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2514,7 +2514,7 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '') print ''; } elseif ($value == 'type_duration') { print ''; - print $form->selectTypeDuration('', $obj->{$value}, array('i','h')); + print $form->selectTypeDuration('', (!empty($obj->{$value}) ? $obj->{$value}:''), array('i','h')); print ''; } else { $fieldValue = isset($obj->{$value}) ? $obj->{$value}: ''; From 4afc21ecb3bad84f1cddafbda7cf9cb8277693f6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 Jan 2023 20:39:09 +0100 Subject: [PATCH 2/4] Update dict.php --- htdocs/admin/dict.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index e5c9dcb3127..1bf360dccf7 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2510,11 +2510,11 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '') print ''; } elseif ($value == 'block_if_negative') { print ''; - print $form->selectyesno("block_if_negative", (!empty($obj->{$value}) ? $obj->{$value}:''), 1); + print $form->selectyesno("block_if_negative", (empty($obj->block_if_negative) ? '' : $obj->block_if_negative), 1); print ''; } elseif ($value == 'type_duration') { print ''; - print $form->selectTypeDuration('', (!empty($obj->{$value}) ? $obj->{$value}:''), array('i','h')); + print $form->selectTypeDuration('', empty($obj->type_duration) ? '' : $obj->type_duration), array('i','h')); print ''; } else { $fieldValue = isset($obj->{$value}) ? $obj->{$value}: ''; From 71ea83d19e1886f81836d2d79c71aadcf20e5cad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 Jan 2023 20:40:15 +0100 Subject: [PATCH 3/4] Update dict.php --- htdocs/admin/dict.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 1bf360dccf7..4919e377c9c 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2514,7 +2514,7 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '') print ''; } elseif ($value == 'type_duration') { print ''; - print $form->selectTypeDuration('', empty($obj->type_duration) ? '' : $obj->type_duration), array('i','h')); + print $form->selectTypeDuration('', (empty($obj->type_duration) ? '' : $obj->type_duration), array('i','h')); print ''; } else { $fieldValue = isset($obj->{$value}) ? $obj->{$value}: ''; From 0303dff199543c3a3b4d5083afc861213fc93a89 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 Jan 2023 20:51:55 +0100 Subject: [PATCH 4/4] Merge --- .../class/companybankaccount.class.php | 61 +++++++++++++------ htdocs/societe/paymentmodes.php | 4 +- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index 26305bb0013..26a6169dbe6 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -35,6 +35,17 @@ class CompanyBankAccount extends Account { public $socid; + /** + * @var string ID to identify managed object + */ + public $element = 'societe_rib'; + + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'societe_rib'; + + /** @var bool $default_rib 1 = this object is the third party's default bank information */ public $default_rib; /** @@ -64,6 +75,13 @@ class CompanyBankAccount extends Account */ public $datem; + /** + * @var string TRIGGER_PREFIX Dolibarr 16.0 and above use the prefix to prevent the creation of inconsistently + * named triggers + * @see CommonObject::call_trigger() + */ + const TRIGGER_PREFIX = 'COMPANY_RIB'; + /** * Constructor @@ -86,7 +104,7 @@ class CompanyBankAccount extends Account * * @param User $user User * @param int $notrigger 1=Disable triggers - * @return int <0 if KO, >= 0 if OK + * @return int <0 if KO, > 0 if OK (ID of newly created company bank account information) */ public function create(User $user = null, $notrigger = 0) { @@ -97,6 +115,7 @@ class CompanyBankAccount extends Account // Check paramaters if (empty($this->socid)) { $this->error = 'BadValueForParameter'; + $this->errors[] = $this->error; return -1; } @@ -114,6 +133,9 @@ class CompanyBankAccount extends Account } } + + $this->db->begin(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)"; $sql .= " VALUES (".((int) $this->socid).", 'ban', '".$this->db->idate($now)."')"; $resql = $this->db->query($sql); @@ -128,19 +150,20 @@ class CompanyBankAccount extends Account $error++; } // End call triggers - - if (!$error) { - return $this->id; - } else { - return 0; - } - } else { - return 1; } } } else { + $error++; $this->error = $this->db->lasterror(); - return 0; + $this->errors[] = $this->error; + } + + if (!$error) { + $this->db->commit(); + return $this->id; + } else { + $this->db->rollback(); + return -1; } } @@ -168,6 +191,8 @@ class CompanyBankAccount extends Account $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1); } + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET"; $sql .= " bank = '".$this->db->escape($this->bank)."'"; $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'"; @@ -203,20 +228,22 @@ class CompanyBankAccount extends Account $error++; } // End call triggers - if (!$error) { - return 1; - } else { - return -1; - } - } else { - return 1; } } else { + $error++; if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error = $langs->trans('ErrorDuplicateField'); } else { $this->error = $this->db->lasterror(); } + $this->errors[] = $this->error; + } + + if (!$error) { + $this->db->commit(); + return 1; + } else { + $this->db->rollback(); return -1; } } diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 6869e80bd87..744d2763b71 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -183,8 +183,10 @@ if (empty($reshook)) { $companybankaccount->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha'); $result = $companybankaccount->update($user); - if (!$result) { + if ($result <= 0) { + // Display error message and get back to edit mode setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); + $action = 'edit'; } else { // If this account is the default bank account, we disable others if ($companybankaccount->default_rib) {