animeic il y a 2 ans
Parent
commit
a7b94777f0
1 fichiers modifiés avec 132 ajouts et 223 suppressions
  1. 132 223
      boxcost/api/bill-produce-excel.go

+ 132 - 223
boxcost/api/bill-produce-excel.go

@@ -27,40 +27,40 @@ type ProduceBillExcel struct {
 
 func (b *ProduceBillExcel) drawTitle() error {
 	b.Row++
-	// marginLeft := excelize.PageMarginLeft(0.15)
-	// startCell := fmt.Sprintf("A%d", b.Row)
-	// endCell := fmt.Sprintf("L%d", b.Row)
-
-	// !isPrint
-	// if !b.Content.IsPrint {
-	// 	endCell = fmt.Sprintf("I%d", b.Row)
-	// 	marginLeft = excelize.PageMarginLeft(0.4)
-	// 	b.Excel.SetColWidth(b.SheetName, "A", "B", 16)
-	// 	b.Excel.SetColWidth(b.SheetName, "C", "H", 10.5)
-	// 	b.Excel.SetColWidth(b.SheetName, "I", "I", 16)
-	// }
-
-	// !!isPdf
-	// if b.IsPdf == "true" {
-	marginLeft := excelize.PageMarginLeft(0.18)
+	//是打印
 	startCell := fmt.Sprintf("A%d", b.Row)
+	marginLeft := excelize.PageMarginLeft(0.18)
 	endCell := fmt.Sprintf("J%d", b.Row)
-	b.Excel.SetColWidth(b.SheetName, "A", "A", 16)
-	b.Excel.SetColWidth(b.SheetName, "B", "C", 14)
-	b.Excel.SetColWidth(b.SheetName, "C", "H", 10)
-	b.Excel.SetColWidth(b.SheetName, "I", "I", 12)
-	b.Excel.SetColWidth(b.SheetName, "J", "J", 14)
+	if b.Content.IsPrint {
+		b.Excel.SetColWidth(b.SheetName, "A", "A", 16)
+		b.Excel.SetColWidth(b.SheetName, "B", "C", 14)
+		b.Excel.SetColWidth(b.SheetName, "C", "H", 10)
+		b.Excel.SetColWidth(b.SheetName, "I", "I", 12)
+		b.Excel.SetColWidth(b.SheetName, "J", "J", 14)
 
-	// !isPrint
-	if !b.Content.IsPrint {
+	} else {
+		// 不是打印
 		endCell = fmt.Sprintf("G%d", b.Row)
 		marginLeft = excelize.PageMarginLeft(0.6)
 		b.Excel.SetColWidth(b.SheetName, "A", "B", 20)
 		b.Excel.SetColWidth(b.SheetName, "C", "F", 12)
 		b.Excel.SetColWidth(b.SheetName, "G", "G", 20)
-	}
+		// 是覆膜
+		if b.Content.IsLam {
+			endCell = fmt.Sprintf("I%d", b.Row)
+			marginLeft = excelize.PageMarginLeft(0.3)
+			b.Excel.SetColWidth(b.SheetName, "A", "A", 16)
+			b.Excel.SetColWidth(b.SheetName, "B", "C", 14)
+			// 覆膜规格
+			// b.Excel.SetColWidth(b.SheetName, "C", "C", 16)
+			b.Excel.SetColWidth(b.SheetName, "D", "D", 10)
+			b.Excel.SetColWidth(b.SheetName, "E", "F", 12)
+			b.Excel.SetColWidth(b.SheetName, "G", "H", 10)
+			b.Excel.SetColWidth(b.SheetName, "I", "I", 14)
+
+		}
 
-	// }
+	}
 
 	b.Excel.SetPageMargins(b.SheetName, marginLeft)
 
@@ -99,71 +99,6 @@ func (b *ProduceBillExcel) drawSubTitles() error {
 		return err
 	}
 
-	// var drawLeft = func(rowIndex int, value string) error {
-	// 	//左边1
-	// 	left1Cell := fmt.Sprintf("A%d", rowIndex)
-	// 	err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("F%d", rowIndex))
-	// 	if err != nil {
-	// 		return err
-	// 	}
-	// 	err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-	// 	if err != nil {
-	// 		return err
-	// 	}
-	// 	b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-	// 	return nil
-	// }
-
-	// var drawRight = func(rowIndex int, value string) error {
-	// 	right1Cell := fmt.Sprintf("G%d", rowIndex)
-	// 	err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("L%d", rowIndex))
-	// 	if err != nil {
-	// 		return err
-	// 	}
-	// 	err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
-	// 	if err != nil {
-	// 		return err
-	// 	}
-	// 	b.Excel.SetCellValue(b.SheetName, right1Cell, value)
-	// 	return nil
-	// }
-
-	// !isPrint
-	// if !b.Content.IsPrint {
-
-	// 	drawLeft = func(rowIndex int, value string) error {
-	// 		//左边1
-	// 		left1Cell := fmt.Sprintf("A%d", rowIndex)
-	// 		err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("E%d", rowIndex))
-	// 		if err != nil {
-	// 			return err
-	// 		}
-	// 		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-	// 		if err != nil {
-	// 			return err
-	// 		}
-	// 		b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-	// 		return nil
-	// 	}
-
-	// 	drawRight = func(rowIndex int, value string) error {
-	// 		right1Cell := fmt.Sprintf("F%d", rowIndex)
-	// 		err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("I%d", rowIndex))
-	// 		if err != nil {
-	// 			return err
-	// 		}
-	// 		err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
-	// 		if err != nil {
-	// 			return err
-	// 		}
-	// 		b.Excel.SetCellValue(b.SheetName, right1Cell, value)
-	// 		return nil
-	// 	}
-
-	// }
-
-	// !!isPdf
-	// if b.IsPdf == "true" {
 	drawLeft := func(rowIndex int, value string) error {
 		//左边1
 		left1Cell := fmt.Sprintf("A%d", rowIndex)
@@ -193,7 +128,6 @@ func (b *ProduceBillExcel) drawSubTitles() error {
 		return nil
 	}
 
-	// !isPrint
 	if !b.Content.IsPrint {
 		drawLeft = func(rowIndex int, value string) error {
 			//左边1
@@ -223,9 +157,38 @@ func (b *ProduceBillExcel) drawSubTitles() error {
 			b.Excel.SetCellValue(b.SheetName, right1Cell, value)
 			return nil
 		}
-	}
+		if b.Content.IsLam {
+			drawLeft = func(rowIndex int, value string) error {
+				//左边1
+				left1Cell := fmt.Sprintf("A%d", rowIndex)
+				err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("F%d", rowIndex))
+				if err != nil {
+					return err
+				}
+				err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
+				if err != nil {
+					return err
+				}
+				b.Excel.SetCellValue(b.SheetName, left1Cell, value)
+				return nil
+			}
+
+			drawRight = func(rowIndex int, value string) error {
+				right1Cell := fmt.Sprintf("G%d", rowIndex)
+				err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("I%d", rowIndex))
+				if err != nil {
+					return err
+				}
+				err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
+				if err != nil {
+					return err
+				}
+				b.Excel.SetCellValue(b.SheetName, right1Cell, value)
+				return nil
+			}
 
-	// }
+		}
+	}
 
 	//第一行
 	drawLeft(b.Row, "类别:"+b.Content.Type)
@@ -284,6 +247,34 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 		return nil
 	}
 
