- Posts: 86
- Thank you received: 2
invoice: add tax rate in every product line
12 years 10 months ago - 12 years 10 months ago #131974
by scharfet
invoice: add tax rate in every product line was created by scharfet
-- HikaShop version -- : 2.2.2
-- Joomla version -- : 2.5.14
Hello I modified the invoice.php in order to display the tax rate. It is working fine when a product is added by the customer, but when I modify an order (add aproduct via backend, selecting one of the existing products/variants) the invoice and shipping invoice show following error message
Error message:
A screenshot with the error.
I observed a difference in the database in hikashop_order_product table in order_product_tax_info column when a product / varian is added in frontend or in backen.
When added in Frontend:
When added in Backend
Why the difference? Can I avoid the the difference in the code or Is this normal?
The code I added to the invoice.php
Line 146:
Please coul you help me fixing this problem?
-- Joomla version -- : 2.5.14
Hello I modified the invoice.php in order to display the tax rate. It is working fine when a product is added by the customer, but when I modify an order (add aproduct via backend, selecting one of the existing products/variants) the invoice and shipping invoice show following error message
Error message:
Code:
Notice: Undefined property: stdClass::$tax_rate in /homez.428/monpetit/www/administrator/templates/bluestork/html/com_hikashop/order/invoice.php on line 146
A screenshot with the error.
I observed a difference in the database in hikashop_order_product table in order_product_tax_info column when a product / varian is added in frontend or in backen.
When added in Frontend:
Code:
a:1:{i:0;O:8:"stdClass":12:{s:11:"taxation_id";s:1...
Code:
a:1:{i:0;O:8:"stdClass":2:{s:11:"tax_namekey";s:7:...
The code I added to the invoice.php
Code:
// tax calculation start -
$tax = " ";
if (is_array($product->order_product_tax_info)) {
$tax_rate = $product->order_product_tax_info[0]->tax_rate * 100;
$tax_amount = $product->order_product_tax_info[0]->tax_amount * $product->order_product_quantity;
$product_amount = $product->order_product_price * $product->order_product_quantity;
$tax_total += $tax_amount;
if ($tax_rate>0) {
if ($tax_rate == (int)$tax_rate) $tax = sprintf("%d",$tax_rate);
else $tax = sprintf("%0.2f",$tax_rate);
$taxes_array[$tax] = @$taxes_array[$tax] + $tax_amount;
$products_array[$tax] = @$products_array[$tax] + $product_amount + $tax_amount;
$tax.=" %";
}
} // tax
Line 146:
Code:
$tax_rate = $product->order_product_tax_info[0]->tax_rate * 100;
Please coul you help me fixing this problem?
Last edit: 12 years 10 months ago by scharfet.
Please Log in or Create an account to join the conversation.
12 years 10 months ago #132190
by Xavier
Replied by Xavier on topic invoice: add tax rate in every product line
Hi,
When you are adding this product from backend, do you select the correct tax percentage in the dropdown on the right of the field of the option VAT ? That should be added to the order.
When you are adding this product from backend, do you select the correct tax percentage in the dropdown on the right of the field of the option VAT ? That should be added to the order.
Please Log in or Create an account to join the conversation.
12 years 10 months ago - 12 years 10 months ago #132241
by scharfet
Replied by scharfet on topic invoice: add tax rate in every product line
Hi Xavier,
yes, I added the correct tax percentage from the dropdown list.
I see in the database that the column order_product_tax_info a different code when product is added in backend.
I thik the error occurs because the code added in my invoice.php can not read the tax rate when the tax rate was adden manually from dropdown list.
I hope I do explain myself.
yes, I added the correct tax percentage from the dropdown list.
I see in the database that the column order_product_tax_info a different code when product is added in backend.
I thik the error occurs because the code added in my invoice.php can not read the tax rate when the tax rate was adden manually from dropdown list.
Code:
// tax calculation start -
$tax = " ";
if (is_array($product->order_product_tax_info)) {
$tax_rate = $product->order_product_tax_info[0]->tax_rate * 100;
$tax_amount = $product->order_product_tax_info[0]->tax_amount * $product->order_product_quantity;
$product_amount = $product->order_product_price * $product->order_product_quantity;
$tax_total += $tax_amount;
if ($tax_rate>0) {
if ($tax_rate == (int)$tax_rate) $tax = sprintf("%d",$tax_rate);
else $tax = sprintf("%0.2f",$tax_rate);
$taxes_array[$tax] = @$taxes_array[$tax] + $tax_amount;
$products_array[$tax] = @$products_array[$tax] + $product_amount + $tax_amount;
$tax.=" %";
}
} // tax
I hope I do explain myself.
Last edit: 12 years 10 months ago by scharfet.
Please Log in or Create an account to join the conversation.
12 years 10 months ago #132363
by Xavier
Replied by Xavier on topic invoice: add tax rate in every product line
Hi,
I just tried on my local and yes indeed, there is some missing data in the tax infos.
But as temporary fix, you could do the following thing to get the tax percentage:
I just tried on my local and yes indeed, there is some missing data in the tax infos.
But as temporary fix, you could do the following thing to get the tax percentage:
Code:
$str = $product->order_product_price;
$length = strlen(substr(strrchr($str, "."), 1)) - 1;
$nb = pow(10,$length);
$tax = $product->order_product_tax * $nb / $product->order_product_price *100.'%';
Please Log in or Create an account to join the conversation.
12 years 10 months ago - 12 years 10 months ago #132370
by scharfet
Replied by scharfet on topic invoice: add tax rate in every product line
Hi Xavier,
I do not know how to implement your code you offered in your last post into the code I have in my invoice.php.
Please could you help me?
Thank you!
PS: Did I understand you right, that the error is caused by an missing code in Hikashop and in the next version of Hikashop it will be fixed? When will the next version come out, in some weeks or some months?
I do not know how to implement your code you offered in your last post into the code I have in my invoice.php.
Please could you help me?
Thank you!
PS: Did I understand you right, that the error is caused by an missing code in Hikashop and in the next version of Hikashop it will be fixed? When will the next version come out, in some weeks or some months?
Code:
<?php
$k=0;
$group = $this->config->get('group_options',0);
$products_array = $taxes_array = array(); $tax_total = 0; //added
foreach($this->order->products as $product){
if($group && $product->order_product_option_parent_id) continue;
// tax calculation START MODIFIED CODE =========================================
$tax = " ";
if (is_array($product->order_product_tax_info)) {
$tax_rate = $product->order_product_tax_info[0]->tax_rate * 100;
$tax_amount = $product->order_product_tax_info[0]->tax_amount * $product->order_product_quantity;
$product_amount = $product->order_product_price * $product->order_product_quantity;
$tax_total += $tax_amount;
if ($tax_rate>0) {
if ($tax_rate == (int)$tax_rate) $tax = sprintf("%d",$tax_rate);
else $tax = sprintf("%0.2f",$tax_rate);
$taxes_array[$tax] = @$taxes_array[$tax] + $tax_amount;
$products_array[$tax] = @$products_array[$tax] + $product_amount + $tax_amount;
$tax.=" %";
}
} // tax END MODIFIED CODE =========================================
?>
Last edit: 12 years 10 months ago by scharfet.
Please Log in or Create an account to join the conversation.
12 years 10 months ago #132445
by Xavier
Replied by Xavier on topic invoice: add tax rate in every product line
The code given should be enough to replace yours to display the tax percentage I think.
As I can see in $tax you are just storing the tax percentage, and that's what my code is doing too.
As I can see in $tax you are just storing the tax percentage, and that's what my code is doing too.
Please Log in or Create an account to join the conversation.
12 years 10 months ago - 12 years 10 months ago #132463
by scharfet
Code in line 150:
When I subsitute the following code with your code I get the error message which you can see above:
Error ocurrs wen I delete the above code and replace it with the follwoing code:
Each product line has this code:
Thank you for your help.
Replied by scharfet on topic invoice: add tax rate in every product line
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /homez.428/monpetit/www/administrator/templates/bluestork/html/com_hikashop/order/invoice.php on line 150
Code in line 150:
Code:
$tax = $product->order_product_tax * $nb / $product->order_product_price *100.'%';
When I subsitute the following code with your code I get the error message which you can see above:
Code:
<?php
$k=0;
$group = $this->config->get('group_options',0);
$products_array = $taxes_array = array(); $tax_total = 0; //added
foreach($this->order->products as $product){
if($group && $product->order_product_option_parent_id) continue;
// tax calculation START MODIFIED CODE =========================================
$tax = " ";
if (is_array($product->order_product_tax_info)) {
$tax_rate = $product->order_product_tax_info[0]->tax_rate * 100;
$tax_amount = $product->order_product_tax_info[0]->tax_amount * $product->order_product_quantity;
$product_amount = $product->order_product_price * $product->order_product_quantity;
$tax_total += $tax_amount;
if ($tax_rate>0) {
if ($tax_rate == (int)$tax_rate) $tax = sprintf("%d",$tax_rate);
else $tax = sprintf("%0.2f",$tax_rate);
$taxes_array[$tax] = @$taxes_array[$tax] + $tax_amount;
$products_array[$tax] = @$products_array[$tax] + $product_amount + $tax_amount;
$tax.=" %";
}
} // tax END MODIFIED CODE =========================================
?>
Error ocurrs wen I delete the above code and replace it with the follwoing code:
Code:
<?php
$str = $product->order_product_price;
$length = strlen(substr(strrchr($str, "."), 1)) - 1;
$nb = pow(10,$length);
$tax = $product->order_product_tax * $nb / $product->order_product_price *100.'%'; ?>
Each product line has this code:
Code:
<?php echo $this->currencyHelper->format($product->order_product_price+$product->order_product_tax,$this->order->order_currency_id); ?>
Thank you for your help.
Last edit: 12 years 10 months ago by scharfet.
Please Log in or Create an account to join the conversation.
12 years 10 months ago #132539
by Xavier
Replied by Xavier on topic invoice: add tax rate in every product line
And what about that code:
Code:
<?php
$str = $product->order_product_price;
$length = strlen(substr(strrchr($str, "."), 1)) - 1;
$nb = pow(10,$length);
$tax = $product->order_product_tax * $nb / $product->order_product_price * 100;
$tax .= '%';
?>
Please Log in or Create an account to join the conversation.
Time to create page: 0.216 seconds