From: Eileen McNaughton Date: Sun, 3 May 2015 03:39:57 +0000 (+1200) Subject: CRM-16367 (Backoffice Contribution Form) move invoicing code to a separate function X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6d4f5b21fcce7de0a8c1d30ee714eef4eb1961af;p=civicrm-core.git CRM-16367 (Backoffice Contribution Form) move invoicing code to a separate function --- diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index c575b6832a..5d35a73900 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1757,56 +1757,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } $statusMsg = ts('The contribution record has been saved.'); - // assign tax calculation for contribution receipts - $taxRate = array(); - $getTaxDetails = FALSE; - $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); - $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); - if ($invoicing) { - if ($action & CRM_Core_Action::ADD) { - $line = $lineItem; - } - elseif ($action & CRM_Core_Action::UPDATE) { - $line = $this->_lineItems; - } - foreach ($line as $key => $value) { - foreach ($value as $v) { - if (isset($taxRate[(string) CRM_Utils_Array::value('tax_rate', $v)])) { - $taxRate[(string) $v['tax_rate']] = $taxRate[(string) $v['tax_rate']] + CRM_Utils_Array::value('tax_amount', $v); - } - else { - if (isset($v['tax_rate'])) { - $taxRate[(string) $v['tax_rate']] = CRM_Utils_Array::value('tax_amount', $v); - $getTaxDetails = TRUE; - } - } - } - } - } - - if ($invoicing) { - if ($action & CRM_Core_Action::UPDATE) { - if (isset($submittedValues['tax_amount'])) { - $totalTaxAmount = $submittedValues['tax_amount']; - } - else { - $totalTaxAmount = $this->_values['tax_amount']; - } - $this->assign('totalTaxAmount', $totalTaxAmount); - $this->assign('dataArray', $taxRate); - } - else { - if (!empty($submittedValues['price_set_id'])) { - $this->assign('totalTaxAmount', $submittedValues['tax_amount']); - $this->assign('getTaxDetails', $getTaxDetails); - $this->assign('dataArray', $taxRate); - $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings)); - } - else { - $this->assign('totalTaxAmount', CRM_Utils_Array::value('tax_amount', $submittedValues)); - } - } - } + $this->invoicingPostProcessHook($submittedValues, $action, $lineItem); //send receipt mail. if ($contribution->id && !empty($formValues['is_email_receipt'])) { @@ -1843,4 +1794,62 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return $contribution; } + /** + * Assign tax calculations to contribution receipts. + * + * @param array $submittedValues + * @param int $action + * @param array $lineItem + */ + protected function invoicingPostProcessHook($submittedValues, $action, $lineItem) { + + $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); + if (!CRM_Utils_Array::value('invoicing', $invoiceSettings)) { + return; + } + $taxRate = array(); + $getTaxDetails = FALSE; + if ($action & CRM_Core_Action::ADD) { + $line = $lineItem; + } + elseif ($action & CRM_Core_Action::UPDATE) { + $line = $this->_lineItems; + } + foreach ($line as $key => $value) { + foreach ($value as $v) { + if (isset($taxRate[(string) CRM_Utils_Array::value('tax_rate', $v)])) { + $taxRate[(string) $v['tax_rate']] = $taxRate[(string) $v['tax_rate']] + CRM_Utils_Array::value('tax_amount', $v); + } + else { + if (isset($v['tax_rate'])) { + $taxRate[(string) $v['tax_rate']] = CRM_Utils_Array::value('tax_amount', $v); + $getTaxDetails = TRUE; + } + } + } + } + + if ($action & CRM_Core_Action::UPDATE) { + if (isset($submittedValues['tax_amount'])) { + $totalTaxAmount = $submittedValues['tax_amount']; + } + else { + $totalTaxAmount = $this->_values['tax_amount']; + } + $this->assign('totalTaxAmount', $totalTaxAmount); + $this->assign('dataArray', $taxRate); + } + else { + if (!empty($submittedValues['price_set_id'])) { + $this->assign('totalTaxAmount', $submittedValues['tax_amount']); + $this->assign('getTaxDetails', $getTaxDetails); + $this->assign('dataArray', $taxRate); + $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings)); + } + else { + $this->assign('totalTaxAmount', CRM_Utils_Array::value('tax_amount', $submittedValues)); + } + } + } + }