Пример #1
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     //check for permission to view contributions
     if (!CRM_Core_Permission::check('access CiviContribute')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     parent::preProcess();
     $contributionId = CRM_Utils_Array::value('id', $_GET);
     $contactId = CRM_Utils_Array::value('cid', $_GET);
     if (isset($contributionId) && isset($contactId)) {
         $this->set('contribution_id', $contributionId);
         $this->set('contact_id', $contactId);
     } else {
         $contributionId = $this->get('contribution_id');
         $contactId = $this->get('contact_id');
     }
     // might be callback to retrieve the downloadable PDF file
     $download = CRM_Utils_Array::value('download', $_GET);
     if ($download == 1) {
         $this->sendFile($contributionId, $contactId);
         // exits
     }
     list($issuedOn, $receiptId) = cdntaxreceipts_issued_on($contributionId);
     if (isset($receiptId)) {
         $existingReceipt = cdntaxreceipts_load_receipt($receiptId);
         $this->_reissue = 1;
         $this->_receipt = $existingReceipt;
     } else {
         $this->_reissue = 0;
     }
     list($method, $email) = cdntaxreceipts_sendMethodForContact($contactId);
     $this->_method = $method;
     if ($method == 'email') {
         $this->_sendTarget = $email;
     }
     // may need to offer a PDF file for download, if returning from form submission.
     // this sets up the form with proper JS to download the file, it doesn't actually send the file.
     // see ?download=1 for sending the file.
     $pdfDownload = CRM_Utils_Array::value('file', $_GET);
     if ($pdfDownload == 1) {
         $this->_pdfFile = 1;
     }
 }
Пример #2
0
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.
 }