CRM-18488 also add next_scheduled_amount
authorEileen <eileen@fuzion.co.nz>
Mon, 2 May 2016 10:50:09 +0000 (10:50 +0000)
committerEileen <eileen@fuzion.co.nz>
Mon, 2 May 2016 10:52:24 +0000 (10:52 +0000)
Note that the code previously would have been inaccurate in the rare situation where pledge payments had been
edited to the point where the ids were not in date order. I have added a fix for that, although if it would be possible to go
further & create a temp table for performance

CRM/Report/Form/Pledge/Detail.php
CRM/Report/Form/Pledge/Pbnp.php

index 0190fa10fa8871b831c382cacca1bca23c5cff26..7d4ba3b08c685c6bf254b13e2a50e92e2cd6a597 100644 (file)
@@ -54,8 +54,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form {
   );
 
   /**
-   */
-  /**
+   * Class constructor.
    */
   public function __construct() {
     $this->_pledgeStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
index 9bc182e71edcc05d20a3857fe259fafb87cb5ecf..e98b87b47806b43e96a5c681ce00b2123c87a09e 100644 (file)
@@ -149,6 +149,10 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
             'type' => CRM_Utils_Type::T_DATE,
             'required' => TRUE,
           ),
+          'scheduled_amount' => array(
+            'type' => CRM_Utils_Type::T_MONEY,
+            'title' => 'Next Payment Amount',
+          ),
         ),
         'filters' => array(
           'scheduled_date' => array(
@@ -270,7 +274,11 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
                         ON ({$this->_aliases['civicrm_pledge']}.contact_id =
                             {$this->_aliases['civicrm_contact']}.id)  AND
                             {$this->_aliases['civicrm_pledge']}.status_id IN ( {$statusIds} )
-             LEFT  JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']}
+             LEFT  JOIN ";
+
+    // Note that the derived query protects us from providing inaccurate data in the edge case where pledge
+    // payments have been edited such that they are not in id order. This might be better as a temp table.
+    $this->_from .= "(SELECT * FROM civicrm_pledge_payment ORDER BY scheduled_date) as {$this->_aliases['civicrm_pledge_payment']}
                         ON ({$this->_aliases['civicrm_pledge']}.id =
                             {$this->_aliases['civicrm_pledge_payment']}.pledge_id AND  {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) ";