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 CiviReport (Moderator: Dave Greenberg) »
  • Pledge report extra fields - custom fields & accounts info
Pages: [1]

Author Topic: Pledge report extra fields - custom fields & accounts info  (Read 1009 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Pledge report extra fields - custom fields & accounts info
November 11, 2010, 04:25:25 pm
Just quickly recording how I customised the Pledge Summary for a customer - this patch adds custom fields to the pledge summary report and also makes accounting code, is_taxable, & Contribution_type available as columns

Unfortunately it looks like I made a mess of the formatting so it's not a pretty patch. Also, I didn't figure out how to only include the left join on civicrm_contribution_type when required (but it IS a really small table)



Code: [Select]
Index: CRM/Report/Form/Pledge/Summary.php
===================================================================
--- CRM/Report/Form/Pledge/Summary.php (revision 30659)
+++ CRM/Report/Form/Pledge/Summary.php (working copy)
@@ -40,7 +40,8 @@
 
     protected $_summary = null;
     protected $_totalPaid = false;
-   
+    protected $_customGroupExtends = array( 'Pledge' );
+    protected $_customGroupGroupBy = true;
     function __construct( ) {
         $this->_columns =
             array(
@@ -130,37 +131,58 @@
                               'pledge_create_date' =>
                               array( 'title'        => 'Pledge Made Date',
                                      'operatorType' => CRM_Report_Form::OP_DATE ),
-                              'pledge_amount'  =>
+                              'pledge_amount'  =>
                               array( 'title'        => ts( 'Pledged Amount' ),
-                                     'operatorType' => CRM_Report_Form::OP_INT ),
+                                     'operatorType' => CRM_Report_Form::OP_INT ),
                               'sid'    =>
                               array( 'name'    => 'status_id',
                                      'title'   => ts( 'Pledge Status' ),
                                      'operatorType' => CRM_Report_Form::OP_MULTISELECT ,
-                                     'options' => CRM_Core_OptionGroup::values('contribution_status') ), ),
-                        ),
+                                     'options' => CRM_Core_OptionGroup::values('contribution_status') ), ),
+                          'grouping'=> 'pledge-fields',
+                              ),
 
-                  'civicrm_group' =>
+                  'civicrm_contribution_type' =>
+                  array( 'dao'    => 'CRM_Contribute_DAO_ContributionType',
+                         'fields' =>
+                         array( 'name' =>
+                                array( 'title' => ts('Contribution_type'),
+                                ),
+                                'accounting_code' =>
+                                array( 'title' => ts('Accounting Code'),
+                                ),
+                                'is_deductible' =>
+                                array( 'title' => ts('Tax Deductible'),
+                                )
+
+                          ),
+                                'grouping'=> 'pledge-fields',
+                          ),
+
+
+
+
+                  'civicrm_group' =>
                   array( 'dao'    => 'CRM_Contact_DAO_Group',
                          'alias'  => 'cgroup',
-                         'filters' =>             
-                         array( 'gid' =>
+                         'filters' =>
+                         array( 'gid' =>
                                 array( 'name'    => 'group_id',
                                        'title'   => ts( ' Group' ),
                                        'operatorType' => CRM_Report_Form::OP_MULTISELECT,
                                        'group'   => true,
                                        'options' => CRM_Core_PseudoConstant::group( ) ) ), ),
-                 
+
                   );
 
         $this->_tagFilter = true;
         parent::__construct( );
     }
-   
+
     function preProcess( ) {
-        parent::preProcess( );           
+        parent::preProcess( );
     }
-   
+
     function select( ) {
         $select = array( );
         $this->_columnHeaders = array( );
@@ -174,15 +196,15 @@
                             $this->_totalPaid = true;
                             unset( $this->_params['fields']['total_paid'] );
                         }
-                       
+
                         // to include optional columns address and email, only if checked
                         if ( $tableName == 'civicrm_address' ) {
                             $this->_addressField = true;
-                            $this->_emailField = true;
-                        } else if ( $tableName == 'civicrm_email' ) {
-                            $this->_emailField = true; 
+                            $this->_emailField = true;
+                        } else if ( $tableName == 'civicrm_email' ) {
+                            $this->_emailField = true;
                         }
