Пример #1
0
 /**
  * Add operation with list of transactions and change account balances.
  *
  * @param Request\Add $req
  *
  * @return Response\Add
  */
 public function add(Request\Add $req)
 {
     $result = new Response\Add();
     $operationTypeId = $req->getOperationTypeId();
     $operationTypeCode = $req->getOperationTypeCode();
     $datePerformed = $req->getDatePerformed();
     $note = $req->getOperationNote();
     $transactions = $req->getTransactions();
     $asRef = $req->getAsTransRef();
     $customerId = $req->getCustomerId();
     $adminUserId = $req->getAdminUserId();
     $def = $this->_manTrans->begin();
     try {
         /* add operation itself */
         if (!$operationTypeId) {
             $operationTypeId = $this->_repoTypeOper->getIdByCode($operationTypeCode);
         }
         $bindToAdd = [EntityOperation::ATTR_TYPE_ID => $operationTypeId, EntityOperation::ATTR_DATE_PREFORMED => $datePerformed];
         if (!is_null($note)) {
             $bindToAdd[EntityOperation::ATTR_NOTE] = $note;
         }
         $operId = $this->_repoOper->create($bindToAdd);
         if ($operId) {
             $transIds = $this->_subAdd->transactions($operId, $transactions, $datePerformed, $asRef);
             $result->setOperationId($operId);
             $result->setTransactionsIds($transIds);
             /* log customer link */
             if ($customerId) {
                 $log = new \Praxigento\Accounting\Data\Entity\Log\Change\Customer();
                 $log->setCustomerRef($customerId);
                 $log->setOperationRef($operId);
                 $this->_repoELogChangeCust->create($log);
             }
             /* log admin link */
             if ($adminUserId) {
                 $log = new \Praxigento\Accounting\Data\Entity\Log\Change\Admin();
                 $log->setUserRef($adminUserId);
                 $log->setOperationRef($operId);
                 $this->_repoELogChangeAdmin->create($log);
             }
             $this->_manTrans->commit($def);
             $result->markSucceed();
         }
     } finally {
         $this->_manTrans->end($def);
     }
     return $result;
 }
Пример #2
0
 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;
 }