Upstream sync

This commit is contained in:
Senad Uka
2023-10-13 11:48:14 +02:00
parent 7369739bdd
commit d01c1a0232
29 changed files with 563 additions and 444 deletions

View File

@@ -3,68 +3,62 @@ package models
import (
"database/sql"
"time"
"github.com/jinzhu/gorm"
)
type Invoice struct {
gorm.Model
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
BaseModel
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
Status string `json:"status"`
Status string `json:"status"`
}
type InvoiceResponse struct {
BaseModel
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
Status string `json:"status"`
Status string `json:"status"`
}
func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
var invoiceResponses []InvoiceResponse
invoiceResponses := []InvoiceResponse{}
for _, invoice := range invoices {
if invoice.InvoiceItem == nil {
emptySlice := make([]InvoiceItem, 0)
@@ -95,7 +89,7 @@ func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
InvoiceDate: invoice.InvoiceDate,
InvoiceDueDate: invoice.InvoiceDueDate,
ContractID: invoice.ContractID,
InvoiceItem: invoice.InvoiceItem,
InvoiceItem: invoice.InvoiceItem,
Status: invoice.Status,
}
invoiceResponses = append(invoiceResponses, invoiceResponse)
@@ -103,23 +97,19 @@ func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
return invoiceResponses
}
type ListInvoiceResponse struct {
Status KeyValue `json:"status"`
Buyer CompanyShortResponse `json:"buyer"`
ContractID int `json:"contractId"`
DateCreated time.Time `json:"dateCreated"`
DueDate time.Time `json:"dueDate"`
Amount string `json:"amount"`
Status KeyValue `json:"status"`
Buyer CompanyShortResponse `json:"buyer"`
ContractID int `json:"contractId"`
DateCreated time.Time `json:"dateCreated"`
DueDate time.Time `json:"dueDate"`
Amount string `json:"amount"`
}
type KeyValue struct {
Key string `json:"key"`
Value string `json:"value"`
}
func GetInvoiceStatuses() []Status {
return []Status{
{Key: "Insurance claimed", Value: "insurance_claimed"},