Ejemplo n.º 1
0
 public function addToWalletActive(Request\AddToWalletActive $req)
 {
     $result = new Response\AddToWalletActive();
     $dateApplied = $req->getDateApplied();
     $datePerformed = $req->getDatePerformed();
     $operTypeCode = $req->getOperationTypeCode();
     $transData = $req->getTransData();
     $asAmount = $req->getAsAmount();
     $asCustId = $req->getAsCustomerId();
     $asRef = $req->getAsRef();
     $this->_logger->info("'Add to Wallet Active' operation is started.");
     /* prepare additional data */
     $datePerformed = is_null($datePerformed) ? $this->_toolDate->getUtcNowForDb() : $datePerformed;
     $dateApplied = is_null($dateApplied) ? $datePerformed : $dateApplied;
     /* get asset type ID */
     $assetTypeId = $this->_repoMod->getTypeAssetIdByCode(Cfg::CODE_TYPE_ASSET_WALLET_ACTIVE);
     /* get representative customer ID */
     $represAccId = $this->_getRepresentativeAccId($assetTypeId);
     /* save operation */
     $reqOperAdd = new \Praxigento\Accounting\Service\Operation\Request\Add();
     $reqOperAdd->setOperationTypeCode($operTypeCode);
     $reqOperAdd->setDatePerformed($datePerformed);
     $reqOperAdd->setAsTransRef($asRef);
     $trans = [];
     $reqGetAccount = new AccountGetRequest();
     $reqGetAccount->setCreateNewAccountIfMissed();
     $reqGetAccount->setAssetTypeId($assetTypeId);
     foreach ($transData as $item) {
         $custId = $item[$asCustId];
         $value = $item[$asAmount];
         if ($value > 0) {
             /* get WALLET_ACTIVE account ID for customer */
             $reqGetAccount->setCustomerId($custId);
             $respGetAccount = $this->_callAccount->get($reqGetAccount);
             $accId = $respGetAccount->getData(Account::ATTR_ID);
             $one = [Transaction::ATTR_DEBIT_ACC_ID => $represAccId, Transaction::ATTR_CREDIT_ACC_ID => $accId, Transaction::ATTR_DATE_APPLIED => $dateApplied, Transaction::ATTR_VALUE => $value];
             if (!is_null($asRef) && isset($item[$asRef])) {
                 $one[$asRef] = $item[$asRef];
             }
             $trans[] = $one;
             $this->_logger->debug("Transaction ({$value}) for customer #{$custId} (acc #{$accId}) is added to operation with type '{$operTypeCode}'.");
         } else {
             $this->_logger->debug("Transaction for customer #{$custId} is '{$value}'. Transaction is not included in operation with type '{$operTypeCode}'.");
         }
     }
     $reqOperAdd->setTransactions($trans);
     $respOperAdd = $this->_callOper->add($reqOperAdd);
     $operId = $respOperAdd->getOperationId();
     $this->_logger->debug("New operation (type id '{$operTypeCode}') is added with id={$operId} .");
     $result->setData($respOperAdd->getData());
     $result->markSucceed();
     $this->_logger->info("'Add to Wallet Active' operation is completed.");
     return $result;
 }
 /**
  * @param $updates [$custId=>[$rankId=>$bonus, ...], ...]
  *
  * @return \Praxigento\Wallet\Service\Operation\Response\AddToWalletActive
  */
 private function _createBonusOperation($updates)
 {
     $asCustId = 'asCid';
     $asAmount = 'asAmnt';
     $asRef = 'asRef';
     $transData = [];
     foreach ($updates as $custId => $ranks) {
         foreach ($ranks as $rankId => $amount) {
             $item = [$asCustId => $custId, $asAmount => $amount, $asRef => $rankId];
             $transData[] = $item;
         }
     }
     $req = new WalletOperationAddToWalletActiveRequest();
     $req->setAsCustomerId($asCustId);
     $req->setAsAmount($asAmount);
     $req->setAsRef($asRef);
     $req->setOperationTypeCode(Cfg::CODE_TYPE_OPER_BONUS);
     $req->setTransData($transData);
     $result = $this->_callWalletOperation->addToWalletActive($req);
     return $result;
 }