dev/financial#166 Clean up money formatting in iif
authoreileen <emcnaughton@wikimedia.org>
Fri, 19 Feb 2021 07:02:10 +0000 (20:02 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 19 Feb 2021 07:05:48 +0000 (20:05 +1300)
This does not turn out to be necessary but I tested & it works & is more correct

CRM/Financial/BAO/ExportFormat/IIF.php

index 349fa5339828a62e4dbb435afc1dc15dee51d756..bd0f13c8fa127fbfb7cf4da9c0e91b1dca2d4384 100644 (file)
@@ -195,7 +195,7 @@ class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat
             'trxn_date' => $this->format($dao->trxn_date, 'date'),
             'trxn_id' => $this->format($dao->trxn_id),
             'account_name' => $this->format($dao->to_account_name),
-            'amount' => $this->format($dao->debit_total_amount, 'money'),
+            'amount' => $this->formatMoney($dao->debit_total_amount),
             'contact_name' => $this->format($dao->contact_to_name),
             'payment_instrument' => $this->format($dao->payment_instrument),
             'check_number' => $this->format($dao->check_number),
@@ -262,7 +262,7 @@ class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat
               'trxn_date' => $this->format($itemDAO->transaction_date, 'date'),
               'spl_id' => $this->format($itemDAO->financial_item_id),
               'account_name' => $this->format($itemDAO->account_name),
-              'amount' => '-' . $this->format($itemDAO->amount, 'money'),
+              'amount' => '-' . $this->formatMoney($itemDAO->amount),
               'contact_name' => $this->format($itemDAO->contact_name),
               'payment_instrument' => $this->format($itemDAO->payment_instrument),
               'description' => $this->format($itemDAO->description),
@@ -277,7 +277,7 @@ class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat
             'trxn_date' => $this->format($dao->trxn_date, 'date'),
             'spl_id' => $this->format($dao->financial_trxn_id),
             'account_name' => $this->format($dao->from_account_name),
-            'amount' => '-' . $this->format($dao->debit_total_amount, 'money'),
+            'amount' => '-' . $this->formatMoney($dao->debit_total_amount),
             'contact_name' => $this->format($dao->contact_from_name),
             'description' => $this->format($dao->item_description),
             'payment_instrument' => $this->format($dao->payment_instrument),
@@ -329,6 +329,17 @@ class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat
     return 'CRM/Financial/ExportFormat/IIF.tpl';
   }
 
+  /**
+   * Format money.
+   *
+   * @param float $amount
+   *
+   * @return mixed|string
+   */
+  public function formatMoney($amount) {
+    return CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency(trim($amount));
+  }
+
   /**
    * @param string $s
    *   the input string
@@ -350,10 +361,6 @@ class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat
         $sout = CRM_Utils_Date::customFormat($s1, $dateFormat);
         break;
 
-      case 'money':
-        $sout = CRM_Utils_Money::format($s, NULL, NULL, TRUE);
-        break;
-
       case 'string':
       case 'notepad':
         $s2 = str_replace("\n", '\n', $s1);