BambooInvoice Forums

Rounding errors

 
Total Posts: 15

Hi,
I was entering historic data for the first couple of months my business was operating (before I got BI working) and it came up with the following:

Amount: $90.00
Goods and Services Tax (12.500%): $11.25
Total: $101.28
Amount Paid: $101.25
Amount Outstanding: $0.03

Obviously this invoice should be closed but now shows as overdue.
There were 6 line items, each at $15.00

0 + 25 = 28 only for extremely large values of 25!

Total Posts: 15

Update: For another client with 6 units (my service costs $15 a pop always) I entered them as a single line item and avoided the problem - so the rounding error would appear to be related to summing multiple line items.

If tax is being calculated per line:

0.125 * 15 = 1.875

6 * 1.875 = 11.25

BUT

6 * 1.88 = 11.28

hence you shouldn’t round the tax per line, only ever round totals.
(Analysis done without looking at the source code, since I am hopeless at finding which bit of php does what)

Total Posts: 9

Update: read update below.

I had the exact same problem and fixed it just now for at least one invoice (it’s late and I don’t have another multi-item invoice that I can test it with, and I want to post my “fix”) by changing line 100 of

bamboo_system_files/application/models/invoices_model.php

in the function getSingleInvoice($invoice_id)

which was reading:

$this->db->select(’(SELECT SUM(’.$this->db->dbprefix(‘invoice_items’).’.amount * ‘.$this->db->dbprefix(‘invoice_items’).’.quantity + ROUND((’.$this->db->dbprefix(‘invoice_items’).’.amount * ‘.$this->db->dbprefix(‘invoice_items’).’.quantity * (’.$this->db->dbprefix(‘invoices’).’.tax1_rate/100 + ‘.$this->db->dbprefix(‘invoices’).’.tax2_rate/100) * ‘.$this->db->dbprefix(‘invoice_items’).’.taxable), 2)) FROM ‘.$this->db->dbprefix(‘invoice_items’).’ WHERE ‘.$this->db->dbprefix(‘invoice_items’).’.invoice_id=’ . $invoice_id . ‘) AS total_with_tax’, FALSE);

to

$this->db->select(’(SELECT SUM(’.$this->db->dbprefix(‘invoice_items’).’.amount * ‘.$this->db->dbprefix(‘invoice_items’).’.quantity + ROUND((’.$this->db->dbprefix(‘invoice_items’).’.amount * ‘.$this->db->dbprefix(‘invoice_items’).’.quantity * (’.$this->db->dbprefix(‘invoices’).’.tax1_rate/100 + ‘.$this->db->dbprefix(‘invoices’).’.tax2_rate/100) * ‘.$this->db->dbprefix(‘invoice_items’).’.taxable), 5)) FROM ‘.$this->db->dbprefix(‘invoice_items’).’ WHERE ‘.$this->db->dbprefix(‘invoice_items’).’.invoice_id=’ . $invoice_id . ‘) AS total_with_tax’, FALSE);

Notice the change of the ROUND digits from 2 to 5, just before the FROM statement.

I tested the rounding by setting the numberformat also to 5 in (around) line 311 of

bamboo_system_files/application/controllers/invoices.php

$data[‘total_with_tax’] = $this->lang->line(‘invoice_total’).’: ‘.$this->settings_model->get_setting(‘currency_symbol’).’ ‘.number_format($data[‘row’]->total_with_tax, 2, $this->config->item(‘currency_decimal’), ‘’).”
\n”;;

You can change that but change it back to 2 for your official invoices.

Update: Reading Zoltarc’s post of Oct 28, 2008 03:57am in which he said “I have removed the ROUND() functions from _getInvoices() and getSingleInvoice() and the problem seems to have disappeared.”, I have removed them too (this is in bambooinvoice 0.8.9 so apparently it was not updated) and my rounding problem is gone too.

Hopefully this works for you too and hopefully it’s not just for this particular invoice of mine.

Gerben

Total Posts: 3

Having the same issue, so hopefully it will be in an update instead of messing with the code:

Bedrag: €102.50
19% BTW (19.000%): €19.48
Totaal: €121.99

Bedrag: €80.00
19% BTW (19.000%): €15.20
Totaal: €95.21

(Language is dutch)
Where does the 1 cent comes from?

Total Posts: 9
Peter H - Mar 12, 2010 08:00pm

Having the same issue, so hopefully it will be in an update instead of messing with the code:

Bedrag: €80.00
19% BTW (19.000%): €15.20
Totaal: €95.21

Where does the 1 cent comes from?

It’s a rounding error, please search for the post of Zoltarc where he says he removed the ROUND() functions altogether.