private function _checkAccount($custId, $value) { $req = new RequestAccountGet(); $req->setCustomerId($custId); $req->setAssetTypeCode(Cfg::CODE_TYPE_ASSET_PV); $resp = $this->_callAccount->get($req); $this->assertTrue($resp->isSucceed()); $actualValue = $resp->getBalance(); $this->assertEquals($value, $actualValue); }
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); } } }
public function debitFromCustomer(Request\DebitFromCustomer $request) { $result = new Response\DebitFromCustomer(); /* get representative customer account for PV asset */ $reqRepres = new AccountGetRepresentativeRequest(); $reqRepres->setAssetTypeCode(Cfg::CODE_TYPE_ASSET_PV); $respRepres = $this->_callAccount->getRepresentative($reqRepres); /* extract input parameters */ $requestData = $request->getData(); $requestData[Request\BetweenCustomers::TO_CUSTOMER_ID] = $respRepres->getData(Account::ATTR_CUST_ID); $requestData[Request\BetweenCustomers::COND_FORCE_ALL] = true; $reqBetween = new Request\BetweenCustomers($requestData); $respBetween = $this->betweenCustomers($reqBetween); if ($respBetween->isSucceed()) { $result->markSucceed(); } return $result; }
/** * @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; }
public function payForSaleOrder(Request\PayForSaleOrder $req) { $result = new Response\PayForSaleOrder(); /* extract request params */ $custId = $req->getCustomerId(); $value = $req->getBaseAmountToPay(); $saleOrderId = $req->getOrderId(); /* collect data */ $reqGet = new \Praxigento\Accounting\Service\Account\Request\Get(); $reqGet->setCustomerId($custId); $reqGet->setAssetTypeCode(Cfg::CODE_TYPE_ASSET_WALLET_ACTIVE); $reqGet->setCreateNewAccountIfMissed(true); $respGet = $this->_callAccount->get($reqGet); $accIdDebit = $respGet->getId(); $assetTypeId = $respGet->getAssetTypeId(); $reqGetRepres = new \Praxigento\Accounting\Service\Account\Request\GetRepresentative(); $reqGetRepres->setAssetTypeId($assetTypeId); $respGetRepres = $this->_callAccount->getRepresentative($reqGetRepres); $accIdCredit = $respGetRepres->getId(); /* compose transaction data */ $transaction = new \Praxigento\Accounting\Data\Entity\Transaction(); $transaction->setDebitAccId($accIdDebit); $transaction->setCreditAccId($accIdCredit); $transaction->setValue($value); /* create operation using service call */ $reqAddOper = new \Praxigento\Accounting\Service\Operation\Request\Add(); $reqAddOper->setOperationTypeCode(Cfg::CODE_TYPE_OPER_WALLET_SALE); $reqAddOper->setTransactions([$transaction]); $reqAddOper->setCustomerId($custId); $respAddOper = $this->_callOper->add($reqAddOper); $operId = $respAddOper->getOperationId(); $result->setOperationId($operId); // /* log sale order operation */ // $log = new \Praxigento\Wallet\Data\Entity\Log\Sale(); // $log->setOperationRef($operId); // $log->setSaleOrderRef($saleOrderId); if ($respAddOper->isSucceed()) { $result->markSucceed(); } return $result; }
public function cacheReset() { $this->_callAccount->cacheReset(); }