<?php

namespace Modules\RemoteData\EntityManagementWs\Model\Entity\CashingDocument;

class Select extends \Modules\RemoteData\EntityManagementWs\Model\Entity\SelectAbstract
{

	protected $entityClass = 'InvoiceCashing';

	/**
	 * {@inheritDoc}
	 * @see \Modules\RemoteData\EntityManagementWs\Model\Entity\SelectAbstract::getResponseFieldsFromEntity()
	 */
	protected function getResponseFieldsFromEntity(\App\Entity\SelectAbstract $entityObj) : \stdClass
	{

		$outputFields = parent::getResponseFieldsFromEntity($entityObj);

		$cashingEnt = \Entity\InvoiceCashing::select($this->id);

		// general cashing doc details
		$outputFields->idInvoice		= $cashingEnt->idInvoice;
		$outputFields->docType			= $cashingEnt->docTypeCode;
		$outputFields->docDate			= $cashingEnt->docDate;
		$outputFields->docNumber		= $cashingEnt->docNumber?:null;

		$outputFields->value			= $cashingEnt->value;
		$outputFields->currency			= $cashingEnt->currency;

		$outputFields->addTime			= \Engine\DateTime::createFromTimestamp($cashingEnt->addTime)->formatDatetimeIso();
		$outputFields->issueTime		= ($cashingEnt->issueTime)?\Engine\DateTime::createFromTimestamp($cashingEnt->issueTime)->formatDatetimeIso():null;
		$outputFields->voidTime			= ($cashingEnt->voidTime)?\Engine\DateTime::createFromTimestamp($cashingEnt->voidTime)->formatDatetimeIso():null;

		// cashing generated docs
		if ($cashingEnt->documentsList) {
			$outputFields->documentsList = array_keys($cashingEnt->documentsList);
		} else {
			$outputFields->documentsList = null;
		}

		return $outputFields;
	}

}

