animeic 2 rokov pred
rodič
commit
0a07a7ecfd

+ 15 - 12
boxcost/api/bill-produce-excel.go

@@ -158,7 +158,7 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 	drawCol("C", "纸张")
 	drawCol("D", "来纸尺寸")
 	drawCol("E", "印刷尺寸")
-	drawCol("F", "数量")
+	drawCol("F", "下单数量")
 	drawCol("G", "完成数量")
 	drawCol2("H", "单价", "元/张")
 	drawCol("I", "预算金额")
@@ -189,32 +189,35 @@ func (b *ProduceBillExcel) drawTableContent() error {
 
 	produces := b.Content.Produces
 	if len(produces) > 0 {
+		startRow := b.Row
+		endRow := b.Row
 		for _, produce := range produces {
-
 			confirmCount := "-"
-			realAmount := "-"
 			price := produce.Price
 			priceStr := fmt.Sprintf("%.2f", price)
 			b.FormatToEmpty(&priceStr)
 			// 预算金额
-			budgetAmount := fmt.Sprintf("%.2f", float64(produce.Count)*price)
-			b.FormatToEmpty(&budgetAmount)
-
+			orderRealPrice := "-"
+			// 实际金额
+			realPrice := "-"
 			if b.Content.Status == "complete" {
 				// 实际完成数
-				confirmCount = fmt.Sprintf("%d", b.Content.ConfirmCount)
+				confirmCount = fmt.Sprintf("%d", produce.ConfirmCount)
 				b.FormatToEmpty(&confirmCount)
-
-				// 实际金额
-				realAmount = fmt.Sprintf("%.2f", float64(b.Content.ConfirmCount)*price)
-				b.FormatToEmpty(&realAmount)
 			}
 
 			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
-			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.Count), confirmCount, priceStr, budgetAmount, realAmount, deliveryTime, produce.Remark)
+			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), confirmCount, priceStr, orderRealPrice, realPrice, deliveryTime, produce.Remark)
 			row++
 			b.Row++
+			endRow = b.Row
 		}
+
+		// 多个工序 合并预算价格、实际价格
+		b.Excel.MergeCell(b.SheetName, fmt.Sprintf("I%d", startRow), fmt.Sprintf("I%d", endRow))
+		b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("I%d", startRow), b.Content.BudgetAmount)
+		b.Excel.MergeCell(b.SheetName, fmt.Sprintf("J%d", startRow), fmt.Sprintf("J%d", endRow))
+		b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("J%d", startRow), b.Content.RealAmount)
 	}
 
 	return nil

+ 2 - 24
boxcost/api/bill-produce.go

@@ -6,7 +6,6 @@ import (
 	"box-cost/log"
 	"errors"
 	"fmt"
-	"strconv"
 	"time"
 
 	"github.com/gin-gonic/gin"
@@ -211,34 +210,13 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 			return nil, err
 		}
 	}
-
-	bill.UpdateTime = time.Now()
-	result, err := repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, bill.Id.Hex(), &bill)
-
 	// 计算结算价格
 	if bill.Status == "complete" {
 		bill.CompleteTime = time.Now()
-		// 计算结算数量和结算金额
-		produce := &model.ProduceBill{}
-		repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-			CollectName: repo.CollectionBillProduce,
-			Query:       repo.Map{"_id": bill.Id},
-		}, produce)
-		if len(produce.Produces) > 0 {
-			// 取数组最后一个元素的下单数为整个流程结算的基础数
-			last := produce.Produces[len(produce.Produces)-1]
-			baseSet := last.ConfirmCount
-			baseNumer := baseSet * last.BatchSize
-			for _, pd := range produce.Produces {
-				pd.SetCount = baseNumer / pd.BatchSize
-				setAmount := float64(pd.SetCount) * pd.Price
-				pd.SetAmount, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", setAmount), 64)
-			}
-		}
-		repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, bill.Id.Hex(), produce)
 	}
 
-	return result, err
+	bill.UpdateTime = time.Now()
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, bill.Id.Hex(), &bill)
 }
 
 // 删除单据

+ 206 - 116
boxcost/api/plan-cost-excel.go

@@ -155,12 +155,15 @@ func (b *PlanCostExcel) drawSupplierContent() error {
 	}
 	row := b.Offset + 4
 	comps := b.Content.Pack.Components
