WebsiteBaker Support (2.8.x) > Bakery Shop
Bakery for Canada
jacobi22:
i try to implemented your code from the last post. Did it work for you? if yes - whats your main bakery settings?
i use for a test
Shop Land == Canada
Shop Province / State == Manitoba (or others)
i try different tax setting, Shop Land, Shop State, Nothing
Tax Rate == 0%, 13%, 0%
My Customer Adress data in the adress form
Country == Canada
State == different to the shop state in my settings
if everything works for you, maybe i've a problem to understand
but if its not work, i'm sure, that the order in the code is the problem
i'll wait for your answer before i write a new (wrong) code
jacobi22:
if i understand everything correct, here my version
but it works for canada only - do you sell products to other country too??
my settings in the shop:
Shop Land == Canada
Shop State = Alberta
Tax == Shop Land
Tax rate == 0%
Price inclusive Tax? == NO
startet at line ~364 of the view_summary.php
--- Code: ---// CALCULATE ITEMS SALES TAX
// *************************
// Initialize vars
$sales_tax = 0;
$f_tax_rate_array = array();
// Calculate tax for Canadian Shop Shipping to Canadian Province/Territory
if (!empty($shipping_state_code)) {
$shipping_prov_code = $shipping_state_code;
}
else {
$shipping_prov_code = $cust_state_code;
}
$can_gst = array("AB","BC","SK","MB","QC","YT","NT","NU");
$can_hst = array("ON","NL","NB");
// Calculate items sales tax
for ($i = 1; $i <= sizeof($items); $i++) {
if(in_array($shipping_prov_code, $can_gst))
{$sItemTaxRate[$i] = 5;
}
elseif(in_array($shipping_prov_code, $can_hst))
{$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);
}
--- End code ---
i use in_array(), array_search doesnt give the key No == 0, it sends false for that
testet with all your provinces with two articles with different item price
sky writer:
Here is how far I got:
--- Code: ---// CALCULATE ITEMS SALES TAX
// *************************
// Initialize vars
$sales_tax = 0;
$f_tax_rate_array = array();
// Calculate Canadian tax based on shipping destination
if (!is_null($shipping_state_code)) {
$shipping_prov_code = $shipping_state_code;
}
else {
$shipping_prov_code = $cust_state_code;
}
$ca_gst = array("BC","AB","SK","MB","QC","YT","NT","NU");
$ca_hst = array("ON","NL","NB");
if(array_search($shipping_prov_code, $ca_gst))
{$sItemTaxRate = 5;
}
elseif(array_search($shipping_prov_code, $ca_hst))
{$sItemTaxRate = 13;
}
elseif($shipping_prov_code == "PE")
{$sItemTaxRate = 14;
}
elseif($shipping_prov_code == "NS")
{$sItemTaxRate = 15;
}
else {
$sItemTaxRate = $items[$i]['tax_rate'];
}
// 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 + $sItemTaxRate);
// $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 * $sItemTaxRate;
// $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($sItemTaxRate, 1);
// $f_tax_rate_array[] = number_format($items[$i]['tax_rate'], 1);
}
--- End code ---
Everything worked except when the customer's province was Ontario (ON), then no tax was added (it should have been 13%). I thought it might be because it matched the shop_state, but then I changed the shop_state to another province and still Ontario did not show the proper tax of 13%. Can't figure that out.
Your code works. Is the key the "i" variable in $sItemTaxRate[$i]?
My shop_country is Canada
shop_state is Ontario
Tax: Shop Country
Tax Rate Product: 0% 0% 0%
Prices including tax: No
This shop will mainly ship to Canada, but also anywhere else. But no tax is charged when shipping outside Canada. Which seems to work with the code I have in place.
Now I just have to make the tax on shipping act the same way (tax on shipping based on shipping province). Can I do this in the view_summary.php file as well, or do I have to go further?
sky writer:
I seem to have the CANADIAN shipping tax based on shipping destination working now as well.
~ line 735
--- Code: ---// CALCULATE SHIPPING SALES TAX
// ****************************
// 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[$i] = 5;
}
elseif(in_array($ship_tax_prov_code, $hst_ca))
{$sShipTaxRate[$i] = 13;
}
elseif($ship_tax_prov_code == "PE")
{$sShipTaxRate[$i] = 14;
}
elseif($ship_tax_prov_code == "NS")
{$sShipTaxRate[$i] = 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[$i] / (100 + $sShipTaxRate[$i]);
//$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 * $sShipTaxRate[$i];
// $sales_tax_shipping = $shipping / 100 * $setting_tax_rate_shipping;
}
--- End code ---
Many thanks Jacobi for your guidance.
jacobi22:
--- Quote from: sky writer on October 13, 2015, 03:23:40 AM ---Everything worked except when the customer's province was Ontario (ON), then no tax was added (it should have been 13%). I thought it might be because it matched the shop_state, but then I changed the shop_state to another province and still Ontario did not show the proper tax of 13%. Can't figure that out.
--- End quote ---
i write this yesterday - use in_array() instead of array_search()
--- Quote from: sky writer on October 13, 2015, 03:23:40 AM --- Is the key the "i" variable in $sItemTaxRate[$i]?
--- End quote ---
[i.] is a counter for the loop's btw for the items in the for-loop here
--- Code: ---// Calculate items sales tax
for ($i = 1; $i <= sizeof($items); $i++) {
--- End code ---
it counts the different kind of articles. $items is a big array with all item datas from the items in the basket. every array-part has the datas for this one item (quantity, price, tax-rate etc)
if you dont use the counter [i.] to split the item array, the next loop for the next item use the item datas from the last loop
--- Quote from: sky writer on October 13, 2015, 03:23:40 AM ---Now I just have to make the tax on shipping act the same way (tax on shipping based on shipping province). Can I do this in the view_summary.php file as well, or do I have to go further?
--- End quote ---
i see, you solved the problem ;-) (Y)
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.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version