1、解决采购需求页面库存数量统计不准确的问题,初始值由0改成1;

2、导出库存详excel时增加"库存数量"列,数量默认为1,方便采购进行excel数据透视;
This commit is contained in:
chenlin 2024-09-02 17:43:34 +08:00
parent c8cedfb72e
commit 5d99ba9e64
2 changed files with 23 additions and 13 deletions

View File

@ -1573,8 +1573,8 @@ func InventoryDetailListExport(list []ErpStockCommodity, c *gin.Context) (string
logger.Info("exportStaffCostPrice is:", logger.Field("exportStaffCostPrice", exportStaffCostPrice))
// 设置标题行
title := []interface{}{"商品编号", "商品名称", "商品分类", "是否串码", "商品串码", "所属门店", "供应商", "首次入库时间", "首次入库方式",
"首次入库订单编号", "最近入库时间"}
title := []interface{}{"商品编号", "商品名称", "商品分类", "是否串码", "商品串码", "所属门店", "供应商", "库存数量",
"首次入库时间", "首次入库方式", "首次入库订单编号", "最近入库时间"}
if exportPurchasePrice {
title = append(title, "入库采购价")
@ -1626,6 +1626,7 @@ func InventoryDetailListExport(list []ErpStockCommodity, c *gin.Context) (string
list[rowId].IMEI,
list[rowId].StoreName,
list[rowId].ErpSupplierName,
1,
list[rowId].FirstStockTime,
storageType,
list[rowId].OriginalSn,

View File

@ -1937,6 +1937,15 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get
}
}
commodityIDs := make([]uint32, len(commodities))
for i, commodity := range commodities {
commodityIDs[i] = commodity.ID
}
if len(commodityIDs) == 0 {
return resp, nil
}
// 批量查询商品上月销售数量
var soldOutCommodities []ErpStockCommodity
firstDay, lastDay := GetLastMonthRange() // 获取上个月的时间范围
@ -1947,12 +1956,12 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get
}
if len(storeIdList) > 1 {
err = orm.Eloquent.Table("erp_stock_commodity").
Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id in (?)",
SoldOut, firstDay, lastDay, storeIdList).Find(&soldOutCommodities).Error
Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id in (?) AND erp_commodity_id IN (?)",
SoldOut, firstDay, lastDay, storeIdList, commodityIDs).Find(&soldOutCommodities).Error
} else {
err = orm.Eloquent.Table("erp_stock_commodity").
Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id = ?",
SoldOut, firstDay, lastDay, storeIdList[0]).Find(&soldOutCommodities).Error
Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id = ? AND erp_commodity_id IN (?)",
SoldOut, firstDay, lastDay, storeIdList[0], commodityIDs).Find(&soldOutCommodities).Error
}
if err != nil {
return nil, err
@ -1973,12 +1982,12 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get
var stockCommodities []ErpStockCommodity
if len(storeIdList) > 1 {
err = orm.Eloquent.Table("erp_stock_commodity").
Where("state = ? AND store_id in (?)",
InStock, storeIdList).Find(&stockCommodities).Error
Where("state = ? AND store_id in (?) AND erp_commodity_id IN (?)",
InStock, storeIdList, commodityIDs).Find(&stockCommodities).Error
} else {
err = orm.Eloquent.Table("erp_stock_commodity").
Where("state = ? AND store_id = ?",
InStock, storeIdList[0]).Find(&stockCommodities).Error
Where("state = ? AND store_id = ? AND erp_commodity_id IN (?)",
InStock, storeIdList[0], commodityIDs).Find(&stockCommodities).Error
}
if err != nil {
return nil, err
@ -1991,14 +2000,14 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get
if exist { // 存在
inStockMap[key] += 1
} else { // 不存在
inStockMap[key] = 0
inStockMap[key] = 1
}
}
// 查询采购需求单信息
var demand []ErpPurchaseDemand
demandQs := orm.Eloquent.Table("erp_purchase_demand").
Where("state = 1").Where("count <> 0")
Where("state = 1").Where("count <> 0").Where("erp_commodity_id IN (?)", commodityIDs)
if len(storeIdList) > 0 {
if len(storeIdList) == 1 {
demandQs = demandQs.Where("store_id = ?", storeIdList[0])
@ -2016,7 +2025,7 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get
demandRemarkQs := orm.Eloquent.Table("erp_purchase_demand_remark").
Where("state = 1").
Where("remark IS NOT NULL").
Where("remark <> ''")
Where("remark <> ''").Where("erp_commodity_id IN (?)", commodityIDs)
err = demandRemarkQs.Find(&demandRemarkInfo).Error
if err != nil {
return nil, err