Fix: Meilleure gestion erreur sur ajout produit facture fournisseur

This commit is contained in:
Laurent Destailleur 2006-05-25 20:34:30 +00:00
parent e9b25e506e
commit d2c4f1f34a
5 changed files with 62 additions and 18 deletions

View File

@ -212,24 +212,31 @@ if ($_GET['action'] == 'add_ligne')
}
if ($result == -1)
{
// \todo
// Quantité insuffisante
$mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
}
}
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='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Label")).'</div>';
}
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 '<td>';
$html->select_societes(empty($_GET['socid'])?'':$_GET['socid'],'socidp','s.fournisseur = 1');
print '</td>';
print '<td width="50%">'.$langs->trans('Comments').'</td></tr>';
print '<td width="50%">'.$langs->trans('Note').'</td></tr>';
print '<tr><td>'.$langs->trans('Ref').'</td><td><input name="facnumber" type="text"></td>';
print '<td width="50%" rowspan="4" valign="top"><textarea name="note" wrap="soft" cols="30" rows="6"></textarea></td></tr>';
print '<td width="50%" rowspan="4" valign="top"><textarea name="note" wrap="soft" cols="30" rows="'.ROWS_8.'"></textarea></td></tr>';
if ($_GET['action'] == 'copy')
{
print '<tr><td>'.$langs->trans('Label').'</td><td><input size="30" name="libelle" value="'.$fac_ori->libelle.'" type="text"></td></tr>';
@ -351,7 +358,7 @@ else
llxHeader('','', $addons);
if ($mesg) { print '<br>'.$mesg.'<br>'; }
if ($mesg) { print $mesg.'<br>'; }
if ($_GET['action'] == 'edit')
{
@ -372,7 +379,7 @@ else
$rownb=9;
print '<td rowspan="'.$rownb.'" valign="top">';
print '<textarea name="note" wrap="soft" cols="60" rows="10">';
print '<textarea name="note" wrap="soft" cols="60" rows="'.ROWS_8.'">';
print stripslashes($fac->note);
print '</textarea></td></tr>';

View File

@ -13,4 +13,5 @@ ShowSupplier=Show supplier
OrderDate=Order date
BuyingPrice=Buying price
AddSupplierPrice=Add supplier price
ChangeSupplierPrice=Change supplier price
ChangeSupplierPrice=Change supplier price
ErrorQtyTooLowForThisSupplier=Quantity too low for this supplier

View File

@ -13,4 +13,5 @@ ShowSupplier=Afficher fournisseur
OrderDate=Date commande
BuyingPrice=Prix d'achat
AddSupplierPrice=Ajouter prix fournisseur
ChangeSupplierPrice=Modifier prix fournisseur
ChangeSupplierPrice=Modifier prix fournisseur
ErrorQtyTooLowForThisSupplier=Quantité insuffisante pour ce fournisseur

View File

@ -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);
}

View File

@ -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;
}