-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Suggestions #31
Comments
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) |
arm32x
added a commit
to arm32x/invoice
that referenced
this issue
Aug 11, 2023
Originally from maaslalani#31 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great project! I took it upon myself to learn GO to help out:
The text was updated successfully, but these errors were encountered: