Browse Source

Merge branch 'dev' of http://124.70.149.18:10880/sunsheng/box-cost into dev

liwei 2 years ago
parent
commit
d176e8071b

+ 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
 
 }

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

@@ -14,7 +14,11 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
+<<<<<<< HEAD
 // 成品采购单据管理
+=======
+// 单据管理
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 func BillProduct(r *GinRouter) {
 
 	// 创建单据
@@ -58,9 +62,15 @@ func ProductReview(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return nil, errors.New("该用户没有权限")
 	}
 	// 查询单据获取已有的签字
+<<<<<<< HEAD
 	bill := model.ProduceBill{}
 	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
 		CollectName: repo.CollectionBillProduce,
+=======
+	bill := model.ProductBill{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduct,
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 		Query:       repo.Map{"_id": id, "reviewed": 1},
 	}, &bill)
 	signs := make([]primitive.ObjectID, 0)
@@ -76,16 +86,28 @@ func ProductReview(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	// 更改状态为已审核 并签字
 	signs = append(signs, userId)
+<<<<<<< HEAD
 	produce := model.ProduceBill{
+=======
+	product := model.ProductBill{
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 		Reviewed:   1,
 		UpdateTime: time.Now(),
 		SignUsers:  signs,
 	}
+<<<<<<< HEAD
 	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, _id, &produce)
 
 }
 
 // 创建成品采购单据
+=======
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, _id, &product)
+
+}
+
+// 创建生产加工单据
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 func CreateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	bill := &model.ProductBill{}
@@ -141,7 +163,11 @@ func GetProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 	var bill model.ProductBill
 	option := &repo.DocSearchOptions{
+<<<<<<< HEAD
 		CollectName: repo.CollectionBillProduce,
+=======
+		CollectName: repo.CollectionBillProduct,
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 		Query:       repo.Map{"_id": id},
 	}
 	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), option, &bill)
@@ -179,7 +205,11 @@ func GetProductBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 
 	option := &repo.PageSearchOptions{
+<<<<<<< HEAD
 		CollectName: repo.CollectionBillProduce,
+=======
+		CollectName: repo.CollectionBillProduct,
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 		Query:       query,
 		Page:        page,
 		Size:        size,
@@ -190,7 +220,11 @@ func GetProductBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 // 更新单据
 func UpdateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+<<<<<<< HEAD
 	var bill model.ProduceBill
+=======
+	var bill model.ProductBill
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 	err := c.ShouldBindJSON(&bill)
 	if err != nil {
 		fmt.Println(err)
@@ -259,7 +293,11 @@ func DownProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	f.SetActiveSheet(index)
 	f.SetDefaultFont("宋体")
 
+<<<<<<< HEAD
 	billExcel := NewProduceBill(f)
+=======
+	billExcel := NewProductBill(f)
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 	// 获取已审核的签名数据
 	if bill.Reviewed == 1 {
 		if len(bill.SignUsers) > 0 {
@@ -273,9 +311,15 @@ func DownProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		}
 
 	}
+<<<<<<< HEAD
 	// billExcel.Content = &bill
 	companyName := getCompanyName(apictx)
 	billExcel.Title = fmt.Sprintf("%s加工单", companyName)
+=======
+	billExcel.Content = &bill
+	companyName := getCompanyName(apictx)
+	billExcel.Title = fmt.Sprintf("%s成品采购单", companyName)
+>>>>>>> bb4e90e71ab5ef881ab438960e3aa9d606f4899c
 	//设置对应的数据
 	billExcel.Draws()
 

+ 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)

+ 294 - 430
boxcost/api/plan-cost-excel.go

@@ -1,143 +1,168 @@
 package api
 
-// // 生产成本表
-// 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
-// }
+import (
+	"fmt"
+
+	"github.com/xuri/excelize/v2"
+)
+
+// 生产成本表
+type PlanCostExcel struct {
+	Offset int
+	Row    int
+
+	Title string //标题
+
+	Excel *excelize.File
+
+	SheetName string
+
+	AlignCenterStyle int
+
+	// Content *model.ProductPlan
+	Content *SupplierPlanCost
+}
+
+func (b *PlanCostExcel) drawTitle() error {
+	// 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
+	}
+
+	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, b.Row, 23)
+	b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
+	return nil
+}
+
+func (b *PlanCostExcel) drawTableTitle() error {
+	// 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, b.Row)
+		left2Cell := fmt.Sprintf("%s%d", prefix, b.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, b.Row)
+		left2Cell := fmt.Sprintf("%s%d", prefix2, b.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, 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, 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, b.Row)
+		// left2Cell := fmt.Sprintf("%s%d", prefix2, row)
+		left3Cell := fmt.Sprintf("%s%d", prefix3, b.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, 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, 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, b.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) 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)
+	}
+
+}
 
 // func (b *PlanCostExcel) drawSupplierContent() error {
+// 	b.Row += 2
 // 	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
@@ -148,7 +173,7 @@ package api
 // 			var perOrderRealPrice float64 = 0.00
 // 			var perRealPrice float64 = 0.00
 
-// 			if len(comp.Mats) > 0 {
+// 			if len(comp.Stages) > 0 {
 // 				startRow := 0
 // 				for _, mat := range comp.Mats {
 // 					if mat.Supplier.SupplierInfo != nil {
