animeic 2 năm trước cách đây
mục cha
commit
53ea768565

+ 197 - 32
boxcost/api/bill-produce-excel.go

@@ -21,6 +21,8 @@ type ProduceBillExcel struct {
 
 	Content    *model.ProduceBill
 	Signatures []*model.Signature
+
+	IsPdf string
 }
 
 func (b *ProduceBillExcel) drawTitle() error {
@@ -37,6 +39,29 @@ func (b *ProduceBillExcel) drawTitle() error {
 		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)
+		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)
+
+		// !isPrint
+		if !b.Content.IsPrint {
+			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)
+		}
+
+	}
+
 	b.Excel.SetPageMargins(b.SheetName, marginLeft)
 
 	err := b.Excel.MergeCell(b.SheetName, startCell, endCell)
@@ -137,6 +162,71 @@ func (b *ProduceBillExcel) drawSubTitles() error {
 
 	}
 
+	// !!isPdf
+	if b.IsPdf == "true" {
+		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("J%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("B%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("C%d", rowIndex)
+				err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("G%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)
 	drawRight(b.Row, "单号:"+b.Content.SerialNumber)
@@ -193,31 +283,60 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 		b.Excel.SetCellValue(b.SheetName, left2Cell, value2)
 		return nil
 	}
+
 	// !isPrint
 	if !b.Content.IsPrint {
-		drawCol("A", "加工项目")
-		drawCol("B", "规格")
-		drawCol("C", "下单数量")
-		drawCol("D", "完成数量")
-		drawCol2("E", "单价", "元/张")
-		drawCol("F", "预算金额")
-		drawCol("G", "实际金额")
-		drawCol("H", "交货时间")
-		drawCol("I", "备注")
+		// !!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 {
-		drawCol("A", "加工项目")
-		drawCol("B", "规格")
-		drawCol("C", "纸张")
-		drawCol("D", "来纸尺寸")
-		drawCol("E", "印刷尺寸")
-		drawCol("F", "下单数量")
-		drawCol("G", "完成数量")
-		drawCol2("H", "单价", "元/张")
-		drawCol("I", "预算金额")
-		drawCol("J", "实际金额")
-		drawCol("K", "交货时间")
-		drawCol("L", "备注")
+		// !!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
@@ -231,6 +350,16 @@ func (b *ProduceBillExcel) drawTableContent() error {
 		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"}
+			}
+
+		}
 		for i, c := range charas {
 			v := ""
 			if i < len(values) {
@@ -264,12 +393,25 @@ func (b *ProduceBillExcel) drawTableContent() error {
 
 			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
 
-			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)
 			// !isPrint
 			if !b.Content.IsPrint {
-				DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, budgetAmount, realPrice, deliveryTime, produce.Remark)
+				// !!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, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, budgetAmount, realPrice, deliveryTime, produce.Remark)
+				// !!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++
@@ -302,8 +444,22 @@ func (b *ProduceBillExcel) drawTableFooter() error {
 		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)
+		// !isPrint
+		if !b.Content.IsPrint {
+			sendToEndCell = fmt.Sprintf("D%d", b.Row)
+			supplierStartCell = fmt.Sprintf("E%d", b.Row)
+			supplierEndCell = fmt.Sprintf("G%d", b.Row)
+		}
 
 	}
+
 	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
 	b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
 	b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
@@ -323,16 +479,8 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 		// Border:    border,
 	})
 
-	style2, _ := b.Excel.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
-		// Border:    border,
-	})
-
 	// 制单人
 	billUserCell := fmt.Sprintf("A%d", b.Row+1)
-	billUservCell := fmt.Sprintf("B%d", b.Row+1)
-	b.Excel.MergeCell(b.SheetName, billUserCell, billUservCell)
-	b.Excel.SetCellStyle(b.SheetName, billUserCell, billUservCell, style2)
 	b.Excel.SetCellValue(b.SheetName, billUserCell, "制单人:"+b.Content.UserName)
 
 	fontNum := "H"
@@ -351,6 +499,23 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 
 	}
 
+	// !!isPdf
+	if b.IsPdf == "true" {
+		fontNum = "F"
+		image1s = "G"
+		image2s = "I"
+		image1e = "H"
+		image2e = "J"
+		if !b.Content.IsPrint {
+			fontNum = "D"
+			image1s = "E"
+			image2s = "G"
+			image1e = "F"
+			image2e = "G"
+		}
+
+	}
+
 	fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)
 	fontEndCell := fmt.Sprintf("%s%d", fontNum, b.Row+2)
 

+ 1 - 0
boxcost/api/bill-produce.go