+	var drawCol3 = 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
+	}
+
+	unit := b.Content.Produces[0].Unit
 	if b.Content.IsPrint {
 		drawCol("A", "加工项目")
 		drawCol("B", "规格")
@@ -291,77 +282,35 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 		drawCol("D", "来纸尺寸")
 		drawCol("E", "印刷尺寸")
 		drawCol("F", "下单数量")
-		drawCol2("G", "单价", "元/张")
+		drawCol2("G", "单价", unit)
 		drawCol("H", "预算金额")
 		drawCol("I", "交货时间")
 		drawCol("J", "备注")
 
 	} else {
-		drawCol("A", "加工项目")
-		drawCol("B", "规格")
-		drawCol("C", "下单数量")
-		drawCol2("D", "单价", "元/张")
-		drawCol("E", "预算金额")
-		drawCol("F", "交货时间")
-		drawCol("G", "备注")
+		if b.Content.IsLam {
+			drawCol("A", "加工项目")
+			drawCol("B", "规格")
+			drawCol("C", "覆膜尺寸")
+			drawCol("D", "下单数量")
+			unit2 := b.Content.Produces[0].Unit2
+			drawCol3("E", "F", "单价", unit, unit2)
+			drawCol("G", "预算金额")
+			drawCol("H", "交货时间")
+			drawCol("I", "备注")
+
+		} else {
+			drawCol("A", "加工项目")
+			drawCol("B", "规格")
+			drawCol("C", "下单数量")
+			drawCol2("D", "单价", unit)
+			drawCol("E", "预算金额")
+			drawCol("F", "交货时间")
+			drawCol("G", "备注")
 
-	}
+		}
 
