Merge pull request #11728 from JMAConsulting/CRM-21809
[civicrm-core.git] / CRM / Batch / BAO / Batch.php
index 378d13f3c529fa6bd0ebc7d33e3cd7900a7bf172..f7ec3dce4f9f21e4e830a14e518bd6af43f262bb 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2017
+ * @copyright CiviCRM LLC (c) 2004-2018
  */
 
 /**
@@ -202,7 +202,8 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
       $batch['item_count'] = CRM_Utils_Array::value('item_count', $value);
       $batch['type'] = CRM_Utils_Array::value('batch_type', $value);
       if (!empty($value['total'])) {
-        $batch['total'] = CRM_Utils_Money::format($value['total']);
+        // CRM-21205
+        $batch['total'] = CRM_Utils_Money::format($value['total'], $value['currency']);
       }
 
       // Compare totals with actuals
@@ -344,6 +345,17 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
         'Batch',
         $values['id']
       );
+      // CRM-21205
+      $values['currency'] = CRM_Core_DAO::singleValueQuery("
+        SELECT GROUP_CONCAT(DISTINCT ft.currency)
+        FROM  civicrm_batch batch
+        JOIN civicrm_entity_batch eb
+          ON batch.id = eb.batch_id
+        JOIN civicrm_financial_trxn ft
+          ON eb.entity_id = ft.id
+        WHERE batch.id = %1
+        GROUP BY batch.id
+      ", array(1 => array($values['id'], 'Positive')));
       $results[$values['id']] = $values;
     }
 
@@ -582,8 +594,10 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
    *   Associated array of batch ids.
    * @param string $exportFormat
    *   Export format.
+   * @param bool $downloadFile
+   *   Download export file?.
    */
-  public static function exportFinancialBatch($batchIds, $exportFormat) {
+  public static function exportFinancialBatch($batchIds, $exportFormat, $downloadFile) {
     if (empty($batchIds)) {
       CRM_Core_Error::fatal(ts('No batches were selected.'));
       return;
@@ -603,6 +617,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
       CRM_Core_Error::fatal("Could not locate exporter: $exporterClass");
     }
     $export = array();
+    $exporter->_isDownloadFile = $downloadFile;
     foreach ($batchIds as $batchId) {
       // export only batches whose status is set to Exported.
       $result = civicrm_api3('Batch', 'getcount', array(