Browse Source

添加成品单据管理

liwei 2 years ago
parent
commit
7e01f39733

+ 309 - 0
boxcost/api/bill-product.go

@@ -0,0 +1,309 @@
+package api
+
+import (
+	"box-cost/db/model"
+	"box-cost/db/repo"
+	"box-cost/log"
+	"errors"
+	"fmt"
+	"time"
+
+	"github.com/gin-gonic/gin"
+	"github.com/xuri/excelize/v2"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+// 成品采购单据管理
+func BillProduct(r *GinRouter) {
+
+	// 创建单据
+	r.POSTJWT("/bill/product/create", CreateProductBill)
+
+	// 获取单据详情
+	r.GET("/bill/product/detail/:id", GetProductBill)
+
+	// 获取单据列表
+	r.GET("/bill/product/list", GetProductBills)
+
+	// 更新单据
+	r.POST("/bill/product/update", UpdateProductBill)
+
+	// 删除单据
+	r.POST("/bill/product/delete/:id", DelProductBill)
+
+	//下载单据
+	r.GET("/bill/product/download", DownProductBill)
+
+	// 审核单据
+	r.POSTJWT("/bill/product/review/:id", ProductReview)
+}
+
+// 审核单据
+func ProductReview(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, err := primitive.ObjectIDFromHex(_id)
+	if err != nil {
+		return nil, errors.New("id错误")
+	}
+	userId, err := primitive.ObjectIDFromHex(apictx.User.Parent)
+	if err != nil {
+		return nil, errors.New("用户异常")
+	}
+	user, err := getUserById(apictx, userId)
+	if err != nil {
+		return nil, errors.New("查找用户失败")
+	}
+	if !isManager(user.Roles) {
+		return nil, errors.New("该用户没有权限")
+	}
+	// 查询单据获取已有的签字
+	bill := model.ProduceBill{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduce,
+		Query:       repo.Map{"_id": id, "reviewed": 1},
+	}, &bill)
+	signs := make([]primitive.ObjectID, 0)
+	if len(bill.SignUsers) > 0 {
+		// 如果自己已存在该集合中了
+		for _, signUser := range bill.SignUsers {
+			if signUser == userId {
+				return nil, errors.New("该单据您已审核过了")
+			}
+		}
+		signs = bill.SignUsers
+	}
+
+	// 更改状态为已审核 并签字
+	signs = append(signs, userId)
+	produce := model.ProduceBill{
+		Reviewed:   1,
+		UpdateTime: time.Now(),
+		SignUsers:  signs,
+	}
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, _id, &produce)
+
+}
+
+// 创建成品采购单据
+func CreateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+
+	bill := &model.ProductBill{}
+	err := c.ShouldBindJSON(bill)
+	if err != nil {
+		fmt.Println(err)
+		return nil, errors.New("参数错误!")
+	}
+	ctx := apictx.CreateRepoCtx()
+
+	if bill.PackId.Hex() == "" {
+		return nil, errors.New("包装产品id为空")
+	}
+	if bill.PlanId.Hex() == "" {
+		return nil, errors.New("生产计划id为空")
+	}
+	if bill.Type == "" {
+		return nil, errors.New("类型为空")
+	}
+
+	bill.SerialNumber, err = generateSerial(apictx, bill.Type)
+	if err != nil {
+		return nil, err
+	}
+
+	bill.Status = "created"
+	if bill.Reviewed == 0 {
+		bill.Reviewed = -1
+	}
+	bill.CreateTime = time.Now()
+	bill.UpdateTime = time.Now()
+	// 制单人数据
+	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
+	fmt.Println("userId:", apictx.User.Parent)
+	if !userId.IsZero() {
+		user, err := getUserById(apictx, userId)
+		if err == nil {
+			bill.UserName = user.Name
+			bill.UserId = userId
+		}
+	}
+
+	result, err := repo.RepoAddDoc(ctx, repo.CollectionBillProduct, &bill)
+	return result, err
+}
+
+// 获取单据信息
+func GetProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	billId := c.Param("id")
+	id, err := primitive.ObjectIDFromHex(billId)
+	if err != nil {
+		return nil, errors.New("非法id")
+	}
+	var bill model.ProductBill
+	option := &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduce,
+		Query:       repo.Map{"_id": id},
+	}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), option, &bill)
+	if !found || err != nil {
+		log.Info(err)
+		return nil, errors.New("数据未找到")
+	}
+
+	return bill, nil
+}
+
+// 获取单据列表
+func GetProductBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+
+	page, size, query := UtilQueryPageSize(c)
+
+	if query["packId"] != nil {
+		query["packId"], _ = primitive.ObjectIDFromHex(query["packId"].(string))
+	}
+	if query["planId"] != nil {
+		query["planId"], _ = primitive.ObjectIDFromHex(query["planId"].(string))
+	}
+
+	// 时间范围查询
+	// createTime 选中的当天时间
+	st, ok1 := query["startTime"]
+	delete(query, "startTime")
+	et, ok2 := query["endTime"]
+	delete(query, "endTime")
+	if ok1 && ok2 {
+		startTime := st.(string)
+		endTime := et.(string)
+		start, end := getTimeRange(startTime, endTime)
+		query["createTime"] = bson.M{"$gte": start, "$lte": end}
+	}
+
+	option := &repo.PageSearchOptions{
+		CollectName: repo.CollectionBillProduce,
+		Query:       query,
+		Page:        page,
+		Size:        size,
+		Sort:        bson.M{"createTime": -1},
+	}
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
+}
+
+// 更新单据
+func UpdateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var bill model.ProduceBill
+	err := c.ShouldBindJSON(&bill)
+	if err != nil {
+		fmt.Println(err)
+		return nil, errors.New("参数错误")
+	}
+	if bill.Id.Hex() == "" {
+		return nil, errors.New("id的为空")
+	}
+
+	billType, err := searchBillTypeById(apictx, repo.CollectionBillProduct, bill.Id)
+	if err != nil {
+		return nil, err
+	}
+
+	// 如果更改类型
+	if billType != bill.Type {
+		bill.SerialNumber, err = generateSerial(apictx, bill.Type)
+		if err != nil {
+			return nil, err
+		}
+	}
+	// 计算结算价格
+	if bill.Status == "complete" {
+		bill.CompleteTime = time.Now()
+	}
+
+	bill.UpdateTime = time.Now()
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, bill.Id.Hex(), &bill)
+}
+
+// 删除单据
+func DelProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	billId := c.Param("id")
+	if billId == "" {
+		return nil, errors.New("id为空")
+	}
+
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, billId)
+}
+
+func DownProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	billId := c.Query("id")
+	isPdf := c.Query("isPdf")
+	if len(billId) < 1 {
+		return nil, fmt.Errorf("id不能为空")
+	}
+
+	id, err := primitive.ObjectIDFromHex(billId)
+	if err != nil {
+		return nil, errors.New("非法id")
+	}
+	var bill model.ProductBill
+	option := &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduct,
+		Query:       repo.Map{"_id": id},
+	}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), option, &bill)
+	if !found || err != nil {
+		log.Info(err)
+		return nil, errors.New("数据未找到")
+	}
+
+	f := excelize.NewFile()
+	// Create a new sheet.
+	index := f.NewSheet("Sheet1")
+	f.SetActiveSheet(index)
+	f.SetDefaultFont("宋体")
+
+	billExcel := NewProduceBill(f)
+	// 获取已审核的签名数据
+	if bill.Reviewed == 1 {
+		if len(bill.SignUsers) > 0 {
+			signs := []*model.Signature{}
+			repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+				CollectName: repo.CollectionSignature,
+				Query:       repo.Map{"_id": bson.M{"$in": bill.SignUsers}},
+				Sort:        bson.M{"sort": 1}, // 升序
+			}, &signs)
+			billExcel.Signatures = signs
+		}
+
+	}
+	// billExcel.Content = &bill
+	companyName := getCompanyName(apictx)
+	billExcel.Title = fmt.Sprintf("%s加工单", companyName)
+	//设置对应的数据
+	billExcel.Draws()
+
+	// 下载为pdf
+	if isPdf == "true" {
+		buf, _ := f.WriteToBuffer()
+		res, err := excelToPdf(buf, apictx.Svc.Conf.PdfApiAddr)
+		if err != nil {
+			return nil, errors.New("转化pdf失败")
+		}
+		c.Header("Content-Type", "application/octet-stream")
+		c.Header("Content-Disposition", "attachment; filename="+"bill.pdf")
+		c.Header("Content-Transfer-Encoding", "binary")
+		err = res.Write(c.Writer)
+		if err != nil {
+			return nil, err
+		}
+		return nil, nil
+	}
+
+	c.Header("Content-Type", "application/octet-stream")
+	c.Header("Content-Disposition", "attachment; filename="+"bill.xlsx")
+	c.Header("Content-Transfer-Encoding", "binary")
+
+	err = f.Write(c.Writer)
+	if err != nil {
+		return nil, err
+	}
+
+	return nil, nil
+}

+ 706 - 713
boxcost/api/plan-cost-excel.go

@@ -1,715 +1,708 @@
 package api
 
