Merge pull request #10154 from bugness-chl/develop-hookfacturerec
NEW Adding hooks to facturerec
This commit is contained in:
commit
e7b703f0c0
@ -998,26 +998,25 @@ class FactureRec extends CommonInvoice
|
|||||||
*
|
*
|
||||||
* WARNING: This method change temporarly context $conf->entity to be in correct context for each recurring invoice found.
|
* WARNING: This method change temporarly context $conf->entity to be in correct context for each recurring invoice found.
|
||||||
*
|
*
|
||||||
* @param int $restictoninvoiceid 0=All qualified template invoices found. > 0 = restrict action on invoice ID
|
* @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 $forcevalidation 1=Force validation of invoice whatever is template auto_validate flag.
|
||||||
* @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
|
* @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
|
||||||
*/
|
*/
|
||||||
function createRecurringInvoices($restictoninvoiceid=0, $forcevalidation=0)
|
function createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0)
|
||||||
{
|
{
|
||||||
global $conf, $langs, $db, $user;
|
global $conf, $langs, $db, $user, $hookmanager;
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
$nb_create=0;
|
||||||
|
|
||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$langs->loadLangs(array("main","bills"));
|
$langs->loadLangs(array("main","bills"));
|
||||||
|
|
||||||
$nb_create=0;
|
|
||||||
|
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
$tmparray=dol_getdate($now);
|
$tmparray=dol_getdate($now);
|
||||||
$today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
|
$today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
|
||||||
|
|
||||||
dol_syslog("createRecurringInvoices restictoninvoiceid=".$restictoninvoiceid." forcevalidation=".$forcevalidation);
|
dol_syslog("createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid." forcevalidation=".$forcevalidation);
|
||||||
|
|
||||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
|
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
|
||||||
$sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
|
$sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
|
||||||
@ -1025,9 +1024,15 @@ class FactureRec extends CommonInvoice
|
|||||||
$sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
|
$sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
|
||||||
$sql.= ' AND suspended = 0';
|
$sql.= ' AND suspended = 0';
|
||||||
$sql.= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
|
$sql.= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
|
||||||
if ($restictoninvoiceid > 0) $sql.=' AND rowid = '.$restictoninvoiceid;
|
if ($restrictioninvoiceid > 0)
|
||||||
|
$sql.=' AND rowid = '.$restrictioninvoiceid;
|
||||||
$sql.= $db->order('entity', 'ASC');
|
$sql.= $db->order('entity', 'ASC');
|
||||||
//print $sql;exit;
|
//print $sql;exit;
|
||||||
|
$parameters = array(
|
||||||
|
'restrictioninvoiceid' => $restrictioninvoiceid,
|
||||||
|
'forcevalidation' => $forcevalidation,
|
||||||
|
);
|
||||||
|
$reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
@ -1035,8 +1040,10 @@ class FactureRec extends CommonInvoice
|
|||||||
$i=0;
|
$i=0;
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
|
|
||||||
if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
|
if ($num)
|
||||||
else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
|
$this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
|
||||||
|
else
|
||||||
|
$this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
|
||||||
|
|
||||||
$saventity = $conf->entity;
|
$saventity = $conf->entity;
|
||||||
|
|
||||||
@ -1048,6 +1055,7 @@ class FactureRec extends CommonInvoice
|
|||||||
|
|
||||||
$invoiceidgenerated = 0;
|
$invoiceidgenerated = 0;
|
||||||
|
|
||||||
|
$facture = null;
|
||||||
$facturerec = new FactureRec($db);
|
$facturerec = new FactureRec($db);
|
||||||
$facturerec->fetch($line->rowid);
|
$facturerec->fetch($line->rowid);
|
||||||
|
|
||||||
@ -1117,6 +1125,16 @@ class FactureRec extends CommonInvoice
|
|||||||
$db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
|
$db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$parameters = array(
|
||||||
|
'cpt' => $i,
|
||||||
|
'total' => $num,
|
||||||
|
'errorCount' => $error,
|
||||||
|
'invoiceidgenerated' => $invoiceidgenerated,
|
||||||
|
'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
|
||||||
|
'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
|
||||||
|
);
|
||||||
|
$reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $facture); // note: $facture can be modified by hooks (warning: $facture can be null)
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user