<?php
 namespace App\PartnerBalance\History\Transactions; class Supplier extends GeneralAbstract { public function populateTransactions() { $this->addInvoices(); $this->addPaymentDocs(); ksort($this->transactionsList); } private function addInvoices() { $invListObj = new \App\EntityList\SupplierInvoices(); $invListObj->applyUserRestriction(false); if ($this->startDate and $this->endDate) { $invListObj->setFilter('inv.invoiceDate', 'BETWEEN', [$this->startDate, $this->endDate]); } elseif ($this->startDate) { $invListObj->setFilter('inv.invoiceDate', '>=', $this->startDate); } elseif ($this->endDate) { $invListObj->setFilter('inv.invoiceDate', '<=', $this->endDate); } $invListObj->setFilter('inv.idSupplier', '=', $this->id); $invListObj->setFilter('inv.currency', '=', $this->currency); $invListObj->setFilter('inv.statusOp', '=', 'confirmed'); $invListObj->setColumns(['inv.id', 'inv.invoiceDate', 'inv.totalValue']); if ($this->selectForUpdate) { $invListObj->setForUpdate(true); } $invListEx = $invListObj->getExecution(); foreach($invListEx as $inv) { $this->addTransaction($inv['invoiceDate'], $inv['totalValue'], 'inv', $inv['id']); } } private function addPaymentDocs() { $payDocListObj = new \App\EntityList\SupplierInvoicePayments(); $payDocListObj->applyUserRestriction(false); if ($this->startDate and $this->endDate) { $payDocListObj->setFilter('doc.docDate', 'BETWEEN', [$this->startDate, $this->endDate]); } elseif ($this->startDate) { $payDocListObj->setFilter('doc.docDate', '>=', $this->startDate); } elseif ($this->endDate) { $payDocListObj->setFilter('doc.docDate', '<=', $this->endDate); } $payDocListObj->setFilter('inv.idSupplier', '=', $this->id); $payDocListObj->setFilter('inv.currency', '=', $this->currency); $payDocListObj->setColumns(['doc.id'=>'idDoc', 'doc.docDate', 'doc.invoicePayedValue'=>'docInvoicePayedValue']); $payDocListObj->setColumns(['doc.idInvoice'=>'idInvoice', 'inv.totalValue'=>'invTotalValue', 'inv.payedValue'=>'invPayedTotal']); if ($this->selectForUpdate) { $payDocListObj->setForUpdate(true); } $payDocListEx = $payDocListObj->getExecution(); foreach($payDocListEx as $doc) { $extraInfo = []; if (abs($doc['invPayedTotal'])<=abs($doc['invTotalValue'])) { $docPayedValue = -$doc['docInvoicePayedValue']; } else { $allInvPaymentDocs = \Entity\SupplierInvoice::select($doc['idInvoice'], $this->selectForUpdate)->paymentDocumentsApplyMode; $docPayedValue = -$allInvPaymentDocs[$doc['idDoc']]['realPayedValue']; $extraInfo['docInvoicePayedValue'] = -(Float)$doc['docInvoicePayedValue']; } $this->addTransaction($doc['docDate'], $docPayedValue, 'doc', $doc['idDoc'], $extraInfo); } } } 