From c2f7d2481cc4793589378df76d5ab1a76ef53aad Mon Sep 17 00:00:00 2001 From: abhishek Date: Mon, 27 Jul 2026 18:54:40 +0530 Subject: [PATCH] stocks change --- models/product.go | 15 ++++++++++----- repositories/productRepository.go | 8 ++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/models/product.go b/models/product.go index fb4751e..08ed611 100644 --- a/models/product.go +++ b/models/product.go @@ -124,11 +124,16 @@ type Locationproducts struct { Productcombo int `json:"productcombo" gorm:"default:0"` Variants int `json:"variants" gorm:"default:0"` Quantity int `json:"quantity"` - Retailprice float64 `json:"retailprice,omitempty"` - Diffprice float64 `json:"diffprice,omitempty"` - Diffpercent float64 `json:"diffpercent,omitempty"` - Othercost float64 `json:"othercost,omitempty"` - Approve int `json:"approve" gorm:"default:0"` + // Price is the per-store selling price from productlocations.price — the one + // CreateProductLocation upserts. Read-only here: it comes from the joined + // productlocations row, not from products. Without it a store could set a + // price and never read it back, so the UI always showed the master price. + Price float64 `json:"price" gorm:"->"` + Retailprice float64 `json:"retailprice,omitempty"` + Diffprice float64 `json:"diffprice,omitempty"` + Diffpercent float64 `json:"diffpercent,omitempty"` + Othercost float64 `json:"othercost,omitempty"` + Approve int `json:"approve" gorm:"default:0"` // Productstatus string `json:"productstatus" gorm:"default:available"` Status string `json:"status" gorm:"default:outofstock"` } diff --git a/repositories/productRepository.go b/repositories/productRepository.go index 8a14848..4156f2b 100644 --- a/repositories/productRepository.go +++ b/repositories/productRepository.go @@ -405,7 +405,11 @@ func (r *productRepository) GetLocationProducts(tenantID, locationID, subcategor params := []interface{}{tenantID, locationID} - query := `SELECT a.*, b.productlocationid, b.status, + // b.price is the per-store selling price. It has to be selected explicitly: + // a.* only covers products (whose price column is retailprice, the master + // price), so without this the catalogue could never read back a price set + // for this outlet via CreateProductLocation. + query := `SELECT a.*, b.productlocationid, b.status, b.price, COALESCE(SUM(CASE WHEN UPPER(c.stocktype) = 'IN' THEN c.quantity ELSE 0 END), 0) AS total_in, COALESCE(SUM(CASE WHEN UPPER(c.stocktype) = 'OUT' THEN c.quantity ELSE 0 END), 0) AS total_out, COALESCE(SUM(CASE WHEN UPPER(c.stocktype) = 'IN' THEN c.quantity ELSE 0 END) - @@ -427,7 +431,7 @@ func (r *productRepository) GetLocationProducts(tenantID, locationID, subcategor query += ` GROUP BY a.productid, a.productname, a.productimage, a.categoryid, a.subcategoryid, a.productunit, a.productcost, a.taxpercent, a.taxamount, a.retailprice, - b.tenantid, b.locationid, b.productlocationid, b.status + b.tenantid, b.locationid, b.productlocationid, b.status, b.price ORDER BY a.productid DESC LIMIT ? OFFSET ?` params = append(params, pagesize, offset)