<?php

namespace Modules\RemoteData\InfoBox;

class View_ImportedOrder extends \App\Mvc\View_RemoteDataInfoBoxEntityAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_RemoteDataInfoBoxEntityAbstract::getEntityRemoteDetails()
	 */
	protected function getEntityRemoteDetails(\App\Entity\SelectAbstract $entity)
	{
		// shorthand notation
		$lang = $this->lang['importedOrder']['fields'];

		// add the header
		$output = \Engine\RemoteData\InfoBox\Container_Main::create( sprintf($lang['title'], $entity->getId()))
			->setShortTitle( $entity->getId())
			->setId(sprintf("%s.%s", __CLASS__, $entity->getId()));

		// OPTIONS ////////////////////////////////////////////////////////////////////////////////
		// filter this imported order
		if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToSection('Modules/Orders/ImportedOrders/ServicesList')) {
			$icon = \Engine\RemoteData\InfoBox\Icon\Icon::create('filter');
			$icon->setJsCallback("window.open(MVC.appUrl('Orders/ImportedOrders/ServicesList', null, {'filters[idFieldType]': 'importedOrderTinaId', 'filters[idField]': {$entity->getId()}, 'listing[reset]': '1' , 'listing[paramsSlot]':'1'} ), '_blank');");
			$icon->setTooltip($this->lang['importedOrder']['options']['filter']);
			$output->addIcon($icon);
		}
		// filter imported documents associated to this imported order
		if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToSection('Modules/Documents/ImportedDocuments')) {
			$icon = \Engine\RemoteData\InfoBox\Icon\Icon::create('cashing');
			$icon->setJsCallback("window.open(MVC.appUrl('Documents/ImportedDocuments', null, {'filters[docRefType]': 'importedOrder', 'filters[docRefId]':'{$entity->getId()}', 'listing[reset]': '1' , 'listing[paramsSlot]':'1'} ), '_blank');");
			$icon->setTooltip($this->lang['importedOrder']['options']['impDocFilter']);
			$output->addIcon($icon);
		}


		// ADD GENERAL DETAILS ////////////////////////////////////////////////////////////////////
		$c0 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['general']['titles']['general']);
		$output->addContainer($c0);
		$c0->addField( \Engine\RemoteData\InfoBox\Field_String::create( 		$lang['idTina'],		$entity->getId() ) );
		$c0->addField( \Engine\RemoteData\InfoBox\Field_String::create(			$lang['idInSystem'],	$entity->idOrderExtSys ) );
		$c0->addField( \Engine\RemoteData\InfoBox\Field_EntityInfoBox::create(	$lang['system'],		$entity->system->name )->setEntity('extResSystem', $entity->idSystem) );
		$c0->addField( \Engine\RemoteData\InfoBox\Field_Date::create(			$lang['orderDate'], 	\Engine\DateTime::createFromIsoDate($entity->date) ) );
		$c0->addField( \Engine\RemoteData\InfoBox\Field_String::create(			$lang['ownerPsg'],		$entity->ownerPassengerFirstName.' '.$entity->ownerPassengerLastName ) );
		$c0->addField( \Engine\RemoteData\InfoBox\Field_String::create(			$lang['ownerCorp'],		$entity->ownerCorporate ) );
		$c0->addField( \Engine\RemoteData\InfoBox\Field_EntityInfoBox::create(	$lang['micePrj'],		$entity->miceProject->name )->setEntity('miceProject', $entity->idMiceProject) );

		// ADD SERVICES ///////////////////////////////////////////////////////////////////////////
		$cnt=1;
		foreach($entity->importedServicesList as $impServiceDet) {

			// add basic info
			$c1 = \Engine\RemoteData\InfoBox\Container_Simple::create(sprintf('Imported service %s', $cnt++));
			$output->addContainer($c1);

			$c1->addField( \Engine\RemoteData\InfoBox\Field_EntityInfoBox::create(	$lang['idServTina'],		$impServiceDet['id'] )->setEntity('importedService', $impServiceDet['id']) );
			$c1->addField(  \Engine\RemoteData\InfoBox\Field_String::create(		$lang['idServiceSys'], 		$impServiceDet['idServiceExtSys'] ) );
			$c1->addField(  \Engine\RemoteData\InfoBox\Field_String::create(		$lang['serviceType'], 		\App\Config\Services_Basic::getInstance()->getServiceName($impServiceDet['serviceCode']) ) );

			$c1->addField(  \Engine\RemoteData\InfoBox\Field_String::create(		$lang['systemStatus'], 		$this->globalLang['importedService']['systemStatusName'][$impServiceDet['systemStatus']] ) );
			$c1->addField(  \Engine\RemoteData\InfoBox\Field_String::create(		$lang['processStatus'], 	$this->globalLang['importedService']['statusName'][$impServiceDet['processStatus']] ) );

		}

		return $output;
	}

}
