From ac7aa8c6e95023def1eba7615d8a42ad52271500 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 29 Jan 2023 20:11:09 +0530 Subject: checking password before editing/deleting user --- invoice/invoice.go | 101 ++++++++++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 64 deletions(-) (limited to 'invoice/invoice.go') diff --git a/invoice/invoice.go b/invoice/invoice.go index 91b881c..f7b638a 100644 --- a/invoice/invoice.go +++ b/invoice/invoice.go @@ -18,45 +18,18 @@ package invoice import ( - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" "github.com/MikunoNaka/OpenBills-server/client" - "github.com/MikunoNaka/OpenBills-server/item" "github.com/MikunoNaka/OpenBills-server/database" + "github.com/MikunoNaka/OpenBills-server/item" + t "github.com/MikunoNaka/OpenBills-server/transport" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" "time" ) // initialise a database connection for this package // not sure if I should do this but I am... -var db *mongo.Database = database.DB - -/* you should be able to: - * - add, modify, delete an invoice - * - add client to invoice - * - add items to invoice - */ - -/* Transporter details can be stored in - * the DB. That is decided by the frontend. - * You can optionally store Transporter - * and Transport details which are often used - */ -type Transporter struct { - Id primitive.ObjectID `bson:"_id,omitempty" json:"Id"` - Name string `bson:"Name" json:"Name"` - GSTIN string `bson:"GSTIN" json:"GSTIN"` - // Issued ID for the transporter if any - TransporterId string `bson:"TransporterId,omitempty" json:"TransporterId"` -} - -// transport vehicle details -type Transport struct { - Id primitive.ObjectID `bson:"_id,omitempty" json:"Id"` - Transporter Transporter `bson:"Transporter,omitempty" json:"Transporter"` - VehicleNum string `bson:"VehicleNum" json:"VehicleNum"` - Note string `bson:"Note" json:"Note"` - TransportMethod string `bson:"TransportMethod" json:"TransportMethod"` -} +var db *mongo.Collection = database.DB.Collection("Invoice") /* The *legendary* Invoice struct * Each Recipient, Item in invoice, Address @@ -80,37 +53,37 @@ type Transport struct { */ // TODO: add place of supply type Invoice struct { - Id primitive.ObjectID `bson:"_id,omitempty" json:"Id"` // not the same as invoice number - InvoiceNumber int `bson:"InvoiceNumber" json:"InvoiceNumber"` - CreatedAt time.Time `bson:"CreatedAt" json:"CreatedAt"` - LastUpdated time.Time `bson:"LastUpdated,omitempty" json:"LastUpdated"` - Recipient client.Client `bson:"Recipient" json:"Recipient"` - Paid bool `bson:"Paid" json:"Paid"` - TransactionId string `bson:"TransactionId" json:"TransactionId"` - Transport Transport `bson:"Transport" json:"Transport"` - // user can apply a discount on the whole invoice - // TODO: float64 isn't the best for this - DiscountPercentage float64 `bson:"DiscountPercentage" json:"DiscountPercentage"` - // helps to filter amount by amount - TotalAmount float64 `bson:"TotalAmount" json:"TotalAmount"` - /* client may have multiple shipping - * addresses but invoice only has one. - * Empty ShippingAddress means shipping - * address same as billing address - */ - BillingAddress client.Address `bson:"BillingAddress" json:"BillingAddress"` - ShippingAddress client.Address `bson:"ShippingAddress,omitempty" json:"ShippingAddress"` - Items []item.InvoiceItem `bson:"Items" json:"Items"` - // user can attach notes to the invoice - // frontend decides if recipient sees this or not - Note string `bson:"Note" json:"Note"` + Id primitive.ObjectID `bson:"_id,omitempty" json:"Id"` // not the same as invoice number + InvoiceNumber int `bson:"InvoiceNumber" json:"InvoiceNumber"` + CreatedAt time.Time `bson:"CreatedAt" json:"CreatedAt"` + LastUpdated time.Time `bson:"LastUpdated,omitempty" json:"LastUpdated"` + Recipient client.Client `bson:"Recipient" json:"Recipient"` + Paid bool `bson:"Paid" json:"Paid"` + TransactionId string `bson:"TransactionId" json:"TransactionId"` + Transport t.Transport `bson:"Transport" json:"Transport"` + // user can apply a discount on the whole invoice + // TODO: float64 isn't the best for this + DiscountPercentage float64 `bson:"DiscountPercentage" json:"DiscountPercentage"` + // helps to filter amount by amount + TotalAmount float64 `bson:"TotalAmount" json:"TotalAmount"` + /* client may have multiple shipping + * addresses but invoice only has one. + * Empty ShippingAddress means shipping + * address same as billing address + */ + BillingAddress client.Address `bson:"BillingAddress" json:"BillingAddress"` + ShippingAddress client.Address `bson:"ShippingAddress,omitempty" json:"ShippingAddress"` + Items []item.InvoiceItem `bson:"Items" json:"Items"` + // user can attach notes to the invoice + // frontend decides if recipient sees this or not + Note string `bson:"Note" json:"Note"` - /* Invoices can be drafts - * I personally like this functionality - * because we can constantly save the - * invoice to the DB as a draft - * and if OpenBills crashes or is disconnected - * we still have the progress - */ - Draft bool `bson:"Draft" json:"Draft"` + /* Invoices can be drafts + * I personally like this functionality + * because we can constantly save the + * invoice to the DB as a draft + * and if OpenBills crashes or is disconnected + * we still have the progress + */ + Draft bool `bson:"Draft" json:"Draft"` } -- cgit v1.2.3