<?php
namespace App\ImportedDocument\EntityMatch; class ClientInvoice extends \App\EntityMatch\BaseAbstract { protected $exportFields = ['invoiceNumber', 'invoiceDate', 'currency', 'temporary', 'cashedStatus', 'voidTime', 'issueTime', 'printTotal', 'idCorporate', 'idCustomer']; protected $entityClassName = '\Entity\Invoice'; protected function setTableName() { global $DBTReservationServiceInvoices; $this->tableName = $DBTReservationServiceInvoices; } public function setTinaId($value) { $this->setSearchCriterion('id', $value, false); } public function setInvoiceNumberDate($invoiceNumber, $invoiceDate) { $this->setSearchCriterion('invoiceNumberAndDate', $invoiceNumber, false, ['invoiceDate'=>$invoiceDate]); } protected function dispatchSearchRecords($field, $value, $useWildcard, Array $options = []) { if ($field=='invoiceNumberAndDate') { return $this->searchRecords_invoiceNumberAndDate($value, $options['invoiceDate']); } else { return parent::dispatchSearchRecords($field, $value, $useWildcard, $options); } } protected function searchRecords_invoiceNumberAndDate($invoiceNumber, $invoiceDate) { if (!is_numeric($invoiceNumber) or $invoiceNumber<=0) { return []; } if ($this->useCacheinSqls) { $cacheKey = 'EntityMatch-ClientInvoice-invoiceNumberAndDate-'.$invoiceDate.'/'.$invoiceNumber; $cachedMatches = \Engine\Cache\General::getInstance(self::CACHE_TYPE)->get($cacheKey); if ($cachedMatches!==null) { return $cachedMatches; } } $return = []; $entityList = new \App\EntityList\Invoices(); $entityList->applyUserRestriction(false); $entityList->setColumns($this->exportFields); $entityList->setFilter('invoiceNumber', '=', $invoiceNumber); $entityList->setFilter('invoiceDate', 'LIKE', $invoiceDate); $entityList->setLimit($this->limitResultsPerCriterion); $records = $entityList->exportRecords(); foreach ($records as $row) { $return[$row[$this->tablePrimaryKey]] = $row; } if ($this->useCacheinSqls) { \Engine\Cache\General::getInstance(self::CACHE_TYPE)->set($cacheKey, $return, $this->cacheTtl); } return $return; } }