-                       
+
                         $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
                         $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value( 'type', $field );
                         $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value( 'title', $field );
@@ -190,35 +212,39 @@
                 }
             }
         }
-       
+
         $this->_select = "SELECT DISTINCT " . implode( ', ', $select );
     }
-   
+
     function from( ) {
         $this->_from = "
             FROM civicrm_pledge {$this->_aliases['civicrm_pledge']}
-                 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
-                      ON ({$this->_aliases['civicrm_contact']}.id =
+            LEFT JOIN civicrm_contribution_type {$this->_aliases['civicrm_contribution_type']}
+                      ON  ({$this->_aliases['civicrm_pledge']}.contribution_type_id =
+                          {$this->_aliases['civicrm_contribution_type']}.id)
+                 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
+                      ON ({$this->_aliases['civicrm_contact']}.id =
                           {$this->_aliases['civicrm_pledge']}.contact_id )
                  {$this->_aclFrom} ";
 
         // include address field if address column is to be included
-        if ( $this->_addressField ) { 
+        if ( $this->_addressField ) {
             $this->_from .= "
-                 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
-                           ON ({$this->_aliases['civicrm_contact']}.id =
+                 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
+                           ON ({$this->_aliases['civicrm_contact']}.id =
                                {$this->_aliases['civicrm_address']}.contact_id) AND
                                {$this->_aliases['civicrm_address']}.is_primary = 1\n";
         }
-       
+
         // include email field if email column is to be included
-        if ( $this->_emailField ) {
+        if ( $this->_emailField ) {
             $this->_from .= "
-                 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
-                           ON ({$this->_aliases['civicrm_contact']}.id =
-                               {$this->_aliases['civicrm_email']}.contact_id) AND
-                               {$this->_aliases['civicrm_email']}.is_primary = 1\n";     
+                 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
+                           ON ({$this->_aliases['civicrm_contact']}.id =
+                               {$this->_aliases['civicrm_email']}.contact_id) AND
+                               {$this->_aliases['civicrm_email']}.is_primary = 1\n";
         }
+
     }
 
     function where( ) {
@@ -231,17 +257,17 @@
                         $relative = CRM_Utils_Array::value( "{$fieldName}_relative", $this->_params );
                         $from     = CRM_Utils_Array::value( "{$fieldName}_from"    , $this->_params );
                         $to       = CRM_Utils_Array::value( "{$fieldName}_to"      , $this->_params );
-                       
+
                         if ( $relative || $from || $to ) {
                             $clause = $this->dateClause( $field['name'], $relative, $from, $to, $field['type'] );
                         }
                     } else {
                         $op = CRM_Utils_Array::value( "{$fieldName}_op", $this->_params );
                         if ( $op ) {
-                            $clause =
+                            $clause =
                                 $this->whereClause( $field,
                                                     $op,
-                                                    CRM_Utils_Array::value( "{$fieldName}_value",
+                                                    CRM_Utils_Array::value( "{$fieldName}_value",
                                                                             $this->_params ),
                                                     CRM_Utils_Array::value( "{$fieldName}_min",
                                                                             $this->_params ),
@@ -249,48 +275,49 @@
                                                                             $this->_params ) );
                         }
                     }
-                   
+
                     if ( ! empty( $clause ) ) {
                         $clauses[] = $clause;
                     }
                 }
             }
-        }   
+        }
         if ( empty( $clauses ) ) {
             $this->_where = "WHERE ({$this->_aliases['civicrm_pledge']}.is_test=0 ) ";
         } else {
-            $this->_where = "WHERE  ({$this->_aliases['civicrm_pledge']}.is_test=0 )  AND
+            $this->_where = "WHERE  ({$this->_aliases['civicrm_pledge']}.is_test=0 )  AND
                                       " . implode( ' AND ', $clauses );
         }
 
         if ( $this->_aclWhere ) {
             $this->_where .= " AND {$this->_aclWhere} ";
-        }
+        }
     }
