diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 5e24417f61851ebb9e115190221129c04e715072..892ee14e0f8609db64398f840cc893ea51604ca1 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -266,7 +266,7 @@ class FactureFournisseur extends CommonInvoice
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
- $result=$this->insertExtraFields();
+ $result=$this->insertExtraFields(); // This also set $this->error or $this->errors if errors are found
if ($result < 0)
{
$error++;
@@ -274,11 +274,15 @@ class FactureFournisseur extends CommonInvoice
}
}
else if ($reshook < 0) $error++;
- // Call trigger
- $result=$this->call_trigger('BILL_SUPPLIER_CREATE',$user);
- if ($result < 0) $error++;
- // End call triggers
-
+
+ if (! $error)
+ {
+ // Call trigger
+ $result=$this->call_trigger('BILL_SUPPLIER_CREATE',$user);
+ if ($result < 0) $error++;
+ // End call triggers
+ }
+
if (! $error)
{
$this->db->commit();
@@ -307,7 +311,7 @@ class FactureFournisseur extends CommonInvoice
}
else
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
$this->db->rollback();
return -2;
}
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 6032a7a5036ba6b59b952b524aca1d13c8ba16d5..c39128218d560de00d5daf53fe159adf2090efcb 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -364,7 +364,7 @@ if (empty($reshook))
if(empty($object->date_echeance)) $object->date_echeance = $object->calculate_date_lim_reglement();
// If creation from another object of another module
- if ($_POST['origin'] && $_POST['originid'])
+ if (! $error && $_POST['origin'] && $_POST['originid'])
{
// Parse element/subelement (ex: project_task)
$element = $subelement = $_POST['origin'];
@@ -468,17 +468,17 @@ if (empty($reshook))
$error++;
}
}
- // If some invoice's lines already known
- else
+ else if (! $error)
{
$id = $object->create($user);
if ($id < 0)
{
$error++;
}
-
+
if (! $error)
{
+ // If some invoice's lines already known
for ($i = 1 ; $i < 9 ; $i++)
{
$label = $_POST['label'.$i];
@@ -513,7 +513,8 @@ if (empty($reshook))
{
$langs->load("errors");
$db->rollback();
- setEventMessage($langs->trans($object->error), 'errors');
+
+ setEventMessages($object->error, $object->errors, 'errors');
$action='create';
$_GET['socid']=$_POST['socid'];
}