<?php
 namespace Modules\Invoices\Cashings\Listing; 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\InvoiceCashings(); $listObj->setColumns(['doc.docDate', 'doc.docNumber', 'doc.docType', 'doc.value', 'doc.currency', 'doc.idUser', 'doc.idBankAccount', 'doc.idOffice', 'doc.addTime', 'doc.voidTime', 'doc.issueTime', 'doc.blockTime', 'doc.idInvoice', 'doc.idImportedDoc', 'inv.invoiceNumber', 'inv.invoiceDate', 'inv.idCorporate', 'inv.idCustomer', ]); if ($filters['id']) { $listObj->setFilter('doc.id', '=', $filters['id']); } if ($filters['idInvoices']) { $idInvoices = explode(",", $filters['idInvoices']); $idInvoices = array_map(function($elm){return trim($elm);}, $idInvoices); $listObj->setFilter('doc.idInvoice', 'IN', $idInvoices); } if ($filters['docDate']['start'] and $filters['docDate']['end']) { $listObj->setFilter('doc.docDate', 'BETWEEN', [$filters['docDate']['start'], $filters['docDate']['end']]); } elseif ($filters['docDate']['start']) { $listObj->setFilter('doc.docDate', '>=', $filters['docDate']['start']); } elseif ($filters['docDate']['end']) { $listObj->setFilter('doc.docDate', '<=', $filters['docDate']['end']); } if ($filters['idSeries']) { $listObj->setFilter('doc.idCashingSeries', '=', $filters['idSeries']); } if ($filters['docNumber']) { $listObj->setFilter('doc.docNumber', '=', $filters['docNumber']); } if ($filters['idOfficeUser']['id']) { list($idOffice, $idUser)=explode('|', $filters['idOfficeUser']['id']); if ($idUser) { $listObj->setFilter('doc.idUser', '=', $idUser); } elseif ($idOffice) { $listObj->setFilter('doc.idOffice', '=', $idOffice); } } if ($filters['docType']) { $listObj->setFilter('doc.docType', '=', $filters['docType']); } if ($filters['currency']) { $listObj->setFilter('doc.currency', '=', $filters['currency']); } if ($filters['voided'] == 'voided') { $listObj->setFilter('doc.voidTime', '>', 0); } elseif ($filters['voided'] == 'notVoided') { $listObj->setFilter('doc.voidTime', '=', 0); } if ($filters['issued'] == 'issued') { $listObj->setFilter('doc.issueTime', '>', 0); } elseif ($filters['issued'] == 'notIssued') { $listObj->setFilter('doc.issueTime', '=', 0); } if ($filters['blocked'] == 'blocked') { $listObj->setFilter('doc.blockTime', '>', 0); } elseif ($filters['blocked'] == 'notBlocked') { $listObj->setFilter('doc.blockTime', '=', 0); } if ($filters['idBankAccount']) { $listObj->setFilter('doc.idBankAccount', '=', $filters['idBankAccount']); } if ($filters['invDate']['start'] and $filters['invDate']['end']) { $listObj->setFilter('inv.invoiceDate', 'BETWEEN', [$filters['invDate']['start'], $filters['invDate']['end']]); } elseif ($filters['invDate']['start']) { $listObj->setFilter('inv.invoiceDate', '>=', $filters['invDate']['start']); } elseif ($filters['invDate']['end']) { $listObj->setFilter('inv.invoiceDate', '<=', $filters['invDate']['end']); } if ($filters['invNumber']) { $listObj->setFilter('inv.invoiceNumber', '=', $filters['invNumber']); } if ($filters['text']) { $listObj->setCustomFilter("doc.explanations LIKE ? OR doc.comments LIKE ?", ["%{$filters['text']}%", "%{$filters['text']}%"]); } if ($filters['idImpDoc']) { $listObj->setFilter('doc.idImportedDoc', '=', $filters['idImpDoc']); } if ($filters['documentImported']=='yes') { $listObj->setFilter('doc.idImportedDoc', '!=', '0'); } elseif ($filters['documentImported']=='no') { $listObj->setFilter('doc.idImportedDoc', '=', '0'); } if ($filters['docAddDate']['start']) { $start = \Engine\DateTime::createFromIsoDateOrDatetime(sprintf('%s 00:00:00', $filters['docAddDate']['start']))->getTimestamp(); $listObj->setFilter('doc.addTime', '>=', $start); } if ($filters['docAddDate']['end']) { $end = \Engine\DateTime::createFromIsoDateOrDatetime(sprintf('%s 23:59:59',$filters['docAddDate']['end']))->getTimestamp(); $listObj->setFilter('doc.addTime', '<=', $end); } if ($filters['customer']['id']) { $listObj->setFilter('inv.idCustomer', 'IN', \Entity\Customer::select($filters['customer']['id'])->fullDuplicatedCustomersGroup); } if ($filters['corporate']['id']) { $listObj->setFilter('inv.idCorporate', 'IN', \Entity\Corporate::select($filters['corporate']['id'])->fullDuplicatedCorporatesGroup); } $listObj->applyUserRestriction(true); $listObj = $this->entityList_inheritListingParams($listingParams, $listObj); $this->recordsList = $listObj->exportRecords(); $this->totalRecordsCount = $listObj->getRecordsCount(); } } 