Jump to content

Recommended Posts

Hi, I am using a PHP script that uses register_global.

 

It has a function where you input a number and it works out the VAT. The problem is it deducts the VAT from the number (price). Does any one know maybe how to reverse it so it adds the VAT rather than take it away.

 

This is the line in the script for the VAT:

 

<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l],2); ?>
<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]-($price[$l]/($vat_at+100)*100),2); ?>
<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]/($vat_at+100)*100, 2); ?>

 

I am assuming something in the middle line needs to be edited but I am not 100% sure.

 

If anyone has nay sguggestions that would be cool.

 

Cheers,

 

Paul

Link to comment
https://forums.phpfreaks.com/topic/170876-invoice-script-add-vat/
Share on other sites

Thanks for the suggestion, I tried that one earlier and it didn't work.

 

I have just figured out though that it's the bottom line that needs to be altered I think and not the middle.

 

The middle line works out the VAT which at the moment is correct, I need the VAT to just be added to the price rather than deducted.

 

Thanks though :)

global $price;

 

I believe this to be the variable for price.

 

This is all the code within the page.

 

<?php
}
function mainform() {
global $HeaderDistance;
global $BorderColour;
global $TableBGcolour;
global $PageTitle;
global $CurrencyUnit;
global $DisplayVat;
global $TaxName;
global $VatRate;
global $InvoiceSignature;
global $n_order;
global $n_price;
global $vat_at;
global $customer_id;
global $customer_address;
global $customer_name;
global $date;
global $order;
global $price;
global $notes;

?>

<TABLE WIDTH="50%" BORDER="0" CELLPADDING="2" CELLSPACING="2" ALIGN="CENTER">
    <TR> 
      <TD align="center" valign="top" colspan="2"><img src="images/gm-invoicelogo.jpg" width="397" height="187"><br> 
        <FORM method="post">
          <table>
            <tr>
              <td colspan="4" align="center"><img src="images/header.jpg" width="559" height="18"><br><br></td>
            </tr>
            <tr>
              <td align="left"><strong>Name:</strong></td>
              <td align="left"><input type="text" name="customer_name" size="38" value="<?php if($customer_name) { print tag($customer_name); } else { print "Insert Customer Name"; } ?>"></td>
              <td align="left"><b>Invoice Date</b><strong>:</strong></td>
              <td align="left"><input type="text" name="date" size="15" value="<?php if($date){ print tag($date); } else { print date("d/m/Y"); } ?>"></td>
            </tr>
            <tr>
              <td align="left"><strong>Address:</strong></td>
              <td align="left"><textarea name="customer_address" rows="5" cols="40"><?php if($customer_address) { print $customer_address; } else { print "Insert Customer Address"; } ?></textarea></td> 
              <td align="left"><b>Invoice Number:</b></td>
              <td align="left"><input type="text" name="customer_id"  size="15" value="<?php if($customer_id){ print tag($customer_id); } else { print "Customer Ref"; } ?>"></td>
            </tr>
            <tr>
              <td></td> 
            </tr>
            
            <tr>
              <td colspan="4"> <table width="100%" CELLPADDING="2" CELLSPACING="0" border="1" bordercolor="<?PHP print "$BorderColour"; ?>">
                  <tr bgcolor="<?PHP print "$TableBGcolour"; ?>"> 
                    <th>Description</th>
                    <th>Cost</th>
                    <th><?PHP print "$TaxName"; ?></th>
                    <th>Total</th>
                  </tr>
                  <tr> 
                    <td><img src="images/spacer.gif" width="450" height="14"></td>
                    <td><img src="images/spacer.gif" width="60" height="14"></td>
                    <td><img src="images/spacer.gif" width="60" height="14"></td>
                    <td><img src="images/spacer.gif" width="60" height="14"></td>
                  </tr>
<?php
$tot_cost = 0;
$tot_vat = 0;
$tot_price = 0;
for($l=0; $l<sizeof($order); $l++){
?>
                  <input type="hidden" name="order[<?php print $l; ?>]" value="<?php print tag($order[$l]); ?>">
                  <input type="hidden" name="price[<?php print $l; ?>]" value="<?php print tag($price[$l]); ?>">
                  <tr> 
                    <td><?php print $order[$l]; ?></td>
                    <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l],2); ?></td>
                    <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]-($price[$l]/($vat_at+100)*100),2); ?></td>
                    <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]/($vat_at+100)*100, 2); ?></td>
                  </tr> 
                  <?php
