<?php

namespace Modules\RemoteData\InfoBox;

class View_InvoiceCashing 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['invoiceCashing']['title'])->setShortTitle($entity->docTypeName);

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

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

		// BUTTONS
		if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToSection('Modules/Invoices/Cashings/Listing')) {
			$icon = \Engine\RemoteData\InfoBox\Icon\Icon::create('filter');
			$icon->setJsCallback("window.open(MVC.appUrl('Invoices/Cashings/Listing', null, {'filters[id]': {$entity->getId()}, 'filters[idOfficeUser][id]':0, 'filters[docDate][start]':'{$entity->docDate}', 'filters[docDate][end]':'{$entity->docDate}',  'listing[reset]': '1' , 'listing[paramsSlot]':'1'} ), '_blank');");
			$icon->setTooltip($this->lang['invoiceCashing']['options']['filter']);
			$output->addIcon($icon);
		}

		// 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['invoiceCashing']['fields']['docType'], $entity->docTypeName) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['invoiceCashing']['fields']['docNumber'], $docNo) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['invoiceCashing']['fields']['series'], $entity->cashingSeries->code) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_Date::create($this->lang['invoiceCashing']['fields']['docDate'], \Engine\DateTime::createFromIsoDate($entity->docDate)) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_Price::create($this->lang['invoiceCashing']['fields']['value'])->setPrice($entity->value, $entity->currency) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['invoiceCashing']['fields']['bankAccount'], $entity->bankAccount->account) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_Callback::create($this->lang['invoiceCashing']['fields']['invoice'], $invNo)->setCallback("clientInvoiceView('{$entity->idInvoice}')") );
		if ($entity->idImportedDoc) {
			$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['invoiceCashing']['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) );

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

		if ($entity->issueTime) {
			$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['invoiceCashing']['fields']['issued'], $this->lang['invoiceCashing']['fields']['issuedSt']));
			$cont2->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['issueUser'], $entity->issueUser->name)->setEntity('user', $entity->idIssueUser) );
			$cont2->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['issueTime'], \Engine\DateTime::createFromTimestamp($entity->issueTime)) );
		}
		if ($entity->blockTime) {
			$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['invoiceCashing']['fields']['block'], $this->lang['invoiceCashing']['fields']['blockSt']));
			$cont2->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['blockUser'], $entity->blockUser->name)->setEntity('user', $entity->idBlockUser) );
			$cont2->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['blockTime'], \Engine\DateTime::createFromTimestamp($entity->blockTime)) );
		}

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

		// VOID DETAILS ---------------------------------------------------------------------------
		if ($entity->voidTime) {
			$contVoid = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['invoiceCashing']['fieldsets']['void']);
			$output->addContainer($contVoid);

			$contVoid->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['invoiceCashing']['fields']['void'], $this->globalLang['yes']));
			$contVoid->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['invoiceCashing']['fields']['voidReason'], $entity->voidReasonName));
			$contVoid->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['voidUser'], $entity->voidUser->name)->setEntity('user', $entity->idVoidUser) );
			$contVoid->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['voidTime'], \Engine\DateTime::createFromTimestamp($entity->voidTime)) );
		}

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

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

		return $output;

	}

}