dev/core#2269 Use contribution's currency instead of the default
authorAhed <ahed@compucorp.co.uk>
Wed, 30 Dec 2020 10:04:38 +0000 (12:04 +0200)
committerAhed <ahed@compucorp.co.uk>
Wed, 30 Dec 2020 10:04:38 +0000 (12:04 +0200)
CRM/Contribute/Form/Task/Invoice.php
tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php
xml/templates/message_templates/contribution_invoice_receipt_html.tpl

index 262225d49061bc97974822faa326225c3a3bbf91..4050ebe825cf51c3804060cfdc2b56673e778a5c 100644 (file)
@@ -363,6 +363,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
         'resourceBase' => $config->userFrameworkResourceURL,
         'defaultCurrency' => $config->defaultCurrency,
         'amount' => $contribution->total_amount,
+        'currency' => $contribution->currency,
         'amountDue' => $amountDue,
         'amountPaid' => $amountPaid,
         'invoice_date' => $invoiceDate,
index 75d8ce3efc94d87ec8652f8853bee9d9d97a11e8..bee4dc15c8a60035cf743202a87b5e8eccd98480 100644 (file)
@@ -161,4 +161,43 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test invoices if payment is made with different currency.
+   *
+   * https://lab.civicrm.org/dev/core/issues/2269
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testThatInvoiceShowTheActuallContributionCurrencyInsteadOfTheDefaultOne() {
+    $this->setDefaultCurrency('USD');
+
+    $this->_individualId = $this->individualCreate();
+
+    $contributionParams = [
+      'contact_id' => $this->_individualId,
+      'total_amount' => 100,
+      'currency' => 'GBP',
+      'financial_type_id' => 'Donation',
+      'contribution_status_id' => 1,
+    ];
+
+    $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+
+    $params = [
+      'output' => 'pdf_invoice',
+      'forPage' => 1,
+    ];
+
+    $invoiceHTML = CRM_Contribute_Form_Task_Invoice::printPDF([$contribution['id']], $params, [$this->_individualId]);
+
+    $this->assertNotContains('$', $invoiceHTML);
+    $this->assertNotContains('Amount USD', $invoiceHTML);
+    $this->assertNotContains('TOTAL USD', $invoiceHTML);
+    $this->assertContains('£ 0.00', $invoiceHTML);
+    $this->assertContains('£ 100.00', $invoiceHTML);
+    $this->assertContains('Amount GBP', $invoiceHTML);
+    $this->assertContains('TOTAL GBP', $invoiceHTML);
+
+  }
+
 }
index 2222bf0b5c05c6c24d0e9bf1429fdc4d0173bb85..cd5733cc6a52642d239e93ee4f436d9dbfea861d 100644 (file)
@@ -76,7 +76,7 @@
                 <th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{ts}Quantity{/ts}</font></th>
                 <th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{ts}Unit Price{/ts}</font></th>
                 <th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{$taxTerm}</font></th>
-                <th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{ts 1=$defaultCurrency}Amount %1{/ts}</font></th>
+                <th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{ts 1=$currency}Amount %1{/ts}</font></th>
               </tr>
               {foreach from=$lineItem item=value key=priceset name=taxpricevalue}
                 {if $smarty.foreach.taxpricevalue.index eq 0}
               {/foreach}
               <tr>
                 <td colspan="3"></td>
-                <td style="text-align:right;white-space: nowrap"><b><font size="1">{ts 1=$defaultCurrency}TOTAL %1{/ts}</font></b></td>
+                <td style="text-align:right;white-space: nowrap"><b><font size="1">{ts 1=$currency}TOTAL %1{/ts}</font></b></td>
                 <td style="text-align:right;"><font size="1">{$amount|crmMoney:$currency}</font></td>
               </tr>
               <tr>
                 <th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{ts}Quantity{/ts}</font></th>
                 <th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{ts}Unit Price{/ts}</font></th>
                 <th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{$taxTerm}</font></th>
-                <th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{ts 1=$defaultCurrency}Amount %1{/ts}</font></th>
+                <th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{ts 1=$currency}Amount %1{/ts}</font></th>
               </tr>
               {foreach from=$lineItem item=value key=priceset name=pricevalue}
                 {if $smarty.foreach.pricevalue.index eq 0}
               </tr>
               <tr>
                 <td colspan="3"></td>
-                <td style="padding-left:28px;text-align:right;"><b><font size="1">{ts 1=$defaultCurrency}TOTAL %1{/ts}</font></b></td>
+                <td style="padding-left:28px;text-align:right;"><b><font size="1">{ts 1=$currency}TOTAL %1{/ts}</font></b></td>
                 <td style="padding-left:28px;text-align:right;"><font size="1">{$amount|crmMoney:$currency}</font></td>
               </tr>
               {if $is_pay_later == 0}