diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 12628d059b661..6475779adc7d7 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -169,14 +169,7 @@ class Notify 'ACTION_CREATE', 'CONTRACT_MODIFY', 'STOCKTRANSFER_CREATE', - 'STOCKTRANSFER_MODIFY', - 'STOCKTRANSFER_VALIDATE', - 'STOCKTRANSFER_UNVALIDATE', - 'STOCKTRANSFER_CLOSE', - 'STOCKTRANSFER_DESTOCK', - 'STOCKTRANSFER_DESTOCK_CANCEL', - 'STOCKTRANSFER_ADDSTOCK', - 'STOCKTRANSFER_ADDSTOCK_CANCEL' + 'STOCKTRANSFER_MODIFY' ); /** @@ -943,6 +936,30 @@ public function send($notifcode, $object, $filename_list = array(), $mimetype_li $object_type = 'contract'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextContractModified", $link, $context_info); break; + case 'STOCKTRANSFER_CREATE': + $link = ''.$newref.''; + $dir_output = $conf->stocktransfer->dir_output."/stocktransfer/".dol_sanitizeFileName($newref); + $object_type = 'stocktransfer'; + $mesg = $outputlangs->transnoentitiesnoconv('Notify_STOCKTRANSFER_CREATE')." ".$link; + break; + case 'STOCKTRANSFER_MODIFY': + $link = ''.$newref.''; + $dir_output = $conf->stocktransfer->dir_output."/stocktransfer/".dol_sanitizeFileName($newref); + $object_type = 'stocktransfer'; + $template = 'STOCKTRANSFER_MODIFY_TEMPLATE'; + $eventKey = 'Notify_STOCKTRANSFER_MODIFY'; + if (!empty($object->context['stocktransfer_event'])) { + $eventKeyCandidate = 'Notify_STOCKTRANSFER_MODIFY_'.strtoupper($object->context['stocktransfer_event']); + $templateCandidate = 'STOCKTRANSFER_MODIFY_'.strtoupper($object->context['stocktransfer_event']).'_TEMPLATE'; + if (!empty(getDolGlobalString($templateCandidate))) { + $template = $templateCandidate; + } + if ($outputlangs->transnoentities($eventKeyCandidate) != $eventKeyCandidate) { + $eventKey = $eventKeyCandidate; + } + } + $mesg = $outputlangs->transnoentitiesnoconv($eventKey)." ".$link; + break; default: $object_type = $object->element; $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type); @@ -955,7 +972,9 @@ public function send($notifcode, $object, $filename_list = array(), $mimetype_li $formmail = new FormMail($this->db); $arraydefaultmessage = null; - $template = $notifcode.'_TEMPLATE'; + if (empty($template)) { + $template = $notifcode.'_TEMPLATE'; + } $labeltouse = getDolGlobalString($template); if (!empty($labeltouse)) { $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type, $user, $outputlangs, 0, 1, $labeltouse); diff --git a/htdocs/install/mysql/data/llx_c_action_trigger.sql b/htdocs/install/mysql/data/llx_c_action_trigger.sql index aab9027f223f6..9197655afc1df 100644 --- a/htdocs/install/mysql/data/llx_c_action_trigger.sql +++ b/htdocs/install/mysql/data/llx_c_action_trigger.sql @@ -154,13 +154,6 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MRP_MO_CANCEL','MO canceled','Executed when a MO is canceled','mrp',663); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_CREATE','Stock transfer created','Executed when a stock transfer is created','stocktransfer',670); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_MODIFY','Stock transfer modified','Executed when a stock transfer is modified','stocktransfer',671); -insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_VALIDATE','Stock transfer validated','Executed when a stock transfer is validated','stocktransfer',672); -insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_UNVALIDATE','Stock transfer back to draft','Executed when a stock transfer is set back to draft','stocktransfer',673); -insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_DESTOCK','Stock transfer source stock decremented','Executed when source warehouses stock is decremented for a stock transfer','stocktransfer',674); -insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_DESTOCK_CANCEL','Stock transfer source stock decrement canceled','Executed when source warehouses stock decrement is canceled for a stock transfer','stocktransfer',675); -insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_CLOSE','Stock transfer closed','Executed when a stock transfer is closed after destination stock increment','stocktransfer',676); -insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_ADDSTOCK','Stock transfer destination stock incremented','Executed when destination warehouses stock is incremented for a stock transfer','stocktransfer',677); -insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('STOCKTRANSFER_ADDSTOCK_CANCEL','Stock transfer destination stock increment canceled','Executed when destination warehouses stock increment is canceled for a stock transfer','stocktransfer',678); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTACT_CREATE','Contact address created','Executed when a contact is created','contact',50); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTACT_MODIFY','Contact address update','Executed when a contact is updated','contact',51); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTACT_SENTBYMAIL','Mails sent from third party card','Executed when you send email from contact address record','contact',52); diff --git a/htdocs/install/mysql/migration/23.0.0-24.0.0.sql b/htdocs/install/mysql/migration/23.0.0-24.0.0.sql index f30a42f81e255..db2f17152c604 100644 --- a/htdocs/install/mysql/migration/23.0.0-24.0.0.sql +++ b/htdocs/install/mysql/migration/23.0.0-24.0.0.sql @@ -193,13 +193,6 @@ INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_CREATE','Stock transfer created','Executed when a stock transfer is created','stocktransfer',670); INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_MODIFY','Stock transfer modified','Executed when a stock transfer is modified','stocktransfer',671); -INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_VALIDATE','Stock transfer validated','Executed when a stock transfer is validated','stocktransfer',672); -INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_UNVALIDATE','Stock transfer back to draft','Executed when a stock transfer is set back to draft','stocktransfer',673); -INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_DESTOCK','Stock transfer source stock decremented','Executed when source warehouses stock is decremented for a stock transfer','stocktransfer',674); -INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_DESTOCK_CANCEL','Stock transfer source stock decrement canceled','Executed when source warehouses stock decrement is canceled for a stock transfer','stocktransfer',675); -INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_CLOSE','Stock transfer closed','Executed when a stock transfer is closed after destination stock increment','stocktransfer',676); -INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_ADDSTOCK','Stock transfer destination stock incremented','Executed when destination warehouses stock is incremented for a stock transfer','stocktransfer',677); -INSERT IGNORE INTO llx_c_action_trigger (code,label,description,elementtype,rang) VALUES ('STOCKTRANSFER_ADDSTOCK_CANCEL','Stock transfer destination stock increment canceled','Executed when destination warehouses stock increment is canceled for a stock transfer','stocktransfer',678); ALTER TABLE llx_c_ticket_category ADD COLUMN fk_ticket_type integer NULL; -- end of migration diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 90e8abe17e749..897a0a6a1b58c 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -427,10 +427,11 @@ SendPrompt=Send ConfirmAiAction=Are you sure you want to %1$s using the %2$s tool? Notify_STOCKTRANSFER_CREATE=Stock transfer created -Notify_STOCKTRANSFER_VALIDATE=Stock transfer validated -Notify_STOCKTRANSFER_UNVALIDATE=Stock transfer set back to draft -Notify_STOCKTRANSFER_DESTOCK=Source stock decreased for stock transfer -Notify_STOCKTRANSFER_DESTOCK_CANCEL=Source stock decrease cancelled for stock transfer -Notify_STOCKTRANSFER_CLOSE=Stock transfer closed -Notify_STOCKTRANSFER_ADDSTOCK=Destination stock increased for stock transfer -Notify_STOCKTRANSFER_ADDSTOCK_CANCEL=Destination stock increase cancelled for stock transfer +Notify_STOCKTRANSFER_MODIFY=Stock transfer modified +Notify_STOCKTRANSFER_MODIFY_ADDSTOCK_CANCEL=Destination stock increase cancelled for stock transfer +Notify_STOCKTRANSFER_MODIFY_ADDSTOCK=Destination stock increased for stock transfer +Notify_STOCKTRANSFER_MODIFY_CLOSE=Stock transfer closed +Notify_STOCKTRANSFER_MODIFY_DESTOCK_CANCEL=Source stock decrease cancelled for stock transfer +Notify_STOCKTRANSFER_MODIFY_DESTOCK=Source stock decreased for stock transfer +Notify_STOCKTRANSFER_MODIFY_UNVALIDATE=Stock transfer set back to draft +Notify_STOCKTRANSFER_MODIFY_VALIDATE=Stock transfer validated diff --git a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php index 1d36b0e0af6ac..419a7915e7de5 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php @@ -634,8 +634,11 @@ public function validate($user, $notrigger = 0) } if (!$error && !$notrigger) { + if (empty($this->context['stocktransfer_event'])) { + $this->context['stocktransfer_event'] = 'validate'; + } // Call trigger - $result = $this->call_trigger('STOCKTRANSFER_VALIDATE', $user); + $result = $this->call_trigger('STOCKTRANSFER_MODIFY', $user); if ($result < 0) { $error++; } @@ -718,7 +721,11 @@ public function setDraft($user, $notrigger = 0) return 0; } - return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFER_UNVALIDATE'); + if (empty($this->context['stocktransfer_event'])) { + $this->context['stocktransfer_event'] = 'unvalidate'; + } + + return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFER_MODIFY'); } /** @@ -735,7 +742,11 @@ public function cancel($user, $notrigger = 0) return 0; } - return $this->setStatusCommon($user, self::STATUS_CLOSED, $notrigger, 'STOCKTRANSFER_CLOSE'); + if (empty($this->context['stocktransfer_event'])) { + $this->context['stocktransfer_event'] = 'close'; + } + + return $this->setStatusCommon($user, self::STATUS_CLOSED, $notrigger, 'STOCKTRANSFER_MODIFY'); } /** diff --git a/htdocs/product/stock/stocktransfer/stocktransfer_card.php b/htdocs/product/stock/stocktransfer/stocktransfer_card.php index 9272e68103962..9cd0d17f922c1 100644 --- a/htdocs/product/stock/stocktransfer/stocktransfer_card.php +++ b/htdocs/product/stock/stocktransfer/stocktransfer_card.php @@ -146,6 +146,14 @@ $triggermodname = 'STOCKTRANSFER_MODIFY'; // Name of trigger action code to execute when we modify record + if ($action == 'confirm_validate' && $confirm == 'yes') { + $object->context['stocktransfer_event'] = 'validate'; + } elseif ($action == 'confirm_setdraft' && $confirm == 'yes') { + $object->context['stocktransfer_event'] = 'unvalidate'; + } elseif ($action == 'confirm_close' && $confirm == 'yes') { + $object->context['stocktransfer_event'] = 'close'; + } + // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; @@ -309,12 +317,8 @@ $object->setStatut($object::STATUS_TRANSFERED, $id); $object->status = $object::STATUS_TRANSFERED; $object->date_reelle_depart = dol_now(); + $object->context['stocktransfer_event'] = 'destock'; $object->update($user); - $result = $object->call_trigger('STOCKTRANSFER_DESTOCK', $user); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } setEventMessage('StockStransferDecremented'); } } @@ -341,12 +345,8 @@ $object->setStatut($object::STATUS_VALIDATED, $id); $object->status = $object::STATUS_VALIDATED; $object->date_reelle_depart = null; + $object->context['stocktransfer_event'] = 'destock_cancel'; $object->update($user); - $result = $object->call_trigger('STOCKTRANSFER_DESTOCK_CANCEL', $user); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } setEventMessage('StockStransferDecrementedCancel', 'warnings'); } } @@ -373,17 +373,8 @@ $object->setStatut($object::STATUS_CLOSED, $id); $object->status = $object::STATUS_CLOSED; $object->date_reelle_arrivee = dol_now(); + $object->context['stocktransfer_event'] = 'addstock'; $object->update($user); - $result = $object->call_trigger('STOCKTRANSFER_CLOSE', $user); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - $result = $object->call_trigger('STOCKTRANSFER_ADDSTOCK', $user); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } setEventMessage('StockStransferIncrementedShort'); } } @@ -410,12 +401,8 @@ $object->setStatut($object::STATUS_TRANSFERED, $id); $object->status = $object::STATUS_TRANSFERED; $object->date_reelle_arrivee = null; + $object->context['stocktransfer_event'] = 'addstock_cancel'; $object->update($user); - $result = $object->call_trigger('STOCKTRANSFER_ADDSTOCK_CANCEL', $user); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } setEventMessage('StockStransferIncrementedShortCancel', 'warnings'); } }