CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Getting a printed receipt for offline Membership
Pages: [1]

Author Topic: Getting a printed receipt for offline Membership  (Read 2530 times)

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Getting a printed receipt for offline Membership
March 30, 2010, 12:32:44 pm
If we do an offline membership we can specify 'send an email receipt'. If we don't have an email address, or have other reasons to need a printed version, then we need a printed version of the information that is included in the 'email receipt'.
Has this already been cooked up by anyone?
Seems there isn't an option to 'print pfd letter' from Find Members in way that you can from Find Contributions - and I suspect that if it was there, it would miss the Contribution information that would be required.

Any suggested short cuts?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Getting a printed receipt for offline Membership
March 30, 2010, 08:24:03 pm

i just checked the contribution PDF.php which prints the contribution receipt:

CRM/Contribute/Form/Task/PDF.php

should be fairly easy to extend this to follow the same process to print a membership receipt (which is basically the membership email we send out)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Getting a printed receipt for offline Membership
April 12, 2010, 03:57:18 am
I have a patch to allow the pdf receipts to be e-mailed rather than printed if anyone wants to try/ test it.

The code below includes a patch on BaseIPN that will be included in 3.1.4.

It also changes the pdfs & e-mails to use the html templates rather than the text ones. Still on the to-do list (although maybe not straight away is changing the PDF code so that it doesn't limit you to '"Please select only online contributions with Completed status."

I Suspect the wording would be 'receipt' if $$$ have been received and 'invoice' if not?

Code: [Select]
Index: CRM/Contribute/Task.php
===================================================================
--- CRM/Contribute/Task.php (revision 27025)
+++ CRM/Contribute/Task.php (working copy)
@@ -80,7 +80,7 @@
                                   3 => ts( 'Export Contributions'   ),
                                   1 => ts( 'Delete Contributions'   ),
                                   5 => ts( 'Send Email to Contacts' ),
-                                  7 => ts( 'Print Contribution Receipts' ),
+                                  7 => ts( 'Print or email Contribution Receipts' ),
                                   6 => ts( 'Update Pending Contribution Status' ),
                                   4 => ts( 'Batch Update Contributions Via Profile' ),
                                   );
Index: CRM/Contribute/BAO/ContributionPage.php
===================================================================
--- CRM/Contribute/BAO/ContributionPage.php (revision 27025)
+++ CRM/Contribute/BAO/ContributionPage.php (working copy)
@@ -256,7 +256,8 @@
                 list ($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
                 return array( 'subject' => $subject,
                               'body'    => $message,
-                              'to'      => $displayName );
+                              'to'      => $displayName,
+                              'html'    => $html);
             }
             
             if ( $values['is_email_receipt'] ) {

Index: CRM/Contribute/Form/Task/PDF.php
===================================================================
--- CRM/Contribute/Form/Task/PDF.php    (revision 27025)
+++ CRM/Contribute/Form/Task/PDF.php    (working copy)
@@ -103,10 +103,13 @@
      */
     public function buildQuickForm()
     {
+     
+        $this->addElement('radio','output',null,'PDF receipts','PDF');
+        $this->addElement('radio','output',null,'email receipts','email');
         $this->addButtons( array(
                                  array ( 'type'      => 'next',
-                                         'name'      => ts('Download Receipt(s)'),
-                                         'isDefault' => true   ),
+                                         'name'      => ts('Generate Receipt(s)'),
+                                         'isDefault' => true   ),                             
                                  array ( 'type'      => 'back',
                                          'name'      => ts('Cancel') ),
                                  )
@@ -132,6 +135,7 @@
         $message  =  array( );
         $template =& CRM_Core_Smarty::singleton( );
 
+
         foreach ( $details as $contribID => $detail ) {
             $input = $ids = $objects = array( );
             
@@ -162,21 +166,39 @@
             $input['trxn_date']  = isset( $contribution->trxn_date ) ? $contribution->trxn_date : null;
 
             // CRM_Core_Error::debug('input',$input);
-           
+            if ($this->_submitValues['output'] == "PDF"){
+              //causes output to be returned to the function rather than the e-mail to be sent
+              // at time of writing the downstream function was either /or WRT returning text or e-mailing
+              // a nice option would be to return the text for further e-mail generation but not
+              // in scope now.
+
+              $returntext = 'true';
+            }
             $values = array( );
-            $mail = $baseIPN->sendMail( $input, $ids, $objects, $values, false, true );
-            $mail = str_replace( "\n\n", "<p>", $mail );
-            $mail = str_replace( "\n", "<br/>", $mail );
+            $mail = $baseIPN->sendMail( $input, $ids, $objects, $values, false, $returntext );
+            // commented out so e-mails / pdfs can be based on html
+            // can't think of any benefits of using the text based template but leaving in for
+            // now in case
+            // $mail = str_replace( "\n\n", "<p>", $mail[] );
+            // $mail = str_replace( "\n", "<br/>", $mail );
 
             $message[] = $mail;
+           
 
             // reset template values before processing next transactions
             $template->clearTemplateVars( );
         }
+        if ($returntext == 'true'){
+            require_once 'CRM/Utils/PDF/Utils.php';
+            CRM_Utils_PDF_Utils::domlib( $message, "civicrmContributionReceipt.pdf" );
+            exit( );
+        }else{
+             $status = array( '', ts('Your mail has been sent.') );
+             CRM_Core_Session::setStatus( $status );
         
-        require_once 'CRM/Utils/PDF/Utils.php';
-        CRM_Utils_PDF_Utils::domlib( $message, "civicrmContributionReceipt.pdf" );
-        exit( );
+        }
+
+
     }
 
 }
