Jump to content

Recommended Posts

i have an website (shopping-cart) and i want to modify the invoice to show the VAT (tax) .

right now if i enable vat tax the prices are shown incorrectly. if the price added by admin is 1000$ the total price with vat is 1200$

i want the price to be displayed 1000$ and before total i want to display the vat of the invoice example:

if the total is 1000 the vat shown will be 1000 / 20 * 120 which means 166.66.

so the invoice looks like this:

product a qty1 price 1000

subtotal 1000

vat(tax) 166

total to pay 1000

 

in the template file i have this function which generates the total and subtotal:

 <table id="total">
 <?php foreach ($totals as $total) { ?>
 <tr>
 <td class="right"><b><?php echo $total['title']; ?>:</b></td>
 <td class="right"><?php echo $total['text']; ?></td>
 </tr>
 <?php } ?>
</table>

 

using

print_r($totals)

will print:

 

Array (
[0] => Array ( [code] => sub_total [title] => Sub-Total [text] => 1000.00€ [value] => 1000 [sort_order] => 1 )
[1] => Array ( [code] => total [title] => Total [text] => 1000.00€ [value] => 1000 [sort_order] => 9 ) )

 

using

print_r($total)

will print:

Array ( [code] => total [title] => Total [text] => 202.00€ [value] => 202 [sort_order] => 9 )

 

basically it's simple what i want to do

 

$totals array i must insert a new row inside to make it look like this:

Array (
[0] => Array ( [code] => sub_total [title] => Sub-Total [text] => 1000.00€ [value] => 1000 [sort_order] => 1 )
[1] => Array ( [code] => VAT [title] => VAT [text] => 166.66€ [value] => 166.66[sort_order] => 2 )
[2] => Array ( [code] => total [title] => Total [text] => 1000.00€ [value] => 1000 [sort_order] => 9 ) )

 

how can i explode and add a row in the middle of the array?

 

please help, thank you!

Edited by work_it_work

Ok, I don't know if I really understand, so I give you a little example how to add a key in the middle of an array

 

 

echo '<pre>';

$a = array(0 => 'A', 1 => 'C');

echo 'BEFORE<br />';
print_r($a);

array_splice($a, 1, 0, 'B');

echo 'AFTER<br />';
print_r($a);

/*
Result:

BEFORE
Array
(
[0] => A
[1] => C
)
AFTER
Array
(
[0] => A
[1] => B
[2] => C
)
*/

thanks for your reply, i managed to solve this problem, here's the solution:

$vat= array(array('code' => 'iva', 'title' => 'IVA', 'text' => $total1, 'value' => '123', 'sort_order' => '2'));
array_splice($totals, 2, 0, $vat);
<table id="total">
	 <?php foreach ($totals as $total) { ?>
	 <tr>
	 <td class="right"><b><?php echo $total['title']; ?>:</b></td>
	 <td class="right"><?php echo $total['text']; ?></td>
	 </tr>
	 <?php } ?>
</table>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.