<?php

namespace Modules\RemoteData\InfoBox;


class View_ContactPerson extends \App\Mvc\View_RemoteDataInfoBoxEntityAbstract
{

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

		// load global config
		$_LANG = \App\Loader_Lang::getInstance()->getAll();

		// the output object
		$fullName = trim(sprintf("%s %s %s", $_LANG['generalData']['personTitles'][$entity->title], $entity->lastName, $entity->firstName));
		$output = \Engine\RemoteData\InfoBox\Container_Main::create( sprintf($this->lang['contactPerson']['title'], $fullName) )
			->setShortTitle( $fullName )
			->setId(sprintf("%s.%s", __CLASS__, $entity->getId()));


		// COMPANY DETAILS
		$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()) );
		if ($entity->type=="corporate") {
			$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['contactPerson']['fields']['company']['name'], $entity->company->alias)->setEntity('corporate', $entity->idCompany) );
		} else {
			$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['contactPerson']['fields']['company']['name'], $entity->company->alias)->setEntity('supplier', $entity->idCompany) );
		}
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['contactPerson']['fields']['company']['type'], $this->lang['contactPerson']['fields']['company'][$entity->type]) );

		// CONTACT PERSON DETAILS
		$cont2 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['contactPerson']['titles']['contactPerson']);
		$output->addContainer($cont2);
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['contactPerson']['fields']['name'], trim(sprintf("%s %s %s", $_LANG['generalData']['personTitles'][$entity->title], $entity->lastName, $entity->firstName))) );
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['contactPerson']['fields']['job'],  $entity->job) );
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['contactPerson']['fields']['role'],   $_LANG['generalData']['contactPersonsRoles'][$entity->role]) );
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['contactPerson']['fields']['department'],  $entity->department) );
		if ($entity->type=="corporate") {
			$cont2->addField(  \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['contactPerson']['fields']['office'], $entity->corporateOffice->name)->setEntity('corporateOffice', $entity->idOffice) );
		}

		// CONTACTING METHODS
		$cont3 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['contactPerson']['titles']['contactDetails']);
		$output->addContainer($cont3);
		$cont3->addField( \Engine\RemoteData\InfoBox\Field_Telephone::create($this->lang['contactPerson']['fields']['telephone'],  $entity->telephone) );
		$cont3->addField( \Engine\RemoteData\InfoBox\Field_Telephone::create($this->lang['contactPerson']['fields']['telephoneMobile'],  $entity->telephoneMobile) );
		$cont3->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['contactPerson']['fields']['fax'],  $entity->fax) );
		$cont3->addField( \Engine\RemoteData\InfoBox\Field_Email::create($this->lang['contactPerson']['fields']['email'],  $entity->email) );

		// MISC INFO
		$cont4 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['general']['titles']['misc'])->setHidden(true);
		$output->addContainer($cont4);
		if ($entity->birthday) {
			$cont4->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['contactPerson']['fields']['birthday'],  $entity->birthday) );
		}
		$cont4->addField( \Engine\RemoteData\InfoBox\Field_MultiLine::create($this->lang['general']['fields']['comments'], $entity->comments) );
		$cont4->addField( \Engine\RemoteData\InfoBox\Field_Remarks::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('contactPerson', $entity->processedRemarks);
		$output->addContainer($cRmk);


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

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

		return $output;

	}

}
