Tax Calculations

From PhpCOIN Documentation

Jump to: navigation, search

Contents

phpCOIN and Taxes

phpCOIN can handle one or two taxes, and can calculate the tax(es) in a variety of ways, controlled by various settings in [Admin] -> [Parameters] -> [all] -> [Invoices] -> xxxxx. If you have taxes disabled, then no tax options will appear when editing products or invoices, nor will tax information be displayed when viewing products or invoices.


Tax 1

Invoices: Tax 01 Enable : Whether or not to calculate tax 1 on items tagged as taxable by tax 1

Invoice Tax 01: Label : What to call this tax on invoices, for example "State Sales Tax"

Invoice Tax 01: Rate : The percentage rate for this tax, for example, "8.625"


Tax 2

Invoices: Tax 02 Enable : Whether or not to calculate tax 2 on items tagged as taxable by tax 2

Invoice Tax 02: Label : What to call this tax on invoices, for example "County Sales Tax"

Invoice Tax 02: Rate : The percentage rate for this tax, for example, "5.00"


Both Taxes

Display Digits: Tax Percent : How many digits after the decimal point to display the tax rate? For example, Canadian HST rate could be zero or two (5.00% HST) whereas New York sales tax needs three digits (8.625% Tax)

Display Digits: Tax Amount: Most jurisdictions require that the tax amount be displayed to two digits the same as currency, but New York requires that the tax amount be displayed to three digits, such as $8.625

Invoice Taxes: Tax By Item : Whether to calculate the taxes on each item individually and keep a running total, or simply calculate the taxes on the invoice totals.

Invoice Taxes: Prices Include Taxes : Some jurisdictions such as Australia require that website prices be tax-included. If "No", phpCOIN will add applicable taxes to items on invoices. If "Yes", phpCOIN assumes that the prices include tax. In that event, taxes will be removed from the items and then recalculated, so the invoice can show the amount of taxes included in the prices. For example, on an item that is priced at $100 with Tax 1 as 10%:

ON:

Items Sub-total: $100.00
Tax Included:      $9.09 (item cost - (item_cost / (1+(tax 1 percent / 100))))
Total:           $100.00

OFF:

Items Sub-total: $100.00
Tax Included:     $10.00 (item cost * tax 1 percent)
Total:           $110.00


Products Taxes

Each individual product or service has three flags, as follows:

Apply Tax 01: Whether or not tax 1 must be charged on this product or service

Apply Tax 02: Whether or not tax 2 must be charged on this product or service

Calc Tax 02 On Tax 01: Some tax jurisdictions require that tax 1 be added to the product and that tax 2 be calculated on the sum of the cost plus tax 1, while other jurisdictions calculate tax 2 only on the cost and ignore tax 1. For example, on an item that is priced at $100 with Tax 1 at 10% and Tax 2 also at 10%:

ON:

Items Sub-total: $100.00
Tax 1:            $10.00
Tax 2:            $11.00 (10% of $110)
Total:           $121.00

OFF:

Items Sub-total: $100.00
Tax 1:            $10.00
Tax 2:            $10.00 (10% of $100)
Total:           $120.00


Invoices

Auto-generated invoices will use the values specified above. Manually generated invoices will select these values as the defaults, but you can over-ride whether or not to calculate tax, the rates, and whether phpCOIN should auto-calculate taxes or use the amounts you manually enter, while creating the invoice.

If you have taxes disabled, then no tax options will appear when editing products or invoices, nor will tax information be displayed when viewing products or invoices.


Multiple or Changed Tax Rates

For most people the setup of Tax1 and Tax2 will suit their needs forever. Sometimes though, one or more of the tax rates needs to be different for one reason or another. An example is Canadian Provincial Sales Tax, which may or may not be charged based on the provice of the buyer in relation to the location of the seller. Another example is the Canadian GST/HST, which has changed the rate twice over the last five years.

phpCOIN v1.4.2 and higher has the capability of great flexibility in tax calculation due to the automatic use of a tax override file, which can be used to override the tax rates(s) set in Admin Parameters. The override file simply needs to change the value of $adata['invc_tax_01_percent'] and/or $adata['invc_tax_02_percent'] according to whatever criteria you need.

Override Filename and Location:

  • For phpCOIN v1.4.2 name the file invoice_tax2_override.php and place it in the root folder of the phpCOIN website.
  • For phpCOIN v1.4.3 to v1.4.5 name the file invoice_tax2_override.php and place it in the /coin_overrides folder.
  • For phpCOIN v1.4.6 and higher, name the file invoice_tax_override.php and place it in the /coin_overrides folder.

At run-time, if the override file exists, phpCOIN will load it and do whatever the file says when calculating invoice totals. Some specific examples of override files for different situations are detailed below.

This feature does NOT update the tax from invoices copied prior to the tax change !!

For invoices that are copied manually or by the scheduled cron job, you will have to manually edit the tax, tax amount, invoice total and paylink.


