From 7a961f1955452380007b6fa77a95943c25255192 Mon Sep 17 00:00:00 2001 From: yashodha Date: Tue, 12 Mar 2013 14:51:36 +0530 Subject: [PATCH] CRM-9394 --- CRM/Report/Form.php | 8 ++++ CRM/Report/Form/Contribute/Detail.php | 47 +++++++++++++------ CRM/Report/Form/Contribute/TopDonor.php | 17 +++++-- CRM/Report/Form/Pledge/Detail.php | 54 ++++++++++++++-------- CRM/Report/Form/Pledge/Pbnp.php | 14 +++++- templates/CRM/Report/Form/Layout/Table.tpl | 6 ++- templates/CRM/Report/Form/Statistics.tpl | 4 +- 7 files changed, 113 insertions(+), 37 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 8cdda86283..5e1ff8f49b 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -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() { diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 5092db6316..1340c7588f 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -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; } diff --git a/CRM/Report/Form/Contribute/TopDonor.php b/CRM/Report/Form/Contribute/TopDonor.php index 8dd4ea062f..d22af1f0d8 100644 --- a/CRM/Report/Form/Contribute/TopDonor.php +++ b/CRM/Report/Form/Contribute/TopDonor.php @@ -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'] . "¤cy_value=" . $row['civicrm_contribution_currency'], $this->_absoluteUrl, $this->_id, $this->_drilldownReport ); $rows[$rowNum]['civicrm_contact_display_name_link'] = $url; diff --git a/CRM/Report/Form/Pledge/Detail.php b/CRM/Report/Form/Pledge/Detail.php index 689bf45f4e..a0f727b218 100644 --- a/CRM/Report/Form/Pledge/Detail.php +++ b/CRM/Report/Form/Pledge/Detail.php @@ -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; } diff --git a/CRM/Report/Form/Pledge/Pbnp.php b/CRM/Report/Form/Pledge/Pbnp.php index 2799099658..61961fcdc3 100644 --- a/CRM/Report/Form/Pledge/Pbnp.php +++ b/CRM/Report/Form/Pledge/Pbnp.php @@ -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() { diff --git a/templates/CRM/Report/Form/Layout/Table.tpl b/templates/CRM/Report/Form/Layout/Table.tpl index 4e85f4b2b8..28db21d601 100644 --- a/templates/CRM/Report/Form/Layout/Table.tpl +++ b/templates/CRM/Report/Form/Layout/Table.tpl @@ -119,7 +119,11 @@ {/if} {/if} {elseif $header.type eq 1024} - {$row.$field|crmMoney} + {if $currencyColumn} + {$row.$field|crmMoney:$row.$currencyColumn} + {else} + {$row.$field|crmMoney} + {/if} {else} {$row.$field} {/if} diff --git a/templates/CRM/Report/Form/Statistics.tpl b/templates/CRM/Report/Form/Statistics.tpl index 534337f9e9..088dfc2972 100644 --- a/templates/CRM/Report/Form/Statistics.tpl +++ b/templates/CRM/Report/Form/Statistics.tpl @@ -54,6 +54,8 @@ {if $row.type eq 1024} {$row.value|crmMoney} + {elseif $row.type eq 2} + {$row.value} {else} {$row.value|crmNumberFormat} {/if} @@ -62,4 +64,4 @@ {/foreach} -{/if} \ No newline at end of file +{/if} -- 2.25.1