-	var totalPlanPrice float32 = 0.00
-	var confirmTotalPlanPrice float64 = 0.00
+	// 预算金额汇总
+	var totalOrderRealPrice float64 = 0.00
+	// 实际金额汇总
+	var totalRealPrice float64 = 0.00
 	if len(comps) > 0 {
 		for _, comp := range comps {
-			var totalOrderRealPrice float32 = 0.00
-			var totalConfirmRealPrice float64 = 0.00
+			var perOrderRealPrice float64 = 0.00
+			var perRealPrice float64 = 0.00
+
 			if len(comp.Mats) > 0 {
 				startRow := 0
 				for _, mat := range comp.Mats {
@@ -172,7 +175,10 @@ func (b *PlanCostExcel) drawSupplierContent() error {
 
 							}
 
-							supplierName := mat.Supplier.SupplierInfo.Name
+							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)
@@ -186,21 +192,25 @@ func (b *PlanCostExcel) drawSupplierContent() error {
 							// 单价
 							orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
 							b.FormatToEmpty(&orderPrice)
-							totalOrderRealPrice += mat.Supplier.OrderRealPrice
+							// 预算金额
 							orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
+							perRealPrice += mat.Supplier.OrderRealPrice
 							b.FormatToEmpty(&orderRealPrice)
 							// 实际金额
-							confirmPrice := mat.Supplier.OrderPrice * float64(mat.ConfirmCount)
-							totalConfirmRealPrice += confirmPrice
-							confirmRealPrice := fmt.Sprintf("%.2f", confirmPrice)
-							b.FormatToEmpty(&confirmRealPrice)
-							b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, confirmRealPrice)
+							perRealPrice += mat.RealPrice
+							realPrice := fmt.Sprintf("%.2f", mat.RealPrice)
+							b.FormatToEmpty(&realPrice)
+							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
 						for _, craft := range mat.Crafts {
 							if craft.Supplier.SupplierInfo != nil { // 外箱材料报错
 								// 工序
@@ -209,38 +219,48 @@ func (b *PlanCostExcel) drawSupplierContent() error {
 										startRow = row
 
 									}
-									craftSupplierName := craft.Supplier.SupplierInfo.Name
-									carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
-									b.FormatToEmpty(&carftOrderCount)
+
+									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)
 
 									// 实际数量
-									confirmCraftCount := fmt.Sprintf("%d", craft.ConfirmCount)
-									b.FormatToEmpty(&confirmCraftCount)
-
-									carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
-									b.FormatToEmpty(&carftOrderPrice)
-									totalOrderRealPrice += craft.Supplier.OrderRealPrice
-									carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
-									b.FormatToEmpty(&carftOrderRealPrice)
-
-									// 实际金额
-									confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.ConfirmCount)
-									totalConfirmRealPrice += confirmCraftPrice
-									confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
-									b.FormatToEmpty(&confirmCraftRealPrice)
-
-									b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, confirmCraftCount, carftOrderPrice, carftOrderRealPrice, confirmCraftRealPrice)
+									confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
+									b.FormatToEmpty(&confirmCount)
+									price := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
+									b.FormatToEmpty(&price)
+
+									// 预算金额
+									budgetAmount := ""
+									b.FormatToEmpty(&budgetAmount)
+
+									// 实际金额 在外层合并单元格
+									realAmount := ""
+									b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
 									row++
+									mergeEndRow = row
 
 								}
 
 							}
 
 						}
+						// 多个工序 合并预算价格、实际价格
+						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 {
@@ -259,8 +279,84 @@ func (b *PlanCostExcel) drawSupplierContent() error {
 				}
 
 			}
