-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ billables: | |
unit_price: 10.23 | ||
currency: € | ||
|
||
# You may enter tax as a percentage here (from 0 to 1.0). | ||
tax: | ||
percentage: 0.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
|
@@ -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) | ||||||
|
@@ -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) | ||||||
|
@@ -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, "") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
GST is a region-specific tax for certain countries. Let's stay with generic "Tax" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, make this configurable in the |
||||||
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) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,10 @@ func (b *BillableItem) Strings() []string { | |
} | ||
} | ||
|
||
type TaxDetails struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should call this something like |
||
Percentage float64 | ||
} | ||
|
||
type BankDetails struct { | ||
TransferType string `yaml:"transfer_type"` | ||
Name string | ||
|
@@ -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"` | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.