upstream sync
This commit is contained in:
@@ -200,19 +200,21 @@ func CreateContract(c *gin.Context) {
|
|||||||
db := shared.GetDb()
|
db := shared.GetDb()
|
||||||
|
|
||||||
newContract := models.Contract{
|
newContract := models.Contract{
|
||||||
BuyerID: payload.BuyerID,
|
BuyerID: payload.BuyerID,
|
||||||
SellerID: payload.SellerID,
|
SellerID: payload.SellerID,
|
||||||
Description: payload.Description,
|
Description: payload.Description,
|
||||||
ProductID: payload.ProductID,
|
ProductID: payload.ProductID,
|
||||||
MinTemp: payload.MinTemp,
|
MinTemp: payload.MinTemp,
|
||||||
MaxTemp: payload.MaxTemp,
|
MaxTemp: payload.MaxTemp,
|
||||||
ArrivalDate: time.Unix(payload.ArrivalDate, 0),
|
ArrivalDate: time.Unix(payload.ArrivalDate, 0),
|
||||||
PenaltyType: payload.PenaltyRec,
|
PenaltyType: payload.PenaltyType,
|
||||||
PenaltyValue: payload.PenaltyValue,
|
PenaltyValue: payload.PenaltyValue,
|
||||||
PenaltyRec: payload.PenaltyRec,
|
PenaltyRec: payload.PenaltyRec,
|
||||||
StartLat: payload.StartLat,
|
StartLat: payload.StartLat,
|
||||||
StartLon: payload.StartLon,
|
StartLon: payload.StartLon,
|
||||||
Status: models.ContractStatusDraft,
|
Status: models.ContractStatusDraft,
|
||||||
|
StartPlaceName: payload.StartPlaceName,
|
||||||
|
EndPlaceName: payload.EndPlaceName,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.Create(&newContract).Error; err != nil {
|
if err := db.Create(&newContract).Error; err != nil {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ func GetInvoices(c *gin.Context) {
|
|||||||
buyerName := c.Query("buyer_name")
|
buyerName := c.Query("buyer_name")
|
||||||
sortBy := c.Query("sort_by")
|
sortBy := c.Query("sort_by")
|
||||||
iDsStr := c.QueryArray("ids[]")
|
iDsStr := c.QueryArray("ids[]")
|
||||||
|
status := c.QueryArray("status")
|
||||||
|
|
||||||
limit, err := strconv.Atoi(limitStr)
|
limit, err := strconv.Atoi(limitStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -39,7 +40,7 @@ func GetInvoices(c *gin.Context) {
|
|||||||
invoiceIDs = append(invoiceIDs, id)
|
invoiceIDs = append(invoiceIDs, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
invoices, total, err := invoice.GetInvoices(buyerName, sortBy, limit, offset, invoiceIDs)
|
invoices, total, err := invoice.GetInvoices(buyerName, sortBy, limit, offset, invoiceIDs, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
@@ -59,7 +60,7 @@ func GetInvoiceByID(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
invoices, _, err := invoice.GetInvoices("", "", 1, 0, []int64{int64(id)})
|
invoices, _, err := invoice.GetInvoices("", "", 1, 0, []int64{int64(id)}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -182,6 +182,29 @@ func GetContractByID(contractID uint64) (models.Contract, int, error) {
|
|||||||
return contract, http.StatusInternalServerError, err
|
return contract, http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return contract, http.StatusOK, nil
|
// Fetch the product
|
||||||
|
var product models.ProductTemplate
|
||||||
|
if err := shared.GetDb().Unscoped().Where("id = ?", contract.ProductID).First(&product).Error; err != nil {
|
||||||
|
log.Printf("GetContractByID Error: Could not fetch product: %v", err)
|
||||||
|
return contract, http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
contract.ProductName = product.Name
|
||||||
|
|
||||||
|
// Fetch the seller
|
||||||
|
var seller models.Company
|
||||||
|
if err := shared.GetDb().Unscoped().Where("id = ?", contract.SellerID).First(&seller).Error; err != nil {
|
||||||
|
log.Printf("GetContractByID Error: Could not fetch seller: %v", err)
|
||||||
|
return contract, http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
contract.SellerName = seller.Name
|
||||||
|
|
||||||
|
// Fetch the buyer
|
||||||
|
var buyer models.Company
|
||||||
|
if err := shared.GetDb().Unscoped().Where("id = ?", contract.BuyerID).First(&buyer).Error; err != nil {
|
||||||
|
log.Printf("GetContractByID Error: Could not fetch buyer: %v", err)
|
||||||
|
return contract, http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
contract.BuyerName = buyer.Name
|
||||||
|
|
||||||
|
return contract, http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"gitlab.com/pactual1/backend/shared"
|
"gitlab.com/pactual1/backend/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetInvoices(buyerName string, sortBy string, limit int, offset int, ids []int64) ([]models.Invoice, int64, error) {
|
func GetInvoices(buyerName string, sortBy string, limit int, offset int, ids []int64, status []string) ([]models.Invoice, int64, error) {
|
||||||
var invoices []models.Invoice
|
var invoices []models.Invoice
|
||||||
|
|
||||||
// Default sort by InvoiceDate DESC
|
// Default sort by InvoiceDate DESC
|
||||||
@@ -35,6 +35,12 @@ func GetInvoices(buyerName string, sortBy string, limit int, offset int, ids []i
|
|||||||
countDb = countDb.Where("id in (?)", ids)
|
countDb = countDb.Where("id in (?)", ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Added conditional for status search
|
||||||
|
if len(status) > 0 {
|
||||||
|
db = db.Where("status in (?)", status)
|
||||||
|
countDb = countDb.Where("status in (?)", status)
|
||||||
|
}
|
||||||
|
|
||||||
var total int64
|
var total int64
|
||||||
if err := countDb.Model(&models.Invoice{}).Count(&total).Error; err != nil {
|
if err := countDb.Model(&models.Invoice{}).Count(&total).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ type Contract struct {
|
|||||||
PenaltyValue int `json:"penaltyValue"`
|
PenaltyValue int `json:"penaltyValue"`
|
||||||
PenaltyRec string `json:"penaltyRec"`
|
PenaltyRec string `json:"penaltyRec"`
|
||||||
BuyerName string `json:"buyerName" gorm:"-"`
|
BuyerName string `json:"buyerName" gorm:"-"`
|
||||||
|
SellerName string `json:"sellerName" gorm:"-"`
|
||||||
|
ProductName string `json:"productName" gorm:"-"`
|
||||||
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
NumberOfDevices int `json:"numberOfDevices" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,11 +93,6 @@ type ContractResponse struct {
|
|||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
} `json:"product"`
|
} `json:"product"`
|
||||||
Template struct {
|
|
||||||
ID uint `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
} `json:"template"`
|
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
BlockchainID string `json:"blockchainId"`
|
BlockchainID string `json:"blockchainId"`
|
||||||
@@ -118,7 +115,6 @@ func ConvertContractsToContractResponse(contracts []Contract) []ContractResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
||||||
|
|
||||||
contractResponse := ContractResponse{
|
contractResponse := ContractResponse{
|
||||||
BaseModel: BaseModel{ID: contract.ID, CreatedAt: contract.CreatedAt, UpdatedAt: contract.UpdatedAt},
|
BaseModel: BaseModel{ID: contract.ID, CreatedAt: contract.CreatedAt, UpdatedAt: contract.UpdatedAt},
|
||||||
Name: contract.Name,
|
Name: contract.Name,
|
||||||
@@ -128,12 +124,14 @@ func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
|||||||
Name string "json:\"name\""
|
Name string "json:\"name\""
|
||||||
}{
|
}{
|
||||||
ID: contract.SellerID,
|
ID: contract.SellerID,
|
||||||
|
Name: contract.SellerName,
|
||||||
},
|
},
|
||||||
Buyer: struct {
|
Buyer: struct {
|
||||||
ID uint "json:\"id\""
|
ID uint "json:\"id\""
|
||||||
Name string "json:\"name\""
|
Name string "json:\"name\""
|
||||||
}{
|
}{
|
||||||
ID: contract.BuyerID,
|
ID: contract.BuyerID,
|
||||||
|
Name: contract.BuyerName,
|
||||||
},
|
},
|
||||||
Start: struct {
|
Start: struct {
|
||||||
Name string "json:\"name\""
|
Name string "json:\"name\""
|
||||||
@@ -162,13 +160,7 @@ func ConvertContractToContractResponse(contract Contract) ContractResponse {
|
|||||||
Name string "json:\"name\""
|
Name string "json:\"name\""
|
||||||
}{
|
}{
|
||||||
ID: contract.ProductID,
|
ID: contract.ProductID,
|
||||||
},
|
Name: contract.ProductName,
|
||||||
Template: struct {
|
|
||||||
ID uint "json:\"id\""
|
|
||||||
Name string "json:\"name\""
|
|
||||||
Value string "json:\"value\""
|
|
||||||
}{
|
|
||||||
ID: contract.TemplateID,
|
|
||||||
},
|
},
|
||||||
Description: contract.Description,
|
Description: contract.Description,
|
||||||
Status: contract.Status,
|
Status: contract.Status,
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"gitlab.com/pactual1/backend/config"
|
|
||||||
"gitlab.com/pactual1/backend/models"
|
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
|
"gitlab.com/pactual1/backend/config"
|
||||||
|
"gitlab.com/pactual1/backend/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
|
|||||||
Reference in New Issue
Block a user