@@ -276,6 +276,7 @@ func DownProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	}
 	billExcel.Content = &bill
+	billExcel.IsPdf = isPdf
 	companyName := getCompanyName(apictx)
 	billExcel.Title = fmt.Sprintf("%s加工单", companyName)
 	//设置对应的数据

+ 137 - 29
boxcost/api/bill-product-excel.go

@@ -27,12 +27,26 @@ type ProductBillExcel struct {
 	Content *model.ProductBill
 
 	Signatures []*model.Signature
+
+	IsPdf string
 }
 
 func (b *ProductBillExcel) drawTitle() error {
 	b.Row++
 	startCell := fmt.Sprintf("A%d", b.Row)
-	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("J%d", b.Row))
+	endCell := fmt.Sprintf("J%d", b.Row)
+	marginLeft := excelize.PageMarginLeft(0.2)
+	// !!isPdf
+	if b.IsPdf == "true" {
+		endCell = fmt.Sprintf("H%d", b.Row)
+		marginLeft = excelize.PageMarginLeft(0.6)
+		b.Excel.SetColWidth(b.SheetName, "A", "A", 18)
+		b.Excel.SetColWidth(b.SheetName, "B", "B", 14)
+		b.Excel.SetColWidth(b.SheetName, "C", "G", 12)
+		b.Excel.SetColWidth(b.SheetName, "H", "H", 18)
+	}
+	b.Excel.SetPageMargins(b.SheetName, marginLeft)
+	err := b.Excel.MergeCell(b.SheetName, startCell, endCell)
 	if err != nil {
 		return err
 	}
@@ -95,6 +109,40 @@ func (b *ProductBillExcel) drawSubTitles() error {
 		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)
+			err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("D%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("E%d", rowIndex)
+			err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("H%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.Title+"订单")
 	drawRight(b.Row, "单号:"+b.Content.SerialNumber)
@@ -139,17 +187,29 @@ func (b *ProductBillExcel) drawTableTitle() error {
 
 		return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
 	}
-	// a采购项目 b规格 c下单数量 d单位 e完成数量 f单价 g预算金额 h实际金额 i交货时间 j备注
-	drawCol("A", "采购项目")
-	drawCol("B", "规格")
-	drawCol("C", "下单数量")
-	drawCol("D", "单位")
-	drawCol("E", "完成数量")
-	drawCol("F", "单价")
-	drawCol("G", "预算金额")
-	drawCol("H", "实际金额")
-	drawCol("I", "交货时间")
-	drawCol("J", "备注")
+
+	// !!isPdf
+	if b.IsPdf == "true" {
+		drawCol("A", "采购项目")
+		drawCol("B", "规格")
+		drawCol("C", "下单数量")
+		drawCol("D", "单位")
+		drawCol("E", "单价")
+		drawCol("F", "预算金额")
+		drawCol("G", "交货时间")
+		drawCol("H", "备注")
+	} else {
+		drawCol("A", "采购项目")
+		drawCol("B", "规格")
+		drawCol("C", "下单数量")
+		drawCol("D", "单位")
+		drawCol("E", "完成数量")
+		drawCol("F", "单价")
+		drawCol("G", "预算金额")
+		drawCol("H", "实际金额")
+		drawCol("I", "交货时间")
+		drawCol("J", "备注")
+	}
 
 	return nil
 }
@@ -159,6 +219,10 @@ func (b *ProductBillExcel) drawTableContent() error {
 
 	var DrawRow = func(rowIndex int, values ...string) {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}
+		// !!isPdf
+		if b.IsPdf == "true" {
+			charas = []string{"A", "B", "C", "D", "E", "F", "G", "H"}
+		}
 		for i, c := range charas {
 			v := ""
 			if i < len(values) {
@@ -193,7 +257,14 @@ func (b *ProductBillExcel) drawTableContent() error {
 			orderCount := fmt.Sprintf("%d", product.OrderCount)
 			price := fmt.Sprintf("%.3f", product.OrderPrice)
 			b.FormatToEmpty(&price)
-			DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, realCount, price, budgetAmount, realPrice, deliveryTime, product.Remark)
+
+			// !!isPdf
+			if b.IsPdf == "true" {
+				DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, price, budgetAmount, deliveryTime, product.Remark)
+			} else {
+				DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, realCount, price, budgetAmount, realPrice, deliveryTime, product.Remark)
+			}
+
 			b.Row++
 		}
 	}
@@ -214,24 +285,26 @@ func (b *ProductBillExcel) drawTableFooter() error {
 		Border:    border,
 	})
 
