CRM-12595 fix formatting in CRM/Upgrade files
[civicrm-core.git] / CRM / Report / Form / Contribute / Bookkeeping.php
index e017ec3584f47bca590017800c43bec5bd36ece4..858e9d0bd104e4a834e24c1682ce87cd6e3f594a 100644 (file)
@@ -95,14 +95,12 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
             'name'  => 'accounting_code',
             'alias' => 'financial_account_civireport_debit',
             'default' => TRUE,
-            'required' => TRUE,
           ),
           'credit_accounting_code' => array(
             'title' => ts('Financial Account Code - Credit'),
             'name'  => 'accounting_code',
             'alias' => 'financial_account_civireport_credit',
             'default' => TRUE,
-            'required' => TRUE,
           ),
           'debit_name' => array(
             'title' => ts('Financial Account Name - Debit'),
@@ -201,6 +199,10 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
           'payment_instrument_id' => array('title' => ts('Payment Instrument'),
             'default' => TRUE,
           ),
+          'currency' => array(
+             'required' => TRUE,
+             'no_display' => TRUE,
+          ), 
           'trxn_date' => array(
             'title' => ts('Transaction Date'),
             'default' => TRUE,
@@ -218,6 +220,13 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Contribute_PseudoConstant::paymentInstrument(),
           ),
+          'currency' => array(
+             'title' => 'Currency',
+             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+             'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
+             'default' => NULL,
+             'type' => CRM_Utils_Type::T_STRING,
+          ),
           'trxn_date' => array( 
             'title' => ts('Transaction Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
@@ -231,6 +240,7 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
           'amount' => array(
             'title' => ts('Amount'),
             'default' => TRUE,
+            'type' => CRM_Utils_Type::T_STRING,
           ),
         ),
         'filters' =>
@@ -290,7 +300,7 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
       }
     }
 
-    $this->_select = "SELECT " . implode(', ', $select) . " ";
+    $this->_select = 'SELECT ' . implode(', ', $select) . ' ';
   }
 
   function from() {
@@ -372,10 +382,10 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
       }
     }
     if (empty($clauses)) {
-      $this->_where = "WHERE ( 1 )";
+      $this->_where = 'WHERE ( 1 )';
     }
     else {
-      $this->_where = "WHERE " . implode(' AND ', $clauses);
+      $this->_where = 'WHERE ' . implode(' AND ', $clauses);
     }
   }
 
@@ -389,28 +399,34 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
     $statistics = parent::statistics($rows);
 
     $select = " SELECT COUNT({$this->_aliases['civicrm_financial_trxn']}.id ) as count,
+                {$this->_aliases['civicrm_contribution']}.currency,
                 SUM(CASE 
                   WHEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id IS NOT NULL
                   THEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.amount
                   ELSE {$this->_aliases['civicrm_entity_financial_trxn']}.amount
-                END) as amount ";
+                END) as amount 
+";
+
+    $sql = "{$select} {$this->_from} {$this->_where} 
+            GROUP BY {$this->_aliases['civicrm_contribution']}.currency
+";
 
-    $sql = "{$select} {$this->_from} {$this->_where}";
     $dao = CRM_Core_DAO::executeQuery($sql);
-    $dao->fetch();
-    if ($dao->count) {
-      $statistics['counts']['amount'] = array(
-        'value' => $dao->amount,
-        'title' => 'Total Amount',
-        'type' => CRM_Utils_Type::T_MONEY,
-      );
-      $statistics['counts']['avg'] = array(
-        'value' => round(($dao->amount / $dao->count), 2),
-        'title' => 'Average',
-        'type' => CRM_Utils_Type::T_MONEY,
-      );
+    while ($dao->fetch()) {
+      $amount[] = CRM_Utils_Money::format($dao->amount, $dao->currency);
+      $avg[] =  CRM_Utils_Money::format(round(($dao->amount / $dao->count), 2), $dao->currency);
     }
 
+    $statistics['counts']['amount'] = array(
+       'value' => implode(', ', $amount),
+       'title' => 'Total Amount',
+       'type' => CRM_Utils_Type::T_STRING,
+    );
+    $statistics['counts']['avg'] = array(
+      'value' => implode(', ', $avg),
+      'title' => 'Average',
+      'type' => CRM_Utils_Type::T_STRING,
+    );
     return $statistics;
   }
 
@@ -424,12 +440,12 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
         CRM_Utils_Array::value('civicrm_contact_sort_name', $rows[$rowNum]) &&
         array_key_exists('civicrm_contact_id', $row)
       ) {
-        $url = CRM_Utils_System::url("civicrm/contact/view",
+        $url = CRM_Utils_System::url('civicrm/contact/view',
           'reset=1&cid=' . $row['civicrm_contact_id'],
           $this->_absoluteUrl
         );
         $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
-        $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
+        $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Summary for this Contact.');
       }
 
       // handle contribution status id
@@ -446,6 +462,9 @@ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
       if ($value = CRM_Utils_Array::value('civicrm_line_item_financial_type_id', $row)) {
         $rows[$rowNum]['civicrm_line_item_financial_type_id'] = $contributionTypes[$value];
       }
+      if ($value = CRM_Utils_Array::value('civicrm_entity_financial_trxn_amount', $row)) {
+        $rows[$rowNum]['civicrm_entity_financial_trxn_amount'] = CRM_Utils_Money::format($rows[$rowNum]['civicrm_entity_financial_trxn_amount'],$rows[$rowNum]['civicrm_financial_trxn_currency']);
+      }
     }
   }
 }