コード例 #1
0
 /**
  * @param array $params
  * @param $context
  */
 public function _checkFinancialRecords($params, $context)
 {
     $entityParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
     $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
     $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
     if ($context == 'pending') {
         $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
         $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
         return;
     }
     $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $trxnParams = array('id' => $trxn['financial_trxn_id']);
     if ($context != 'online' && $context != 'payLater') {
         $compareParams = array('to_financial_account_id' => 6, 'total_amount' => 100, 'status_id' => 1);
     }
     if ($context == 'feeAmount') {
         $compareParams['fee_amount'] = 50;
     } elseif ($context == 'online') {
         $compareParams = array('to_financial_account_id' => 12, 'total_amount' => 100, 'status_id' => 1);
     } elseif ($context == 'payLater') {
         $compareParams = array('to_financial_account_id' => 7, 'total_amount' => 100, 'status_id' => 2);
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
     $entityParams = array('financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item');
     $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $fitemParams = array('id' => $entityTrxn['entity_id']);
     $compareParams = array('amount' => 100, 'status_id' => 1, 'financial_account_id' => 1);
     if ($context == 'payLater') {
         $compareParams = array('amount' => 100, 'status_id' => 3, 'financial_account_id' => 1);
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
     if ($context == 'feeAmount') {
         $maxParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
         $maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE));
         $trxnParams = array('id' => $maxTrxn['financial_trxn_id']);
         $compareParams = array('to_financial_account_id' => 5, 'from_financial_account_id' => 6, 'total_amount' => 50, 'status_id' => 1);
         $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC');
         $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
         $fitemParams = array('entity_id' => $trxnId['financialTrxnId'], 'entity_table' => 'civicrm_financial_trxn');
         $compareParams = array('amount' => 50, 'status_id' => 1, 'financial_account_id' => 5);
         $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
     }
 }
コード例 #2
0
 /**
  * @param array $params
  * @param $context
  */
 public function _checkFinancialRecords($params, $context)
 {
     $entityParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
     if ($context == 'pending') {
         $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
         $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
         return;
     }
     $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $trxnParams = array('id' => $trxn['financial_trxn_id']);
     if ($context != 'online' && $context != 'payLater') {
         $compareParams = array('to_financial_account_id' => 6, 'total_amount' => 120, 'status_id' => 1);
     }
     if ($context == 'online') {
         $compareParams = array('to_financial_account_id' => 12, 'total_amount' => 120, 'status_id' => 1);
     } elseif ($context == 'payLater') {
         $compareParams = array('to_financial_account_id' => 7, 'total_amount' => 120, 'status_id' => 2);
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
     $entityParams = array('financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item');
     $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $fitemParams = array('id' => $entityTrxn['entity_id']);
     $compareParams = array('amount' => 100, 'status_id' => 1, 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID));
     if ($context == 'payLater') {
         $compareParams = array('amount' => 100, 'status_id' => 3, 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID));
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
 }
コード例 #3
0
 /**
  * @param array $params
  * @param $context
  */
 public function _checkFinancialRecords($params, $context)
 {
     $entityParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
     $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
     $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
     if ($context == 'pending') {
         $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
         $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
         return;
     }
     $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $trxnParams = array('id' => $trxn['financial_trxn_id']);
     if ($context != 'online' && $context != 'payLater') {
         $compareParams = array('to_financial_account_id' => 6, 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 1);
     }
     if ($context == 'feeAmount') {
         $compareParams['fee_amount'] = 50;
     } elseif ($context == 'online') {
         $compareParams = array('to_financial_account_id' => 12, 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 1, 'payment_instrument_id' => 1);
     } elseif ($context == 'payLater') {
         $compareParams = array('to_financial_account_id' => 7, 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 2);
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
     $entityParams = array('financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item');
     $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $fitemParams = array('id' => $entityTrxn['entity_id']);
     $compareParams = array('amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 1, 'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1));
     if ($context == 'payLater') {
         $compareParams = array('amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 3, 'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1));
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
     if ($context == 'feeAmount') {
         $maxParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
         $maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE));
         $trxnParams = array('id' => $maxTrxn['financial_trxn_id']);
         $compareParams = array('to_financial_account_id' => 5, 'from_financial_account_id' => 6, 'total_amount' => 50, 'status_id' => 1);
         $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC');
         $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
         $fitemParams = array('entity_id' => $trxnId['financialTrxnId'], 'entity_table' => 'civicrm_financial_trxn');
         $compareParams = array('amount' => 50, 'status_id' => 1, 'financial_account_id' => 5);
         $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
     }
     // This checks that empty Sales tax rows are not being created. If for any reason it needs to be removed the
     // line should be copied into all the functions that call this function & evaluated there
     // Be really careful not to remove or bypass this without ensuring stray rows do not re-appear
     // when calling completeTransaction or repeatTransaction.
     $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0);
 }
