piesync / billbo

Easy to use billing service for Stripe with VAT support
MIT License
73 stars 3 forks source link

Discounts + VAT #67

Closed challengee closed 9 years ago

challengee commented 10 years ago

Fixes #59 and fixes #44

challengee commented 10 years ago

@mohawke this should be ready, what do you think?

mohawke commented 10 years ago

does this fix an issue?

mohawke commented 10 years ago

Maybe just calculate the VAT amount and Discount based on the given data?

A = invoice amount (given)
Vr = VAT rate (given)
T = invoice total (given)

D = discount
V = VAT amount

1)  A - D + V = T
2) (A - D)*Vr = V

This leads to:

D = [ A*( 1 + Vr ) - T ] / ( 1 + Vr )

Then you can use the rounded D here ( we'll call it Dr ):

V = (A - Dr)*Vr 

Then round this V to Vr and put Vr and Dr on the invoice. This should be correct according to VAT regulations.

@challengee : what do you think?

challengee commented 9 years ago

Seems like a good idea, I'll give this a try

mohawke commented 9 years ago

Looks correct now!