Skip to content

Commit

Permalink
Allow custom tax naming. Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
relistan committed Mar 1, 2020
1 parent bb93890 commit 2daa5dd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ are:
* Everything on the bill is the same currency
* Filenames will be output in a standard way

Current limitations:

* Has tax support with one rate for all entries. May eventually support
different rates for different line items.

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

Expand Down
Binary file modified assets/example.pdf
Binary file not shown.
Binary file modified assets/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions billing.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ billables:
unit_price: 10.23
currency:

# You may enter tax as a percentage here (from 0 to 1.0).
# You may enter tax as a percentage here (from 0 to 1.0). This will
# be applied to all items on the invoice.
tax:
percentage: 0.1
default_percentage: 0.1
tax_name: "GST" # Default "Tax". Some countries use GST, some VAT, etc

# Where to send the money!
bank:
Expand Down
13 changes: 11 additions & 2 deletions invoice/bill.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ func (b *Bill) drawBillablesTable(headers []string, billables []BillableItem, ta
}

// Calculate tax
tax := subTotal * taxDetails.Percentage
var tax float64
if taxDetails != nil {
tax = subTotal * taxDetails.DefaultPercentage
}
total := subTotal + tax

// Draw the Sub-Total
Expand All @@ -273,11 +276,17 @@ func (b *Bill) drawBillablesTable(headers []string, billables []BillableItem, ta
b.textFormat(widths[len(widths)-2], 4, "Subtotal", "1", 0, "R", true, 0, "")
b.textFormat(widths[len(widths)-1], 4, subTotalText, "1", 0, "R", true, 0, "")

// Handle configurable tax name
taxName := "Tax"
if taxDetails != nil && taxDetails.TaxName != "" {
taxName = taxDetails.TaxName
}

// Draw Tax
b.pdf.Ln(4)
b.drawBlanks(billables, widths)
taxText := billables[0].Currency + " " + niceFloatStr(tax)
b.textFormat(widths[len(widths)-2], 4, "GST", "1", 0, "R", true, 0, "")
b.textFormat(widths[len(widths)-2], 4, taxName, "1", 0, "R", true, 0, "")
b.textFormat(widths[len(widths)-1], 4, taxText, "1", 0, "R", true, 0, "")

// Draw Total
Expand Down
5 changes: 3 additions & 2 deletions invoice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func (b *BillableItem) Strings() []string {
}

type TaxDetails struct {
Percentage float64
DefaultPercentage float64 `yaml:"default_percentage"`
TaxName string `yaml:"tax_name"`
}

type BankDetails struct {
Expand Down Expand Up @@ -97,7 +98,7 @@ type BillColor struct {
}

type AppConfig struct {
OutputDir string `yaml:"output_dir"`
OutputDir string `yaml:"output_dir"`
}

type BillingConfig struct {
Expand Down

0 comments on commit 2daa5dd

Please sign in to comment.