animeic %!s(int64=2) %!d(string=hai) anos
pai
achega
779b02ffdf

BIN=BIN
boxcost/__debug_bin


+ 46 - 70
boxcost/api/bill-produce-excel.go

@@ -24,12 +24,11 @@ type ProduceBillExcel struct {
 }
 
 func (b *ProduceBillExcel) drawTitle() error {
-	// 设置外边距
+	b.Row++
 	marginLeft := excelize.PageMarginLeft(0.15)
 	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("L%d", tileIndex))
+	startCell := fmt.Sprintf("A%d", b.Row)
+	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("L%d", b.Row))
 	if err != nil {
 		return err
 	}
@@ -44,14 +43,13 @@ func (b *ProduceBillExcel) 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 *ProduceBillExcel) drawSubTitles() error {
-	row := b.Offset + 2
-
+	b.Row++
 	styleLeft, err := b.Excel.NewStyle(&excelize.Style{
 		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
 		Font:      &excelize.Font{Size: 11}})
@@ -95,18 +93,18 @@ func (b *ProduceBillExcel) drawSubTitles() error {
 	}
 
 	//第一行
-	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)
@@ -114,19 +112,17 @@ func (b *ProduceBillExcel) 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 *ProduceBillExcel) drawTableTitle() error {
-	row := b.Offset + 5
-
-	//A加工项目 B规格(克) 尺寸C-D 数量E 单价F-G 交货时间H 备注I
+	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 {
@@ -142,8 +138,8 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 
 	var drawCol2 = func(prefix string, value1 string, value2 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.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
 		if err != nil {
 			return err
@@ -170,8 +166,7 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 }
 
 func (b *ProduceBillExcel) drawTableContent() error {
-	row := b.Offset + 7
-	b.Row = row
+	b.Row += 2
 	var DrawRow = func(rowIndex int, values ...string) {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
 		for i, c := range charas {
@@ -189,48 +184,34 @@ func (b *ProduceBillExcel) drawTableContent() error {
 
 	produces := b.Content.Produces
 	if len(produces) > 0 {
-		startRow := b.Row
-		endRow := b.Row
 		for _, produce := range produces {
-			confirmCount := "-"
+			realCount := ""
 			price := produce.Price
 			priceStr := fmt.Sprintf("%.3f", price)
 			b.FormatToEmpty(&priceStr)
 			// 预算金额
-			orderRealPrice := "-"
+			orderPrice := fmt.Sprintf("%.3f", produce.Price*float64(produce.OrderCount))
+			b.FormatToEmpty(&orderPrice)
 			// 实际金额
-			realPrice := "-"
+			realPrice := ""
 			if b.Content.Status == "complete" {
 				// 实际完成数
-				confirmCount = fmt.Sprintf("%d", produce.ConfirmCount)
-				b.FormatToEmpty(&confirmCount)
+				realCount = fmt.Sprintf("%d", produce.ConfirmCount)
+				b.FormatToEmpty(&realCount)
+				realPrice = fmt.Sprintf("%.3f", produce.Price*float64(produce.ConfirmCount))
 			}
 
 			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
-			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), confirmCount, priceStr, orderRealPrice, realPrice, deliveryTime, produce.Remark)
-			endRow = b.Row
-			row++
+			DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, orderPrice, realPrice, deliveryTime, produce.Remark)
 			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
 }
 
 func (b *ProduceBillExcel) drawTableFooter() error {
-	// row := b.Offset + 8
-	// b.Row++
-	row := b.Row
-
-	left1Cell := fmt.Sprintf("A%d", row)
-
+	left1Cell := fmt.Sprintf("A%d", b.Row)
 	border := []excelize.Border{
 		{Type: "top", Style: 1, Color: "000000"},
 		{Type: "left", Style: 1, Color: "000000"},
@@ -246,18 +227,18 @@ func (b *ProduceBillExcel) drawTableFooter() error {
 	b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
 	b.Excel.SetCellValue(b.SheetName, left1Cell, "送货地址")
 
-	addCel := fmt.Sprintf("B%d", row)
+	addCel := fmt.Sprintf("B%d", b.Row)
 
-	b.Excel.MergeCell(b.SheetName, addCel, fmt.Sprintf("E%d", row))
-	b.Excel.SetCellStyle(b.SheetName, addCel, fmt.Sprintf("E%d", row), styleLeft)
+	b.Excel.MergeCell(b.SheetName, addCel, fmt.Sprintf("E%d", b.Row))
+	b.Excel.SetCellStyle(b.SheetName, addCel, fmt.Sprintf("E%d", b.Row), styleLeft)
 	b.Excel.SetCellValue(b.SheetName, addCel, b.Content.SendTo)
 
-	sureCel := fmt.Sprintf("F%d", row)
-	b.Excel.MergeCell(b.SheetName, sureCel, fmt.Sprintf("L%d", row))
-	b.Excel.SetCellStyle(b.SheetName, sureCel, fmt.Sprintf("L%d", row), styleLeft)
+	sureCel := fmt.Sprintf("F%d", b.Row)
+	b.Excel.MergeCell(b.SheetName, sureCel, fmt.Sprintf("L%d", b.Row))
+	b.Excel.SetCellStyle(b.SheetName, sureCel, fmt.Sprintf("L%d", b.Row), styleLeft)
 	b.Excel.SetCellValue(b.SheetName, sureCel, "供应商签字:")
 
-	b.Excel.SetRowHeight(b.SheetName, row, 21)
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
 
 	return nil
 }
@@ -265,7 +246,7 @@ func (b *ProduceBillExcel) drawTableFooter() error {
 func (b *ProduceBillExcel) drawTableSignature() error {
 	// row := b.Offset + 11
 	b.Row += 2
-	row := b.Row
+	// row := b.Row
 
 	style1, _ := b.Excel.NewStyle(&excelize.Style{
 		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
@@ -273,25 +254,25 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 	})
 
 	// 制单人
-	billUserCell := fmt.Sprintf("A%d", row+1)
+	billUserCell := fmt.Sprintf("A%d", b.Row+1)
 	b.Excel.SetCellValue(b.SheetName, billUserCell, "制单人:")
-	billUservCell := fmt.Sprintf("B%d", row+1)
+	billUservCell := fmt.Sprintf("B%d", b.Row+1)
 	b.Excel.SetCellValue(b.SheetName, billUservCell, b.Content.UserName)
 
-	fontCell := fmt.Sprintf("H%d", row)
-	imageCell1 := fmt.Sprintf("I%d", row)
-	imageCell2 := fmt.Sprintf("K%d", row)
-	b.Excel.MergeCell(b.SheetName, fontCell, fmt.Sprintf("H%d", row+2))
+	fontCell := fmt.Sprintf("H%d", b.Row)
+	imageCell1 := fmt.Sprintf("I%d", b.Row)
+	imageCell2 := fmt.Sprintf("K%d", b.Row)
+	b.Excel.MergeCell(b.SheetName, fontCell, fmt.Sprintf("H%d", b.Row+2))
 	b.Excel.SetCellStyle(b.SheetName, fontCell, fontCell, style1)
 	b.Excel.SetCellValue(b.SheetName, fontCell, "审核签字:")
 
 	// 签字图片1 I10-J12
-	b.Excel.MergeCell(b.SheetName, imageCell1, fmt.Sprintf("J%d", row+2))
+	b.Excel.MergeCell(b.SheetName, imageCell1, fmt.Sprintf("J%d", b.Row+2))
 	b.Excel.SetCellStyle(b.SheetName, imageCell1, imageCell1, style1)
 	b.Excel.SetCellValue(b.SheetName, imageCell1, "")
 
 	// 签字图片2 K10-L12
-	b.Excel.MergeCell(b.SheetName, imageCell2, fmt.Sprintf("L%d", row+2))
+	b.Excel.MergeCell(b.SheetName, imageCell2, fmt.Sprintf("L%d", b.Row+2))
 	b.Excel.SetCellStyle(b.SheetName, imageCell2, imageCell1, style1)
 	b.Excel.SetCellValue(b.SheetName, imageCell2, "")
 
@@ -306,7 +287,7 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 		}
 	}
 
-	b.Excel.SetRowHeight(b.SheetName, row, 21)
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
 
 	return nil
 }
@@ -343,11 +324,6 @@ func NewProduceBill(f *excelize.File) *ProduceBillExcel {
 		Signatures:       make([]*model.Signature, 0),
 	}
 
-	// f.SetColWidth(b.SheetName, "A", "A", 17)
-	// f.SetColWidth(b.SheetName, "B", "B", 13)
-	// f.SetColWidth(b.SheetName, "C", "G", 9.5)
-	// f.SetColWidth(b.SheetName, "H", "I", 12)
-
 	f.SetColWidth(b.SheetName, "A", "A", 12)
 	f.SetColWidth(b.SheetName, "B", "K", 9.5)
 	// f.SetColWidth(b.SheetName, "I", "J", 8)

+ 36 - 33
boxcost/api/bill-purchase-excel.go

@@ -31,9 +31,10 @@ type PurchaseBillExcel struct {
 func (b *PurchaseBillExcel) drawTitle() error {
 	marginLeft := excelize.PageMarginLeft(0.15)
 	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("L%d", tileIndex))
+	// tileIndex := b.Offset + 1
+	b.Row++
+	startCell := fmt.Sprintf("A%d", b.Row)
+	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("L%d", b.Row))
 	if err != nil {
 		return err
 	}
@@ -48,14 +49,15 @@ func (b *PurchaseBillExcel) 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 *PurchaseBillExcel) drawSubTitles() error {
 
-	row := b.Offset + 2
+	// row := b.Offset + 2
+	b.Row++
 
 	styleLeft, err := b.Excel.NewStyle(&excelize.Style{
 		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
@@ -99,18 +101,18 @@ func (b *PurchaseBillExcel) 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)
@@ -118,18 +120,19 @@ func (b *PurchaseBillExcel) 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 *PurchaseBillExcel) drawTableTitle() error {
-	row := b.Offset + 5
+	// row := b.Offset + 5
+	b.Row += 3
 	//A采购项目 B规格(克) 尺寸C-D 数量E 单价F-G 交货时间H 备注I
 	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 {
@@ -144,8 +147,8 @@ func (b *PurchaseBillExcel) 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
@@ -160,11 +163,11 @@ func (b *PurchaseBillExcel) 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
@@ -206,8 +209,9 @@ func (b *PurchaseBillExcel) drawTableTitle() error {
 }
 
 func (b *PurchaseBillExcel) drawTableContent() error {
-	row := b.Offset + 7
-	b.Row = row
+	// row := b.Offset + 7
+	// b.Row = row
+	b.Row += 2
 
 	var DrawRow = func(rowIndex int, values ...string) {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
@@ -228,27 +232,26 @@ func (b *PurchaseBillExcel) drawTableContent() error {
 		for _, paper := range papers {
 			deliveryTime := paper.DeliveryTime.Local().Format("2006-01-02")
 
-			confirmCount := "-"
-			realAmount := "-"
+			realCount := ""
+			realPrice := ""
 			price := fmt.Sprintf("%.3f", paper.Price)
 			price2 := fmt.Sprintf("%.3f", paper.Price2)
 
 			// 预算金额
-			budgetAmount := fmt.Sprintf("%.3f", b.Content.BudgetAmount)
-			b.FormatToEmpty(&budgetAmount)
+			orderPrice := fmt.Sprintf("%.3f", paper.Price*float64(paper.OrderCount))
+			b.FormatToEmpty(&orderPrice)
 
 			if b.Content.Status == "complete" {
 				// 实际完成数
-				confirmCount = fmt.Sprintf("%d", b.Content.ConfirmCount)
-				b.FormatToEmpty(&confirmCount)
+				realCount = fmt.Sprintf("%d", paper.ConfirmCount)
+				b.FormatToEmpty(&realCount)
 
 				// 实际金额
-				realAmount = fmt.Sprintf("%.3f", b.Content.RealAmount)
-				b.FormatToEmpty(&realAmount)
+				realPrice = fmt.Sprintf("%.3f", paper.Price*float64(paper.ConfirmCount))
+				b.FormatToEmpty(&realPrice)
 			}
 
-			DrawRow(row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), confirmCount, price, price2, budgetAmount, realAmount, deliveryTime, paper.Remark)
-			row++
+			DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), realCount, price, price2, orderPrice, realPrice, deliveryTime, paper.Remark)
 			b.Row++
 		}
 	}

+ 34 - 67
boxcost/api/report-produce-excel.go

@@ -29,9 +29,9 @@ func (b *ReportProduceExcel) drawTitle() error {
 	// 设置外边距
 	marginLeft := excelize.PageMarginLeft(0.15)
 	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("L%d", tileIndex))
+	b.Row++
+	startCell := fmt.Sprintf("A%d", b.Row)
+	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("L%d", b.Row))
 	if err != nil {
 		return err
 	}
@@ -46,13 +46,13 @@ func (b *ReportProduceExcel) 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 *ReportProduceExcel) drawSubTitles() error {
-	row := b.Offset + 2
+	b.Row++
 
 	styleLeft, err := b.Excel.NewStyle(&excelize.Style{
 		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
@@ -97,18 +97,18 @@ func (b *ReportProduceExcel) drawSubTitles() error {
 	}
 
 	//第一行
-	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)
@@ -116,19 +116,19 @@ func (b *ReportProduceExcel) 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 *ReportProduceExcel) drawTableTitle() error {
-	row := b.Offset + 5
+	b.Row += 3
 
 	//A加工项目 B规格(克) 尺寸C-D 数量E 单价F-G 交货时间H 备注I
 	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 {
@@ -144,8 +144,8 @@ func (b *ReportProduceExcel) drawTableTitle() error {
 
 	var drawCol2 = func(prefix string, value1 string, value2 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.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
 		if err != nil {
 			return err
@@ -172,8 +172,7 @@ func (b *ReportProduceExcel) drawTableTitle() error {
 }
 
 func (b *ReportProduceExcel) drawTableContent() error {
-	row := b.Offset + 7
-	b.Row = row
+	b.Row += 2
 	var DrawRow = func(rowIndex int, values ...string) {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
 		for i, c := range charas {
@@ -190,40 +189,31 @@ func (b *ReportProduceExcel) drawTableContent() error {
 	}
 
 	produces := b.Content.Produces
+
 	if len(produces) > 0 {
-		startRow := b.Row
-		endRow := b.Row
 		for _, produce := range produces {
-
-			confirmCount := "-"
-			realAmount := "-"
+			realCount := ""
 			price := produce.Price
-
 			priceStr := fmt.Sprintf("%.3f", price)
 			b.FormatToEmpty(&priceStr)
-
 			// 预算金额
-			budgetAmount := ""
-
-			// 实际完成数
-			confirmCount = fmt.Sprintf("%d", produce.ConfirmCount)
-			b.FormatToEmpty(&confirmCount)
-
+			orderPrice := fmt.Sprintf("%.3f", produce.Price*float64(produce.OrderCount))
+			b.FormatToEmpty(&orderPrice)
 			// 实际金额
-			realAmount = ""
+			realPrice := ""
+			if b.Content.Status == "complete" {
+				// 实际完成数
+				realCount = fmt.Sprintf("%d", produce.ConfirmCount)
+				b.FormatToEmpty(&realCount)
+				realPrice = fmt.Sprintf("%.3f", produce.Price*float64(produce.ConfirmCount))
+			}
 
 			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
-			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++
+			DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, orderPrice, realPrice, deliveryTime, produce.Remark)
 			b.Row++
+			b.BudgetCount += produce.Price * float64(produce.OrderCount)
+			b.RealCount += produce.Price * float64(produce.ConfirmCount)
 		}
-		// 多个工序 合并预算价格、实际价格
-		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)
-		b.BudgetCount += b.Content.BudgetAmount
-		b.RealCount += b.Content.RealAmount
 	}
 
 	return nil
@@ -236,29 +226,6 @@ func (b *ReportProduceExcel) Draws() {
 	b.drawTableContent()
 }
 
-func (b *ReportProduceExcel) Count() {
-	row := b.Row + 1
-
-	startCell := fmt.Sprintf("%s%d", "A", row)
-	endCell := fmt.Sprintf("%s%d", "H", row)
-	b.Excel.MergeCell(b.SheetName, startCell, endCell)
-	b.Excel.SetCellStyle(b.SheetName, startCell, endCell, b.AlignCenterStyle)
-	b.Excel.SetCellValue(b.SheetName, startCell, "汇总金额")
-
-	// 预算金额汇总
-	budgetCountCell := fmt.Sprintf("%s%d", "I", row)
-	b.Excel.SetCellValue(b.SheetName, budgetCountCell, b.BudgetCount)
-	b.Excel.SetCellStyle(b.SheetName, budgetCountCell, budgetCountCell, b.AlignCenterStyle)
-
-	// 实际金额汇总
-	RealCountCell := fmt.Sprintf("%s%d", "J", row)
-	b.Excel.SetCellValue(b.SheetName, RealCountCell, b.RealCount)
-	b.Excel.SetCellStyle(b.SheetName, RealCountCell, RealCountCell, b.AlignCenterStyle)
-
-	b.Excel.SetRowHeight(b.SheetName, row, 21)
-
-}
-
 func NewReportProduceExcel(f *excelize.File) *ReportProduceExcel {
 
 	border := []excelize.Border{

+ 19 - 38
boxcost/api/report-purchase-excel.go

@@ -24,6 +24,9 @@ type ReportPurchaseExcel struct {
 	AlignCenterStyle int
 
 	Content *model.PurchaseBill
+
+	BudgetCount float64
+	RealCount   float64
 }
 
 func (b *ReportPurchaseExcel) drawTitle() error {
@@ -224,30 +227,35 @@ func (b *ReportPurchaseExcel) drawTableContent() error {
 			b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
 		}
 	}
+
 	papers := b.Content.Paper
 	if len(papers) > 0 {
 		for _, paper := range papers {
 			deliveryTime := paper.DeliveryTime.Local().Format("2006-01-02")
 
-			confirmCount := "-"
-			realAmount := "-"
+			realCount := ""
+			realPrice := ""
 			price := fmt.Sprintf("%.3f", paper.Price)
 			price2 := fmt.Sprintf("%.3f", paper.Price2)
 
 			// 预算金额
-			budgetAmount := fmt.Sprintf("%.3f", b.Content.BudgetAmount)
-			b.FormatToEmpty(&budgetAmount)
+			orderPrice := fmt.Sprintf("%.3f", paper.Price*float64(paper.OrderCount))
+			b.FormatToEmpty(&orderPrice)
 
-			// 实际完成数
-			confirmCount = fmt.Sprintf("%d", b.Content.ConfirmCount)
-			b.FormatToEmpty(&confirmCount)
+			if b.Content.Status == "complete" {
+				// 实际完成数
+				realCount = fmt.Sprintf("%d", paper.ConfirmCount)
+				b.FormatToEmpty(&realCount)
 
-			// 实际金额
-			realAmount = fmt.Sprintf("%.3f", b.Content.RealAmount)
-			b.FormatToEmpty(&realAmount)
+				// 实际金额
+				realPrice = fmt.Sprintf("%.3f", paper.Price*float64(paper.ConfirmCount))
+				b.FormatToEmpty(&realPrice)
+			}
 
-			DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), confirmCount, price, price2, budgetAmount, realAmount, deliveryTime, paper.Remark)
+			DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), realCount, price, price2, orderPrice, realPrice, deliveryTime, paper.Remark)
 			b.Row++
+			b.BudgetCount += paper.Price * float64(paper.OrderCount)
+			b.RealCount += paper.Price * float64(paper.ConfirmCount)
 		}
 	}
 
@@ -298,30 +306,3 @@ func (b *ReportPurchaseExcel) FormatToEmpty(str *string) {
 	}
 
 }
-
-// 接口方法
-
-func (b *ReportPurchaseExcel) PrintPurchType() string {
-	return "purchase report"
-
-}
-func (b *ReportPurchaseExcel) SetContent(content *model.PurchaseBill) {
-	b.Content = content
-
-}
-func (b *ReportPurchaseExcel) SetOffset(offset int) {
-	b.Offset = offset
-}
-func (b *ReportPurchaseExcel) SetTitle(title string) {
-	b.Title = title
-
-}
-
-func (b *ReportPurchaseExcel) SetRow(row int) {
-	b.Row = row
-
-}
-func (b *ReportPurchaseExcel) GetRow() int {
-	return b.Row
-
-}

+ 8 - 11
boxcost/api/report.go

@@ -68,8 +68,6 @@ func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
 		CollectName: repo.CollectionBillProduce,
 		Query:       handleReportQuery(query),
 	}, &produces)
-	fmt.Println(err)
-	fmt.Println(produces)
 	if err != nil || len(produces) < 1 {
 		return nil, errors.New("数据不存在")
 	}
@@ -181,21 +179,20 @@ func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, er
 	var row int = 0
 
 	for _, purchase := range purchases {
-		var reportBill IRPurchBill
-		// if purchase.Process != nil {
-		// 	reportBill = NewReportProcessBill(f)
-
-		// }
+		var reportBill *ReportPurchaseExcel
 		if len(purchase.Paper) > 0 {
 			reportBill = NewReportPurchaseExcel(f)
 		}
-		reportBill.SetRow(row)
-		reportBill.SetContent(&purchase)
-		reportBill.SetTitle(fmt.Sprintf("%s原材料采购单", companyName))
+		if reportBill == nil {
+			return nil, errors.New("数据不存在")
+		}
+		reportBill.Row = row
+		reportBill.Content = &purchase
+		reportBill.Title = fmt.Sprintf("%s原材料采购单", companyName)
 		reportBill.Draws()
 		budgetCount += purchase.BudgetAmount
 		realCount += purchase.RealAmount
-		row = reportBill.GetRow() + 3
+		row = reportBill.Row + 3
 	}
 	row = row - 2
 	startCell := fmt.Sprintf("%s%d", "A", row)

+ 1 - 0
boxcost/boxcost.log

@@ -18,3 +18,4 @@
 {"level":"info","timestamp":"2023-02-21 12:21:18","message":"[error decoding key papers.0.price: cannot decode string into a float32 or float64 type]","service_name":"boxcost"}
 {"level":"info","timestamp":"2023-02-21 12:23:02","message":"[<nil>]","service_name":"boxcost"}
 {"level":"info","timestamp":"2023-02-21 12:25:42","message":"[error decoding key papers.0.price: cannot decode string into a float32 or float64 type]","service_name":"boxcost"}
+{"level":"info","timestamp":"2023-02-21 14:15:57","message":"[<nil>]","service_name":"boxcost"}

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

@@ -31,7 +31,7 @@ type PaperBill struct {
 	Remark string `bson:"remark,omitempty" json:"remark"`
 
 	//备注
-	ConfirmCount string `bson:"confirmCount,omitempty" json:"confirmCount"`
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
 
 	//交货时间
 	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`