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/controller.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'invoice/controller.go') diff --git a/invoice/controller.go b/invoice/controller.go index 02bbaf5..7260834 100644 --- a/invoice/controller.go +++ b/invoice/controller.go @@ -101,6 +101,19 @@ func handleSaveInvoice (ctx *gin.Context) { userId := uId.(uint) invoice.UserID = userId + // if invoice number is 0, generate one! + if invoice.InvoiceNumber == 0 { + n, err := getNewInvoiceNumber(invoice.UserID) + + if err != nil { + ctx.Error(err) + ctx.Abort() + return + } + + invoice.InvoiceNumber = n + } + err := invoice.upsert() if err != nil { ctx.Error(err) -- cgit v1.2.3