From 0c0ff4dec9c77f18a84110f4aa42d2e6b61d6a5f Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Thu, 10 Feb 2022 17:06:46 +0100 Subject: [PATCH 01/10] add WORKFLOW_TICKET_CREATE_INTERVENTION to workflow constants --- htdocs/core/modules/modWorkflow.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/modWorkflow.class.php b/htdocs/core/modules/modWorkflow.class.php index dc05bf9dc66..248d3c006ce 100644 --- a/htdocs/core/modules/modWorkflow.class.php +++ b/htdocs/core/modules/modWorkflow.class.php @@ -95,7 +95,8 @@ class modWorkflow extends DolibarrModules 8=>array('WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER', 'chaine', '1', 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER', 0, 'current', 0), 9=>array('WORKFLOW_BILL_ON_RECEPTION', 'chaine', '1', 'WORKFLOW_BILL_ON_RECEPTION', 0, 'current', 0), 10=>array('WORKFLOW_TICKET_LINK_CONTRACT', 'chaine', '0', 'Automatically link a ticket to available contracts', 0, 'current', 0), - 11=>array('WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS', 'chaine', '0', 'Search among parent companies contracts when automatically linking a ticket to available contracts', 0, 'current', 0) + 11=>array('WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS', 'chaine', '0', 'Search among parent companies contracts when automatically linking a ticket to available contracts', 0, 'current', 0), + 11=>array('WORKFLOW_TICKET_CREATE_INTERVENTION', 'chaine', '1', 'WORKFLOW_TICKET_CREATE_INTERVENTION', 0, 'current', 0) ); // Boxes From 4790006c3a1adabd9e87af11efb0cc9cc6469af4 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Thu, 10 Feb 2022 17:09:09 +0100 Subject: [PATCH 02/10] workflow config: add button for WORKFLOW_TICKET_CREATE_INTERVENTION --- htdocs/admin/workflow.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/admin/workflow.php b/htdocs/admin/workflow.php index da82f163a7f..a684d642b2f 100644 --- a/htdocs/admin/workflow.php +++ b/htdocs/admin/workflow.php @@ -71,6 +71,12 @@ $workflowcodes = array( 'enabled'=>(!empty($conf->commande->enabled) && !empty($conf->facture->enabled)), 'picto'=>'bill' ), + 'WORKFLOW_TICKET_CREATE_INTERVENTION' => array ( + 'family'=>'create', + 'position'=>25, + 'enabled'=>(!empty($conf->ticket->enabled) && !empty($conf->ficheinter->enabled)), + 'picto'=>'ticket' + ), 'separator1'=>array('family'=>'separator', 'position'=>25, 'title'=>''), From 8db171ae4153dbafc41bf3037b8d575d2d5ba912 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Thu, 10 Feb 2022 17:11:35 +0100 Subject: [PATCH 03/10] add translation string for workflow ticket fichinter creation --- htdocs/langs/en_US/workflow.lang | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/langs/en_US/workflow.lang b/htdocs/langs/en_US/workflow.lang index 6ddf8d9c6a3..e5c07583931 100644 --- a/htdocs/langs/en_US/workflow.lang +++ b/htdocs/langs/en_US/workflow.lang @@ -7,6 +7,7 @@ descWORKFLOW_PROPAL_AUTOCREATE_ORDER=Automatically create a sales order after a descWORKFLOW_PROPAL_AUTOCREATE_INVOICE=Automatically create a customer invoice after a commercial proposal is signed (the new invoice will have same amount as the proposal) descWORKFLOW_CONTRACT_AUTOCREATE_INVOICE=Automatically create a customer invoice after a contract is validated descWORKFLOW_ORDER_AUTOCREATE_INVOICE=Automatically create a customer invoice after a sales order is closed (the new invoice will have same amount as the order) +descWORKFLOW_TICKET_CREATE_INTERVENTION=Create an intervention when opening a ticket from backend and link it to the ticket. # Autoclassify customer proposal or order descWORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL=Classify linked source proposal as billed when sales order is set to billed (and if the amount of the order is the same as the total amount of the signed linked proposal) descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal as billed when customer invoice is validated (and if the amount of the invoice is the same as the total amount of the signed linked proposal) From ea68ed9c07e55e84cc3a356d906db27960d2c3a6 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Mon, 7 Feb 2022 17:02:19 +0100 Subject: [PATCH 04/10] move automatic intervention creation from ticket/card.php to triggers/workflow.php --- ...e_20_modWorkflow_WorkflowManager.class.php | 23 ++++++++++++++++++- htdocs/ticket/card.php | 22 ------------------ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php index 4e98af5c6c7..ff9787dbb06 100644 --- a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -435,7 +435,6 @@ class InterfaceWorkflowManager extends DolibarrTriggers $number_contracts_found = 0; foreach ($company_ids as $company_id) { $contrat->socid = $company_id; - $list = $contrat->getListOfContracts($option = 'all', $status = [Contrat::STATUS_DRAFT, Contrat::STATUS_VALIDATED], $product_categories = [$conf->global->TICKET_PRODUCT_CATEGORY], $line_status = [ContratLigne::STATUS_INITIAL, ContratLigne::STATUS_OPEN]); if (is_array($list) && !empty($list)) { $number_contracts_found = count($list); @@ -457,6 +456,28 @@ class InterfaceWorkflowManager extends DolibarrTriggers if (empty(NOLOGIN)) setEventMessage($langs->trans('TicketNoContractFoundToLink'), 'mesgs'); } } + // Automatically create intervention + if (!empty($conf->ficheinter->enabled) && !empty($conf->ticket->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_TICKET_CREATE_INTERVENTION) && !empty($object->fk_soc)) { + $fichinter = new Fichinter($this->db); + $fichinter->socid = $object->fk_soc; + $fichinter->fk_project = $projectid; + $fichinter->fk_contrat = (int) $object->fk_contract; + $fichinter->author = $user->id; + $fichinter->model_pdf = 'soleil'; + $fichinter->origin = $object->element; + $fichinter->origin_id = $object->id; + + // Extrafields + $extrafields = new ExtraFields($this->db); + $extrafields->fetch_name_optionals_label($fichinter->table_element); + $array_options = $extrafields->getOptionalsFromPost($fichinter->table_element); + $fichinter->array_options = $array_options; + + $id = $fichinter->create($user); + if ($id <= 0) { + setEventMessages($fichinter->error, null, 'errors'); + } + } } return 0; } diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 1cebeec3506..99913e6c997 100755 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -254,28 +254,6 @@ if (empty($reshook)) { $result = $object->assignUser($user, $user->id, 1); $object->add_contact($user->id, "SUPPORTTEC", 'internal'); } - - // Auto create fiche intervention - if (!empty($conf->global->TICKET_AUTO_CREATE_FICHINTER_CREATE)) { - $fichinter = new Fichinter($db); - $fichinter->socid = $object->fk_soc; - $fichinter->fk_project = $projectid; - $fichinter->fk_contrat = $object->fk_contract; - $fichinter->author = $user->id; - $fichinter->model_pdf = 'soleil'; - $fichinter->origin = $object->element; - $fichinter->origin_id = $object->id; - - // Extrafields - $extrafields->fetch_name_optionals_label($fichinter->table_element); - $array_options = $extrafields->getOptionalsFromPost($fichinter->table_element); - $fichinter->array_options = $array_options; - - $id = $fichinter->create($user); - if ($id <= 0) { - setEventMessages($fichinter->error, null, 'errors'); - } - } } if (!$error) { From 424125ca03403532778069c430e381b323064ca9 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Tue, 8 Feb 2022 11:22:38 +0100 Subject: [PATCH 05/10] Workflow fichinter: use default fichinter pdf model --- .../triggers/interface_20_modWorkflow_WorkflowManager.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php index ff9787dbb06..e229e40fd8a 100644 --- a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -463,7 +463,7 @@ class InterfaceWorkflowManager extends DolibarrTriggers $fichinter->fk_project = $projectid; $fichinter->fk_contrat = (int) $object->fk_contract; $fichinter->author = $user->id; - $fichinter->model_pdf = 'soleil'; + $fichinter->model_pdf = (!empty($conf->global->FICHEINTER_ADDON_PDF)) ? $conf->global->FICHEINTER_ADDON_PDF : 'soleil'; $fichinter->origin = $object->element; $fichinter->origin_id = $object->id; From 35d596e1dcedd7634c39a16b6e0ceea005c505e3 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Thu, 10 Feb 2022 17:28:18 +0100 Subject: [PATCH 06/10] rename constant TICKET_AUTO_CREATE_FICHINTER_CREATE to WORKFLOW_TICKET_CREATE_INTERVENTION --- htdocs/install/mysql/migration/15.0.0-16.0.0.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 1876d3428b4..3859c1331e2 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -117,6 +117,7 @@ INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) value ALTER TABLE llx_ticket ADD COLUMN date_last_msg_sent datetime AFTER date_read; UPDATE llx_const SET name = 'WORKFLOW_TICKET_LINK_CONTRACT' WHERE name = 'TICKET_AUTO_ASSIGN_CONTRACT_CREATE'; +UPDATE llx_const SET name = 'WORKFLOW_TICKET_CREATE_INTERVENTION' WHERE name = 'TICKET_AUTO_CREATE_FICHINTER_CREATE'; CREATE TABLE llx_stock_mouvement_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, From ac7f02e0d37bff9e45884f3630287155158eadd1 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Thu, 10 Feb 2022 17:47:40 +0100 Subject: [PATCH 07/10] stickler corrections --- htdocs/admin/workflow.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/admin/workflow.php b/htdocs/admin/workflow.php index a684d642b2f..a68f49e36e3 100644 --- a/htdocs/admin/workflow.php +++ b/htdocs/admin/workflow.php @@ -72,10 +72,10 @@ $workflowcodes = array( 'picto'=>'bill' ), 'WORKFLOW_TICKET_CREATE_INTERVENTION' => array ( - 'family'=>'create', - 'position'=>25, - 'enabled'=>(!empty($conf->ticket->enabled) && !empty($conf->ficheinter->enabled)), - 'picto'=>'ticket' + 'family'=>'create', + 'position'=>25, + 'enabled'=>(!empty($conf->ticket->enabled) && !empty($conf->ficheinter->enabled)), + 'picto'=>'ticket' ), 'separator1'=>array('family'=>'separator', 'position'=>25, 'title'=>''), From 2ec7818c75cdf2c03801a074aade499e6e2fe7c2 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Fri, 18 Mar 2022 10:13:19 +0100 Subject: [PATCH 08/10] When the ficheinter can't be created, display an error. --- .../interface_20_modWorkflow_WorkflowManager.class.php | 4 ++-- htdocs/fichinter/class/fichinter.class.php | 2 +- htdocs/langs/en_US/interventions.lang | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php index e229e40fd8a..1d46aec1008 100644 --- a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -457,9 +457,9 @@ class InterfaceWorkflowManager extends DolibarrTriggers } } // Automatically create intervention - if (!empty($conf->ficheinter->enabled) && !empty($conf->ticket->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_TICKET_CREATE_INTERVENTION) && !empty($object->fk_soc)) { + if (!empty($conf->ficheinter->enabled) && !empty($conf->ticket->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_TICKET_CREATE_INTERVENTION)) { $fichinter = new Fichinter($this->db); - $fichinter->socid = $object->fk_soc; + $fichinter->socid = (int) $object->fk_soc; $fichinter->fk_project = $projectid; $fichinter->fk_contrat = (int) $object->fk_contract; $fichinter->author = $user->id; diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index fac008ec304..ee2bf9269ce 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -255,7 +255,7 @@ class Fichinter extends CommonObject } if ($this->socid <= 0) { - $this->error = 'ErrorBadParameterForFunc'; + $this->error = 'ErrorFicheinterCompanyDoesNotExist'; dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -1; } diff --git a/htdocs/langs/en_US/interventions.lang b/htdocs/langs/en_US/interventions.lang index 7c117fcd1f2..a57a84fc4c8 100644 --- a/htdocs/langs/en_US/interventions.lang +++ b/htdocs/langs/en_US/interventions.lang @@ -67,3 +67,4 @@ ToCreateAPredefinedIntervention=To create a predefined or recurring intervention ConfirmReopenIntervention=Are you sure you want to open back the intervention %s? GenerateInter=Generate intervention FichinterNoContractLinked=Intervention %s has been created without a linked contract. +ErrorFicheinterCompanyDoesNotExist=Company does not exist. Intervention has not been created. From 7469cf79f5b5694242c0f4c1715828c9f387ea01 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Fri, 18 Mar 2022 10:17:16 +0100 Subject: [PATCH 09/10] enhance option explanation string --- htdocs/langs/en_US/workflow.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/workflow.lang b/htdocs/langs/en_US/workflow.lang index e5c07583931..803a31c9646 100644 --- a/htdocs/langs/en_US/workflow.lang +++ b/htdocs/langs/en_US/workflow.lang @@ -7,7 +7,7 @@ descWORKFLOW_PROPAL_AUTOCREATE_ORDER=Automatically create a sales order after a descWORKFLOW_PROPAL_AUTOCREATE_INVOICE=Automatically create a customer invoice after a commercial proposal is signed (the new invoice will have same amount as the proposal) descWORKFLOW_CONTRACT_AUTOCREATE_INVOICE=Automatically create a customer invoice after a contract is validated descWORKFLOW_ORDER_AUTOCREATE_INVOICE=Automatically create a customer invoice after a sales order is closed (the new invoice will have same amount as the order) -descWORKFLOW_TICKET_CREATE_INTERVENTION=Create an intervention when opening a ticket from backend and link it to the ticket. +descWORKFLOW_TICKET_CREATE_INTERVENTION=On ticket creation, automatically create an intervention. # Autoclassify customer proposal or order descWORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL=Classify linked source proposal as billed when sales order is set to billed (and if the amount of the order is the same as the total amount of the signed linked proposal) descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal as billed when customer invoice is validated (and if the amount of the invoice is the same as the total amount of the signed linked proposal) From 9fec63c9088c75c83da68dde7ffcac19cedfc047 Mon Sep 17 00:00:00 2001 From: Thomas Negre Date: Mon, 4 Apr 2022 10:20:43 +0200 Subject: [PATCH 10/10] Empty commit to re-launch Travis