aboutsummaryrefslogtreecommitdiff
path: root/invoice/controller.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/controller.go
parent9df37d57e454c49b2c55418ad53b6d49a2be2589 (diff)
auto-generate invoice numberv0.2.0
Diffstat (limited to 'invoice/controller.go')
-rw-r--r--invoice/controller.go13
1 files changed, 13 insertions, 0 deletions
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)