<?php
 namespace App\ReportsData\Populate\Entity; class Document extends \App\ReportsData\Populate\GeneralAbstract { protected function getDbTableName() { global $DBTRd_documents; return $DBTRd_documents; } protected function getEntityFields() { $entity = \Entity\Document::select($this->id); if (!$entity->recordExists()) { return null; } if ($entity->preview) { return null; } $history = $entity->history; $genHis = $history[0]; $emailDetails = []; foreach (array_reverse($history) as $data) { if ($data['op'] == 'e') { $emailDetails = $data['details']; $emailDetails['time'] = $data['t']; } } $fieldsDetails = $entity->fieldsDetails; $customTextArr = []; if ($fieldsDetails) { foreach ($fieldsDetails as $name => $field) { if (strpos($name, 'customText') !== FALSE) { $customTextArr[$name] = [ 'name' => $field['n'], 'value' => $field['val'], ]; } } } $return = [ 'id' => $this->id, 'pivot' => $entity->pivotCode, 'idPivot' => $entity->idPivot, 'docType' => $entity->docTypeCode, 'idTemplate' => $entity->idTemplate, 'idDocSeries' => $entity->idDocumentSeries, 'format' => $entity->format, 'docNumber' => $entity->docNumber, 'docDate' => $entity->docDate, 'generation' => $entity->generationCode, 'preview' => $entity->preview, 'comments' => $entity->comments, 'idAutoProcessRule' => $entity->idAutoProcessRule, 'idAddUser' => (Int)$genHis['us'], 'addTime' => ($entity->addDateTime?:($entity->docDate." 00:00:00")), 'emailDetails' => $emailDetails ? json_encode($emailDetails) : '', 'fieldsDetails' => $customTextArr ? json_encode($customTextArr) : '', 'extraInfo' => ($entity->extraInfo ? json_encode($entity->extraInfo) : ''), ]; switch ($entity->pivotCode) { case 'invoice': $this->addPopulatingReference('ClientInvoice', $entity->idPivot); break; case 'order': $this->addPopulatingReference('Order', $entity->idPivot); break; case 'service': $this->addPopulatingReference('Service', $entity->idPivot); break; case 'cashing': $this->addPopulatingReference('ClientInvoiceCashing', $entity->idPivot); break; case 'payment': $this->addPopulatingReference('SupplierInvoicePayment', $entity->idPivot); break; case 'importedDocument': $this->addPopulatingReference('ImportedDocument', $entity->idPivot); break; } return $return; } } 