-	// b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-	// b.Excel.SetCellValue(b.SheetName, left1Cell, "送货地址:")
-
-	addCel := fmt.Sprintf("A%d", b.Row)
+	sendToStartCell := fmt.Sprintf("A%d", b.Row)
+	sendToEndCell := fmt.Sprintf("G%d", b.Row)
+	supplierStartCell := fmt.Sprintf("H%d", b.Row)
+	supplierEndCell := fmt.Sprintf("J%d", b.Row)
 
-	b.Excel.MergeCell(b.SheetName, addCel, fmt.Sprintf("G%d", b.Row))
-	b.Excel.SetCellStyle(b.SheetName, addCel, fmt.Sprintf("G%d", b.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)
+	// !!isPdf
+	if b.IsPdf == "true" {
+		sendToEndCell = fmt.Sprintf("E%d", b.Row)
+		supplierStartCell = fmt.Sprintf("F%d", b.Row)
+		supplierEndCell = fmt.Sprintf("H%d", b.Row)
 
-	// sureCel := fmt.Sprintf("F%d", b.Row)
-	sureCel := fmt.Sprintf("H%d", b.Row)
-	b.Excel.MergeCell(b.SheetName, sureCel, fmt.Sprintf("J%d", b.Row))
-	b.Excel.SetCellStyle(b.SheetName, sureCel, fmt.Sprintf("J%d", b.Row), styleLeft)
-	b.Excel.SetCellValue(b.SheetName, sureCel, " 收货人:")
+	}
 
-	b.Excel.SetRowHeight(b.SheetName, b.Row, 30)
+	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
+	b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
+	b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
+	b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
+	b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
+	b.Excel.SetCellValue(b.SheetName, supplierStartCell, " 收货人:")
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
 
 	return nil
 }
@@ -249,6 +322,10 @@ func (b *ProductBillExcel) drawRemark() error {
 	remarkRowNum := len(reg.FindAllString(b.Content.Remark, -1)) + 1
 	b.Row += remarkRowNum
 	remarkContentEcell := fmt.Sprintf("J%d", b.Row)
+	// !!isPdf
+	if b.IsPdf == "true" {
+		remarkContentEcell = fmt.Sprintf("H%d", b.Row)
+	}
 	b.Excel.MergeCell(b.SheetName, remarkContentScell, remarkContentEcell)
 	b.Excel.SetCellValue(b.SheetName, remarkContentScell, b.Content.Remark)
 
@@ -289,6 +366,38 @@ func (b *ProductBillExcel) drawRemark() error {
 		return nil
 	}
 
+	// !!isPdf
+	if b.IsPdf == "true" {
+		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("H%d", rowIndex))
+			if err != nil {
+				return err
+			}
+			err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleLeft)
+			if err != nil {
+				return err
+			}
+			b.Excel.SetCellValue(b.SheetName, right1Cell, value)
+			return nil
+		}
+	}
+
 	//第一行
 	drawLeft(b.Row, "甲方:"+b.Title)
 	drawRight(b.Row, "乙方:"+b.Content.Supplier)
@@ -396,7 +505,6 @@ func NewProductBill(f *excelize.File) *ProductBillExcel {
 		Signatures:       make([]*model.Signature, 0),
 	}
 
-	// f.SetColWidth(b.SheetName, "A", "J", 11.5)
 	f.SetColWidth(b.SheetName, "A", "A", 17)
 	f.SetColWidth(b.SheetName, "B", "B", 12)
 	f.SetColWidth(b.SheetName, "C", "H", 10.5)

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

@@ -280,6 +280,7 @@ func DownProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	}
 	billExcel.Content = &bill
+	billExcel.IsPdf = isPdf
 	billExcel.Title = getCompanyName(apictx)
 	//设置对应的数据
 	billExcel.Draws()

+ 130 - 52
boxcost/api/bill-purchase-excel.go

@@ -27,14 +27,25 @@ type PurchaseBillExcel struct {
 	Content *model.PurchaseBill
 
 	Signatures []*model.Signature
+	IsPdf      string
 }
 
 func (b *PurchaseBillExcel) drawTitle() error {
 	marginLeft := excelize.PageMarginLeft(0.15)
-	b.Excel.SetPageMargins(b.SheetName, marginLeft)
+
 	b.Row++
 	startCell := fmt.Sprintf("A%d", b.Row)
-	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("L%d", b.Row))
+	endCell := fmt.Sprintf("L%d", b.Row)
+	// !!isPdf
+	if b.IsPdf == "true" {
+		endCell = fmt.Sprintf("J%d", b.Row)
+		marginLeft = excelize.PageMarginLeft(0.2)
+		b.Excel.SetColWidth(b.SheetName, "A", "B", 14)
+		b.Excel.SetColWidth(b.SheetName, "C", "I", 10.5)
+		b.Excel.SetColWidth(b.SheetName, "J", "J", 14)
+	}
+	b.Excel.SetPageMargins(b.SheetName, marginLeft)
+	err := b.Excel.MergeCell(b.SheetName, startCell, endCell)
 	if err != nil {
 		return err
 	}
