From 91023d7ddfda5e263be351cfc2b9d58324ec7685 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 9 Dec 2009 23:40:30 +0000 Subject: [PATCH] Better error management --- htdocs/product.class.php | 5 +++-- htdocs/product/fournisseurs.php | 27 ++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 389d2febaf2..e2568a7a3ae 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1673,7 +1673,7 @@ class Product extends CommonObject * \param user Utilisateur qui fait le lien * \param id_fourn Id du fournisseur * \param ref_fourn Reference chez le fournisseur - * \return int < 0 si erreur, > 0 si ok + * \return int < 0 if KO, 0 if link already exists, > 0 if OK */ function add_fournisseur($user, $id_fourn, $ref_fourn) { @@ -1737,8 +1737,9 @@ class Product extends CommonObject $obj = $this->db->fetch_object($resql); $this->product_fourn_id = $obj->rowid; } + + return 0; } - $this->db->free($resql); } else { diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index f1c034c5f1b..b31772ffd23 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -115,7 +115,15 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc $error++; $mesg='
'.$product->error.'
'; } - + if ($ret == 0) + { + $error++; + $mesg='
'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct").'
'; + } + } + + if (! $error) + { if ($_POST["qty"]) { if ($_POST["price"] >= 0) @@ -124,22 +132,15 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc $result=$supplier->fetch($_POST["id_fourn"]); $ret=$product->update_buyprice($_POST["qty"], $_POST["price"], $user, $_POST["price_base_type"], $supplier); - if (!$error) + if ($ret < 0) { - if ($ret < 0) + $error++; + $mesg='
'.$product->error.'
'; + if ($ret == -2) { - $error++; - $mesg='
'.$product->error.'
'; - if ($ret == -2) - { - $mesg='
'.$langs->trans("ProductHasAlreadyReferenceInThisSupplier").'
'; - } + $mesg='
'.$langs->trans("ProductHasAlreadyReferenceInThisSupplier").'
'; } } - else - { - $mesg='
'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct").'
'; - } } else {