-			totalPlanPrice += totalOrderRealPrice
-			confirmTotalPlanPrice += totalConfirmRealPrice
+			// 预算
+			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+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)
+			}
+
+			drawCol("B", "C", "材料/工序")
+			drawCol("D", "D", "供应商名称")
+			drawCol("E", "G", "规格")
+			drawCol("H", "H", "单位")
+			drawCol("I", "I", "下单数量")
+			drawCol("J", "J", "实际数量")
+			drawCol("K", "K", "单价")
+			drawCol("L", "L", "预算金额")
+			drawCol("M", "M", "实际金额")
+			row++
+
+			var DrawRow = func(rowIndex int, values ...string) {
+				charas := []string{"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)
+				}
+			}
+
+			if len(b.Content.Process) > 0 {
+				for _, ps := range b.Content.Process {
+					if supplierId == ps.Supplier.SupplierInfo.Id {
+						orderCount := fmt.Sprintf("%.2f", ps.Supplier.OrderCount)
+						confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
+						price := fmt.Sprintf("%.2f", ps.Supplier.OrderPrice)
+						b.FormatToEmpty(&price)
+						totalOrderRealPrice += ps.Supplier.OrderRealPrice
+						totalRealPrice += ps.RealPrice
+						orderRealPrice := fmt.Sprintf("%.2f", ps.Supplier.OrderRealPrice)
+						b.FormatToEmpty(&orderRealPrice)
+						realPrice := fmt.Sprintf("%.2f", ps.RealPrice)
+						DrawRow(row, ps.ProcessInfo.Name, ps.Supplier.SupplierInfo.Name, ps.ProcessInfo.Norm, ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
+						row++
+
+					}
+
+				}
+
+			}
+
 		}
 
 		// 生产汇总金额
@@ -274,15 +370,15 @@ func (b *PlanCostExcel) drawSupplierContent() error {
 
 		// 生产预算汇总
 		b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
-		planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice)
-		b.FormatToEmpty(&planTotalPrice)
-		b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
+		planOrderRealPrice := fmt.Sprintf("%.2f", totalOrderRealPrice)
+		b.FormatToEmpty(&planOrderRealPrice)
+		b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
 
 		// 生产实际汇总
 		b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
-		planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
-		b.FormatToEmpty(&planConfirmTotalPrice)
-		b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
+		planRealPrice := fmt.Sprintf("%.2f", totalRealPrice)
+		b.FormatToEmpty(&planRealPrice)
+		b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
 
 	}
 
