cancel
Showing results for 
Search instead for 
Did you mean: 

How to get tax listing from invoice object

SOLVED

How to get tax listing from invoice object

Good Morning,

 

I am stuck here with the following problem:
For an invoice-object I need all tax-percentages, tax-amounts and
total without tax that were processed within this invoice

 

Eg:

20%, 5€, 25€

10%,5€,50€

0%,0€,100€

...

How can I achieve that? is there any documentation about the classes in Magento2?
For the moment it is just trial and error for me Smiley Sad

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to get tax listing from invoice object

Hello,

 

Let's example you have invoice item and object name for invoice item is $invoiceItem

 

echo $invoiceItem->getOrderItem()->getTaxPercent()

By above code you will get Percentage for specific item.

 

If it will work or help you then mark as solutionSmiley Happy


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

5 REPLIES 5

Re: How to get tax listing from invoice object

Hello,

 

Hope you have invoice object

 

let's example your invoice object name is $invoice

 

echo $invoice->getTaxAmount();

above code for get Tax value from invoice

 

echo $invoice->getBaseGrandTotal();

above code get base total.

 

for percentage you will get from all invoice item.

 

Hope it will work for you.

 

If it will help you, then mark as solution


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to get tax listing from invoice object

Hi, thanks.
So far so good, but my problem is, that we have different taxes for
different kinds of goods. So one invoice can contain different items with
different tax percentages.

Is there a way to get an array with tax percentages and totals for each tax
percentages?

Regards,
Gunther

Re: How to get tax listing from invoice object

Hello,

 

Let's example you have invoice item and object name for invoice item is $invoiceItem

 

echo $invoiceItem->getOrderItem()->getTaxPercent()

By above code you will get Percentage for specific item.

 

If it will work or help you then mark as solutionSmiley Happy


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

Re: How to get tax listing from invoice object

@kornblumenapo

 

is that work for you?


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to get tax listing from invoice object

@kornblumenapo, you can loop all the items of invoice object and create an array for tax percentage based on product if or sku & then do rest calculation.$taxes

$taxes = [];
foreach ($invoice->getAllItems() as $item) {
	$taxes[$item->getProductId()] = $item->getTaxPercent();
}

Then in $taxes, you will get taxes for each product id.