3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
36 * This class provides the functionality to email a group of
39 class CRM_Contribute_Form_Task_Invoice
extends CRM_Contribute_Form_Task
{
41 * Are we operating in "single mode", i.e. updating the task of only
42 * one specific contribution?
46 public $_single = FALSE;
49 * gives all the statues for conribution
53 public $_contributionStatusId;
56 * gives the HTML template of PDF Invoice
60 public $_messageInvoice;
63 * This variable is used to assign parameters for HTML template of PDF Invoice
67 public $_invoiceTemplate;
72 public $_selectedOutput;
75 * build all the data structures needed to build the form
80 function preProcess() {
81 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
83 $this->_contributionIds
= array($id);
84 $this->_componentClause
= " civicrm_contribution.id IN ( $id ) ";
85 $this->_single
= TRUE;
86 $this->assign('totalSelectedContributions', 1);
88 // set the redirection after actions
89 $contactId = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE);
90 $url = CRM_Utils_System
::url('civicrm/contact/view/contribution',
91 "action=view&reset=1&id={$id}&cid={$contactId}&context=contribution&selectedChild=contribute"
94 CRM_Core_Session
::singleton()->pushUserContext($url);
100 // check that all the contribution ids have status Completed, Pending, Refunded.
101 $this->_contributionStatusId
= CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
102 $status = array('Completed', 'Pending', 'Refunded');
104 foreach ($this->_contributionStatusId
as $key => $value) {
105 if (in_array($value, $status)) {
109 $Id = implode(",", $statusId);
110 $query = "SELECT count(*) FROM civicrm_contribution WHERE contribution_status_id NOT IN ($Id) AND {$this->_componentClause}";
111 $count = CRM_Core_DAO
::singleValueQuery($query);
113 CRM_Core_Error
::statusBounce(ts('Please select only contributions with Completed, Pending, Refunded status.'));
116 // we have all the contribution ids, so now we get the contact ids
117 parent
::setContactIDs();
118 $this->assign('single', $this->_single
);
120 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this);
121 $urlParams = 'force=1';
122 if (CRM_Utils_Rule
::qfKey($qfKey)) {
123 $urlParams .= "&qfKey=$qfKey";
126 $url = CRM_Utils_System
::url('civicrm/contribute/search', $urlParams);
130 'title' => ts('Search Results'),
134 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
136 $this->_selectedOutput
= CRM_Utils_Request
::retrieve('select', 'String', $this);
137 $this->assign('selectedOutput', $this->_selectedOutput
);
139 if ($this->_selectedOutput
== 'email') {
140 CRM_Utils_System
::setTitle(ts('Email Invoice'));
143 CRM_Utils_System
::setTitle(ts('Print Contribution Invoice'));
154 public function buildQuickForm() {
155 $session = CRM_Core_Session
::singleton();
156 if (CRM_Core_Permission
::check('administer CiviCRM')) {
157 $this->assign('isAdmin', 1);
159 $contactID = $session->get('userID');
160 $contactEmails = CRM_Core_BAO_Email
::allEmails($contactID);
162 $fromDisplayName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
163 $contactID, 'display_name'
165 foreach ($contactEmails as $emailId => $item) {
166 $email = $item['email'];
168 $emails[$emailId] = '"' . $fromDisplayName . '" <' . $email . '> ';
170 if (isset($emails[$emailId])) {
171 $emails[$emailId] .= $item['locationType'];
172 if ($item['is_primary']) {
173 $emails[$emailId] .= ' ' . ts('(preferred)');
175 $emails[$emailId] = htmlspecialchars($emails[$emailId]);
178 $fromEmailAddress = CRM_Core_OptionGroup
::values('from_email_address');
179 foreach ($fromEmailAddress as $key => $email) {
180 $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]);
182 $fromEmail = CRM_Utils_Array
::crmArrayMerge($emails, $fromEmailAddress);
183 $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') +
$fromEmail);
184 if ($this->_selectedOutput
!= 'email') {
185 $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice');
186 $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice');
187 $this->addRule('output', ts('Selection required'), 'required');
188 $this->addFormRule(array('CRM_Contribute_Form_Task_Invoice', 'formRule'));
191 $this->addRule('from_email_address', ts('From Email Address is required'), 'required');
194 $this->addWysiwyg('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.)'), array(
199 if ($this->_selectedOutput
== 'email') {
200 $this->addButtons(array(
203 'name' => ts('Email Invoice'),
208 'name' => ts('Cancel'),
214 $this->addButtons(array(
217 'name' => ts('Process Invoice(s)'),
222 'name' => ts('Cancel'),
230 * global validation rules for the form
234 * @internal param array $fields posted values of the form
236 * @return array list of errors to be posted back to the form
240 static function formRule($values) {
243 if ($values['output'] == 'email_invoice' && empty($values['from_email_address'])) {
244 $errors['from_email_address'] = ts("From Email Address is required");
251 * process the form after the input has been submitted and validated
257 public function postProcess() {
258 $params = $this->controller
->exportValues($this->_name
);
259 $this->printPDF($this->_contributionIds
, $params, $this->_contactIds
, $this);
264 * process the PDf and email with activity and attachment
265 * on click of Print Invoices
267 * @param array $contribIDs Contribution Id
268 * @param array $params associated array of submitted values
269 * @param array $contactIds Contact Id
270 * @param object $form form object
274 static function printPDF($contribIDs, &$params, $contactIds, &$form) {
275 // get all the details needed to generate a invoice
276 $messageInvoice = array();
277 $invoiceTemplate = CRM_Core_Smarty
::singleton();
278 $invoiceElements = CRM_Contribute_Form_Task_PDF
::getElements($contribIDs, $params, $contactIds);
280 // gives the status id when contribution status is 'Refunded'
281 $contributionStatusID = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
282 $refundedStatusId = CRM_Utils_Array
::key('Refunded', $contributionStatusID);
284 // getting data from admin page
285 $prefixValue = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
287 foreach ($invoiceElements['details'] as $contribID => $detail) {
288 $input = $ids = $objects = array();
289 if (in_array($detail['contact'], $invoiceElements['excludeContactIds'])) {
293 $input['component'] = $detail['component'];
295 $ids['contact'] = $detail['contact'];
296 $ids['contribution'] = $contribID;
297 $ids['contributionRecur'] = NULL;
298 $ids['contributionPage'] = NULL;
299 $ids['membership'] = CRM_Utils_Array
::value('membership', $detail);
300 $ids['participant'] = CRM_Utils_Array
::value('participant', $detail);
301 $ids['event'] = CRM_Utils_Array
::value('event', $detail);
303 if (!$invoiceElements['baseIPN']->validateData($input, $ids, $objects, FALSE)) {
304 CRM_Core_Error
::fatal();
307 $contribution = & $objects['contribution'];
309 $input['amount'] = $contribution->total_amount
;
310 $input['invoice_id'] = $contribution->invoice_id
;
311 $input['receive_date'] = $contribution->receive_date
;
312 $input['contribution_status_id'] = $contribution->contribution_status_id
;
313 $input['organization_name'] = $contribution->_relatedObjects
['contact']->organization_name
;
315 $objects['contribution']->receive_date
= CRM_Utils_Date
::isoToMysql($objects['contribution']->receive_date
);
317 $addressParams = array('contact_id' => $contribution->contact_id
);
318 $addressDetails = CRM_Core_BAO_Address
::getValues($addressParams);
320 // to get billing address if present
321 $billingAddress = array();
322 foreach ($addressDetails as $key => $address) {
323 if ((isset($address['is_billing']) && $address['is_billing'] == 1) && (isset($address['is_primary']) && $address['is_primary'] == 1) && $address['contact_id'] == $contribution->contact_id
) {
324 $billingAddress[$address['contact_id']] = $address;
327 elseif (($address['is_billing'] == 0 && $address['is_primary'] == 1) ||
(isset($address['is_billing']) && $address['is_billing'] == 1) && $address['contact_id'] == $contribution->contact_id
) {
328 $billingAddress[$address['contact_id']] = $address;
332 if (!empty($billingAddress[$contribution->contact_id
]['state_province_id'])) {
333 $stateProvinceAbbreviation = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($billingAddress[$contribution->contact_id
]['state_province_id']);
336 $stateProvinceAbbreviation = '';
339 if ($contribution->contribution_status_id
== $refundedStatusId) {
340 $creditNoteId = CRM_Utils_Array
::value('credit_notes_prefix', $prefixValue) . "" . $contribution->id
;
342 $invoiceId = CRM_Utils_Array
::value('invoice_prefix', $prefixValue) . "" . $contribution->id
;
344 //to obtain due date for PDF invoice
345 $contributionReceiveDate = date('F j,Y', strtotime(date($input['receive_date'])));
346 $invoiceDate = date("F j, Y");
347 $dueDate = date('F j ,Y', strtotime($contributionReceiveDate . "+" . $prefixValue['due_date'] . "" . $prefixValue['due_date_period']));
349 if ($input['component'] == 'contribute') {
351 $etable = 'contribution';
352 $lineItem = CRM_Price_BAO_LineItem
::getLineItems($eid, $etable, NULL, TRUE, TRUE);
355 $eid = $contribution->_relatedObjects
['participant']->id
;
356 $etable = 'participant';
357 $lineItem = CRM_Price_BAO_LineItem
::getLineItems($eid, $etable);
360 //TO DO: Need to do changes for partially paid to display amount due on PDF invoice
361 $amountDue = ($input['amount'] - $input['amount']);
363 // retreiving the subtotal and sum of same tax_rate
364 $dataArray = array();
366 foreach ($lineItem as $entity_id => $taxRate) {
367 if (isset($dataArray[(string) $taxRate['tax_rate']])) {
368 $dataArray[(string) $taxRate['tax_rate']] = $dataArray[(string) $taxRate['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $taxRate);
371 $dataArray[(string) $taxRate['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $taxRate);
373 $subTotal +
= CRM_Utils_Array
::value('subTotal', $taxRate);
376 // to email the invoice
377 $mailDetails = array();
379 if ($contribution->_component
== 'event') {
380 $daoName = 'CRM_Event_DAO_Event';
381 $pageId = $contribution->_relatedObjects
['event']->id
;
382 $mailElements = array(
385 'confirm_from_email',
389 CRM_Core_DAO
::commonRetrieveAll($daoName, 'id', $pageId, $mailDetails, $mailElements);
390 $values['title'] = CRM_Utils_Array
::value('title', $mailDetails[$contribution->_relatedObjects
['event']->id
]);
391 $values['confirm_from_name'] = CRM_Utils_Array
::value('confirm_from_name', $mailDetails[$contribution->_relatedObjects
['event']->id
]);
392 $values['confirm_from_email'] = CRM_Utils_Array
::value('confirm_from_email', $mailDetails[$contribution->_relatedObjects
['event']->id
]);
393 $values['cc_confirm'] = CRM_Utils_Array
::value('cc_confirm', $mailDetails[$contribution->_relatedObjects
['event']->id
]);
394 $values['bcc_confirm'] = CRM_Utils_Array
::value('bcc_confirm', $mailDetails[$contribution->_relatedObjects
['event']->id
]);
396 $title = CRM_Utils_Array
::value('title', $mailDetails[$contribution->_relatedObjects
['event']->id
]);
398 elseif ($contribution->_component
== 'contribute') {
399 $daoName = 'CRM_Contribute_DAO_ContributionPage';
400 $pageId = $contribution->contribution_page_id
;
401 $mailElements = array(
404 'receipt_from_email',
408 CRM_Core_DAO
::commonRetrieveAll($daoName, 'id', $pageId, $mailDetails, $mailElements);
410 $values['title'] = CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($contribution->contribution_page_id
, $mailDetails));
411 $values['receipt_from_name'] = CRM_Utils_Array
::value('receipt_from_name', CRM_Utils_Array
::value($contribution->contribution_page_id
, $mailDetails));
412 $values['receipt_from_email'] = CRM_Utils_Array
::value('receipt_from_email', CRM_Utils_Array
::value($contribution->contribution_page_id
, $mailDetails));
413 $values['cc_receipt'] = CRM_Utils_Array
::value('cc_receipt', CRM_Utils_Array
::value($contribution->contribution_page_id
, $mailDetails));
414 $values['bcc_receipt'] = CRM_Utils_Array
::value('bcc_receipt', CRM_Utils_Array
::value($contribution->contribution_page_id
, $mailDetails));
416 $title = CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($contribution->contribution_page_id
, $mailDetails));
418 $source = $contribution->source
;
420 $config = CRM_Core_Config
::singleton();
421 if (!isset($params['forPage'])) {
422 $config->doNotAttachPDFReceipt
= 1;
425 // get organization address
426 $domain = CRM_Core_BAO_Domain
::getDomain();
427 $locParams = array('contact_id' => $domain->id
);
428 $locationDefaults = CRM_Core_BAO_Location
::getValues($locParams);
429 if (isset($locationDefaults['address'][1]['state_province_id'])) {
430 $stateProvinceAbbreviationDomain = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($locationDefaults['address'][1]['state_province_id']);
433 $stateProvinceAbbreviationDomain = '';
435 if (isset($locationDefaults['address'][1]['country_id'])) {
436 $countryDomain = CRM_Core_PseudoConstant
::country($locationDefaults['address'][1]['country_id']);
442 // parameters to be assign for template
445 'component' => $input['component'],
446 'id' => $contribution->id
,
448 'invoice_id' => $invoiceId,
449 'resourceBase' => $config->userFrameworkResourceURL
,
450 'defaultCurrency' => $config->defaultCurrency
,
451 'amount' => $contribution->total_amount
,
452 'amountDue' => $amountDue,
453 'invoice_date' => $invoiceDate,
454 'dueDate' => $dueDate,
455 'notes' => CRM_Utils_Array
::value('notes', $prefixValue),
456 'display_name' => $contribution->_relatedObjects
['contact']->display_name
,
457 'lineItem' => $lineItem,
458 'dataArray' => $dataArray,
459 'refundedStatusId' => $refundedStatusId,
460 'contribution_status_id' => $contribution->contribution_status_id
,
461 'subTotal' => $subTotal,
462 'street_address' => CRM_Utils_Array
::value('street_address', CRM_Utils_Array
::value($contribution->contact_id
, $billingAddress)),
463 'supplemental_address_1' => CRM_Utils_Array
::value('supplemental_address_1', CRM_Utils_Array
::value($contribution->contact_id
, $billingAddress)),
464 'supplemental_address_2' => CRM_Utils_Array
::value('supplemental_address_2', CRM_Utils_Array
::value($contribution->contact_id
, $billingAddress)),
465 'city' => CRM_Utils_Array
::value('city', CRM_Utils_Array
::value($contribution->contact_id
, $billingAddress)),
466 'stateProvinceAbbreviation' => $stateProvinceAbbreviation,
467 'postal_code' => CRM_Utils_Array
::value('postal_code', CRM_Utils_Array
::value($contribution->contact_id
, $billingAddress)),
468 'is_pay_later' => $contribution->is_pay_later
,
469 'organization_name' => $contribution->_relatedObjects
['contact']->organization_name
,
470 'domain_organization' => $domain->name
,
471 'domain_street_address' => CRM_Utils_Array
::value('street_address', CRM_Utils_Array
::value('1', $locationDefaults['address'])),
472 'domain_supplemental_address_1' => CRM_Utils_Array
::value('supplemental_address_1', CRM_Utils_Array
::value('1', $locationDefaults['address'])),
473 'domain_supplemental_address_2' => CRM_Utils_Array
::value('supplemental_address_2', CRM_Utils_Array
::value('1', $locationDefaults['address'])),
474 'domain_city' => CRM_Utils_Array
::value('city', CRM_Utils_Array
::value('1', $locationDefaults['address'])),
475 'domain_postal_code' => CRM_Utils_Array
::value('postal_code', CRM_Utils_Array
::value('1', $locationDefaults['address'])),
476 'domain_state' => $stateProvinceAbbreviationDomain,
477 'domain_country' => $countryDomain,
478 'domain_email' => CRM_Utils_Array
::value('email', CRM_Utils_Array
::value('1', $locationDefaults['email'])),
479 'domain_phone' => CRM_Utils_Array
::value('phone', CRM_Utils_Array
::value('1', $locationDefaults['phone'])),
482 if (isset($creditNoteId)) {
483 $tplParams['creditnote_id'] = $creditNoteId;
486 $sendTemplateParams = array(
487 'groupName' => 'msg_tpl_workflow_contribution',
488 'valueName' => 'contribution_invoice_receipt',
489 'contactId' => $contribution->contact_id
,
490 'tplParams' => $tplParams,
491 'PDFFilename' => 'Invoice.pdf',
493 $session = CRM_Core_Session
::singleton();
494 $contactID = $session->get('userID');
495 $contactEmails = CRM_Core_BAO_Email
::allEmails($contactID);
497 $fromDisplayName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
498 $contactID, 'display_name'
501 foreach ($contactEmails as $emailId => $item) {
502 $email = $item['email'];
504 $emails[$emailId] = '"' . $fromDisplayName . '" <' . $email . '> ';
507 $fromEmail = CRM_Utils_Array
::crmArrayMerge($emails, CRM_Core_OptionGroup
::values('from_email_address'));
509 // from email address
510 if (isset($params['from_email_address'])) {
511 $fromEmailAddress = CRM_Utils_Array
::value($params['from_email_address'], $fromEmail);
513 // condition to check for download PDF Invoice or email Invoice
514 if ($invoiceElements['createPdf']) {
515 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
516 if (isset($params['forPage'])) {
521 'subject' => $subject,
526 $messageInvoice[] = $mail['html'];
529 $messageInvoice[] = nl2br($mail['body']);
533 elseif ($contribution->_component
== 'contribute') {
534 $email = CRM_Contact_BAO_Contact
::getPrimaryEmail($contribution->contact_id
);
536 $sendTemplateParams['tplParams'] = array_merge($tplParams, array('email_comment' => $invoiceElements['params']['email_comment']));
537 $sendTemplateParams['from'] = $fromEmailAddress;
538 $sendTemplateParams['toEmail'] = $email;
539 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
540 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
542 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
543 // functions call for adding activity with attachment
544 $fileName = self
::putFile($html);
545 self
::addActivities($subject, $contribution->contact_id
, $fileName, $params);
547 elseif ($contribution->_component
== 'event') {
548 $email = CRM_Contact_BAO_Contact
::getPrimaryEmail($contribution->contact_id
);
550 $sendTemplateParams['tplParams'] = array_merge($tplParams, array('email_comment' => $invoiceElements['params']['email_comment']));
551 $sendTemplateParams['from'] = $fromEmailAddress;
552 $sendTemplateParams['toEmail'] = $email;
553 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_confirm', $values);
554 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_confirm', $values);
556 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
557 // functions call for adding activity with attachment
558 $fileName = self
::putFile($html);
559 self
::addActivities($subject, $contribution->contact_id
, $fileName, $params);
562 CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id
, 'invoice_id', $invoiceId);
563 if ($contribution->contribution_status_id
== $refundedStatusId) {
564 CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id
, 'creditnote_id', $creditNoteId);
566 $invoiceTemplate->clearTemplateVars();
569 if ($invoiceElements['createPdf']) {
570 if (isset($params['forPage'])) {
574 CRM_Utils_PDF_Utils
::html2pdf($messageInvoice, 'Invoice.pdf', FALSE, array(
579 // functions call for adding activity with attachment
580 $fileName = self
::putFile($html);
581 self
::addActivities($subject, $contactIds, $fileName, $params);
583 CRM_Utils_System
::civiExit();
587 if ($invoiceElements['suppressedEmails']) {
588 $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).', array(1 => $invoiceElements['suppressedEmails']));
589 $msgTitle = ts('Email Error');
593 $status = ts('Your mail has been sent.');
594 $msgTitle = ts('Sent');
595 $msgType = 'success';
597 CRM_Core_Session
::setStatus($status, $msgTitle, $msgType);
603 * This function is use for adding activity for
604 * Email Invoice and the PDF Invoice
606 * @param string $subject Activity subject
607 * @param array $contactIds Contact Id
608 * @param string $fileName gives the location with name of the file
609 * @param array $params for invoices
614 static public function addActivities($subject, $contactIds, $fileName, $params) {
615 $session = CRM_Core_Session
::singleton();
616 $userID = $session->get('userID');
617 $config = CRM_Core_Config
::singleton();
618 $config->doNotAttachPDFReceipt
= 1;
620 if (!empty($params['output']) && $params['output'] == 'pdf_invoice') {
621 $activityTypeID = CRM_Core_OptionGroup
::getValue('activity_type',
622 'Downloaded Invoice',
627 $activityTypeID = CRM_Core_OptionGroup
::getValue('activity_type',
633 $activityParams = array(
634 'subject' => $subject,
635 'source_contact_id' => $userID,
636 'target_contact_id' => $contactIds,
637 'activity_type_id' => $activityTypeID,
638 'activity_date_time' => date('YmdHis'),
639 'attachFile_1' => array(
641 'type' => 'application/pdf',
642 'location' => $fileName,
643 'upload_date' => date('YmdHis'),
646 CRM_Activity_BAO_Activity
::create($activityParams);
651 * This function is use for creating the Invoice file in upload folder
654 * @param $html content for pdf in html format
656 * return $fileName of file which is in pdf format
660 static public function putFile($html) {
661 require_once("packages/dompdf/dompdf_config.inc.php");
662 spl_autoload_register('DOMPDF_autoload');
664 $doc->load_html($html);
666 $html = $doc->output();
667 $config = CRM_Core_Config
::singleton();
668 $fileName = $config->uploadDir
. 'Invoice.pdf';
669 file_put_contents($fileName, $html);
674 * Callback to perform action on Print Invoice button.
676 static function getPrintPDF() {
677 $contributionId = CRM_Utils_Request
::retrieve('id', 'Positive', CRM_Core_DAO
::$_nullObject, FALSE);
678 $contributionIDs = array($contributionId);
679 $contactId = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullObject, FALSE);
680 $params = array('output' => 'pdf_invoice');
681 CRM_Contribute_Form_Task_Invoice
::printPDF($contributionIDs, $params, $contactId, CRM_Core_DAO
::$_nullObject);