From d51f58b8fea22c9dfd64f3a1665d1994697dfa94 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 3 Dec 2023 19:23:51 +0530 Subject: auto-generate invoice number --- invoice/service.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'invoice/service.go') 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) -- cgit v1.2.3