From d91b8b335dce2447802e09a914e2a30bf7132368 Mon Sep 17 00:00:00 2001 From: dpradeep Date: Thu, 22 May 2014 10:09:10 +0530 Subject: [PATCH] VAT-366 Handle database entry(lineitem creation etc) of tax amounts --- CRM/Contribute/Form/Contribution.php | 3 +++ CRM/Contribute/Form/Contribution/Confirm.php | 2 ++ CRM/Event/Form/Participant.php | 7 +++++++ CRM/Event/Form/Registration/Confirm.php | 2 ++ CRM/Event/Form/Registration/Register.php | 3 +++ CRM/Member/BAO/Membership.php | 2 +- CRM/Member/Form/Membership.php | 3 +++ xml/schema/Contribute/Contribution.xml | 12 ++++++++++++ xml/schema/Price/LineItem.xml | 12 ++++++++++++ 9 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index c27932b18dbe..f8afdec141d8 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1218,6 +1218,9 @@ public function postProcess() { } $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)) { + $params['tax_amount'] = $submittedValues['tax_amount']; + } //create contribution. if ($isQuickConfig) { $params['is_quick_config'] = 1; diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 0fb447d4239c..79289b2a02d8 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -144,6 +144,7 @@ public function preProcess() { $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $this->get('amount'); + $this->_params['tax_amount'] = $this->get('tax_amount'); $this->_useForMember = $this->get('useForMember'); @@ -1193,6 +1194,7 @@ static function processContribution( 'receive_date' => (CRM_Utils_Array::value('receive_date', $params)) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], + 'tax_amount' => $params['tax_amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index e70c86b4e542..c1c54904a50c 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1392,6 +1392,10 @@ public function postProcess() { } } + if (CRM_Utils_Array::value('tax_amount', $this->_params)) { + $contributionParams['tax_amount'] = $this->_params['tax_amount']; + } + if ($this->_single) { if (empty($ids)) { $ids = array(); @@ -1445,6 +1449,9 @@ public function postProcess() { ($params['status_id'] != array_search('Partially paid', $participantStatus)) ) { $line['unit_price'] = $line['line_total'] = $params['total_amount']; + if (!empty($params['tax_amount'])) { + $line['unit_price'] = $line['unit_price'] - $params['tax_amount']; + } } $lineItem[$this->_priceSetId][$lineKey] = $line; } diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 4905bc8f1a3e..057fcff93e6b 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -69,6 +69,7 @@ function preProcess() { $this->_lineItem = $this->get('lineItem'); $this->_params = $this->get('params'); + $this->_params[0]['tax_amount'] = $this->get('tax_amount'); $this->_params[0]['is_pay_later'] = $this->get('is_pay_later'); $this->assign('is_pay_later', $this->_params[0]['is_pay_later']); @@ -853,6 +854,7 @@ static function processContribution(&$form, $params, $result, $contactID, $form->_values['event']['financial_type_id'] : $params['financial_type_id'], 'receive_date' => $now, 'total_amount' => $params['amount'], + 'tax_amount' => $params['tax_amount'], 'amount_level' => $params['amount_level'], 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index aba61f1c5ede..97355050cc5d 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -1069,6 +1069,9 @@ public function postProcess() { else { $lineItem = array(); CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem); + if ($params['tax_amount']) { + $this->set('tax_amount', $params['tax_amount']); + } $this->set('lineItem', array($lineItem)); $this->set('lineItemParticipantsCount', array($primaryParticipantCount)); } diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index c790d4b8fc9b..2b859c5c8f5b 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2725,7 +2725,7 @@ static function recordMembershipContribution( &$params, $ids = array()) { $recordContribution = array( 'contact_id', 'total_amount', 'receive_date', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'invoice_id', 'is_test', - 'contribution_status_id', 'check_number', 'campaign_id', 'is_pay_later', + 'contribution_status_id', 'check_number', 'campaign_id', 'is_pay_later', 'tax_amount' ); foreach ($recordContribution as $f) { $contributionParams[$f] = CRM_Utils_Array::value($f, $params); diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index acd57ebd27e9..6818dc7ca896 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1148,6 +1148,9 @@ public function postProcess() { if ($priceSetId) { CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]); + if (CRM_Utils_Array::value('tax_amount', $this->_params)) { + $params['tax_amount'] = $this->_params['tax_amount']; + } $params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params); $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues); if (!empty($lineItem[$priceSetId])) { diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index b74263329ec4..c20417fb894a 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -448,6 +448,18 @@ Select + + tax_amount + decimal + true + /tax(.?am(ou)?nt)?/i + /^\d+(\.\d{2})?$/ + Total tax amount of this contribution. + 4.5 + + Text + + campaign_id civicrm_campaign
diff --git a/xml/schema/Price/LineItem.xml b/xml/schema/Price/LineItem.xml index 329ce44093c9..2ce9ea7c3e88 100644 --- a/xml/schema/Price/LineItem.xml +++ b/xml/schema/Price/LineItem.xml @@ -168,5 +168,17 @@ Text + + tax_amount + decimal + true + /tax(.?am(ou)?nt)?/i + /^\d+(\.\d{2})?$/ + tax of each item + 4.5 + + Text + +