LaravelDaily / laravel-invoices

Laravel package to generate PDF invoices from various customizable parameters
GNU General Public License v3.0
1.4k stars 304 forks source link

How to fix price after tax? #101

Closed tdrabikdev closed 3 years ago

tdrabikdev commented 3 years ago

Describe the bug Tax is rounded up and it give a wrong sum on invoice.

To Reproduce

        $customer = new Buyer([
            'name'          => 'John Doe',
            'custom_fields' => [
                'email' => 'test@example.com',
            ],
        ]);

        $item = (new InvoiceItem())->title('Service 1')->pricePerUnit(8.33);

        $invoice = Invoice::make()
            ->buyer($customer)

            ->taxRate(20)
            ->addItem($item);

        return $invoice->stream();

Expected behavior gross price £9.99, tax 20%, net price £8.33 tax:£ 1.66 price on invoice £9.99

Result gross price £9.99, tax 20%, net price £8.33 tax:£ 1.67 price on invoice £10.00

Screenshots

image

Desktop (please complete the following information):

mc0de commented 3 years ago

Actually this is expected behavior, because 20% of 8.33 is 1.(6) so it gets rounded to 1.67 Specifically for this case and if it might be an issue for someone we provide override methods, but then you need to calculate taxes yourself and pass the result as a parameter

<...>
        $invoice = Invoice::make()
            ->buyer($customer)
            ->totalTaxes(1.66)
            ->addItem($item);

        return $invoice->stream();

see more on README.md in General section