From 861f180635058f2632d46670c34c3bc938d4ebb1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Nov 2007 17:30:47 +0000 Subject: [PATCH] Fix: Gestion erreur sur bordereau remise cheque --- htdocs/compta/paiement/cheque/fiche.php | 5 +- .../paiement/cheque/remisecheque.class.php | 208 +++++++++--------- 2 files changed, 108 insertions(+), 105 deletions(-) diff --git a/htdocs/compta/paiement/cheque/fiche.php b/htdocs/compta/paiement/cheque/fiche.php index 78da89cec4e..7984e7740f7 100644 --- a/htdocs/compta/paiement/cheque/fiche.php +++ b/htdocs/compta/paiement/cheque/fiche.php @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /** @@ -58,14 +57,14 @@ if ($_GET['action'] == 'create' && $_GET["accountid"] > 0 && $user->rights->banq { $remisecheque = new RemiseCheque($db); $result = $remisecheque->Create($user, $_GET["accountid"]); - if ($result === 0) + if ($result >= 0) { Header("Location: fiche.php?id=".$remisecheque->id); exit; } else { - $mesg='
'.$paiement->error.'
'; + $mesg='
'.$remisecheque->error.'
'; } } diff --git a/htdocs/compta/paiement/cheque/remisecheque.class.php b/htdocs/compta/paiement/cheque/remisecheque.class.php index ac5ddac96c1..6f9f4c0063e 100644 --- a/htdocs/compta/paiement/cheque/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/remisecheque.class.php @@ -104,115 +104,119 @@ class RemiseCheque } - /** - \brief Insère la remise en base - \param user utilisateur qui effectue l'operation - \param account_id Compte bancaire concerne - */ - function Create($user, $account_id) - { - $this->errno = 0; - $this->db->begin(); - $this->id = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (datec, date_bordereau,fk_user_author,fk_bank_account)"; - $sql .= " VALUES (now(),now(),".$user->id.",".$account_id.")"; - - $resql = $this->db->query($sql); - if ( $resql ) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque"); - - if ($this->id == 0) - { - $this->errno = -1024; - dolibarr_syslog("Remisecheque::Create Erreur Lecture ID ($this->errno)"); - } + /** + \brief Crée bordereau en base + \param user Utilisateur qui effectue l'operation + \param account_id Compte bancaire concerne + \return int <0 if KO, >0 if OK + */ + function Create($user, $account_id) + { + $this->errno = 0; + $this->id = 0; - if ($this->id > 0 && $this->errno === 0) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; - $sql.= " SET number='(PROV".$this->id.")'"; - $sql.= " WHERE rowid='".$this->id."';"; - $resql = $this->db->query($sql); - if (!$resql) - { - $this->errno = -1025; - dolibarr_syslog("RemiseCheque::Create ERREUR UPDATE ($this->errno)"); - } - } + $this->db->begin(); - if ($this->id > 0 && $this->errno === 0) - { - $lines = array(); - $sql = "SELECT b.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= " WHERE b.fk_type = 'CHQ' AND b.amount > 0"; - $sql.= " AND b.fk_bordereau = 0 AND b.fk_account='$account_id'"; - $sql.= " LIMIT 40;"; // On limite a 40 pour ne générer des PDF que d'une page - - $resql = $this->db->query($sql); - - if ($resql) - { - while ( $row = $this->db->fetch_row($resql) ) - { - array_push($lines, $row[0]); - } - $this->db->free($resql); - } - else - { - $this->errno = -1026; - dolibarr_syslog("RemiseCheque::Create ERREUR SELECT ($this->errno)"); - } - } - - if ($this->id > 0 && $this->errno === 0) - { - foreach ($lines as $lineid) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."bank as b"; - $sql.= " SET fk_bordereau = ".$this->id; - $sql.= " WHERE b.rowid = $lineid;"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (datec, date_bordereau,fk_user_author,fk_bank_account)"; + $sql .= " VALUES (now(),now(),".$user->id.",".$account_id.")"; $resql = $this->db->query($sql); - if (!$resql) - { - $this->errno = -18; - dolibarr_syslog("RemiseCheque::Create ERREUR UPDATE ($this->errno)"); - } - } - } + if ( $resql ) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque"); + + if ($this->id == 0) + { + $this->errno = -1024; + dolibarr_syslog("Remisecheque::Create Erreur Lecture ID ($this->errno)"); + } - if ($this->id > 0 && $this->errno === 0) - { - if ($this->UpdateAmount() <> 0) - { - $this->errno = -1027; - dolibarr_syslog("RemiseCheque::Create ERREUR ($this->errno)"); - } - } - } - else - { - $result = -1; - dolibarr_syslog("RemiseCheque::Create Erreur $result INSERT Mysql"); - } - + if ($this->id > 0 && $this->errno === 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; + $sql.= " SET number='(PROV".$this->id.")'"; + $sql.= " WHERE rowid='".$this->id."';"; + $resql = $this->db->query($sql); + if (!$resql) + { + $this->errno = -1025; + dolibarr_syslog("RemiseCheque::Create ERREUR UPDATE ($this->errno)"); + } + } - if ($this->errno === 0) - { - $this->db->commit(); - } - else - { - $this->db->rollback(); - dolibarr_syslog("RemiseCheque::Create ROLLBACK ($this->errno)"); - } - - return $this->errno; - } + if ($this->id > 0 && $this->errno === 0) + { + $lines = array(); + $sql = "SELECT b.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= " WHERE b.fk_type = 'CHQ' AND b.amount > 0"; + $sql.= " AND b.fk_bordereau = 0 AND b.fk_account='$account_id'"; + $sql.= " LIMIT 40;"; // On limite a 40 pour ne générer des PDF que d'une page + + $resql = $this->db->query($sql); + + if ($resql) + { + while ( $row = $this->db->fetch_row($resql) ) + { + array_push($lines, $row[0]); + } + $this->db->free($resql); + } + else + { + $this->errno = -1026; + dolibarr_syslog("RemiseCheque::Create ERREUR SELECT ($this->errno)"); + } + } + + if ($this->id > 0 && $this->errno === 0) + { + foreach ($lines as $lineid) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."bank as b"; + $sql.= " SET fk_bordereau = ".$this->id; + $sql.= " WHERE b.rowid = $lineid;"; + + $resql = $this->db->query($sql); + if (!$resql) + { + $this->errno = -18; + dolibarr_syslog("RemiseCheque::Create ERREUR UPDATE ($this->errno)"); + } + } + } + + if ($this->id > 0 && $this->errno === 0) + { + if ($this->UpdateAmount() <> 0) + { + $this->errno = -1027; + dolibarr_syslog("RemiseCheque::Create ERREUR ($this->errno)"); + } + } + } + else + { + $result = -1; + dolibarr_syslog("RemiseCheque::Create Erreur $result INSERT Mysql"); + } + + + if ($this->errno == 0) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + dolibarr_syslog("RemiseCheque::Create ROLLBACK ($this->errno)"); + return $this->errno; + } + + } /** \brief Supprime la remise en base