upstream sync
This commit is contained in:
@@ -182,6 +182,29 @@ func GetContractByID(contractID uint64) (models.Contract, int, error) {
|
||||
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"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Added conditional for status search
|
||||
if len(status) > 0 {
|
||||
db = db.Where("status in (?)", status)
|
||||
countDb = countDb.Where("status in (?)", status)
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := countDb.Model(&models.Invoice{}).Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
Reference in New Issue
Block a user