-	// // !isPrint
-	// if !b.Content.IsPrint {
-
-	// 	// !!isPdf
-	// 	if b.IsPdf == "true" {
-	// 		drawCol("A", "加工项目")
-	// 		drawCol("B", "规格")
-	// 		drawCol("C", "下单数量")
-	// 		drawCol2("D", "单价", "元/张")
-	// 		drawCol("E", "预算金额")
-	// 		drawCol("F", "交货时间")
-	// 		drawCol("G", "备注")
-	// 	} else {
-	// 		drawCol("A", "加工项目")
-	// 		drawCol("B", "规格")
-	// 		drawCol("C", "下单数量")
-	// 		drawCol("D", "完成数量")
-	// 		drawCol2("E", "单价", "元/张")
-	// 		drawCol("F", "预算金额")
-	// 		drawCol("G", "实际金额")
-	// 		drawCol("H", "交货时间")
-	// 		drawCol("I", "备注")
-	// 	}
-
-	// } else {
-	// 	// !!isPdf
-	// 	if b.IsPdf == "true" {
-	// 		drawCol("A", "加工项目")
-	// 		drawCol("B", "规格")
-	// 		drawCol("C", "纸张")
-	// 		drawCol("D", "来纸尺寸")
-	// 		drawCol("E", "印刷尺寸")
-	// 		drawCol("F", "下单数量")
-	// 		drawCol2("G", "单价", "元/张")
-	// 		drawCol("H", "预算金额")
-	// 		drawCol("I", "交货时间")
-	// 		drawCol("J", "备注")
-
-	// 	} else {
-	// 		drawCol("A", "加工项目")
-	// 		drawCol("B", "规格")
-	// 		drawCol("C", "纸张")
-	// 		drawCol("D", "来纸尺寸")
-	// 		drawCol("E", "印刷尺寸")
-	// 		drawCol("F", "下单数量")
-	// 		drawCol("G", "完成数量")
-	// 		drawCol2("H", "单价", "元/张")
-	// 		drawCol("I", "预算金额")
-	// 		drawCol("J", "实际金额")
-	// 		drawCol("K", "交货时间")
-	// 		drawCol("L", "备注")
-
-	// 	}
-
-	// }
+	}
 
 	return nil
 }
@@ -369,18 +318,14 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 func (b *ProduceBillExcel) drawTableContent() error {
 	b.Row += 2
 	var DrawRow = func(rowIndex int, values ...string) {
-		// charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
-		// // !isPrint
-		// if !b.Content.IsPrint {
-		// 	charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
-		// }
-
-		// !!isPdf
 		// if b.IsPdf == "true" {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}
 		// !isPrint
 		if !b.Content.IsPrint {
 			charas = []string{"A", "B", "C", "D", "E", "F", "G"}
+			if b.Content.IsLam {
+				charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
+			}
 		}
 
 		// }
@@ -421,30 +366,17 @@ func (b *ProduceBillExcel) drawTableContent() error {
 				DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
 
 			} else {
-				DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
+				// 覆膜
+				if b.Content.IsLam {
+					DrawRow(b.Row, produce.Name, produce.Norm, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, fmt.Sprintf("%.3f", produce.Price2), budgetAmount, deliveryTime, produce.Remark)
 
-			}
-			// !isPrint
-			// if !b.Content.IsPrint {
-			// 	// !!isPdf
-			// 	if b.IsPdf == "true" {
-			// 		DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
-
-			// 	} else {
-			// 		DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, budgetAmount, realPrice, deliveryTime, produce.Remark)
+				} else {
 
-			// 	}
+					DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
 
-			// } else {
-			// 	// !!isPdf
-			// 	if b.IsPdf == "true" {
-			// 		DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
-			// 	} else {
-			// 		DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, budgetAmount, realPrice, deliveryTime, produce.Remark)
+				}
 
-			// 	}
-
-			// }
+			}
 			b.Row++
 		}
 	}
