<?php

namespace App\ReportsData\Populate\Entity;

class Order extends \App\ReportsData\Populate\GeneralAbstract
{

	/**
	 * Returns the table name that will store the current entity queue.
	 * @return string
	 */
	protected function getDbTableName()
	{
		global $DBTRd_orders;
		return $DBTRd_orders;
	}


	/**
	 * {@inheritDoc}
	 * @see \App\ReportsData\Populate\GeneralAbstract::getEntityFields()
	 */
	protected function getEntityFields()
	{
		// get current entity details
		$entity = \Entity\Order::select($this->id);

		// for non existing rows - return null
		if (!$entity->recordExists()) {
			return null;
		}

		// populate the entity details
		$return = [
			'id'						=> $this->id,
			'convertedId'				=> $entity->convertedId,
			'orderNumber'				=> $entity->reservationNumber,
			'orderCode'					=> $entity->reservationCode,
			'idAutoProcessRule'			=> $entity->idAutoProcessRule,
			'orderType'					=> $entity->resType,
			'flag'						=> $entity->flag,
			'servicesType'				=> $entity->servicesType,
			'date'						=> $entity->date,
			'idCustomerOwner'			=> $entity->idCustomerOwner,
			'idCustomers'				=> ($entity->idCustomersList ? json_encode($entity->idCustomersList) : ''),
			'idCorporateOwner'			=> $entity->idCorporateOwner,
			'idCorporateOwnerOffice'	=> $entity->idCorporateOwnerOffice,
			'corporateOwnerOfficeCostCenter' => $entity->corporateOwnerOfficeCostCenter,
			'idCorporates'				=> ($entity->idCorporatesList ? json_encode($entity->idCorporatesList) : ''),
			'idContactPerson'			=> $entity->idContactPerson,
			'pax'						=> $entity->pax,
			'undefinedPaxDetails'		=> ($entity->undefinedPax ? json_encode($entity->undefinedPax) : ''),
			'startDate'					=> $entity->startDate,
			'endDate'					=> $entity->endDate,
			'idMiceProject'				=> $entity->idMiceProject,
			'description'				=> $entity->description,
			'notes'						=> $entity->notes,
			'comments'					=> $entity->comments,
			'statusOp'					=> $entity->statusOp,
			'statusFin'					=> $entity->statusFin,
			'genDocsAssoc'				=> ($entity->generatedDocumentsAssoc ? json_encode($entity->generatedDocumentsAssoc) : ''),
			'idUser'					=> $entity->idUser,
			'idOffice'					=> $entity->idOffice,
			'idDepartment'				=> $entity->idDepartment,
			'idAddUser'					=> $entity->idAddUser,
			'addTime'					=> \Engine\DateTime::createFromTimestamp($entity->addTime)->formatDatetimeIso(),
			'lastUpdateTime'			=> ( $entity->lastUpdateTime ? \Engine\DateTime::createFromTimestamp($entity->lastUpdateTime)->formatDatetimeIso() : null ),
			'idUpdateUser'				=> $entity->idUpdateUser,
			'updatesCount'				=> $entity->updatesCount,

		];

		return $return;
	}

}
