Fix: Error when duplicate ref

This commit is contained in:
Laurent Destailleur 2011-02-09 17:28:46 +00:00
parent 0a7cdf53e7
commit 3617a36f06

View File

@ -307,36 +307,44 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
else else
{ {
$facid = $facfou->create($user); $facid = $facfou->create($user);
if ($facid < 0)
for ($i = 1 ; $i < 9 ; $i++)
{ {
$label = $_POST['label'.$i]; $error++;
$amountht = price2num($_POST['amount'.$i]); }
$amountttc = price2num($_POST['amountttc'.$i]);
$tauxtva = price2num($_POST['tauxtva'.$i]); if (! $error)
$qty = $_POST['qty'.$i]; {
$fk_product = $_POST['fk_product'.$i]; for ($i = 1 ; $i < 9 ; $i++)
if ($label)
{ {
if ($amountht) $label = $_POST['label'.$i];
$amountht = price2num($_POST['amount'.$i]);
$amountttc = price2num($_POST['amountttc'.$i]);
$tauxtva = price2num($_POST['tauxtva'.$i]);
$qty = $_POST['qty'.$i];
$fk_product = $_POST['fk_product'.$i];
if ($label)
{ {
$price_base='HT'; $amount=$amountht; if ($amountht)
{
$price_base='HT'; $amount=$amountht;
}
else
{
$price_base='TTC'; $amount=$amountttc;
}
$atleastoneline=1;
$ret=$facfou->addline($label, $amount, $tauxtva, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base);
if ($ret < 0) $error++;
} }
else
{
$price_base='TTC'; $amount=$amountttc;
}
$atleastoneline=1;
$ret=$facfou->addline($label, $amount, $tauxtva, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base);
if ($ret < 0) $error++;
} }
} }
} }
if ($error) if ($error)
{ {
$langs->load("errors");
$db->rollback(); $db->rollback();
$mesg='<div class="error">'.$facfou->error.'</div>'; $mesg='<div class="error">'.$langs->trans($facfou->error).'</div>';
$_GET['action']='create'; $_GET['action']='create';
$_GET['socid']=$_POST['socid']; $_GET['socid']=$_POST['socid'];
} }