<?php
namespace Modules\Documents\ImportedDocuments; class Model extends \App\Mvc\Model_ListingAbstract { public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams) { $filters=$listingParams->getFilters(); $listObj = new \App\EntityList\ImportedDocuments(); $listObj->setColumns(['idExternalSystem', 'docCategory', 'docType', 'docNumber', 'docCategory', 'docDate', 'docValue', 'docCurrency', 'addTime', 'idAddUser', 'status', 'idSupplier', 'idCustomer', 'idCorporate', 'systemStatus', 'usedValue', 'idUser', 'idAgencyBankAccount', 'idIssueUser', 'issueTime', ]); if ($filters['docDate']) { $listObj->setFilter('docDate', '>=', $filters['docDate']['start']); $listObj->setFilter('docDate', '<=', $filters['docDate']['end']); } if ($filters['docCategory']) { $listObj->setFilter('docCategory', '=', $filters['docCategory']); } if ($filters['docType']) { $listObj->setFilter('docType', '=', $filters['docType']); } if ($filters['addDate']['start']) { $listObj->setFilter('addTime', '>=', $filters['addDate']['start'].' 00:00:00'); } if ($filters['addDate']['end']) { $listObj->setFilter('addTime', '<=', $filters['addDate']['end'].' 23:59:59'); } if ($filters['system']) { $listObj->setFilter('idExternalSystem', '=', $filters['system']); } if ($filters['systemStatus']) { $listObj->setFilter('systemStatus', '=', $filters['systemStatus']); } if (is_array($filters['status']) && $filters['status']) { $listObj->setFilter('status', 'IN', array_values($filters['status'])); } if ($filters['issued'] == 'issued') { $listObj->setFilter('issueTime', 'IS NOT NULL'); } elseif ($filters['issued'] == 'notIssued') { $listObj->setFilter('issueTime', 'IS NULL'); } if ($filters['responsible']['id']) { $listObj->setFilter('idUser', '=', $filters['responsible']['id']); } if ($filters['docNumber']) { $listObj->setFilter('docNumber', '=', $filters['docNumber']); } if ($filters['corporate']['id']) { $listObj->setFilter('idCorporate', 'IN', \Entity\Corporate::select($filters['corporate']['id'])->fullDuplicatedCorporatesGroup); } if ($filters['customer']['id']) { $listObj->setFilter('idCustomer', 'IN', \Entity\Customer::select($filters['customer']['id'])->fullDuplicatedCustomersGroup); } if ($filters['supplier']['id']) { $listObj->setFilter('idSupplier', 'IN', \Entity\Supplier::select($filters['supplier']['id'])->fullDuplicatedSuppliersGroup); } if ($filters['docCurrency']) { $listObj->setFilter('docCurrency', '=', $filters['docCurrency']); } if ($filters['idDocSystem']) { $listObj->setFilter('idSystem', '=', $filters['idDocSystem']); } if ($filters['idTina']) { $docIds = array_filter( array_map( function($elem){ return trim($elem);}, explode(',', $filters['idTina']) ) ); $listObj->setFilter('id', 'IN', $docIds); } if ($filters['idAgencyBankAccount']) { if ($filters['idAgencyBankAccount']!='none') { $listObj->setFilter('idAgencyBankAccount', '=', $filters['idAgencyBankAccount']); } else { $listObj->setFilter('idAgencyBankAccount', '=', '0'); } } if ($filters['comments']) { $listObj->setFilter('comments', 'LIKE', "%{$filters['comments']}%"); } if ($filters['remarks']) { $listObj->setFilter('importedDocumentRemarks.value', '=', $filters['remarks']); $listObj->setGroupBy('importedDocument.id'); } if ($filters['docRefId'] and $filters['docRefType']) { $refIds = array_filter( array_map( function($elem){ return trim($elem);}, explode(',', $filters['docRefId']) ) ); $refSearchList = []; switch ($filters['docRefType']) { case 'service': case 'importedService': case 'clientInvoice': case 'supplierInvoice': foreach ($refIds as $refId) { $refSearchList[$filters['docRefType'].':'.$refId] = true; } break; case 'importedOrder': foreach ($refIds as $refId) { $impOrderEnt = \Entity\ImportedOrder::select($refId); foreach($impOrderEnt->importedServicesList as $impServDet) { $refSearchList['importedService:'.$impServDet['id']] = true; } } break; } if ($refSearchList) { $filterSQL = implode( ' OR ', array_fill(0, count($refSearchList), 'docReferences LIKE ?') ); $bindVars = array_map( function($elem) { return '%|'.$elem.'|%';}, array_keys($refSearchList) ); $listObj->setCustomFilter( $filterSQL, $bindVars); } } $listObj = $this->entityList_inheritListingParams($listingParams, $listObj); $this->recordsList = $listObj->exportRecords(); $this->totalRecordsCount = $listObj->getRecordsCount(); } public function getImportedDocumentFiles($idDocument) { $filesList = \Entity\ImportedDocument::select($idDocument)->files; $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $listFiles = []; foreach ($filesList as $fileInfo) { $fullPathFile = APP_REAL_PATH.$CFG['paths']['files'].$fileInfo['file']; $listFiles[] = [ 'fullPathFile' => $fullPathFile, 'file' => $fileInfo['file'], 'name' => $fileInfo['name'], 'fileExists' => \Engine\File::check($fullPathFile), 'time' => $fileInfo['time'], ]; } return $listFiles; } private function _sortByDate($a, $b) { return $a['time'] - $b['time']; } }