animeic 2 years ago
parent
commit
90db658c81

+ 61 - 61
boxcost/api/bill-process-excel.go → boxcost/api/bill-product-excel.go

@@ -12,7 +12,7 @@ import (
 	"github.com/xuri/excelize/v2"
 )
 
-type ProcessBillExcel struct {
+type ProductBillExcel struct {
 	Offset int
 	Row    int
 
@@ -24,17 +24,17 @@ type ProcessBillExcel struct {
 
 	AlignCenterStyle int
 
-	Content *model.PurchaseBill
+	Content *model.ProductBill
 
 	Signatures []*model.Signature
 }
 
-func (b *ProcessBillExcel) drawTitle() error {
+func (b *ProductBillExcel) drawTitle() error {
 	marginLeft := excelize.PageMarginLeft(0.25)
 	b.Excel.SetPageMargins(b.SheetName, marginLeft)
-	tileIndex := b.Offset + 1
-	startCell := fmt.Sprintf("A%d", tileIndex)
-	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("J%d", tileIndex))
+	b.Row++
+	startCell := fmt.Sprintf("A%d", b.Row)
+	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("J%d", b.Row))
 	if err != nil {
 		return err
 	}
@@ -49,13 +49,13 @@ func (b *ProcessBillExcel) drawTitle() error {
 	if err != nil {
 		return err
 	}
-	b.Excel.SetRowHeight(b.SheetName, tileIndex, 23)
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 23)
 	b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
 	return nil
 }
 
-func (b *ProcessBillExcel) drawSubTitles() error {
-	row := b.Offset + 2
+func (b *ProductBillExcel) drawSubTitles() error {
+	b.Row++
 	styleLeft, err := b.Excel.NewStyle(&excelize.Style{
 		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
 		Font:      &excelize.Font{Size: 11}})
@@ -98,18 +98,18 @@ func (b *ProcessBillExcel) drawSubTitles() error {
 		return nil
 	}
 	//第一行
-	drawLeft(row, "类别:"+b.Content.Type)
-	drawRight(row, "单号:"+b.Content.SerialNumber)
-	b.Excel.SetRowHeight(b.SheetName, row, 21)
+	drawLeft(b.Row, "类别:"+b.Content.Type)
+	drawRight(b.Row, "单号:"+b.Content.SerialNumber)
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
 
 	//第二行
-	drawLeft(row+1, "供应商名称:"+b.Content.Supplier)
+	drawLeft(b.Row+1, "供应商名称:"+b.Content.Supplier)
 	timeformat := b.Content.CreateTime.Local().Format("2006年01月02号 15:04:05")
-	drawRight(row+1, "下单时间:"+timeformat)
-	b.Excel.SetRowHeight(b.SheetName, row+1, 21)
+	drawRight(b.Row+1, "下单时间:"+timeformat)
+	b.Excel.SetRowHeight(b.SheetName, b.Row+1, 21)
 
 	//第三行
-	drawLeft(row+2, "产品名称:"+b.Content.ProductName)
+	drawLeft(b.Row+2, "产品名称:"+b.Content.ProductName)
 	status := ""
 	if b.Content.Status == "complete" {
 		status = fmt.Sprintf("已完成(%d)", b.Content.ConfirmCount)
@@ -117,18 +117,18 @@ func (b *ProcessBillExcel) drawSubTitles() error {
 	if b.Content.Status == "created" {
 		status = "进行中"
 	}
-	drawRight(row+2, "状态:"+status)
-	b.Excel.SetRowHeight(b.SheetName, row+2, 21)
+	drawRight(b.Row+2, "状态:"+status)
+	b.Excel.SetRowHeight(b.SheetName, b.Row+2, 21)
 
 	return nil
 }
 
-func (b *ProcessBillExcel) drawTableTitle() error {
-	row := b.Offset + 5
+func (b *ProductBillExcel) drawTableTitle() error {
+	b.Row += 3
 	// 品名 规格  数量 单位 单价 金额
 	var drawCol = func(prefix string, value string) error {
-		left1Cell := fmt.Sprintf("%s%d", prefix, row)
-		left2Cell := fmt.Sprintf("%s%d", prefix, row+1)
+		left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
+		left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
 
 		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
 		if err != nil {
@@ -156,9 +156,8 @@ func (b *ProcessBillExcel) drawTableTitle() error {
 	return nil
 }
 
-func (b *ProcessBillExcel) drawTableContent() error {
-	row := b.Offset + 7
-	b.Row = row
+func (b *ProductBillExcel) drawTableContent() error {
+	b.Row += 2
 
 	var DrawRow = func(rowIndex int, values ...string) {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}
@@ -174,36 +173,37 @@ func (b *ProcessBillExcel) drawTableContent() error {
 			b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
 		}
 	}
-	ps := b.Content.Process
-	if ps != nil {
-		deliveryTime := ps.DeliveryTime.Local().Format("2006-01-02")
-		confirmCount := "-"
-		realAmount := "-"
-		// 预算金额
-		budgetAmount := fmt.Sprintf("%.3f", b.Content.BudgetAmount)
-		b.FormatToEmpty(&budgetAmount)
-
-		// 实际完成数
-		confirmCount = fmt.Sprintf("%d", ps.ConfirmCount)
-		b.FormatToEmpty(&confirmCount)
-
-		// 实际金额
-		realAmount = fmt.Sprintf("%.3f", b.Content.RealAmount)
-		b.FormatToEmpty(&realAmount)
-
-		// a采购项目 b规格 c下单数量 d单位 e完成数量 f单价 g预算金额 h实际金额 i交货时间 j备注
-		orderCount := fmt.Sprintf("%d", ps.OrderCount)
-		price := fmt.Sprintf("%.3f", ps.Price)
-		b.FormatToEmpty(&price)
-		DrawRow(row, ps.Name, ps.Norm, orderCount, ps.Unit, confirmCount, price, budgetAmount, realAmount, deliveryTime, ps.Remark)
-		row++
-		b.Row++
+	products := b.Content.Products
+	if len(products) > 0 {
+		for _, product := range products {
+			deliveryTime := product.DeliveryTime.Local().Format("2006-01-02")
+			realCount := "-"
+			realPrice := "-"
+			// 预算金额
+			orderPrice := fmt.Sprintf("%.3f", float64(product.OrderCount)*product.Price)
+			b.FormatToEmpty(&orderPrice)
+
+			// 实际完成数
+			realCount = fmt.Sprintf("%d", product.ConfirmCount)
+			b.FormatToEmpty(&realCount)
+
+			// 实际金额
+			realPrice = fmt.Sprintf("%.3f", float64(product.ConfirmCount)*product.Price)
+			b.FormatToEmpty(&realPrice)
+
+			// a采购项目 b规格 c下单数量 d单位 e完成数量 f单价 g预算金额 h实际金额 i交货时间 j备注
+			orderCount := fmt.Sprintf("%d", product.OrderCount)
+			price := fmt.Sprintf("%.3f", product.Price)
+			b.FormatToEmpty(&price)
+			DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, realCount, price, orderPrice, realPrice, deliveryTime, product.Remark)
+			b.Row++
+		}
 	}
 
 	return nil
 }
 
-func (b *ProcessBillExcel) drawTableFooter() error {
+func (b *ProductBillExcel) drawTableFooter() error {
 	left1Cell := fmt.Sprintf("A%d", b.Row)
 	border := []excelize.Border{
 		{Type: "top", Style: 1, Color: "000000"},
@@ -235,7 +235,7 @@ func (b *ProcessBillExcel) drawTableFooter() error {
 	return nil
 }
 
-func (b *ProcessBillExcel) drawRemark() error {
+func (b *ProductBillExcel) drawRemark() error {
 	// 填备注
 	b.Row++
 	remarkTitleCell := fmt.Sprintf("A%d", b.Row)
@@ -255,7 +255,7 @@ func (b *ProcessBillExcel) drawRemark() error {
 
 }
 
-func (b *ProcessBillExcel) drawTableSignature() error {
+func (b *ProductBillExcel) drawTableSignature() error {
 	b.Row += 2
 	style1, _ := b.Excel.NewStyle(&excelize.Style{
 		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
@@ -307,7 +307,7 @@ func (b *ProcessBillExcel) drawTableSignature() error {
 	return nil
 }
 
-func (b *ProcessBillExcel) Draws() {
+func (b *ProductBillExcel) Draws() {
 	b.drawTitle()
 	b.drawSubTitles()
 	b.drawTableTitle()
@@ -317,7 +317,7 @@ func (b *ProcessBillExcel) Draws() {
 	b.drawTableSignature()
 }
 
-func NewProcessBill(f *excelize.File) *ProcessBillExcel {
+func NewProductBill(f *excelize.File) *ProductBillExcel {
 
 	border := []excelize.Border{
 		{Type: "top", Style: 1, Color: "000000"},
@@ -332,7 +332,7 @@ func NewProcessBill(f *excelize.File) *ProcessBillExcel {
 		Font:      &excelize.Font{Size: 10},
 	})
 
-	b := &ProcessBillExcel{
+	b := &ProductBillExcel{
 		Title:            "原材料采购单",
 		SheetName:        "Sheet1",
 		Excel:            f,
@@ -346,30 +346,30 @@ func NewProcessBill(f *excelize.File) *ProcessBillExcel {
 	return b
 }
 
-func (b *ProcessBillExcel) FormatToEmpty(str *string) {
+func (b *ProductBillExcel) FormatToEmpty(str *string) {
 	if *str == "0" || *str == "0.000" {
 		*str = ""
 	}
 
 }
 
-func (b *ProcessBillExcel) PrintPurchType() string {
+func (b *ProductBillExcel) PrintPurchType() string {
 	return "process"
 }
 
-func (b *ProcessBillExcel) SetContent(content *model.PurchaseBill) {
+func (b *ProductBillExcel) SetContent(content *model.ProductBill) {
 	b.Content = content
 
 }
-func (b *ProcessBillExcel) SetTitle(title string) {
+func (b *ProductBillExcel) SetTitle(title string) {
 	b.Title = title
 
 }
-func (b *ProcessBillExcel) SetOffset(offset int) {
+func (b *ProductBillExcel) SetOffset(offset int) {
 	b.Offset = offset
 
 }
-func (b *ProcessBillExcel) SetSignatures(sign []*model.Signature) {
+func (b *ProductBillExcel) SetSignatures(sign []*model.Signature) {
 	b.Signatures = sign
 
 }

+ 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.ProductBill{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduct,
+		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)
+	product := model.ProductBill{
+		Reviewed:   1,
+		UpdateTime: time.Now(),
+		SignUsers:  signs,
+	}
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, _id, &product)
+
+}
+
+// 创建生产加工单据
+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.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("数据未找到")
+	}
+
+	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.CollectionBillProduct,
+		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.ProductBill
+	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 := NewProductBill(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
+}

+ 3 - 3
boxcost/api/bill.go

@@ -227,9 +227,9 @@ func DownLoadBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	var billExcel IPurchBill
 
-	if bill.Process != nil {
-		billExcel = NewProcessBill(f)
-	}
+	// if bill.Process != nil {
+	// 	billExcel = NewProcessBill(f)
+	// }
 
 	if len(bill.Paper) > 0 {
 		billExcel = NewPurchaseBill(f)

+ 334 - 477
boxcost/api/plan-cost-excel.go

@@ -4,12 +4,12 @@ import (
 	"fmt"
 
 	"github.com/xuri/excelize/v2"
-	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 // 生产成本表
 type PlanCostExcel struct {
 	Offset int
+	Row    int
 
 	Title string //标题
 
@@ -18,16 +18,16 @@ type PlanCostExcel struct {
 	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))
+	// tileIndex := b.Offset + 1
+	b.Row++
+	startCell := fmt.Sprintf("A%d", b.Row)
+	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("M%d", b.Row))
 	if err != nil {
 		return err
 	}
@@ -42,19 +42,20 @@ func (b *PlanCostExcel) drawTitle() error {
 	if err != nil {
 		return err
 	}
-	b.Excel.SetRowHeight(b.SheetName, tileIndex, 23)
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 23)
 	b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
 	return nil
 }
 
 func (b *PlanCostExcel) drawTableTitle() error {
-	row := b.Offset + 2
+	// row := b.Offset + 2
+	b.Row++
 
 	//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)
+		left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
+		left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
 
 		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
 		if err != nil {
@@ -69,8 +70,8 @@ func (b *PlanCostExcel) drawTableTitle() error {
 	}
 
 	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)
+		left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
+		left2Cell := fmt.Sprintf("%s%d", prefix2, b.Row)
 		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
 		if err != nil {
 			return err
@@ -85,19 +86,19 @@ func (b *PlanCostExcel) drawTableTitle() error {
 		}
 		b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
 
-		val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
+		val2Cel := fmt.Sprintf("%s%d", prefix1, b.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)
+		val3Cel := fmt.Sprintf("%s%d", prefix2, b.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)
+		left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
 		// left2Cell := fmt.Sprintf("%s%d", prefix2, row)
-		left3Cell := fmt.Sprintf("%s%d", prefix3, row)
+		left3Cell := fmt.Sprintf("%s%d", prefix3, b.Row)
 		err := b.Excel.MergeCell(b.SheetName, left1Cell, left3Cell)
 		if err != nil {
 			return err
@@ -112,15 +113,15 @@ func (b *PlanCostExcel) drawTableTitle() error {
 		}
 		b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
 
-		val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
+		val2Cel := fmt.Sprintf("%s%d", prefix1, b.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)
+		val3Cel := fmt.Sprintf("%s%d", prefix2, b.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)
+		val4Cel := fmt.Sprintf("%s%d", prefix3, b.Row+1)
 		b.Excel.SetCellStyle(b.SheetName, val4Cel, val4Cel, b.AlignCenterStyle)
 		b.Excel.SetCellValue(b.SheetName, val4Cel, value4)
 		return nil
@@ -139,283 +140,6 @@ func (b *PlanCostExcel) drawTableTitle() error {
 	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 {
@@ -433,130 +157,332 @@ func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
 
 }
 
-type MergeRow struct {
-	Rows         []int
-	RealAmount   float64
-	BudgetAmount float64
-}
+// func (b *PlanCostExcel) drawSupplierContent() error {
+// 	b.Row += 2
+// 	supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
+// 	if err != nil {
+// 		return err
+// 	}
+// 	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.Stages) > 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) drawAllContent() error {
-	row := b.Offset + 4
+	b.Row += 2
 	comps := b.Content.Pack.Components
 	// 预算金额汇总
-	var totalOrderRealPrice float64 = 0.00
+	var totalOrderPrice float64 = 0.00
 	// 实际金额汇总
 	var totalRealPrice float64 = 0.00
 	if len(comps) > 0 {
 		for _, comp := range comps {
-			var perOrderRealPrice float64 = 0.00
+			var perOrderPrice float64 = 0.00
 			var perRealPrice float64 = 0.00
-			if len(comp.Mats) > 0 {
-				startRow := row
-				for _, mat := range comp.Mats {
+			if len(comp.Stages) > 0 {
+				startRow := b.Row
+				for _, stage := range comp.Stages {
 					// 材料
 					supplierName := ""
-					if mat.Supplier.SupplierInfo != nil {
-						supplierName = mat.Supplier.SupplierInfo.Name
+					if stage.SupplierInfo != nil {
+						supplierName = stage.SupplierInfo.Name
 					}
-					matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
+					matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
 					b.FormatToEmpty(&matHeigth)
-					matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
+					matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
 					b.FormatToEmpty(&matWidth)
-					orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
+					orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
 					b.FormatToEmpty(&orderCount)
 
 					// 实际数量
-					confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
-					b.FormatToEmpty(&confirmCount)
+					realCount := fmt.Sprintf("%d", stage.RealCount)
+					b.FormatToEmpty(&realCount)
 					// 单价
-					orderPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderPrice)
-					b.FormatToEmpty(&orderPrice)
+					price := fmt.Sprintf("%.3f", stage.Price)
+					b.FormatToEmpty(&price)
 					// 预算金额
-					orderRealPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderRealPrice)
-					perOrderRealPrice += mat.Supplier.OrderRealPrice
-					b.FormatToEmpty(&orderRealPrice)
+					orderPrice := fmt.Sprintf("%.3f", stage.OrderPrice)
+					perOrderPrice += stage.OrderPrice
+					b.FormatToEmpty(&orderPrice)
 					// 实际金额
-					perRealPrice += mat.RealPrice
-					realPrice := fmt.Sprintf("%.3f", mat.RealPrice)
+					perRealPrice += stage.RealPrice
+					realPrice := fmt.Sprintf("%.3f", stage.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
+					if stage.Unit == "吨" || stage.Unit == "平方米" {
+						stage.Unit = "张"
 					}
+					b.drawRow(b.Row, "", stage.Name, "", supplierName, stage.Norm, matHeigth, matWidth, stage.Unit, orderCount, realCount, price, orderPrice, realPrice)
+
+					b.Row++
+
 				}
-				endRow := row - 1
+				endRow := b.Row - 1
 				// 组件名字
 				startACell := fmt.Sprintf("%s%d", "A", startRow)
 				endACell := fmt.Sprintf("%s%d", "A", endRow)
@@ -569,92 +495,22 @@ func (b *PlanCostExcel) drawAllContent() error {
 			}
 
 			// 预算
-			totalOrderRealPrice += perOrderRealPrice
+			totalOrderPrice += perOrderPrice
 			// 实际金额
 			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)
+	startACell := fmt.Sprintf("%s%d", "A", b.Row)
+	endKCell := fmt.Sprintf("%s%d", "K", b.Row)
+	LCell := fmt.Sprintf("%s%d", "L", b.Row)
+	MCell := fmt.Sprintf("%s%d", "M", b.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)
+	planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderPrice)
 	b.FormatToEmpty(&planOrderRealPrice)
 	b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
 
@@ -670,11 +526,12 @@ func (b *PlanCostExcel) drawAllContent() error {
 func (b *PlanCostExcel) Draws() {
 	b.drawTitle()
 	b.drawTableTitle()
-	if b.Content.SupplierId != "" {
-		b.drawSupplierContent()
-	} else {
-		b.drawAllContent()
-	}
+	// if b.Content.SupplierId != "" {
+	// 	b.drawSupplierContent()
+	// } else {
+	// 	b.drawAllContent()
+	// }
+	b.drawAllContent()
 
 }
 

+ 3 - 3
boxcost/api/plan.go

@@ -137,9 +137,9 @@ func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			fmt.Println(purchase)
 			if found {
 				var billExcel IPurchBill
-				if purchase.Process != nil {
-					billExcel = NewProcessBill(f)
-				}
+				// if purchase.Process != nil {
+				// 	billExcel = NewProcessBill(f)
+				// }
 
 				if len(purchase.Paper) > 0 {
 					billExcel = NewPurchaseBill(f)

+ 3 - 3
boxcost/api/process.go → boxcost/api/product.go

@@ -14,10 +14,10 @@ import (
 func Process(r *GinRouter) {
 
 	// 获取生产计划详情
-	r.GET("/process/detail/:id", ProcessDetail)
+	r.GET("/product/detail/:id", ProcessDetail)
 
-	CreateCRUD(r, "/process", &CRUDOption{
-		Collection: "process",
+	CreateCRUD(r, "/product", &CRUDOption{
+		Collection: "product",
 		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			entity := &model.Process{}
 			c.ShouldBindJSON(entity)

+ 39 - 63
boxcost/api/report-process-excel.go

@@ -12,7 +12,7 @@ import (
 	"github.com/xuri/excelize/v2"
 )
 
-type ReportProcessExcel struct {
+type ReportProductExcel struct {
 	Offset int
 	Row    int
 
@@ -24,13 +24,13 @@ type ReportProcessExcel struct {
 
 	AlignCenterStyle int
 
-	Content *model.PurchaseBill
+	Content *model.ProductBill
 
 	BudgetCount float64
 	RealCount   float64
 }
 
-func (b *ReportProcessExcel) drawTitle() error {
+func (b *ReportProductExcel) drawTitle() error {
 	marginLeft := excelize.PageMarginLeft(0.3)
 	b.Excel.SetPageMargins(b.SheetName, marginLeft)
 	// tileIndex := b.Offset + 1
@@ -56,7 +56,7 @@ func (b *ReportProcessExcel) drawTitle() error {
 	return nil
 }
 
-func (b *ReportProcessExcel) drawSubTitles() error {
+func (b *ReportProductExcel) drawSubTitles() error {
 	// row := b.Offset + 2
 	b.Row++
 	styleLeft, err := b.Excel.NewStyle(&excelize.Style{
@@ -128,7 +128,7 @@ func (b *ReportProcessExcel) drawSubTitles() error {
 	return nil
 }
 
-func (b *ReportProcessExcel) drawTableTitle() error {
+func (b *ReportProductExcel) drawTableTitle() error {
 	// row := b.Offset + 5
 	b.Row++
 	// 品名 规格  数量 单位 单价 金额
@@ -162,7 +162,7 @@ func (b *ReportProcessExcel) drawTableTitle() error {
 	return nil
 }
 
-func (b *ReportProcessExcel) drawTableContent() error {
+func (b *ReportProductExcel) drawTableContent() error {
 	// row := b.Offset + 7
 	// b.Row = row
 	b.Row += 2
@@ -181,38 +181,40 @@ func (b *ReportProcessExcel) drawTableContent() error {
 			b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
 		}
 	}
-	ps := b.Content.Process
-	if ps != nil {
-		deliveryTime := ps.DeliveryTime.Local().Format("2006-01-02")
-		confirmCount := "-"
-		realAmount := "-"
-		// 预算金额
-		budgetAmount := fmt.Sprintf("%.3f", b.Content.BudgetAmount)
-		b.FormatToEmpty(&budgetAmount)
-
-		// 实际完成数
-		confirmCount = fmt.Sprintf("%d", ps.ConfirmCount)
-		b.FormatToEmpty(&confirmCount)
-
-		// 实际金额
-		realAmount = fmt.Sprintf("%.3f", b.Content.RealAmount)
-		b.FormatToEmpty(&realAmount)
-
-		// a采购项目 b规格 c下单数量 d单位 e完成数量 f单价 g预算金额 h实际金额 i交货时间 j备注
-		orderCount := fmt.Sprintf("%d", ps.OrderCount)
-		price := fmt.Sprintf("%.3f", ps.Price)
-		b.FormatToEmpty(&price)
-		DrawRow(b.Row, ps.Name, ps.Norm, orderCount, ps.Unit, confirmCount, price, budgetAmount, realAmount, deliveryTime, ps.Remark)
-		// row++
-		b.Row++
-		b.BudgetCount += b.Content.BudgetAmount
-		b.RealCount += b.Content.RealAmount
+
+	products := b.Content.Products
+	if len(products) > 0 {
+		for _, product := range products {
+			deliveryTime := product.DeliveryTime.Local().Format("2006-01-02")
+			realCount := "-"
+			realPrice := "-"
+			// 预算金额
+			orderPrice := fmt.Sprintf("%.3f", float64(product.OrderCount)*product.Price)
+			b.FormatToEmpty(&orderPrice)
+
+			// 实际完成数
+			realCount = fmt.Sprintf("%d", product.ConfirmCount)
+			b.FormatToEmpty(&realCount)
+
+			// 实际金额
+			realPrice = fmt.Sprintf("%.3f", float64(product.ConfirmCount)*product.Price)
+			b.FormatToEmpty(&realPrice)
+
+			// a采购项目 b规格 c下单数量 d单位 e完成数量 f单价 g预算金额 h实际金额 i交货时间 j备注
+			orderCount := fmt.Sprintf("%d", product.OrderCount)
+			price := fmt.Sprintf("%.3f", product.Price)
+			b.FormatToEmpty(&price)
+			DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, realCount, price, orderPrice, realPrice, deliveryTime, product.Remark)
+			b.Row++
+			b.BudgetCount += float64(product.OrderCount) * product.Price
+			b.RealCount += float64(product.ConfirmCount) * product.Price
+		}
 	}
 
 	return nil
 }
 
-func (b *ReportProcessExcel) drawRemark() error {
+func (b *ReportProductExcel) drawRemark() error {
 	// 填备注
 	b.Row++
 	remarkTitleCell := fmt.Sprintf("A%d", b.Row)
@@ -232,7 +234,7 @@ func (b *ReportProcessExcel) drawRemark() error {
 
 }
 
-func (b *ReportProcessExcel) Draws() {
+func (b *ReportProductExcel) Draws() {
 	b.drawTitle()
 	b.drawSubTitles()
 	b.drawTableTitle()
@@ -240,7 +242,7 @@ func (b *ReportProcessExcel) Draws() {
 	b.drawRemark()
 }
 
-func NewReportProcessBill(f *excelize.File) *ReportProcessExcel {
+func NewReportProductBill(f *excelize.File) *ReportProductExcel {
 
 	border := []excelize.Border{
 		{Type: "top", Style: 1, Color: "000000"},
@@ -255,7 +257,7 @@ func NewReportProcessBill(f *excelize.File) *ReportProcessExcel {
 		Font:      &excelize.Font{Size: 10},
 	})
 
-	b := &ReportProcessExcel{
+	b := &ReportProductExcel{
 		Title:            "原材料采购单",
 		SheetName:        "Sheet1",
 		Excel:            f,
@@ -268,35 +270,9 @@ func NewReportProcessBill(f *excelize.File) *ReportProcessExcel {
 	return b
 }
 
-func (b *ReportProcessExcel) FormatToEmpty(str *string) {
+func (b *ReportProductExcel) FormatToEmpty(str *string) {
 	if *str == "0" || *str == "0.000" {
 		*str = ""
 	}
 
 }
-
-func (b *ReportProcessExcel) PrintPurchType() string {
-	return "process report"
-}
-
-func (b *ReportProcessExcel) SetContent(content *model.PurchaseBill) {
-	b.Content = content
-
-}
-func (b *ReportProcessExcel) SetTitle(title string) {
-	b.Title = title
-
-}
-func (b *ReportProcessExcel) SetOffset(offset int) {
-	b.Offset = offset
-
-}
-func (b *ReportProcessExcel) SetRow(row int) {
-	b.Row = row
-
-}
-
-func (b *ReportProcessExcel) GetRow() int {
-	return b.Row
-
-}

+ 3 - 3
boxcost/api/report.go

@@ -169,10 +169,10 @@ func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, er
 
 	for _, purchase := range purchases {
 		var reportBill IRPurchBill
-		if purchase.Process != nil {
-			reportBill = NewReportProcessBill(f)
+		// if purchase.Process != nil {
+		// 	reportBill = NewReportProcessBill(f)
 
-		}
+		// }
 		if len(purchase.Paper) > 0 {
 			reportBill = NewReportPurchaseExcel(f)
 		}

+ 2 - 2
boxcost/api/router.go

@@ -50,8 +50,8 @@ func RegRouters(svc *Service) {
 	// 统计报表
 	Report(boxcost)
 
-	// 工序管理
-	Process(boxcost)
+	// 成品采购管理
+	Product(boxcost)
 }
 
 func Logger() gin.HandlerFunc {

+ 4 - 4
boxcost/api/supplier-price.go

@@ -149,7 +149,7 @@ func SupplierPrice(r *GinRouter) {
 	})
 
 	CreateCRUD(r, "/supplier/process", &CRUDOption{
-		Collection: repo.CollectionSupplierProcessprice,
+		Collection: repo.CollectionSupplierProductprice,
 		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			entity := &model.SupplierPrice{}
 			c.ShouldBindJSON(entity)
@@ -160,7 +160,7 @@ func SupplierPrice(r *GinRouter) {
 
 			curr := &model.SupplierPrice{}
 			ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-				CollectName: repo.CollectionSupplierProcessprice,
+				CollectName: repo.CollectionSupplierProductprice,
 				Query:       repo.Map{"productId": entity.ProductId, "supplierId": entity.SupplierId},
 				Project:     []string{"_id"},
 			}, curr)
@@ -194,9 +194,9 @@ func SupplierPrice(r *GinRouter) {
 			for _, ps := range page.List {
 				_id, _ := ps["productId"].(primitive.ObjectID)
 
-				process := &model.Process{}
+				process := &model.Product{}
 				repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-					CollectName: repo.CollectionProcess,
+					CollectName: repo.CollectionProduct,
 					Query:       repo.Map{"_id": _id},
 				}, process)
 				ps["processInfo"] = process

+ 3 - 3
boxcost/api/supplier.go

@@ -200,14 +200,14 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		}
 	}
 
-	if query["processId"] != nil {
+	if query["productId"] != nil {
 		processId := query["processId"].(string)
 		if len(processId) < 1 {
-			return nil, fmt.Errorf("processId(string)为空")
+			return nil, fmt.Errorf("productId(string)为空")
 		}
 		id, _ := primitive.ObjectIDFromHex(processId)
 		ok, list := repo.RepoSeachDocsMap(apictx.CreateRepoCtx(), &repo.DocsSearchOptions{
-			CollectName: repo.CollectionSupplierProcessprice,
+			CollectName: repo.CollectionSupplierProductprice,
 			Query:       repo.Map{"productId": id},
 			Project:     []string{"supplierId"},
 		})

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

@@ -67,9 +67,6 @@ type PurchaseBill struct {
 	//纸张类采购
 	Paper []*PaperBill `bson:"papers,omitempty" json:"papers"`
 
-	// 工序管理
-	Process *ProcessBill `bson:"process,omitempty" json:"process"`
-
 	// 序号
 	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
 
@@ -172,3 +169,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:"remark,omitempty" json:"remark"`
+}
+
+// 成品采购单据
+type ProductBillData struct {
+	//名字
+	Name     string `bson:"name,omitempty" json:"name"`
+	Supplier string `bson:"supplier,omitempty" json:"supplier"`
+
+	Type string `bson:"type,omitempty" json:"type"`
+	//规格(质量要求)
+	Norm string `bson:"norm,omitempty" json:"norm"`
+
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
+	// 单位
+	Unit string `bson:"unit,omitempty" json:"unit"`
+	//单价
+	Price float64 `bson:"price,omitempty" json:"price"`
+	// 金额
+	//备注
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	//交货时间
+	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
+
+	//确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+}

+ 2 - 47
boxcost/db/model/process.go

@@ -6,8 +6,8 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
-// 工序管理 用于选择模板
-type Process struct {
+// 成品采购管理 用于选择模板
+type Product struct {
 	Id    primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
 	Name  string             `bson:"name,omitempty" json:"name"`
 	Unit  string             `bson:"unit,omitempty" json:"unit"`
@@ -21,48 +21,3 @@ type Process struct {
 	CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
 	UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
 }
-
-// 算到采购单里面
-type ProcessBill struct {
-	//名字
-	Name     string `bson:"name,omitempty" json:"name"`
-	Supplier string `bson:"supplier,omitempty" json:"supplier"`
-
-	//名字
-	Type string `bson:"type,omitempty" json:"type"`
-	//规格(质量要求)
-	Norm string `bson:"norm,omitempty" json:"norm"`
-	//数量
-	Count int `bson:"count,omitempty" json:"count"`
-	// 下单数量
-	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
-	// 单位
-	Unit string `bson:"unit,omitempty" json:"unit"`
-	//单价
-	Price float64 `bson:"price,omitempty" json:"price"`
-	// 金额
-	//备注
-	Remark string `bson:"remark,omitempty" json:"remark"`
-
-	//交货时间
-	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
-
-	//确认收货数量
-	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
-}
-
-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"` //备注
-
-	// 实际金额
-	RealPrice float64 `bson:"realPrice,omitempty" json:"realPrice"`
-	// 下单数量
-	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
-	//确认收货数量
-	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
-}

+ 1 - 2
boxcost/db/repo/repo.go

@@ -20,7 +20,7 @@ type RepoSession struct {
 const (
 	CollectionMaterial      = "material"
 	CollectionCraft         = "craft"
-	CollectionProcess       = "process" // todo不需要
+	CollectionProduct       = "product"
 	CollectionSupplier      = "supplier"
 	CollectionSupplierPrice = "supplier-price"
 	CollectionPack          = "pack"
@@ -31,7 +31,6 @@ const (
 
 	CollectionSupplierMatprice     = "supplier-mats"
 	CollectionSupplierCraftprice   = "supplier-crafts"
-	CollectionSupplierProcessprice = "supplier-process" // todo 不需要
 	CollectionSupplierProductprice = "supplier-product" // 成品采购
 	CollectionIncrement            = "increment"
 	CollectionSignature            = "signature"