@@ -97,6 +108,41 @@ func (b *PurchaseBillExcel) drawSubTitles() error {
 		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)
+			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("J%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)
 	drawRight(b.Row, "单号:"+b.Content.SerialNumber)
@@ -168,18 +214,9 @@ func (b *PurchaseBillExcel) drawTableTitle() error {
 		b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
 		return nil
 	}
-
-	drawCol("A", "采购项目")
-	drawCol("B", "规格(克)")
-
-	drawCol("E", "下单数量")
-	drawCol("F", "完成数量")
-
-	drawCol2("C", "D", "尺寸(mm)", "长", "宽")
-	drawCol2("C", "D", "尺寸(mm)", "长", "宽")
+	// ??? for ragne
 	unit1 := "-"
 	unit2 := "-"
-	// ??? for ragne
 	if len(b.Content.Paper) > 0 {
 		if b.Content.Paper[0].PriceUnit != "" {
 			unit1 = b.Content.Paper[0].PriceUnit
@@ -195,11 +232,31 @@ func (b *PurchaseBillExcel) drawTableTitle() error {
 		}
 	}
 
-	drawCol2("G", "H", "单价", unit1, unit2)
-	drawCol("I", "预算金额")
-	drawCol("J", "实际金额")
-	drawCol("K", "交货时间")
-	drawCol("L", "备注")
+	// !!isPdf
+	if b.IsPdf == "true" {
+		drawCol("A", "采购项目")
+		drawCol("B", "规格(克)")
+		drawCol2("C", "D", "尺寸(mm)", "长", "宽")
+		drawCol2("C", "D", "尺寸(mm)", "长", "宽")
+		drawCol("E", "下单数量")
+		drawCol2("F", "G", "单价", unit1, unit2)
+		drawCol("H", "预算金额")
+		drawCol("I", "交货时间")
+		drawCol("J", "备注")
+
+	} else {
+		drawCol("A", "采购项目")
+		drawCol("B", "规格(克)")
+		drawCol("E", "下单数量")
+		drawCol("F", "完成数量")
+		drawCol2("C", "D", "尺寸(mm)", "长", "宽")
+		drawCol2("C", "D", "尺寸(mm)", "长", "宽")
+		drawCol2("G", "H", "单价", unit1, unit2)
+		drawCol("I", "预算金额")
+		drawCol("J", "实际金额")
+		drawCol("K", "交货时间")
+		drawCol("L", "备注")
+	}
 
 	return nil
 }
@@ -209,6 +266,10 @@ func (b *PurchaseBillExcel) drawTableContent() error {
 
 	var DrawRow = func(rowIndex int, values ...string) {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
+		// !!isPdf
+		if b.IsPdf == "true" {
+			charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}
+		}
 		for i, c := range charas {
 			v := ""
 			if i < len(values) {
@@ -242,8 +303,14 @@ func (b *PurchaseBillExcel) drawTableContent() error {
 			// 实际金额
 			realPrice = fmt.Sprintf("%.3f", paper.OrderPrice*float64(paper.ConfirmCount))
 			b.FormatToEmpty(&realPrice)
+			// !!isPdf
+			if b.IsPdf == "true" {
+				DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), price, price2, budgetAmount, deliveryTime, paper.Remark)
+			} else {
+				DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), realCount, price, price2, budgetAmount, realPrice, deliveryTime, paper.Remark)
+
+			}
 
-			DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), realCount, price, price2, budgetAmount, realPrice, deliveryTime, paper.Remark)
 			b.Row++
 		}
 	}
@@ -252,8 +319,6 @@ func (b *PurchaseBillExcel) drawTableContent() error {
 }
 
 func (b *PurchaseBillExcel) drawTableFooter() error {
-	row := b.Row
-
 	border := []excelize.Border{
 		{Type: "top", Style: 1, Color: "000000"},
 		{Type: "left", Style: 1, Color: "000000"},
@@ -266,17 +331,25 @@ func (b *PurchaseBillExcel) drawTableFooter() error {
 		Border:    border,
 	})
 
-	addCel := fmt.Sprintf("A%d", row)
-	b.Excel.MergeCell(b.SheetName, addCel, fmt.Sprintf("G%d", row))
-	b.Excel.SetCellStyle(b.SheetName, addCel, fmt.Sprintf("G%d", row), styleLeft)
-	b.Excel.SetCellValue(b.SheetName, addCel, "送货地址:"+b.Content.SendTo)
+	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)
 
