function cdntaxreceipts_civicrm_buildForm($formName, &$form) { if (is_a($form, 'CRM_Contribute_Form_ContributionView')) { // add "Issue Tax Receipt" button to the "View Contribution" page // if the Tax Receipt has NOT yet been issued -> display a white maple leaf icon // if the Tax Receipt has already been issued -> display a red maple leaf icon CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.cdntaxreceipts', 'css/civicrm_cdntaxreceipts.css'); $contributionId = $form->get('id'); $buttons = array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE)); $subName = 'view_tax_receipt'; if (isset($contributionId) && cdntaxreceipts_eligibleForReceipt($contributionId)) { list($issued_on, $receipt_id) = cdntaxreceipts_issued_on($contributionId); $is_original_receipt = empty($issued_on); if ($is_original_receipt) { $subName = 'issue_tax_receipt'; } $buttons[] = array('type' => 'submit', 'subName' => $subName, 'name' => ts('Tax Receipt', array('domain' => 'org.civicrm.cdntaxreceipts')), 'isDefault' => FALSE); $form->addButtons($buttons); } } }
/** * process the form after the input has been submitted and validated * * @access public * * @return None */ function postProcess() { // lets get around the time limit issue if possible if (!ini_get('safe_mode')) { set_time_limit(0); } // Issue 1895204: Turn off geocoding to avoid hitting Google API limits $config =& CRM_Core_Config::singleton(); $oldGeocode = $config->geocodeMethod; unset($config->geocodeMethod); $params = $this->controller->exportValues($this->_name); $originalOnly = FALSE; if ($params['receipt_option'] == 'original_only') { $originalOnly = TRUE; } $previewMode = FALSE; if (isset($params['is_preview']) && $params['is_preview'] == 1) { $previewMode = TRUE; } /** * Drupal module include */ //module_load_include('.inc','civicrm_cdntaxreceipts','civicrm_cdntaxreceipts'); //module_load_include('.module','civicrm_cdntaxreceipts','civicrm_cdntaxreceipts'); // start a PDF to collect receipts that cannot be emailed $receiptsForPrinting = cdntaxreceipts_openCollectedPDF(); $emailCount = 0; $printCount = 0; $failCount = 0; foreach ($this->_contributionIds as $item => $contributionId) { if ($emailCount + $printCount + $failCount >= self::MAX_RECEIPT_COUNT) { $status = ts('Maximum of %1 tax receipt(s) were sent. Please repeat to continue processing.', array(1 => self::MAX_RECEIPT_COUNT, 'domain' => 'org.civicrm.cdntaxreceipts')); CRM_Core_Session::setStatus($status, '', 'info'); break; } // 1. Load Contribution information $contribution = new CRM_Contribute_DAO_Contribution(); $contribution->id = $contributionId; if (!$contribution->find(TRUE)) { CRM_Core_Error::fatal("CDNTaxReceipts: Could not find corresponding contribution id."); } // 2. If Contribution is eligible for receipting, issue the tax receipt. Otherwise ignore. if (cdntaxreceipts_eligibleForReceipt($contribution->id)) { list($issued_on, $receipt_id) = cdntaxreceipts_issued_on($contribution->id); if (empty($issued_on) || !$originalOnly) { list($ret, $method) = cdntaxreceipts_issueTaxReceipt($contribution, $receiptsForPrinting, $previewMode); if ($ret == 0) { $failCount++; } elseif ($method == 'email') { $emailCount++; } else { $printCount++; } } } } // 3. Set session status if ($previewMode) { $status = ts('%1 tax receipt(s) have been previewed. No receipts have been issued.', array(1 => $printCount, 'domain' => 'org.civicrm.cdntaxreceipts')); CRM_Core_Session::setStatus($status, '', 'success'); } else { $status = ts('%1 tax receipt(s) were sent by email.', array(1 => $emailCount, 'domain' => 'org.civicrm.cdntaxreceipts')); CRM_Core_Session::setStatus($status, '', 'success'); $status = ts('%1 tax receipt(s) need to be printed.', array(1 => $printCount, 'domain' => 'org.civicrm.cdntaxreceipts')); CRM_Core_Session::setStatus($status, '', 'success'); } if ($failCount > 0) { $status = ts('%1 tax receipt(s) failed to process.', array(1 => $failCount, 'domain' => 'org.civicrm.cdntaxreceipts')); CRM_Core_Session::setStatus($status, '', 'error'); } // Issue 1895204: Reset geocoding $config->geocodeMethod = $oldGeocode; // 4. send the collected PDF for download // NB: This exits if a file is sent. cdntaxreceipts_sendCollectedPDF($receiptsForPrinting, 'Receipts-To-Print-' . (int) $_SERVER['REQUEST_TIME'] . '.pdf'); // EXITS. }
function createTempEligibilityTable() { $sql = "\nCREATE TEMPORARY TABLE cdntaxreceipts_temp_civireport_eligible (\n contribution_id int unsigned,\n eligible_amount decimal(20,2)\n) ENGINE=HEAP DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; CRM_Core_DAO::executeQuery($sql); $this->from(FALSE); $this->where(FALSE); $sql = "SELECT {$this->_aliases['civicrm_contribution']}.id {$this->_from} {$this->_where}"; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { if (cdntaxreceipts_eligibleForReceipt($dao->id)) { $amount = cdntaxreceipts_eligibleAmount($dao->id); $sql = "INSERT INTO cdntaxreceipts_temp_civireport_eligible (contribution_id,eligible_amount)\n VALUES ({$dao->id}, {$amount})"; CRM_Core_DAO::executeQuery($sql); } } }
/** * process the form after the input has been submitted and validated * * @access public * * @return None */ function postProcess() { // ensure the user has permission to issue the tax receipt. if (!CRM_Core_Permission::check('issue cdn tax receipts')) { CRM_Core_Error::fatal(ts('You do not have permission to access this page', array('domain' => 'org.civicrm.cdntaxreceipts'))); } // load the contribution $contributionId = $this->get('contribution_id'); $contactId = $this->get('contact_id'); $contribution = new CRM_Contribute_DAO_Contribution(); $contribution->id = $contributionId; if (!$contribution->find(TRUE)) { CRM_Core_Error::fatal("CDNTaxReceipts: Could not retrieve details for this contribution"); } // issue tax receipt, or report error if ineligible if (!cdntaxreceipts_eligibleForReceipt($contribution->id)) { $statusMsg = ts('This contribution is not tax deductible and/or not completed. No receipt has been issued.', array('domain' => 'org.civicrm.cdntaxreceipts')); CRM_Core_Session::setStatus($statusMsg); } else { list($result, $method, $pdf) = cdntaxreceipts_issueTaxReceipt($contribution); if ($result == TRUE) { if ($method == 'email') { $statusMsg = ts('Tax Receipt has been emailed to the contributor.', array('domain' => 'org.civicrm.cdntaxreceipts')); } else { $statusMsg = ts('Tax Receipt has been generated for printing.', array('domain' => 'org.civicrm.cdntaxreceipts')); } CRM_Core_Session::setStatus($statusMsg); } else { $statusMsg = ts('Encountered an error. Tax receipt has not been issued.', array('domain' => 'org.civicrm.cdntaxreceipts')); CRM_Core_Session::setStatus($statusMsg); unset($pdf); } } // refresh the form, with file stored in session if we need it. $urlParams = array('reset=1', 'cid=' . $contactId, 'id=' . $contributionId); if ($method == 'print' && isset($pdf)) { $session = CRM_Core_Session::singleton(); $session->set("pdf_file_" . $contributionId . "_" . $contactId, $pdf, 'cdntaxreceipts'); $urlParams[] = 'file=1'; } $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), implode('&', $urlParams)); CRM_Utils_System::redirect($url); }