return CRM_Core_DAO::singleValueQuery($sql, $params);
}
+ /**
+ * @param array $contribution
+ * @param array $params
+ *
+ * @return CRM_Core_BAO_FinancialTrxn
+ */
+ public static function getPartialPaymentTrxn($contribution, $params) {
+ $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params);
+ $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']);
+ $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount');
+ $cmp = bccomp($total, $paid, 5);
+ if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount
+ civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));
+ }
+ return $trxn;
+ }
+
}
*
* @return array
*/
- protected function addParticipantWithContribution() {
+ public function addParticipantWithContribution() {
// creating price set, price field
require_once 'CiviTest/Event.php';
$this->_contactId = Contact::createIndividual();
$this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.');
}
+ /**
+ * Test getPartialPaymentTrxn function.
+ */
+ public function testGetPartialPaymentTrxn() {
+ $contributionTest = new CRM_Contribute_BAO_ContributionTest();
+ list($lineItems, $contribution) = $contributionTest->addParticipantWithContribution();
+ $contribution = (array) $contribution;
+ $params = array(
+ 'contribution_id' => $contribution['id'],
+ 'total_amount' => 100.00,
+ );
+ $trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params);
+
+ $this->assertEquals('100.00', $trxn->total_amount, 'Amount does not match.');
+
+ $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution['id']);
+ $this->assertEquals('250.00', $totalPaymentAmount, 'Amount does not match.');
+ }
+
}