Minor code cleanup
authoreileen <emcnaughton@wikimedia.org>
Fri, 15 Mar 2019 22:19:45 +0000 (11:19 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 15 Mar 2019 22:19:45 +0000 (11:19 +1300)
Invoicing code has been poorly integrated into CiviCRM with much copy & paste,
no following of settings spec and an awful lot of outright hacking.

This is a small step towards moving invoice logic to a centralised place -
specifically in this case the unpacking of the non-standard settings that have been
used. Perhaps once using these functions we can standardise them!

Ideally I'd like to see all the invoicing assigns in a function on this
class, better yet once which mimics the pre or buildForm hook & even
better one day to grow up & be a real hook

CRM/Contribute/Form/Contribution/ThankYou.php
CRM/Event/Form/Registration/ThankYou.php
CRM/Invoicing/Utils.php

index 05efdae2266671facc5c31239ae2e22f8573ff6c..f393a4c0a9a2f1653fdebf17ffb27ee9a19868a9 100644 (file)
@@ -107,13 +107,11 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont
     }
 
     $params = $this->_params;
-    $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
-    $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
+    $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled();
     // Make a copy of line items array to use for display only
     $tplLineItems = $this->_lineItem;
     if ($invoicing) {
       $getTaxDetails = FALSE;
-      $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
       foreach ($this->_lineItem as $key => $value) {
         foreach ($value as $k => $v) {
           if (isset($v['tax_rate'])) {
@@ -126,7 +124,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont
         }
       }
       $this->assign('getTaxDetails', $getTaxDetails);
-      $this->assign('taxTerm', $taxTerm);
+      $this->assign('taxTerm', CRM_Invoicing_Utils::getTaxTerm());
       $this->assign('totalTaxAmount', $params['tax_amount']);
     }
 
index 95d67d719873a8e664932d3de246f38ff54270ea..600f4891b65d95acb3f3a15303e96f1ade0e3467 100644 (file)
@@ -96,9 +96,7 @@ class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
     }
     $this->assignToTemplate();
 
-    $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
-    $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
-    $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
+    $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled();
     $getTaxDetails = FALSE;
     $taxAmount = 0;
 
@@ -129,7 +127,7 @@ class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
     if ($invoicing) {
       $this->assign('getTaxDetails', $getTaxDetails);
       $this->assign('totalTaxAmount', $taxAmount);
-      $this->assign('taxTerm', $taxTerm);
+      $this->assign('taxTerm', CRM_Invoicing_Utils::getTaxTerm());
     }
     $this->assign('totalAmount', $this->_totalAmount);
 
index 907f089ad62be1e59ad815186be3b5bc5f1e032e..bad42ae8bce40f1ad78d2fa5846c5a656f056a68 100644 (file)
@@ -94,4 +94,15 @@ class CRM_Invoicing_Utils {
     return CRM_Utils_Array::value('default_invoice_page', $invoiceSettings);
   }
 
+  /**
+   * Function to get the tax term.
+   *
+   * The value is nested in the contribution_invoice_settings setting - which
+   * is unsupported. Here we have a wrapper function to make later cleanup easier.
+   */
+  public static function getTaxTerm() {
+    $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
+    return CRM_Utils_Array::value('tax_term', $invoiceSettings);
+  }
+
 }