-import (
-	"fmt"
-
-	"github.com/xuri/excelize/v2"
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-// 生产成本表
-type PlanCostExcel struct {
-	Offset int
-
-	Title string //标题
-
-	Excel *excelize.File
-
-	SheetName string
-
-	AlignCenterStyle int
-	Row              int
-
-	// Content *model.ProductPlan
-	Content *SupplierPlanCost
-}
-
-func (b *PlanCostExcel) drawTitle() error {
-	tileIndex := b.Offset + 1
-	startCell := fmt.Sprintf("A%d", tileIndex)
-	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("M%d", tileIndex))
-	if err != nil {
-		return err
-	}
-
-	style, err := b.Excel.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
-		Font:      &excelize.Font{Bold: true, Size: 18}})
-	if err != nil {
-		return err
-	}
-	err = b.Excel.SetCellStyle(b.SheetName, startCell, startCell, style)
-	if err != nil {
-		return err
-	}
-	b.Excel.SetRowHeight(b.SheetName, tileIndex, 23)
-	b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
-	return nil
-}
-
-func (b *PlanCostExcel) drawTableTitle() error {
-	row := b.Offset + 2
-
-	//A采购项目 B规格(克) 尺寸C-D 数量E 单价F-G 交货时间H 备注I
-	// A产品名称
-	var drawCol = func(prefix string, value string) error {
-		left1Cell := fmt.Sprintf("%s%d", prefix, row)
-		left2Cell := fmt.Sprintf("%s%d", prefix, row+1)
-
-		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
-		if err != nil {
-			return err
-		}
-		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
-		if err != nil {
-			return err
-		}
-
-		return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-	}
-
-	var drawCol2 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
-		left1Cell := fmt.Sprintf("%s%d", prefix1, row)
-		left2Cell := fmt.Sprintf("%s%d", prefix2, row)
-		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
-		if err != nil {
-			return err
-		}
-		if err != nil {
-			fmt.Println(err)
-			return err
-		}
-		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
-		if err != nil {
-			return err
-		}
-		b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
-
-		val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
-		b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
-
-		val3Cel := fmt.Sprintf("%s%d", prefix2, row+1)
-		b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
-		return nil
-	}
-	var drawCol3 = func(prefix1 string, prefix2 string, prefix3 string, value1 string, value2 string, value3 string, value4 string) error {
-		left1Cell := fmt.Sprintf("%s%d", prefix1, row)
-		// left2Cell := fmt.Sprintf("%s%d", prefix2, row)
-		left3Cell := fmt.Sprintf("%s%d", prefix3, row)
-		err := b.Excel.MergeCell(b.SheetName, left1Cell, left3Cell)
-		if err != nil {
-			return err
-		}
-		if err != nil {
-			fmt.Println(err)
-			return err
-		}
-		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left3Cell, b.AlignCenterStyle)
-		if err != nil {
-			return err
-		}
-		b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
-
-		val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
-		b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
-
-		val3Cel := fmt.Sprintf("%s%d", prefix2, row+1)
-		b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
-
-		val4Cel := fmt.Sprintf("%s%d", prefix3, row+1)
-		b.Excel.SetCellStyle(b.SheetName, val4Cel, val4Cel, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, val4Cel, value4)
-		return nil
-	}
-
-	drawCol("A", "产品部件名称")
-	drawCol2("B", "C", "材料/工序", "材料", "工序")
-	drawCol("D", "供应商名称")
-	drawCol3("E", "F", "G", "规格", "厚度(纸克)", "长", "宽")
-	drawCol("H", "单位")
-	drawCol("I", "下单数量")
-	drawCol("J", "实际数量")
-	drawCol("K", "单价")
-	drawCol("L", "预算金额")
-	drawCol("M", "实际金额")
-	return nil
-}
-
-func (b *PlanCostExcel) drawSupplierContent() error {
-	supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
-	if err != nil {
-		return err
-	}
-	row := b.Offset + 4
-	comps := b.Content.Pack.Components
-	// 预算金额汇总
-	var totalOrderRealPrice float64 = 0.00
-	// 实际金额汇总
-	var totalRealPrice float64 = 0.00
-	if len(comps) > 0 {
-		for _, comp := range comps {
-			var perOrderRealPrice float64 = 0.00
-			var perRealPrice float64 = 0.00
-
-			if len(comp.Mats) > 0 {
-				startRow := 0
-				for _, mat := range comp.Mats {
-					if mat.Supplier.SupplierInfo != nil {
-						if supplierId == mat.Supplier.SupplierInfo.Id {
-							// 材料
-							if startRow == 0 {
-								startRow = row
-
-							}
-
-							supplierName := ""
-							if mat.Supplier.SupplierInfo != nil {
-								supplierName = mat.Supplier.SupplierInfo.Name
-							}
-							matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
-							b.FormatToEmpty(&matHeigth)
-							matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
-							b.FormatToEmpty(&matWidth)
-							orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
-							b.FormatToEmpty(&orderCount)
-
-							// 实际数量
-							confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
-							b.FormatToEmpty(&confirmCount)
-							// 单价
-							orderPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderPrice)
-							b.FormatToEmpty(&orderPrice)
-							// 预算金额
-							orderRealPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderRealPrice)
-							perOrderRealPrice += mat.Supplier.OrderRealPrice
-							b.FormatToEmpty(&orderRealPrice)
-							// 实际金额
-							perRealPrice += mat.RealPrice
-							realPrice := fmt.Sprintf("%.3f", mat.RealPrice)
-							b.FormatToEmpty(&realPrice)
-							if mat.MatInfo.Unit == "吨" || mat.MatInfo.Unit == "平方米" {
-								mat.MatInfo.Unit = "张"
-							}
-
-							b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, realPrice)
-
-							row++
-						}
-
-					}
-
-					if len(mat.Crafts) > 0 {
-						// 实际数量、预算数量
-						// mergeStartRow := row
-						// mergeEndRow := row
-						cates := map[string]MergeRow{}
-						for _, craft := range mat.Crafts {
-							if craft.Supplier.SupplierInfo != nil { // 外箱材料报错
-								// 工序
-								if supplierId == craft.Supplier.SupplierInfo.Id {
-									if startRow == 0 {
-										startRow = row
-
-									}
-
-									supplierName := ""
-									if craft.Supplier.SupplierInfo != nil {
-										supplierName = craft.Supplier.SupplierInfo.Name
-									}
-
-									orderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
-									b.FormatToEmpty(&orderCount)
-									carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
-									b.FormatToEmpty(&carftHeigth)
-									carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
-									b.FormatToEmpty(&carftWidth)
-
-									// 实际数量
-									confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
-									b.FormatToEmpty(&confirmCount)
-									price := fmt.Sprintf("%.3f", craft.Supplier.OrderPrice)
-									b.FormatToEmpty(&price)
-
-									// 预算金额
-									budgetAmount := ""
-									b.FormatToEmpty(&budgetAmount)
-
-									// 实际金额 在外层合并单元格
-									realAmount := ""
-
-									if craft.CraftInfo.Unit == "吨" || craft.CraftInfo.Unit == "平方米" {
-										craft.CraftInfo.Unit = "张"
-									}
-
-									b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
-									// mergeEndRow = row
-									category := craft.CraftInfo.Category
-									cates[category] = MergeRow{
-										Rows:         append(cates[category].Rows, row),
-										RealAmount:   craft.RealPrice,
-										BudgetAmount: craft.Supplier.OrderRealPrice,
-									}
-
-									row++
-								}
-
-							}
-
-						}
-
-						fmt.Println(cates)
-						for _, cate := range cates {
-							mergeStartRow := cate.Rows[0]
-							mergeEndRow := cate.Rows[len(cate.Rows)-1]
-							orderRealPrice := cate.BudgetAmount
-							realPrice := cate.RealAmount
-							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
-							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), orderRealPrice)
-							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
-							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), realPrice)
-							perRealPrice += realPrice
-							perOrderRealPrice += orderRealPrice
-						}
-						// 多个工序 合并预算价格、实际价格
-						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
-						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), mat.Crafts[0].Supplier.OrderRealPrice)
-						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
-						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), mat.Crafts[0].RealPrice)
-						// perRealPrice += mat.Crafts[0].RealPrice
-						// perOrderRealPrice += mat.Crafts[0].Supplier.OrderRealPrice
-
-					}
-				}
-				if startRow != 0 {
-					endRow := row - 1
-					// 组件名字
-					startACell := fmt.Sprintf("%s%d", "A", startRow)
-					endACell := fmt.Sprintf("%s%d", "A", endRow)
-					b.Excel.MergeCell(b.SheetName, startACell, endACell)
-
-					err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
-					if err != nil {
-						return err
-					}
-					b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
-
-				}
-
-			}
-			// 预算
-			totalOrderRealPrice += perOrderRealPrice
-			// 预算
-			totalRealPrice += perRealPrice
-		}
-
-	}
-
-	// 工序数据
-	if b.Content.Process != nil {
-		if len(b.Content.Process) > 0 {
-			isSupplier := false
-			for _, ps := range b.Content.Process {
-				if supplierId == ps.Supplier.SupplierInfo.Id {
-					isSupplier = true
-					break
-				}
-			}
-
-			if isSupplier {
-				// 生产汇总金额
-				startACell := fmt.Sprintf("%s%d", "A", row)
-				endMCell := fmt.Sprintf("%s%d", "K", row)
-				b.Excel.MergeCell(b.SheetName, startACell, endMCell)
-				b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
-				b.Excel.SetCellValue(b.SheetName, startACell, "额外工序")
-				row++
-				// 工序 外箱 手工费 表头
-				var drawCol = func(startCell, endCell string, value string) error {
-					left1Cell := fmt.Sprintf("%s%d", startCell, row)
-					left2Cell := fmt.Sprintf("%s%d", endCell, row)
-					err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
-					if err != nil {
-						return err
-					}
-					err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
-					if err != nil {
-						return err
-					}
-
-					return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-				}
-
-				drawCol("A", "A", "")
-				drawCol("B", "C", "材料/工序")
-				drawCol("D", "E", "供应商名称")
-				drawCol("F", "G", "规格")
-				drawCol("H", "H", "单位")
-				drawCol("I", "I", "下单数量")
-				drawCol("J", "J", "实际数量")
-				drawCol("K", "K", "单价")
-				drawCol("L", "L", "预算金额")
-				drawCol("M", "M", "实际金额")
-				row++
-				if len(b.Content.Process) > 0 {
-					for _, ps := range b.Content.Process {
-						orderCount := fmt.Sprintf("%.3f", ps.Supplier.OrderCount)
-						confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
-						price := fmt.Sprintf("%.3f", ps.Supplier.OrderPrice)
-						b.FormatToEmpty(&price)
-						totalOrderRealPrice += ps.Supplier.OrderRealPrice
-						totalRealPrice += ps.RealPrice
-						orderRealPrice := fmt.Sprintf("%.3f", ps.Supplier.OrderRealPrice)
-						b.FormatToEmpty(&orderRealPrice)
-						realPrice := fmt.Sprintf("%.3f", ps.RealPrice)
-						supplierName := ""
-						if ps.Supplier.SupplierInfo != nil {
-							supplierName = ps.Supplier.SupplierInfo.Name
-						}
-
-						b.drawRow(row, "", "", "", "", "", "", "", ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
-
-						b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "B", row), fmt.Sprintf("%s%d", "C", row))
-						b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "B", row), ps.ProcessInfo.Name)
-
-						b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "D", row), fmt.Sprintf("%s%d", "E", row))
-						b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "D", row), supplierName)
-
-						b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "F", row), fmt.Sprintf("%s%d", "G", row))
-						b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "F", row), ps.ProcessInfo.Norm)
-
-						row++
-					}
-
-				}
-
-			}
-
-		}
-
-	}
-
-	// 生产汇总金额
-	startACell := fmt.Sprintf("%s%d", "A", row)
-	endKCell := fmt.Sprintf("%s%d", "K", row)
-	LCell := fmt.Sprintf("%s%d", "L", row)
-	MCell := fmt.Sprintf("%s%d", "M", row)
-	b.Excel.MergeCell(b.SheetName, startACell, endKCell)
-	b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
-	b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
-
-	// 生产预算汇总
-	b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
-	planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderRealPrice)
-	b.FormatToEmpty(&planOrderRealPrice)
-	b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
-
-	// 生产实际汇总
-	b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
-	planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
-	b.FormatToEmpty(&planRealPrice)
-	b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
-
-	return nil
-}
-
-func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
-	charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"}
-	for i, c := range charas {
-		v := ""
-		if i < len(values) {
-			v = values[i]
-		}
-		b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
-
-		val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
-		b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
-
-		b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
-	}
-
-}
-
-type MergeRow struct {
-	Rows         []int
-	RealAmount   float64
-	BudgetAmount float64
-}
-
-func (b *PlanCostExcel) drawAllContent() error {
-	row := b.Offset + 4
-	comps := b.Content.Pack.Components
-	// 预算金额汇总
-	var totalOrderRealPrice float64 = 0.00
-	// 实际金额汇总
-	var totalRealPrice float64 = 0.00
-	if len(comps) > 0 {
-		for _, comp := range comps {
-			var perOrderRealPrice float64 = 0.00
-			var perRealPrice float64 = 0.00
-			if len(comp.Mats) > 0 {
-				startRow := row
-				for _, mat := range comp.Mats {
-					// 材料
-					supplierName := ""
-					if mat.Supplier.SupplierInfo != nil {
-						supplierName = mat.Supplier.SupplierInfo.Name
-					}
-					matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
-					b.FormatToEmpty(&matHeigth)
-					matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
-					b.FormatToEmpty(&matWidth)
-					orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
-					b.FormatToEmpty(&orderCount)
-
-					// 实际数量
-					confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
-					b.FormatToEmpty(&confirmCount)
-					// 单价
-					orderPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderPrice)
-					b.FormatToEmpty(&orderPrice)
-					// 预算金额
-					orderRealPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderRealPrice)
-					perOrderRealPrice += mat.Supplier.OrderRealPrice
-					b.FormatToEmpty(&orderRealPrice)
-					// 实际金额
-					perRealPrice += mat.RealPrice
-					realPrice := fmt.Sprintf("%.3f", mat.RealPrice)
-					b.FormatToEmpty(&realPrice)
-					if mat.MatInfo.Unit == "吨" || mat.MatInfo.Unit == "平方米" {
-						mat.MatInfo.Unit = "张"
-					}
-					b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, realPrice)
-
-					row++
-					if len(mat.Crafts) > 0 {
-						// 实际数量、预算数量
-						// mergeStartRow := row
-						// mergeEndRow := row
-
-						cates := map[string]MergeRow{}
-						for _, craft := range mat.Crafts {
-
-							supplierName := ""
-							if craft.Supplier.SupplierInfo != nil {
-								supplierName = craft.Supplier.SupplierInfo.Name
-							}
-
-							orderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
-							b.FormatToEmpty(&orderCount)
-							carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
-							b.FormatToEmpty(&carftHeigth)
-							carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
-							b.FormatToEmpty(&carftWidth)
-
-							// 实际数量
-							confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
-							b.FormatToEmpty(&confirmCount)
-							price := fmt.Sprintf("%.3f", craft.Supplier.OrderPrice)
-							b.FormatToEmpty(&price)
-
-							// 预算金额
-							budgetAmount := ""
-							b.FormatToEmpty(&budgetAmount)
-
-							// 实际金额 在外层合并单元格
-							realAmount := ""
-							if craft.CraftInfo.Unit == "吨" || craft.CraftInfo.Unit == "平方米" {
-								craft.CraftInfo.Unit = "张"
-							}
-							b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
-							// mergeEndRow = row
-
-							category := craft.CraftInfo.Category
-							cates[category] = MergeRow{
-								Rows:         append(cates[category].Rows, row),
-								RealAmount:   craft.RealPrice,
-								BudgetAmount: craft.Supplier.OrderRealPrice,
-							}
-							row++
-
-						}
-						// 获取分类合并
-						fmt.Println(cates)
-						for _, cate := range cates {
-							mergeStartRow := cate.Rows[0]
-							mergeEndRow := cate.Rows[len(cate.Rows)-1]
-							orderRealPrice := cate.BudgetAmount
-							realPrice := cate.RealAmount
-							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
-							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), orderRealPrice)
-							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
-							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), realPrice)
-							perRealPrice += realPrice
-							perOrderRealPrice += orderRealPrice
-
-						}
-						// 多个工序 合并预算价格、实际价格
-						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
-						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), mat.Crafts[0].Supplier.OrderRealPrice)
-						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
-						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), mat.Crafts[0].RealPrice)
-						// perRealPrice += mat.Crafts[0].RealPrice
-						// perOrderRealPrice += mat.Crafts[0].Supplier.OrderRealPrice
-					}
-				}
-				endRow := row - 1
-				// 组件名字
-				startACell := fmt.Sprintf("%s%d", "A", startRow)
-				endACell := fmt.Sprintf("%s%d", "A", endRow)
-				b.Excel.MergeCell(b.SheetName, startACell, endACell)
-				err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
-				if err != nil {
-					return err
-				}
-				b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
-			}
-
-			// 预算
-			totalOrderRealPrice += perOrderRealPrice
-			// 实际金额
-			totalRealPrice += perRealPrice
-		}
-	}
-	// 工序数据
-	if b.Content.Process != nil {
-		// 生产汇总金额
-		startACell := fmt.Sprintf("%s%d", "A", row)
-		endMCell := fmt.Sprintf("%s%d", "K", row)
-		b.Excel.MergeCell(b.SheetName, startACell, endMCell)
-		b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, startACell, "额外工序")
-		row++
-		// 工序 外箱 手工费 表头
-		var drawCol = func(startCell, endCell string, value string) error {
-			left1Cell := fmt.Sprintf("%s%d", startCell, row)
-			left2Cell := fmt.Sprintf("%s%d", endCell, row)
-			err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
-			if err != nil {
-				return err
-			}
-			err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
-			if err != nil {
-				return err
-			}
-
-			return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-		}
-
-		drawCol("A", "A", "")
-		drawCol("B", "C", "材料/工序")
-		drawCol("D", "E", "供应商名称")
-		drawCol("F", "G", "规格")
-		drawCol("H", "H", "单位")
-		drawCol("I", "I", "下单数量")
-		drawCol("J", "J", "实际数量")
-		drawCol("K", "K", "单价")
-		drawCol("L", "L", "预算金额")
-		drawCol("M", "M", "实际金额")
-		row++
-		if len(b.Content.Process) > 0 {
-			for _, ps := range b.Content.Process {
-				orderCount := fmt.Sprintf("%.3f", ps.Supplier.OrderCount)
-				confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
-				price := fmt.Sprintf("%.3f", ps.Supplier.OrderPrice)
-				b.FormatToEmpty(&price)
-				totalOrderRealPrice += ps.Supplier.OrderRealPrice
-				totalRealPrice += ps.RealPrice
-				orderRealPrice := fmt.Sprintf("%.3f", ps.Supplier.OrderRealPrice)
-				b.FormatToEmpty(&orderRealPrice)
-				realPrice := fmt.Sprintf("%.3f", ps.RealPrice)
-				supplierName := ""
-				if ps.Supplier.SupplierInfo != nil {
-					supplierName = ps.Supplier.SupplierInfo.Name
-				}
-
-				b.drawRow(row, "", "", "", "", "", "", "", ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
-
-				b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "B", row), fmt.Sprintf("%s%d", "C", row))
-				b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "B", row), ps.ProcessInfo.Name)
-
-				b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "D", row), fmt.Sprintf("%s%d", "E", row))
-				b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "D", row), supplierName)
-
-				b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "F", row), fmt.Sprintf("%s%d", "G", row))
-				b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "F", row), ps.ProcessInfo.Norm)
-
-				row++
-			}
-
-		}
-
-	}
-	// 生产汇总金额
-	startACell := fmt.Sprintf("%s%d", "A", row)
-	endKCell := fmt.Sprintf("%s%d", "K", row)
-	LCell := fmt.Sprintf("%s%d", "L", row)
-	MCell := fmt.Sprintf("%s%d", "M", row)
-	b.Excel.MergeCell(b.SheetName, startACell, endKCell)
-	b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
-	b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
-
-	// 生产预算汇总
-	b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
-	planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderRealPrice)
-	b.FormatToEmpty(&planOrderRealPrice)
-	b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
-
-	// 生产实际汇总
-	b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
-	planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
-	b.FormatToEmpty(&planRealPrice)
-	b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
-
-	return nil
-}
-
-func (b *PlanCostExcel) Draws() {
-	b.drawTitle()
-	b.drawTableTitle()
-	if b.Content.SupplierId != "" {
-		b.drawSupplierContent()
-	} else {
-		b.drawAllContent()
-	}
-
-}
-
-func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
-
-	border := []excelize.Border{
-		{Type: "top", Style: 1, Color: "000000"},
-		{Type: "left", Style: 1, Color: "000000"},
-		{Type: "right", Style: 1, Color: "000000"},
-		{Type: "bottom", Style: 1, Color: "000000"},
-	}
-
-	styleLeft, _ := f.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
-		Border:    border,
-		Font:      &excelize.Font{Size: 10},
-	})
-
-	b := &PlanCostExcel{
-		Title:            "生产成本表",
-		SheetName:        "Sheet1",
-		Excel:            f,
-		Offset:           0,
-		AlignCenterStyle: styleLeft,
-	}
-
-	f.SetColWidth(b.SheetName, "A", "D", 12)
-	f.SetColWidth(b.SheetName, "E", "M", 10)
-	f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
-	return b
-}
-
-func (b *PlanCostExcel) FormatToEmpty(str *string) {
-	if *str == "0" || *str == "0.000" {
-		*str = ""
-	}
-
-}
+// // 生产成本表
+// type PlanCostExcel struct {
+// 	Offset int
+
+// 	Title string //标题
+
+// 	Excel *excelize.File
+
+// 	SheetName string
+
+// 	AlignCenterStyle int
+// 	Row              int
+
+// 	// Content *model.ProductPlan
+// 	Content *SupplierPlanCost
+// }
+
+// func (b *PlanCostExcel) drawTitle() error {
+// 	tileIndex := b.Offset + 1
+// 	startCell := fmt.Sprintf("A%d", tileIndex)
+// 	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("M%d", tileIndex))
+// 	if err != nil {
+// 		return err
+// 	}
+
+// 	style, err := b.Excel.NewStyle(&excelize.Style{
+// 		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
+// 		Font:      &excelize.Font{Bold: true, Size: 18}})
+// 	if err != nil {
+// 		return err
+// 	}
+// 	err = b.Excel.SetCellStyle(b.SheetName, startCell, startCell, style)
+// 	if err != nil {
+// 		return err
+// 	}
+// 	b.Excel.SetRowHeight(b.SheetName, tileIndex, 23)
+// 	b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
+// 	return nil
+// }
+
+// func (b *PlanCostExcel) drawTableTitle() error {
+// 	row := b.Offset + 2
+
+// 	//A采购项目 B规格(克) 尺寸C-D 数量E 单价F-G 交货时间H 备注I
+// 	// A产品名称
+// 	var drawCol = func(prefix string, value string) error {
+// 		left1Cell := fmt.Sprintf("%s%d", prefix, row)
+// 		left2Cell := fmt.Sprintf("%s%d", prefix, row+1)
+
+// 		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
+// 		if err != nil {
+// 			return err
+// 		}
+// 		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
+// 		if err != nil {
+// 			return err
+// 		}
+
+// 		return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
+// 	}
+
+// 	var drawCol2 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
+// 		left1Cell := fmt.Sprintf("%s%d", prefix1, row)
+// 		left2Cell := fmt.Sprintf("%s%d", prefix2, row)
+// 		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
+// 		if err != nil {
+// 			return err
+// 		}
+// 		if err != nil {
+// 			fmt.Println(err)
+// 			return err
+// 		}
+// 		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
+// 		if err != nil {
+// 			return err
+// 		}
+// 		b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
+
+// 		val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
+// 		b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
+// 		b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
+
+// 		val3Cel := fmt.Sprintf("%s%d", prefix2, row+1)
+// 		b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
+// 		b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
+// 		return nil
+// 	}
+// 	var drawCol3 = func(prefix1 string, prefix2 string, prefix3 string, value1 string, value2 string, value3 string, value4 string) error {
+// 		left1Cell := fmt.Sprintf("%s%d", prefix1, row)
+// 		// left2Cell := fmt.Sprintf("%s%d", prefix2, row)
+// 		left3Cell := fmt.Sprintf("%s%d", prefix3, row)
+// 		err := b.Excel.MergeCell(b.SheetName, left1Cell, left3Cell)
+// 		if err != nil {
+// 			return err
+// 		}
+// 		if err != nil {
+// 			fmt.Println(err)
+// 			return err
+// 		}
+// 		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left3Cell, b.AlignCenterStyle)
+// 		if err != nil {
+// 			return err
+// 		}
+// 		b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
+
+// 		val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
+// 		b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
+// 		b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
+
+// 		val3Cel := fmt.Sprintf("%s%d", prefix2, row+1)
+// 		b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
+// 		b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
+
+// 		val4Cel := fmt.Sprintf("%s%d", prefix3, row+1)
+// 		b.Excel.SetCellStyle(b.SheetName, val4Cel, val4Cel, b.AlignCenterStyle)
+// 		b.Excel.SetCellValue(b.SheetName, val4Cel, value4)
+// 		return nil
+// 	}
+
+// 	drawCol("A", "产品部件名称")
+// 	drawCol2("B", "C", "材料/工序", "材料", "工序")
+// 	drawCol("D", "供应商名称")
+// 	drawCol3("E", "F", "G", "规格", "厚度(纸克)", "长", "宽")
+// 	drawCol("H", "单位")
+// 	drawCol("I", "下单数量")
+// 	drawCol("J", "实际数量")
+// 	drawCol("K", "单价")
+// 	drawCol("L", "预算金额")
+// 	drawCol("M", "实际金额")
+// 	return nil
+// }
+
+// func (b *PlanCostExcel) drawSupplierContent() error {
+// 	supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
+// 	if err != nil {
+// 		return err
+// 	}
+// 	row := b.Offset + 4
+// 	comps := b.Content.Pack.Components
+// 	// 预算金额汇总
+// 	var totalOrderRealPrice float64 = 0.00
+// 	// 实际金额汇总
+// 	var totalRealPrice float64 = 0.00
+// 	if len(comps) > 0 {
+// 		for _, comp := range comps {
+// 			var perOrderRealPrice float64 = 0.00
+// 			var perRealPrice float64 = 0.00
+
+// 			if len(comp.Mats) > 0 {
+// 				startRow := 0
+// 				for _, mat := range comp.Mats {
+// 					if mat.Supplier.SupplierInfo != nil {
+// 						if supplierId == mat.Supplier.SupplierInfo.Id {
+// 							// 材料
+// 							if startRow == 0 {
+// 								startRow = row
+
+// 							}
+
+// 							supplierName := ""
+// 							if mat.Supplier.SupplierInfo != nil {
+// 								supplierName = mat.Supplier.SupplierInfo.Name
+// 							}
+// 							matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
+// 							b.FormatToEmpty(&matHeigth)
+// 							matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
+// 							b.FormatToEmpty(&matWidth)
+// 							orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
+// 							b.FormatToEmpty(&orderCount)
+
+// 							// 实际数量
+// 							confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
+// 							b.FormatToEmpty(&confirmCount)
+// 							// 单价
+// 							orderPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderPrice)
+// 							b.FormatToEmpty(&orderPrice)
+// 							// 预算金额
+// 							orderRealPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderRealPrice)
+// 							perOrderRealPrice += mat.Supplier.OrderRealPrice
+// 							b.FormatToEmpty(&orderRealPrice)
+// 							// 实际金额
+// 							perRealPrice += mat.RealPrice
+// 							realPrice := fmt.Sprintf("%.3f", mat.RealPrice)
+// 							b.FormatToEmpty(&realPrice)
+// 							if mat.MatInfo.Unit == "吨" || mat.MatInfo.Unit == "平方米" {
+// 								mat.MatInfo.Unit = "张"
+// 							}
+
+// 							b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, realPrice)
+
+// 							row++
+// 						}
+
+// 					}
+
+// 					if len(mat.Crafts) > 0 {
+// 						// 实际数量、预算数量
+// 						// mergeStartRow := row
+// 						// mergeEndRow := row
+// 						cates := map[string]MergeRow{}
+// 						for _, craft := range mat.Crafts {
+// 							if craft.Supplier.SupplierInfo != nil { // 外箱材料报错
+// 								// 工序
+// 								if supplierId == craft.Supplier.SupplierInfo.Id {
+// 									if startRow == 0 {
+// 										startRow = row
+
+// 									}
+
+// 									supplierName := ""
+// 									if craft.Supplier.SupplierInfo != nil {
+// 										supplierName = craft.Supplier.SupplierInfo.Name
+// 									}
+
+// 									orderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
+// 									b.FormatToEmpty(&orderCount)
+// 									carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
+// 									b.FormatToEmpty(&carftHeigth)
+// 									carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
+// 									b.FormatToEmpty(&carftWidth)
+
+// 									// 实际数量
+// 									confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
+// 									b.FormatToEmpty(&confirmCount)
+// 									price := fmt.Sprintf("%.3f", craft.Supplier.OrderPrice)
+// 									b.FormatToEmpty(&price)
+
+// 									// 预算金额
+// 									budgetAmount := ""
+// 									b.FormatToEmpty(&budgetAmount)
+
+// 									// 实际金额 在外层合并单元格
+// 									realAmount := ""
+
+// 									if craft.CraftInfo.Unit == "吨" || craft.CraftInfo.Unit == "平方米" {
+// 										craft.CraftInfo.Unit = "张"
+// 									}
+
+// 									b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
+// 									// mergeEndRow = row
+// 									category := craft.CraftInfo.Category
+// 									cates[category] = MergeRow{
+// 										Rows:         append(cates[category].Rows, row),
+// 										RealAmount:   craft.RealPrice,
+// 										BudgetAmount: craft.Supplier.OrderRealPrice,
+// 									}
+
+// 									row++
+// 								}
+
+// 							}
+
+// 						}
+
+// 						fmt.Println(cates)
+// 						for _, cate := range cates {
+// 							mergeStartRow := cate.Rows[0]
+// 							mergeEndRow := cate.Rows[len(cate.Rows)-1]
+// 							orderRealPrice := cate.BudgetAmount
+// 							realPrice := cate.RealAmount
+// 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
+// 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), orderRealPrice)
+// 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
+// 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), realPrice)
+// 							perRealPrice += realPrice
+// 							perOrderRealPrice += orderRealPrice
+// 						}
+// 						// 多个工序 合并预算价格、实际价格
+// 						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
+// 						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), mat.Crafts[0].Supplier.OrderRealPrice)
+// 						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
+// 						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), mat.Crafts[0].RealPrice)
+// 						// perRealPrice += mat.Crafts[0].RealPrice
+// 						// perOrderRealPrice += mat.Crafts[0].Supplier.OrderRealPrice
+
+// 					}
+// 				}
+// 				if startRow != 0 {
+// 					endRow := row - 1
+// 					// 组件名字
+// 					startACell := fmt.Sprintf("%s%d", "A", startRow)
+// 					endACell := fmt.Sprintf("%s%d", "A", endRow)
+// 					b.Excel.MergeCell(b.SheetName, startACell, endACell)
+
+// 					err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
+// 					if err != nil {
+// 						return err
+// 					}
+// 					b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
+
+// 				}
+
+// 			}
+// 			// 预算
+// 			totalOrderRealPrice += perOrderRealPrice
+// 			// 预算
+// 			totalRealPrice += perRealPrice
+// 		}
+
+// 	}
+
+// 	// 工序数据
+// 	if b.Content.Process != nil {
+// 		if len(b.Content.Process) > 0 {
+// 			isSupplier := false
+// 			for _, ps := range b.Content.Process {
+// 				if supplierId == ps.Supplier.SupplierInfo.Id {
+// 					isSupplier = true
+// 					break
+// 				}
+// 			}
+
+// 			if isSupplier {
+// 				// 生产汇总金额
+// 				startACell := fmt.Sprintf("%s%d", "A", row)
+// 				endMCell := fmt.Sprintf("%s%d", "K", row)
+// 				b.Excel.MergeCell(b.SheetName, startACell, endMCell)
+// 				b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
+// 				b.Excel.SetCellValue(b.SheetName, startACell, "额外工序")
+// 				row++
+// 				// 工序 外箱 手工费 表头
+// 				var drawCol = func(startCell, endCell string, value string) error {
+// 					left1Cell := fmt.Sprintf("%s%d", startCell, row)
+// 					left2Cell := fmt.Sprintf("%s%d", endCell, row)
+// 					err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
+// 					if err != nil {
+// 						return err
+// 					}
+// 					err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
+// 					if err != nil {
+// 						return err
+// 					}
+
+// 					return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
+// 				}
+
+// 				drawCol("A", "A", "")
+// 				drawCol("B", "C", "材料/工序")
+// 				drawCol("D", "E", "供应商名称")
+// 				drawCol("F", "G", "规格")
+// 				drawCol("H", "H", "单位")
+// 				drawCol("I", "I", "下单数量")
+// 				drawCol("J", "J", "实际数量")
+// 				drawCol("K", "K", "单价")
+// 				drawCol("L", "L", "预算金额")
+// 				drawCol("M", "M", "实际金额")
+// 				row++
+// 				if len(b.Content.Process) > 0 {
+// 					for _, ps := range b.Content.Process {
+// 						orderCount := fmt.Sprintf("%.3f", ps.Supplier.OrderCount)
+// 						confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
+// 						price := fmt.Sprintf("%.3f", ps.Supplier.OrderPrice)
+// 						b.FormatToEmpty(&price)
+// 						totalOrderRealPrice += ps.Supplier.OrderRealPrice
+// 						totalRealPrice += ps.RealPrice
+// 						orderRealPrice := fmt.Sprintf("%.3f", ps.Supplier.OrderRealPrice)
+// 						b.FormatToEmpty(&orderRealPrice)
+// 						realPrice := fmt.Sprintf("%.3f", ps.RealPrice)
+// 						supplierName := ""
+// 						if ps.Supplier.SupplierInfo != nil {
+// 							supplierName = ps.Supplier.SupplierInfo.Name
+// 						}
+
+// 						b.drawRow(row, "", "", "", "", "", "", "", ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
+
+// 						b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "B", row), fmt.Sprintf("%s%d", "C", row))
+// 						b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "B", row), ps.ProcessInfo.Name)
+
+// 						b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "D", row), fmt.Sprintf("%s%d", "E", row))
+// 						b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "D", row), supplierName)
+
+// 						b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "F", row), fmt.Sprintf("%s%d", "G", row))
+// 						b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "F", row), ps.ProcessInfo.Norm)
+
+// 						row++
+// 					}
+
+// 				}
+
+// 			}
+
+// 		}
+
+// 	}
+
+// 	// 生产汇总金额
+// 	startACell := fmt.Sprintf("%s%d", "A", row)
+// 	endKCell := fmt.Sprintf("%s%d", "K", row)
+// 	LCell := fmt.Sprintf("%s%d", "L", row)
+// 	MCell := fmt.Sprintf("%s%d", "M", row)
+// 	b.Excel.MergeCell(b.SheetName, startACell, endKCell)
+// 	b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
+// 	b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
+
+// 	// 生产预算汇总
+// 	b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
+// 	planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderRealPrice)
+// 	b.FormatToEmpty(&planOrderRealPrice)
+// 	b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
+
+// 	// 生产实际汇总
+// 	b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
+// 	planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
+// 	b.FormatToEmpty(&planRealPrice)
+// 	b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
+
+// 	return nil
+// }
+
+// func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
+// 	charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"}
+// 	for i, c := range charas {
+// 		v := ""
+// 		if i < len(values) {
+// 			v = values[i]
+// 		}
+// 		b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
+
+// 		val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
+// 		b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
+
+// 		b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
+// 	}
+
+// }
+
+// type MergeRow struct {
+// 	Rows         []int
+// 	RealAmount   float64
+// 	BudgetAmount float64
+// }
+
+// func (b *PlanCostExcel) drawAllContent() error {
+// 	row := b.Offset + 4
+// 	comps := b.Content.Pack.Components
+// 	// 预算金额汇总
+// 	var totalOrderRealPrice float64 = 0.00
+// 	// 实际金额汇总
+// 	var totalRealPrice float64 = 0.00
+// 	if len(comps) > 0 {
+// 		for _, comp := range comps {
+// 			var perOrderRealPrice float64 = 0.00
+// 			var perRealPrice float64 = 0.00
+// 			if len(comp.Mats) > 0 {
+// 				startRow := row
+// 				for _, mat := range comp.Mats {
+// 					// 材料
+// 					supplierName := ""
+// 					if mat.Supplier.SupplierInfo != nil {
+// 						supplierName = mat.Supplier.SupplierInfo.Name
+// 					}
+// 					matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
+// 					b.FormatToEmpty(&matHeigth)
+// 					matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
+// 					b.FormatToEmpty(&matWidth)
+// 					orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
+// 					b.FormatToEmpty(&orderCount)
+
+// 					// 实际数量
+// 					confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
+// 					b.FormatToEmpty(&confirmCount)
+// 					// 单价
+// 					orderPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderPrice)
+// 					b.FormatToEmpty(&orderPrice)
+// 					// 预算金额
+// 					orderRealPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderRealPrice)
+// 					perOrderRealPrice += mat.Supplier.OrderRealPrice
+// 					b.FormatToEmpty(&orderRealPrice)
+// 					// 实际金额
+// 					perRealPrice += mat.RealPrice
+// 					realPrice := fmt.Sprintf("%.3f", mat.RealPrice)
+// 					b.FormatToEmpty(&realPrice)
+// 					if mat.MatInfo.Unit == "吨" || mat.MatInfo.Unit == "平方米" {
+// 						mat.MatInfo.Unit = "张"
+// 					}
+// 					b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, realPrice)
+
+// 					row++
+// 					if len(mat.Crafts) > 0 {
+// 						// 实际数量、预算数量
+// 						// mergeStartRow := row
+// 						// mergeEndRow := row
+
+// 						cates := map[string]MergeRow{}
+// 						for _, craft := range mat.Crafts {
+
+// 							supplierName := ""
+// 							if craft.Supplier.SupplierInfo != nil {
+// 								supplierName = craft.Supplier.SupplierInfo.Name
+// 							}
+
+// 							orderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
+// 							b.FormatToEmpty(&orderCount)
+// 							carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
+// 							b.FormatToEmpty(&carftHeigth)
+// 							carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
+// 							b.FormatToEmpty(&carftWidth)
+
+// 							// 实际数量
+// 							confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
+// 							b.FormatToEmpty(&confirmCount)
+// 							price := fmt.Sprintf("%.3f", craft.Supplier.OrderPrice)
+// 							b.FormatToEmpty(&price)
+
+// 							// 预算金额
+// 							budgetAmount := ""
+// 							b.FormatToEmpty(&budgetAmount)
+
+// 							// 实际金额 在外层合并单元格
+// 							realAmount := ""
+// 							if craft.CraftInfo.Unit == "吨" || craft.CraftInfo.Unit == "平方米" {
+// 								craft.CraftInfo.Unit = "张"
+// 							}
+// 							b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
+// 							// mergeEndRow = row
+
+// 							category := craft.CraftInfo.Category
+// 							cates[category] = MergeRow{
+// 								Rows:         append(cates[category].Rows, row),
+// 								RealAmount:   craft.RealPrice,
+// 								BudgetAmount: craft.Supplier.OrderRealPrice,
+// 							}
+// 							row++
+
+// 						}
+// 						// 获取分类合并
+// 						fmt.Println(cates)
+// 						for _, cate := range cates {
+// 							mergeStartRow := cate.Rows[0]
+// 							mergeEndRow := cate.Rows[len(cate.Rows)-1]
+// 							orderRealPrice := cate.BudgetAmount
+// 							realPrice := cate.RealAmount
+// 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
+// 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), orderRealPrice)
+// 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
+// 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), realPrice)
+// 							perRealPrice += realPrice
+// 							perOrderRealPrice += orderRealPrice
+
+// 						}
+// 						// 多个工序 合并预算价格、实际价格
+// 						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
+// 						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), mat.Crafts[0].Supplier.OrderRealPrice)
+// 						// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
+// 						// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), mat.Crafts[0].RealPrice)
+// 						// perRealPrice += mat.Crafts[0].RealPrice
+// 						// perOrderRealPrice += mat.Crafts[0].Supplier.OrderRealPrice
+// 					}
+// 				}
+// 				endRow := row - 1
+// 				// 组件名字
+// 				startACell := fmt.Sprintf("%s%d", "A", startRow)
+// 				endACell := fmt.Sprintf("%s%d", "A", endRow)
+// 				b.Excel.MergeCell(b.SheetName, startACell, endACell)
+// 				err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
+// 				if err != nil {
+// 					return err
+// 				}
+// 				b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
+// 			}
+
+// 			// 预算
+// 			totalOrderRealPrice += perOrderRealPrice
+// 			// 实际金额
+// 			totalRealPrice += perRealPrice
+// 		}
+// 	}
+// 	// 工序数据
+// 	if b.Content.Process != nil {
+// 		// 生产汇总金额
+// 		startACell := fmt.Sprintf("%s%d", "A", row)
+// 		endMCell := fmt.Sprintf("%s%d", "K", row)
+// 		b.Excel.MergeCell(b.SheetName, startACell, endMCell)
+// 		b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
+// 		b.Excel.SetCellValue(b.SheetName, startACell, "额外工序")
+// 		row++
+// 		// 工序 外箱 手工费 表头
+// 		var drawCol = func(startCell, endCell string, value string) error {
+// 			left1Cell := fmt.Sprintf("%s%d", startCell, row)
+// 			left2Cell := fmt.Sprintf("%s%d", endCell, row)
+// 			err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
+// 			if err != nil {
+// 				return err
+// 			}
+// 			err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
+// 			if err != nil {
+// 				return err
+// 			}
+
+// 			return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
+// 		}
+
+// 		drawCol("A", "A", "")
+// 		drawCol("B", "C", "材料/工序")
+// 		drawCol("D", "E", "供应商名称")
+// 		drawCol("F", "G", "规格")
+// 		drawCol("H", "H", "单位")
+// 		drawCol("I", "I", "下单数量")
+// 		drawCol("J", "J", "实际数量")
+// 		drawCol("K", "K", "单价")
+// 		drawCol("L", "L", "预算金额")
+// 		drawCol("M", "M", "实际金额")
+// 		row++
+// 		if len(b.Content.Process) > 0 {
+// 			for _, ps := range b.Content.Process {
+// 				orderCount := fmt.Sprintf("%.3f", ps.Supplier.OrderCount)
+// 				confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
+// 				price := fmt.Sprintf("%.3f", ps.Supplier.OrderPrice)
+// 				b.FormatToEmpty(&price)
+// 				totalOrderRealPrice += ps.Supplier.OrderRealPrice
+// 				totalRealPrice += ps.RealPrice
+// 				orderRealPrice := fmt.Sprintf("%.3f", ps.Supplier.OrderRealPrice)
+// 				b.FormatToEmpty(&orderRealPrice)
+// 				realPrice := fmt.Sprintf("%.3f", ps.RealPrice)
+// 				supplierName := ""
+// 				if ps.Supplier.SupplierInfo != nil {
+// 					supplierName = ps.Supplier.SupplierInfo.Name
+// 				}
+
+// 				b.drawRow(row, "", "", "", "", "", "", "", ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
+
+// 				b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "B", row), fmt.Sprintf("%s%d", "C", row))
+// 				b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "B", row), ps.ProcessInfo.Name)
+
+// 				b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "D", row), fmt.Sprintf("%s%d", "E", row))
+// 				b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "D", row), supplierName)
+
+// 				b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "F", row), fmt.Sprintf("%s%d", "G", row))
+// 				b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "F", row), ps.ProcessInfo.Norm)
+
+// 				row++
+// 			}
+
+// 		}
+
+// 	}
+// 	// 生产汇总金额
+// 	startACell := fmt.Sprintf("%s%d", "A", row)
+// 	endKCell := fmt.Sprintf("%s%d", "K", row)
+// 	LCell := fmt.Sprintf("%s%d", "L", row)
+// 	MCell := fmt.Sprintf("%s%d", "M", row)
+// 	b.Excel.MergeCell(b.SheetName, startACell, endKCell)
+// 	b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
+// 	b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
+
+// 	// 生产预算汇总
+// 	b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
+// 	planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderRealPrice)
+// 	b.FormatToEmpty(&planOrderRealPrice)
+// 	b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
+
+// 	// 生产实际汇总
+// 	b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
+// 	planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
+// 	b.FormatToEmpty(&planRealPrice)
+// 	b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
+
+// 	return nil
+// }
+
+// func (b *PlanCostExcel) Draws() {
+// 	b.drawTitle()
+// 	b.drawTableTitle()
+// 	if b.Content.SupplierId != "" {
+// 		b.drawSupplierContent()
+// 	} else {
+// 		b.drawAllContent()
+// 	}
+
+// }
+
+// func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
+
+// 	border := []excelize.Border{
+// 		{Type: "top", Style: 1, Color: "000000"},
+// 		{Type: "left", Style: 1, Color: "000000"},
+// 		{Type: "right", Style: 1, Color: "000000"},
+// 		{Type: "bottom", Style: 1, Color: "000000"},
+// 	}
+
+// 	styleLeft, _ := f.NewStyle(&excelize.Style{
+// 		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
+// 		Border:    border,
+// 		Font:      &excelize.Font{Size: 10},
+// 	})
+
+// 	b := &PlanCostExcel{
+// 		Title:            "生产成本表",
+// 		SheetName:        "Sheet1",
+// 		Excel:            f,
+// 		Offset:           0,
+// 		AlignCenterStyle: styleLeft,
+// 	}
+
+// 	f.SetColWidth(b.SheetName, "A", "D", 12)
+// 	f.SetColWidth(b.SheetName, "E", "M", 10)
+// 	f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
+// 	return b
+// }
+
+// func (b *PlanCostExcel) FormatToEmpty(str *string) {
+// 	if *str == "0" || *str == "0.000" {
+// 		*str = ""
+// 	}
+
+// }

