From d2c4f1f34a346d4c94947a41abb43ca925483db2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 25 May 2006 20:34:30 +0000 Subject: [PATCH] Fix: Meilleure gestion erreur sur ajout produit facture fournisseur --- htdocs/fourn/facture/fiche.php | 33 +++++++++++++++++++------------ htdocs/langs/en_US/suppliers.lang | 3 ++- htdocs/langs/fr_FR/suppliers.lang | 3 ++- htdocs/main.inc.php | 10 ++++++++++ htdocs/product.class.php | 31 ++++++++++++++++++++++++++--- 5 files changed, 62 insertions(+), 18 deletions(-) diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 5ffdbd3cf3e..1193c59468f 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -212,24 +212,31 @@ if ($_GET['action'] == 'add_ligne') } if ($result == -1) { - // \todo // Quantité insuffisante + $mesg='
'.$langs->trans("ErrorQtyTooLowForThisSupplier").'
'; } } else { $tauxtva = price2num($_POST['tauxtva']); - if (strlen($_POST['label']) > 0 && !empty($_POST['amount'])) + if (! $_POST['label']) { - $ht = price2num($_POST['amount']); - $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); - } + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Label")).'
'; + } else { - $ttc = price2num($_POST['amountttc']); - $ht = $ttc / (1 + ($tauxtva / 100)); - $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); - } + if (!empty($_POST['amount'])) + { + $ht = price2num($_POST['amount']); + $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); + } + else + { + $ttc = price2num($_POST['amountttc']); + $ht = $ttc / (1 + ($tauxtva / 100)); + $facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']); + } + } } $_GET['action'] = 'edit'; } @@ -264,11 +271,11 @@ if ($_GET['action'] == 'create' or $_GET['action'] == 'copy') print ''; $html->select_societes(empty($_GET['socid'])?'':$_GET['socid'],'socidp','s.fournisseur = 1'); print ''; - print ''.$langs->trans('Comments').''; + print ''.$langs->trans('Note').''; print ''.$langs->trans('Ref').''; - print ''; + print ''; if ($_GET['action'] == 'copy') { print ''.$langs->trans('Label').''; @@ -351,7 +358,7 @@ else llxHeader('','', $addons); - if ($mesg) { print '
'.$mesg.'
'; } + if ($mesg) { print $mesg.'
'; } if ($_GET['action'] == 'edit') { @@ -372,7 +379,7 @@ else $rownb=9; print ''; - print ''; diff --git a/htdocs/langs/en_US/suppliers.lang b/htdocs/langs/en_US/suppliers.lang index 26f1a35468d..1c506ff4cdb 100644 --- a/htdocs/langs/en_US/suppliers.lang +++ b/htdocs/langs/en_US/suppliers.lang @@ -13,4 +13,5 @@ ShowSupplier=Show supplier OrderDate=Order date BuyingPrice=Buying price AddSupplierPrice=Add supplier price -ChangeSupplierPrice=Change supplier price \ No newline at end of file +ChangeSupplierPrice=Change supplier price +ErrorQtyTooLowForThisSupplier=Quantity too low for this supplier \ No newline at end of file diff --git a/htdocs/langs/fr_FR/suppliers.lang b/htdocs/langs/fr_FR/suppliers.lang index 6352e6dac07..656a06cce59 100644 --- a/htdocs/langs/fr_FR/suppliers.lang +++ b/htdocs/langs/fr_FR/suppliers.lang @@ -13,4 +13,5 @@ ShowSupplier=Afficher fournisseur OrderDate=Date commande BuyingPrice=Prix d'achat AddSupplierPrice=Ajouter prix fournisseur -ChangeSupplierPrice=Modifier prix fournisseur \ No newline at end of file +ChangeSupplierPrice=Modifier prix fournisseur +ErrorQtyTooLowForThisSupplier=Quantité insuffisante pour ce fournisseur \ No newline at end of file diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index bfacad8f864..3e0882f7d78 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -239,6 +239,11 @@ if (! eregi("firefox",$_SERVER["HTTP_USER_AGENT"])) define('ROWS_2',2); define('ROWS_3',3); define('ROWS_4',4); + define('ROWS_5',5); + define('ROWS_6',6); + define('ROWS_7',7); + define('ROWS_8',8); + define('ROWS_9',9); } else { @@ -246,6 +251,11 @@ else define('ROWS_2',1); define('ROWS_3',2); define('ROWS_4',3); + define('ROWS_5',4); + define('ROWS_6',5); + define('ROWS_7',6); + define('ROWS_8',7); + define('ROWS_9',8); } diff --git a/htdocs/product.class.php b/htdocs/product.class.php index c4ac5061fe5..a3cc1095932 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -554,7 +554,7 @@ class Product /** * \brief Lit le prix pratiqué par un fournisseur * \param fourn_id Id du fournisseur - * \param qty Quantite pour lequel le prix est valide + * \param qty Quantite recherchée * \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé */ function get_buyprice($fourn_id, $qty) @@ -582,12 +582,37 @@ class Product } else { - return 0; + // On refait le meme select mais sans critere de quantite + $sql = "SELECT pf.price as price, pf.quantity as quantity"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf"; + $sql.= " WHERE pf.fk_soc = ".$fourn_id; + $sql.= " AND pf.fk_product =" .$this->id; + //$sql.= " AND quantity <= ".$qty; + $sql.= " ORDER BY quantity DESC"; + $sql.= " LIMIT 1"; + + $resql = $this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($result); + if ($num) + { + return -1; // Ce produit existe chez ce fournisseur mais qté insuffisante + } + else + { + return 0; // Ce produit n'existe pas chez ce fournisseur + } + } + else + { + return -3; + } } } else { - return -1; + return -2; } return $result; }