@@ -309,12 +405,14 @@ func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
 func (b *PlanCostExcel) drawAllContent() error {
 	row := b.Offset + 4
 	comps := b.Content.Pack.Components
-	var totalPlanPrice float32 = 0.00
-	var confirmTotalPlanPrice float64 = 0.00
+	// 预算金额汇总
+	var totalOrderRealPrice float64 = 0.00
+	// 实际金额汇总
+	var totalRealPrice float64 = 0.00
 	if len(comps) > 0 {
 		for _, comp := range comps {
-			var totalConfirmRealPrice float64 = 0.00
-			var totalOrderRealPrice float32 = 0.00
+			var perOrderRealPrice float64 = 0.00
+			var perRealPrice float64 = 0.00
 			if len(comp.Mats) > 0 {
 				startRow := row
 				for _, mat := range comp.Mats {
@@ -336,63 +434,57 @@ func (b *PlanCostExcel) drawAllContent() error {
 					// 单价
 					orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
 					b.FormatToEmpty(&orderPrice)
+					// 预算金额
 					orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
-					totalOrderRealPrice += mat.Supplier.OrderRealPrice
+					perRealPrice += mat.Supplier.OrderRealPrice
 					b.FormatToEmpty(&orderRealPrice)
 					// 实际金额
-					confirmPrice := mat.Supplier.OrderPrice * float64(mat.ConfirmCount)
-					totalConfirmRealPrice += confirmPrice
-					confirmRealPrice := fmt.Sprintf("%.2f", confirmPrice)
-					b.FormatToEmpty(&confirmRealPrice)
-					b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, confirmRealPrice)
+					perRealPrice += mat.RealPrice
+					realPrice := fmt.Sprintf("%.2f", mat.RealPrice)
+					b.FormatToEmpty(&realPrice)
+					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 {
-						// ??? 多个工序 合并预算价格
-						craftStartRow := row
-						craftEndRow := row
+						// 实际数量、预算数量
+						mergeStartRow := row
+						mergeEndRow := row
 						for _, craft := range mat.Crafts {
-							craftSupplierName := ""
-							if craft.Supplier.SupplierInfo != nil { // 外箱材料报错
-								craftSupplierName = craft.Supplier.SupplierInfo.Name
-
+							supplierName := ""
+							if craft.Supplier.SupplierInfo != nil {
+								supplierName = craft.Supplier.SupplierInfo.Name
 							}
-							carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
-							b.FormatToEmpty(&carftOrderCount)
+
+							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)
 
 							// 实际数量
-							confirmCraftCount := fmt.Sprintf("%d", craft.ConfirmCount)
-							b.FormatToEmpty(&confirmCraftCount)
-
-							carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
-							b.FormatToEmpty(&carftOrderPrice)
-							carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
-							b.FormatToEmpty(&carftOrderRealPrice)
-
-							// 实际金额
-							confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.ConfirmCount)
+							confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
+							b.FormatToEmpty(&confirmCount)
+							price := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
+							b.FormatToEmpty(&price)
 
-							totalConfirmRealPrice += confirmCraftPrice
-							confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
-							b.FormatToEmpty(&confirmCraftRealPrice)
+							// 预算金额
+							budgetAmount := ""
+							b.FormatToEmpty(&budgetAmount)
 
-							b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, confirmCraftCount, carftOrderPrice, carftOrderRealPrice, confirmCraftRealPrice)
+							// 实际金额 在外层合并单元格
+							realAmount := ""
+							b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
 							row++
-							craftEndRow = row
-						}
-						// 多个工序 合并预算价格
-						if len(mat.Crafts) > 1 {
-							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", craftStartRow), fmt.Sprintf("L%d", craftEndRow))
-							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", craftStartRow), mat.Crafts[0].Supplier.OrderRealPrice)
-
+							mergeEndRow = row
 						}
-						// 只加一次合并的预算金额
-						totalOrderRealPrice += mat.Crafts[0].Supplier.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
@@ -407,22 +499,21 @@ func (b *PlanCostExcel) drawAllContent() error {
 				b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
 			}
 
-			// 实际
-			confirmTotalPlanPrice += totalConfirmRealPrice
-
 			// 预算
-			totalPlanPrice += totalOrderRealPrice
+			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, "其他")
+		b.Excel.SetCellValue(b.SheetName, startACell, "额外工序")
 		row++
 		// 工序 外箱 手工费 表头
 		var drawCol = func(startCell, endCell string, value string) error {
@@ -466,23 +557,22 @@ func (b *PlanCostExcel) drawAllContent() error {
 			}
 		}
 
-		ps := b.Content.Process
-		count := fmt.Sprintf("%.2f", ps.Supplier.OrderCount)
-		confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
-		price := fmt.Sprintf("%.2f", ps.Supplier.OrderPrice)
-		b.FormatToEmpty(&price)
-		// budgetAmountf := ps.Supplier.OrderPrice * float64(ps.Supplier.OrderCount)
-		budgetAmount := fmt.Sprintf("%.2f", ps.Supplier.OrderRealPrice)
-		b.FormatToEmpty(&budgetAmount)
-		// realAmountf := ps.Price * float64(ps.ConfirmCount)
-		realAmountf := ps.Supplier.OrderPrice * float64(ps.ConfirmCount)
-		realAmount := fmt.Sprintf("%.2f", realAmountf)
-		b.FormatToEmpty(&realAmount)
-		confirmTotalPlanPrice += realAmountf
-		totalPlanPrice += float32(ps.Supplier.OrderRealPrice)
-
-		DrawRow(row, ps.ProcessInfo.Name, ps.Supplier.SupplierInfo.Name, ps.ProcessInfo.Norm, ps.ProcessInfo.Unit, count, confirmCount, price, budgetAmount, realAmount)
-		row++
+		if len(b.Content.Process) > 0 {
+			for _, ps := range b.Content.Process {
+				orderCount := fmt.Sprintf("%.2f", ps.Supplier.OrderCount)
+				confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
+				price := fmt.Sprintf("%.2f", ps.Supplier.OrderPrice)
+				b.FormatToEmpty(&price)
+				totalOrderRealPrice += ps.Supplier.OrderRealPrice
+				totalRealPrice += ps.RealPrice
+				orderRealPrice := fmt.Sprintf("%.2f", ps.Supplier.OrderRealPrice)
+				b.FormatToEmpty(&orderRealPrice)
+				realPrice := fmt.Sprintf("%.2f", ps.RealPrice)
+				DrawRow(row, ps.ProcessInfo.Name, ps.Supplier.SupplierInfo.Name, ps.ProcessInfo.Norm, ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
+				row++
+			}
+
+		}
 
 	}
 	// 生产汇总金额
@@ -496,16 +586,15 @@ func (b *PlanCostExcel) drawAllContent() error {
 
 	// 生产预算汇总
 	b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
-	// planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice) //
-	planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice)
-	b.FormatToEmpty(&planTotalPrice)
-	b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
+	planOrderRealPrice := fmt.Sprintf("%.2f", totalOrderRealPrice)
+	b.FormatToEmpty(&planOrderRealPrice)
+	b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
 
 	// 生产实际汇总
 	b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
-	planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
-	b.FormatToEmpty(&planConfirmTotalPrice)
-	b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
+	planRealPrice := fmt.Sprintf("%.2f", totalRealPrice)
+	b.FormatToEmpty(&planRealPrice)
+	b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
 
 	return nil
 }
@@ -513,11 +602,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()
 
 }
 

+ 30 - 0
boxcost/api/process.go

@@ -2,12 +2,20 @@ package api
 
 import (
 	"box-cost/db/model"
+	"box-cost/db/repo"
+	"box-cost/log"
+	"errors"
 	"time"
 
 	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 func Process(r *GinRouter) {
+
+	// 获取生产计划详情
+	r.GET("/process/detail/:id", ProcessDetail)
+
 	CreateCRUD(r, "/process", &CRUDOption{
 		Collection: "process",
 		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
@@ -29,3 +37,25 @@ func Process(r *GinRouter) {
 		SearchProject: []string{"name", "unit", "norm", "price", "category", "remark"},
 	})
 }
+
+func ProcessDetail(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
+	option := &repo.DocSearchOptions{
+		CollectName: repo.CollectionProcess,
+		Query:       repo.Map{"_id": id},
+	}
+
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), option, &process)
+	if !found || err != nil {
+		log.Info(err)
+		return nil, errors.New("数据未找到")
+	}
+
+	return process, nil
+
+}

+ 4 - 4
boxcost/api/report-produce-excel.go

@@ -160,7 +160,7 @@ func (b *ReportProduceExcel) drawTableTitle() error {
 	drawCol("C", "纸张")
 	drawCol("D", "来纸尺寸")
 	drawCol("E", "印刷尺寸")
-	drawCol("F", "数量")
+	drawCol("F", "下单数量")
 	drawCol("G", "完成数量")
 	drawCol2("H", "单价", "元/张")
 	drawCol("I", "预算金额")
@@ -201,10 +201,10 @@ func (b *ReportProduceExcel) drawTableContent() error {
 			b.FormatToEmpty(&priceStr)
 
 			// 预算金额
-			budgetAmount := fmt.Sprintf("%.2f", float64(produce.Count)*price)
+			budgetAmount := fmt.Sprintf("%.2f", float64(produce.OrderCount)*price)
 			b.FormatToEmpty(&budgetAmount)
 
-			b.BudgetCount += float64(produce.Count) * price
+			b.BudgetCount += float64(produce.OrderCount) * price
 
 			// 实际完成数
 			confirmCount = fmt.Sprintf("%d", b.Content.ConfirmCount)
@@ -217,7 +217,7 @@ func (b *ReportProduceExcel) drawTableContent() error {
 			b.RealCount += float64(b.Content.ConfirmCount) * price
 
 			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
-			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.Count), confirmCount, priceStr, budgetAmount, realAmount, deliveryTime, produce.Remark)
+			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), confirmCount, priceStr, budgetAmount, realAmount, deliveryTime, produce.Remark)
 			row++
 			b.Row++
 		}

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

