<?php

namespace App\ReportsData\Populate\Entity;

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

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


	/**
	 * {@inheritDoc}
	 * @see \App\ReportsData\Populate\GeneralAbstract::getEntityFields()
	 */
	protected function getEntityFields()
	{

		// get current entity details
		$entity = \Entity\Office::select($this->id);

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

		// populate the entity details
		$return = [
			'id'					=> $this->id,
			'deleted'				=> $entity->deleted,
			'name'					=> $entity->name,
			'defaultOffice'			=> $entity->defaultOffice,
			'iataCode'				=> implode(', ', $entity->iataCode),
			'address'				=> $entity->address,
			'deliveryAddress'		=> $entity->deliveryAddress,
			'zipCode'				=> $entity->zipCode,
			'countryCode'			=> $entity->countryCode,
			'cityId'				=> $entity->cityId,
			'telephone'				=> $entity->telephone,
			'fax'					=> $entity->fax,
			'email'					=> $entity->email,
			'web'					=> $entity->web,
			'comments'				=> $entity->comments,
			'idDefaultBankAccount'	=> $entity->idDefaultBankAccount,
			'remarks'				=> $entity->remarks,
			'processedRemarks'		=> ($entity->processedRemarks ? json_encode($entity->processedRemarks) : ''),
			'addTime'				=> \Engine\DateTime::createFromTimestamp($entity->addTime)->formatDatetimeIso(),
			'idAddUser'				=> $entity->idAddUser,
			'lastUpdateTime'		=> ( $entity->lastUpdateTime ? \Engine\DateTime::createFromTimestamp($entity->lastUpdateTime)->formatDatetimeIso() : null ),
			'idUpdateUser'			=> $entity->idUpdateUser,
			'updatesCount'			=> $entity->updatesCount,
		];

		return $return;
	}

}



