From 3f7bb5e2245302e0ab0952567de38429ffcf6140 Mon Sep 17 00:00:00 2001 From: Parag Bhilkar Date: Mon, 18 Aug 2014 21:09:53 +0530 Subject: [PATCH] Display tax amount in receipt for offline contribution with and without price set. --- CRM/Contribute/Form/Contribution.php | 53 ++++++++++++++++--- .../contribution_offline_receipt_html.tpl | 4 +- .../contribution_offline_receipt_text.tpl | 4 +- .../contribution_offline_receipt_html.tpl | 4 +- .../contribution_offline_receipt_text.tpl | 4 +- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 2e15a29966..2c5e91cd05 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1066,6 +1066,12 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $submittedValues, $lineItem[$priceSetId]); + // unset tax amount for offline 'is_quick_config' contribution + if ($this->_priceSet['is_quick_config'] && + !array_key_exists($submittedValues['financial_type_id'], CRM_Core_PseudoConstant::getTaxRates()) + ) { + unset($submittedValues['tax_amount']); + } $submittedValues['total_amount'] = CRM_Utils_Array::value('amount', $submittedValues); } if ($this->_id) { @@ -1268,7 +1274,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } $params['line_item'] = $lineItem; $params['payment_processor_id'] = $params['payment_processor'] = CRM_Utils_Array::value('id', $this->_paymentProcessor); - if (CRM_Utils_Array::value('tax_amount', $submittedValues)) { + if (isset($submittedValues['tax_amount'])) { $params['tax_amount'] = $submittedValues['tax_amount']; } //create contribution. @@ -1343,14 +1349,27 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // assign tax calculation for contribution receipts $taxRate = array(); - if ($this->_action & CRM_Core_Action::UPDATE) { - foreach ($this->_lineItems as $key => $value) { + $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); + $this->assign('invoicing', $invoicing); + if ($invoicing) { + if ($this->_action & CRM_Core_Action::ADD) { + $line = $lineItem; + } + elseif ($this->_action & CRM_Core_Action::UPDATE) { + $line = $this->_lineItems; + } + foreach ($line as $key => $value) { foreach ($value as $v) { if (isset($taxRate[(string) $v['tax_rate']])) { $taxRate[(string) $v['tax_rate']] = $taxRate[(string) $v['tax_rate']] + CRM_Utils_Array::value('tax_amount', $v); } else { - $taxRate[(string) $v['tax_rate']] = CRM_Utils_Array::value('tax_amount', $v); + if (isset($v['tax_rate'])) { + $taxRate[(string) $v['tax_rate']] = CRM_Utils_Array::value('tax_amount', $v); + $getTaxDetails = TRUE; + } } } } @@ -1358,9 +1377,29 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP else { $taxRate = array($submittedValues['tax_amount']); } - - $smarty = CRM_Core_Smarty::singleton(); - $smarty->assign('dataArray', $taxRate); + + if ($invoicing) { + if ($this->_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 (CRM_Utils_Array::value('price_set_id', $submittedValues)) { + $this->assign('totalTaxAmount', $submittedValues['tax_amount']); + $this->assign('getTaxDetails', $getTaxDetails); + $this->assign('dataArray', $taxRate); + } + else { + $this->assign('totalTaxAmount', CRM_Utils_Array::value('tax_amount', $submittedValues)); + } + } + } //send receipt mail. if ($contribution->id && !empty($formValues['is_email_receipt'])) { diff --git a/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_html.tpl b/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_html.tpl index 56ae50f6c9..264e0fee87 100644 --- a/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_html.tpl +++ b/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_html.tpl @@ -115,7 +115,7 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0 || $value != ''} -  {$taxTerm} {$priceset}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {else}  {ts}No{/ts} {$taxTerm} @@ -125,7 +125,7 @@ {/foreach} {/if} - {if $getTaxDetails && $totalTaxAmount} + {if $getTaxDetails && $totalTaxAmount !== 'null'} {ts}Total Tax Amount{/ts} diff --git a/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_text.tpl b/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_text.tpl index d0b54802db..7eacb63d83 100644 --- a/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_text.tpl +++ b/CRM/Upgrade/4.5.beta5.msg_template/message_templates/contribution_offline_receipt_text.tpl @@ -35,14 +35,14 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0 || $value != ''} -{$taxTerm} {$priceset}% : {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"}% : {$value|crmMoney:$currency} {else} {ts}No{/ts} {$taxTerm} : {$value|crmMoney:$currency} {/if} {/foreach} {/if} -{if $getTaxDetails && $totalTaxAmount} +{if $getTaxDetails && $totalTaxAmount !== 'null'} {ts}Total Tax Amount{/ts} : {$totalTaxAmount|crmMoney:$currency} {/if} {ts}Total Amount{/ts} : {$formValues.total_amount|crmMoney:$currency} diff --git a/xml/templates/message_templates/contribution_offline_receipt_html.tpl b/xml/templates/message_templates/contribution_offline_receipt_html.tpl index 56ae50f6c9..264e0fee87 100644 --- a/xml/templates/message_templates/contribution_offline_receipt_html.tpl +++ b/xml/templates/message_templates/contribution_offline_receipt_html.tpl @@ -115,7 +115,7 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0 || $value != ''} -  {$taxTerm} {$priceset}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {else}  {ts}No{/ts} {$taxTerm} @@ -125,7 +125,7 @@ {/foreach} {/if} - {if $getTaxDetails && $totalTaxAmount} + {if $getTaxDetails && $totalTaxAmount !== 'null'} {ts}Total Tax Amount{/ts} diff --git a/xml/templates/message_templates/contribution_offline_receipt_text.tpl b/xml/templates/message_templates/contribution_offline_receipt_text.tpl index d0b54802db..7eacb63d83 100644 --- a/xml/templates/message_templates/contribution_offline_receipt_text.tpl +++ b/xml/templates/message_templates/contribution_offline_receipt_text.tpl @@ -35,14 +35,14 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0 || $value != ''} -{$taxTerm} {$priceset}% : {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"}% : {$value|crmMoney:$currency} {else} {ts}No{/ts} {$taxTerm} : {$value|crmMoney:$currency} {/if} {/foreach} {/if} -{if $getTaxDetails && $totalTaxAmount} +{if $getTaxDetails && $totalTaxAmount !== 'null'} {ts}Total Tax Amount{/ts} : {$totalTaxAmount|crmMoney:$currency} {/if} {ts}Total Amount{/ts} : {$formValues.total_amount|crmMoney:$currency} -- 2.25.1