Workflow : sort contracts when automatic linking to ticket.
Introduces constants TICKET_PRODUCT_CATEGORY and WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS. Rename constant TICKET_AUTO_ASSIGN_CONTRACT_CREATE to WORKFLOW_TICKET_LINK_CONTRACT.
This commit is contained in:
parent
a14a63fdad
commit
90ab7da40d
@ -424,6 +424,41 @@ class InterfaceWorkflowManager extends DolibarrTriggers
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'TICKET_CREATE') {
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
// Auto link contract
|
||||
if (!empty($conf->contract->enabled) && !empty($conf->ticket->enabled) && !empty($conf->ficheinter->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_TICKET_LINK_CONTRACT) && !empty($conf->global->TICKET_PRODUCT_CATEGORY) && !empty($object->fk_soc)) {
|
||||
|
||||
$societe = new Societe($this->db);
|
||||
$company_ids = (empty($conf->global->WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS)) ? [$object->fk_soc] : $societe->getParentsForCompany($object->fk_soc, [$object->fk_soc]);
|
||||
|
||||
$contrat = new Contrat($this->db);
|
||||
$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);
|
||||
if ($number_contracts_found == 1) {
|
||||
$contractid = $list[0]->id;
|
||||
$object->setContract($contractid);
|
||||
break;
|
||||
} elseif ($number_contracts_found > 1) {
|
||||
foreach($list as $linked_contract) {
|
||||
$object->setContract($linked_contract->id);
|
||||
// don't set '$contractid' so it is not used when creating an intervention.
|
||||
}
|
||||
setEventMessage($langs->trans('TicketManyContractsLinked'), 'warnings');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($number_contracts_found == 0) {
|
||||
setEventMessage($langs->trans('TicketNoContractFoundToLink'), 'mesgs');
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -110,6 +110,8 @@ 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';
|
||||
|
||||
CREATE TABLE llx_stock_mouvement_extrafields (
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
@ -66,3 +66,4 @@ RepeatableIntervention=Template of intervention
|
||||
ToCreateAPredefinedIntervention=To create a predefined or recurring intervention, create a common intervention and convert it into intervention template
|
||||
ConfirmReopenIntervention=Are you sure you want to open back the intervention <b>%s</b>?
|
||||
GenerateInter=Generate intervention
|
||||
FichinterNoContractLinked=Intervention %s has been created without a linked contract.
|
||||
|
||||
@ -258,6 +258,8 @@ TicketNotCreatedFromPublicInterface=Not available. Ticket was not created from p
|
||||
ErrorTicketRefRequired=Ticket reference name is required
|
||||
TicketsDelayForFirstResponseTooLong=Too much time elapsed since ticket opening without any answer.
|
||||
TicketsDelayFromLastResponseTooLong=Too much time elapsed since last answer on this ticket.
|
||||
TicketNoContractFoundToLink=No contract was found to be automatically linked to this ticket. Please link a contract manually.
|
||||
TicketManyContractsLinked=Many contracts have been automatically linked to this ticket. Make sure to verify which should be chosen.
|
||||
|
||||
#
|
||||
# Logs
|
||||
|
||||
@ -255,22 +255,6 @@ if (empty($reshook)) {
|
||||
$object->add_contact($user->id, "SUPPORTTEC", 'internal');
|
||||
}
|
||||
|
||||
// Auto assign contrat
|
||||
$contractid = 0;
|
||||
if (!empty($conf->global->TICKET_AUTO_ASSIGN_CONTRACT_CREATE)) {
|
||||
$contrat = new Contrat($db);
|
||||
$contrat->socid = $object->fk_soc;
|
||||
$list = $contrat->getListOfContracts();
|
||||
|
||||
if (is_array($list) && !empty($list)) {
|
||||
if (count($list) == 1) {
|
||||
$contractid = $list[0]->id;
|
||||
$object->setContract($contractid);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Auto create fiche intervention
|
||||
if (!empty($conf->global->TICKET_AUTO_CREATE_FICHINTER_CREATE)) {
|
||||
$fichinter = new Fichinter($db);
|
||||
@ -292,6 +276,7 @@ if (empty($reshook)) {
|
||||
setEventMessages($fichinter->error, null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user