Towards CRM-20392 (IIDA-108), code cleanup, removed cruft code
[civicrm-core.git] / CRM / Contribute / Form / AdditionalPayment.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2017
32 */
33
34 /**
35 * This form records additional payments needed when event/contribution is partially paid.
36 */
37 class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_AbstractEditPayment {
38 public $_contributeMode = 'direct';
39
40 /**
41 * Related component whose financial payment is being processed.
42 *
43 * @var string
44 */
45 protected $_component = NULL;
46
47 /**
48 * Id of the component entity
49 */
50 public $_id = NULL;
51
52 protected $_owed = NULL;
53
54 protected $_refund = NULL;
55
56 protected $_contactId = NULL;
57
58 protected $_contributorDisplayName = NULL;
59
60 protected $_contributorEmail = NULL;
61
62 protected $_toDoNotEmail = NULL;
63
64 protected $_paymentType = NULL;
65
66 protected $_contributionId = NULL;
67
68 protected $fromEmailId = NULL;
69
70 protected $_fromEmails = NULL;
71
72 protected $_view = NULL;
73
74 public $_action = NULL;
75
76 public function preProcess() {
77 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
78 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
79 $this->_component = CRM_Utils_Request::retrieve('component', 'String', $this, TRUE);
80 $this->_view = CRM_Utils_Request::retrieve('view', 'String', $this, FALSE);
81 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
82 $this->assign('component', $this->_component);
83 $this->assign('id', $this->_id);
84 $this->assign('suppressPaymentFormButtons', $this->isBeingCalledFromSelectorContext());
85
86 if ($this->_view == 'transaction' && ($this->_action & CRM_Core_Action::BROWSE)) {
87 $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, TRUE);
88 $transactionRows = $paymentInfo['transaction'];
89 $title = ts('View Payment');
90 if ($this->_component == 'event') {
91 $info = CRM_Event_BAO_Participant::participantDetails($this->_id);
92 $title .= " - {$info['title']}";
93 }
94 CRM_Utils_System::setTitle($title);
95 $this->assign('transaction', TRUE);
96 $this->assign('rows', $transactionRows);
97 return;
98 }
99 $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
100 $this->_formType = CRM_Utils_Array::value('formType', $_GET);
101
102 $enitityType = NULL;
103 $enitityType = 'contribution';
104 if ($this->_component == 'event') {
105 $enitityType = 'participant';
106 $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id');
107 $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
108 $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId);
109 }
110 else {
111 $this->_contributionId = $this->_id;
112 $this->_fromEmails['from_email_id'] = CRM_Core_BAO_Email::getFromEmail();
113 }
114
115 $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $enitityType);
116 $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE);
117
118 $this->_amtPaid = $paymentDetails['paid'];
119 $this->_amtTotal = $paymentDetails['total'];
120
121 if (!empty($paymentInfo['refund_due'])) {
122 $paymentAmt = $this->_refund = $paymentInfo['refund_due'];
123 $this->_paymentType = 'refund';
124 }
125 elseif (!empty($paymentInfo['amount_owed'])) {
126 $paymentAmt = $this->_owed = $paymentInfo['amount_owed'];
127 $this->_paymentType = 'owed';
128 }
129 else {
130 CRM_Core_Error::fatal(ts('No payment information found for this record'));
131 }
132
133 //set the payment mode - _mode property is defined in parent class
134 $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
135
136 if (!empty($this->_mode) && $this->_paymentType == 'refund') {
137 CRM_Core_Error::fatal(ts('Credit card payment is not for Refund payments use'));
138 }
139
140 list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
141
142 $this->assignPaymentRelatedVariables();
143
144 $this->assign('contributionMode', $this->_mode);
145 $this->assign('contactId', $this->_contactId);
146 $this->assign('paymentType', $this->_paymentType);
147 $this->assign('paymentAmt', abs($paymentAmt));
148
149 $this->setPageTitle($this->_refund ? ts('Refund') : ts('Payment'));
150 }
151
152 /**
153 * Is this function being called from a datatable selector.
154 *
155 * If so we don't want to show the buttons.
156 */
157 protected function isBeingCalledFromSelectorContext() {
158 return CRM_Utils_Request::retrieve('selector', 'Positive');
159 }
160
161 /**
162 * This virtual function is used to set the default values of
163 * various form elements
164 *
165 * access public
166 *
167 * @return array
168 * reference to the array of default values
169 */
170 /**
171 * @return array
172 */
173 public function setDefaultValues() {
174 if ($this->_view == 'transaction' && ($this->_action & CRM_Core_Action::BROWSE)) {
175 return NULL;
176 }
177 $defaults = array();
178 if ($this->_mode) {
179 CRM_Core_Payment_Form::setDefaultValues($this, $this->_contactId);
180 $defaults = array_merge($defaults, $this->_defaults);
181 }
182
183 if (empty($defaults['trxn_date']) && empty($defaults['trxn_date_time'])) {
184 list($defaults['trxn_date'], $defaults['trxn_date_time'])
185 = CRM_Utils_Date::setDateDefaults(
186 CRM_Utils_Array::value('register_date', $defaults),
187 'activityDateTime'
188 );
189 }
190
191 if ($this->_refund) {
192 $defaults['total_amount'] = abs($this->_refund);
193 }
194
195 // Set $newCredit variable in template to control whether link to credit card mode is included
196 $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
197 return $defaults;
198 }
199
200 /**
201 * Build the form object.
202 */
203 public function buildQuickForm() {
204 if ($this->_view == 'transaction' && ($this->_action & CRM_Core_Action::BROWSE)) {
205 $this->addButtons(array(
206 array(
207 'type' => 'cancel',
208 'name' => ts('Done'),
209 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
210 'isDefault' => TRUE,
211 ),
212 )
213 );
214 return;
215 }
216
217 CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE);
218 $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialTrxn');
219
220 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL);
221 $label = ($this->_refund) ? ts('Refund Amount') : ts('Payment Amount');
222 $this->addMoney('total_amount',
223 $label,
224 FALSE,
225 $attributes['total_amount'],
226 TRUE, 'currency', NULL
227 );
228
229 $this->add('select', 'payment_instrument_id',
230 ts('Payment Method'),
231 array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
232 TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
233 );
234
235 $this->add('text', 'check_number', ts('Check Number'), $attributes['financial_trxn_check_number']);
236 $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
237
238 //add receipt for offline contribution
239 $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
240
241 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']);
242
243 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
244
245 // add various dates
246 $dateLabel = ($this->_refund) ? ts('Refund Date') : ts('Date Received');
247 $this->addDateTime('trxn_date', $dateLabel, FALSE, array('formatType' => 'activityDateTime'));
248
249 if ($this->_contactId && $this->_id) {
250 if ($this->_component == 'event') {
251 $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
252 $event = CRM_Event_BAO_Event::getEvents(0, $eventId);
253 $this->assign('eventName', $event[$eventId]);
254 }
255 }
256
257 $this->assign('displayName', $this->_contributorDisplayName);
258 $this->assign('component', $this->_component);
259 $this->assign('email', $this->_contributorEmail);
260
261 $this->add('text', 'fee_amount', ts('Fee Amount'),
262 $attributes['fee_amount']
263 );
264 $this->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
265
266 $this->add('text', 'net_amount', ts('Net Amount'),
267 $attributes['net_amount']
268 );
269 $this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
270
271 $js = NULL;
272 if (!$this->_mode) {
273 $js = array('onclick' => "return verify( );");
274 }
275
276 $buttonName = $this->_refund ? 'Record Refund' : 'Record Payment';
277 $this->addButtons(array(
278 array(
279 'type' => 'upload',
280 'name' => ts('%1', array(1 => $buttonName)),
281 'js' => $js,
282 'isDefault' => TRUE,
283 ),
284 array(
285 'type' => 'cancel',
286 'name' => ts('Cancel'),
287 ),
288 )
289 );
290 $mailingInfo = Civi::settings()->get('mailing_backend');
291 $this->assign('outBound_option', $mailingInfo['outBound_option']);
292
293 $this->addFormRule(array('CRM_Contribute_Form_AdditionalPayment', 'formRule'), $this);
294 }
295
296 /**
297 * @param $fields
298 * @param $files
299 * @param $self
300 *
301 * @return array
302 */
303 public static function formRule($fields, $files, $self) {
304 $errors = array();
305 if ($self->_paymentType == 'owed' && $fields['total_amount'] > $self->_owed) {
306 $errors['total_amount'] = ts('Payment amount cannot be greater than owed amount');
307 }
308 if ($self->_paymentType == 'refund' && $fields['total_amount'] != abs($self->_refund)) {
309 $errors['total_amount'] = ts('Refund amount must equal refund due amount.');
310 }
311 $netAmt = $fields['total_amount'] - $fields['fee_amount'];
312 if (!empty($fields['net_amount']) && $netAmt != $fields['net_amount']) {
313 $errors['net_amount'] = ts('Net amount should be equal to the difference between payment amount and fee amount.');
314 }
315 return $errors;
316 }
317
318 public function postProcess() {
319 $participantId = NULL;
320 $childTab = 'contribute';
321 if ($this->_component == 'event') {
322 $participantId = $this->_id;
323 $childTab = 'participant';
324 }
325 $submittedValues = $this->controller->exportValues($this->_name);
326 $submittedValues['confirm_email_text'] = CRM_Utils_Array::value('receipt_text', $submittedValues);
327 $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution',
328 'contribution_status_id',
329 array('labelColumn' => 'name')
330 );
331 $contributionStatusID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_contributionId, 'contribution_status_id');
332 if ($contributionStatuses[$contributionStatusID] == 'Pending') {
333 civicrm_api3('Contribution', 'create',
334 array(
335 'id' => $this->_contributionId,
336 'contribution_status_id' => array_search('Partially paid', $contributionStatuses),
337 'is_pay_later' => 0,
338 )
339 );
340 }
341 $submittedValues['trxn_date'] = CRM_Utils_Date::processDate($submittedValues['trxn_date'], $submittedValues['trxn_date_time']);
342 if ($this->_mode) {
343 // process credit card
344 $this->assign('contributeMode', 'direct');
345 $this->processCreditCard($submittedValues);
346 $submittedValues = $this->_params;
347 }
348 else {
349 $defaults = array();
350 $contribution = civicrm_api3('Contribution', 'getsingle', array(
351 'return' => array("contribution_status_id"),
352 'id' => $this->_contributionId,
353 ));
354 $contributionStatusId = CRM_Utils_Array::value('contribution_status_id', $contribution);
355 $result = CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $submittedValues, $this->_paymentType, $participantId);
356 // Fetch the contribution & do proportional line item assignment
357 $params = array('id' => $this->_contributionId);
358 $contribution = CRM_Contribute_BAO_Contribution::retrieve($params, $defaults, $params);
359 CRM_Contribute_BAO_Contribution::addPayments(array($contribution), $contributionStatusId);
360
361 // email sending
362 if (!empty($result) && !empty($submittedValues['is_email_receipt'])) {
363 $submittedValues['contact_id'] = $this->_contactId;
364 $submittedValues['contribution_id'] = $this->_contributionId;
365
366 // to get 'from email id' for send receipt
367 $this->fromEmailId = $submittedValues['from_email_address'];
368 $sendReceipt = $this->emailReceipt($submittedValues);
369 }
370
371 $statusMsg = ts('The payment record has been processed.');
372 if (!empty($submittedValues['is_email_receipt']) && $sendReceipt) {
373 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
374 }
375 CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
376
377 $session = CRM_Core_Session::singleton();
378 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
379 "reset=1&cid={$this->_contactId}&selectedChild={$childTab}"
380 ));
381 }
382 }
383
384 /**
385 * @param $submittedValues
386 */
387 public function processCreditCard($submittedValues) {
388 $config = CRM_Core_Config::singleton();
389 $session = CRM_Core_Session::singleton();
390
391 $unsetParams = array(
392 'trxn_id',
393 'payment_instrument_id',
394 'contribution_status_id',
395 );
396 foreach ($unsetParams as $key) {
397 if (isset($submittedValues[$key])) {
398 unset($submittedValues[$key]);
399 }
400 }
401
402 // Get the required fields value only.
403 $params = $this->_params = $submittedValues;
404
405 //get the payment processor id as per mode.
406 //@todo unclear relevance of mode - seems like a lot of duplicated params here!
407 $this->_params['payment_processor'] = $params['payment_processor_id']
408 = $this->_params['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor['id'];
409
410 $now = date('YmdHis');
411 $fields = array();
412
413 // we need to retrieve email address
414 if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
415 list($this->userDisplayName,
416 $this->userEmail
417 ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
418 $this->assign('displayName', $this->userDisplayName);
419 }
420
421 //set email for primary location.
422 $fields['email-Primary'] = 1;
423 $params['email-Primary'] = $this->_contributorEmail;
424
425 // now set the values for the billing location.
426 foreach ($this->_fields as $name => $dontCare) {
427 $fields[$name] = 1;
428 }
429
430 // also add location name to the array
431 $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
432 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
433 $fields["address_name-{$this->_bltID}"] = 1;
434
435 $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
436 $this->_contactId,
437 'contact_type'
438 );
439
440 $nameFields = array('first_name', 'middle_name', 'last_name');
441 foreach ($nameFields as $name) {
442 $fields[$name] = 1;
443 if (array_key_exists("billing_$name", $params)) {
444 $params[$name] = $params["billing_{$name}"];
445 $params['preserveDBName'] = TRUE;
446 }
447 }
448
449 if (!empty($params['source'])) {
450 unset($params['source']);
451 }
452 $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields,
453 $this->_contactId,
454 NULL, NULL,
455 $ctype
456 );
457
458 // Add all the additional payment params we need.
459 $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
460 $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
461
462 if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD) {
463 $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
464 $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
465 }
466 $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
467 $this->_params['amount'] = $this->_params['total_amount'];
468 // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
469 // function to get correct amount level consistently. Remove setting of the amount level in
470 // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
471 // to cover all variants.
472 $this->_params['amount_level'] = 0;
473 $this->_params['currencyID'] = CRM_Utils_Array::value('currency',
474 $this->_params,
475 $config->defaultCurrency
476 );
477
478 if (!empty($this->_params['trxn_date'])) {
479 $this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['trxn_date'], $this->_params['trxn_date_time']);
480 }
481
482 if (empty($this->_params['invoice_id'])) {
483 $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
484 }
485 else {
486 $this->_params['invoiceID'] = $this->_params['invoice_id'];
487 }
488
489 $this->assignBillingName($params);
490 $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
491 $params,
492 $this->_bltID
493 ));
494
495 $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
496 $date = CRM_Utils_Date::mysqlToIso($date);
497 $this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params));
498 $this->assign('credit_card_exp_date', $date);
499 $this->assign('credit_card_number',
500 CRM_Utils_System::mungeCreditCard($params['credit_card_number'])
501 );
502
503 //Add common data to formatted params
504 CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this);
505 // at this point we've created a contact and stored its address etc
506 // all the payment processors expect the name and address to be in the
507 // so we copy stuff over to first_name etc.
508 $paymentParams = $this->_params;
509 $paymentParams['contactID'] = $this->_contactId;
510 CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
511
512 // add some financial type details to the params list
513 // if folks need to use it
514 $paymentParams['contributionType_name'] = $this->_params['contributionType_name'] = $contributionType->name;
515 $paymentParams['contributionPageID'] = NULL;
516 if (!empty($this->_params['is_email_receipt'])) {
517 $paymentParams['email'] = $this->_contributorEmail;
518 $paymentParams['is_email_receipt'] = 1;
519 }
520 else {
521 $paymentParams['is_email_receipt'] = 0;
522 $this->_params['is_email_receipt'] = 0;
523 }
524 if (!empty($this->_params['receive_date'])) {
525 $paymentParams['receive_date'] = $this->_params['receive_date'];
526 }
527 if (!empty($this->_params['receive_date'])) {
528 $paymentParams['receive_date'] = $this->_params['receive_date'];
529 }
530
531 $result = NULL;
532
533 if ($paymentParams['amount'] > 0.0) {
534 try {
535 // force a reget of the payment processor in case the form changed it, CRM-7179
536 $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
537 $result = $payment->doPayment($paymentParams);
538 }
539 catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
540 //set the contribution mode.
541 $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}";
542 if ($this->_mode) {
543 $urlParams .= "&mode={$this->_mode}";
544 }
545 CRM_Core_Error::displaySessionError($result);
546 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/add', $urlParams));
547 }
548 }
549
550 if ($result) {
551 $this->_params = array_merge($this->_params, $result);
552 }
553
554 if (empty($this->_params['receive_date'])) {
555 $this->_params['receive_date'] = $now;
556 }
557
558 $this->set('params', $this->_params);
559
560 // set source if not set
561 if (empty($this->_params['source'])) {
562 $userID = $session->get('userID');
563 $userSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID,
564 'sort_name'
565 );
566 $this->_params['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
567 }
568 }
569
570 /**
571 * @param array $params
572 *
573 * @return mixed
574 */
575 public function emailReceipt(&$params) {
576 // email receipt sending
577 // send message template
578 if ($this->_component == 'event') {
579 $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
580
581 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
582 CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $eventId, $events, $returnProperties);
583 $event = $events[$eventId];
584 unset($event['start_date']);
585 unset($event['end_date']);
586
587 $this->assign('event', $event);
588 $this->assign('isShowLocation', $event['is_show_location']);
589 if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
590 $locationParams = array(
591 'entity_id' => $eventId,
592 'entity_table' => 'civicrm_event',
593 );
594 $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
595 $this->assign('location', $location);
596 }
597 }
598
599 // assign payment info here
600 $paymentConfig['confirm_email_text'] = CRM_Utils_Array::value('confirm_email_text', $params);
601 $this->assign('paymentConfig', $paymentConfig);
602 $isRefund = ($this->_paymentType == 'refund') ? TRUE : FALSE;
603 $this->assign('isRefund', $isRefund);
604 if ($isRefund) {
605 $this->assign('totalPaid', $this->_amtPaid);
606 $this->assign('totalAmount', $this->_amtTotal);
607 $this->assign('refundAmount', $params['total_amount']);
608 }
609 else {
610 $balance = $this->_amtTotal - ($this->_amtPaid + $params['total_amount']);
611 $paymentsComplete = ($balance == 0) ? 1 : 0;
612 $this->assign('amountOwed', $balance);
613 $this->assign('totalAmount', $this->_amtTotal);
614 $this->assign('paymentAmount', $params['total_amount']);
615 $this->assign('paymentsComplete', $paymentsComplete);
616 }
617 $this->assign('contactDisplayName', $this->_contributorDisplayName);
618
619 // assign trxn details
620 $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $params));
621 $this->assign('receive_date', CRM_Utils_Array::value('trxn_date', $params));
622 $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
623 if (array_key_exists('payment_instrument_id', $params)) {
624 $this->assign('paidBy',
625 CRM_Utils_Array::value($params['payment_instrument_id'],
626 $paymentInstrument
627 )
628 );
629 }
630 $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
631
632 $sendTemplateParams = array(
633 'groupName' => 'msg_tpl_workflow_contribution',
634 'valueName' => 'payment_or_refund_notification',
635 'contactId' => $this->_contactId,
636 'PDFFilename' => ts('notification') . '.pdf',
637 );
638
639 // try to send emails only if email id is present
640 // and the do-not-email option is not checked for that contact
641 if ($this->_contributorEmail && !$this->_toDoNotEmail) {
642 if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
643 $receiptFrom = $params['from_email_address'];
644 }
645
646 $sendTemplateParams['from'] = $receiptFrom;
647 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
648 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
649 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc', $this->_fromEmails);
650 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc', $this->_fromEmails);
651 }
652 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
653 return $mailSent;
654 }
655
656 }