From 0ea4a5db7ddb5f13b6a7d9a9ebc7435ba8e86da2 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sat, 31 Jan 2015 00:08:45 +0100
Subject: [PATCH] Fixed: Error management on triggers

---
 htdocs/commande/card.php                         |  4 ++++
 htdocs/compta/facture.php                        |  6 ++++--
 htdocs/fourn/class/fournisseur.facture.class.php |  2 +-
 htdocs/fourn/commande/card.php                   |  4 ++--
 htdocs/fourn/facture/card.php                    | 15 +++++++--------
 5 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index 99414909426..5b76dd59323 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -928,6 +928,10 @@ if (empty($reshook))
 					$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
 				}
 			}
+			else
+			{
+				setEventMessages($object->error, $object->errors, 'errors');
+			}
 		}
 	}
 
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index c4ea066f801..8e74c674084 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -2399,7 +2399,8 @@ if ($action == 'create')
 	}
 
 	// Confirmation de la validation
-	if ($action == 'valid') {
+	if ($action == 'valid')
+	{
 		// on verifie si l'objet est en numerotation provisoire
 		$objectref = substr($object->ref, 1, 4);
 		if ($objectref == 'PROV') {
@@ -2430,7 +2431,8 @@ if ($action == 'create')
 			$qualified_for_stock_change = $object->hasProductsOrServices(1);
 		}
 
-		if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
+		if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
+		{
 			$langs->load("stocks");
 			require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
 			require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index f4823f81f4c..96e00aba182 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -947,7 +947,7 @@ class FactureFournisseur extends CommonInvoice
             }
 
             // Triggers call
-            if (! $error && $notrigger)
+            if (! $error && empty($notrigger))
             {
                 // Call trigger
                 $result=$this->call_trigger('BILL_SUPPLIER_VALIDATE',$user);
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 2f4e3f45782..022b46f6a9b 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -531,8 +531,8 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseu
     	}
     }
     else
-    {
-        setEventMessage($object->error, 'errors');
+	{
+        setEventMessages($object->error, $object->errors, 'errors');
     }
 
     // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 9542fc062e7..f3e752ed9d4 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -154,8 +154,7 @@ elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fourni
         $result = $object->validate($user,'',$idwarehouse);
         if ($result < 0)
         {
-            setEventMessage($object->error,'errors');
-            setEventMessage($object->errors,'errors');
+            setEventMessages($object->error,$object->errors,'errors');
         }
     }
 }
@@ -300,13 +299,13 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
         $_GET['socid']=$_POST['socid'];
         $error++;
     }
-    
+
     // Fill array 'array_options' with data from add form
-    
+
     if (! $error)
     {
         $db->begin();
-        
+
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 		$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
 		if ($ret < 0) $error ++;
@@ -1183,7 +1182,7 @@ if ($action == 'create')
 {
 	$facturestatic = new FactureFournisseur($db);
 	$extralabels = $extrafields->fetch_name_optionals_label($facturestatic->table_element);
-	
+
     print_fiche_titre($langs->trans('NewBill'));
 
     dol_htmloutput_events();
@@ -1424,7 +1423,7 @@ if ($action == 'create')
     print '</td>';
     // print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
     print '</tr>';
-    
+
 	if (empty($reshook) && ! empty($extrafields->attribute_label))
 	{
 		print $object->showOptionals($extrafields, 'edit');
@@ -1540,7 +1539,7 @@ else
         $societe = new Fournisseur($db);
         $result=$societe->fetch($object->socid);
         if ($result < 0) dol_print_error($db);
-        
+
         // fetch optionals attributes and labels
 		$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 
-- 
GitLab