$tot_cost += $price[$l]/($vat_at+100)*100;
$tot_vat += $price[$l]-($price[$l]/($vat_at+100)*100);
$tot_price += $price[$l];
}
?>
                  <tr> 
                    <td>
                      <input type="text" name="order[<?php print sizeof($order); ?>]" size="70"></td>
                    <td align="right"><?php print "$CurrencyUnit"; ?>
                      <input type="text" name="price[<?php print sizeof($price); ?>]" size="4"></td>
                    <td align="right"><img src="images/spacer.gif" width="60" height="14"></td>
                    <td align="right"><img src="images/spacer.gif" width="60" height="14"></td>
                  </tr> <tr> 
                    <td colspan=4><?php if($DisplayVat == "Y") {
				print "<input type=\"hidden\" name=\"vat_at\" value=\"$VatRate\" size=\"4\">
				<i>$TaxName charged at a rate of $VatRate%</i>"; } else print "<img src=\"images/spacer.gif\" width=\"1\" height=\"14\">"; ?></td>
                  </tr>
                </table>                <table align="right" width="0"  CELLPADDING="2" CELLSPACING="1" border="1" bordercolor="<?PHP print "$BorderColour"; ?>">
                  <br>
                  <tr> 
                    <td width="60" align="right"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_price,2); ?></b></td>
                    <td align="right" width="60"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_vat,2); ?></b></td>
                    <td align="right" width="60"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_cost,2); ?></b></td>
                  </tr>
              </table></td> 
            </tr>
            <tr>
              <td colspan="4"><br><div align="center"><img src="images/footer.jpg" width="488" height="60"><br><br><br>
Green Media Advertising Ltd, company reg: 06594457, vat reg: 93211665</div><br>
                <div align="center"><?php print "$InvoiceSignature"; ?></div><br> 
                <br><div align="center"><input name="action" type="submit" value="Update Invoice" class="button">   
                  <input name="action" type="submit" value="Process Invoice" class="button">
              </div></td> 
            </tr></table>
        </FORM> </TD>
    </TR>
  </TABLE>

Is VAT like a goods and services tax added to the cost of sold items?

 

The three lines you posted in the first post ouput values that are dervied from the formulas using the value of $price[$l] and $vat_at. I can't see where $vat_at is defined to anything in your full file post, but it is global so I don't know if it is pulling that value from somewhere else? From the code you've posted, $vat_at = nothing.

 

The output shows that the third line should be the tax total, the second line should be whatever $Taxname is?

 

What is the formula for working out how much VAT is on an item? For example, In Australia we have 10% GST. So if you have a GST inclusive price, you can work out how much is GST by the formula: price / 11 = GST.

 

Ok... upon a more in depth look at your code, I think I may have an answer.

 

Let's break this down...

 

<th>Cost</th>
<th><?PHP print "$TaxName"; ?></th>
<th>Total</th>

 

<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l],2); ?>
<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]-($price[$l]/($vat_at+100)*100),2); ?>
<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]/($vat_at+100)*100, 2); ?>

 

These lines must coresspond to Cost, $TaxName (a string "VAT" I would assume) and Total.

 

I did a mock up of $price[$l]-($price[$l]/($vat_at+100)*100). Say price is 100 and vat_at is 15 (%):

100 - (100 / (15 + 100) * 100)

100 - (100 / 115 * 100)

100 - 0.8695 * 100

100 - 86.95

$TaxName (VAT) = 13.05

 

Now for $price[$l]/($vat_at+100)*100:

100 / (15 + 100) * 100

100 / 115 * 100

0.8695 * 100

Price = 86.95

 

This code is taking $price[$l] as a GROSS amount and working out how much VAT is included in the price. If you are doing invoices, you probably want to ADD your VAT as you have already asked.

 

So if you are charging 100 for an item, and want to include VAT (example 15%) you should be able to use the following formula:

 

$priceIncVAT = $price[$l] + $price[$l]-($price[$l]/($vat_at+100)*100);

 

You should be able to change the third line of code as follows:

From:
<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]/($vat_at+100)*100, 2); ?>
To:
<?php print "$CurrencyUnit"; ?><?php print number_format($price[$l] + $price[$l]/($vat_at+100)*100, 2); ?>

 

Hope this helps.

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.