CRM-9394
authoryashodha <yashodha.chaku@webaccess.co.in>
Tue, 12 Mar 2013 09:21:36 +0000 (14:51 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Tue, 12 Mar 2013 09:21:36 +0000 (14:51 +0530)
CRM/Report/Form.php
CRM/Report/Form/Contribute/Detail.php
CRM/Report/Form/Contribute/TopDonor.php
CRM/Report/Form/Pledge/Detail.php
CRM/Report/Form/Pledge/Pbnp.php
templates/CRM/Report/Form/Layout/Table.tpl
templates/CRM/Report/Form/Statistics.tpl

index 8cdda86283645cf24c162fcf59d2cdcc1ebc5b37..5e1ff8f49b0018bcb1c2c1ebc8f66315cc5026dd 100644 (file)
@@ -228,6 +228,11 @@ class CRM_Report_Form extends CRM_Core_Form {
   public $_columnHeaders = array();
   public $_orderBy = NULL;
   public $_groupBy = NULL;
+  
+  /**
+   * Variable to hold the currency alias
+   */
+  protected $_currencyColumn = NULL;
 
   /**
    *
@@ -271,6 +276,9 @@ class CRM_Report_Form extends CRM_Core_Form {
 
     // add / modify display columns, filters ..etc
     CRM_Utils_Hook::alterReportVar('columns', $this->_columns, $this);
+
+    //assign currencyColumn variable to tpl
+    $this->assign('currencyColumn', $this->_currencyColumn);
   }
 
   function preProcessCommon() {
index 5092db63166157f0e0182177aea9d1dad19685d5..1340c7588f78a699d839f9201a94a38d6764e63c 100644 (file)
@@ -181,6 +181,10 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
           ),
           'payment_instrument_id' => array('title' => ts('Payment Type'),
           ),
+          'currency' =>
+          array('required' => TRUE,
+            'no_display' => TRUE,
+          ),
           'trxn_id' => NULL,
           'receive_date' => array('default' => TRUE),
           'receipt_date' => NULL,
@@ -199,6 +203,10 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         array(
           'receive_date' =>
           array('operatorType' => CRM_Report_Form::OP_DATE),
+          'currency' =>
+          array('title' => 'Currency',
+            'operatorType' => CRM_Utils_Type::T_STRING,
+          ),
                                  'financial_type_id'   =>
                                     array( 'title'        => ts( 'Financial Type' ), 
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
@@ -322,6 +330,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
       );
       $this->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign'));
     }
+
+    $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
   }
 
@@ -467,27 +477,38 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
   function statistics(&$rows) {
     $statistics = parent::statistics($rows);
 
+    $totalAmount = $average = array();
+    $count = 0;
     $select = "
         SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as count,
                SUM( {$this->_aliases['civicrm_contribution']}.total_amount ) as amount,
-               ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as avg
+               ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as avg,
+               {$this->_aliases['civicrm_contribution']}.currency as currency
         ";
 
-    $sql = "{$select} {$this->_from} {$this->_where}";
+    $group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
+    $sql = "{$select} {$this->_from} {$this->_where} {$group}";
     $dao = CRM_Core_DAO::executeQuery($sql);
 
-    if ($dao->fetch()) {
-      $statistics['counts']['amount'] = array(
-        'value' => $dao->amount,
-        'title' => 'Total Amount',
-        'type' => CRM_Utils_Type::T_MONEY,
-      );
-      $statistics['counts']['avg'] = array(
-        'value' => $dao->avg,
-        'title' => 'Average',
-        'type' => CRM_Utils_Type::T_MONEY,
-      );
+    while ($dao->fetch()) {
+      $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")";
+      $average[] =   CRM_Utils_Money::format($dao->avg, $dao->currency);
+      $count += $dao->count;  
     }
+    $statistics['counts']['amount'] = array(
+      'title' => ts('Total Amount (Donations)'),
+      'value' => implode(',  ', $totalAmount),
+      'type' => CRM_Utils_Type::T_STRING,
+    );
+    $statistics['counts']['count'] = array(
+      'title' => ts('Total Donations'),
+      'value' => $count,
+    );
+    $statistics['counts']['avg'] = array(
+      'title' => ts('Average'),
+      'value' => implode(',  ', $average),
+      'type' => CRM_Utils_Type::T_STRING,
+    );
 
     return $statistics;
   }
index 8dd4ea062f5fd6e39f4ed9c362c5db23dbb61a80..d22af1f0d84d4a6786ba5b9b7464a7c44f2e9526 100644 (file)
@@ -83,6 +83,10 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
               'avg' => ts('Average'),
             ),
           ),
+          'currency' => 
+          array('required' => TRUE,
+             'no_display' => TRUE,
+          ),
         ),
         'filters' =>
         array(
@@ -91,6 +95,11 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
             'default' => 'this.year',
             'operatorType' => CRM_Report_Form::OP_DATE,
           ),
+          'currency' =>
+          array('title' => ts('Currency'),
+            'default' => NULL,
+            'type' => CRM_Utils_Type::T_STRING,
+          ),
           'total_range' =>
           array('title' => ts('Show no. of Top Donors'),
             'type' => CRM_Utils_Type::T_INT,
@@ -156,6 +165,7 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
     );
 
     $this->_tagFilter = TRUE;
+    $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
   }
 
@@ -300,7 +310,7 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
   }
 
   function groupBy() {
-    $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contact']}.id ";
+    $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_contribution']}.currency";
   }
 
   function postProcess() {
@@ -404,10 +414,11 @@ ORDER BY civicrm_contribution_total_amount_sum DESC
         $rows[$rowNum]['civicrm_donor_rank'] = $rank++;
         // convert display name to links
         if (array_key_exists('civicrm_contact_display_name', $row) &&
-          array_key_exists('civicrm_contact_id', $row)
+          array_key_exists('civicrm_contact_id', $row) &&
+            CRM_Utils_Array::value('civicrm_contribution_currency', $row)
         ) {
           $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
-            'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
+            'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'] . "&currency_value=" . $row['civicrm_contribution_currency'],
             $this->_absoluteUrl, $this->_id, $this->_drilldownReport
           );
           $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
index 689bf45f4ecf5e115db7d043f5a259af7e1b9fd0..a0f727b218f3c0a3ac81b3f23092c2434cb85eff 100644 (file)
@@ -94,6 +94,11 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form {
             'required' => TRUE,
             'type' => CRM_Utils_Type::T_MONEY,
           ),
+          'currency' =>
+          array(
+            'required' => TRUE,
+            'no_display' => TRUE,
+          ),
           'frequency_unit' =>
           array('title' => ts('Frequency Unit'),
           ),
@@ -127,6 +132,11 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form {
           array('title' => ts('Pledged Amount'),
             'operatorType' => CRM_Report_Form::OP_INT,
           ),
+          'currency' =>
+          array('title' => 'Currency',
+            'default' =>  NULL,
+            'type' => CRM_Utils_Type::T_STRING,
+          ),
           'sid' =>
           array(
             'name' => 'status_id',
@@ -210,7 +220,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form {
   function groupBy() {
     parent::groupBy();
     if (empty($this->_groupBy) && $this->_totalPaid) {
-      $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_pledge']}.id " ;
+      $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_pledge']}.id, {$this->_aliases['civicrm_pledge']}.currency" ;
     }
   }
   function from() {
@@ -252,31 +262,39 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form {
     $statistics = parent::statistics($rows);
 
     if (!$this->_having) {
+      $totalAmount = $average = array();
+      $count = 0;
       $select = "
             SELECT COUNT({$this->_aliases['civicrm_pledge']}.amount )       as count,
                    SUM({$this->_aliases['civicrm_pledge']}.amount )         as amount,
-                   ROUND(AVG({$this->_aliases['civicrm_pledge']}.amount), 2) as avg
+                   ROUND(AVG({$this->_aliases['civicrm_pledge']}.amount), 2) as avg,
+                   {$this->_aliases['civicrm_pledge']}.currency as currency
             ";
 
-      $sql = "{$select} {$this->_from} {$this->_where}";
+      $group = "\nGROUP BY {$this->_aliases['civicrm_pledge']}.currency";
+      $sql = "{$select} {$this->_from} {$this->_where} {$group}";
       $dao = CRM_Core_DAO::executeQuery($sql);
 
-      if ($dao->fetch()) {
-        $statistics['counts']['amount'] = array(
-          'value' => $dao->amount,
-          'title' => 'Total Pledged',
-          'type' => CRM_Utils_Type::T_MONEY,
-        );
-        $statistics['counts']['count '] = array(
-          'value' => $dao->count,
-          'title' => 'Total No Pledges',
-        );
-        $statistics['counts']['avg   '] = array(
-          'value' => $dao->avg,
-          'title' => 'Average',
-          'type' => CRM_Utils_Type::T_MONEY,
-        );
+      while ($dao->fetch()) {
+       $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")";
+       $average[] =   CRM_Utils_Money::format($dao->avg, $dao->currency);
+       $count += $dao->count; 
       }
+
+      $statistics['counts']['amount'] = array(
+        'title' => ts('Total Pledged (Number of Pledge)'),
+        'value' => implode(',  ', $totalAmount),
+        'type' => CRM_Utils_Type::T_STRING,
+      );
+      $statistics['counts']['count'] = array(
+        'title' => ts('Total No Pledges'),
+        'value' => $count,
+      );
+      $statistics['counts']['avg'] = array(
+        'title' => ts('Average'),
+        'value' => implode(',  ', $average),
+        'type' => CRM_Utils_Type::T_STRING,
+     );
     }
     return $statistics;
   }
index 2799099658bd78ed35461968d2c96af228d0e5fa..61961fcdc3ed6fa48f272cf3cd5713403cd7012d 100644 (file)
@@ -83,6 +83,11 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
             'required' => TRUE,
             'type' => CRM_Utils_Type::T_MONEY,
           ),
+          'currency' =>
+          array(
+            'required' => TRUE,
+            'no_display' => TRUE,
+          ),
           'status_id' =>
           array('title' => ts('Status'),
           ),
@@ -93,6 +98,11 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
           array(
             'title' => 'Pledge Made',
             'operatorType' => CRM_Report_Form::OP_DATE,
+          ),
+          'currency' =>
+          array('title' => 'Currency',
+             'default' =>  NULL,
+             'type' => CRM_Utils_Type::T_STRING,
           ),
                                  'financial_type_id' =>
                                  array( 'title'        =>  ts('Financial Type'),
@@ -159,6 +169,7 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
     );
 
     $this->_tagFilter = TRUE;
+    $this->_currencyColumn = 'civicrm_pledge_currency';
     parent::__construct();
   }
 
@@ -240,7 +251,8 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
   function groupBy() {
     $this->_groupBy = "
          GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id, 
-                  {$this->_aliases['civicrm_pledge']}.id";
+                  {$this->_aliases['civicrm_pledge']}.id,
+                  {$this->_aliases['civicrm_pledge']}.currency";
   }
 
   function orderBy() {
index 4e85f4b2b8dc5a4d704d19d59124f9554c9819f0..28db21d601c379b266751d578d3141598709d8f7 100644 (file)
                                 {/if}
                             {/if}
                         {elseif $header.type eq 1024}
-                            <span class="nowrap">{$row.$field|crmMoney}</span>
+                            {if $currencyColumn}
+                                <span class="nowrap">{$row.$field|crmMoney:$row.$currencyColumn}</span>
+                            {else}
+                                <span class="nowrap">{$row.$field|crmMoney}</span>
+                                                  {/if}
                         {else}
                             {$row.$field}
                         {/if}
index 534337f9e954bd5b4b3161753e8c7ffb1fd0c6e1..088dfc2972ec7a03361f873dc9da49039cca5960 100644 (file)
@@ -54,6 +54,8 @@
                 <td>
                    {if $row.type eq 1024}
                        {$row.value|crmMoney}
+                   {elseif $row.type eq 2}
+                       {$row.value}
                    {else}
                        {$row.value|crmNumberFormat}
                    {/if}
@@ -62,4 +64,4 @@
             </tr>
         {/foreach}
     </table>
-{/if}
\ No newline at end of file
+{/if}