-	sureCel := fmt.Sprintf("H%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)
-	b.Excel.SetCellValue(b.SheetName, sureCel, "供应商签字:")
+	// !!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)
 
-	b.Excel.SetRowHeight(b.SheetName, row, 21)
+	}
+	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
+	b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
+	b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
+	b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
+	b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
+	b.Excel.SetCellValue(b.SheetName, supplierStartCell, "供应商签字:")
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
 
 	return nil
 }
@@ -292,36 +365,46 @@ func (b *PurchaseBillExcel) drawTableSignature() error {
 	// 制单人
 	billUserCell := fmt.Sprintf("A%d", b.Row+1)
 	b.Excel.SetCellValue(b.SheetName, billUserCell, "制单人:"+b.Content.UserName)
-	// billUservCell := fmt.Sprintf("B%d", b.Row+1)
-	// b.Excel.SetCellValue(b.SheetName, billUservCell, b.Content.UserName)
 
-	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))
+	fontNum := "H"
+	image1s := "I"
+	image2s := "K"
+	image1e := "J"
+	image2e := "L"
+
+	// !!isPdf
+	if b.IsPdf == "true" {
+		fontNum = "F"
+		image1s = "G"
+		image2s = "I"
+		image1e = "H"
+		image2e = "J"
+
+	}
+
+	fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)
+	fontEndCell := fmt.Sprintf("%s%d", fontNum, b.Row+2)
+
+	imageCell1 := fmt.Sprintf("%s%d", image1s, b.Row)
+	imageEndCell1 := fmt.Sprintf("%s%d", image1e, b.Row+2)
+
+	imageCell2 := fmt.Sprintf("%s%d", image2s, b.Row)
+	imageEndCell2 := fmt.Sprintf("%s%d", image2e, b.Row+2)
+
+	b.Excel.MergeCell(b.SheetName, fontCell, fontEndCell)
 	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", b.Row+2))
+	b.Excel.MergeCell(b.SheetName, imageCell1, imageEndCell1)
 	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", b.Row+2))
+	b.Excel.MergeCell(b.SheetName, imageCell2, imageEndCell2)
 	b.Excel.SetCellStyle(b.SheetName, imageCell2, imageCell1, style1)
 	b.Excel.SetCellValue(b.SheetName, imageCell2, "")
 
-	// 状态为已审核时,签字
-	// `{
-	// 	"x_scale": 0.12,
-	// 	"y_scale": 0.12,
-	// 	"x_offset": 30,
-	// 	"print_obj": true,
-	// 	"lock_aspect_ratio": false,
-	// 	"locked": false,
-	// 	"positioning": "oncell"
-	// }`
 	if b.Content.Reviewed == 1 {
 		imageCells := []string{imageCell1, imageCell2}
 		if len(b.Signatures) > 0 {
@@ -370,14 +453,9 @@ func NewPurchaseBill(f *excelize.File) *PurchaseBillExcel {
 		Signatures:       make([]*model.Signature, 0),
 	}
 
-	// f.SetColWidth(b.SheetName, "A", "A", 12)
-	// f.SetColWidth(b.SheetName, "B", "K", 9.5)
-	// f.SetColWidth(b.SheetName, "L", "L", 10)
-
 	f.SetColWidth(b.SheetName, "A", "A", 15)
 	f.SetColWidth(b.SheetName, "B", "B", 15)
 	f.SetColWidth(b.SheetName, "C", "G", 7)
-	// f.SetColWidth(b.SheetName, "C", "H", 9.5)
 	f.SetColWidth(b.SheetName, "H", "K", 10)
 	f.SetColWidth(b.SheetName, "L", "L", 11)
 	f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))

+ 1 - 0
boxcost/api/bill.go

@@ -247,6 +247,7 @@ func DownLoadBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	}
 	billExcel.Content = &bill
+	billExcel.IsPdf = isPdf
 	companyName := getCompanyName(apictx)
 	billExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
 

+ 1 - 1
boxcost/api/plan.go

@@ -34,7 +34,7 @@ func ProductPlan(r *GinRouter) {
 	r.POST("/plan/delete/:id", DelProductPlan)
 
 	// 下载部件单据
-	r.GET("/bill/plan/download", DownLoadCompBills)
+	// r.GET("/bill/plan/download", DownLoadCompBills)
 	r.GET("/bill/plan/download", DownLoadPlanBills)
 
 	// 生产成本表