3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Event_BAO_AdditionalPaymentTest
32 class CRM_Event_BAO_AdditionalPaymentTest
extends CiviUnitTestCase
{
34 public function setUp() {
36 $this->_contactId
= $this->individualCreate();
37 $event = $this->eventCreate();
38 $this->_eventId
= $event['id'];
41 public function tearDown() {
42 $this->eventDelete($this->_eventId
);
46 'civicrm_contribution',
47 'civicrm_participant',
48 'civicrm_participant_payment',
50 'civicrm_financial_item',
51 'civicrm_financial_trxn',
52 'civicrm_entity_financial_trxn',
59 * Helper function to record participant with paid contribution.
61 * @param int $feeTotal
62 * @param int $actualPaidAmt
67 protected function addParticipantWithPayment($feeTotal, $actualPaidAmt) {
68 $priceSetId = $this->eventPriceSetCreate($feeTotal);
69 CRM_Price_BAO_PriceSet
::addTo('civicrm_event', $this->_eventId
, $priceSetId);
71 // create participant record
72 $eventId = $this->_eventId
;
73 $participantParams = array(
77 'event_id' => $eventId,
78 'register_date' => date('Y-m-d') . " 00:00:00",
81 'source' => 'Event_' . $eventId,
82 'contact_id' => $this->_contactId
,
83 'note' => 'Note added for Event_' . $eventId,
84 'fee_level' => '\ 1Price_Field - 55\ 1',
86 $participant = $this->callAPISuccess('participant', 'create', $participantParams);
87 $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
88 // create participant contribution with partial payment
89 $contributionParams = array(
90 'total_amount' => $actualPaidAmt,
91 'source' => 'Fall Fundraiser Dinner: Offline registration',
93 'non_deductible_amount' => 'null',
94 'receipt_date' => date('Y-m-d') . " 00:00:00",
95 'contact_id' => $this->_contactId
,
96 'financial_type_id' => 4,
97 'payment_instrument_id' => 4,
98 'contribution_status_id' => 1,
99 'receive_date' => date('Y-m-d') . " 00:00:00",
101 'partial_payment_total' => $feeTotal,
102 'partial_amount_pay' => $actualPaidAmt,
105 $contribution = CRM_Contribute_BAO_Contribution
::create($contributionParams);
106 $contributionId = $contribution->id
;
107 $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
109 // add participant payment entry
110 $this->callAPISuccess('participant_payment', 'create', array(
111 'participant_id' => $participant['id'],
112 'contribution_id' => $contributionId,
115 // -- processing priceSet using the BAO
117 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId, TRUE, FALSE);
118 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
119 $feeBlock = CRM_Utils_Array
::value('fields', $priceSet);
120 $params['price_2'] = $feeTotal;
121 CRM_Price_BAO_PriceSet
::processAmount($feeBlock,
124 $lineItemVal[$priceSetId] = $lineItem;
125 CRM_Price_BAO_LineItem
::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
126 return array($participant, $contribution);
132 public function testAddPartialPayment() {
135 $balance = $feeAmt - $amtPaid;
136 list($participant, $contribution) = $this->addParticipantWithPayment($feeAmt, $amtPaid);
137 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($participant['id'], 'event');
140 $this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper');
141 $this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper');
142 $this->assertEquals(round($paymentInfo['balance']), $balance, 'Balance amount is not proper');
145 $this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant');
146 $this->assertEquals($contribution->contribution_status_id
, 8, 'Status record is not proper for contribution');