$params['trxnParams']['to_financial_account_id'] = $financialAccount;
$params['trxnParams']['total_amount'] = $amount;
$params['trxnParams']['fee_amount'] = $params['trxnParams']['net_amount'] = 0;
- $params['trxnParams']['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
+ $params['trxnParams']['status_id'] = $params['contribution_status_id'];
$params['trxnParams']['contribution_id'] = $contributionId;
$trxn = self::create($params['trxnParams']);
if (empty($params['entity_id'])) {
* @return array
*/
public static function getTotalPayments($contributionId) {
- $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
- $sql = "SELECT SUM(ft.total_amount) FROM civicrm_financial_trxn ft
- INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution')
+ $statusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
+
+ $sql = "SELECT SUM(ft.total_amount) FROM civicrm_financial_trxn ft
+ INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution')
WHERE eft.entity_id = %1 AND ft.is_payment = 1 AND ft.status_id = %2";
$params = array(
1 => array($contributionId, 'Integer'),
2 => array($statusId, 'Integer'),
);
+
return CRM_Core_DAO::singleValueQuery($sql, $params);
}
}
/**
- * Create() method (create and update modes).
+ * Test getTotalPayments function.
*/
- public function testIsPaymentFlagForPending() {
- require_once 'CiviTest/Contact.php';
- $contactId = Contact::createIndividual();
- $ids = array('contribution' => NULL);
+ public function testGetTotalPayments() {
+ $contactId = $this->individualCreate();
$params = array(
'contact_id' => $contactId,
'thankyou_date' => '20080522',
);
- $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
- $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
- $this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.');
+ $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
+ $this->assertEquals($contactId, $contribution->contact_id);
$totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id);
$this->assertEquals(0, $totalPaymentAmount, 'Amount not matching.');
//update contribution amount
- $ids = array('contribution' => $contribution->id);
+ $params['id'] = $contribution->id;
$params['contribution_status_id'] = 1;
- $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
- $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id .');
- $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id, 'Check for status updation.');
+ $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
+ $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id);
$totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id);
$this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.');
- //Delete Contribution
- $this->contributionDelete($contribution->id);
- Contact::delete($contactId);
}
}