stocks change

This commit is contained in:
2026-07-27 18:54:40 +05:30
parent f57127444f
commit c2f7d2481c
2 changed files with 16 additions and 7 deletions

View File

@@ -124,11 +124,16 @@ type Locationproducts struct {
Productcombo int `json:"productcombo" gorm:"default:0"` Productcombo int `json:"productcombo" gorm:"default:0"`
Variants int `json:"variants" gorm:"default:0"` Variants int `json:"variants" gorm:"default:0"`
Quantity int `json:"quantity"` Quantity int `json:"quantity"`
Retailprice float64 `json:"retailprice,omitempty"` // Price is the per-store selling price from productlocations.price — the one
Diffprice float64 `json:"diffprice,omitempty"` // CreateProductLocation upserts. Read-only here: it comes from the joined
Diffpercent float64 `json:"diffpercent,omitempty"` // productlocations row, not from products. Without it a store could set a
Othercost float64 `json:"othercost,omitempty"` // price and never read it back, so the UI always showed the master price.
Approve int `json:"approve" gorm:"default:0"` 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"` // Productstatus string `json:"productstatus" gorm:"default:available"`
Status string `json:"status" gorm:"default:outofstock"` Status string `json:"status" gorm:"default:outofstock"`
} }

View File

@@ -405,7 +405,11 @@ func (r *productRepository) GetLocationProducts(tenantID, locationID, subcategor
params := []interface{}{tenantID, locationID} 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) = '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) = '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) - 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, query += ` GROUP BY a.productid, a.productname, a.productimage, a.categoryid, a.subcategoryid,
a.productunit, a.productcost, a.taxpercent, a.taxamount, a.retailprice, 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 ?` ORDER BY a.productid DESC LIMIT ? OFFSET ?`
params = append(params, pagesize, offset) params = append(params, pagesize, offset)