LaravelDaily / laravel-invoices

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

Precalculation #220

Closed alexcinergy closed 10 months ago

alexcinergy commented 10 months ago

Hello!

Is it possible to make a precalculation of the invoice before send it to the browser?

I want to use your calculation() method, but once I've use it then when I sending it to the browser I got:

Exception: Invoice: you must have taxes only on items or only on invoice in file "/vendor/laraveldaily/laravel-invoices/src/Traits/InvoiceHelpers.php on line 356"

Because there is a check for:

if ($item->hasTax() && $this->hasTax()) {
    throw new Exception('Invoice: you must have taxes only on items or only on invoice.');
}

Please assist.

alexcinergy commented 10 months ago

I have extend your class with 2 extra methods like

Get calculation: public function prepare()

    {
        parent::validate();
        parent::calculate();
    }

Reset before stream

    public function reset()
    {
        $this->hasItemTax = $this->total_taxes = $this->total_discount = $this->taxable_amount = 0;
    }

But not sure am I right

mc0de commented 10 months ago

@alexcinergy it is not clear for me what you're trying to do.

What is the real problem are you trying to solve?

Tax exception is for a reason, usually you should be doing one of this:

mc0de commented 10 months ago

Closing as there is no further explanation provided.

See https://xyproblem.info/