From a6dae99f562aa304d08618c52703d0f0da6e15f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 13 Mar 2023 19:45:42 +0100 Subject: [PATCH] More robust various payment when data are corrupted --- htdocs/compta/bank/class/account.class.php | 2 ++ htdocs/compta/bank/various_payment/card.php | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index e9eb67e9734..c04dbc597df 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1082,6 +1082,8 @@ class Account extends CommonObject $this->db->begin(); + // @TODO Check there is no child into llx_payment_various, ... to allow deletion ? + // Delete link between tag and bank account if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account"; diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index f673c24fe74..64bcb9787f5 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -638,20 +638,24 @@ if ($id) { print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0); print ''; + $bankaccountnotfound = 0; + if (isModEnabled('banque')) { print ''; print ''.$langs->trans('BankTransactionLine').''; print ''; - if ($object->fk_account > 0) { - if ($object->fk_bank > 0) { - $bankline = new AccountLine($db); - $bankline->fetch($object->fk_bank); + if ($object->fk_bank > 0) { + $bankline = new AccountLine($db); + $result = $bankline->fetch($object->fk_bank); - print $bankline->getNomUrl(1, 0, 'showall'); + if ($result <= 0) { + $bankaccountnotfound = 1; } else { - print ''.$langs->trans("NoRecordfound").''; + print $bankline->getNomUrl(1, 0, 'showall'); } } else { + $bankaccountnotfound = 1; + print ''.$langs->trans("NoRecordfound").''; } print ''; @@ -685,7 +689,7 @@ if ($id) { } // Delete - if (empty($object->rappro)) { + if (empty($object->rappro) || $bankaccountnotfound) { if (!empty($user->rights->banque->modifier)) { if ($alreadyaccounted) { print '
'.$langs->trans("Delete").'
';