3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
30 require_once 'CiviTest/Contact.php';
31 require_once 'CiviTest/Event.php';
32 require_once 'CiviTest/Participant.php';
35 * Class CRM_Event_BAO_AdditionalPaymentTest
37 class CRM_Event_BAO_AdditionalPaymentTest
extends CiviUnitTestCase
{
39 public function setUp() {
41 $this->_contactId
= Contact
::createIndividual();
42 $this->_eventId
= Event
::create($this->_contactId
);
45 public function tearDown() {
46 $this->eventDelete($this->_eventId
);
50 'civicrm_contribution',
51 'civicrm_participant',
52 'civicrm_participant_payment',
54 'civicrm_financial_item',
55 'civicrm_financial_trxn',
56 'civicrm_entity_financial_trxn',
63 * helper function to record participant with paid contribution.
65 * @param $actualPaidAmt
70 public function _addParticipantWithPayment($feeTotal, $actualPaidAmt) {
71 // creating price set, price field
72 $paramsSet['title'] = 'Price Set';
73 $paramsSet['name'] = CRM_Utils_String
::titleToVar('Price Set');
74 $paramsSet['is_active'] = FALSE;
75 $paramsSet['extends'] = 1;
77 $priceset = CRM_Price_BAO_PriceSet
::create($paramsSet);
78 CRM_Price_BAO_PriceSet
::addTo('civicrm_event', $this->_eventId
, $priceset->id
);
79 $priceSetId = $priceset->id
;
81 //Checking for priceset added in the table.
82 $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
83 'id', $paramsSet['title'], 'Check DB for created priceset'
86 'label' => 'Price Field',
87 'name' => CRM_Utils_String
::titleToVar('Price Field'),
88 'html_type' => 'Text',
90 'option_label' => array('1' => 'Price Field'),
91 'option_value' => array('1' => $feeTotal),
92 'option_name' => array('1' => $feeTotal),
93 'option_weight' => array('1' => 1),
94 'option_amount' => array('1' => 1),
95 'is_display_amounts' => 1,
97 'options_per_line' => 1,
98 'is_active' => array('1' => 1),
99 'price_set_id' => $priceset->id
,
101 'financial_type_id' => CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'),
105 $pricefield = CRM_Price_BAO_PriceField
::create($paramsField, $ids);
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'
112 // create participant record
113 $eventId = $this->_eventId
;
114 $participantParams = array(
118 'event_id' => $eventId,
119 'register_date' => date('Y-m-d') . " 00:00:00",
122 'source' => 'Event_' . $eventId,
123 'contact_id' => $this->_contactId
,
124 'note' => 'Note added for Event_' . $eventId,
125 'fee_level' => '\ 1Price_Field - 55\ 1',
127 $participant = $this->callAPISuccess('participant', 'create', $participantParams);
128 $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
129 // create participant contribution with partial payment
130 $contributionParams = array(
131 'total_amount' => $actualPaidAmt,
132 'source' => 'Fall Fundraiser Dinner: Offline registration',
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",
142 'partial_payment_total' => $feeTotal,
143 'partial_amount_pay' => $actualPaidAmt,
146 $contribution = CRM_Contribute_BAO_Contribution
::create($contributionParams);
147 $contributionId = $contribution->id
;
148 $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
150 // add participant payment entry
151 $this->callAPISuccess('participant_payment', 'create', array(
152 'participant_id' => $participant['id'],
153 'contribution_id' => $contributionId,
156 // -- processing priceSet using the BAO
158 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId, TRUE, FALSE);
159 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
160 $feeBlock = CRM_Utils_Array
::value('fields', $priceSet);
161 $params['price_2'] = $feeTotal;
162 CRM_Price_BAO_PriceSet
::processAmount($feeBlock,
165 $lineItemVal[$priceSetId] = $lineItem;
166 CRM_Price_BAO_LineItem
::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
167 return array($participant, $contribution);
173 public function testAddPartialPayment() {
176 $balance = $feeAmt - $amtPaid;
177 list($participant, $contribution) = $this->_addParticipantWithPayment($feeAmt, $amtPaid);
178 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($participant['id'], 'event');
181 $this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper');
182 $this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper');
183 $this->assertEquals(round($paymentInfo['balance']), $balance, 'Balance amount is not proper');
186 $this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant');
187 $this->assertEquals($contribution->contribution_status_id
, 8, 'Status record is not proper for contribution');