Skip to content

Commit

Permalink
Merge pull request civicrm#17 from Parag18/VAT-414-Push
Browse files Browse the repository at this point in the history
VAT-414 The system public pages should be updated to show the VAT/Tax br...
  • Loading branch information
pradpnayak committed Jul 1, 2014
2 parents 42b7a99 + d1bd44d commit 68ef3c6
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 5 deletions.
21 changes: 21 additions & 0 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ public function buildQuickForm() {

// 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']))
) {
Expand Down Expand Up @@ -1019,6 +1025,21 @@ public function postProcess() {
}
}

// 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);
Expand Down
1 change: 1 addition & 0 deletions CRM/Contribute/Form/Contribution/ThankYou.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function buildQuickForm() {
$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);
Expand Down
3 changes: 3 additions & 0 deletions CRM/Contribute/Form/ContributionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public function preProcess() {

// 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);
Expand Down
5 changes: 5 additions & 0 deletions CRM/Event/Form/EventFees.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,14 @@ static function buildQuickForm(&$form) {
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'])) {
Expand Down
3 changes: 3 additions & 0 deletions CRM/Event/Form/ParticipantView.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ public function preProcess() {
$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);
}
Expand Down
16 changes: 16 additions & 0 deletions CRM/Event/Form/Registration/ThankYou.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,34 @@ public function buildQuickForm() {
}
$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');
Expand Down
6 changes: 6 additions & 0 deletions CRM/Price/BAO/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ static function getLineItems($entityId, $entity = 'participant', $isQuick = NULL
);

$dao = CRM_Core_DAO::executeQuery("$selectClause $fromClause $whereClause", $params);
$getTaxDetails = FALSE;
while ($dao->fetch()) {
if (!$dao->id) {
continue;
Expand All @@ -185,7 +186,12 @@ static function getLineItems($entityId, $entity = 'participant', $isQuick = NULL
);
$lineItems[$dao->id]['tax_rate'] = CRM_Price_BAO_LineItem::calculateTaxRate($lineItems[$dao->id]);
$lineItems[$dao->id]['subTotal'] = $lineItems[$dao->id]['qty'] * $lineItems[$dao->id]['unit_price'];
if ($lineItems[$dao->id]['tax_amount'] != '') {
$getTaxDetails = TRUE;
}
}
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('getTaxDetails', $getTaxDetails);
return $lineItems;
}

Expand Down
12 changes: 12 additions & 0 deletions CRM/Price/Page/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function browse() {
$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]);
Expand All @@ -143,7 +145,16 @@ function browse() {

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()));
Expand Down Expand Up @@ -185,6 +196,7 @@ function browse() {
'PriceField',
$priceFieldBAO->id
);
$this->assign('getTaxDetails', $getTaxDetails);
}

$returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
Expand Down
12 changes: 12 additions & 0 deletions CRM/Price/Page/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,19 @@ function browse() {
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']];
}
Expand Down Expand Up @@ -177,6 +188,7 @@ function browse() {
'id', $returnURL, $filter
);

$this->assign('getTaxDetails', $getTaxDetails);
$this->assign('customOption', $customOption);
$this->assign('sid', $this->_sid);
}
Expand Down
3 changes: 3 additions & 0 deletions templates/CRM/Contribute/Form/Contribution/Confirm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
{$membership_name} {ts}Membership{/ts}: <strong>{$minimum_fee|crmMoney}</strong>
{/if}
{else}
{if $totalTaxAmount }
{ts}Total Tax Amount{/ts}: <strong>{$totalTaxAmount|crmMoney} </strong><br />
{/if}
{if $amount }
{ts}Total Amount{/ts}: <strong>{$amount|crmMoney} {if $amount_level } - {$amount_level} {/if}</strong>
{else}
Expand Down
3 changes: 3 additions & 0 deletions templates/CRM/Contribute/Form/Contribution/ThankYou.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<strong> -------------------------------------------</strong><br />
{ts}Total{/ts}: <strong>{$amount+$membership_amount|crmMoney}</strong><br />
{else}
{if $totalTaxAmount}
{ts}Tax Amount{/ts}: <strong>{$totalTaxAmount|crmMoney}</strong><br />
{/if}
{ts}Amount{/ts}: <strong>{$amount|crmMoney} {if $amount_level} - {$amount_level} {/if}</strong><br />
{/if}
{/if}
Expand Down
8 changes: 7 additions & 1 deletion templates/CRM/Contribute/Page/PaymentInfo.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
});
</script>
Expand Down
6 changes: 6 additions & 0 deletions templates/CRM/Event/Form/Registration/Confirm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<div class="clear"></div>
{/foreach}
</div>
{if $totalTaxAmount}
<div class="crm-section no-label total-amount-section">
<div class="content bold">{ts}Total Tax Amount{/ts}:&nbsp;&nbsp;{$totalTaxAmount|crmMoney}</div>
<div class="clear"></div>
</div>
{/if}
{if $totalAmount}
<div class="crm-section no-label total-amount-section">
<div class="content bold">{ts}Total Amount{/ts}:&nbsp;&nbsp;{$totalAmount|crmMoney}</div>
Expand Down
4 changes: 4 additions & 0 deletions templates/CRM/Event/Form/Registration/ThankYou.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
<div class="clear"></div>
{/foreach}
</div>
{if $totalTaxAmount}
<div class="content bold">{ts}Tax Total{/ts}:&nbsp;&nbsp;{$totalTaxAmount|crmMoney}</div>
<div class="clear"></div>
{/if}
{if $totalAmount}
<div class="crm-section no-label total-amount-section">
<div class="content bold">{ts}Event Total{/ts}:&nbsp;&nbsp;{$totalAmount|crmMoney}</div>
Expand Down
14 changes: 14 additions & 0 deletions templates/CRM/Price/Page/Field.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<th>{ts}Active On{/ts}</th>
<th>{ts}Expire On{/ts}</th>
<th id="nosort">{ts}Price{/ts}</th>
{if $getTaxDetails}
<th>{ts}Tax Label{/ts}</th>
<th>{ts}Tax Amount{/ts}</th>
{/if}
<th></th>
<th class="hiddenElement"></th>
</tr>
Expand All @@ -83,6 +87,16 @@
<td>{if $row.active_on}{$row.active_on|date_format:"%Y-%m-%d %T"}{/if}</td>
<td>{if $row.expire_on}{$row.expire_on|date_format:"%Y-%m-%d %T"}{/if}</td>
<td>{if $row.html_type eq "Text / Numeric Quantity"}{$row.price|crmMoney}{else}<a href="{crmURL p="civicrm/admin/price/field/option" q="action=browse&reset=1&sid=$sid&fid=$fid"}">{if $isReserved}{ts}View Price Options{/ts}{else}{ts}Edit Price Options{/ts}{/if}</a>{/if}</td>
{if $getTaxDetails}
<td>{if $row.tax_rate != '' && $row.html_type eq "Text / Numeric Quantity"}
{if $row.tax_rate == 0.00}
{ts}VAT(Exempt){/ts}
{else}
{ts}VAT{/ts}({$row.tax_rate|string_format:"%.2f"}%)
{/if}
{/if}</td>
<td>{if $row.html_type eq "Text / Numeric Quantity" }{$row.tax_amount|crmMoney}{/if}</td>
{/if}
<td class="field-action">{$row.action|replace:'xx':$row.id}</td>
<td class="order hiddenElement">{$row.weight}</td>
</tr>
Expand Down
45 changes: 41 additions & 4 deletions templates/CRM/Price/Page/LineItem.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@
{else}
<th class="right">{ts}Qty{/ts}</th>
<th class="right">{ts}Unit Price{/ts}</th>
<th class="right">{ts}Total Price{/ts}</th>
{/if}
{if !$totalTaxAmount}
<th class="right">{ts}Total Price{/ts}</th>
{/if}
{/if}

