aboutsummaryrefslogtreecommitdiff
path: root/invoice/service.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-12-03 19:23:51 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-12-03 19:23:51 +0530
commitd51f58b8fea22c9dfd64f3a1665d1994697dfa94 (patch)
tree59d08944268d372a0b8df131552fb8e3431f2213 /invoice/service.go
parent9df37d57e454c49b2c55418ad53b6d49a2be2589 (diff)
auto-generate invoice numberv0.2.0
Diffstat (limited to 'invoice/service.go')
-rw-r--r--invoice/service.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/invoice/service.go b/invoice/service.go
index 099f6a0..3dcc5e2 100644
--- a/invoice/service.go
+++ b/invoice/service.go
@@ -21,6 +21,16 @@ import (
e "vidhukant.com/openbills/errors"
)
+// returns greatest invoice number + 1
+func getNewInvoiceNumber(userId uint) (uint, error) {
+ var i uint
+
+ row := db.Model(&Invoice{}).Where("user_id = ?", userId).Select("max(invoice_number)").Row()
+ err := row.Scan(&i)
+
+ return i + 1, err
+}
+
func getInvoice(invoice *Invoice, id uint) error {
res := db.Preload("BillingAddress").Preload("ShippingAddress").Preload("Items").Find(&invoice, id)