From 3617a36f06c85e7d8e02b20e011ea518e700b37d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 9 Feb 2011 17:28:46 +0000 Subject: [PATCH] Fix: Error when duplicate ref --- htdocs/fourn/facture/fiche.php | 46 ++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 774fb102929..c112844d220 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -307,36 +307,44 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) else { $facid = $facfou->create($user); - - for ($i = 1 ; $i < 9 ; $i++) + if ($facid < 0) { - $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) + $error++; + } + + if (! $error) + { + for ($i = 1 ; $i < 9 ; $i++) { - 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) { + $langs->load("errors"); $db->rollback(); - $mesg='
'.$facfou->error.'
'; + $mesg='
'.$langs->trans($facfou->error).'
'; $_GET['action']='create'; $_GET['socid']=$_POST['socid']; }