<?php

namespace Modules\RemoteData\InfoBox;

class View_SupplierInvoicePayment extends \App\Mvc\View_RemoteDataInfoBoxEntityAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_RemoteDataInfoBoxEntityAbstract::getEntityRemoteDetails()
	 */
	protected function getEntityRemoteDetails(\App\Entity\SelectAbstract $entity)
	{

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

		// document number
		$docNo=$entity->docNumber;
		if (!$docNo) $docNo='-';

		// invoice number
		$invNo=$entity->supplierInvoice->invoiceNumber.' / '.\Engine\DateTime::createFromIsoDate($entity->supplierInvoice->invoiceDate)->formatDateStd();


		// BASIC INFO -----------------------------------------------------------------------------
		$cont1 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['general']['titles']['general']);
		$output->addContainer($cont1);

		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['general']['fields']['id'], $entity->getId()) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['supplierInvoicePayment']['fields']['docType'], $entity->docTypeName) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['supplierInvoicePayment']['fields']['docNumber'], $docNo) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_Date::create($this->lang['supplierInvoicePayment']['fields']['docDate'], \Engine\DateTime::createFromIsoDate($entity->docDate)) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_Price::create($this->lang['supplierInvoicePayment']['fields']['value'])->setPrice($entity->value, $entity->currency) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['supplierInvoicePayment']['fields']['bankAccount'], $entity->bankAccount->account) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_Callback::create($this->lang['supplierInvoicePayment']['fields']['invoice'], $invNo)->setCallback("supplierInvoiceView('{$entity->idInvoice}')") );
		if ($entity->idImportedDoc) {
			$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['supplierInvoicePayment']['fields']['idImportedDoc'], '#'.$entity->idImportedDoc)->setEntity('importedDocument', $entity->idImportedDoc) );
		}

		// MISC INFO ------------------------------------------------------------------------------
		$cont2 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['general']['titles']['misc'])->setHidden(true);
		$output->addContainer($cont2);

		$cont2->addField( \Engine\RemoteData\InfoBox\Field_MultiLine::create($this->lang['general']['fields']['explanations'], $entity->explanations) );
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_MultiLine::create($this->lang['general']['fields']['comments'], $entity->comments) );
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_MultiLine::create($this->lang['general']['fields']['remarks'], $entity->remarks) );

		// PROCESSED REMARKS
		$cRmk = \Engine\RemoteData\InfoBox\Container_ProcessedRemarks::create($this->lang['general']['fields']['processedRemarks'])->setHidden(true);
		$cRmk->addRemarkFields('supplierInvoicePayment', $entity->processedRemarks);
		$output->addContainer($cRmk);


		// USER INFO ------------------------------------------------------------------------------
		$cont3 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['supplierInvoicePayment']['titles']['users']);
		$output->addContainer($cont3);

		$cont3->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['respUser'], $entity->user->name)->setEntity('user', $entity->idUser) );
		$cont3->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['respOffice'], $entity->office->name)->setEntity('office', $entity->idOffice) );

		$cont3->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['blockUser'], $entity->blockUser->name)->setEntity('user', $entity->idBlockUser) );
		$cont3->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['blockTime'], \Engine\DateTime::createFromTimestamp($entity->blockTime)) );

		$cont3->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['addUser'], $entity->addUser->name)->setEntity('user', $entity->idAddUser) );
		$cont3->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['addTime'], \Engine\DateTime::createFromTimestamp($entity->addTime)) );
		$cont3->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['updateTime'], \Engine\DateTime::createFromTimestamp($entity->lastUpdateTime)) );
		$cont3->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['updateUser'], $entity->updateUser->name)->setEntity('user', $entity->idUpdateUser) );
		if ($entity->updatesCount) {
			$cont3->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['general']['fields']['updatesCount'], $entity->updatesCount) );
		}

		return $output;

	}

}