data->Filter['mmCode']) || !isset($contract->data->Filter['vehicleYear'])) { return $contract->deviceError( 'Required fields not provided', 'Requires `mmCode` and `vehicleYear`. Optionally accepts `mileage` and `condition`.' ); } $this->em = \Utility\Registry::getEntityManager(); $data = $tu->searchByMmCode( $contract->data->Filter['mmCode'], $this->em->getRepository('\Stock\Entity\Year') ->find($contract->data->Filter['vehicleYear']) ->name, isset($contract->data->Filter['mileage']) ? $contract->data->Filter['mileage'] : null, isset($contract->data->Filter['condition']) ? $this->em->getRepository('\Stock\Entity\Condition') ->find($contract->data->Filter['condition']) ->name : null ); if (is_null($data) || empty($data)) { return $contract->deviceError( 'API call to remote host failed.', 'No data could be retrieved from remote service.' ); } return $contract->deviceSuccess('Data retrieved.', $data); } /** * Contract to acquire TransUnion data. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\Recurring */ public function contractTransUnionFromMmCode($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addRequiredInput(array( 'Filter' => array( 'type' => 'Id', 'vehicleYear' => 'Id' ) )); $requirement->addOptionalInput(array( 'Filter' => array( 'stockId' => 'Id' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * Acquire TransUnion data. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeTransUnionFromMmCode($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $tu = new \Utility\Comms\TransUnion(); if (!isset($contract->data->Filter['type']) || !isset($contract->data->Filter['vehicleYear'])) { return $contract->error( 'Required fields not provided', 'Requires `type` and `vehicleYear`. Optionally accepts `km` and `condition`.' ); } $this->em = \Utility\Registry::getEntityManager(); $data = $tu->searchByMmCode( $this->em->getRepository('\Stock\Entity\Type') ->find($contract->data->Filter['type']) ->mmCode, $this->em->getRepository('\Stock\Entity\Year') ->find($contract->data->Filter['vehicleYear']) ->name, null, null ); if (is_null($data) || empty($data) || false == $data) { return $contract->error( 'API call to remote host failed.', 'No data could be retrieved from remote service.', array() ); } if (isset($contract->data->Filter['stockId']) && is_numeric($contract->data->Filter['stockId']) && 0 < $contract->data->Filter['stockId'] && isset($data['VehicleDetails']) && isset($data['VehicleDetails'][0]) && isset($data['VehicleDetails'][0]['Value'])) { $jobRecord = $this->em->find('Stock\\Entity\\Stock', $contract->data->Filter['stockId']); $jobRecord->oldTradePrice = $jobRecord->tradePrice; $jobRecord->oldRetailPrice = $jobRecord->retailPrice; $jobRecord->oldListPrice = $jobRecord->listPrice; $jobRecord->tradePrice = 0.00 + $data['VehicleDetails'][0]['Value']['TradePrice']; $jobRecord->retailPrice = 0.00 + $data['VehicleDetails'][0]['Value']['RetailPrice']; $jobRecord->listPrice = 0.00 + $data['VehicleDetails'][0]['Value']['NewPrice']; $this->em->flush($jobRecord); } return $contract->success('Data retrieved.', $data); } /** * Contract to acquire TransUnionHPI data. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\Recurring */ public function contractTransUnionForHPI($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addRequiredInput(array( 'Filter' => array( 'username' => 'String255', 'pass' => 'String255', 'stock' => 'Id' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * Acquire TransUnionHPI data. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeTransUnionForHPI($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { ini_set('memory_limit','-1'); $data[] = 'false'; $username = $contract->data->Filter['username']; $password = $contract->data->Filter['pass']; $stockId = $contract->data->Filter['stock']; $jobRecord = $this->em->find('Stock\\Entity\\Stock', $stockId); #-> Chat to TU. $authData = \Utility\Registry::getAuthData(); $client = new \Zend\Soap\Client( // "https://autoinsight.transunion.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl", //LIVE // "http://secureuat.decisionsystems.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl", //QA "https://autotest.transunion.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl", //new LIVE oct 2016 array( 'soap_version' => SOAP_1_1 ) ); $query = array( 'ExtensionData' => null, 'Colour' => !is_null($jobRecord->exteriorColour) ? $jobRecord->exteriorColour->name : '', 'Condition' => !is_null($jobRecord->condition) ? $jobRecord->condition->name : '', 'CustomerProductId' => 0, 'EngineNumber' => !is_null($jobRecord->engineNumber) ? (string) strtoupper($jobRecord->engineNumber) : '', 'GuideMonth' => 1, 'GuideYear' => $jobRecord->vehicleYear->name, 'LoginId' => (string) $username, 'Password' => (string) $password, 'RegistrationNumber' => strtoupper($jobRecord->registrationNumber), 'RegistrationYear' => $jobRecord->type->introYear->name, 'RequestorPerson' => $authData['firstName'] . ' ' . $authData['familyName'], 'RequestorTelNumber' => $authData['mobile'], 'VehicleCode' => (string) $jobRecord->type->mmCode, 'VehicleMileage' => !is_null($jobRecord->km) ? $jobRecord->km : 0, 'VinOrChasisNumber' => !is_null($jobRecord->vinNumber) ? strtoupper($jobRecord->vinNumber) : '' ); if ('' == $query['Colour']) { unset($query['Colour']); } if ('' == $query['Condition']) { unset($query['Condition']); } if ('' == $query['EngineNumber']) { unset($query['EngineNumber']); } if ('' == $query['EngineNumber']) { unset($query['EngineNumber']); } if ('' == $query['RegistrationNumber']) { unset($query['RegistrationNumber']); } if ('' == $query['VinOrChasisNumber']) { unset($query['VinOrChasisNumber']); } try { // \Utility\Debug::errorLog('sending HPI', '---------------------'); $res = $client->call("AISConvergedB2B", array( 'AISConvergedB2B' => array( 'query' => $query ) )); } catch (\Exception $e) { #-> Log entry. ini_set('memory_limit','512M'); \Utility\Debug::errorLog('Exception on HPI request', ''); \Utility\Debug::errorLog('TU HPI request exception', "$e"); $message = 'Could not connect to service.'; $log = new \Stock\Entity\TuhpiLog(); $log->stock = $jobRecord; $log->status = $message; $this->em->persist($log); $this->em->flush($log); throw new \Exception($message); } if (isset($res->AISConvergedB2BResult) && is_object($res->AISConvergedB2BResult) && (!isset($res->AISConvergedB2BResult->ErrorCode) || empty($res->AISConvergedB2BResult->ErrorCode))) { $this->res = $res->AISConvergedB2BResult; } else { ini_set('memory_limit','512M'); \Utility\Debug::errorLog('No result on HPI request', ''); \Utility\Debug::errorLog('query', $query); \Utility\Debug::errorLog('result', $res); $message = isset($res->AISConvergedB2BResult->ErrorMessage) ? $res->AISConvergedB2BResult->ErrorMessage : 'Could not collect HPI report.'; #-> Log entry. $log = new \Stock\Entity\TuhpiLog(); $log->stock = $jobRecord; $log->status = $message; $this->em->persist($log); $this->em->flush($log); throw new \Exception($message); } // \Utility\Debug::errorLog('query', $query); // \Utility\Debug::errorLog('result', $this->res); #-> Save to DB. $data = array( 'stock' => $jobRecord, 'transactionNumber' => isset($this->res->TransactionNumber) ? $this->res->TransactionNumber : '', // Finance Information 'f_financeProvider' => $this->getVal('Finance', 'Finance', 'FinanceProvider'), 'f_financeBranch' => $this->getVal('Finance', 'Finance', 'FinanceBranch'), 'f_agreementOrAccountNumber' => $this->getVal('Finance', 'Finance', 'AgreementOrAccountNumber'), 'f_agreementType' => $this->getVal('Finance', 'Finance', 'AgreementType'), 'f_telephoneNumber' => $this->getVal('Finance', 'Finance', 'TelNumber'), 'f_resultCode' => $this->getVal('Finance', 'Finance', ''), // Finance History 'fh_data' => $this->getItVal('FinanceHistory', 'FinanceHistory', array( 'financeHouse' => 'FinanceHouse', 'agreementOrAccountNumber' => 'AgreementOrAccountNumber', 'agreementType' => 'AgreementType', 'telephoneNumber' => 'TelephoneNumber', 'startDate' => 'StartDate', 'endDate' => 'EndDate', 'resultCode' => 'ResultCode' )), // Accident History 'ah_data' => $this->getItVal('AccidentHistory', 'AccidentHistory', array( 'source' => 'Source', 'assessmentDate' => 'AssessmentDate', 'vehicleDescription' => 'VehicleDescription', 'vinMatch' => 'VinMatch', 'regMatch' => 'RegMatch', 'estimatedRepairCost' => 'EstimatedRepairCost', 'assessmentNumber' => 'AssessmentNumber', 'engineMatch' => 'EngineMatch', 'estimatePercentageOfRetailValue' => 'EstimatePercentageOfRetailValue', 'resultCode' => 'ResultCode' )), // Stolen Information 'si_policeStation' => $this->getVal('StolenInfo', 'Stolen', 'PoliceStation'), 'si_caseNumber' => $this->getVal('StolenInfo', 'Stolen', 'CaseNumber'), 'si_dateStolen' => $this->getVal('StolenInfo', 'Stolen', 'DateStolen'), 'si_vinMatch' => $this->getVal('StolenInfo', 'Stolen', 'VinMatch'), 'si_engineMatch' => $this->getVal('StolenInfo', 'Stolen', 'EngineMatch'), 'si_registrationMatch' => $this->getVal('StolenInfo', 'Stolen', 'RegistrationMatch'), 'si_resultCode' => $this->getVal('StolenInfo', 'Stolen', 'ResultCode'), // Alert Information 'ai_company' => $this->getVal('AlertInfo', 'Alert', 'Company'), 'ai_referenceNumber' => $this->getVal('AlertInfo', 'Alert', 'ReferenceNumber'), 'ai_alertReason' => $this->getVal('AlertInfo', 'Alert', 'AlertReason'), 'ai_telephoneNumber' => $this->getVal('AlertInfo', 'Alert', 'TelephoneNumber'), 'ai_resultCode' => $this->getVal('AlertInfo', 'Alert', 'ResultCode'), // IVID History Information 'ivid_responseCode' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ResponseCode'), 'ivid_responseDescription' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ResponseDescription'), 'ivid_referenceNumber' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ReferenceNumber'), 'ivid_contactNumber' => $this->getVal('IVIDHistory', 'IVIDHistory', 'CcontactNumber'), 'ivid_resultCode' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ResultCode'), // Microdot Information 'mi_company' => $this->getVal('MicrodotInfo', 'Microdot', 'Company'), 'mi_referenceNumber' => $this->getVal('MicrodotInfo', 'Microdot', 'ReferenceNumber'), 'mi_contactNumber' => $this->getVal('MicrodotInfo', 'Microdot', 'ContactNumber'), 'mi_dateApplied' => $this->getVal('MicrodotInfo', 'Microdot', 'DateApplied'), 'mi_resultCode' => $this->getVal('MicrodotInfo', 'Microdot', 'ResultCode'), // VESA Information 'vesa_CertificateNumber' => $this->getVal('VesaInfo', 'Vesa', 'CertificateNumber'), 'vesa_dateFitted' => $this->getVal('VesaInfo', 'Vesa', 'DateFitted'), 'vesa_brandName' => $this->getVal('VesaInfo', 'Vesa', 'BrandName'), 'vesa_brandModel' => $this->getVal('VesaInfo', 'Vesa', 'BrandModel'), 'vesa_deviceDescriptionType' => $this->getVal('VesaInfo', 'Vesa', 'DeviceDescriptionType'), 'vesa_resultCode' => $this->getVal('VesaInfo', 'Vesa', 'ResultCode'), // Registration History 'rh_data' => $this->getItVal('RegistrationHistory', 'RegistrationHistory', array( 'dateRegistered' => 'DateRegistered', 'registrationNumber' => 'RegistrationNumber', 'resultCode' => 'ResultCode' )), // Enquiry History 'eh_data' => $this->getItVal('EnquiryHistory', 'EnquiriesHistory', array( 'source' => 'Source', 'transactionDate' => 'TransactionDate', 'resultCode' => 'ResultCode' )), // Mileage History 'mh_data' => $this->getItVal('MileageHistory', 'MileageHistory', array( 'source' => 'Source', 'vehicleMileage' => 'VehicleMileage', 'dateRegistered' => 'DateRegistered', 'resultCode' => 'ResultCode' )), // VehicleOptionCodes 'vc_month' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'Month', 0), 'vc_year' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'Year', 0), 'vc_newOptionCode' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'NewOptionCode', 0), 'vc_usedOptionCode' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'UsedOptionCode', 0), 'vc_maximumRange' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'MaximumRange', 0), 'vc_minimunRange' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'MinimunRange', 0), 'vc_newPrice' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'NewPrice', 0), 'vc_retailPrice' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'RetailPrice', 0), 'vc_tradePrice' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'TradePrice', 0), 'vc_resultCode' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'ResultCode'), // VehicleConfirmationInfo 'vci_HPINumber' => $this->getRtVal('VehicleConfirmationInfo', 'HPINumber'), 'vci_matchColour' => $this->getRtVal('VehicleConfirmationInfo', 'MatchColour'), 'vci_matchEngineNumber' => $this->getRtVal('VehicleConfirmationInfo', 'MatchEngineNumber'), 'vci_matchManufacturer' => $this->getRtVal('VehicleConfirmationInfo', 'MatchManufacturer'), 'vci_matchModel' => $this->getRtVal('VehicleConfirmationInfo', 'MatchModel'), 'vci_matchString' => $this->getRtVal('VehicleConfirmationInfo', 'MatchString'), 'vci_matchVehicleRegistration' => $this->getRtVal('VehicleConfirmationInfo', 'MatchVehicleRegistration'), 'vci_matchVinorChassis' => $this->getRtVal('VehicleConfirmationInfo', 'MatchVinorChassis'), 'vci_matchYear' => $this->getRtVal('VehicleConfirmationInfo', 'MatchYear'), // VehicleValueInfo 'vvi_guideMonth' => $this->getRtVal('VehicleValueInfo', 'GuideMonth', 0), 'vvi_guideYear' => $this->getRtVal('VehicleValueInfo', 'GuideYear', 0), 'vvi_newListPrice' => $this->getRtVal('VehicleValueInfo', 'NewListPrice', 0), 'vvi_retailPrice' => $this->getRtVal('VehicleValueInfo', 'RetailPrice', 0), 'vvi_tradePrice' => $this->getRtVal('VehicleValueInfo', 'TradePrice', 0), 'vvi_costPrice' => $this->getRtVal('VehicleValueInfo', 'CostPrice', 0), 'vvi_adjustedRetailPrice_mileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedRetailPrice_MileageAndCondition', 0), 'vvi_AdjustedTradePrice_MileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedTradePrice_MileageAndCondition', 0), 'vvi_adjustedRetailPrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedRetailPrice', 0), 'vvi_adjustedTradePrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedTradePrice', 0), 'vvi_estimatedRetailPrice' => $this->getRtVal('VehicleValueInfo', 'EstimatedRetailPrice', 0), 'vvi_estimatedTradePrice' => $this->getRtVal('VehicleValueInfo', 'EstimatedTradePrice', 0), 'vvi_estimatedCostPrice' => $this->getRtVal('VehicleValueInfo', 'EstimatedCostPrice', 0), 'vvi_adjustedEstimatedRetailPrice_mileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedRetailPrice_MileageAndCondition', 0), 'vvi_adjustedEstimatedTradePrice_mileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedTradePrice_MileageAndCondition', 0), 'vvi_adjustedEstimatedcostprice_mileageandcondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedCostPrice_MileageAndCondition', 0), 'vvi_adjustedEstimatedRetailPrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedRetailPrice', 0), 'vvi_adjustedEstimatedTradePrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedTradePrice', 0), 'vvi_adjustedEstimatedCostPrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedCostPrice', 0), 'vvi_resultCode' => $this->getRtVal('VehicleValueInfo', 'ResultCode'), // Error codes 'error_code' => null, 'hpi_type' => 'HPI' ); // \Utility\Debug::errorLog('data', $data); $rep = new \Stock\Entity\Tuhpi(); $rep->fromArray($data); $this->em->persist($rep); $this->em->flush($rep); #-> Log entry. $log = new \Stock\Entity\TuhpiLog(); $log->tuhpi = $rep; $log->stock = $jobRecord; $log->status = 'Success'; $this->em->persist($log); $this->em->flush($log); return $contract->success('Data retrieved.', array('id' => $rep->id)); } /** * Contract to acquire TransUnionHPI data. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\Recurring */ public function contractTransUnionForHPIAccident($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addRequiredInput(array( 'Filter' => array( 'username' => 'String255', 'pass' => 'String255', 'stock' => 'Id' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * Acquire TransUnionHPI data. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeTransUnionForHPIAccident($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { ini_set('memory_limit','-1'); $data[] = 'false'; // \Utility\Debug::errorLog('$contract->data', $contract->data); $username = $contract->data->Filter['username']; $password = $contract->data->Filter['pass']; $stockId = $contract->data->Filter['stock']; $jobRecord = $this->em->find('Stock\\Entity\\Stock', $stockId); #-> Chat to TU. $authData = \Utility\Registry::getAuthData(); $client = new \Zend\Soap\Client( // "https://autoinsight.transunion.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl", //LIVE // "http://secureuat.decisionsystems.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl", //QA "https://autotest.transunion.co.za/AISConvergedB2BWrapper/AISConvergedB2BWrapper.asmx?wsdl", //new LIVE oct 2016 array( 'soap_version' => SOAP_1_1 ) ); $query = array( 'ExtensionData' => null, 'Colour' => !is_null($jobRecord->exteriorColour) ? $jobRecord->exteriorColour->name : '', 'Condition' => !is_null($jobRecord->condition) ? $jobRecord->condition->name : '', 'CustomerProductId' => 0, 'EngineNumber' => !is_null($jobRecord->engineNumber) ? (string) strtoupper($jobRecord->engineNumber) : '', 'GuideMonth' => 1, 'GuideYear' => $jobRecord->vehicleYear->name, // 'LoginId' => (string) $username, // 'Password' => (string) $password, 'LoginId' => (string) "187681", 'Password' => (string) "Bid187681#", 'RegistrationNumber' => strtoupper($jobRecord->registrationNumber), 'RegistrationYear' => $jobRecord->type->introYear->name, 'RequestorPerson' => $authData['firstName'] . ' ' . $authData['familyName'], 'RequestorTelNumber' => $authData['mobile'], 'VehicleCode' => (string) $jobRecord->type->mmCode, 'VehicleMileage' => !is_null($jobRecord->km) ? $jobRecord->km : 0, 'VinOrChasisNumber' => !is_null($jobRecord->vinNumber) ? strtoupper($jobRecord->vinNumber) : '' ); if ('' == $query['Colour']) { unset($query['Colour']); } if ('' == $query['Condition']) { unset($query['Condition']); } if ('' == $query['EngineNumber']) { unset($query['EngineNumber']); } if ('' == $query['EngineNumber']) { unset($query['EngineNumber']); } if ('' == $query['RegistrationNumber']) { unset($query['RegistrationNumber']); } if ('' == $query['VinOrChasisNumber']) { unset($query['VinOrChasisNumber']); } try { // \Utility\Debug::errorLog('sending HPI', '---------------------'); $res = $client->call("AISConvergedB2B", array( 'AISConvergedB2B' => array( 'query' => $query ) )); } catch (\Exception $e) { #-> Log entry. ini_set('memory_limit','512M'); \Utility\Debug::errorLog('Exception on HPI request', ''); \Utility\Debug::errorLog('TU HPI request exception', "$e"); $message = 'Could not connect to service.'; $log = new \Stock\Entity\TuhpiLog(); $log->stock = $jobRecord; $log->status = $message; $this->em->persist($log); $this->em->flush($log); throw new \Exception($message); } if (isset($res->AISConvergedB2BResult) && is_object($res->AISConvergedB2BResult) && (!isset($res->AISConvergedB2BResult->ErrorCode) || empty($res->AISConvergedB2BResult->ErrorCode))) { $this->res = $res->AISConvergedB2BResult; } else { ini_set('memory_limit','512M'); \Utility\Debug::errorLog('No result on HPI request', ''); \Utility\Debug::errorLog('query Accident', $query); \Utility\Debug::errorLog('result Accident', $res); $message = isset($res->AISConvergedB2BResult->ErrorMessage) ? $res->AISConvergedB2BResult->ErrorMessage : 'Could not collect HPI report.'; #-> Log entry. $log = new \Stock\Entity\TuhpiLog(); $log->stock = $jobRecord; $log->status = $message; $this->em->persist($log); $this->em->flush($log); throw new \Exception($message); } // \Utility\Debug::errorLog('query Accident', $query); // \Utility\Debug::errorLog('result Accident', $this->res); $datatest = array(// Accident History 'ah_data' => $this->getItVal('AccidentHistory', 'AccidentHistory', array( 'source' => 'Source', 'assessmentDate' => 'AssessmentDate', 'vehicleDescription' => 'VehicleDescription', 'vinMatch' => 'VinMatch', 'regMatch' => 'RegMatch', 'estimatedRepairCost' => 'EstimatedRepairCost', 'assessmentNumber' => 'AssessmentNumber', 'engineMatch' => 'EngineMatch', 'estimatePercentageOfRetailValue' => 'EstimatePercentageOfRetailValue', 'resultCode' => 'ResultCode' ))); // \Utility\Debug::errorLog('$datatest', $datatest); #-> Save to DB. $data = array( 'stock' => $jobRecord, 'transactionNumber' => isset($this->res->TransactionNumber) ? $this->res->TransactionNumber : '', // Finance Information 'f_financeProvider' => $this->getVal('Finance', 'Finance', 'FinanceProvider'), 'f_financeBranch' => $this->getVal('Finance', 'Finance', 'FinanceBranch'), 'f_agreementOrAccountNumber' => $this->getVal('Finance', 'Finance', 'AgreementOrAccountNumber'), 'f_agreementType' => $this->getVal('Finance', 'Finance', 'AgreementType'), 'f_telephoneNumber' => $this->getVal('Finance', 'Finance', 'TelNumber'), 'f_resultCode' => $this->getVal('Finance', 'Finance', ''), // Finance History 'fh_data' => $this->getItVal('FinanceHistory', 'FinanceHistory', array( 'financeHouse' => 'FinanceHouse', 'agreementOrAccountNumber' => 'AgreementOrAccountNumber', 'agreementType' => 'AgreementType', 'telephoneNumber' => 'TelephoneNumber', 'startDate' => 'StartDate', 'endDate' => 'EndDate', 'resultCode' => 'ResultCode' )), // Accident History 'ah_data' => $this->getItVal('AccidentHistory', 'AccidentHistory', array( 'source' => 'Source', 'assessmentDate' => 'AssessmentDate', 'vehicleDescription' => 'VehicleDescription', 'vinMatch' => 'VinMatch', 'regMatch' => 'RegMatch', 'estimatedRepairCost' => 'EstimatedRepairCost', 'assessmentNumber' => 'AssessmentNumber', 'engineMatch' => 'EngineMatch', 'estimatePercentageOfRetailValue' => 'EstimatePercentageOfRetailValue', 'resultCode' => 'ResultCode' )), // Stolen Information 'si_policeStation' => $this->getVal('StolenInfo', 'Stolen', 'PoliceStation'), 'si_caseNumber' => $this->getVal('StolenInfo', 'Stolen', 'CaseNumber'), 'si_dateStolen' => $this->getVal('StolenInfo', 'Stolen', 'DateStolen'), 'si_vinMatch' => $this->getVal('StolenInfo', 'Stolen', 'VinMatch'), 'si_engineMatch' => $this->getVal('StolenInfo', 'Stolen', 'EngineMatch'), 'si_registrationMatch' => $this->getVal('StolenInfo', 'Stolen', 'RegistrationMatch'), 'si_resultCode' => $this->getVal('StolenInfo', 'Stolen', 'ResultCode'), // Alert Information 'ai_company' => $this->getVal('AlertInfo', 'Alert', 'Company'), 'ai_referenceNumber' => $this->getVal('AlertInfo', 'Alert', 'ReferenceNumber'), 'ai_alertReason' => $this->getVal('AlertInfo', 'Alert', 'AlertReason'), 'ai_telephoneNumber' => $this->getVal('AlertInfo', 'Alert', 'TelephoneNumber'), 'ai_resultCode' => $this->getVal('AlertInfo', 'Alert', 'ResultCode'), // IVID History Information 'ivid_responseCode' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ResponseCode'), 'ivid_responseDescription' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ResponseDescription'), 'ivid_referenceNumber' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ReferenceNumber'), 'ivid_contactNumber' => $this->getVal('IVIDHistory', 'IVIDHistory', 'CcontactNumber'), 'ivid_resultCode' => $this->getVal('IVIDHistory', 'IVIDHistory', 'ResultCode'), // Microdot Information 'mi_company' => $this->getVal('MicrodotInfo', 'Microdot', 'Company'), 'mi_referenceNumber' => $this->getVal('MicrodotInfo', 'Microdot', 'ReferenceNumber'), 'mi_contactNumber' => $this->getVal('MicrodotInfo', 'Microdot', 'ContactNumber'), 'mi_dateApplied' => $this->getVal('MicrodotInfo', 'Microdot', 'DateApplied'), 'mi_resultCode' => $this->getVal('MicrodotInfo', 'Microdot', 'ResultCode'), // VESA Information 'vesa_CertificateNumber' => $this->getVal('VesaInfo', 'Vesa', 'CertificateNumber'), 'vesa_dateFitted' => $this->getVal('VesaInfo', 'Vesa', 'DateFitted'), 'vesa_brandName' => $this->getVal('VesaInfo', 'Vesa', 'BrandName'), 'vesa_brandModel' => $this->getVal('VesaInfo', 'Vesa', 'BrandModel'), 'vesa_deviceDescriptionType' => $this->getVal('VesaInfo', 'Vesa', 'DeviceDescriptionType'), 'vesa_resultCode' => $this->getVal('VesaInfo', 'Vesa', 'ResultCode'), // Registration History 'rh_data' => $this->getItVal('RegistrationHistory', 'RegistrationHistory', array( 'dateRegistered' => 'DateRegistered', 'registrationNumber' => 'RegistrationNumber', 'resultCode' => 'ResultCode' )), // Enquiry History 'eh_data' => $this->getItVal('EnquiryHistory', 'EnquiriesHistory', array( 'source' => 'Source', 'transactionDate' => 'TransactionDate', 'resultCode' => 'ResultCode' )), // Mileage History 'mh_data' => $this->getItVal('MileageHistory', 'MileageHistory', array( 'source' => 'Source', 'vehicleMileage' => 'VehicleMileage', 'dateRegistered' => 'DateRegistered', 'resultCode' => 'ResultCode' )), // VehicleOptionCodes 'vc_month' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'Month', 0), 'vc_year' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'Year', 0), 'vc_newOptionCode' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'NewOptionCode', 0), 'vc_usedOptionCode' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'UsedOptionCode', 0), 'vc_maximumRange' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'MaximumRange', 0), 'vc_minimunRange' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'MinimunRange', 0), 'vc_newPrice' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'NewPrice', 0), 'vc_retailPrice' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'RetailPrice', 0), 'vc_tradePrice' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'TradePrice', 0), 'vc_resultCode' => $this->getVal('VehicleOptionCodesPrice', 'VehicleOptionCode', 'ResultCode'), // VehicleConfirmationInfo 'vci_HPINumber' => $this->getRtVal('VehicleConfirmationInfo', 'HPINumber'), 'vci_matchColour' => $this->getRtVal('VehicleConfirmationInfo', 'MatchColour'), 'vci_matchEngineNumber' => $this->getRtVal('VehicleConfirmationInfo', 'MatchEngineNumber'), 'vci_matchManufacturer' => $this->getRtVal('VehicleConfirmationInfo', 'MatchManufacturer'), 'vci_matchModel' => $this->getRtVal('VehicleConfirmationInfo', 'MatchModel'), 'vci_matchString' => $this->getRtVal('VehicleConfirmationInfo', 'MatchString'), 'vci_matchVehicleRegistration' => $this->getRtVal('VehicleConfirmationInfo', 'MatchVehicleRegistration'), 'vci_matchVinorChassis' => $this->getRtVal('VehicleConfirmationInfo', 'MatchVinorChassis'), 'vci_matchYear' => $this->getRtVal('VehicleConfirmationInfo', 'MatchYear'), // VehicleValueInfo 'vvi_guideMonth' => $this->getRtVal('VehicleValueInfo', 'GuideMonth', 0), 'vvi_guideYear' => $this->getRtVal('VehicleValueInfo', 'GuideYear', 0), 'vvi_newListPrice' => $this->getRtVal('VehicleValueInfo', 'NewListPrice', 0), 'vvi_retailPrice' => $this->getRtVal('VehicleValueInfo', 'RetailPrice', 0), 'vvi_tradePrice' => $this->getRtVal('VehicleValueInfo', 'TradePrice', 0), 'vvi_costPrice' => $this->getRtVal('VehicleValueInfo', 'CostPrice', 0), 'vvi_adjustedRetailPrice_mileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedRetailPrice_MileageAndCondition', 0), 'vvi_AdjustedTradePrice_MileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedTradePrice_MileageAndCondition', 0), 'vvi_adjustedRetailPrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedRetailPrice', 0), 'vvi_adjustedTradePrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedTradePrice', 0), 'vvi_estimatedRetailPrice' => $this->getRtVal('VehicleValueInfo', 'EstimatedRetailPrice', 0), 'vvi_estimatedTradePrice' => $this->getRtVal('VehicleValueInfo', 'EstimatedTradePrice', 0), 'vvi_estimatedCostPrice' => $this->getRtVal('VehicleValueInfo', 'EstimatedCostPrice', 0), 'vvi_adjustedEstimatedRetailPrice_mileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedRetailPrice_MileageAndCondition', 0), 'vvi_adjustedEstimatedTradePrice_mileageAndCondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedTradePrice_MileageAndCondition', 0), 'vvi_adjustedEstimatedcostprice_mileageandcondition' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedCostPrice_MileageAndCondition', 0), 'vvi_adjustedEstimatedRetailPrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedRetailPrice', 0), 'vvi_adjustedEstimatedTradePrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedTradePrice', 0), 'vvi_adjustedEstimatedCostPrice' => $this->getRtVal('VehicleValueInfo', 'AdjustedEstimatedCostPrice', 0), 'vvi_resultCode' => $this->getRtVal('VehicleValueInfo', 'ResultCode'), // Error codes 'error_code' => null, 'hpi_type' => 'ACC' ); // \Utility\Debug::errorLog('data', $data); $rep = new \Stock\Entity\Tuhpi(); $rep->fromArray($data); $this->em->persist($rep); $this->em->flush($rep); #-> Log entry. $log = new \Stock\Entity\TuhpiLog(); $log->tuhpi = $rep; $log->stock = $jobRecord; $log->status = 'Success'; $this->em->persist($log); $this->em->flush($log); return $contract->success('Data retrieved.', array('id' => $rep->id)); } private $res = null; private function getRtVal($root, $param, $default = '') { return isset($this->res->$root->$param) ? $this->res->$root->$param : $default; } private function getVal($root, $parent, $param, $default = '') { return isset($this->res->$root->$parent->$param) ? $this->res->$root->$parent->$param : $default; } private function getItVal($root, $parent, $map) { if (isset($this->res->$root->$parent) // && is_array($this->res->$root->$parent) && !empty($this->res->$root->$parent)) { $data = array(); if(is_array($this->res->$root->$parent)) { // \Utility\Debug::errorLog('--------------------------- is_array', '---------------------------'); foreach ($this->res->$root->$parent as $item) { $entry = array(); foreach ($map as $field => $param) { $entry[$field] = isset($item->$param) ? $item->$param : null; } $data[] = $entry; } } else { // \Utility\Debug::errorLog('--------------------------- not array', '---------------------------'); foreach ($this->res->$root as $item) { // \Utility\Debug::errorLog('$item', $item); // if(!property_exists($item,'ValidationMessages')) { $entry = array(); foreach ($item as $field => $param) { // \Utility\Debug::errorLog('$field', $field); // \Utility\Debug::errorLog('$param', $param); $entry[lcfirst($field)] = isset($param) ? $param : null; } $data[] = $entry; } } } // \Utility\Debug::errorLog('$data', $data); return $data; } else { return array(); } } /** * Contract to list vehicle makes according to Category and Year. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\Recurring */ public function contractListMakes($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addRequiredInput(array( 'Filter' => array( 'category' => 'Id', 'year' => 'Id' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * List vehicle makes according to Category and Year. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeListMakes($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $dql = 'SELECT DISTINCT mk.id as value, mk.name as label ' . 'FROM \Stock\Entity\Type tp ' . 'JOIN tp.model md ' . 'JOIN md.make mk ' . 'WHERE IDENTITY(tp.category) = :category' . ' AND IDENTITY(tp.introYear) <= :year' . ' AND (' . ' IDENTITY(tp.discYear) >= :year' . ' OR tp.discYear IS NULL' . ' )'; $data = $this->em->createQuery($dql) ->setParameter('category', $contract->data->Filter['category']) ->setParameter('year', $contract->data->Filter['year']) ->getArrayResult(); return $contract->success('Data Collected.', $data); } /** * Contract to list vehicle models according to Category and Year. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractListModels($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addRequiredInput(array( 'Filter' => array( 'category' => 'Id', 'year' => 'Id', 'make' => 'Id' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * List vehicle models according to Category and Year. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeListModels($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $dql = 'SELECT DISTINCT md.id as value, md.name as label ' . 'FROM \Stock\Entity\Type tp ' . 'JOIN tp.model md ' . 'WHERE IDENTITY(md.make) = :make' . ' AND IDENTITY(tp.category) = :category' . ' AND IDENTITY(tp.introYear) <= :year' . ' AND (' . ' IDENTITY(tp.discYear) >= :year' . ' OR tp.discYear IS NULL' . ' )'; $data = $this->em->createQuery($dql) ->setParameter('make', $contract->data->Filter['make']) ->setParameter('category', $contract->data->Filter['category']) ->setParameter('year', $contract->data->Filter['year']) ->getArrayResult(); return $contract->success('Data Collected.', $data); } /** * Contract to list vehicle types according to Category and Year. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractListTypes($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addRequiredInput(array( 'Filter' => array( 'category' => 'Id', 'year' => 'Id', 'model' => 'Id' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * List vehicle types according to Category and Year. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeListTypes($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { /* SELECT tp.id AS value, TRIM(LEADING '0' FROM tp.mm_code) AS mmCode, tp.name AS label, iy.name AS typeIntroYear, dy.name AS typeDiscYear FROM vehicle_type tp LEFT JOIN vehicle_year iy ON tp.intro_vehicle_year_id = iy.id LEFT JOIN vehicle_year dy ON tp.disc_vehicle_year_id = dy.id WHERE tp.vehicle_model_id = 111 AND tp.vehicle_category_id = 2 AND iy.name < 2015 AND (dy.name >= 2015 OR dy.name IS NULL) GROUP BY 2 , 3 , 4 ORDER BY mmCode , tp.id; */ /*$dql = 'SELECT DISTINCT tp.id as value, tp.name as label, iy.name as typeIntroYear, dy.name as typeDiscYear ' . 'FROM \Stock\Entity\Type tp ' . 'LEFT JOIN tp.introYear iy ' . 'LEFT JOIN tp.discYear dy ' . 'WHERE IDENTITY(tp.model) = :model' . ' AND IDENTITY(tp.category) = :category' . ' AND iy.id <= :year' . ' AND (' . ' dy.id >= :year' . ' OR tp.discYear IS NULL' . ' )';*/ $dql = 'SELECT max(tp.id) as value, tp.name as label, iy.name as typeIntroYear, dy.name as typeDiscYear, tp.mmCode as mmCode ' . 'FROM \Stock\Entity\Type tp ' . 'LEFT JOIN tp.introYear iy ' . 'LEFT JOIN tp.discYear dy ' . 'WHERE IDENTITY(tp.model) = :model' . ' AND IDENTITY(tp.category) = :category' . ' AND iy.id <= :year' . ' AND (' . ' dy.id >= :year' . ' OR tp.discYear IS NULL' . ' )' . ' GROUP BY tp.mmCode, tp.name, iy.name, dy.name' . ' ORDER BY tp.name'; $dataGet = $this->em->createQuery($dql) ->setParameter('model', $contract->data->Filter['model']) ->setParameter('category', $contract->data->Filter['category']) ->setParameter('year', $contract->data->Filter['year']) ->getArrayResult(); //Debug::errorLog("dataGet", $dataGet); $data = array(); foreach($dataGet as $dataProcess) { $typeDiscYear = ''; if('' != $dataProcess['typeDiscYear']) { $typeDiscYear = $dataProcess['typeDiscYear']; } array_push($data,array( 'value' => $dataProcess['value'], 'label' => $dataProcess['label'] . ' (' . $dataProcess['typeIntroYear'] . ' - ' . $typeDiscYear . ')' )); } return $contract->success('Data Collected.', $data); // $dql = 'SELECT DISTINCT tp.id as value, tp.name as label ' // . 'FROM \Stock\Entity\Type tp ' // . 'WHERE IDENTITY(tp.model) = :model' // . ' AND IDENTITY(tp.category) = :category' // . ' AND IDENTITY(tp.introYear) <= :year' // . ' AND (' // . ' IDENTITY(tp.discYear) >= :year' // . ' OR tp.discYear IS NULL' // . ' )'; // $data = $this->em->createQuery($dql) // ->setParameter('model', $contract->data->Filter['model']) // ->setParameter('category', $contract->data->Filter['category']) // ->setParameter('year', $contract->data->Filter['year']) // ->getArrayResult(); // return $contract->success('Data Collected.', $data); } }