Commit | Line | Data |
---|---|---|
a5f2ebe4 PJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
a5f2ebe4 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
a5f2ebe4 PJ |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | ||
29 | ||
30 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
31 | require_once 'CiviTest/Contact.php'; | |
32 | require_once 'CiviTest/Event.php'; | |
33 | require_once 'CiviTest/Participant.php'; | |
4cbe18b8 EM |
34 | |
35 | /** | |
36 | * Class CRM_Event_BAO_AdditionalPaymentTest | |
37 | */ | |
a5f2ebe4 | 38 | class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { |
a5f2ebe4 | 39 | |
00be9182 | 40 | public function setUp() { |
a5f2ebe4 PJ |
41 | parent::setUp(); |
42 | $this->_contactId = Contact::createIndividual(); | |
43 | $this->_eventId = Event::create($this->_contactId); | |
44 | } | |
45 | ||
00be9182 | 46 | public function tearDown() { |
7b167a00 AH |
47 | $this->eventDelete($this->_eventId); |
48 | $this->quickCleanup( | |
49 | array( | |
50 | 'civicrm_contact', | |
51 | 'civicrm_contribution', | |
52 | 'civicrm_participant', | |
53 | 'civicrm_participant_payment', | |
54 | 'civicrm_line_item', | |
55 | 'civicrm_financial_item', | |
56 | 'civicrm_financial_trxn', | |
57 | 'civicrm_entity_financial_trxn', | |
58 | ), | |
59 | TRUE | |
60 | ); | |
61 | } | |
62 | ||
a5f2ebe4 | 63 | // helper function to record participant with paid contribution |
4cbe18b8 EM |
64 | /** |
65 | * @param $feeTotal | |
66 | * @param $actualPaidAmt | |
67 | * | |
68 | * @return array | |
69 | * @throws Exception | |
70 | */ | |
00be9182 | 71 | public function _addParticipantWithPayment($feeTotal, $actualPaidAmt) { |
a5f2ebe4 PJ |
72 | // creating price set, price field |
73 | $paramsSet['title'] = 'Price Set'; | |
74 | $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); | |
75 | $paramsSet['is_active'] = FALSE; | |
76 | $paramsSet['extends'] = 1; | |
77 | ||
78 | $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); | |
79 | CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceset->id); | |
80 | $priceSetId = $priceset->id; | |
81 | ||
82 | //Checking for priceset added in the table. | |
83 | $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', | |
84 | 'id', $paramsSet['title'], 'Check DB for created priceset' | |
85 | ); | |
86 | $paramsField = array( | |
87 | 'label' => 'Price Field', | |
88 | 'name' => CRM_Utils_String::titleToVar('Price Field'), | |
89 | 'html_type' => 'Text', | |
90 | 'price' => $feeTotal, | |
91 | 'option_label' => array('1' => 'Price Field'), | |
92 | 'option_value' => array('1' => $feeTotal), | |
93 | 'option_name' => array('1' => $feeTotal), | |
94 | 'option_weight' => array('1' => 1), | |
95 | 'option_amount' => array('1' => 1), | |
96 | 'is_display_amounts' => 1, | |
97 | 'weight' => 1, | |
98 | 'options_per_line' => 1, | |
99 | 'is_active' => array('1' => 1), | |
100 | 'price_set_id' => $priceset->id, | |
101 | 'is_enter_qty' => 1, | |
102 | ); | |
103 | ||
104 | $ids = array(); | |
105 | $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids); | |
106 | ||
107 | //Checking for priceset added in the table. | |
108 | $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', | |
109 | 'id', $paramsField['label'], 'Check DB for created pricefield' | |
110 | ); | |
111 | ||
112 | // create participant record | |
113 | $eventId = $this->_eventId; | |
114 | $participantParams = array( | |
115 | 'send_receipt' => 1, | |
116 | 'is_test' => 0, | |
117 | 'is_pay_later' => 0, | |
118 | 'event_id' => $eventId, | |
119 | 'register_date' => date('Y-m-d') . " 00:00:00", | |
120 | 'role_id' => 1, | |
121 | 'status_id' => 14, | |
122 | 'source' => 'Event_' . $eventId, | |
123 | 'contact_id' => $this->_contactId, | |
124 | 'note' => 'Note added for Event_' . $eventId, | |
125 | 'fee_level' => '\ 1Price_Field - 55\ 1', | |
126 | ); | |
172b82d1 EM |
127 | $participant = $this->callAPISuccess('participant', 'create', $participantParams); |
128 | $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); | |
a5f2ebe4 PJ |
129 | // create participant contribution with partial payment |
130 | $contributionParams = array( | |
131 | 'total_amount' => $actualPaidAmt, | |
132 | 'source' => 'Fall Fundraiser Dinner: Offline registration', | |
133 | 'currency' => 'USD', | |
134 | 'non_deductible_amount' => 'null', | |
135 | 'receipt_date' => date('Y-m-d') . " 00:00:00", | |
136 | 'contact_id' => $this->_contactId, | |
137 | 'financial_type_id' => 4, | |
138 | 'payment_instrument_id' => 4, | |
139 | 'contribution_status_id' => 1, | |
140 | 'receive_date' => date('Y-m-d') . " 00:00:00", | |
141 | 'skipLineItem' => 1, | |
142 | 'partial_payment_total' => $feeTotal, | |
21dfd5f5 | 143 | 'partial_amount_pay' => $actualPaidAmt, |
a5f2ebe4 | 144 | ); |
172b82d1 EM |
145 | |
146 | $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams); | |
a5f2ebe4 | 147 | $contributionId = $contribution->id; |
172b82d1 | 148 | $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); |
a5f2ebe4 PJ |
149 | |
150 | // add participant payment entry | |
172b82d1 | 151 | $this->callAPISuccess('participant_payment', 'create', array('participant_id' => $participant['id'], 'contribution_id' => $contributionId)); |
a5f2ebe4 PJ |
152 | |
153 | // -- processing priceSet using the BAO | |
154 | $lineItem = array(); | |
155 | $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE); | |
156 | $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); | |
157 | $feeBlock = CRM_Utils_Array::value('fields', $priceSet); | |
158 | $params['price_2'] = $feeTotal; | |
159 | CRM_Price_BAO_PriceSet::processAmount($feeBlock, | |
160 | $params, $lineItem | |
161 | ); | |
162 | $lineItemVal[$priceSetId] = $lineItem; | |
172b82d1 | 163 | CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant'); |
a5f2ebe4 PJ |
164 | return array($participant, $contribution); |
165 | } | |
166 | ||
167 | // CRM-13964 | |
00be9182 | 168 | public function testAddPartialPayment() { |
a5f2ebe4 PJ |
169 | $feeAmt = 100; |
170 | $amtPaid = 60; | |
171 | $balance = $feeAmt - $amtPaid; | |
172 | list($participant, $contribution) = $this->_addParticipantWithPayment($feeAmt, $amtPaid); | |
172b82d1 | 173 | $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event'); |
a5f2ebe4 PJ |
174 | |
175 | // amount checking | |
176 | $this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper'); | |
177 | $this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper'); | |
178 | $this->assertEquals(round($paymentInfo['balance']), $balance, 'Balance amount is not proper'); | |
179 | ||
180 | // status checking | |
172b82d1 | 181 | $this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant'); |
a5f2ebe4 PJ |
182 | $this->assertEquals($contribution->contribution_status_id, 8, 'Status record is not proper for contribution'); |
183 | } | |
7b167a00 | 184 | } |