<?php
namespace App\ImportedDocument; class Payment extends DocumentAbstract { protected $docCategory = 'payment'; protected $supplier; protected $supplierInvoicesList=null; public function setSupplier(\App\ImportedDocument\Supplier $supplier) { $this->supplier = $supplier; } public function getSupplier() { return $this->supplier; } public function addSupplierInvoice(\App\ImportedDocument\SupplierInvoice $invoice) { $this->supplierInvoicesList[] = $invoice; } public function getSupplierInvoicesList() { return $this->supplierInvoicesList; } public function clearSupplierInvoicesList() { $this->supplierInvoicesList = []; } protected function validateEntityFields_specificDoc(\App\MessagesCollector $messagesCollector) :void { if ($this->supplier) { $messagesCollector->appendMessages($this->supplier->check(), 'Supplier: %s'); } if ($this->supplierInvoicesList) { foreach ($this->supplierInvoicesList as $suppInv) { $messagesCollector->appendMessages($suppInv->check(), 'Supplier invoice: %s'); if ($suppInv->limitProcessingValue and $suppInv->currency and $suppInv->currency!=$this->currency) { $messagesCollector->addWarning(sprintf('The supplier invoice currency (%s) is different than the document currency (%s).', $suppInv->currency, $this->currency)); } if ($suppInv->limitProcessingValue) { if ( ($suppInv->limitProcessingValue>0 and $this->value<0) or ($suppInv->limitProcessingValue<0 and $this->value>0) ) { $messagesCollector->addWarning('The supplier invoice limit processing value must have the same sign as the document.'); } } } } } public function getMatchedDocumentType($idExternalSystem) { if (!strlen($this->docType)) { return null; } $matchedDocType = \App\Config\ImportedDocuments\Matches::getInstance()->getDocType($idExternalSystem, $this->docType, $this->docCategory); if ($matchedDocType) { return $matchedDocType; } elseif (\App\Config\PaymentDocuments::getInstance()->isActive($this->docType)) { return $this->docType; } else { return null; } } public function getMatchedPartnerDetails() { $externalSystemId = \Entity\ImportedDocumentsSystem::getSystemIdByCode($this->externalSystemCode); $suppMatching = null; $suppObj = $this->getSupplier(); if (!$suppObj) { $suppObj = new \App\ImportedDocument\Supplier(); } $suppMatching = $suppObj->getMatchedId($externalSystemId, $this); if ($suppMatching) { return ['type'=>'supplier', 'id'=>$suppMatching]; } return []; } }