<?php
 namespace App\ReportsData\Populate\Entity; class Supplier extends \App\ReportsData\Populate\GeneralAbstract { private $dbTableName_supplierGroups; protected function getDbTableName() { global $DBTRd_suppliers, $DBTRd_supplierGroups; $this->dbTableName_supplierGroups = $DBTRd_supplierGroups; return $DBTRd_suppliers; } protected function getEntityFields() { $entity = \Entity\Supplier::select($this->id); if (!$entity->recordExists()) { return null; } $return = [ 'id' => $this->id, 'deleted' => $entity->deleted, 'locked' => $entity->locked, 'alias' => $entity->alias, 'companyPrefix' => $entity->companyPrefix, 'companyName' => $entity->company, 'companySuffix' => $entity->companySuffix, 'idTrust' => $entity->idTrust, 'category' => $entity->category, 'address' => $entity->address, 'deliveryAddress' => $entity->deliveryAddress, 'zipCode' => $entity->zipCode, 'countryCode' => $entity->countryCode, 'cityId' => $entity->cityId, 'regNo' => $entity->regNo, 'fiscalCode' => $entity->fiscalCode, 'vatRegistered' => $entity->vatRegistered, 'vatCertificateNumber' => $entity->vatCertificateNumber, 'incomeTaxPayer' => $entity->incomeTaxPayer, 'accountingNumber' => $entity->accountingNumber, 'bankAccounts' => ($entity->bankAccounts ? json_encode($entity->bankAccounts) : '' ), 'telephone' => $entity->telephone, 'fax' => $entity->fax, 'email' => $entity->email, 'website' => $entity->website, 'comments' => $entity->comments, 'remarks' => $entity->remarks, 'processedRemarks' => ($entity->processedRemarks ? json_encode($entity->processedRemarks) : ''), 'lockedComments' => $entity->lockedComments, 'codes' => ( $entity->codes ? json_encode($entity->codes) : '' ), 'iataCode' => $entity->codeIata, 'tktCode' => $entity->codeTktCode, 'idRealSupplier' => $entity->idRealSupplier, '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, ]; if ($entity->duplicatedSuppliersList) { foreach($entity->duplicatedSuppliersList as $idDuplSupp) { $this->addPopulatingReference('Supplier', $idDuplSupp); } } return $return; } public function populate() :void { parent::populate(); $groups = \Entity\Supplier::select($this->id)->idGroupElements; $this->dbExecuteDelete($this->dbTableName_supplierGroups, 'idSupplier', $this->id); if ($groups) { foreach($groups as $idGroupElement) { $fields = [ 'idGroupElement' => $idGroupElement, 'idSupplier' => $this->id, ]; $this->dbExecuteInsert($this->dbTableName_supplierGroups, $fields); } } } } 