-     
+
     function postProcess( ) {
-       
+
         $this->beginPostProcess( );
 
         // get the acl clauses built before we assemble the query
         $this->buildACLClause( $this->_aliases['civicrm_contact'] );
         $this->select ( );
         $this->from   ( null, true );
-        $this->where  ( );
-        $this->limit( ); 
-       
+        $this->customDataFrom( );
+        $this->where  ( );
+        $this->limit( );
+
         $sql   = "{$this->_select} {$this->_from} {$this->_where} {$this->_limit}";
-       
+
         $rows  = $payment = array();
         $count = $due = $paid = 0;
-       
+
         $dao   = CRM_Core_DAO::executeQuery( $sql );
 
         // Set pager for the Main Query only which displays basic information
         $this->setPager( );
         $this->assign ( 'columnHeaders', $this->_columnHeaders );
-       
-        while( $dao->fetch() ){
+
+        while( $dao->fetch() ){
             $pledgeID  = $dao->civicrm_pledge_id;
             foreach ( $this->_columnHeaders as $columnHeadersKey => $columnHeadersValue ) {
                 $row = array();
@@ -300,23 +327,23 @@
             }
             $pledgeIDArray[] = $pledgeID;
         }
-       
-        // Pledge- Payment Detail Headers
-        $tableHeader = array( 'scheduled_date'  => array ( 'type'  => CRM_Utils_Type::T_DATE ,
+
+        // Pledge- Payment Detail Headers
+        $tableHeader = array( 'scheduled_date'  => array ( 'type'  => CRM_Utils_Type::T_DATE ,
                                                            'title' => 'Next Payment Due'),
-                              'scheduled_amount'=> array ( 'type'  => CRM_Utils_Type::T_MONEY ,
-                                                           'title' => 'Next Payment Amount'), 
-                              'total_paid'      => array ( 'type'  => CRM_Utils_Type::T_MONEY ,
+                              'scheduled_amount'=> array ( 'type'  => CRM_Utils_Type::T_MONEY ,
+                                                           'title' => 'Next Payment Amount'),
+                              'total_paid'      => array ( 'type'  => CRM_Utils_Type::T_MONEY ,
                                                            'title' => 'Total Amount Paid'),
-                              'balance_due'     => array ( 'type'  => CRM_Utils_Type::T_MONEY ,
-                                                           'title' => 'Balance Due') ,
+                              'balance_due'     => array ( 'type'  => CRM_Utils_Type::T_MONEY ,
+                                                           'title' => 'Balance Due') ,
                               'status_id'       => null,
                               );
         foreach ( $tableHeader as $k => $val ) {
             $this->_columnHeaders[$k] = $val;
         }
 
-        if ( !$this->_totalPaid ){
+        if ( !$this->_totalPaid ){
             unset( $this->_columnHeaders['total_paid'] );
         }
 
@@ -325,87 +352,87 @@
         if ( !empty( $display ) ){
             $sqlPayment = "
                  SELECT min(payment.scheduled_date) as scheduled_date,
-                        payment.pledge_id,
-                        payment.scheduled_amount,
+                        payment.pledge_id,
+                        payment.scheduled_amount,
                         pledge.contact_id
-             
-                  FROM civicrm_pledge_payment payment
-                       LEFT JOIN civicrm_pledge pledge
+
+                  FROM civicrm_pledge_payment payment
+                       LEFT JOIN civicrm_pledge pledge
                                  ON pledge.id = payment.pledge_id
-                     
-                  WHERE payment.status_id = 2 
 
+                  WHERE payment.status_id = 2
+
                   GROUP BY payment.pledge_id";
-           
+
             $daoPayment = CRM_Core_DAO::executeQuery( $sqlPayment );
-           
+
             while ( $daoPayment->fetch() ) {
                 foreach ( $pledgeIDArray as $key => $val ) {
                     if ( $val == $daoPayment->pledge_id ) {
 
-                        $display[$daoPayment->pledge_id]['scheduled_date']   =
+                        $display[$daoPayment->pledge_id]['scheduled_date']   =
                             $daoPayment->scheduled_date;
 
-                        $display[$daoPayment->pledge_id]['scheduled_amount'] =
+                        $display[$daoPayment->pledge_id]['scheduled_amount'] =
                             $daoPayment->scheduled_amount;
                     }
                 }
             }
-         
+
             // Do calculations for Total amount paid AND
-            // Balance Due, based on Pledge Status either
+            // Balance Due, based on Pledge Status either
             // In Progress, Pending or Completed
             foreach ( $display as $pledgeID => $data ) {
                 $count = $due = $paid = 0;
 
                 // Get Sum of all the payments made
                 $payDetailsSQL = "
-                    SELECT SUM( payment.actual_amount ) as total_amount
-                       FROM civicrm_pledge_payment payment
+                    SELECT SUM( payment.actual_amount ) as total_amount
+                       FROM civicrm_pledge_payment payment
                        WHERE payment.pledge_id = {$pledgeID} AND
                              payment.status_id = 1";
-               
+
                 $totalPaidAmt = CRM_Core_DAO::singleValueQuery( $payDetailsSQL );
-               
+
                 if ( CRM_Utils_Array::value( 'civicrm_pledge_status_id', $data ) == 5 ) {
                     $due  = $data['civicrm_pledge_amount'] - $totalPaidAmt;
                     $paid = $totalPaidAmt;
-                    $count++;
+                    $count++;
                 } else if ( CRM_Utils_Array::value( 'civicrm_pledge_status_id', $data ) == 2 ) {
-                    $due  = $data['civicrm_pledge_amount'];
+                    $due  = $data['civicrm_pledge_amount'];
                     $paid = 0;
                 } else if ( CRM_Utils_Array::value( 'civicrm_pledge_status_id', $data ) == 1 ) {
                     $due  = 0;
                     $paid = $paid + $data['civicrm_pledge_amount'];
                 }
-               
+
                 $display[$pledgeID]['total_paid' ] = $paid;
                 $display[$pledgeID]['balance_due'] = $due;
             }
         }
-               
+
         // Displaying entire data on the form
         if( ! empty( $display ) ) {
-            foreach( $display as $key => $value ) {               
-                $row = array( ); 
+            foreach( $display as $key => $value ) {
+                $row = array( );
                 foreach ( $this->_columnHeaders as $columnKey => $columnValue ) {
                     if ( CRM_Utils_Array::value( $columnKey, $value ) ) {
                         $row[ $columnKey ] = $value [ $columnKey ];
                     }
-                }
+                }
                 $rows[ ] = $row;
-            }     
+            }
         }
-       
+
         unset($this->_columnHeaders['status_id']);
         unset($this->_columnHeaders['civicrm_pledge_id']);
         unset($this->_columnHeaders['civicrm_pledge_contact_id']);
-               
+
         $this->formatDisplay( $rows, false);
         $this->doTemplateAssignment( $rows );
         $this->endPostProcess( $rows );
     }
-   
+
     function alterDisplay( &$rows ) {
         // custom code to alter rows
         $entryFound = false;
@@ -428,7 +455,7 @@
                                 $prev_cid = $cid;
                             }
                         }
-                       
+
                         if ( $display_flag ) {
                             foreach ( $row as $colName => $colVal ) {
                                 if ( in_array($colName, $this->_noRepeats) ) {
@@ -442,10 +469,10 @@
             }
             
             // convert display name to links
-            if ( array_key_exists('civicrm_contact_display_name', $row) &&
+            if ( array_key_exists('civicrm_contact_display_name', $row) &&
                  array_key_exists('civicrm_pledge_contact_id', $row) ) {
-                $url = CRM_Utils_System::url( "civicrm/contact/view"  ,
-                                              'reset=1&cid=' . $row['civicrm_pledge_contact_id'],
+                $url = CRM_Utils_System::url( "civicrm/contact/view"  ,
+                                              'reset=1&cid=' . $row['civicrm_pledge_contact_id'],
                                               $this->_absoluteUrl );
                 $rows[$rowNum]['civicrm_contact_display_name_link' ] = $url;
                 $rows[$rowNum]['civicrm_contact_display_name_hover'] = 


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 CiviReport (Moderator: Dave Greenberg) »
  • Pledge report extra fields - custom fields & accounts info

This forum was archived on 2017-11-26.