<?php
namespace App\Worldspan\StructureParser\Structures\Spoil;

class Documents extends \App\Worldspan\StructureParser\Structures\Base\Documents
{
	protected function _getData()
	{
		list($parsedStructure, $transactionType, $transactionIndexes, ) = $this->getTransactionDetails();

		$item = new \App\Worldspan\StructureParser\Types\Document();

		$item->RECLOC = $parsedStructure['R1']['PNRFileAddress'];
		$item->docNumber = $parsedStructure['-C']['DocumentNumber'];
		$item->docDate = ($parsedStructure['R1']['DateOfLastChangeToTheItinerary']?:$parsedStructure['R3']['BookingDateAndYear']);
		$item->issueDate = $parsedStructure['R3']['TransmittingDateAndYear'];

		$transactions = \App\Worldspan\Storage\StorageHandler::getInstance()->selectServiceArrFromDB([
			'docNumber'=>$item->docNumber,
			'docDate>'=> \Engine\DateTime::createFromIsoDatetime($parsedStructure['RecordTrailer']['fileIssueDate_'])->modify("-180days")->formatDateIso(),
		]);
		if ($transactions) {
			$oldService = \Entity\SabreService::select($transactions[0]['id']);

			$item->RECLOC = $oldService->RECLOC;
			$item->docDate = \Engine\DateTime::createFromIsoDatetime($parsedStructure['RecordTrailer']['fileIssueDate_'])->formatDateIso();
		}

		$item = $this->populate($item, $parsedStructure, $transactionType, $transactionIndexes);

		return $item;
	}
}
