Browse Source

add c_action_trigger for auto batch invoice création

Florian HENRY 3 years ago
parent
commit
8ebeb0bf8a

+ 14 - 1
htdocs/compta/facture/class/facture-rec.class.php

@@ -1257,9 +1257,10 @@ class FactureRec extends CommonInvoice
 	 *
 	 *  @param	int		$restrictioninvoiceid		0=All qualified template invoices found. > 0 = restrict action on invoice ID
 	 *  @param	int		$forcevalidation		1=Force validation of invoice whatever is template auto_validate flag.
+	 *	@param     	int 	$notrigger 			Disable the trigger
 	 *  @return	int								0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
 	 */
-	public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0)
+	public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0, $notrigger = 0)
 	{
 		global $conf, $langs, $db, $user, $hookmanager;
 
@@ -1339,6 +1340,8 @@ class FactureRec extends CommonInvoice
 						$this->error = $facture->error;
 						$error++;
 					}
+
+
 					if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
 						$result = $facture->validate($user);
 						if ($result <= 0) {
@@ -1357,6 +1360,16 @@ class FactureRec extends CommonInvoice
 							$error++;
 						}
 					}
+					if (!$error && !$notrigger) {
+						// Call trigger
+						$result = $facturerec->call_trigger('BILLREC_CREATEBILL', $user);
+						if ($result < 0) {
+							$this->errors = $facturerec->errors;
+							$this->error = $facturerec->error;
+							$error++;
+						}
+						// End call triggers
+					}
 				} else {
 					$error++;
 					$this->error = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity."\n";

+ 1 - 0
htdocs/install/mysql/data/llx_c_action_trigger.sql

@@ -179,3 +179,4 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILLREC_CREATE','Template invoices created','Executed when a Template invoices is created','facturerec',900);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILLREC_MODIFY','Template invoices update','Executed when a Template invoices is updated','facturerec',901);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILLREC_DELETE','Template invoices deleted','Executed when a Template invoices is deleted','facturerec',902);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILLREC_AUTOCREATEBILL','Template invoices use to create invoices with auto batch','Executed when a Template invoices is use to create invoice with auto batch','facturerec',903);