@@ -409,300 +434,139 @@ package api
 // 	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 = ""
-// 	}
-
-// }
+func (b *PlanCostExcel) drawAllContent() error {
+	b.Row += 2
+	comps := b.Content.Pack.Components
+	// 预算金额汇总
+	var totalOrderPrice float64 = 0.00
+	// 实际金额汇总
+	var totalRealPrice float64 = 0.00
+	if len(comps) > 0 {
+		for _, comp := range comps {
+			var perOrderPrice float64 = 0.00
+			var perRealPrice float64 = 0.00
+			if len(comp.Stages) > 0 {
+				startRow := b.Row
+				for _, stage := range comp.Stages {
+					// 材料
+					supplierName := ""
+					if stage.SupplierInfo != nil {
+						supplierName = stage.SupplierInfo.Name
+					}
+					matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
+					b.FormatToEmpty(&matHeigth)
+					matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
+					b.FormatToEmpty(&matWidth)
+					orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
+					b.FormatToEmpty(&orderCount)
+
+					// 实际数量
+					realCount := fmt.Sprintf("%d", stage.RealCount)
+					b.FormatToEmpty(&realCount)
+					// 单价
+					price := fmt.Sprintf("%.3f", stage.Price)
+					b.FormatToEmpty(&price)
+					// 预算金额
+					orderPrice := fmt.Sprintf("%.3f", stage.OrderPrice)
+					perOrderPrice += stage.OrderPrice
+					b.FormatToEmpty(&orderPrice)
+					// 实际金额
+					perRealPrice += stage.RealPrice
+					realPrice := fmt.Sprintf("%.3f", stage.RealPrice)
+					b.FormatToEmpty(&realPrice)
+					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 := b.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)
+			}
+
+			// 预算
+			totalOrderPrice += perOrderPrice
+			// 实际金额
+			totalRealPrice += perRealPrice
+		}
+	}
+	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", totalOrderPrice)
+	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()
+	// }
+	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 = ""
+	}
+
+}

+ 17 - 17
boxcost/api/plan.go

@@ -122,23 +122,23 @@ type SupplierPlanCost struct {
 
 // 	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)
-// 				}
+// 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)

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

@@ -11,42 +11,42 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
-func Process(r *GinRouter) {
+func Product(r *GinRouter) {
 
 	// 获取生产计划详情
-	r.GET("/process/detail/:id", ProcessDetail)
+	r.GET("/product/detail/:id", ProductDetail)
 
-	CreateCRUD(r, "/process", &CRUDOption{
-		Collection: "process",
+	CreateCRUD(r, "/product", &CRUDOption{
+		Collection: "product",
 		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-			entity := &model.Process{}
+			entity := &model.Product{}
 			c.ShouldBindJSON(entity)
 			entity.CreateTime = time.Now()
 			entity.UpdateTime = time.Now()
 			return entity, nil
 		},
 		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
-			return &model.Process{}
+			return &model.Product{}
 		},
 
 		JWT: true,
 		OnUpdate: func(c *gin.Context, apictx *ApiSession, entity interface{}) {
-			process := entity.(*model.Process)
+			process := entity.(*model.Product)
 			process.UpdateTime = time.Now()
 		},
 		SearchProject: []string{"name", "unit", "norm", "price", "category", "remark"},
 	})
 }
 
-func ProcessDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func ProductDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	processId := c.Param("id")
 	id, err := primitive.ObjectIDFromHex(processId)
 	if err != nil {
 		return nil, errors.New("非法id")
 	}
-	var process model.Process
+	var process model.Product
 	option := &repo.DocSearchOptions{
-		CollectName: repo.CollectionProcess,
+		CollectName: repo.CollectionProduct,
 		Query:       repo.Map{"_id": id},
 	}
 

+ 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

@@ -54,8 +54,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

@@ -201,14 +201,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"},
 		})

+ 3 - 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"`
 
@@ -243,4 +240,7 @@ type ProductBillData struct {
 
 	// 确认收货数量
 	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	//纸张
+	Unit string `bson:"unit,omitempty" json:"unit"`
 }

+ 0 - 68
boxcost/db/model/process.go

@@ -1,68 +0,0 @@
-package model
-
-import (
-	"time"
-
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-// 工序管理 用于选择模板
-type Process struct {
-	Id    primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Name  string             `bson:"name,omitempty" json:"name"`
-	Unit  string             `bson:"unit,omitempty" json:"unit"`
-	Norm  string             `bson:"norm,omitempty" json:"norm"`
-	Price float64            `bson:"price,omitempty" json:"price"`
-	// 分类
-	Category string `bson:"category,omitempty" json:"category"`
-
-	// 单个工艺备注
-	Remark     string    `bson:"remark,omitempty" json:"remark"`
-	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"`
-}

+ 23 - 0
boxcost/db/model/product.go

@@ -0,0 +1,23 @@
+package model
+
+import (
+	"time"
+
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+// 成品采购管理 用于选择模板
+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"`
+	Norm  string             `bson:"norm,omitempty" json:"norm"`
+	Price float64            `bson:"price,omitempty" json:"price"`
+	// 分类
+	Category string `bson:"category,omitempty" json:"category"`
+
+	// 单个工艺备注
+	Remark     string    `bson:"remark,omitempty" json:"remark"`
+	CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
+}

+ 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"