Attach Report to Email Notification
Estimated reading: 1 minute
You can attach a document, generated by a report already defined in Deepser, to a notification email.
This functionality is configured within Email Events.
EXAMPLE: ATTACH WORKLOG REPORT TO OPERATION CLOSURE NOTIFICATION.
To generate a report and attach it to an email notification you need to edit ‘To’ field of the email event.
In this example the configuration of the REQUESTER – Closed Operation event will be changed.
Replace the PHP code in the field ‘To‘ with the following one.
//set Requester User as recipient
$user = $this->getModel()->getRequesterUser();
if ($user && $user->getId()){
$this->changeLanguage($user->getLocale());
$this->addTo($user->getEmail());
}
$attachment = Deep::getModel('deep_attachment/attachment');
//load the report instance
$report = Deep::getModel('deep_report/report')->load(14); // id 14 = Worklog Report
//pass to the report the id of the operation
$report->setFormData(['operation_id' => $this->getModel()->getId()]);
//run the report
$reportHistory = $report->run();
//set document as attachment
$attachment->setContent($reportHistory->getContent());
//define naming template
$attachment->setFileName('Worklog Report_'. $this->getModel()->getId() . '.pdf');
//set filetype
$attachment->setFileType(Zend_Mime::TYPE_OCTETSTREAM);
//add attachment to the message
$mailAttachments = new Varien_Data_Collection();
$mailAttachments->addItem($attachment);
$this->getMailbox()->setForcedAttachments($mailAttachments);