<?php
 namespace Modules\Orders\Amadeus\ServicesList; 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\AmadeusServices(); $listObj->setColumns(['serviceCode', 'transactionStatus', 'transactionCode', 'docNumber', 'docDate', 'passengerFirstName', 'passengerLastName', 'idTINABookUser', 'idTINAIssueUser', 'serv.addTime',]); $listObj->setFilter("serv.transactionStatus", 'IN', ['new', 'reissue', 'reissued', 'refund', 'refunded', 'void', 'voided']); $listObj->setFilter("serv.autoIgnored", '!=', 'conjunction'); if($filters['general']){ $listObj->setCustomFilter("serv.id=? OR serv.idAmadeusBookUser=? OR serv.idAmadeusIssueUser=? OR serv.idAmadeusBookOffice=? OR serv.idAmadeusIssueOffice=?", [ $filters['general'], $filters['general'], $filters['general'], $filters['general'], $filters['general'], ]); } if ($filters['transactionCode']) { $listObj->setFilter("serv.transactionCode", 'LIKE', $filters['transactionCode']."%"); } if ($filters['docNumber']) { $listObj->setFilter("serv.docNumber", '=', $filters['docNumber']); } if ($filters['docDate']['start']) { $listObj->setFilter("serv.docDate", ">=", $filters['docDate']['start']); } if ($filters['docDate']['end']) { $listObj->setFilter("serv.docDate", "<=", $filters['docDate']['end']); } if ($filters['serviceCode']) { $listObj->setFilter("serv.serviceCode", "=", $filters['serviceCode']); } if ($filters['transactionStatus']) { $listObj->setFilter("serv.transactionStatus", "=", $filters['transactionStatus']); } if ($filters['passenger']) { $names = explodeClean(" ", $filters['passenger']); if(count($names)>1){ $listObj->setCustomFilter("serv.passengerFirstName RLIKE '".implode("|", $names)."' AND serv.passengerLastName RLIKE '".implode("|", $names)."'"); }else{ $listObj->setCustomFilter("serv.passengerFirstName RLIKE '".implode("|", $names)."' OR serv.passengerLastName RLIKE '".implode("|", $names)."'"); } } if ($filters['isAIR']) { if($filters['isAIR']=="AIR") { $listObj->setFilter("file.isAIR", "=", 1); } else if($filters['isAIR']=="IMR") { $listObj->setFilter("file.isAIR", "=", 0); } } if ($filters['idUser']['id']) { switch ($filters['idUser_source']) { case '': $listObj->setCustomFilter("serv.idTINABookUser=? OR serv.idTINAIssueUser=?", [$filters['idUser']['id'], $filters['idUser']['id']]); break; case 'amadeus.idTINABookUser': $listObj->setFilter("serv.idTINABookUser", '=', $filters['idUser']['id']); break; case 'amadeus.idTINAIssueUser': $listObj->setFilter("serv.idTINAIssueUser", '=', $filters['idUser']['id']); break; default: throw new \Exception("Invalid idUser_source"); } } $listObj->setOrderBy('serv.id', 'desc'); $listObj->setLimit($listingParams->getResultsPerPage()*$listingParams->getCurrentPage(), $listingParams->getResultsPerPage()); $recordsList = new \App\EntityList\RecordIterator($listObj->getExecution(), "\Entity\AmadeusService"); $this->recordsList = []; foreach ($recordsList as $entity) { if ($entity['entity']->transactionReferences) { foreach ($entity['entity']->transactionReferences as $ref) { if (in_array($ref['relationType'], ['reissueOf', 'refund'])) { $entity['transactionReferences'][] = [ 'id' => $ref['id'], 'relationType' => $ref['relationType'], 'entity' => \Entity\AmadeusService::select($ref['id']), ]; } } } $this->recordsList[] = $entity; } $this->totalRecordsCount = $listObj->getRecordsCount(); } } 