diff options
| author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-10-13 00:37:30 +0530 | 
|---|---|---|
| committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-10-13 00:37:30 +0530 | 
| commit | fb9ba155438100f295fdb563ad955151ee038ad3 (patch) | |
| tree | 558c27ce3910a2aa2e7d18803b7548f6e7f6a032 /invoice/invoice.go | |
| parent | 327a32f563394f92313e4a751515d69d90f4e7f5 (diff) | |
flattened out the invoice schema, was overengineered
Diffstat (limited to 'invoice/invoice.go')
| -rw-r--r-- | invoice/invoice.go | 79 | 
1 files changed, 45 insertions, 34 deletions
diff --git a/invoice/invoice.go b/invoice/invoice.go index 97ba254..9cbc4e7 100644 --- a/invoice/invoice.go +++ b/invoice/invoice.go @@ -1,5 +1,5 @@  /* openbills - Server for web based Libre Billing Software - * Copyright (C) 2023-2024  Vidhu Kant Sharma <vidhukant@vidhukant.com> + * Copyright (C) 2023-2025  Vidhu Kant Sharma <vidhukant@vidhukant.com>   *   * This program is free software: you can redistribute it and/or modify   * it under the terms of the GNU General Public License as published by @@ -21,7 +21,6 @@ import (  	"gorm.io/gorm"  	"time"  	d "vidhukant.com/openbills/db" -	i "vidhukant.com/openbills/item"  	u "vidhukant.com/openbills/util"  ) @@ -30,27 +29,26 @@ var db *gorm.DB  func init() {  	db = d.DB -	db.AutoMigrate(&Invoice{}, &InvoiceItem{}, &InvoiceBillingAddress{}, &InvoiceShippingAddress{}, &CustomField{}) -} - -type InvoiceBillingAddress struct { -	gorm.Model -	u.Address -	InvoiceID uint -} - -type InvoiceShippingAddress struct { -	gorm.Model -	u.Address -	InvoiceID uint +	db.AutoMigrate(&Invoice{}, &InvoiceItem{}, &CustomField{})  }  type InvoiceItem struct { -	i.Item  	ID        uint  	InvoiceID uint -	BrandName string  	Quantity  string // float +	// fields below these must be kept in sync with +	// item.SavedItem. I'm not extending that struct because +	// there are some things that I don't want / want in a +	// different format. In short, it's *not* worth the headache +	Name          string +	BrandName     string +	Category      string +	Description   string +	HSN           string +	UnitOfMeasure string +	VariantName   string +	UnitPrice     string // float +	GSTPercentage string // float  }  // user can add as many custom fields as they like @@ -63,24 +61,37 @@ type CustomField struct {  type Invoice struct {  	gorm.Model -	InvoiceDate     time.Time -	InvoiceNumber   uint -	BillingAddress  InvoiceBillingAddress -	ShippingAddress InvoiceShippingAddress -	IsDraft         bool -	Note            string -	Items           []InvoiceItem -	CustomFields    []CustomField +	InvoiceDate   time.Time +	InvoiceNumber uint +	IsDraft       bool +	Note          string +	Items         []InvoiceItem +	CustomFields  []CustomField + +	BillingAddressText       string +	BillingAddressCity       string +	BillingAddressState      string +	BillingAddressPostalCode string +	BillingAddressCountry    string + +	ShippingAddressText       string +	ShippingAddressCity       string +	ShippingAddressState      string +	ShippingAddressPostalCode string +	ShippingAddressCountry    string + +	IssuerFirmName    string +	IssuerFirmGstin   string +	IssuerFirmPhone   string +	IssuerFirmEmail   string +	IssuerFirmWebsite string + +	IssuerFirmAddressText       string +	IssuerFirmAddressCity       string +	IssuerFirmAddressState      string +	IssuerFirmAddressPostalCode string +	IssuerFirmAddressCountry    string -	// issuer and customer details are stored here -	// because they are NOT intended to ever change -	IssuerFirmName      string -	IssuerFirmAddress   string -	IssuerFirmGstin     string -	IssuerFirmPhone     string -	IssuerFirmEmail     string -	IssuerFirmWebsite   string -	IssuerFirmDetails   string  	CustomerName        string  	CustomerGstin       string  	CustomerContactName string  |