@@ -466,19 +398,7 @@ func (b *ProduceBillExcel) drawTableFooter() error {
 	})
 
 	sendToStartCell := fmt.Sprintf("A%d", b.Row)
-	// sendToEndCell := fmt.Sprintf("G%d", b.Row)
-	// supplierStartCell := fmt.Sprintf("H%d", b.Row)
-	// supplierEndCell := fmt.Sprintf("L%d", b.Row)
-
-	// // !isPrint
-	// if !b.Content.IsPrint {
-	// 	sendToEndCell = fmt.Sprintf("F%d", b.Row)
-	// 	supplierStartCell = fmt.Sprintf("G%d", b.Row)
-	// 	supplierEndCell = fmt.Sprintf("I%d", b.Row)
-	// }
-
-	// !!isPdf
-	// if b.IsPdf == "true" {
+
 	sendToEndCell := fmt.Sprintf("E%d", b.Row)
 	supplierStartCell := fmt.Sprintf("F%d", b.Row)
 	supplierEndCell := fmt.Sprintf("J%d", b.Row)
@@ -487,9 +407,14 @@ func (b *ProduceBillExcel) drawTableFooter() error {
 		sendToEndCell = fmt.Sprintf("D%d", b.Row)
 		supplierStartCell = fmt.Sprintf("E%d", b.Row)
 		supplierEndCell = fmt.Sprintf("G%d", b.Row)
-	}
 
-	// }
+		if b.Content.IsLam {
+			sendToEndCell = fmt.Sprintf("F%d", b.Row)
+			supplierStartCell = fmt.Sprintf("G%d", b.Row)
+			supplierEndCell = fmt.Sprintf("I%d", b.Row)
+
+		}
+	}
 
 	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
 	b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
@@ -516,24 +441,6 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 	b.Excel.MergeCell(b.SheetName, billUserCellS, billUserCellE)
 	b.Excel.SetCellValue(b.SheetName, billUserCellS, "制单人:"+b.Content.UserName)
 
-	// fontNum := "H"
-	// image1s := "I"
-	// image2s := "K"
-	// image1e := "J"
-	// image2e := "L"
-
-	// // !isPrint
-	// if !b.Content.IsPrint {
-	// 	fontNum = "E"
-	// 	image1s = "F"
-	// 	image2s = "H"
-	// 	image1e = "G"
-	// 	image2e = "I"
-
-	// }
-
-	// !!isPdf
-	// if b.IsPdf == "true" {
 	fontNum := "F"
 	image1s := "G"
 	image2s := "I"
@@ -545,9 +452,15 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 		image2s = "G"
 		image1e = "F"
 		image2e = "G"
-	}
+		if b.Content.IsLam {
+			fontNum = "E"
+			image1s = "F"
+			image2s = "H"
+			image1e = "G"
+			image2e = "I"
 
-	// }
+		}
+	}
 
 	fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)
 	fontEndCell := fmt.Sprintf("%s%d", fontNum, b.Row+2)
@@ -620,10 +533,6 @@ func NewProduceBill(f *excelize.File) *ProduceBillExcel {
 		Signatures:       make([]*model.Signature, 0),
 	}
 
-	// f.SetColWidth(b.SheetName, "A", "A", 12)
-	// f.SetColWidth(b.SheetName, "B", "K", 9.5)
-	// // f.SetColWidth(b.SheetName, "I", "J", 8)
-	// f.SetColWidth(b.SheetName, "L", "L", 10)
 	f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
 
 	return b