diff --git a/main.go b/main.go index 440f5ff499d089f66d3b35fff8ffc692e7e8882d..51d2548797dc02dc49cf732e64122a7b7d9c27b8 100644 --- a/main.go +++ b/main.go @@ -129,7 +129,19 @@ var generateCmd = &cobra.Command{ writeLogo(&pdf, file.Logo, file.From) writeTitle(&pdf, file.Title, file.Id, file.Date) writeBillTo(&pdf, file.To) - writeHeaderRow(&pdf) + showLineItemDetails := false + for i := range file.Items { + q := 1 + if len(file.Quantities) > i { + q = file.Quantities[i] + } + if q != 1 { + showLineItemDetails = true + break + } + } + + writeHeaderRow(&pdf, showLineItemDetails) subtotal := 0.0 for i := range file.Items { q := 1 diff --git a/pdf.go b/pdf.go index 34d19505484dfda9e7fb2873ddcef1abe894ba60..ceb140ac8f547301077343576fb7aa360d86b976 100644 --- a/pdf.go +++ b/pdf.go @@ -105,14 +105,16 @@ func writeBillTo(pdf *gopdf.GoPdf, to string) { pdf.Br(64) } -func writeHeaderRow(pdf *gopdf.GoPdf) { +func writeHeaderRow(pdf *gopdf.GoPdf, showLineItemDetails bool) { _ = pdf.SetFont("Inter", "", 9) pdf.SetTextColor(55, 55, 55) _ = pdf.Cell(nil, "ITEM") - pdf.SetX(quantityColumnOffset) - _ = pdf.Cell(nil, "QTY") - pdf.SetX(rateColumnOffset) - _ = pdf.Cell(nil, "RATE") + if showLineItemDetails { + pdf.SetX(quantityColumnOffset) + _ = pdf.Cell(nil, "QTY") + pdf.SetX(rateColumnOffset) + _ = pdf.Cell(nil, "RATE") + } pdf.SetX(amountColumnOffset) _ = pdf.Cell(nil, "AMOUNT") pdf.Br(24) @@ -157,10 +159,12 @@ func writeRow(pdf *gopdf.GoPdf, item string, quantity int, rate float64) { amount := strconv.FormatFloat(total, 'f', 2, 64) _ = pdf.Cell(nil, item) - pdf.SetX(quantityColumnOffset) - _ = pdf.Cell(nil, strconv.Itoa(quantity)) - pdf.SetX(rateColumnOffset) - _ = pdf.Cell(nil, currencySymbols[file.Currency]+strconv.FormatFloat(rate, 'f', 2, 64)) + if quantity != 1 { + pdf.SetX(quantityColumnOffset) + _ = pdf.Cell(nil, strconv.Itoa(quantity)) + pdf.SetX(rateColumnOffset) + _ = pdf.Cell(nil, currencySymbols[file.Currency]+strconv.FormatFloat(rate, 'f', 2, 64)) + } pdf.SetX(amountColumnOffset) _ = pdf.Cell(nil, currencySymbols[file.Currency]+amount) pdf.Br(24)