{if $totalTaxAmount}
<th class="right">{ts}Subtotal{/ts}</th>
<th class="right">{ts}Tax Rate{/ts}</th>
<th class="right">{ts}Tax Amount{/ts}</th>
<th class="right">{ts}Total Amount{/ts}</th>
{/if}

{if $pricesetFieldsCount}
<th class="right">{ts}Total Participants{/ts}</th>{/if}
Expand All @@ -53,8 +62,30 @@
{if $context NEQ "Membership"}
<td class="right">{$line.qty}</td>
<td class="right">{$line.unit_price|crmMoney}</td>
{/if}
{else}
<td class="right">{$line.line_total|crmMoney}</td>
{/if}
{if !$totalTaxAmount && $context NEQ "Membership"}
<td class="right">{$line.line_total|crmMoney}</td>
{/if}
{if $totalTaxAmount}
<td class="right">{$line.line_total-$line.tax_amount|crmMoney}</td>
{if $line.tax_rate != ""}
{if $line.tax_rate == 0}
<td class="right">{ts}VAT(exempt){/ts}</td>
{else}
<td class="right">{ts}VAT{/ts}({$line.tax_rate|string_format:"%.2f"}%)</td>
{/if}
<td class="right">{$line.tax_amount|crmMoney}</td>
{elseif $line.tax_amount != ''}
<td class="right">{ts}VAT(exempt){/ts}</td>
<td class="right">{$line.tax_amount|crmMoney}</td>
{else}
<td></td>
<td></td>
{/if}
<td class="right">{$line.line_total|crmMoney}</td>
{/if}
{if $pricesetFieldsCount}<td class="right">{$line.participant_count}</td> {/if}
</tr>
{/foreach}
Expand All @@ -64,10 +95,16 @@

<div class="crm-section no-label total_amount-section">
<div class="content bold">
{if $totalTaxAmount}
{ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney}<br />
{/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}<br />
{/if}
{ts}Total{/ts}:
{elseif $context EQ "Membership"}
{ts}Membership Fee Total{/ts}:
{else}
Expand Down
14 changes: 14 additions & 0 deletions templates/CRM/Price/Page/Option.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<th>{ts}Default{/ts}</th>
<th>{ts}Financial Type{/ts}</th>
<th id="order" class="sortable">{ts}Order{/ts}</th>
{if $getTaxDetails}
<th>{ts}Tax Label{/ts}</th>
<th>{ts}Tax Amount{/ts}</th>
{/if}
<th>{ts}Enabled?{/ts}</th>
<th></th>
<th class="hiddenElement"></th>
Expand All @@ -73,6 +77,16 @@
<td class="crm-price-option-is_default">{if $row.is_default}<img src="{$config->resourceBase}i/check.gif" alt="{ts}Default{/ts}" />{/if}</td>
<td class="nowrap crm-price-option-financial-type-id">{$row.financial_type_id}</td>
<td class="nowrap crm-price-option-order">{$row.weight}</td>
{if $getTaxDetails}
<td>{if $row.tax_rate != '' }
{if $row.tax_rate == 0.00}
{ts}VAT(Exempt){/ts}
{else}
{ts}VAT{/ts}({$row.tax_rate|string_format:"%.2f"}%)
{/if}
{/if}</td>
<td>{$row.tax_amount|crmMoney}</td>
{/if}
<td id="row_{$row.id}_status" class="crm-price-option-is_active">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
<td>{$row.action|replace:'xx':$row.id}</td>
<td class="order hiddenElement">{$row.weight}</td>
Expand Down

0 comments on commit 68ef3c6

Please sign in to comment.