From a32709be6fef89106c85c3da7882e4cc7befb041 Mon Sep 17 00:00:00 2001 From: Parag Bhilkar Date: Thu, 26 Jun 2014 12:20:36 +0530 Subject: [PATCH] VAT-414 The system public pages should be updated to show the VAT/Tax breakdown for all line items on each contribution record and in a price set. --- CRM/Contribute/Form/Contribution.php | 21 +++++++++ CRM/Contribute/Form/Contribution/ThankYou.php | 1 + CRM/Contribute/Form/ContributionView.php | 3 ++ CRM/Event/Form/EventFees.php | 5 +++ CRM/Event/Form/ParticipantView.php | 3 ++ CRM/Event/Form/Registration/ThankYou.php | 16 +++++++ CRM/Price/Page/Field.php | 12 +++++ CRM/Price/Page/Option.php | 12 +++++ .../Contribute/Form/Contribution/Confirm.tpl | 3 ++ .../Contribute/Form/Contribution/ThankYou.tpl | 3 ++ templates/CRM/Contribute/Page/PaymentInfo.tpl | 8 +++- .../CRM/Event/Form/Registration/Confirm.tpl | 6 +++ .../CRM/Event/Form/Registration/ThankYou.tpl | 4 ++ templates/CRM/Price/Page/Field.tpl | 14 ++++++ templates/CRM/Price/Page/LineItem.tpl | 45 +++++++++++++++++-- templates/CRM/Price/Page/Option.tpl | 14 ++++++ 16 files changed, 165 insertions(+), 5 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index f8afdec141..f80f9ebd28 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -504,6 +504,12 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // build price set form. $buildPriceSet = FALSE; + + // showing tax amount on edit contribution page + if ($this->_action & CRM_Core_Action::UPDATE && isset($this->_values['tax_amount'])) { + $this->assign('totalTaxAmount', $this->_values['tax_amount']); + } + if (empty($this->_lineItems) && ($this->_priceSetId || !empty($_POST['price_set_id'])) ) { @@ -1019,6 +1025,21 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } + // assign dataArray for contribution receipts + $dataArray = array(); + foreach ($this->_lineItems as $key => $value) { + foreach ($value as $v) { + if (isset($dataArray[$v['tax_rate']])) { + $dataArray[$v['tax_rate']] = $dataArray[$v['tax_rate']] + CRM_Utils_Array::value('tax_amount', $v); + } + else { + $dataArray[$v['tax_rate']] = CRM_Utils_Array::value('tax_amount', $v); + } + } + } + $smarty = CRM_Core_Smarty::singleton(); + $smarty->assign('dataArray', $dataArray); + // process price set and get total amount and line items. $lineItem = array(); $priceSetId = CRM_Utils_Array::value('price_set_id', $submittedValues); diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index 1597730d54..c8b0895bbb 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -119,6 +119,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont $this->assign('useForMember', $this->get('useForMember')); $params = $this->_params; + $this->assign('totalTaxAmount', $params['tax_amount']); if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) { $honorName = null; $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); diff --git a/CRM/Contribute/Form/ContributionView.php b/CRM/Contribute/Form/ContributionView.php index 23e08dd5b8..34a011edfa 100644 --- a/CRM/Contribute/Form/ContributionView.php +++ b/CRM/Contribute/Form/ContributionView.php @@ -144,6 +144,9 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form { // assign values to the template $this->assign($values); + if (isset($values['tax_amount'])) { + $this->assign('totalTaxAmount', $values['tax_amount']); + } $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index 753417c809..f81f3dc2b9 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -380,9 +380,14 @@ SELECT id, html_type CRM_Event_Form_Registration::initEventFee($form, $event['id']); CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId); $lineItem = array(); + $totalTaxAmount = 0; if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) { $lineItem[] = $form->_values['line_items']; + foreach ($form->_values['line_items'] as $key => $value) { + $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount; + } } + $form->assign('totalTaxAmount', $totalTaxAmount); $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem); $discounts = array(); if (!empty($form->_values['discount'])) { diff --git a/CRM/Event/Form/ParticipantView.php b/CRM/Event/Form/ParticipantView.php index 0f4faa706a..815a4ead24 100644 --- a/CRM/Event/Form/ParticipantView.php +++ b/CRM/Event/Form/ParticipantView.php @@ -179,11 +179,14 @@ class CRM_Event_Form_ParticipantView extends CRM_Core_Form { $displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']); $participantCount = array(); + $totalTaxAmount = 0; foreach ($lineItem as $k => $v) { if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) { $participantCount[] = $lineItem[$k]['participant_count']; } + $totalTaxAmount = $v['tax_amount'] + $totalTaxAmount; } + $this->assign('totalTaxAmount', $totalTaxAmount); if ($participantCount) { $this->assign('pricesetFieldsCount', $participantCount); } diff --git a/CRM/Event/Form/Registration/ThankYou.php b/CRM/Event/Form/Registration/ThankYou.php index 7c9fc60705..eabe6d4cbf 100644 --- a/CRM/Event/Form/Registration/ThankYou.php +++ b/CRM/Event/Form/Registration/ThankYou.php @@ -98,18 +98,34 @@ class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration { } $this->assignToTemplate(); + $taxAmount = 0; if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $lineItemForTemplate = array(); foreach ($this->_lineItem as $key => $value) { if (!empty($value)) { $lineItemForTemplate[$key] = $value; + foreach ($value as $v) { + if (isset($v['tax_amount'])) { + $taxAmount += $v['tax_amount']; + } + } } } if (!empty($lineItemForTemplate)) { $this->assign('lineItem', $lineItemForTemplate); } } + else { + foreach ($this->_lineItem as $lineItemKey => $lineItemValue) { + foreach ($lineItemValue as $v) { + if (isset($v['tax_amount'])) { + $taxAmount += $v['tax_amount']; + } + } + } + } + $this->assign('totalTaxAmount', $taxAmount); $this->assign('totalAmount', $this->_totalAmount); $hookDiscount = $this->get('hookDiscount'); diff --git a/CRM/Price/Page/Field.php b/CRM/Price/Page/Field.php index fb5453e592..495ca2476e 100644 --- a/CRM/Price/Page/Field.php +++ b/CRM/Price/Page/Field.php @@ -132,6 +132,8 @@ class CRM_Price_Page_Field extends CRM_Core_Page { $priceFieldBAO->orderBy('weight, label'); $priceFieldBAO->find(); + $getTaxDetails = FALSE; + $taxRate = CRM_Core_PseudoConstant::getTaxRates(); while ($priceFieldBAO->fetch()) { $priceField[$priceFieldBAO->id] = array(); CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]); @@ -143,7 +145,16 @@ class CRM_Price_Page_Field extends CRM_Core_Page { CRM_Price_BAO_PriceFieldValue::retrieve($params, $optionValues); + $financialTypeId = $optionValues['financial_type_id']; $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues); + if (isset($taxRate[$financialTypeId])) { + $priceField[$priceFieldBAO->id]['tax_rate'] = $taxRate[$financialTypeId]; + $getTaxDetails = TRUE; + } + if (isset($priceField[$priceFieldBAO->id]['tax_rate'])) { + $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate']); + $priceField[$priceFieldBAO->id]['tax_amount'] = $taxAmount['tax_amount']; + } } $action = array_sum(array_keys($this->actionLinks())); @@ -185,6 +196,7 @@ class CRM_Price_Page_Field extends CRM_Core_Page { 'PriceField', $priceFieldBAO->id ); + $this->assign('getTaxDetails', $getTaxDetails); } $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}"); diff --git a/CRM/Price/Page/Option.php b/CRM/Price/Page/Option.php index 78a0bb7c59..fdcab22b32 100644 --- a/CRM/Price/Page/Option.php +++ b/CRM/Price/Page/Option.php @@ -133,8 +133,19 @@ class CRM_Price_Page_Option extends CRM_Core_Page { CRM_Price_BAO_PriceFieldValue::getValues($this->_fid, $customOption); $config = CRM_Core_Config::singleton(); $financialType = CRM_Contribute_PseudoConstant::financialType(); + $taxRate = CRM_Core_PseudoConstant::getTaxRates(); + $getTaxDetails = FALSE; foreach ($customOption as $id => $values) { $action = array_sum(array_keys($this->actionLinks())); + // Adding the required fields in the array + if (isset($taxRate[$values['financial_type_id']])) { + $customOption[$id]['tax_rate'] = $taxRate[$values['financial_type_id']]; + if (isset($customOption[$id]['tax_rate'])) { + $getTaxDetails = TRUE; + } + $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate']); + $customOption[$id]['tax_amount'] = $taxAmount['tax_amount']; + } if (!empty($values['financial_type_id'])){ $customOption[$id]['financial_type_id'] = $financialType[$values['financial_type_id']]; } @@ -177,6 +188,7 @@ class CRM_Price_Page_Option extends CRM_Core_Page { 'id', $returnURL, $filter ); + $this->assign('getTaxDetails', $getTaxDetails); $this->assign('customOption', $customOption); $this->assign('sid', $this->_sid); } diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index f773ff4e51..435fcc0ac6 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -79,6 +79,9 @@ {$membership_name} {ts}Membership{/ts}: {$minimum_fee|crmMoney} {/if} {else} + {if $totalTaxAmount } + {ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney}
+ {/if} {if $amount } {ts}Total Amount{/ts}: {$amount|crmMoney} {if $amount_level } - {$amount_level} {/if} {else} diff --git a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl index 955413da87..fa39cf4f9b 100644 --- a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl +++ b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl @@ -115,6 +115,9 @@ -------------------------------------------
{ts}Total{/ts}: {$amount+$membership_amount|crmMoney}
{else} + {if $totalTaxAmount} + {ts}Tax Amount{/ts}: {$totalTaxAmount|crmMoney}
+ {/if} {ts}Amount{/ts}: {$amount|crmMoney} {if $amount_level} - {$amount_level} {/if}
{/if} {/if} diff --git a/templates/CRM/Contribute/Page/PaymentInfo.tpl b/templates/CRM/Contribute/Page/PaymentInfo.tpl index 812233877a..3cfc2d10ee 100644 --- a/templates/CRM/Contribute/Page/PaymentInfo.tpl +++ b/templates/CRM/Contribute/Page/PaymentInfo.tpl @@ -37,7 +37,13 @@ CRM.$(function($) { } }); - cj('.total_amount-section').remove(); + var taxAmount = "{$totalTaxAmount}"; + if (taxAmount) { + cj('.total_amount-section').show(); + } + else { + cj('.total_amount-section').remove(); + } } }); diff --git a/templates/CRM/Event/Form/Registration/Confirm.tpl b/templates/CRM/Event/Form/Registration/Confirm.tpl index 9fafdc53bf..435a508d7b 100644 --- a/templates/CRM/Event/Form/Registration/Confirm.tpl +++ b/templates/CRM/Event/Form/Registration/Confirm.tpl @@ -117,6 +117,12 @@
{/foreach} + {if $totalTaxAmount} +
+
{ts}Total Tax Amount{/ts}:  {$totalTaxAmount|crmMoney}
+
+
+ {/if} {if $totalAmount}
{ts}Total Amount{/ts}:  {$totalAmount|crmMoney}
diff --git a/templates/CRM/Event/Form/Registration/ThankYou.tpl b/templates/CRM/Event/Form/Registration/ThankYou.tpl index 1e27523e31..e55d507ac6 100644 --- a/templates/CRM/Event/Form/Registration/ThankYou.tpl +++ b/templates/CRM/Event/Form/Registration/ThankYou.tpl @@ -109,6 +109,10 @@
{/foreach}
+ {if $totalTaxAmount} +
{ts}Tax Total{/ts}:  {$totalTaxAmount|crmMoney}
+
+ {/if} {if $totalAmount}
{ts}Event Total{/ts}:  {$totalAmount|crmMoney}
diff --git a/templates/CRM/Price/Page/Field.tpl b/templates/CRM/Price/Page/Field.tpl index 84159ad0ce..d10ebc6a30 100644 --- a/templates/CRM/Price/Page/Field.tpl +++ b/templates/CRM/Price/Page/Field.tpl @@ -69,6 +69,10 @@ {ts}Active On{/ts} {ts}Expire On{/ts} {ts}Price{/ts} + {if $getTaxDetails} + {ts}Tax Label{/ts} + {ts}Tax Amount{/ts} + {/if} @@ -83,6 +87,16 @@ {if $row.active_on}{$row.active_on|date_format:"%Y-%m-%d %T"}{/if} {if $row.expire_on}{$row.expire_on|date_format:"%Y-%m-%d %T"}{/if} {if $row.html_type eq "Text / Numeric Quantity"}{$row.price|crmMoney}{else}{if $isReserved}{ts}View Price Options{/ts}{else}{ts}Edit Price Options{/ts}{/if}{/if} + {if $getTaxDetails} + {if $row.tax_rate != '' && $row.html_type eq "Text / Numeric Quantity"} + {if $row.tax_rate == 0.00} + VAT(Exempt) + {else} + VAT({$row.tax_rate|string_format:"%.2f"}%) + {/if} + {/if} + {if $row.html_type eq "Text / Numeric Quantity" }{$row.tax_amount|crmMoney}{/if} + {/if} {$row.action|replace:'xx':$row.id} {$row.weight} diff --git a/templates/CRM/Price/Page/LineItem.tpl b/templates/CRM/Price/Page/LineItem.tpl index feacbc347d..a66a55108a 100644 --- a/templates/CRM/Price/Page/LineItem.tpl +++ b/templates/CRM/Price/Page/LineItem.tpl @@ -41,8 +41,17 @@ {else} {ts}Qty{/ts} {ts}Unit Price{/ts} - {ts}Total Price{/ts} - {/if} + {if !$totalTaxAmount} + {ts}Total Price{/ts} + {/if} + {/if} + + {if $totalTaxAmount} + {ts}Subtotal{/ts} + {ts}Tax Rate{/ts} + {ts}Tax Amount{/ts} + {ts}Total Amount{/ts} + {/if} {if $pricesetFieldsCount} {ts}Total Participants{/ts}{/if} @@ -53,8 +62,30 @@ {if $context NEQ "Membership"} {$line.qty} {$line.unit_price|crmMoney} - {/if} + {else} {$line.line_total|crmMoney} +{/if} + {if !$totalTaxAmount && $context NEQ "Membership"} + {$line.line_total|crmMoney} + {/if} + {if $totalTaxAmount} + {$line.line_total-$line.tax_amount|crmMoney} + {if $line.tax_rate != ""} + {if $line.tax_rate == 0} + VAT(exempt) + {else} + VAT({$line.tax_rate|string_format:"%.2f"}%) + {/if} + {$line.tax_amount|crmMoney} + {elseif $line.tax_amount != ''} + VAT(exempt) + {$line.tax_amount|crmMoney} + {else} + + + {/if} + {$line.line_total|crmMoney} + {/if} {if $pricesetFieldsCount}{$line.participant_count} {/if} {/foreach} @@ -64,10 +95,16 @@
+ {if $totalTaxAmount} + {ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney}
+ {/if} {if $context EQ "Contribution"} {ts}Contribution Total{/ts}: {elseif $context EQ "Event"} - {ts}Event Total{/ts}: + {if $totalTaxAmount} + {ts}Event SubTotal: {$totalAmount-$totalTaxAmount|crmMoney}{/ts}
+ {/if} + {ts}Total{/ts}: {elseif $context EQ "Membership"} {ts}Membership Fee Total{/ts}: {else} diff --git a/templates/CRM/Price/Page/Option.tpl b/templates/CRM/Price/Page/Option.tpl index 7419811118..b532489dbd 100644 --- a/templates/CRM/Price/Page/Option.tpl +++ b/templates/CRM/Price/Page/Option.tpl @@ -61,6 +61,10 @@ {ts}Default{/ts} {ts}Financial Type{/ts} {ts}Order{/ts} + {if $getTaxDetails} + {ts}Tax Label{/ts} + {ts}Tax Amount{/ts} + {/if} {ts}Enabled?{/ts} @@ -73,6 +77,16 @@ {if $row.is_default}{ts}Default{/ts}{/if} {$row.financial_type_id} {$row.weight} + {if $getTaxDetails} + {if $row.tax_rate != '' } + {if $row.tax_rate == 0.00} + VAT(Exempt) + {else} + VAT({$row.tax_rate|string_format:"%.2f"}%) + {/if} + {/if} + {$row.tax_amount|crmMoney} + {/if} {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} {$row.action|replace:'xx':$row.id} {$row.weight} -- 2.25.1