<?php
namespace ModulesAbstract\PluginReports\Report\Model\Gatherer; class InvoiceCashing extends GathererAbstract { protected $invoiceCashingsIterator = NULL; public function getRequiredFilters() { return [ 'interval', 'documentIssued', 'corporateAndSegment', 'docTypes', ]; } protected function objectInitialize() { $listObj = new \App\EntityList\InvoiceCashings(); $listObj->setColumns(['doc.id']); $listObj->setFilter('doc.docDate', '>=', $this->filters['interval']['start']); $listObj->setFilter('doc.docDate', '<=', $this->filters['interval']['end']); $listObj->applyUserRestriction(false); if ($this->filters['documentIssued']) { $listObj->setCustomFilter("doc.issueTime > 0 OR doc.blockTime > 0"); } if ($this->filters['corporateAndSegment']['type'] == 'corporate') { if ($this->filters['corporateAndSegment']['entityId']) { $listObj->setFilter('inv.idCorporate', '=', $this->filters['corporateAndSegment']['entityId']); } else { $listObj->setFilter('inv.idCorporate', '!=', 0); } } elseif ($this->filters['corporateAndSegment']['type'] == 'segment') { if ($this->filters['corporateAndSegment']['entityId']) { $corporateObj = new \App\EntityList\Corporates(); $corporateObj->setFilter('idSegment', '=', $this->filters['corporateAndSegment']['entityId']); $corporateArray = $corporateObj->exportRecords(); $idCorporates= []; foreach ($corporateArray as $corporateDetails) { $idCorporates[] = $corporateDetails['id']; } if ($idCorporates) { $listObj->setFilter('inv.idCorporate', 'IN', $idCorporates); } else { $this->invoiceCashingsIterator = new \ADORecordSet_empty(); return; } } else { $listObj->setFilter('inv.idCorporate', '!=', 0); } } if ($this->filters['docTypes']) { $listObj->setFilter('doc.docType', 'IN', $this->filters['docTypes']); } $this->invoiceCashingsIterator = $listObj->getExecution(); } protected function objectDestroy() { if ($this->invoiceCashingsIterator) { $this->invoiceCashingsIterator->Close(); $this->invoiceCashingsIterator = NULL; } } protected function objectNext() { if ($this->invoiceCashingsIterator && !$this->invoiceCashingsIterator->EOF) { $result = $this->invoiceCashingsIterator->FetchRow(); return ['invoiceCashingId' => $result['id']]; } return NULL; } }