Multiple Tax2 Rates Based on Client Location

The combination of tax1 setup as GST and tax2 setup as PST will usually meet the needs of Canadian users. Sometimes, however, a Canadian seller may need to handle multiple tax2 rates depending on where the product is being shipped to or where the service is deemed to be performed in. The contents of the override file should be similar to the following:

<?php
/**
 * Override tax2 percentage rate depending on client location
 */

# First we retrieve invoice/client info so we can determine the client's province
	$query	 = 'SELECT * FROM '.$_DBCFG['clients'].', '.$_DBCFG['invoices'];
	$query	.= ' WHERE '.$_DBCFG['clients'].'.cl_id='.$_DBCFG['invoices'].'.invc_cl_id';
	$query	.= ' AND '.$_DBCFG['invoices'].'.invc_id='.$adata['invc_id'];
	$result	 = $db_coin->db_query_execute($query);
	while ($row = $db_coin->db_fetch_array($result)) {$_prov = $row['cl_state_prov'];}

# Then we over-ride tax2 rate based on client's province
# We can add more provinces and rates here, and even override the tax2 description
	IF ($_prov == 'QC') {		// Charge 7.5% for Quebec
		$adata['invc_tax_02_percent'] = 7.5;
	} ELSEIF ($_prov == 'BC') {	// Charge 7.0% for British Columbia
		$adata['invc_tax_02_percent'] = 7;
	} ELSE {			// Charge 0% for everywhere else
		$adata['invc_tax_02_percent'] = 0;
	}
?>

In this example, phpCOIN will over-ride the tax2 percentages depending on the customer's location before adding taxes to the invoice or recalculating taxes, as the case may be.


Multiple Tax1 Rates Based on Invoice Number

When your tax authority changes a tax rate over time, you cannot just change the rate in Admin -> Parameters because the old invoices will display the new rate when viewed/emailed/printed, and the tax amount calculated will change to use the new rate if the invoice is edited for any reason. The contents of the override file should be similar to the following:

<?php
/**
 * Override tax1 percentage rate depending on invoice number
 * Check for the OLDEST invoice first, then check for newer and newer
 * until we are finally at the newest invoices.
 */

# If the invoice number is less than 1000 the rate is 15%
     IF ($row['invc_id'] < 1000) {
          $adata['invc_tax_01_percent'] = 15;

# But if the invoice number is more than 1000 but less than 2000 the rate is 14%
     } ELSEIF ($row['invc_id'] < 2000) {
          $adata['invc_tax_01_percent'] = 14;

# Otherwise the rate is 13%
     } ELSE {
          $adata['invc_tax_01_percent'] = 13;
     }

?>

In this example, phpCOIN will over-ride the tax1 percentages depending on the invoice number before adding taxes to the invoice or recalculating taxes, as the case may be.


Multiple Tax1 Rates Based on Invoice Date

When your tax authority changes a tax rate over time, you cannot just change the rate in Admin -> Parameters because the old invoices will display the new rate when viewed/emailed/printed, and the tax amount calculated will change to use the new rate if the invoice is edited for any reason. The contents of the override file should be similar to the following:

<?php
/**
 * Override tax1 percentage rate depending on invoice date
 * Check for the OLDEST invoice first, then check for newer and newer
 * until we are finally at the newest invoices.
 * The date is a *nix timestamp
 */

# If the invoice date is before 2002-01-01 the rate is 15%
     IF ($row['invc_ts'] < 1009843201) {
          $adata['invc_tax_01_percent'] = 15;

# But if the invoice date is after 2002-01-01 but before 2005-01-01 the rate is 14%
     } ELSEIF ($row['invc_ts'] < 1104537601) {
          $adata['invc_tax_01_percent'] = 14;

# Otherwise the rate is 13%
     } ELSE {
          $adata['invc_tax_01_percent'] = 13;
     }

?>

In this example, phpCOIN will over-ride the tax1 percentages depending on the invoice date before adding taxes to the invoice or recalculating taxes, as the case may be.

Change Item Tax Flags

If you need to manipulate the individual items on an invoice immediately prior to taxes being calculated, for example to set the tax 2 piggyback on/off depending on client location, that is accomplished as of phpCOIN v1.6.0 with an 'invoice_items_override.php' file located in the /coin_overrides folder. You should change the values of $row['ii_apply_tax_02'] and $row['ii_calc_tax_02_pb'] and $row['ii_apply_tax_01'] in order to affect the tax calculations, using code similar to the Multiple Tax2 Rates Based on Client Location sample above

Personal tools

Inscrita el Registro Mercantil de Mallorca Tomo 2140, Hoja No. PM-51034, Folio 135
This website owned and operated by: Technology Services RPVW S.L. CIF# B57345084
Avda Constitucion 48 Bajos Alaro 07340 Baleares SPAIN
Tel:+34 971518362    Fax: +34 971518368    eMail: support@phpcoin.com