/** * Get account ID for representative customer. * * @param int $assetTypeId * * @return int */ private function _getRepresentativeAccId($assetTypeId) { $req = new AccountGetRepresentativeRequest(); $req->setAssetTypeId($assetTypeId); $resp = $this->_callAccount->getRepresentative($req); $result = $resp->getData(Account::ATTR_ID); return $result; }
private function _validateWalletsAfterTeam() { $EXPECT_REPRES_AMOUNT = -6.25; $EXPECT_BALANCE = [1 => 0.0, 2 => 0, 3 => 6.25, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0]; /* get Asset Type ID foe WALLET_ACTIVE */ $assetTypeId = $this->_repoTypeAsset->getIdByCode(Cfg::CODE_TYPE_ASSET_WALLET_ACTIVE); /* get representative account for WALLET_ACTIVE */ $reqRepresAcc = new AccGetRepresentativeRequest(); $reqRepresAcc->setAssetTypeId($assetTypeId); $respRepresAcc = $this->_callAccAccount->getRepresentative($reqRepresAcc); $represAccId = $respRepresAcc->getData(Account::ATTR_ID); /* get data for WALLET_ACTIVE accounts */ $where = Account::ATTR_ASSET_TYPE_ID . '=' . $assetTypeId; $balanceData = $this->_repoBasic->getEntities(Account::ENTITY_NAME, null, $where); /* convert balances to form that is relative to customer index (not id) */ foreach ($balanceData as $one) { $accId = $one[Account::ATTR_ID]; $custId = $one[Account::ATTR_CUST_ID]; $balance = $one[Account::ATTR_BALANCE]; if ($accId == $represAccId) { $this->assertEquals($EXPECT_REPRES_AMOUNT, $balance); } else { /* get customer index by customer id */ $index = $this->_mapCustomerIndexByMageId[$custId]; $expBalance = $EXPECT_BALANCE[$index]; $this->assertEquals($expBalance, $balance); } } }
/** * @param $updates array [[Calc::A_CUST_ID, Calc::A_VALUE], ...] * @param $operTypeCode * @param null $datePerformed * @param null $dateApplied * * @return \Praxigento\Accounting\Service\Operation\Response\Add */ public function saveOperationWalletActive($updates, $operTypeCode, $datePerformed = null, $dateApplied = null) { /* prepare additional data */ $datePerformed = is_null($datePerformed) ? $this->_toolDate->getUtcNowForDb() : $datePerformed; $dateApplied = is_null($dateApplied) ? $datePerformed : $dateApplied; /* get asset type ID */ $assetTypeId = $this->_repoTypeAsset->getIdByCode(Cfg::CODE_TYPE_ASSET_WALLET_ACTIVE); /* get representative account data */ $reqAccRepres = new AccountGetRepresentativeRequest(); $reqAccRepres->setAssetTypeId($assetTypeId); $respAccRepres = $this->_callAccount->getRepresentative($reqAccRepres); $represAccId = $respAccRepres->getData(Account::ATTR_ID); /* save operation */ $req = new OperationAddRequest(); $req->setOperationTypeCode($operTypeCode); $req->setDatePerformed($datePerformed); $trans = []; $reqGetAccount = new AccountGetRequest(); $reqGetAccount->setCreateNewAccountIfMissed(); $reqGetAccount->setAssetTypeId($assetTypeId); foreach ($updates as $item) { $customerId = $item[Calc::A_CUST_ID]; $value = $item[Calc::A_VALUE]; if ($value > 0) { /* get WALLET_ACTIVE account ID for customer */ $reqGetAccount->setCustomerId($customerId); $respGetAccount = $this->_callAccount->get($reqGetAccount); $accId = $respGetAccount->getData(Account::ATTR_ID); /* skip representative account */ if ($accId == $represAccId) { continue; } $trans[] = [Transaction::ATTR_DEBIT_ACC_ID => $represAccId, Transaction::ATTR_CREDIT_ACC_ID => $accId, Transaction::ATTR_DATE_APPLIED => $dateApplied, Transaction::ATTR_VALUE => $value]; $this->_logger->debug("Transaction ({$value}) for customer #{$customerId} (acc #{$accId}) is added to operation '{$operTypeCode}'."); } else { $this->_logger->debug("Transaction for customer #{$customerId} is 0.00. Transaction is not included in operation '{$operTypeCode}'."); } } $req->setTransactions($trans); $result = $this->_callOper->add($req); $operId = $result->getOperationId(); $this->_logger->debug("New '{$operTypeCode}' operation is added with id={$operId}."); return $result; }