add c_action_trigger and fix travis

This commit is contained in:
Florian HENRY 2022-05-13 11:23:49 +02:00
parent fa6d738037
commit 0425becc03
4 changed files with 113 additions and 26 deletions

View File

@ -173,6 +173,9 @@ if (!empty($triggers)) {
if ($module == 'contact') {
$module = 'societe';
}
if ($module == 'facturerec') {
$module = 'facture';
}
// If 'element' value is myobject@mymodule instead of mymodule
$tmparray = explode('@', $module);

View File

@ -270,6 +270,7 @@ class FactureRec extends CommonInvoice
if ($result > 0) {
// On positionne en mode brouillon la facture
$this->brouillon = 1;
$this->fk_soc = $facsrc->socid;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
$sql .= "titre";
@ -301,7 +302,7 @@ class FactureRec extends CommonInvoice
$sql .= ", suspended";
$sql .= ") VALUES (";
$sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'";
$sql .= ", ".((int) $facsrc->socid);
$sql .= ", ".((int) $this->fk_soc);
$sql .= ", ".((int) $conf->entity);
$sql .= ", '".$this->db->idate($now)."'";
$sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0');
@ -1788,10 +1789,13 @@ class FactureRec extends CommonInvoice
*
* @param int $frequency value of frequency
* @param string $unit unit of frequency (d, m, y)
* @param int $notrigger Disable the trigger
* @return int <0 if KO, >0 if OK
*/
public function setFrequencyAndUnit($frequency, $unit)
public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
return -1;
@ -1815,6 +1819,16 @@ class FactureRec extends CommonInvoice
if (!empty($unit)) {
$this->unit_frequency = $unit;
}
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_MODIFY', $user);
if ($result < 0) {
return $result;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -1827,10 +1841,14 @@ class FactureRec extends CommonInvoice
*
* @param datetime $date date of execution
* @param int $increment_nb_gen_done 0 do nothing more, >0 increment nb_gen_done
* @param int $notrigger Disable the trigger
* @return int <0 if KO, >0 if OK
*/
public function setNextDate($date, $increment_nb_gen_done = 0)
public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
return -1;
@ -1848,6 +1866,15 @@ class FactureRec extends CommonInvoice
if ($increment_nb_gen_done > 0) {
$this->nb_gen_done++;
}
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_MODIFY', $user);
if ($result < 0) {
return $result;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -1859,10 +1886,14 @@ class FactureRec extends CommonInvoice
* Update the maximum period
*
* @param int $nb number of maximum period
* @param int $notrigger Disable the trigger
* @return int <0 if KO, >0 if OK
*/
public function setMaxPeriod($nb)
public function setMaxPeriod($nb, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
return -1;
@ -1879,6 +1910,16 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->nb_gen_max = $nb;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_MODIFY', $user);
if ($result < 0) {
return $result;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -1890,10 +1931,13 @@ class FactureRec extends CommonInvoice
* Update the auto validate flag of invoice
*
* @param int $validate 0 to create in draft, 1 to create and validate invoice
* @param int $notrigger Disable the trigger
* @return int <0 if KO, >0 if OK
*/
public function setAutoValidate($validate)
public function setAutoValidate($validate, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
return -1;
@ -1906,6 +1950,16 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->auto_validate = $validate;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_MODIFY', $user);
if ($result < 0) {
return $result;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -1917,10 +1971,13 @@ class FactureRec extends CommonInvoice
* Update the auto generate documents
*
* @param int $validate 0 no document, 1 to generate document
* @param int $notrigger Disable the trigger
* @return int <0 if KO, >0 if OK
*/
public function setGeneratePdf($validate)
public function setGeneratePdf($validate, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
return -1;
@ -1933,6 +1990,16 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->generate_pdf = $validate;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_MODIFY', $user);
if ($result < 0) {
return $result;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -1944,10 +2011,12 @@ class FactureRec extends CommonInvoice
* Update the model for documents
*
* @param string $model model of document generator
* @param int $notrigger Disable the trigger
* @return int <0 if KO, >0 if OK
*/
public function setModelPdf($model)
public function setModelPdf($model, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
return -1;
@ -1960,6 +2029,16 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->model_pdf = $model;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_MODIFY', $user);
if ($result < 0) {
return $result;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);

View File

@ -515,22 +515,22 @@ INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) values ( 2
-- Burundi Regions (id country=61) -- https://fr.wikipedia.org/wiki/Provinces_du_Burundi
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6101, '', 0, "Bubanza");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6102, '', 0, "Bujumbura Mairie");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6103, '', 0, "Bujumbura Rural");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6104, '', 0, "Bururi");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6105, '', 0, "Cankuzo");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6106, '', 0, "Cibitoke");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6107, '', 0, "Gitega");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6108, '', 0, "Karuzi");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6109, '', 0, "Kayanza");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6110, '', 0, "Kirundo");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6111, '', 0, "Makamba");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6112, '', 0, "Muramvya");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6113, '', 0, "Muyinga");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6114, '', 0, "Mwaro");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6115, '', 0, "Ngozi");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6116, '', 0, "Rumonge");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6117, '', 0, "Rutana");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6118, '', 0, "Ruyigi");
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6101, '', 0, 'Bubanza');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6102, '', 0, 'Bujumbura Mairie');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6103, '', 0, 'Bujumbura Rural');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6104, '', 0, 'Bururi');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6105, '', 0, 'Cankuzo');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6106, '', 0, 'Cibitoke');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6107, '', 0, 'Gitega');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6108, '', 0, 'Karuzi');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6109, '', 0, 'Kayanza');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6110, '', 0, 'Kirundo');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6111, '', 0, 'Makamba');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6112, '', 0, 'Muramvya');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6113, '', 0, 'Muyinga');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6114, '', 0, 'Mwaro');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6115, '', 0, 'Ngozi');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6116, '', 0, 'Rumonge');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6117, '', 0, 'Rutana');
INSERT INTO llx_c_regions (fk_pays, code_region, cheflieu, tncc, nom) VALUES ( 61, 6118, '', 0, 'Ruyigi');

View File

@ -167,10 +167,15 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_DELETE','Task deleted','Executed when a project task is deleted','project',152);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ACTION_CREATE','Action added','Executed when an action is added to the agenda','agenda',700);
-- oliday
-- holiday
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('HOLIDAY_CREATE','Holiday created','Executed when a holiday is created','holiday',800);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('HOLIDAY_MODIFY','Holiday modified','Executed when a holiday is modified','holiday',801);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('HOLIDAY_VALIDATE','Holiday validated','Executed when a holiday is validated','holiday',802);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('HOLIDAY_APPROVE','Holiday aprouved','Executed when a holiday is aprouved','holiday',803);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('HOLIDAY_CANCEL','Holiday canceled','Executed when a holiday is canceled','holiday',802);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('HOLIDAY_DELETE','Holiday deleted','Executed when a holiday is deleted','holiday',804);
-- facture rec
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);