@@ -149,7 +149,7 @@ func SupplierPrice(r *GinRouter) {
 	})
 
 	CreateCRUD(r, "/supplier/process", &CRUDOption{
-		Collection: repo.CollectionSupplierCraftprice,
+		Collection: repo.CollectionSupplierProcessprice,
 		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			entity := &model.SupplierPrice{}
 			c.ShouldBindJSON(entity)

+ 6 - 4
boxcost/api/supplier.go

@@ -129,11 +129,13 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		}
 
 		listOut = list
-	} else {
+	}
 
-		if query["craftId"] == nil {
-			return nil, fmt.Errorf("参数错误 craftId 或matId不能为空")
-		}
+	if query["craftId"] != nil {
+
+		// if query["craftId"] == nil {
+		// 	return nil, fmt.Errorf("参数错误 craftId 或matId不能为空")
+		// }
 
 		cratf := &model.Craft{}
 

+ 23 - 15
boxcost/db/model/bill.go

@@ -27,6 +27,9 @@ type PaperBill struct {
 	//数量
 	Count int `bson:"count,omitempty" json:"count"`
 
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
+
 	//备注
 	Remark string `bson:"remark,omitempty" json:"remark"`
 
@@ -61,9 +64,6 @@ type PurchaseBill struct {
 	//商品名字
 	ProductName string `bson:"productName,omitempty" json:"productName"`
 
-	//确认收货数量
-	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
-
 	//纸张类采购
 	Paper []*PaperBill `bson:"papers,omitempty" json:"papers"`
 
@@ -74,6 +74,15 @@ type PurchaseBill struct {
 	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
 
 	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	// 实际金额
+	RealAmount float64 `bson:"realAmount,omitempty" json:"realAmount"`
+
+	// 预算金额
+	BudgetAmount float64 `bson:"budgetAmount,omitempty" json:"realAmbudgetAmountount"`
+
+	//确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
 }
 
 // 工艺生产数据
@@ -89,8 +98,11 @@ type ProduceBillData struct {
 
 	Price2 float64 `bson:"price2,omitempty" json:"price2"`
 
-	//数量
-	Count int `bson:"count,omitempty" json:"count"`
+	// 成品数量
+	// Count int `bson:"count,omitempty" json:"count"`
+
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
 
 	//备注
 	Remark string `bson:"remark,omitempty" json:"remark"`
@@ -107,18 +119,8 @@ type ProduceBillData struct {
 	//交货时间
 	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
 
-	// todo
-	// 单位成品数
-	BatchSize int `bson:"batchSize,omitempty" json:"batchSize"`
-
 	// 确认收货数量
 	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
-
-	// 结算数量
-	SetCount int `bson:"setCount,omitempty" json:"setCount"`
-
-	// 结算金额
-	SetAmount float64 `bson:"setAmount,omitempty" json:"setAmount"`
 }
 
 type ProduceBill struct {
@@ -143,6 +145,12 @@ type ProduceBill struct {
 	//确认收货数量
 	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
 
+	// 实际金额
+	RealAmount float64 `bson:"realAmount,omitempty" json:"realAmount"`
+
+	// 预算金额
+	BudgetAmount float64 `bson:"budgetAmount,omitempty" json:"realAmbudgetAmountount"`
+
 	//供应商
 	Supplier string `bson:"supplier,omitempty" json:"supplier"`
 

+ 7 - 2
boxcost/db/model/pack.go

@@ -55,8 +55,8 @@ type SupplierPriceVo struct {
 	//订单数据量
 	OrderCount float64 `bson:"orderCount,omitempty" json:"orderCount"`
 
-	//订单实际金额
-	OrderRealPrice float32 `bson:"orderRealPrice,omitempty" json:"orderRealPrice"`
+	// 预算金额
+	OrderRealPrice float64 `bson:"orderRealPrice,omitempty" json:"orderRealPrice"`
 
 	//供应商信息
 	SupplierInfo *Supplier `bson:"supplierInfo,omitempty" json:"supplierInfo"`
@@ -80,6 +80,8 @@ type PackComponentMat struct {
 
 	Remark string `bson:"remark,omitempty" json:"remark"` //备注
 
+	RealPrice float64 `bson:"realPrice,omitempty" json:"realPrice"`
+
 	//确认收货数量
 	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
 }
@@ -106,6 +108,9 @@ type PackComponentMatCraft struct {
 
 	Remark string `bson:"remark,omitempty" json:"remark"` //备注
 
+	// 实际金额
+	RealPrice float64 `bson:"realPrice,omitempty" json:"realPrice"`
+
 	//确认收货数量
 	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
 }

+ 1 - 1
boxcost/db/model/plan.go

@@ -16,7 +16,7 @@ type ProductPlan struct {
 	CreateUser string `bson:"createUser,omitempty" json:"createUser"`
 
 	// 工序 外箱、手工非
-	Process *ProcessData `bson:"process,omitempty" json:"process"`
+	Process []*ProcessData `bson:"process,omitempty" json:"process"`
 
 	//生产数量
 	Total int `bson:"total,omitempty" json:"total"`

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

@@ -28,15 +28,14 @@ type ProcessBill struct {
 	Name     string `bson:"name,omitempty" json:"name"`
 	Supplier string `bson:"supplier,omitempty" json:"supplier"`
 
-	//确认收货数量
-	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
-
 	//名字
 	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"`
 	//单价
@@ -47,15 +46,23 @@ type ProcessBill struct {
 
 	//交货时间
 	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:"crafts,omitempty" json:"crafts"`
+	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"`
 }