コード例 #4
0
 function _checkFinancialRecords($params, $context)
 {
     $entityParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
     $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $trxnParams = array('id' => $trxn['financial_trxn_id']);
     switch ($context) {
         case 'online':
             $compareParams = array('to_financial_account_id' => 12, 'total_amount' => 100, 'status_id' => 1);
             break;
         case 'offline':
             $compareParams = array('to_financial_account_id' => 6, 'total_amount' => 100, 'status_id' => 1);
             break;
         case 'payLater':
             $compareParams = array('to_financial_account_id' => 7, 'total_amount' => 100, 'status_id' => 2);
             break;
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
     $entityParams = array('financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item');
     $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $fitemParams = array('id' => $entityTrxn['entity_id']);
     if ($context == 'offline' || $context == 'online') {
         $compareParams = array('amount' => 100, 'status_id' => 1, 'financial_account_id' => 1);
     } elseif ($context == 'payLater') {
         $compareParams = array('amount' => 100, 'status_id' => 3, 'financial_account_id' => 1);
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
 }
コード例 #5
0
 /**
  * check method retrieveEntityFinancialTrxn()
  */
 function testRetrieveEntityFinancialTrxn()
 {
     $entityTrxn = self::testCreateEntityTrxn();
     $params = array('entity_table' => 'civicrm_contribution', 'entity_id' => 1, 'financial_trxn_id' => $entityTrxn->financial_trxn_id, 'amount' => $entityTrxn->amount);
     CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params);
     $entityResult = $this->assertDBNotNull('CRM_Financial_DAO_EntityFinancialTrxn', $entityTrxn->financial_trxn_id, 'amount', 'financial_trxn_id', 'Database check on added entity financial trxn record.');
     $this->assertEquals($entityResult, $entityTrxn->amount, 'Verify Amount for Financial Item');
 }
コード例 #6
0
 /**
  * Check financial transaction.
  *
  * @todo break this down into sensible functions - most calls to it only use a few lines out of the big if.
  *
  * @param array $contribution
  * @param string $context
  * @param int $instrumentId
  * @param array $extraParams
  */
 public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array())
 {
     $trxnParams = array('entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution');
     $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, TRUE));
     $params = array('id' => $trxn['financial_trxn_id']);
     if ($context == 'payLater') {
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
         $compareParams = array('status_id' => 1, 'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId));
     } elseif ($context == 'refund') {
         $compareParams = array('to_financial_account_id' => 6, 'total_amount' => -100, 'status_id' => 7, 'trxn_date' => '2015-01-01 09:00:00', 'trxn_id' => 'the refund');
     } elseif ($context == 'cancelPending') {
         $compareParams = array('to_financial_account_id' => 7, 'total_amount' => -100, 'status_id' => 3);
     } elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') {
         $entityParams = array('entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'amount' => -100);
         $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
         $trxnParams1 = array('id' => $trxn['financial_trxn_id']);
         if (empty($extraParams)) {
             $compareParams = array('total_amount' => -100, 'status_id' => 1);
         } else {
             $compareParams = array('total_amount' => 100, 'status_id' => 1);
         }
         if ($context == 'paymentInstrument') {
             $compareParams += array('to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4), 'payment_instrument_id' => 4);
         } else {
             $compareParams['to_financial_account_id'] = 12;
         }
         $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, array_merge($compareParams, $extraParams));
         $compareParams['total_amount'] = 100;
         if ($context == 'paymentInstrument') {
             $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($instrumentId);
             $compareParams['payment_instrument_id'] = $instrumentId;
         } else {
             $compareParams['to_financial_account_id'] = 12;
         }
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, array_merge($compareParams, $extraParams));
 }