<?php
namespace App\Dashboard\Widget; class OrderCashingsList extends \Engine\Dashboard\Widgets\WidgetAbstract { protected $cacheLifetime = 60; protected function getDefaultOptions() { $return = []; return $return; } protected function populateLocalOptionsForm(\Engine\Form\Container\GeneralAbstract $form) { return $form; } protected function getWidgetCacheLifeDurations() { return [0, 30, 60, 300, 600, 900, 1800, 3600]; } protected function extractFormOptions($formData) { $options = []; $this->setOptions($options); } protected function getContentId() { return $this->getOption_rec('idOrder')."_".serialize($this->getOptions()); } protected function getData() { $calledClass = get_called_class(); $className = stripClassNamespace($calledClass); $loaderLang = \App\Loader_Lang::getInstance(); $loaderLang->loadAppFile("_customLoad/dashboard/widgets/_general.lang.php"); $loaderLang->loadAppFile("_customLoad/dashboard/widgets/{$className}.lang.php"); $loaderLang->loadAppFile("invoices/cashings/management/cashings.lang.php"); $_LANG = $loaderLang->getAll(); $output = []; if ($this->getOption_rec('idOrder')) { if (!is_numeric($this->getOption_rec('idOrder')) || $this->getOption_rec('idOrder') <= 0) { $output['errorMessage'] = $_LANG['dashboard']['widgetsList'][$calledClass]['messages']['invalidIdOrder']; } if (!$output['errorMessage']) { $orderEntity = \Entity\Order::select($this->getOption_rec('idOrder')); if (!$orderEntity->recordExists()) { $output['errorMessage'] = $_LANG['dashboard']['widgetsList'][$calledClass]['messages']['invalidIdOrder']; } switch(\App\UserAccess\CurrentUserAccessFast::getInstance()->getAccessOptionValue('reservationView')) { case 'all': break; case 'own': if ($orderEntity->idUser != CURRENT_ID_USER) { $output['errorMessage'] = $_LANG['dashboard']['widgetsList'][$calledClass]['messages']['reservationView']['own']; } break; case 'deptAndOff': if ($orderEntity->idOffice != CURRENT_ID_OFFICE || $orderEntity->user->idDepartment != CURRENT_ID_DEPT) { $output['errorMessage'] = $_LANG['dashboard']['widgetsList'][$calledClass]['messages']['reservationView']['deptAndOff']; } break; case 'office': if ($orderEntity->idOffice != CURRENT_ID_OFFICE) { $output['errorMessage'] = $_LANG['dashboard']['widgetsList'][$calledClass]['messages']['reservationView']['office']; } break; default: throw new \Engine\Dashboard\Exception('Wrong user access value for `reservationView` in `'.__METHOD__.'` method.'); } } } if (!$output['errorMessage']) { $orderHelper = \App\Dashboard\Widget\Helper\Order::getInstance($this->getOption_rec('idOrder')); $output['cashingsList'] = $orderHelper->getInvoiceCashingsList(); foreach ($output['cashingsList'] as $idCashing => $det) { if ($det['voidTime']) { continue; } $output['groupedCashingTotals'][$det['currency']] += $det['value']; } $buttonGeneralStatusRestrictionList = []; if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('cashingDocumentsManagement')) { $buttonGeneralStatusRestrictionList['issueDocuments'] = true; } $output['buttonGeneralStatusRestriction'] = $buttonGeneralStatusRestrictionList; $output['lang'] = $_LANG['Invoices']['Cashings']; $output['columnsList'] = [ 'docNumber' => true, 'docDate' => true, 'docType' => true, 'value' => true, 'responsible' => true, 'invoiceDetails' => true, 'issued' => true, 'blocked' => true, 'voided' => true, 'viewOption' => true, ]; } return $output; } }