Contracts and Escalation Rules
Using escalation rules, it is possible to set up, for example, the sending of a notification that a contract will expire soon.
Below we will see how to configure the alert in detail.
Template Email
As a first step, let’s proceed with the creation of a new email template.
To create the new template, you need to follow the following path: System > Tools (1)> Email (2)> Templates (3).
On the screen that will open, press the “Add Mail Template” button.
On the screen that will open immediately afterwards you will need to fill in the fields as indicated:
Field | Value | Note |
Name | Alert contract expiration | Can be changed |
Code | alert_contract_expiration | Can be changed |
Status | Enabled |
|
Subject:
getModel();
$customerName = Deep::getModel('deep_company/company')->load($contract->getCustomerCompanyId())->getName();
$nrContratto = $contract->getContractNumber();
$expirationDate = new Zend_Date(Deep::helper('deep_calendar')->convertDateToUserTimezone($contract->getExpirationDate(), Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), Deep::app()->getLocale()->getLocale()));
$expiringDate = $expirationDate->get('dd/MM/YYYY');
?>
__('Contract Nr.').$nrContratto." - ".Deep::helper('deep_email')->__('expiring on:')." ".$expiringDate; ?>
Body:
getModel();
$nomeContratto = $contract->getName();
$nrContratto = $contract->getContractNumber();
$expiringDate=new DateTime();
$expiringDate=$expiringDate->createFromFormat('Y-m-d H:i:s',$contract->getExpirationDate());
$expiringDate->setTimezone(new DateTimeZone('Europe/Rome'));
$expiringDate=$expiringDate->format('d/m/Y');
$url = Deep::getUrl('adminhtml/contract_contract/edit', ['id' => $contract->getId()]);
?>
includeTemplate("sedoc_header") ?>
$contract->getId()]); ?>
Go to the Contract
includeTemplate("footer") ?>
Escalation Rule
To create the Escalation rule, the following path must be followed: System (1)> Service Configuration (2)> Escalation Rules (3).
On the screen that will appear, press the “Add Rule” button.
On the screen that opens, fill in the data as indicated below.
Field | Value | Note | |
Name | Contract expiration | Can be changed | |
Model Alias | DeepContract – Contract |
| |
Email Event |
| To be filled in later, after the creation of the event | |
Level | 0 | Can be changed. For more info press here | |
Next Level | 1 | Can be changed. For more info press here | |
Cron Expression | 0 * * * * | Every hour | |
Status | Enabled |
| |
After filling in the fields, press the “Apply” button.
Once saved, query-builders will appear. You will need to set the filters as follows:
The filters set are as follows:
- Expiration Date less date after now 30,0,0 à 30 days left before the contract expires.
- Expired equal 0 à The contract has not expired.
Email Event
To create the new event, which will later be linked to the Escalation rule, you need to follow the following path: System > Tools (1)> Email (2)> Event(3).
On the screen that will appear, press the “Add Event” button.
Below are the values to be entered in the required fields:
Field | Value | Note |
Name | Alert contract expiration | Can be changed |
Status | Enabled |
|
Email Template | Alert contract expiration – [alert_contract_expiration] | Field that corresponds to the previously created template |
Model | DeepContract – Contact |
|
Event Expression:
if($this->getModel()->getExpirationDate()){
if($this->getModel()->getId() && $this->getModel()->getData('escalation_rule') && $this->getModel()->getData('escalation_rule')['entity_id'] == 3){
return true;
}
return false;
}
return false;
Note: “3” represents the ID of the escalation rule
To:
$this->addTo('mail.test@mail.com');
Note: ‘mail.test@mail.com’ is to be replaced with the email address to be notified.
Once all the fields are filled in, you will need to save the event by pressing the “Apply” or “Save” button.
Next, we reopen the escalation rule created earlier to set up the newly created event.