/** * 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); } } }
/** * Account PV on sale done. * * @param Request\AccountPv $request * * @return Response\AccountPv */ public function accountPv(Request\AccountPv $request) { $result = new Response\AccountPv(); $saleId = $request->getSaleOrderId(); $customerId = $request->getCustomerId(); $dateApplied = $request->getDateApplied(); $this->_logger->info("PV accounting operation for sale order #{$saleId} is started."); $sale = $this->_repoSale->getById($saleId); $pvTotal = $sale->getTotal(); /* get customer for sale order */ if (is_null($customerId)) { $this->_logger->info("There is no customer ID in request, select customer ID from sale order data."); $customerId = $this->_repoMod->getSaleOrderCustomerId($saleId); $this->_logger->info("Order #{$saleId} is created by customer #{$customerId}."); } /* get PV account data for customer */ $reqGetAccCust = new GetAccountRequest(); $reqGetAccCust->setCustomerId($customerId); $reqGetAccCust->setAssetTypeCode(Cfg::CODE_TYPE_ASSET_PV); $reqGetAccCust->setCreateNewAccountIfMissed(true); $respGetAccCust = $this->_callAccount->get($reqGetAccCust); /* get PV account data for representative */ $reqGetAccRepres = new GetAccountRepresentativeRequest(); $reqGetAccRepres->setAssetTypeCode(Cfg::CODE_TYPE_ASSET_PV); $respGetAccRepres = $this->_callAccount->getRepresentative($reqGetAccRepres); /* create one operation with one transaction */ $reqAddOper = new AddOperationRequest(); $reqAddOper->setOperationTypeCode(Cfg::CODE_TYPE_OPER_PV_SALE_PAID); $trans = [Transaction::ATTR_DEBIT_ACC_ID => $respGetAccRepres->getId(), Transaction::ATTR_CREDIT_ACC_ID => $respGetAccCust->getId(), Transaction::ATTR_VALUE => $pvTotal, Transaction::ATTR_DATE_APPLIED => $dateApplied]; $reqAddOper->setTransactions([$trans]); $respAddOper = $this->_callOperation->add($reqAddOper); $operId = $respAddOper->getOperationId(); $result->setOperationId($operId); $result->markSucceed(); $this->_logger->info("PV accounting operation for sale order #{$saleId} is completed."); return $result; }
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; }