summaryrefslogtreecommitdiff
path: root/invoice/invoice.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2023-01-29 20:11:09 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2023-01-29 20:11:09 +0530
commitac7aa8c6e95023def1eba7615d8a42ad52271500 (patch)
treeb3477a9d3ae39244a759b19fe42e7d3bccbda38d /invoice/invoice.go
parent0607478f1e4c86619a606af7876a6625e859ee1a (diff)
checking password before editing/deleting user
Diffstat (limited to 'invoice/invoice.go')
-rw-r--r--invoice/invoice.go101
1 files changed, 37 insertions, 64 deletions
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"`
}