<?php
 namespace App\PartnerBalance\FixStoredValues\ImpDocsBalance; class Corporate extends \App\PartnerBalance\FixStoredValues\PartnerBalanceAbstract { protected string $entityNameDbField = 'idCorporate'; protected string $filterDocCategory = 'cashing'; public function __construct() { global $DBTCorporatesImpDocBalance; $this->mainDbTableName = $DBTCorporatesImpDocBalance; } public function getAllRealBalances(bool $forUpdate) :array { $impDocsList = new \App\EntityList\ImportedDocuments(); if ($forUpdate) { $impDocsList->setForUpdate(true); } $impDocsList->applyUserRestriction(false); $impDocsList->setFilter('status', 'IN', ['new', 'partial']); $impDocsList->setFilter($this->entityNameDbField, '>', 0); $impDocsList->setFilter('docCategory', '=', $this->filterDocCategory); $impDocsList->setColumns(['docValue', 'usedValue', 'docCurrency', $this->entityNameDbField, 'status']); $balancesList = []; foreach($impDocsList->getExecution() as $doc) { if (!key_exists($doc[$this->entityNameDbField], $balancesList)) { $balancesList[$doc[$this->entityNameDbField]] = []; } if (!key_exists($doc['docCurrency'], $balancesList[$doc[$this->entityNameDbField]])) { $balancesList[$doc[$this->entityNameDbField]][$doc['docCurrency']] = 0; } if ($doc['status']=='partial') { $adjustment = $doc['docValue'] - $doc['usedValue']; } else { $adjustment = $doc['docValue']; } $balancesList[$doc[$this->entityNameDbField]][$doc['docCurrency']] = $balancesList[$doc[$this->entityNameDbField]][$doc['docCurrency']] + $adjustment; } return $balancesList; } } 