Remove instances of fatal
[civicrm-core.git] / CRM / Contribute / Form / Task / Invoice.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 use Dompdf\Dompdf;
13 use Dompdf\Options;
14
15 /**
16 *
17 * @package CRM
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 */
20
21 /**
22 * This class provides the functionality to email a group of
23 * contacts.
24 */
25 class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
26 /**
27 * Are we operating in "single mode", i.e. updating the task of only
28 * one specific contribution?
29 *
30 * @var bool
31 */
32 public $_single = FALSE;
33
34 /**
35 * Gives all the statues for conribution.
36 * @var int
37 */
38 public $_contributionStatusId;
39
40 /**
41 * Gives the HTML template of PDF Invoice.
42 * @var string
43 */
44 public $_messageInvoice;
45
46 /**
47 * This variable is used to assign parameters for HTML template of PDF Invoice.
48 * @var string
49 */
50 public $_invoiceTemplate;
51
52 /**
53 * Selected output.
54 * @var string
55 */
56 public $_selectedOutput;
57
58 /**
59 * Build all the data structures needed to build the form.
60 */
61 public function preProcess() {
62 $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
63 if ($id) {
64 $this->_contributionIds = [$id];
65 $this->_componentClause = " civicrm_contribution.id IN ( $id ) ";
66 $this->_single = TRUE;
67 $this->assign('totalSelectedContributions', 1);
68
69 // set the redirection after actions
70 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
71 $url = CRM_Utils_System::url('civicrm/contact/view/contribution',
72 "action=view&reset=1&id={$id}&cid={$contactId}&context=contribution&selectedChild=contribute"
73 );
74
75 CRM_Core_Session::singleton()->pushUserContext($url);
76 }
77 else {
78 parent::preProcess();
79 }
80
81 // check that all the contribution ids have status Completed, Pending, Refunded, or Partially Paid.
82 $this->_contributionStatusId = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
83 $status = ['Completed', 'Pending', 'Refunded', 'Partially paid'];
84 $statusId = [];
85 foreach ($this->_contributionStatusId as $key => $value) {
86 if (in_array($value, $status)) {
87 $statusId[] = $key;
88 }
89 }
90 $Id = implode(",", $statusId);
91 $query = "SELECT count(*) FROM civicrm_contribution WHERE contribution_status_id NOT IN ($Id) AND {$this->_componentClause}";
92 $count = CRM_Core_DAO::singleValueQuery($query);
93 if ($count != 0) {
94 CRM_Core_Error::statusBounce(ts('Please select only contributions with Completed, Pending, Refunded, or Partially Paid status.'));
95 }
96
97 // we have all the contribution ids, so now we get the contact ids
98 parent::setContactIDs();
99 $this->assign('single', $this->_single);
100
101 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
102 $urlParams = 'force=1';
103 if (CRM_Utils_Rule::qfKey($qfKey)) {
104 $urlParams .= "&qfKey=$qfKey";
105 }
106
107 $url = CRM_Utils_System::url('civicrm/contribute/search', $urlParams);
108 $breadCrumb = [
109 [
110 'url' => $url,
111 'title' => ts('Search Results'),
112 ],
113 ];
114
115 CRM_Utils_System::appendBreadCrumb($breadCrumb);
116
117 $this->_selectedOutput = CRM_Utils_Request::retrieve('select', 'String', $this);
118 $this->assign('selectedOutput', $this->_selectedOutput);
119
120 CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
121 if ($this->_selectedOutput == 'email') {
122 CRM_Utils_System::setTitle(ts('Email Invoice'));
123 }
124 else {
125 CRM_Utils_System::setTitle(ts('Print Contribution Invoice'));
126 }
127 }
128
129 /**
130 * Build the form object.
131 */
132 public function buildQuickForm() {
133 $this->preventAjaxSubmit();
134 if (CRM_Core_Permission::check('administer CiviCRM')) {
135 $this->assign('isAdmin', 1);
136 }
137
138 $this->add('select', 'from_email_address', ts('From'), $this->_fromEmails, TRUE);
139 if ($this->_selectedOutput != 'email') {
140 $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice');
141 $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice');
142 $this->addRule('output', ts('Selection required'), 'required');
143 $this->addFormRule(['CRM_Contribute_Form_Task_Invoice', 'formRule']);
144 }
145 else {
146 $this->addRule('from_email_address', ts('From Email Address is required'), 'required');
147 }
148
149 $this->add('wysiwyg', 'email_comment', ts('If you would like to add personal message to email please add it here. (If sending to more then one receipient the same message will be sent to each contact.)'), [
150 'rows' => 2,
151 'cols' => 40,
152 ]);
153
154 $this->addButtons([
155 [
156 'type' => 'upload',
157 'name' => $this->_selectedOutput == 'email' ? ts('Send Email') : ts('Process Invoice(s)'),
158 'isDefault' => TRUE,
159 ],
160 [
161 'type' => 'cancel',
162 'name' => ts('Cancel'),
163 ],
164 ]);
165 }
166
167 /**
168 * Global validation rules for the form.
169 *
170 * @param array $values
171 *
172 * @return array
173 * list of errors to be posted back to the form
174 */
175 public static function formRule($values) {
176 $errors = [];
177
178 if ($values['output'] == 'email_invoice' && empty($values['from_email_address'])) {
179 $errors['from_email_address'] = ts("From Email Address is required");
180 }
181
182 return $errors;
183 }
184
185 /**
186 * Process the form after the input has been submitted and validated.
187 */
188 public function postProcess() {
189 $params = $this->controller->exportValues($this->_name);
190 self::printPDF($this->_contributionIds, $params, $this->_contactIds);
191 }
192
193 /**
194 * Process the PDf and email with activity and attachment on click of Print Invoices.
195 *
196 * @param array $contribIDs
197 * Contribution Id.
198 * @param array $params
199 * Associated array of submitted values.
200 * @param array $contactIds
201 * Contact Id.
202 */
203 public static function printPDF($contribIDs, &$params, $contactIds) {
204 // get all the details needed to generate a invoice
205 $messageInvoice = [];
206 $invoiceTemplate = CRM_Core_Smarty::singleton();
207 $invoiceElements = CRM_Contribute_Form_Task_PDF::getElements($contribIDs, $params, $contactIds);
208
209 // gives the status id when contribution status is 'Refunded'
210 $contributionStatusID = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
211 $refundedStatusId = CRM_Utils_Array::key('Refunded', $contributionStatusID);
212 $cancelledStatusId = CRM_Utils_Array::key('Cancelled', $contributionStatusID);
213 $pendingStatusId = CRM_Utils_Array::key('Pending', $contributionStatusID);
214
215 // getting data from admin page
216 $prefixValue = Civi::settings()->get('contribution_invoice_settings');
217
218 foreach ($invoiceElements['details'] as $contribID => $detail) {
219 $input = $ids = $objects = [];
220 if (in_array($detail['contact'], $invoiceElements['excludeContactIds'])) {
221 continue;
222 }
223
224 $input['component'] = $detail['component'];
225
226 $ids['contact'] = $detail['contact'];
227 $ids['contribution'] = $contribID;
228 $ids['contributionRecur'] = NULL;
229 $ids['contributionPage'] = NULL;
230 $ids['membership'] = CRM_Utils_Array::value('membership', $detail);
231 $ids['participant'] = CRM_Utils_Array::value('participant', $detail);
232 $ids['event'] = CRM_Utils_Array::value('event', $detail);
233
234 if (!$invoiceElements['baseIPN']->validateData($input, $ids, $objects, FALSE)) {
235 CRM_Core_Error::fatal();
236 }
237
238 $contribution = &$objects['contribution'];
239
240 $input['amount'] = $contribution->total_amount;
241 $input['invoice_id'] = $contribution->invoice_id;
242 $input['receive_date'] = $contribution->receive_date;
243 $input['contribution_status_id'] = $contribution->contribution_status_id;
244 $input['organization_name'] = $contribution->_relatedObjects['contact']->organization_name;
245
246 $objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);
247
248 // Fetch the billing address. getValues should prioritize the billing
249 // address, otherwise will return the primary address.
250 $billingAddress = [];
251
252 $addressDetails = CRM_Core_BAO_Address::getValues([
253 'contact_id' => $contribution->contact_id,
254 'is_billing' => 1,
255 ]);
256
257 if (!empty($addressDetails)) {
258 $billingAddress = array_shift($addressDetails);
259 }
260
261 if ($contribution->contribution_status_id == $refundedStatusId || $contribution->contribution_status_id == $cancelledStatusId) {
262 $creditNoteId = $contribution->creditnote_id;
263 }
264 if (!$contribution->invoice_number) {
265 $contribution->invoice_number = CRM_Contribute_BAO_Contribution::getInvoiceNumber($contribution->id);
266 }
267
268 //to obtain due date for PDF invoice
269 $contributionReceiveDate = date('F j,Y', strtotime(date($input['receive_date'])));
270 $invoiceDate = date("F j, Y");
271 $dueDate = date('F j, Y', strtotime($contributionReceiveDate . "+" . $prefixValue['due_date'] . "" . $prefixValue['due_date_period']));
272
273 $amountPaid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribID, TRUE);
274 $amountDue = ($input['amount'] - $amountPaid);
275
276 // retrieving the subtotal and sum of same tax_rate
277 $dataArray = [];
278 $subTotal = 0;
279 $lineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribID);
280 foreach ($lineItem as $taxRate) {
281 if (isset($dataArray[(string) $taxRate['tax_rate']])) {
282 $dataArray[(string) $taxRate['tax_rate']] = $dataArray[(string) $taxRate['tax_rate']] + CRM_Utils_Array::value('tax_amount', $taxRate);
283 }
284 else {
285 $dataArray[(string) $taxRate['tax_rate']] = CRM_Utils_Array::value('tax_amount', $taxRate);
286 }
287 $subTotal += CRM_Utils_Array::value('subTotal', $taxRate);
288 }
289
290 // to email the invoice
291 $mailDetails = [];
292 $values = [];
293 if ($contribution->_component == 'event') {
294 $daoName = 'CRM_Event_DAO_Event';
295 $pageId = $contribution->_relatedObjects['event']->id;
296 $mailElements = [
297 'title',
298 'confirm_from_name',
299 'confirm_from_email',
300 ];
301 CRM_Core_DAO::commonRetrieveAll($daoName, 'id', $pageId, $mailDetails, $mailElements);
302 $values['title'] = CRM_Utils_Array::value('title', $mailDetails[$contribution->_relatedObjects['event']->id]);
303 $values['confirm_from_name'] = CRM_Utils_Array::value('confirm_from_name', $mailDetails[$contribution->_relatedObjects['event']->id]);
304 $values['confirm_from_email'] = CRM_Utils_Array::value('confirm_from_email', $mailDetails[$contribution->_relatedObjects['event']->id]);
305
306 $title = CRM_Utils_Array::value('title', $mailDetails[$contribution->_relatedObjects['event']->id]);
307 }
308 elseif ($contribution->_component == 'contribute') {
309 $daoName = 'CRM_Contribute_DAO_ContributionPage';
310 $pageId = $contribution->contribution_page_id;
311 $mailElements = [
312 'title',
313 'receipt_from_name',
314 'receipt_from_email',
315 'cc_receipt',
316 'bcc_receipt',
317 ];
318 CRM_Core_DAO::commonRetrieveAll($daoName, 'id', $pageId, $mailDetails, $mailElements);
319
320 $values['title'] = CRM_Utils_Array::value('title', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
321 $values['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
322 $values['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
323 $values['cc_receipt'] = CRM_Utils_Array::value('cc_receipt', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
324 $values['bcc_receipt'] = CRM_Utils_Array::value('bcc_receipt', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
325
326 $title = CRM_Utils_Array::value('title', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
327 }
328 $source = $contribution->source;
329
330 $config = CRM_Core_Config::singleton();
331 if (!isset($params['forPage'])) {
332 $config->doNotAttachPDFReceipt = 1;
333 }
334
335 // get organization address
336 $domain = CRM_Core_BAO_Domain::getDomain();
337 $locParams = ['contact_id' => $domain->contact_id];
338 $locationDefaults = CRM_Core_BAO_Location::getValues($locParams);
339 if (isset($locationDefaults['address'][1]['state_province_id'])) {
340 $stateProvinceAbbreviationDomain = CRM_Core_PseudoConstant::stateProvinceAbbreviation($locationDefaults['address'][1]['state_province_id']);
341 }
342 else {
343 $stateProvinceAbbreviationDomain = '';
344 }
345 if (isset($locationDefaults['address'][1]['country_id'])) {
346 $countryDomain = CRM_Core_PseudoConstant::country($locationDefaults['address'][1]['country_id']);
347 }
348 else {
349 $countryDomain = '';
350 }
351
352 // parameters to be assign for template
353 $tplParams = [
354 'title' => $title,
355 'component' => $input['component'],
356 'id' => $contribution->id,
357 'source' => $source,
358 'invoice_number' => $contribution->invoice_number,
359 'invoice_id' => $contribution->invoice_id,
360 'resourceBase' => $config->userFrameworkResourceURL,
361 'defaultCurrency' => $config->defaultCurrency,
362 'amount' => $contribution->total_amount,
363 'amountDue' => $amountDue,
364 'amountPaid' => $amountPaid,
365 'invoice_date' => $invoiceDate,
366 'dueDate' => $dueDate,
367 'notes' => CRM_Utils_Array::value('notes', $prefixValue),
368 'display_name' => $contribution->_relatedObjects['contact']->display_name,
369 'lineItem' => $lineItem,
370 'dataArray' => $dataArray,
371 'refundedStatusId' => $refundedStatusId,
372 'pendingStatusId' => $pendingStatusId,
373 'cancelledStatusId' => $cancelledStatusId,
374 'contribution_status_id' => $contribution->contribution_status_id,
375 'contributionStatusName' => CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution->contribution_status_id),
376 'subTotal' => $subTotal,
377 'street_address' => CRM_Utils_Array::value('street_address', $billingAddress),
378 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', $billingAddress),
379 'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', $billingAddress),
380 'supplemental_address_3' => CRM_Utils_Array::value('supplemental_address_3', $billingAddress),
381 'city' => CRM_Utils_Array::value('city', $billingAddress),
382 'postal_code' => CRM_Utils_Array::value('postal_code', $billingAddress),
383 'state_province' => CRM_Utils_Array::value('state_province', $billingAddress),
384 'state_province_abbreviation' => CRM_Utils_Array::value('state_province_abbreviation', $billingAddress),
385 // Kept for backwards compatibility
386 'stateProvinceAbbreviation' => CRM_Utils_Array::value('state_province_abbreviation', $billingAddress),
387 'country' => CRM_Utils_Array::value('country', $billingAddress),
388 'is_pay_later' => $contribution->is_pay_later,
389 'organization_name' => $contribution->_relatedObjects['contact']->organization_name,
390 'domain_organization' => $domain->name,
391 'domain_street_address' => CRM_Utils_Array::value('street_address', CRM_Utils_Array::value('1', $locationDefaults['address'])),
392 'domain_supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', CRM_Utils_Array::value('1', $locationDefaults['address'])),
393 'domain_supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', CRM_Utils_Array::value('1', $locationDefaults['address'])),
394 'domain_supplemental_address_3' => CRM_Utils_Array::value('supplemental_address_3', CRM_Utils_Array::value('1', $locationDefaults['address'])),
395 'domain_city' => CRM_Utils_Array::value('city', CRM_Utils_Array::value('1', $locationDefaults['address'])),
396 'domain_postal_code' => CRM_Utils_Array::value('postal_code', CRM_Utils_Array::value('1', $locationDefaults['address'])),
397 'domain_state' => $stateProvinceAbbreviationDomain,
398 'domain_country' => $countryDomain,
399 'domain_email' => CRM_Utils_Array::value('email', CRM_Utils_Array::value('1', $locationDefaults['email'])),
400 'domain_phone' => CRM_Utils_Array::value('phone', CRM_Utils_Array::value('1', $locationDefaults['phone'])),
401 ];
402
403 if (isset($creditNoteId)) {
404 $tplParams['creditnote_id'] = $creditNoteId;
405 }
406
407 $pdfFileName = $contribution->invoice_number . ".pdf";
408 $sendTemplateParams = [
409 'groupName' => 'msg_tpl_workflow_contribution',
410 'valueName' => 'contribution_invoice_receipt',
411 'contactId' => $contribution->contact_id,
412 'tplParams' => $tplParams,
413 'PDFFilename' => $pdfFileName,
414 ];
415
416 // from email address
417 $fromEmailAddress = CRM_Utils_Array::value('from_email_address', $params);
418
419 // condition to check for download PDF Invoice or email Invoice
420 if ($invoiceElements['createPdf']) {
421 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
422 if (isset($params['forPage'])) {
423 return $html;
424 }
425 else {
426 $mail = [
427 'subject' => $subject,
428 'body' => $message,
429 'html' => $html,
430 ];
431 if ($mail['html']) {
432 $messageInvoice[] = $mail['html'];
433 }
434 else {
435 $messageInvoice[] = nl2br($mail['body']);
436 }
437 }
438 }
439 elseif ($contribution->_component == 'contribute') {
440 $email = CRM_Contact_BAO_Contact::getPrimaryEmail($contribution->contact_id);
441
442 $sendTemplateParams['tplParams'] = array_merge($tplParams, ['email_comment' => $invoiceElements['params']['email_comment']]);
443 $sendTemplateParams['from'] = $fromEmailAddress;
444 $sendTemplateParams['toEmail'] = $email;
445 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values);
446 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values);
447
448 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
449 // functions call for adding activity with attachment
450 $fileName = self::putFile($html, $pdfFileName);
451 self::addActivities($subject, $contribution->contact_id, $fileName, $params);
452 }
453 elseif ($contribution->_component == 'event') {
454 $email = CRM_Contact_BAO_Contact::getPrimaryEmail($contribution->contact_id);
455
456 $sendTemplateParams['tplParams'] = array_merge($tplParams, ['email_comment' => $invoiceElements['params']['email_comment']]);
457 $sendTemplateParams['from'] = $fromEmailAddress;
458 $sendTemplateParams['toEmail'] = $email;
459 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_confirm', $values);
460 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_confirm', $values);
461
462 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
463 // functions call for adding activity with attachment
464 $fileName = self::putFile($html, $pdfFileName);
465 self::addActivities($subject, $contribution->contact_id, $fileName, $params);
466 }
467 $invoiceTemplate->clearTemplateVars();
468 }
469
470 if ($invoiceElements['createPdf']) {
471 if (isset($params['forPage'])) {
472 return $html;
473 }
474 else {
475 CRM_Utils_PDF_Utils::html2pdf($messageInvoice, $pdfFileName, FALSE, [
476 'margin_top' => 10,
477 'margin_left' => 65,
478 'metric' => 'px',
479 ]);
480 // functions call for adding activity with attachment
481 $fileName = self::putFile($html, $pdfFileName);
482 self::addActivities($subject, $contactIds, $fileName, $params);
483
484 CRM_Utils_System::civiExit();
485 }
486 }
487 else {
488 if ($invoiceElements['suppressedEmails']) {
489 $status = ts('Email was NOT sent to %1 contacts (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).', [1 => $invoiceElements['suppressedEmails']]);
490 $msgTitle = ts('Email Error');
491 $msgType = 'error';
492 }
493 else {
494 $status = ts('Your mail has been sent.');
495 $msgTitle = ts('Sent');
496 $msgType = 'success';
497 }
498 CRM_Core_Session::setStatus($status, $msgTitle, $msgType);
499 }
500 }
501
502 /**
503 * Add activity for Email Invoice and the PDF Invoice.
504 *
505 * @param string $subject
506 * Activity subject.
507 * @param array $contactIds
508 * Contact Id.
509 * @param string $fileName
510 * Gives the location with name of the file.
511 * @param array $params
512 * For invoices.
513 *
514 */
515 public static function addActivities($subject, $contactIds, $fileName, $params) {
516 $session = CRM_Core_Session::singleton();
517 $userID = $session->get('userID');
518 $config = CRM_Core_Config::singleton();
519 $config->doNotAttachPDFReceipt = 1;
520
521 if (!empty($params['output']) && $params['output'] == 'pdf_invoice') {
522 $activityTypeID = CRM_Core_PseudoConstant::getKey(
523 'CRM_Activity_DAO_Activity',
524 'activity_type_id',
525 'Downloaded Invoice'
526 );
527 }
528 else {
529 $activityTypeID = CRM_Core_PseudoConstant::getKey(
530 'CRM_Activity_DAO_Activity',
531 'activity_type_id',
532 'Emailed Invoice'
533 );
534 }
535
536 $activityParams = [
537 'subject' => $subject,
538 'source_contact_id' => $userID,
539 'target_contact_id' => $contactIds,
540 'activity_type_id' => $activityTypeID,
541 'activity_date_time' => date('YmdHis'),
542 'attachFile_1' => [
543 'uri' => $fileName,
544 'type' => 'application/pdf',
545 'location' => $fileName,
546 'upload_date' => date('YmdHis'),
547 ],
548 ];
549 CRM_Activity_BAO_Activity::create($activityParams);
550 }
551
552 /**
553 * Create the Invoice file in upload folder for attachment.
554 *
555 * @param string $html
556 * Content for pdf in html format.
557 *
558 * @param string $name
559 *
560 * @return string
561 * Name of file which is in pdf format
562 */
563 public static function putFile($html, $name = 'Invoice.pdf') {
564 $options = new Options();
565 $options->set('isRemoteEnabled', TRUE);
566
567 $doc = new DOMPDF($options);
568 $doc->load_html($html);
569 $doc->render();
570 $html = $doc->output();
571 $config = CRM_Core_Config::singleton();
572 $fileName = $config->uploadDir . $name;
573 file_put_contents($fileName, $html);
574 return $fileName;
575 }
576
577 /**
578 * Callback to perform action on Print Invoice button.
579 */
580 public static function getPrintPDF() {
581 $contributionId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject, FALSE);
582 $contributionIDs = [$contributionId];
583 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE);
584 $params = ['output' => 'pdf_invoice'];
585 CRM_Contribute_Form_Task_Invoice::printPDF($contributionIDs, $params, $contactId);
586 }
587
588 }