<?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); $invListObj->setFilter('inv.invoiceDate', 'BETWEEN', [$this->startDate, $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); $payDocListObj->setFilter('doc.docDate', 'BETWEEN', [$this->startDate, $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); } } } 