Skip to content

Commit

Permalink
Merge pull request civicrm#18 from Parag18/VAT-415-Push
Browse files Browse the repository at this point in the history
VAT-415 The default receipts that the system sends out should be updated...
  • Loading branch information
pradpnayak committed Jul 1, 2014
2 parents 4423f3b + 83ddbdb commit 42b7a99
Show file tree
Hide file tree
Showing 16 changed files with 522 additions and 12 deletions.
18 changes: 18 additions & 0 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ public function buildQuickForm() {
$amount_block_is_active = $this->get('amount_block_is_active');
$this->assign('amount_block_is_active', $amount_block_is_active);

$this->assign('totalTaxAmount', $params['tax_amount']);
if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
$option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
$productID = $params['selectProduct'];
Expand Down Expand Up @@ -1296,6 +1297,23 @@ static function processContribution(

if (isset($params['amount'])) {
$contribParams['line_item'] = $form->_lineItem;
//add dataArray in the receipt
$dataArray = array();
foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
foreach ($lineItemValue as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
}
else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
}
}
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('dataArray', $dataArray);
$smarty->assign('totalTaxAmount', $totalTaxAmount);
//add contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
Expand Down
22 changes: 22 additions & 0 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,28 @@ public function postProcess() {
if ($this->_isPaidEvent) {
// fix amount for each of participants ( for bulk mode )
$eventAmount = array();
//add dataArray in the receipts in ADD and UPDATE condition
$totalTaxAmount = 0;
$dataArray = array();
if ($this->_action & CRM_Core_Action::ADD) {
$line = $lineItem[0];
}
elseif ($this->_action & CRM_Core_Action::UPDATE) {
$line = $this->_values['line_items'];
}
foreach ($line as $key => $value) {
if (isset($value['tax_amount'])) {
$totalTaxAmount += $value['tax_amount'];
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
}
else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
}
$this->assign('totalTaxAmount', $totalTaxAmount);
$this->assign('dataArray', $dataArray);
if (!empty($additionalParticipantDetails)) {
$params['amount_level'] = preg_replace('//', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName;
}
Expand Down
19 changes: 19 additions & 0 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ public function buildQuickForm() {
) {
$this->_amount = array();

$taxAmount = 0;
foreach ($this->_params as $k => $v) {
//display tax amount on confirmation page
$taxAmount += $v['tax_amount'];
if (is_array($v)) {
foreach (array(
'first_name', 'last_name') as $name) {
Expand Down Expand Up @@ -272,6 +275,7 @@ public function buildQuickForm() {
}
}

$this->assign('totalTaxAmount', $taxAmount);
$this->assign('part', $this->_part);
$this->set('part', $this->_part);
$this->assign('amounts', $this->_amount);
Expand Down Expand Up @@ -669,6 +673,8 @@ public function postProcess() {
}

$entityTable = 'civicrm_participant';
$totalTaxAmount = 0;
$dataArray = array();
foreach ($this->_lineItem as $key => $value) {
if (($value != 'skip') &&
($entityId = CRM_Utils_Array::value($key, $allParticipantIds))
Expand All @@ -681,7 +687,20 @@ public function postProcess() {
$lineItem[$this->_priceSetId] = $value;
CRM_Price_BAO_LineItem::processPriceSet($entityId, $lineItem, $contribution, $entityTable);
}
foreach ($value as $line) {
if (isset($line['tax_amount']) && isset($line['tax_rate'])) {
$totalTaxAmount = $line['tax_amount'] + $totalTaxAmount;
if (isset($dataArray[$line['tax_rate']])) {
$dataArray[$line['tax_rate']] = $dataArray[$line['tax_rate']] + CRM_Utils_Array::value('tax_amount', $line);
}
else {
$dataArray[$line['tax_rate']] = CRM_Utils_Array::value('tax_amount', $line);
}
}
}
}
$this->assign('dataArray', $dataArray);
$this->assign('totalTaxAmount', $totalTaxAmount);
}

//update status and send mail to cancelled additonal participants, CRM-4320
Expand Down
18 changes: 18 additions & 0 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,7 @@ public function postProcess() {
}

if (!empty($lineItem[$priceSetId])) {
$totalTaxAmount = 0;
foreach ($lineItem[$priceSetId] as & $priceFieldOp) {
if (!empty($priceFieldOp['membership_type_id'])) {
$priceFieldOp['start_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'], '%d%f %b, %Y') : '-';
Expand All @@ -1666,8 +1667,25 @@ public function postProcess() {
else {
$priceFieldOp['start_date'] = $priceFieldOp['end_date'] = 'N/A';
}
if (isset($priceFieldOp['tax_amount'])) {
$totalTaxAmount += $priceFieldOp['tax_amount'];
}
}
//add dataArray membership receipt
$dataArray = array();
foreach ($lineItem[$priceSetId] as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] += $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
} else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
}
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('dataArray', $dataArray);
}
$this->assign('totalTaxAmount', $totalTaxAmount);
$this->assign('lineItem', !empty($lineItem) && !$isQuickConfig ? $lineItem : FALSE);

$receiptSend = FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<th>{ts}Item{/ts}</th>
<th>{ts}Qty{/ts}</th>
<th>{ts}Each{/ts}</th>
{if $totalTaxAmount}
<th>{ts}Subtotal{/ts}</th>
<th>{ts}Tax Rate{/ts}</th>
<th>{ts}Tax Amount{/ts}</th>
{/if}
<th>{ts}Total{/ts}</th>
</tr>
{foreach from=$value item=line}
Expand All @@ -71,6 +76,17 @@
<td>
{$line.unit_price|crmMoney:$currency}
</td>
{if $totalTaxAmount}
<td>
{$line.unit_price*$line.qty|crmMoney:$currency}
</td>
<td>
{$line.tax_rate|crmMoney:$currency}
</td>
<td>
{$line.tax_amount|crmMoney:$currency}
</td>
{/if}
<td>
{$line.line_total|crmMoney:$currency}
</td>
Expand All @@ -81,6 +97,39 @@
</tr>
{/foreach}
{/if}
{if $dataArray && $totalTaxAmount}
<tr>
<td {$labelStyle}>
{ts} Amount before Tax : {/ts}
</td>
<td {$valueStyle}>
{$formValues.total_amount-$totalTaxAmount|crmMoney:$currency}
</td>
</tr>

{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset}
<td>&nbsp;{ts}Vat{/ts}{$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{elseif $priceset == 0}
<td>&nbsp;{ts}No Vat{/ts}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
{/foreach}
{/if}

{if $totalTaxAmount}
<tr>
<td {$labelStyle}>
{ts}Total Tax Amount{/ts}
</td>
<td {$valueStyle}>
{$totalTaxAmount|crmMoney:$currency}
</td>
</tr>
{/if}

<tr>
<td {$labelStyle}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,35 @@
{capture assign=ts_item}{ts}Item{/ts}{/capture}
{capture assign=ts_qty}{ts}Qty{/ts}{/capture}
{capture assign=ts_each}{ts}Each{/ts}{/capture}
{if $totalTaxAmount}
{capture assign=ts_subtotal}{ts}Subtotal{/ts}{/capture}
{capture assign=ts_taxRate}{ts}Tax Rate{/ts}{/capture}
{capture assign=ts_taxAmount}{ts}Tax Amount{/ts}{/capture}
{/if}
{capture assign=ts_total}{ts}Total{/ts}{/capture}
{$ts_item|string_format:"%-30s"} {$ts_qty|string_format:"%5s"} {$ts_each|string_format:"%10s"} {$ts_total|string_format:"%10s"}
{$ts_item|string_format:"%-30s"} {$ts_qty|string_format:"%5s"} {$ts_each|string_format:"%10s"} {if $totalTaxAmount} {$ts_subtotal|string_format:"%10s"} {$ts_taxRate|string_format:"%10s"} {$ts_taxAmount|string_format:"%10s"} {/if} {$ts_total|string_format:"%10s"}
----------------------------------------------------------
{foreach from=$value item=line}
{capture assign=ts_item}{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description} {$line.description}{/if}{/capture}{$ts_item|truncate:30:"..."|string_format:"%-30s"} {$line.qty|string_format:"%5s"} {$line.unit_price|crmMoney:$currency|string_format:"%10s"} {$line.line_total|crmMoney:$currency|string_format:"%10s"}
{capture assign=ts_item}{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description} {$line.description}{/if}{/capture}{$ts_item|truncate:30:"..."|string_format:"%-30s"} {$line.qty|string_format:"%5s"} {$line.unit_price|crmMoney:$currency|string_format:"%10s"} {if $totalTaxAmount}{$line.unit_price*$line.qty|crmMoney:$currency|string_format:"%10s"} {$line.tax_rate|crmMoney:$currency|string_format:"%10s"} {$line.tax_amount|crmMoney:$currency|string_format:"%10s"} {/if}{$line.line_total|crmMoney:$currency|string_format:"%10s"}
{/foreach}
{/foreach}
{/if}

{if $dataArray && $totalTaxAmount}
{ts}Amount before Tax{/ts}: {$formValues.total_amount-$totalTaxAmount|crmMoney:$currency}

{foreach from=$dataArray item=value key=priceset}
{if $priceset}
{ts}Vat{/ts}{$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency}
{elseif $priceset == 0}
{ts}No Vat{/ts}: {$value|crmMoney:$currency}
{/if}
{/foreach}
{/if}

{if $totalTaxAmount}
{ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney:$currency}
{/if}
{ts}Total Amount{/ts}: {$formValues.total_amount|crmMoney:$currency}
{if $receive_date}
{ts}Received Date{/ts}: {$receive_date|truncate:10:''|crmDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<th>{ts}Item{/ts}</th>
<th>{ts}Qty{/ts}</th>
<th>{ts}Each{/ts}</th>
{if $dataArray}
<th>{ts}Subtotal{/ts}</th>
<th>{ts}Tax Rate{/ts}</th>
<th>{ts}Tax Amount{/ts}</th>
{/if}
<th>{ts}Total{/ts}</th>
</tr>
{foreach from=$value item=line}
Expand All @@ -69,6 +74,17 @@
<td>
{$line.unit_price|crmMoney:$currency}
</td>
{if $dataArray}
<td>
{$line.unit_price*$line.qty|crmMoney:$currency}
</td>
<td>
{$line.tax_rate|crmMoney:$currency}
</td>
<td>
{$line.tax_amount|crmMoney:$currency}
</td>
{/if}
<td>
{$line.line_total|crmMoney:$currency}
</td>
Expand All @@ -78,6 +94,37 @@
</td>
</tr>
{/foreach}
{if $dataArray}
<tr>
<td {$labelStyle}>
{ts} Amount before Tax : {/ts}
</td>
<td {$valueStyle}>
{$amount-$totalTaxAmount|crmMoney:$currency}
</td>
</tr>

{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset}
<td>&nbsp;{ts}Vat{/ts}{$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{elseif $priceset == 0}
<td>&nbsp;{ts}No Vat{/ts}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
{/foreach}

<tr>
<td {$labelStyle}>
{ts}Total Tax{/ts}
</td>
<td {$valueStyle}>
{$totalTaxAmount|crmMoney:$currency}
</td>
</tr>
{/if}
<tr>
<td {$labelStyle}>
{ts}Total Amount{/ts}
Expand All @@ -89,6 +136,16 @@

{else}

{if $totalTaxAmount}
<tr>
<td {$labelStyle}>
{ts}Total Tax Amount{/ts}
</td>
<td {$valueStyle}>
{$totalTaxAmount|crmMoney:$currency}
</td>
</tr>
{/if}
<tr>
<td {$labelStyle}>
{ts}Amount{/ts}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,34 @@
{capture assign=ts_item}{ts}Item{/ts}{/capture}
{capture assign=ts_qty}{ts}Qty{/ts}{/capture}
{capture assign=ts_each}{ts}Each{/ts}{/capture}
{if $totalTaxAmount}
{capture assign=ts_subtotal}{ts}Subtotal{/ts}{/capture}
{capture assign=ts_taxRate}{ts}Tax Rate{/ts}{/capture}
{capture assign=ts_taxAmount}{ts}Tax Amount{/ts}{/capture}
{/if}
{capture assign=ts_total}{ts}Total{/ts}{/capture}
{$ts_item|string_format:"%-30s"} {$ts_qty|string_format:"%5s"} {$ts_each|string_format:"%10s"} {$ts_total|string_format:"%10s"}
{$ts_item|string_format:"%-30s"} {$ts_qty|string_format:"%5s"} {$ts_each|string_format:"%10s"} {if $totalTaxAmount} {$ts_subtotal|string_format:"%10s"} {$ts_taxRate|string_format:"%10s"} {$ts_taxAmount|string_format:"%10s"} {/if} {$ts_total|string_format:"%10s"}
----------------------------------------------------------
{foreach from=$value item=line}
{capture assign=ts_item}{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description} {$line.description}{/if}{/capture}{$ts_item|truncate:30:"..."|string_format:"%-30s"} {$line.qty|string_format:"%5s"} {$line.unit_price|crmMoney:$currency|string_format:"%10s"} {$line.line_total|crmMoney:$currency|string_format:"%10s"}
{capture assign=ts_item}{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description} {$line.description}{/if}{/capture}{$ts_item|truncate:30:"..."|string_format:"%-30s"} {$line.qty|string_format:"%5s"} {$line.unit_price|crmMoney:$currency|string_format:"%10s"} {if $totalTaxAmount}{$line.unit_price*$line.qty|crmMoney:$currency|string_format:"%10s"} {$line.tax_rate|crmMoney:$currency|string_format:"%10s"} {$line.tax_amount|crmMoney:$currency|string_format:"%10s"} {/if}{$line.line_total|crmMoney:$currency|string_format:"%10s"}
{/foreach}
{/foreach}

{if $dataArray && $totalTaxAmount}
{ts}Amount before Tax{/ts}: {$amount-$totalTaxAmount|crmMoney:$currency}

{foreach from=$dataArray item=value key=priceset}
{if $priceset}
{ts}Vat{/ts}{$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency}
{elseif $priceset == 0}
{ts}No Vat{/ts}: {$value|crmMoney:$currency}
{/if}
{/foreach}
{/if}

{if $totalTaxAmount}
{ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney:$currency}
{/if}

{ts}Total Amount{/ts}: {$amount|crmMoney:$currency}
{else}
Expand Down
Loading

0 comments on commit 42b7a99

Please sign in to comment.