Fix to avoid passing non-money to money::format
authoreileen <emcnaughton@wikimedia.org>
Tue, 30 Mar 2021 00:25:55 +0000 (13:25 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 30 Mar 2021 00:25:55 +0000 (13:25 +1300)
CRM/Report/Form/Contribute/DeferredRevenue.php
tests/phpunit/api/v3/ReportTemplateTest.php

index 1ecd40cacac47c46d07929e043144d205c373d3f..d4cbdb557b7ffe5982a70a9817071ead270db39c 100644 (file)
@@ -425,6 +425,8 @@ class CRM_Report_Form_Contribute_DeferredRevenue extends CRM_Report_Form {
    *
    * @param string $sql
    * @param array $rows
+   *
+   * @throws \CRM_Core_Exception
    */
   public function buildRows($sql, &$rows) {
     $dao = CRM_Core_DAO::executeQuery($sql);
@@ -449,7 +451,11 @@ class CRM_Report_Form_Contribute_DeferredRevenue extends CRM_Report_Form {
             $row[$key] = CRM_Utils_Date::customFormat($dao->$key, $dateFormat);
           }
           elseif (CRM_Utils_Array::value('type', $value) & CRM_Utils_Type::T_MONEY) {
-            $row[$key] = CRM_Utils_Money::format($dao->$key);
+            $values = [];
+            foreach (explode(',', $dao->$key) as $moneyValue) {
+              $values[] = CRM_Utils_Money::format($moneyValue);
+            }
+            $row[$key] = implode(',', $values);
           }
           else {
             $row[$key] = $dao->$key;
@@ -460,9 +466,9 @@ class CRM_Report_Form_Contribute_DeferredRevenue extends CRM_Report_Form {
         $rows[$arraykey]['label'] = "Deferred Revenue Account: {$dao->civicrm_financial_account_name} ({$dao->civicrm_financial_account_accounting_code}), Revenue Account: {$dao->civicrm_financial_account_1_name} {$dao->civicrm_financial_account_1_accounting_code}";
         $trxnDate = explode(',', $dao->civicrm_financial_trxn_1_trxn_date);
         $trxnAmount = explode(',', $dao->civicrm_financial_trxn_1_total_amount);
-        foreach ($trxnDate as $key => $date) {
+        foreach ($trxnDate as $trxnKey => $date) {
           $keyDate = date('M, Y', strtotime($date));
-          $rows[$arraykey]['rows'][$dao->civicrm_financial_item_id][$keyDate] = CRM_Utils_Money::format($trxnAmount[$key]);
+          $rows[$arraykey]['rows'][$dao->civicrm_financial_item_id][$keyDate] = CRM_Utils_Money::format($trxnAmount[$trxnKey]);
         }
       }
     }
index 2076fd3ee1a1dd010588da4f965f275f132d5cbb..7d1d3b7a4d312e5a0dde39e8a588423389078664 100644 (file)
@@ -119,7 +119,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
    *
    * @throws \CRM_Core_Exception
    */
-  public function testReportTemplateSelectWhere($reportID) {
+  public function testReportTemplateSelectWhere($reportID): void {
     $this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'hookSelectWhere']);
     $result = $this->callAPISuccess('report_template', 'getrows', [
       'report_id' => $reportID,
@@ -1032,8 +1032,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
    * Test Deferred Revenue Report.
    *
    * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
-  public function testDeferredRevenueReport() {
+  public function testDeferredRevenueReport(): void {
     $indv1 = $this->individualCreate();
     $indv2 = $this->individualCreate();
     Civi::settings()->set('deferred_revenue_enabled', TRUE);