<?php
 namespace App\Dashboard\Widget; class QuickReports_TopSuppliers 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_TopSuppliers']['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 = $periodEnd - 3; $defaultFilters = [ ['column'=>'invoiceDateY', 'operation'=>'BETWEEN', 'value'=>[$periodStart, $periodEnd] ], ['column'=>'statusOp', 'operation'=>'=', 'value'=>'confirmed' ], ]; $pivotContentGen = new \App\QuickReports\PivotTables\GenerateContent('SupplierInvoiceRows'); $pivotContentGen->addFilters($defaultFilters); $pivotContentGen->setRowsField('idSupplier'); $pivotContentGen->setRowsLimit(10, true); $pivotContentGen->setColsField('invoiceDateY'); $pivotContentGen->setColsOrder('invoiceDateY', null, 'ASC'); if ($reportCurrency == 'default') { $pivotContentGen->setRowsOrder('rowTtlDef', 'SUM', 'DESC'); $pivotContentGen->setDataField('rowTtlDef', 'SUM'); } else { $pivotContentGen->setRowsOrder('rowTtlWrk', 'SUM', 'DESC'); $pivotContentGen->setDataField('rowTtlWrk', 'SUM'); } $sh = new \App\Dashboard\Widget\Helper\QrSheet($pivotContentGen, $lang['suppPerYears']['name'], $lang['suppPerYears']['description'], $lang['suppPerYears']['title']); $sh->setDisplayCurrency($currency); $qrSheetsManager->addQrSheet($sh, 'suppPerYears'); $pivotContentGen = new \App\QuickReports\PivotTables\GenerateContent('SupplierInvoiceRows'); $pivotContentGen->addFilters($defaultFilters); $pivotContentGen->setRowsField('idSupplier'); $pivotContentGen->setRowsLimit(10, true); $pivotContentGen->setColsField('invoiceDateM'); $pivotContentGen->setColsOrder('invoiceDateM', null, 'ASC'); if ($reportCurrency == 'default') { $pivotContentGen->setRowsOrder('rowTtlDef', 'SUM', 'DESC'); $pivotContentGen->setDataField('rowTtlDef', 'SUM'); } else { $pivotContentGen->setRowsOrder('rowTtlWrk', 'SUM', 'DESC'); $pivotContentGen->setDataField('rowTtlWrk', 'SUM'); } $sh = new \App\Dashboard\Widget\Helper\QrSheet($pivotContentGen, $lang['suppPerMonths']['name'], $lang['suppPerMonths']['description'], $lang['suppPerMonths']['title']); $sh->setDisplayCurrency($currency); $qrSheetsManager->addQrSheet($sh, 'suppPerMonths'); $qrSheetsManager->addReference('suppPerYears', 'colsFields', 'suppPerMonths'); $qrSheetsManager->setIdDefaultSheet('suppPerYears'); } 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); } } 