<?php
 namespace Modules\Admin\ImportEntities\Model\Import; class ImportedServicesRefund extends \Modules\Admin\ImportEntities\Model\ImportAbstract { protected $fields = [ 'serviceId', 'refundDate', 'issueUser', 'issueOffice', 'formOfPayment', 'currency', 'fareUsedSupplierValue', 'fareUsedCommissionValue', 'fareUsedTaxValue', 'fareUsedTaxDetails', 'penaltyValue', 'serviceFeeValue', 'returnOriginalServiceFee', ]; protected $useDateFormat = true; public function process() { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $messagesFromImport = new \App\MessagesCollector(); foreach ($this->fileData as $row) { try { \DB::startTransaction(); $importedOrderObj = new \App\ImportedOrder\Order(); $this->populateImportedOrder($row, $importedOrderObj); $importedOrderEnt = \Entity\ImportedOrder::insert(); $importedOrderEnt->order = $importedOrderObj; $importedOrderEnt->applyMode = 'merge'; $importedOrderEnt->save(); \DB::commitTransaction(); $messagesFromImport->addSuccess( sprintf( $_LANG['Admin']['ImportEntities']['index']['msgs']['impServicesRefunds']['saveOk'], $row['serviceId'], $importedOrderEnt->getId() ) ); } catch (\App\Entity\Exception $e) { $messagesFromImport->addWarning(sprintf($_LANG['Admin']['ImportEntities']['index']['msgs']['impServicesRefunds']['saveError'], $row['serviceId'])); $messagesFromImport->appendMessages($e->getMessagesCollector()); \DB::rollbackTransaction(); } } return $messagesFromImport; } protected function populateImportedOrder(array $row, \App\ImportedOrder\Order $importedOrderObj) { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $importedOrderObj->externalSystemCode = $CFG['Admin']['ImportEntities']['ImportedServicesInsert']['system']['default']; $importedServiceObj = new \App\ImportedOrder\Service(); $importedServiceObj->idSystem = $row['serviceId']; $importedServiceObj->operation = 'refund'; $importedServiceObj->forceOperation = false; $refundDetailsObj = new \App\ImportedOrder\RefundDetails(); $refundDetailsObj->date = \Engine\DateTime::createFromFormat($this->dateFormat, $row['refundDate'])->formatDateIso(); if ($row['issueUser']) { $issueUserObj = new \App\ImportedOrder\User(); $issueUserObj->idSystem = $row['issueUser']; $refundDetailsObj->issueUser = $issueUserObj; } if ($row['issueOffice']) { $issueOfficeObj = new \App\ImportedOrder\Office(); $issueOfficeObj->idSystem = $row['issueOffice']; $refundDetailsObj->issueOffice = $issueOfficeObj; } if (strlen($row['formOfPayment'])) { $refundDetailsObj->formOfPayment = $row['formOfPayment']; } if ($row['currency']) { $refundDetailsObj->currency = $row['currency']; } if (strlen($row['fareUsedSupplierValue'])) { $refundDetailsObj->fareUsedSupplierValue = $row['fareUsedSupplierValue']; } if (strlen($row['fareUsedCommissionValue'])) { $refundDetailsObj->fareUsedCommissionValue = $row['fareUsedCommissionValue']; } if (strlen($row['fareUsedTaxValue'])) { $refundDetailsObj->fareUsedTaxValue = $row['fareUsedTaxValue']; } if (strlen($row['penaltyValue'])) { $refundDetailsObj->penaltyValue = $row['penaltyValue']; } if (strlen($row['serviceFeeValue'])) { $refundDetailsObj->serviceFeeValue = $row['serviceFeeValue']; } if (strlen($row['returnOriginalServiceFee'])) { $refundDetailsObj->returnOriginalServiceFee = (bool)$row['returnOriginalServiceFee']; } if ($row['fareUsedTaxDetails']) { foreach ( explodeClean('/', $row['fareUsedTaxDetails']) as $thisTax) { $thisTaxClean = trim($thisTax); $taxCode = substr($thisTaxClean, 0, 2); $taxValue = substr($thisTaxClean, 2); $refundDetailsObj->addFareUsedTaxCode($taxCode, $taxValue, $row['currency']); } } $importedServiceObj->refundDetails = $refundDetailsObj; $importedOrderObj->addService($importedServiceObj); } } 