/**
  * @expectedException \Exception
  */
 public function test_transactions_exception()
 {
     /** === Test Data === */
     $OPER_ID = 2;
     $DATE_PERFORMED = 'date';
     $TRANS = [[Transaction::ATTR_DEBIT_ACC_ID => 'debit', Transaction::ATTR_CREDIT_ACC_ID => 'credit', Transaction::ATTR_VALUE => 'value']];
     $TRAN_ID = 4;
     /** === Setup Mocks === */
     // $respTransAdd = $this->_callTransaction->add($reqTransAdd);
     $mResp = new AddResponse();
     $this->mCallTransaction->shouldReceive('add')->andReturn($mResp);
     /** === Call and asserts  === */
     $this->obj->transactions($OPER_ID, $TRANS, $DATE_PERFORMED);
 }
Пример #2
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;
 }