diff --git a/htdocs/admin/agenda.php b/htdocs/admin/agenda.php index af09d32bc73..52926cf1b19 100644 --- a/htdocs/admin/agenda.php +++ b/htdocs/admin/agenda.php @@ -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); diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 6300e387067..18b1e752c0b 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -1695,7 +1695,20 @@ if ($action == 'create') { $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - print ''; + print ''; + print '
'; + + $MAXEVENT = 10; + + //$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id); + + // List of actions on element + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter); + + print '
'; + print ''; } } diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 7058364d1f1..a406a48c7f6 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -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'); @@ -1256,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; @@ -1338,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) { @@ -1356,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"; @@ -1788,10 +1802,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 +1832,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 +1854,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 +1879,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 +1899,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 +1923,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 +1944,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 +1963,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 +1984,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 +2003,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 +2024,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 +2042,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); diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 8c419eec3c9..f80f041730e 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -2229,6 +2229,11 @@ function dolGetElementUrl($objectid, $objecttype, $withpicto = 0, $option = '') $classpath = 'product/stock/class'; $classfile = 'entrepot'; $classname = 'Entrepot'; + } elseif ($objecttype == 'facturerec') { + $classpath = 'compta/facture/class'; + $classfile = 'facture-rec'; + $classname = 'FactureRec'; + $module='facture'; } if (!empty($conf->$module->enabled)) { diff --git a/htdocs/install/mysql/data/llx_c_action_trigger.sql b/htdocs/install/mysql/data/llx_c_action_trigger.sql index d039c285a3e..e4936c53ba3 100644 --- a/htdocs/install/mysql/data/llx_c_action_trigger.sql +++ b/htdocs/install/mysql/data/llx_c_action_trigger.sql @@ -167,10 +167,16 @@ 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); +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); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 33ca6d0ec9c..b0630f0394e 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -717,7 +717,8 @@ class User extends CommonObject 'knowledgerecord' => 'knowledgerecord@knowledgemanagement', 'skill@hrm' => 'all@hrm', // skill / job / position objects rights are for the moment grouped into right level "all" 'job@hrm' => 'all@hrm', // skill / job / position objects rights are for the moment grouped into right level "all" - 'position@hrm' => 'all@hrm' // skill / job / position objects rights are for the moment grouped into right level "all" + 'position@hrm' => 'all@hrm', // skill / job / position objects rights are for the moment grouped into right level "all" + 'facturerec' => 'facture' ); if (!empty($moduletomoduletouse[$module])) { $module = $moduletomoduletouse[$module];