+ 151 - 152
boxcost/api/plan.go

@@ -9,7 +9,6 @@ import (
 	"time"
 
 	"github.com/gin-gonic/gin"
-	"github.com/xuri/excelize/v2"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
@@ -33,10 +32,10 @@ func ProductPlan(r *GinRouter) {
 	r.POST("/plan/delete/:id", DelProductPlan)
 
 	// 下载部件打印单
-	r.GET("/bill/plan/download", DownLoadPlan)
+	// r.GET("/bill/plan/download", DownLoadPlan)
 
 	// 生产成本表
-	r.GET("/plan/cost/download", DownLoadPlanCost)
+	// r.GET("/plan/cost/download", DownLoadPlanCost)
 
 }
 
@@ -45,155 +44,155 @@ type SupplierPlanCost struct {
 	SupplierId string
 }
 
-func DownLoadPlanCost(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_planId := c.Query("id")
-	supplierId := c.Query("supplierId")
-	planId, err := primitive.ObjectIDFromHex(_planId)
-	if err != nil {
-		return nil, errors.New("planId错误")
-	}
-	supplierPlanCost := &SupplierPlanCost{}
-
-	plan := model.ProductPlan{}
-	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionProductPlan,
-		Query:       repo.Map{"_id": planId},
-	}, &plan)
-	if !found || err != nil {
-		return nil, errors.New("数据未找到")
-	}
-	supplierPlanCost.ProductPlan = &plan
-	supplierPlanCost.SupplierId = supplierId
-
-	f := excelize.NewFile()
-	index := f.NewSheet("Sheet1")
-	f.SetActiveSheet(index)
-	f.SetDefaultFont("宋体")
-	planCostExcel := NewPlanCostExcel(f)
-	planCostExcel.Title = fmt.Sprintf("生产成本表(%s)%d盒", plan.Name, plan.Total)
-	planCostExcel.Content = supplierPlanCost
-	planCostExcel.Draws()
-
-	c.Header("Content-Type", "application/octet-stream")
-	c.Header("Content-Disposition", "attachment; filename="+"planCost.xlsx")
-	c.Header("Content-Transfer-Encoding", "binary")
-
-	err = f.Write(c.Writer)
-	if err != nil {
-		return nil, err
-	}
-	return nil, nil
-
-}
-func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_planId := c.Query("id")
-	compId := c.Query("compId")
-	planId, err := primitive.ObjectIDFromHex(_planId)
-	if err != nil {
-		return nil, errors.New("planId错误")
-	}
-	plan := model.ProductPlan{}
-	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionProductPlan,
-		Query:       repo.Map{"_id": planId},
-	}, &plan)
-	if !found || err != nil {
-		return nil, errors.New("数据未找到")
-	}
-	// 获取部件单据
-	curComp := &model.PackComponent{}
-	for _, comp := range plan.Pack.Components {
-		if comp.Id == compId {
-			curComp = comp
-		}
-	}
-	if curComp.Id == "" {
-		return nil, errors.New("该组件不存在")
-	}
-
-	// 获取bill
-	if len(curComp.Stages) == 0 {
-		return nil, errors.New("该组件数据不存在")
-	}
-	f := excelize.NewFile()
-	// Create a new sheet.
-	index := f.NewSheet("Sheet1")
-	f.SetActiveSheet(index)
-	f.SetDefaultFont("宋体")
-
-	companyName := getCompanyName(apictx)
-
-	offset := 0
-	for _, mat := range curComp.Stages {
-		// 采购单
-		_purchaseId := mat.BillId
-		purchaseId, err := primitive.ObjectIDFromHex(_purchaseId)
-		if err == nil {
-			purchase := model.PurchaseBill{}
-			found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-				CollectName: repo.CollectionBillPurchase,
-				Query:       repo.Map{"_id": purchaseId},
-			}, &purchase)
-			fmt.Println(purchase)
-			if found {
-				var billExcel IPurchBill
-				if purchase.Process != nil {
-					billExcel = NewProcessBill(f)
-				}
-
-				if len(purchase.Paper) > 0 {
-					billExcel = NewPurchaseBill(f)
-				}
-				// purchaseExcel := NewPurchaseBill(f)
-				billExcel.SetContent(&purchase)
-				billExcel.SetTitle(fmt.Sprintf("%s原材料采购单", companyName))
-				billExcel.SetOffset(offset)
-				// billExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
-				//设置对应的数据
-				// purchaseExcel.Offset = offset
-				billExcel.Draws()
-
-				offset += 15
-			}
-		}
-		// if len(mat.Crafts) > 0 {
-		// 	for _, carft := range mat.Crafts {
-		// 		// 加工单
-		// 		_produceId := carft.BillId
-		// 		produceId, err := primitive.ObjectIDFromHex(_produceId)
-		// 		if err == nil {
-		// 			produce := model.ProduceBill{}
-		// 			found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		// 				CollectName: repo.CollectionBillProduce,
-		// 				Query:       repo.Map{"_id": produceId},
-		// 			}, &produce)
-		// 			if found {
-		// 				produceExcel := NewProduceBill(f)
-		// 				produceExcel.Content = &produce
-		// 				produceExcel.Title = fmt.Sprintf("%s加工单", companyName)
-		// 				//设置对应的数据
-		// 				produceExcel.Offset = offset
-		// 				produceExcel.Draws()
-
-		// 				offset += 15
-		// 			}
-
-		// 		}
-		// 	}
-		// }
-	}
-
-	c.Header("Content-Type", "application/octet-stream")
-	c.Header("Content-Disposition", "attachment; filename="+"bill.xlsx")
-	c.Header("Content-Transfer-Encoding", "binary")
-
-	err = f.Write(c.Writer)
-	if err != nil {
-		return nil, err
-	}
-
-	return nil, nil
-}
+// func DownLoadPlanCost(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+// 	_planId := c.Query("id")
+// 	supplierId := c.Query("supplierId")
+// 	planId, err := primitive.ObjectIDFromHex(_planId)
+// 	if err != nil {
+// 		return nil, errors.New("planId错误")
+// 	}
+// 	supplierPlanCost := &SupplierPlanCost{}
+
+// 	plan := model.ProductPlan{}
+// 	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+// 		CollectName: repo.CollectionProductPlan,
+// 		Query:       repo.Map{"_id": planId},
+// 	}, &plan)
+// 	if !found || err != nil {
+// 		return nil, errors.New("数据未找到")
+// 	}
+// 	supplierPlanCost.ProductPlan = &plan
+// 	supplierPlanCost.SupplierId = supplierId
+
+// 	f := excelize.NewFile()
+// 	index := f.NewSheet("Sheet1")
+// 	f.SetActiveSheet(index)
+// 	f.SetDefaultFont("宋体")
+// 	planCostExcel := NewPlanCostExcel(f)
+// 	planCostExcel.Title = fmt.Sprintf("生产成本表(%s)%d盒", plan.Name, plan.Total)
+// 	planCostExcel.Content = supplierPlanCost
+// 	planCostExcel.Draws()
+
+// 	c.Header("Content-Type", "application/octet-stream")
+// 	c.Header("Content-Disposition", "attachment; filename="+"planCost.xlsx")
+// 	c.Header("Content-Transfer-Encoding", "binary")
+
+// 	err = f.Write(c.Writer)
+// 	if err != nil {
+// 		return nil, err
+// 	}
+// 	return nil, nil
+
+// }
+// func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+// 	_planId := c.Query("id")
+// 	compId := c.Query("compId")
+// 	planId, err := primitive.ObjectIDFromHex(_planId)
+// 	if err != nil {
+// 		return nil, errors.New("planId错误")
+// 	}
+// 	plan := model.ProductPlan{}
+// 	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+// 		CollectName: repo.CollectionProductPlan,
+// 		Query:       repo.Map{"_id": planId},
+// 	}, &plan)
+// 	if !found || err != nil {
+// 		return nil, errors.New("数据未找到")
+// 	}
+// 	// 获取部件单据
+// 	curComp := &model.PackComponent{}
+// 	for _, comp := range plan.Pack.Components {
+// 		if comp.Id == compId {
+// 			curComp = comp
+// 		}
+// 	}
+// 	if curComp.Id == "" {
+// 		return nil, errors.New("该组件不存在")
+// 	}
+
+// 	// 获取bill
+// 	if len(curComp.Stages) == 0 {
+// 		return nil, errors.New("该组件数据不存在")
+// 	}
+// 	f := excelize.NewFile()
+// 	// Create a new sheet.
+// 	index := f.NewSheet("Sheet1")
+// 	f.SetActiveSheet(index)
+// 	f.SetDefaultFont("宋体")
+
+// 	companyName := getCompanyName(apictx)
+
+// 	offset := 0
+// 	for _, mat := range curComp.Stages {
+// 		// 采购单
+// 		_purchaseId := mat.BillId
+// 		purchaseId, err := primitive.ObjectIDFromHex(_purchaseId)
+// 		if err == nil {
+// 			purchase := model.PurchaseBill{}
+// 			found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+// 				CollectName: repo.CollectionBillPurchase,
+// 				Query:       repo.Map{"_id": purchaseId},
+// 			}, &purchase)
+// 			fmt.Println(purchase)
+// 			if found {
+// 				var billExcel IPurchBill
+// 				if purchase.Process != nil {
+// 					billExcel = NewProcessBill(f)
+// 				}
+
+// 				if len(purchase.Paper) > 0 {
+// 					billExcel = NewPurchaseBill(f)
+// 				}
+// 				// purchaseExcel := NewPurchaseBill(f)
+// 				billExcel.SetContent(&purchase)
+// 				billExcel.SetTitle(fmt.Sprintf("%s原材料采购单", companyName))
+// 				billExcel.SetOffset(offset)
+// 				// billExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
+// 				//设置对应的数据
+// 				// purchaseExcel.Offset = offset
+// 				billExcel.Draws()
+
+// 				offset += 15
+// 			}
+// 		}
+// 		// if len(mat.Crafts) > 0 {
+// 		// 	for _, carft := range mat.Crafts {
+// 		// 		// 加工单
+// 		// 		_produceId := carft.BillId
+// 		// 		produceId, err := primitive.ObjectIDFromHex(_produceId)
+// 		// 		if err == nil {
+// 		// 			produce := model.ProduceBill{}
+// 		// 			found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+// 		// 				CollectName: repo.CollectionBillProduce,
+// 		// 				Query:       repo.Map{"_id": produceId},
+// 		// 			}, &produce)
+// 		// 			if found {
+// 		// 				produceExcel := NewProduceBill(f)
+// 		// 				produceExcel.Content = &produce
+// 		// 				produceExcel.Title = fmt.Sprintf("%s加工单", companyName)
+// 		// 				//设置对应的数据
+// 		// 				produceExcel.Offset = offset
+// 		// 				produceExcel.Draws()
+
+// 		// 				offset += 15
+// 		// 			}
+
+// 		// 		}
+// 		// 	}
+// 		// }
+// 	}
+
+// 	c.Header("Content-Type", "application/octet-stream")
+// 	c.Header("Content-Disposition", "attachment; filename="+"bill.xlsx")
+// 	c.Header("Content-Transfer-Encoding", "binary")
+
+// 	err = f.Write(c.Writer)
+// 	if err != nil {
+// 		return nil, err
+// 	}
+
+// 	return nil, nil
+// }
 
 // 创建生产计划
 func CreateProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {

+ 5 - 1
boxcost/api/router.go

@@ -36,11 +36,15 @@ func RegRouters(svc *Service) {
 	// 生产计划管理
 	ProductPlan(boxcost)
 
-	// 单据管理
+	//材料采购单据管理
 	Bill(boxcost)
 
+	//加工单据
 	BillProduce(boxcost)
 
+	//成品采购
+	BillProduct(boxcost)
+
 	//设置
 	Setting(boxcost)
 

+ 4 - 3
boxcost/api/supplier.go

@@ -92,9 +92,10 @@ func GetSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
-	// if cate,ok := query["category"];ok{
-	// 	delete(query,"category")
-	// }
+	if cate, ok := query["category"]; ok {
+		delete(query, "category")
+		query["categorys"] = bson.M{"$in": []string{cate.(string)}}
+	}
 
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionSupplier,

+ 1 - 1
boxcost/db/db.go

@@ -35,7 +35,7 @@ func (db *MongoDB) GetOrCreateDatabase(name string) *mongo.Database {
 }
 
 func NewMongoDB(bus *comm.NatsBus) *MongoDB {
-	inst, err := bus.NewMongoDBFromConfig("box-mongo")
+	inst, err := bus.NewMongoDBFromConfigDev("box-mongo")
 	if err != nil {
 		panic(err)
 	}

+ 72 - 0
boxcost/db/model/bill.go

@@ -172,3 +172,75 @@ type ProduceBill struct {
 	// 序号
 	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
 }
+
+// 成品采购单据
+type ProductBill struct {
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	PackId     primitive.ObjectID `bson:"packId,omitempty" json:"packId"`
+	PlanId     primitive.ObjectID `bson:"planId,omitempty" json:"planId"`
+	SupplierId primitive.ObjectID `bson:"supplierId,omitempty" json:"supplierId"`
+	UserId     primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
+	UserName   string             `bson:"userName,omitempty" json:"userName"`
+
+	// 类别
+	Type string `bson:"type,omitempty" json:"type"`
+
+	// 进行中 created  已完成 complete 已弃用 deprecated
+	Status       string               `bson:"status,omitempty" json:"status"`
+	Reviewed     int                  `bson:"reviewed,omitempty" json:"reviewed"`   // -1 代表未审核 1已审核
+	SignUsers    []primitive.ObjectID `bson:"signUsers,omitempty" json:"signUsers"` // 多个签名人
+	CreateTime   time.Time            `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime   time.Time            `bson:"updateTime,omitempty" json:"updateTime"`
+	CompleteTime time.Time            `bson:"completeTime,omitempty" json:"completeTime"`
+
+	//确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	// 实际金额
+	RealAmount float64 `bson:"realAmount,omitempty" json:"realAmount"`
+
+	// 预算金额
+	BudgetAmount float64 `bson:"budgetAmount,omitempty" json:"budgetAmount"`
+
+	//供应商
+	Supplier string `bson:"supplier,omitempty" json:"supplier"`
+
+	//送货地址
+	SendTo string `bson:"sendTo,omitempty" json:"sendTo"`
+
+	//商品名字
+	ProductName string `bson:"productName,omitempty" json:"productName"`
+
+	//有哪些成品采购数据
+	Products []*ProductBillData `bson:"products,omitempty" json:"products"`
+
+	// 序号
+	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
+
+	//备注
+	Remark string `bson:"serialNumber,omitempty" json:"serialNumber"`
+}
+
+// 工艺生产数据
+type ProductBillData struct {
+	//名字
+	Name string `bson:"name,omitempty" json:"name"`
+
+	//规格(质量要求)
+	Norm string `bson:"norm,omitempty" json:"norm"`
+
+	//单价 数量
+	Price float64 `bson:"price,omitempty" json:"price"`
+
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
+
+	//备注
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	//交货时间
+	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
+
+	// 确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+}

+ 4 - 4
boxcost/db/model/process.go

@@ -54,10 +54,10 @@ type ProcessBill struct {
 type ProcessData struct {
 	Id string `bson:"id,omitempty" json:"id"`
 	//所有工艺
-	ProcessInfo *Process         `bson:"processInfo,omitempty" json:"processInfo"`
-	Supplier    *SupplierPriceVo `bson:"supplier,omitempty" json:"supplier"`
-	BillId      string           `bson:"billId,omitempty" json:"billId"`
-	Remark      string           `bson:"remark,omitempty" json:"remark"` //备注
+	ProcessInfo *Process `bson:"processInfo,omitempty" json:"processInfo"`
+	// Supplier    *SupplierPriceVo `bson:"supplier,omitempty" json:"supplier"`
+	BillId string `bson:"billId,omitempty" json:"billId"`
+	Remark string `bson:"remark,omitempty" json:"remark"` //备注
 
 	// 实际金额
 	RealPrice float64 `bson:"realPrice,omitempty" json:"realPrice"`

+ 1 - 1
comm

@@ -1 +1 @@
-Subproject commit 7001469cabb57b8ac042bbca0e8d45786415f257
+Subproject commit 03721d7b9d3dd23b9cffdf9388845c89ace40049