maaslalani / invoice

Command line invoice generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestions

pyrite357 opened this issue · comments

Great project! I took it upon myself to learn GO to help out:

  • no dates on items (my clients want to see a date beside each item, a date column is preferred
  • an optional time column (e.g. 08:32 to 16:43), some clients want that
  • newline support in the --from/--to (so we can include address, phone, etc), or just sep params for addresses
  • i don't like having rate as a column as it is redundant, but can see how it would help people with a mix of rates. Flag to turn it off would be nice
  • Place for payment terms (e.g. NET 15)
  • An optional column for category/project numbers
  • A way to toggle on/off all the columns in Items
  • A total for Qty at the bottom (for me, each item is in hours, so clients want to see Total Hours)
  • (Fix below) - Qty doesn't seem to accept numbers < 1 (e.g. 0.25), so how can i bill for 0.25 hours?
  • #32 - A cli parameter to get the version of invoice would be nice when making new issues in Gitlab ;)

I don't feel like making a PR, but here is a patch for the Quantities to support float. Idk if I left anything out, but it's working for my uses. This is my FIRST time writing GO code lol.

diff --git a/main.go b/main.go
index 440f5ff..26c63f4 100644
--- a/main.go
+++ b/main.go
@@ -30,7 +30,7 @@ type Invoice struct {
 	Due  string `json:"due" yaml:"due"`
 
 	Items      []string  `json:"items" yaml:"items"`
-	Quantities []int     `json:"quantities" yaml:"quantities"`
+	Quantities []float64 `json:"quantities" yaml:"quantities"`
 	Rates      []float64 `json:"rates" yaml:"rates"`
 
 	Tax      float64 `json:"tax" yaml:"tax"`
@@ -45,7 +45,7 @@ func DefaultInvoice() Invoice {
 		Id:         time.Now().Format("20060102"),
 		Title:      "INVOICE",
 		Rates:      []float64{25},
-		Quantities: []int{2},
+		Quantities: []float64{25},
 		Items:      []string{"Paper Cranes"},
 		From:       "Project Folded, Inc.",
 		To:         "Untitled Corporation, Inc.",
@@ -72,7 +72,7 @@ func init() {
 	generateCmd.Flags().StringVar(&file.Title, "title", "INVOICE", "Title")
 
 	generateCmd.Flags().Float64SliceVarP(&file.Rates, "rate", "r", defaultInvoice.Rates, "Rates")
-	generateCmd.Flags().IntSliceVarP(&file.Quantities, "quantity", "q", defaultInvoice.Quantities, "Quantities")
+	generateCmd.Flags().Float64SliceVarP(&file.Quantities, "quantity", "q", defaultInvoice.Quantities, "Quantities")
 	generateCmd.Flags().StringSliceVarP(&file.Items, "item", "i", defaultInvoice.Items, "Items")
 
 	generateCmd.Flags().StringVarP(&file.Logo, "logo", "l", defaultInvoice.Logo, "Company logo")
@@ -132,7 +132,7 @@ var generateCmd = &cobra.Command{
 		writeHeaderRow(&pdf)
 		subtotal := 0.0
 		for i := range file.Items {
-			q := 1
+			q := 1.0
 			if len(file.Quantities) > i {
 				q = file.Quantities[i]
 			}
diff --git a/pdf.go b/pdf.go
index 5a1cd55..81b9465 100644
--- a/pdf.go
+++ b/pdf.go
@@ -123,7 +123,7 @@ func writeFooter(pdf *gopdf.GoPdf, id string) {
 	pdf.Br(48)
 }
 
-func writeRow(pdf *gopdf.GoPdf, item string, quantity int, rate float64) {
+func writeRow(pdf *gopdf.GoPdf, item string, quantity float64, rate float64) {
 	_ = pdf.SetFont("Inter", "", 11)
 	pdf.SetTextColor(0, 0, 0)
 
@@ -132,7 +132,8 @@ func writeRow(pdf *gopdf.GoPdf, item string, quantity int, rate float64) {
 
 	_ = pdf.Cell(nil, item)
 	pdf.SetX(quantityColumnOffset)
-	_ = pdf.Cell(nil, strconv.Itoa(quantity))
+	//_ = pdf.Cell(nil, strconv.Itoa(quantity))
+	_ = pdf.Cell(nil, strconv.FormatFloat(quantity, 'f', 2, 64))
 	pdf.SetX(rateColumnOffset)
 	_ = pdf.Cell(nil, currencySymbols[file.Currency]+strconv.FormatFloat(rate, 'f', 2, 64))
 	pdf.SetX(amountColumnOffset)