Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for entering tax as a percentage of Total #4

Merged
merged 2 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ are:
* Everything on the bill is the same currency
* Filenames will be output in a standard way

Current limitations:
* It almost has support for tax calculation but it's not there yet

The Problem This Solves
------------------------

Expand Down
4 changes: 4 additions & 0 deletions billing.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ billables:
unit_price: 10.23
currency: €

# You may enter tax as a percentage here (from 0 to 1.0).
tax:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tax:
default_tax:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to make various adjustments elsewhere in the code to make this work also. Didn't try to find them all.

percentage: 0.1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to support a default tax and an overridable tax rate per item. Some items may be taxable at different rates.


# Where to send the money!
bank:
# Any fields you don't specify here, will be left entirely off
Expand Down
17 changes: 11 additions & 6 deletions invoice/bill.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (b *Bill) RenderToFile() error {
headers = []string{"Qty", "Description", "Unit Price", "Line Total"}
widths := []float64{16, 125.5, 25, 25}

b.drawBillablesTable(headers, b.config.Billables, widths)
b.drawBillablesTable(headers, b.config.Billables, b.config.Tax, widths)
b.drawBankDetails()

// It's safe to MustParse here because we validate args earlier
Expand Down Expand Up @@ -229,7 +229,7 @@ func (b *Bill) drawBlanks(billables []BillableItem, widths []float64) {

// drawBillableaTable renders the table containing one line each
// for the billable items described in the YAML file.
func (b *Bill) drawBillablesTable(headers []string, billables []BillableItem, widths []float64) {
func (b *Bill) drawBillablesTable(headers []string, billables []BillableItem, taxDetails *TaxDetails, widths []float64) {
b.pdf.SetFillColor(255, 0, 0)
b.whiteText()
b.pdf.SetDrawColor(64, 64, 64)
Expand Down Expand Up @@ -260,6 +260,10 @@ func (b *Bill) drawBillablesTable(headers []string, billables []BillableItem, wi
b.pdf.Ln(4)
}

// Calculate tax
tax := subTotal * taxDetails.Percentage
total := subTotal + tax

// Draw the Sub-Total
b.pdf.SetDrawColor(255, 255, 255)
b.pdf.SetFont(b.config.Business.SerifFont, "", 8)
Expand All @@ -272,18 +276,19 @@ func (b *Bill) drawBillablesTable(headers []string, billables []BillableItem, wi
// Draw Tax
b.pdf.Ln(4)
b.drawBlanks(billables, widths)
b.textFormat(widths[len(widths)-2], 4, "Tax", "1", 0, "R", true, 0, "")
b.textFormat(widths[len(widths)-1], 4, "0", "1", 0, "R", true, 0, "")
taxText := billables[0].Currency + " " + niceFloatStr(tax)
b.textFormat(widths[len(widths)-2], 4, "GST", "1", 0, "R", true, 0, "")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
b.textFormat(widths[len(widths)-2], 4, "GST", "1", 0, "R", true, 0, "")
b.textFormat(widths[len(widths)-2], 4, "Tax", "1", 0, "R", true, 0, "")

GST is a region-specific tax for certain countries. Let's stay with generic "Tax"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, make this configurable in the default_tax block in the config.

b.textFormat(widths[len(widths)-1], 4, taxText, "1", 0, "R", true, 0, "")

// Draw Total
// XXX Total just uses sub-total and assumes €0.00 tax for now...
b.pdf.Ln(4)
b.drawBlanks(billables, widths)
b.pdf.SetFont(b.config.Business.SerifFont, "B", 10)
y := b.pdf.GetY()
x := b.pdf.GetX()
totalText := billables[0].Currency + " " + niceFloatStr(total)
b.textFormat(widths[len(widths)-2], 6, "Total", "1", 0, "R", true, 0, "")
b.textFormat(widths[len(widths)-1], 6, subTotalText, "1", 0, "R", true, 0, "")
b.textFormat(widths[len(widths)-1], 6, totalText, "1", 0, "R", true, 0, "")
x2 := b.pdf.GetX()

b.pdf.SetDrawColor(64, 64, 64)
Expand Down
5 changes: 5 additions & 0 deletions invoice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (b *BillableItem) Strings() []string {
}
}

type TaxDetails struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should call this something like DefaultTax instead.

Percentage float64
}

type BankDetails struct {
TransferType string `yaml:"transfer_type"`
Name string
Expand Down Expand Up @@ -97,6 +101,7 @@ type BillingConfig struct {
Bill *BillDetails `yaml:"bill"`
BillTo *BillToDetails `yaml:"bill_to"`
Billables []BillableItem `yaml:"billables"`
Tax *TaxDetails `yaml:"tax"`
Bank *BankDetails `yaml:"bank"`
Colors *BillColor `yaml:"colors"`
}
Expand Down