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 change(Request\Change $request)
 {
     $result = new Response\Reset();
     $accCustId = $request->getCustomerAccountId();
     $adminUserId = $request->getAdminUserId();
     $value = $request->getChangeValue();
     $def = $this->_manTrans->begin();
     try {
         /* get account's asset type by ID */
         $assetTypeId = $this->_repoAccount->getAssetTypeId($accCustId);
         /* get representative account id for given asset type */
         $accRepresId = $this->_repoMod->getRepresentativeAccountId($assetTypeId);
         /* get operation type by code and date performed */
         $operTypeId = $this->_repoTypeOper->getIdByCode(Cfg::CODE_TYPE_OPER_CHANGE_BALANCE);
         $dateNow = $this->_toolDate->getUtcNowForDb();
         /* create operation */
         $operation = new \Praxigento\Accounting\Data\Entity\Operation();
         $operation->setTypeId($operTypeId);
         $operation->setDatePerformed($dateNow);
         $operId = $this->_repoOperation->create($operation);
         /* create transaction */
         $trans = new \Praxigento\Accounting\Data\Entity\Transaction();
         $trans->setOperationId($operId);
         $trans->setDateApplied($dateNow);
         if ($value > 0) {
             $trans->setDebitAccId($accRepresId);
             $trans->setCreditAccId($accCustId);
         } else {
             $trans->setDebitAccId($accCustId);
             $trans->setCreditAccId($accRepresId);
         }
         $trans->setValue(abs($value));
         $this->_repoTransaction->create($trans);
         /* log details (operator name who performs the operation) */
         $log = new ELogChangeAdmin();
         $log->setOperationRef($operId);
         $log->setUserRef($adminUserId);
         $this->_repoLogChangeAdmin->create($log);
         $this->_manTrans->commit($def);
         $result->markSucceed();
     } finally {
         $this->_manTrans->end($def);
     }
     return $result;
 }