diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 7f2a5bc7d3b..f7f3f3997ad 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -604,9 +604,22 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer)
*/
if ($_POST['action'] == "addline" && $user->rights->propale->creer)
{
- if (isset($_POST['qty']) && (($_POST['np_price']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
+ $propal = new Propal($db);
+ $result=0;
+
+ if (empty($_POST['idprod']) && $_POST["type"] < 0)
+ {
+ $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
';
+ $result = -1 ;
+ }
+ if (empty($_POST['idprod']) && (! isset($_POST["np_price"]) || $_POST["np_price"]=='')) // Unit price can be 0 but not ''
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).'
';
+ $result = -1 ;
+ }
+
+ if ($result >= 0 && isset($_POST['qty']) && (($_POST['np_price']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
{
- $propal = new Propal($db);
$ret=$propal->fetch($_POST['propalid']);
if ($ret < 0)
{
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 255a98118e1..084ef67f6ef 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -320,13 +320,13 @@ if ($_POST['action'] == 'addline' && $user->rights->commande->creer)
$mesg = ''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
';
$result = -1 ;
}
- if (empty($_POST['idprod']) && ! isset($_POST["pu"])) // Field pu can be 0
+ if (empty($_POST['idprod']) && (! isset($_POST["pu"]) || $_POST["pu"]=='')) // Unit price can be 0 but not ''
{
$mesg = ''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).'
';
$result = -1 ;
}
- if ($_POST['qty'] && (($_POST['pu'] != '' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
+ if ($result >= 0 && $_POST['qty'] && (($_POST['pu'] != '' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
{
$ret=$commande->fetch($_POST['id']);
if ($ret < 0)
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 12f890dfb44..b9bde043416 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -841,22 +841,23 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
*/
if (($_POST['action'] == 'addline' || $_POST['action'] == 'addline_predef') && $user->rights->facture->creer)
{
+ $fac = new Facture($db);
$result=0;
if (empty($_POST['idprod']) && $_POST["type"] < 0)
{
- $fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")) ;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
';
$result = -1 ;
}
- if (empty($_POST['idprod']) && empty($_POST["pu"]))
+ if (empty($_POST['idprod']) && (! isset($_POST["pu"]) || $_POST["pu"]=='')) // Unit price can be 0 but not ''
{
- $fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")) ;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).'
';
$result = -1 ;
}
+ // qty can't be null for invoice (no option)
if ($result >= 0 && $_POST['qty'] && (($_POST['pu']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
{
- $fac = new Facture($db);
$ret=$fac->fetch($_POST['facid']);
if ($ret < 0)
{
@@ -980,7 +981,7 @@ if (($_POST['action'] == 'addline' || $_POST['action'] == 'addline_predef') && $
}
else
{
- $mesg=''.$fac->error.'
';
+ if (empty($mesg)) $mesg=''.$fac->error.'
';
}
$_GET['facid']=$_POST['facid']; // Pour réaffichage de la fiche en cours d'édition