Index: CRM/Core/Payment/BaseIPN.php
===================================================================
--- CRM/Core/Payment/BaseIPN.php    (revision 27025)
+++ CRM/Core/Payment/BaseIPN.php    (working copy)
@@ -117,29 +117,10 @@
         $objects['contributionType'] = $contributionType;
         $paymentProcessorID          = null;
         if ( $input['component'] == 'contribute' ) {
-            // get the contribution page id from the contribution
-            // and then initialize the payment processor from it
-            if ( ! $contribution->contribution_page_id ) {
-                if ( !CRM_Utils_Array::value( 'pledge_payment', $ids ) ) {
-                // return if we are just doing an optional validation
-                if ( ! $required ) {
-                    return true;
-                }
-               
-                CRM_Core_Error::debug_log_message( "Could not find contribution page for contribution record: $contributionID" );
-                echo "Failure: Could not find contribution page for contribution record: $contributionID<p>";
-                return false;
-                }
-            }
-            //for offline pldedge we dont have contribution page.
-            if ( !CRM_Utils_Array::value( 'pledge_payment', $ids ) ) {
-                // get the payment processor id from contribution page
-                $paymentProcessorID = CRM_Core_DAO::getFieldValue( 'CRM_Contribute_DAO_ContributionPage',
-                                                                   $contribution->contribution_page_id,
-                                                                   'payment_processor_id' );
-            }
-                       
-            // now retrieve the other optional objects
+              // fetching optional objects
+              // have moved this befor the 'important' payment processor related objects
+              // as this code is also used by Contribute/Task/PDF.php to generate receipts
+              // and these should be returned also for off-line components
             if ( isset( $ids['membership'] ) ) {
                 require_once 'CRM/Member/DAO/Membership.php';
                 $membership = new CRM_Member_DAO_Membership( );
@@ -184,6 +165,30 @@
                 }
                 $objects['contributionRecur'] =& $recur;
             }
