WebsiteBaker Support (2.8.x) > Bakery Shop
Bakery for Canada
sky writer:
--- Quote ---i use in_array(), array_search doesnt give the key No == 0, it sends false for that
--- End quote ---
I missed that line, sorry, and thank you. I don't understand this part - "key No == 0, it sends false for that". But I will do some homework and figure it out.
--- Quote ---Tip: make a renamed copy from this view_summary.php (maybe view_summary_canada .php) and let it stay in the bakery-folder as a backup. so that you dont overwrite your work in the next upgrade.
--- End quote ---
Wise advice, thank you!
sky writer:
In an effort to incorporate Canada's confusing tax laws into the Bakery WITHOUT affecting the module for those operating outside of Canada, I added a couple of checks for the $setting_shop_country so only those shops with Canada 'CA' set as their "Shop Country" will run the new code. I hope this helps someone. I welcome any feedback or improvements to my code. Much credit to Jacobi for his guidance and expertise.
I have only tested this with Bakery v1.72 on WB 2.8.3 SP4
All changes take place in view_summary.php
~line 293
after:
--- Code: ---// Convert state code to state name
--- End code ---
add:
--- Code: ---// Retain shipping state code for Canadian sales tax calculation
$shipping_state_code = $ship_state;
--- End code ---
starting ~line 362
replace:
--- Code: ---// CALCULATE ITEMS SALES TAX
// *************************
// Initialize vars
$sales_tax = 0;
$f_tax_rate_array = array();
// Calculate items sales tax
for ($i = 1; $i <= sizeof($items); $i++) {
if ($setting_tax_included == 'included') {
// Calculate tax amount for prices including tax (brutto)
$sales_tax = $sales_tax + $items[$i]['price'] * $items[$i]['quantity'] * $items[$i]['tax_rate'] / (100 + $items[$i]['tax_rate']);
}
else {
// Calculate tax amount for prices excluding tax (netto)
$sales_tax = $sales_tax + $items[$i]['price'] * $items[$i]['quantity'] / 100 * $items[$i]['tax_rate'];
}
// Get tax rate(s) for display
$f_tax_rate_array[] = number_format($items[$i]['tax_rate'], 1);
}
--- End code ---
with:
--- Code: ---// CALCULATE ITEMS SALES TAX
// *************************
// Initialize vars
$sales_tax = 0;
$f_tax_rate_array = array();
// Check if Shop Country is Canada
if ($setting_shop_country=='CA') {
// Canadian Shop - Check if there is a shipping address
if (!is_null($shipping_state_code)) {
$shipping_prov_code = $shipping_state_code;
}
else {
$shipping_prov_code = $cust_state_code;
}
$gst_ca = array("AB","BC","SK","MB","QC","YT","NT","NU");
$hst_ca = array("ON","NL","NB");
// Calculate Canadian tax on total order based on shipping destination
for ($i = 1; $i <= sizeof($items); $i++) {
// Calculate items Canadian sales tax
if(in_array($shipping_prov_code, $gst_ca))
{$sItemTaxRate[$i] = 5;}
elseif(in_array($shipping_prov_code, $hst_ca))
{$sItemTaxRate[$i] = 13;}
elseif($shipping_prov_code == "PE")
{$sItemTaxRate[$i] = 14;}
elseif($shipping_prov_code == "NS")
{$sItemTaxRate[$i] = 15;}
else {
$sItemTaxRate = $items[$i]['tax_rate'];
}
if ($setting_tax_included == 'included') {
// Calculate tax amount for prices including tax (brutto)
$sales_tax = $sales_tax + $items[$i]['price'] * $items[$i]['quantity'] * $sItemTaxRate[$i] / (100 + $sItemTaxRate[$i]);
}
else {
// Calculate tax amount for prices excluding tax (netto)
$sales_tax = $sales_tax + $items[$i]['price'] * $items[$i]['quantity'] / 100 * $sItemTaxRate[$i];
}
// Get tax rate(s) for display
$f_tax_rate_array[] = number_format($sItemTaxRate[$i], 1);
}
}
else{
// Calculate items sales tax
for ($i = 1; $i <= sizeof($items); $i++) {
if ($setting_tax_included == 'included') {
// Calculate tax amount for prices including tax (brutto)
$sales_tax = $sales_tax + $items[$i]['price'] * $items[$i]['quantity'] * $items[$i]['tax_rate'] / (100 + $items[$i]['tax_rate']);
}
else {
// Calculate tax amount for prices excluding tax (netto)
$sales_tax = $sales_tax + $items[$i]['price'] * $items[$i]['quantity'] / 100 * $items[$i]['tax_rate'];
}
// Get tax rate(s) for display
$f_tax_rate_array[] = number_format($items[$i]['tax_rate'], 1);
}
}
--- End code ---
That takes care of the item tax based on the shipping destination.
Now for the shipping tax based on shipping destination:
starting ~line 743
replace:
--- Code: ---// CALCULATE SHIPPING SALES TAX
// ****************************
// Calculate tax amount for shipping including tax (brutto)
if ($setting_tax_included == 'included') {
$sales_tax_shipping = $shipping * $setting_tax_rate_shipping / (100 + $setting_tax_rate_shipping);
}
else {
// Calculate tax amount for shipping excluding tax (netto)
$sales_tax_shipping = $shipping / 100 * $setting_tax_rate_shipping;
}
--- End code ---
with:
--- Code: ---// CALCULATE SHIPPING SALES TAX
// ****************************
// Check if Shop Country is Canada
if ($setting_shop_country=='CA') {
// Calculate Canadian shipping tax based on shipping destination
$ship_tax_prov_code = $shipping_prov_code;
// Calculate shipping Canadian sales tax
if(in_array($ship_tax_prov_code, $gst_ca))
{$sShipTaxRate = 5;
}
elseif(in_array($ship_tax_prov_code, $hst_ca))
{$sShipTaxRate = 13;
}
elseif($ship_tax_prov_code == "PE")
{$sShipTaxRate = 14;
}
elseif($ship_tax_prov_code == "NS")
{$sShipTaxRate = 15;
}
else {
$sShipTaxRate = $setting_tax_rate_shipping;
}
// Calculate tax amount for shipping including tax (brutto)
if ($setting_tax_included == 'included') {
$sales_tax_shipping = $shipping * $sShipTaxRate / (100 + $sShipTaxRate);
}
else {
// Calculate tax amount for shipping excluding tax (netto)
$sales_tax_shipping = $shipping / 100 * $sShipTaxRate;
}
}
else {
// Calculate tax amount for shipping including tax (brutto)
if ($setting_tax_included == 'included') {
$sales_tax_shipping = $shipping * $setting_tax_rate_shipping / (100 + $setting_tax_rate_shipping);
}
else {
// Calculate tax amount for shipping excluding tax (netto)
$sales_tax_shipping = $shipping / 100 * $setting_tax_rate_shipping;
}
}
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version