1、库存调拨详情增加库存数量的字段;
2、修复导出采购报表(按商品)excel最后1行商品信息不全的缺陷;
This commit is contained in:
parent
5c9cfd8e14
commit
95c7fd228e
|
@ -306,7 +306,12 @@ func InventoryAllotDetail(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
allotOrder.Commodities = models.MergeCommodities(allotCommodities)
|
||||
mergeCommodities := models.MergeCommodities(allotCommodities)
|
||||
allotOrder.Commodities = mergeCommodities
|
||||
|
||||
// 查询商品的库存数量
|
||||
allotOrder.Commodities, _ = models.UpdateStockCounts(mergeCommodities, allotOrder.DeliverStoreId)
|
||||
|
||||
app.OK(c, allotOrder, "查询成功")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ type ErpInventoryAllotCommodity struct {
|
|||
Count uint32 `json:"count"` // 数量
|
||||
Amount float64 `json:"amount"` // 金额(采购价)
|
||||
Remark string `json:"remark"` // 备注
|
||||
StockCount uint32 `json:"stock_count" gorm:"-"` // 库存数量
|
||||
}
|
||||
|
||||
// InventoryAllotAddReq 新增库存调拨入参
|
||||
|
@ -786,6 +787,46 @@ func MergeCommodities(commodities []ErpInventoryAllotCommodity) []ErpInventoryAl
|
|||
return mergedCommodities
|
||||
}
|
||||
|
||||
// UpdateStockCounts 根据传入的 storeId 更新每个商品的库存数量。
|
||||
func UpdateStockCounts(commodities []ErpInventoryAllotCommodity, storeId uint32) ([]ErpInventoryAllotCommodity, error) {
|
||||
// 收集商品 ID
|
||||
var commodityIDs []uint32
|
||||
for _, commodity := range commodities {
|
||||
commodityIDs = append(commodityIDs, commodity.CommodityId)
|
||||
}
|
||||
|
||||
// 查询数据库中的库存数量
|
||||
var stockCounts []struct {
|
||||
ErpCommodityID uint32 `gorm:"column:erp_commodity_id"`
|
||||
StockCount int64 `gorm:"column:stock_count"`
|
||||
}
|
||||
err := orm.Eloquent.Table("erp_stock_commodity").
|
||||
Where("erp_commodity_id IN (?) AND state = ? AND store_id = ?", commodityIDs, InStock, storeId).
|
||||
Select("erp_commodity_id, COUNT(*) as stock_count").
|
||||
Group("erp_commodity_id").
|
||||
Scan(&stockCounts).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 创建库存数量映射
|
||||
stockCountMap := make(map[uint32]int64)
|
||||
for _, stock := range stockCounts {
|
||||
stockCountMap[stock.ErpCommodityID] = stock.StockCount
|
||||
}
|
||||
|
||||
// 更新商品的 StockCount 字段
|
||||
for i, commodity := range commodities {
|
||||
if count, exists := stockCountMap[commodity.CommodityId]; exists {
|
||||
commodities[i].StockCount = uint32(count)
|
||||
} else {
|
||||
commodities[i].StockCount = 0 // 如果没有库存记录,则默认为 0
|
||||
}
|
||||
}
|
||||
|
||||
return commodities, nil
|
||||
}
|
||||
|
||||
// MergeAllCommodities 遍历库存调拨商品信息,将商品id相同的所有商品进行合并,数量累加即可
|
||||
func MergeAllCommodities(commodities []ErpInventoryAllotCommodity) []ErpInventoryAllotCommodity {
|
||||
// 用于存储合并后的商品信息
|
||||
|
|
|
@ -4895,7 +4895,7 @@ func reportByCommodityExport(req *ErpPurchaseReportByCommodityResp) (string, err
|
|||
req.NonExecutionCount, // 未执行数量
|
||||
}
|
||||
for i, _ := range end {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+i, nExcelStartRow+2)
|
||||
cell, _ := excelize.CoordinatesToCellName(1+i, nExcelStartRow+3)
|
||||
err := file.SetCellValue(fSheet, cell, end[i])
|
||||
if err != nil {
|
||||
logger.Error("file set value err:", logger.Field("err", err))
|
||||
|
@ -4934,7 +4934,7 @@ func reportByCommodityExport(req *ErpPurchaseReportByCommodityResp) (string, err
|
|||
file.SetColWidth("Sheet1", "C", "C", 13)
|
||||
file.SetColWidth("Sheet1", "E", "E", 25)
|
||||
|
||||
endRow := fmt.Sprintf("Q"+"%d", nExcelStartRow+2)
|
||||
endRow := fmt.Sprintf("Q"+"%d", nExcelStartRow+3)
|
||||
// 应用样式到整个表格
|
||||
_ = file.SetCellStyle("Sheet1", "A1", endRow, style)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user