diff options
Diffstat (limited to 'invoice/service.go')
-rw-r--r-- | invoice/service.go | 10 |
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) |