+         
+          // get the contribution page id from the contribution
+            // and then initialize the payment processor from it
+            if ( ! $contribution->contribution_page_id ) {
+                if ( !CRM_Utils_Array::value( 'pledge_payment', $ids ) ) {
+                // return if we are just doing an optional validation
+                if ( ! $required ) {
+                    return true;
+                }
+               
+                CRM_Core_Error::debug_log_message( "Could not find contribution page for contribution record: $contributionID" );
+                echo "Failure: Could not find contribution page for contribution record: $contributionID<p>";
+                return false;
+                }
+            }
+            //for offline pldedge we dont have contribution page.
+            if ( !CRM_Utils_Array::value( 'pledge_payment', $ids ) ) {
+                // get the payment processor id from contribution page
+                $paymentProcessorID = CRM_Core_DAO::getFieldValue( 'CRM_Contribute_DAO_ContributionPage',
+                                                                   $contribution->contribution_page_id,
+                                                                   'payment_processor_id' );
+            }
+                       
+
         } else {
             // we are in event mode
             // make sure event exists and is valid
@@ -532,6 +537,17 @@
                     // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id)
                     $values['is_email_receipt'] = 1;
                     $values['title']            = 'Contribution';
+                    // set receipt from e-mail to be default as there will not be one coming in from the
+                    // contribution page - could also set this to be the logged in user? Not sure which is more appropriate
+                    require_once 'CRM/Core/OptionGroup.php';
+                   if (!isset($values['receipt_from_email'])){
+                            //get the default from email address.
+                            $defaultAddress = CRM_Core_OptionGroup::values( 'from_email_address', null, null, null, ' AND is_default = 1' );
+                            preg_match('/<([^>]*)>/',    current($defaultAddress), $matches);
+                            $values['receipt_from_email'] = $matches[1];
+                            preg_match('/"([^"]*)"/',    current($defaultAddress), $matches);
+                            $values['receipt_from_name'] = $matches[1];
+                    }                 
                 }
             } else {
                 // event
@@ -771,7 +787,6 @@
                 $isTest = true;
             }
             // CRM_Core_Error::debug('val',$values);
-
             return CRM_Contribute_BAO_ContributionPage::sendMail( $ids['contact'], $values, $isTest, $returnMessageText );
         }
     }
Index: CRM/Utils/PDF/Utils.php
===================================================================
--- CRM/Utils/PDF/Utils.php (revision 27025)
+++ CRM/Utils/PDF/Utils.php (working copy)
         
@@ -58,19 +58,49 @@
 </style>
 ";
 
+
+
+
+   
+$htmlElementstoStrip = array(
+                        '@<head[^>]*?>.*?</head>@siu',
+                        '@<body>@siu',
+                        '@</body>@siu',
+                        '@</html>@siu',
+                        '@<!DOCTYPE[^>]*?>@siu',
+                        );
+$htmlElementsInstead = array("","","","","");                     
+
         foreach ( $values as $value ) {
+          $value['html'] = preg_replace
+            ($htmlElementstoStrip,$htmlElementsInstead,$value['html']
+            );
+
             if ( ! $first ) {
                 $html .= "<h2 class=\"page_break\">{$value['to']}: {$value['subject']}</h2><p>";
             } else {
                 $html .= "<h2>{$value['to']}: {$value['subject']}</h2><p>";
                 $first = false;
             }
-            $html .= "{$value['body']}\n";
+            if ($value['html']){
+             
+                $html .= "{$value['html']}\n";             
+            } else{
+                $html .= "{$value['body']}\n";
+            }
         }
+
+ /*        if ($text[0]['html']){
+          $html = $text[0]['html'];
+        }
+   */     
+
+//  echo $html;
         $dompdf->load_html( $html );
         $dompdf->render( );
         $dompdf->stream( $fileName );
-    }
+echo $html;
+                            }
 
     static function html2pdf( $text,
                               $fileName = 'civicrm.pdf',
Index: templates/CRM/Contribute/Form/Task/PDF.tpl
===================================================================
--- templates/CRM/Contribute/Form/Task/PDF.tpl  (revision 26715)
+++ templates/CRM/Contribute/Form/Task/PDF.tpl  (working copy)
@@ -33,10 +33,14 @@
   </dl>
 </div>
 <div id="help">
-    {ts}A PDF file containing one receipt per page will be downloaded to your local computer when you click <strong>Download Receipt(s)</strong>.
+    {ts}If you choose to PDF the receipts A PDF file containing one receipt per page will be downloaded to your local computer when you click <strong>Download Receipt(s)</strong>.
     Your browser may display the file for you automatically, or you may need to open it for printing using any PDF reader (such as Adobe&reg; Reader).{/ts}
 </div>
+
+  {$form.output.PDF.html}
+  {$form.output.email.html}
 <div class="spacer"></div>
 <div class="form-item">
+
  {$form.buttons.html}
 </div>
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Getting a printed receipt for offline Membership
April 12, 2010, 02:15:57 pm
I have created an issue for this

http://issues.civicrm.org/jira/browse/CRM-6089

Appreciate if anyone wants to try it.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Getting a printed receipt for offline Membership

This forum was archived on 2017-11-26.