<?php

namespace App\ImportedOrder\PopulateEntity;

/**
 * The class is used for populating a corporate entity object with data from an imported corporate (from imported order).
 * @author Gabriel
 */
class Corporate extends GeneralAbstract
{

	/**
	 * The imported entity (service); this is redundant, it's added only for the IDE autocomplete to work.
	 * @var \App\ImportedOrder\Corporate
	 */
	protected $importedEntity;

	/**
	 * The imported entity class name.
	 * @var String
	 */
	protected $importedEntityClass = '\App\ImportedOrder\Corporate';

	/**
	 * The populating entity class name.
	 * @var String
	 */
	protected $populatingEntityClass = '\Entity\Corporate';


	/**
	 * (non-PHPdoc)
	 * @see \App\ImportedOrder\PopulateEntity\GeneralAbstract::populate()
	 */
	public function populate()
	{

		// attach the company and the alias
		if ($this->importedEntity->nameLocal!==null) {
			$this->populatingEntity->alias =					htmlClean(mb_strtoupper($this->importedEntity->nameLocal));
			$this->populatingEntity->companyLocal =				htmlClean(mb_strtoupper($this->importedEntity->nameLocal));
		}
		if ($this->importedEntity->nameStandard!==null) {
			$this->populatingEntity->alias =					htmlClean(mb_strtoupper($this->importedEntity->nameStandard)); // rewrite "alias" - "standard name" should be more important than "local name"
			$this->populatingEntity->companyStandard =			htmlClean(mb_strtoupper($this->importedEntity->nameStandard));
		}
		// prefix and suffix
		if ($this->importedEntity->prefixStandard!==null) {
			$this->populatingEntity->companyPrefixStandard =	$this->importedEntity->prefixStandard;
		}
		if ($this->importedEntity->suffixStandard!==null) {
			$this->populatingEntity->companySuffixStandard =	$this->importedEntity->suffixStandard;
		}
		if ($this->importedEntity->prefixLocal!==null) {
			$this->populatingEntity->companyPrefixLocal =		$this->importedEntity->prefixLocal;
		}
		if ($this->importedEntity->suffixLocal!==null) {
			$this->populatingEntity->companySuffixLocal =		$this->importedEntity->suffixLocal;
		}
		// attach the fiscal code
		if ($this->importedEntity->fiscalCode!==null) {
			$this->populatingEntity->fiscalCode =				htmlClean($this->importedEntity->fiscalCode);
		}
		// attach the VAT certificate number
		if ($this->importedEntity->vatCertificateNumber!==null) {
			$this->populatingEntity->vatCertificateNumber =		htmlClean($this->importedEntity->vatCertificateNumber);
			if (strlen($this->importedEntity->vatCertificateNumber)) {
				$this->populatingEntity->vatRegistered =		1;
			}
		}
		// attach the registry address
		if ($this->importedEntity->registryAddress!==null) {
			$this->populatingEntity->registryAddress =			htmlClean($this->importedEntity->registryAddress);
		}
		// attach the contact details
		if ($this->importedEntity->email!==null) {
			$this->populatingEntity->email =					$this->importedEntity->email;
		}
		if ($this->importedEntity->telephone!==null) {
			$this->populatingEntity->telephone =				htmlClean($this->importedEntity->telephone);
		}
		// attach the remarks
		if ($this->importedEntity->remarks!==null) {
			$this->populatingEntity->remarks =					htmlClean($this->importedEntity->remarks);
		}

	}

}
