<?php
 namespace App\Dashboard\Widget; class QuickReports_TopAgentsPerf extends QuickReports_GeneralAbstract { use Traits\FinancialWidget; protected function definePivotSheets(\App\Dashboard\Widget\Helper\QrSheetsManager $qrSheetsManager) { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $lang = $_LANG['dashboard']['widgetsList']['App\Dashboard\Widget\QuickReports_TopAgentsPerf']['sheets']; if ($this->getOption('reportCurrency')=='default') { $reportCurrency = 'default'; $currency = \App\Config\Currencies::getInstance()->getDefaultCurrency(); } else { $reportCurrency = 'work'; $currency = \App\Config\Currencies::getInstance()->getWorkCurrency(); } $periodEnd = TODAY_YEAR; $periodStart = TODAY_YEAR - 3; $defaultFilters = [ ['column'=>'invoiceDateY', 'operation'=>'BETWEEN', 'value'=>[$periodStart, $periodEnd]], ['column'=>'invoiceVoidDate', 'operation'=>'IS NULL'], ['column'=>'invoiceIssueDate', 'operation'=>'IS NOT NULL'], ]; $pivotContentGen1 = new \App\QuickReports\PivotTables\GenerateContent('ClientInvoiceRows'); $pivotContentGen1->addFilters($defaultFilters); $pivotContentGen1->setRowsField('invoiceDateY'); $pivotContentGen1->setRowsOrder('invoiceDateY', null, 'ASC'); if ($reportCurrency == 'default') { $pivotContentGen1->setDataField('rowTtlDef', 'SUM'); } else { $pivotContentGen1->setDataField('rowTtlWrk', 'SUM'); } $sh1 = new \App\Dashboard\Widget\Helper\QrSheet($pivotContentGen1, $lang['perYear']['name'], $lang['perYear']['description'], $lang['perYear']['title']); $sh1->setDisplayCurrency($currency); $qrSheetsManager->addQrSheet($sh1, 'perYear'); $pivotContentGen2 = new \App\QuickReports\PivotTables\GenerateContent('ClientInvoiceRows'); $pivotContentGen2->addFilters($defaultFilters); $pivotContentGen2->setColsField('invoiceDateM'); $pivotContentGen2->setColsOrder('invoiceDateM', null, 'ASC'); $pivotContentGen2->setRowsField('serviceIdUser'); $pivotContentGen2->setRowsLimit(10, true); if ($reportCurrency == 'default') { $pivotContentGen2->setRowsOrder('rowTtlDef', 'SUM', 'DESC'); $pivotContentGen2->setDataField('rowTtlDef', 'SUM'); } else { $pivotContentGen2->setRowsOrder('rowTtlWrk', 'SUM', 'DESC'); $pivotContentGen2->setDataField('rowTtlWrk', 'SUM'); } $sh2 = new \App\Dashboard\Widget\Helper\QrSheet($pivotContentGen2, $lang['agentsPerMonth']['name'], $lang['agentsPerMonth']['description'], $lang['agentsPerMonth']['title']); $sh2->setDisplayCurrency($currency); $qrSheetsManager->addQrSheet($sh2, 'agentsPerMonth'); $pivotContentGen3 = new \App\QuickReports\PivotTables\GenerateContent('ClientInvoiceRows'); $pivotContentGen3->addFilters($defaultFilters); $pivotContentGen3->setColsField('invoiceDateM'); $pivotContentGen3->setColsOrder('invoiceDateM', null, 'ASC'); $pivotContentGen3->setRowsField('serviceCode'); $pivotContentGen3->setRowsLimit(10, true); if ($reportCurrency == 'default') { $pivotContentGen3->setRowsOrder('rowTtlDef', 'SUM', 'DESC'); $pivotContentGen3->setDataField('rowTtlDef', 'SUM'); } else { $pivotContentGen3->setRowsOrder('rowTtlWrk', 'SUM', 'DESC'); $pivotContentGen3->setDataField('rowTtlWrk', 'SUM'); } $sh3 = new \App\Dashboard\Widget\Helper\QrSheet($pivotContentGen3, $lang['agentDetailsPerMonth']['name'], $lang['agentDetailsPerMonth']['description'], $lang['agentDetailsPerMonth']['title']); $sh3->setDisplayCurrency($currency); $qrSheetsManager->addQrSheet($sh3, 'agentDetailsPerMonth'); $qrSheetsManager->setIdDefaultSheet('perYear'); $qrSheetsManager->addReference('perYear', 'rowsFields', 'agentsPerMonth'); $qrSheetsManager->addReference('agentsPerMonth', 'rowsFields', 'agentDetailsPerMonth'); } protected function getDefaultOptions() { return [ 'reportCurrency' => 'work', ]; } protected function populateLocalOptionsForm(\Engine\Form\Container\GeneralAbstract $form) { $loaderLang = \App\Loader_Lang::getInstance(); $loaderLang->loadAppFile("_customLoad/dashboard/widgets/_general.lang.php"); $_LANG = $loaderLang->getAll(); $fieldset = \Engine\Form\Container\Fieldset::create(''); $defCurr = \App\Config\Currencies::getInstance()->getDefaultCurrency(); $workCurr = \App\Config\Currencies::getInstance()->getWorkCurrency(); $field = new \Engine\Form\Input\Radio($_LANG['dashboard']['widgets']['_GENERAL_']['qrExtra']['currency'], 'reportCurrency', $this->getOption('reportCurrency')); $field->setPossibleValues(['default'=>sprintf($_LANG['dashboard']['widgets']['_GENERAL_']['qrExtra']['defCurr'], $defCurr), 'work'=>sprintf($_LANG['dashboard']['widgets']['_GENERAL_']['qrExtra']['wrkCurr'], $workCurr)]); $fieldset->addElement($field); $form->addContainer($fieldset); return $form; } protected function extractFormOptions($formData) { $options = ['reportCurrency' => $formData['reportCurrency'] ]; $this->setOptions($options); } }