1、修改采购报表(按商品)的excel导出功能,增加"一级分类"、"二级分类",同一个商品下每个采购单都填充商品信息;
This commit is contained in:
parent
aae1718e7c
commit
9d676a0607
|
@ -231,3 +231,48 @@ func TransformErpCategoryIds(categoryIds []uint32) ([]uint32, error) {
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CategoryLevels 代表分类层级信息
|
||||
type CategoryLevels struct {
|
||||
Level1 Category `json:"level1"`
|
||||
Level2 Category `json:"level2,omitempty"`
|
||||
Level3 Category `json:"level3,omitempty"`
|
||||
}
|
||||
|
||||
// GetCategoryLevels 根据商品分类ID获取分类层级信息
|
||||
func GetCategoryLevels(categoryID uint32) (CategoryLevels, error) {
|
||||
var levels CategoryLevels
|
||||
|
||||
// 维持当前分类的ID
|
||||
currentID := categoryID
|
||||
levelCount := 0
|
||||
|
||||
for currentID != 0 && levelCount < 3 {
|
||||
var currentCategory Category
|
||||
|
||||
// 查询当前分类
|
||||
err := orm.Eloquent.Model(&Category{}).Where("id = ?", currentID).First(¤tCategory).Error
|
||||
if err != nil {
|
||||
return levels, err
|
||||
}
|
||||
|
||||
// 根据分类编号的长度判断层级
|
||||
numberLength := len(currentCategory.Number)
|
||||
switch numberLength {
|
||||
case 3:
|
||||
levels.Level1 = currentCategory // 一级分类
|
||||
case 6:
|
||||
levels.Level2 = currentCategory // 二级分类
|
||||
case 9:
|
||||
levels.Level3 = currentCategory // 三级分类
|
||||
default:
|
||||
return levels, nil // 超过9位返回空
|
||||
}
|
||||
|
||||
// 移动到上级分类
|
||||
currentID = currentCategory.Pid
|
||||
levelCount++
|
||||
}
|
||||
|
||||
return levels, nil
|
||||
}
|
||||
|
|
|
@ -4924,9 +4924,9 @@ func reportByCommodityExport(req *ErpPurchaseReportByCommodityResp) (string, err
|
|||
fmt.Println("url fileName:", url+fileName)
|
||||
|
||||
// 组合标题栏数据
|
||||
title1 := []interface{}{"商品名称", "商品分类", "单据编号", "类型", "店铺名称", "供应商", "经手人", "制单人", "审核时间",
|
||||
title1 := []interface{}{"商品名称", "商品分类", "", "", "单据编号", "类型", "店铺名称", "供应商", "经手人", "制单人", "审核时间",
|
||||
"计划采购", "", "", "已执行", "", "", "未执行", ""}
|
||||
title2 := []interface{}{"商品名称", "商品分类", "单据编号", "类型", "店铺名称", "供应商", "经手人", "制单人", "审核时间",
|
||||
title2 := []interface{}{"商品名称", "一级分类", "二级分类", "三级分类", "单据编号", "类型", "店铺名称", "供应商", "经手人", "制单人", "审核时间",
|
||||
"采购金额", "采购单价", "采购数量", "已执行金额", "执行单价", "已执行数量", "未执行金额", "未执行数量"}
|
||||
for i, _ := range title1 {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+i, 1)
|
||||
|
@ -4948,9 +4948,12 @@ func reportByCommodityExport(req *ErpPurchaseReportByCommodityResp) (string, err
|
|||
var row2 []interface{}
|
||||
nExcelStartRow := 0
|
||||
for _, commodityData := range req.List {
|
||||
categoryLevels, _ := GetCategoryLevels(commodityData.ErpCategoryID)
|
||||
row1 = []interface{}{
|
||||
commodityData.ErpCommodityName, // 商品名称
|
||||
commodityData.ErpCategoryName, // 商品分类
|
||||
categoryLevels.Level1.Name, // 一级分类
|
||||
categoryLevels.Level2.Name, // 二级分类
|
||||
categoryLevels.Level3.Name, // 三级分类
|
||||
"", // 单据编号
|
||||
"", // 类型
|
||||
"", // 店铺名称
|
||||
|
@ -4994,23 +4997,25 @@ func reportByCommodityExport(req *ErpPurchaseReportByCommodityResp) (string, err
|
|||
}
|
||||
|
||||
row2 = []interface{}{
|
||||
"", // 商品名称
|
||||
"", // 商品分类
|
||||
orderData.SerialNumber, // 单据编号
|
||||
orderType, // 类型
|
||||
orderData.StoreName, // 店铺名称
|
||||
orderData.ErpSupplierName, // 供应商
|
||||
orderData.HandlerName, // 经手人
|
||||
orderData.MakerName, // 制单人
|
||||
strTime, // 审核时间
|
||||
orderData.PlanAmount, // 计划采购金额
|
||||
orderData.PlanPrice, // 计划采购单价
|
||||
orderData.PlanCount, // 计划采购数量
|
||||
orderData.Amount, // 已执行金额
|
||||
orderData.Price, // 已执行单价
|
||||
orderData.Count, // 已执行数量
|
||||
orderData.NonExecutionAmount, // 未执行金额
|
||||
orderData.NonExecutionCount, // 未执行数量
|
||||
commodityData.ErpCommodityName, // 商品名称
|
||||
categoryLevels.Level1.Name, // 一级分类
|
||||
categoryLevels.Level2.Name, // 二级分类
|
||||
categoryLevels.Level3.Name, // 三级分类
|
||||
orderData.SerialNumber, // 单据编号
|
||||
orderType, // 类型
|
||||
orderData.StoreName, // 店铺名称
|
||||
orderData.ErpSupplierName, // 供应商
|
||||
orderData.HandlerName, // 经手人
|
||||
orderData.MakerName, // 制单人
|
||||
strTime, // 审核时间
|
||||
orderData.PlanAmount, // 计划采购金额
|
||||
orderData.PlanPrice, // 计划采购单价
|
||||
orderData.PlanCount, // 计划采购数量
|
||||
orderData.Amount, // 已执行金额
|
||||
orderData.Price, // 已执行单价
|
||||
orderData.Count, // 已执行数量
|
||||
orderData.NonExecutionAmount, // 未执行金额
|
||||
orderData.NonExecutionCount, // 未执行数量
|
||||
}
|
||||
|
||||
for j, _ := range row2 {
|
||||
|
@ -5025,7 +5030,7 @@ func reportByCommodityExport(req *ErpPurchaseReportByCommodityResp) (string, err
|
|||
}
|
||||
|
||||
totalData := "订单数:" + strconv.FormatInt(int64(req.Total), 10)
|
||||
end := []interface{}{totalData, "", "", "", "", "", "", "", "",
|
||||
end := []interface{}{totalData, "", "", "", "", "", "", "", "", "", "",
|
||||
req.PlanAmount, // 计划采购金额
|
||||
"--", // 计划采购单价
|
||||
req.PlanCount, // 计划采购数量
|
||||
|
@ -5052,30 +5057,30 @@ func reportByCommodityExport(req *ErpPurchaseReportByCommodityResp) (string, err
|
|||
|
||||
// 合并单元格
|
||||
_ = file.MergeCell(fSheet, "A1", "A2")
|
||||
_ = file.MergeCell(fSheet, "B1", "B2")
|
||||
_ = file.MergeCell(fSheet, "C1", "C2")
|
||||
_ = file.MergeCell(fSheet, "D1", "D2")
|
||||
_ = file.MergeCell(fSheet, "B1", "D1")
|
||||
_ = file.MergeCell(fSheet, "E1", "E2")
|
||||
_ = file.MergeCell(fSheet, "F1", "F2")
|
||||
_ = file.MergeCell(fSheet, "G1", "G2")
|
||||
_ = file.MergeCell(fSheet, "H1", "H2")
|
||||
_ = file.MergeCell(fSheet, "I1", "I2")
|
||||
_ = file.MergeCell(fSheet, "J1", "J2")
|
||||
_ = file.MergeCell(fSheet, "K1", "K2")
|
||||
|
||||
_ = file.MergeCell(fSheet, "J1", "L1")
|
||||
_ = file.MergeCell(fSheet, "M1", "O1")
|
||||
_ = file.MergeCell(fSheet, "P1", "Q1")
|
||||
_ = file.MergeCell(fSheet, "L1", "N1")
|
||||
_ = file.MergeCell(fSheet, "O1", "Q1")
|
||||
_ = file.MergeCell(fSheet, "R1", "S1")
|
||||
|
||||
//设置单元格高度
|
||||
file.SetRowHeight("Sheet1", 1, 20)
|
||||
file.SetRowHeight("Sheet1", 2, 20)
|
||||
|
||||
// 设置单元格大小
|
||||
file.SetColWidth("Sheet1", "A", "A", 15)
|
||||
file.SetColWidth("Sheet1", "A", "A", 30)
|
||||
file.SetColWidth("Sheet1", "B", "B", 10)
|
||||
file.SetColWidth("Sheet1", "C", "C", 13)
|
||||
file.SetColWidth("Sheet1", "E", "E", 25)
|
||||
file.SetColWidth("Sheet1", "E", "E", 13)
|
||||
file.SetColWidth("Sheet1", "G", "G", 25)
|
||||
|
||||
endRow := fmt.Sprintf("Q"+"%d", nExcelStartRow+3)
|
||||
endRow := fmt.Sprintf("S"+"%d", nExcelStartRow+3)
|
||||
// 应用样式到整个表格
|
||||
_ = file.SetCellStyle("Sheet1", "A1", endRow, style)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user