Report Configuration
Within the report configuration, an admin user can:
- Create a custom folder
- Create an executable report
- Schedule a report for automatic delivery to one or more users
Folder Creation
To create a new folder for your reports, you can go to “System->Report->Folder”. On the folders grid you can see all the previously created folders.
By clicking on Add Folder button, the following screen will appear:
Below is a description of the available fields:
Field | Description |
Name | Folder’s name |
Code | This field is used to uniquely identify a folder. It is best |
Position | This field indicates the position and listing of this folder on the grid. |
Icon | On this field you can use an image as icon for the folder. |
Enabled Groups | This field is used to limit visibility of users that can have access to this folder. |
Status | Select field that is used to enable or disable the folder. |
Report Creation
To configure a new report, you should go under “System->Report->Report”.
You can now see the reports grid and the “Add Report” button, when you click on it you can create a new report.
By clicking on Add Report button the following screen will appear:
Below is a description of available fields:
Field | Description |
Name | Report Name |
Code | Report’s code field is used to identify the report with a unique string. Utilizing a single string for this purpose is considered the most effective approach. |
Library | Field of select type where you choose the type of report PDF, XLS and CVS. |
Folder | Select field where select the destination folder for placing this report. |
CSV Delimiter | This field is only visible if the library is ‘CSV’. Delimiter field can be populated by a character such as ‘ ; ’ or ‘ , ’ which will be used as a separator between file records. |
CSV Enclosure | This field is only visible if library is ‘CSV’. CSV enclosure field is used to define the enclosing characters of each record, for example double or single quotes. |
Form Render Expression
The initial stage in setting up a report involves configuring Form Render Expression. On this field you can configure all the Filters based on which data will be extracted from the report. This field is configured in the same way for both: PDF and Excel report.
To add the filters the following custom code is used:
// Firstly it is retrieved type values array. This values will be used as options on the filter field.
$type = Deep::helper('deep_service/type')->typeToOptionArray();
$this->addField(
'type_id', // this indicates the filter field code, which has to be unique for each field
'select', // filter field type, in this case its select, but it can also be text, date
array(
'label' => Deep::helper('deep_service')->__('Type'), // Label of the filter field
'multiple' => 'multiple', // In fields of type select you can add this parameter if you want to select multiple choices for this //filter
'values' => $type, // If field is of type select you also need to provide the option values that can be selected from this field. // The given value for this parameter should be of type array. In this case the given value is an array with all the service types.
'columns' =>1 // This field indicates the width of this field on the report fieldset.
)
);
$this->addField(
'created_at_from',
'date',
array(
'label' => Deep::helper('deep_service')->__('(Created Date) From'),
'image' => $this->getSkinUrl('images/grid-cal.png'),
'time' => true, // this parameter indicates whether you want to display also the time on this field.
// with format parameter you set the format of the date. In this case the given value gives a format date based on the //current user Local time zone.
'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
'columns' =>1,
)
);
$this->addField(
'created_at_to',
'date',
array(
'label' => Deep::helper('deep_service')->__('(Created Date) To'),
'image' => $this->getSkinUrl('images/grid-cal.png'),
'time' => true,
'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
'columns' =>1, ));
After the configuration of form render expression is finished you can click on the “Preview” button, to see all the filters created. An example PDF report is shown below where there are extracted tickets filtered by type and creation date.
Here is the preview of report filters:
Then to extract the report based on these filters, you can click on the “Run” button on the right corner.
NOTE: If the “Before Run Expression” or “Run Expression” script is not correct, the report will not run.
Before Run Expression
Before Run Expression is used to filter the collection that will be shown on the report, by using the filter fields configured on the “Form Render Expression”.
On the first line the PDF library is initialized by setting the paper format and orientation.
The following code iterates through each filter field and filters the collection based on those. Then the variable assigned with the operation collection is set to the report object.
// PDF library is initialized by setting the paper format and orientation.
$this->loadLibraryObj()->setPaper('A4', 'landscape');
$filters = $this->getFormData(); // Retrieve all the filters from Form Render Expression
// Retrieve the operation collection
$collection = Deep::getResourceModel('deep_service/operation_collection');
// Iterate through each filter field and filter the collection based on those.
if ($filters['created_at_from'] !='')
{
$collection->addFieldToFilter( 'main_table.created_at', [ 'gt' =>
Deep::helper('deep_calendar')->filterDateTime($value) ] );
}
if ($filters['created_at_to'])
{
$collection->addFieldToFilter( 'main_table.created_at', [ 'lt' =>
Deep::helper('deep_calendar')->filterDateTime($value) ] );
}
if ($filters['type_id'] !='') {
$collection->addFieldToFilter( 'main_table.type_id', [ 'in' => $value ] );
}
// Then the variable assigned with the operation collection is set to the report object.
$this->setData('operation_collection',$collection);
Run Expression
The run Expression Field is used to configure the layout structure of the report as well as retrieve all the records from the “Before Run Expression” field and display them on the report. On case of a PDF report, you can write html code to create tables and styles for it and Php code to retrieve all the needed values that are to be shown.
When the report is of type PDF here is the example of it: On the first part of the code there are some styles to format the page structure and also the table that will display the operation data.
getName();
// collection of operation to be later used on the table
$collection = $this->getData('collection');
// map the fields that are to be shown on the table of operation records
$fields = [
'entity_id'=>'Id',
'type_id'=>'Service Type',
'title'=>'Title',
'requester_username'=>'Requester User',
'status'=>'Status',
];
// retrieve the status List values
$statusList = Deep::helper('deep_list')->loadListValues(Deep_Service_Model_Operation::LIST_CODE_STATUS)->toOptionHash();
?>
__($reportName); ?>
__($reportName); ?>
__($reportName);
?>
count() == 0){
echo "No data found";
return;}?>
$value): ?>
__($value); ?>
$value): ?>
load($operation->getData($field),'username')->getId() ? Deep::getModel('deep_admin/user')->load($operation->getData($field),'username')->getName() :'' ;
}else if($field == 'status')
{
$value = $statusList[$operation->getData($field)]; // Retrieve status Value Label
}else if($field == 'type_id')
{
$value = Deep::getModel('deep_service/type')->load($operation->getData($field))->getId() ? Deep::getModel('deep_service/type')->load($operation->getData($field))->getName() :'' ;
}else{
$value = $operation->getData($field);
}
echo $value;
?>
Scheduled Report
Scheduled Reports are reports that are sent by email periodically through a cron expression. To configure a scheduled report you should go under “System->Report-> Scheduled Report” and click on the ‘Add Scheduled Report’ button.
By clicking on “Add Scheduled Report” button you can create a scheduled report.
Below there is an example of a scheduled report that sends an email with the Invoice Report attached, every first day of the month.
Below is a description of the available fields:
Field | Description |
Name | With this field you can set the Scheduled Report’s name. |
Report | Select field where you can select a configured report that will be used as the scheduled report. |
Cron Expression | On this field you can set the time period on which the report will be sent. |
Send To | Text field where you can set the email addresses divided by ‘;’ that will receive the report. |
Message Subject | Custom code expression field where you can set the email subject in html format, the same format used as in email template. |
Message Body | Custom code expression field where you can set the email message body in html format, the same format used as in email template. |
Mailbox Id | Select field where you can choose the mailbox from which the email will be sent. |
Email Template | Select field where you can choose the email template that will be used for this email. When selecting an email template, the ‘message subject’ and ‘message body’ fields will be ignored. |
Status | With this field you can ‘enable’ or ‘disable’ the scheduled report. |