animeic 1 year ago
parent
commit
46a33d89f5
2 changed files with 101 additions and 216 deletions
  1. 99 21
      boxcost/api/bill-produce-excel.go
  2. 2 195
      boxcost/api/plan.go

+ 99 - 21
boxcost/api/bill-produce-excel.go

@@ -93,15 +93,16 @@ func (b *ProduceBillExcel) drawTitle() error {
 
 	} else if b.Content.IsPaper {
 		// 是纸张类型
-		b.RowMap = map[string]int{"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7, "I": 8}
-		b.RowWidthArray = []float64{14, 14, 14, 12, 7, 12, 12, 12, 16}
-		endCell = fmt.Sprintf("I%d", b.Row)
-		marginLeft = excelize.PageMarginLeft(0.2)
-		b.Excel.SetColWidth(b.SheetName, "A", "C", 14)
-		b.Excel.SetColWidth(b.SheetName, "D", "D", 12)
-		b.Excel.SetColWidth(b.SheetName, "E", "E", 10)
-		b.Excel.SetColWidth(b.SheetName, "F", "H", 12)
-		b.Excel.SetColWidth(b.SheetName, "I", "I", 16)
+		b.RowMap = map[string]int{"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7, "I": 8, "J": 9, "K": 10}
+		b.RowWidthArray = []float64{11, 11, 11, 10, 10, 10, 8, 10, 9, 12, 14}
+		endCell = fmt.Sprintf("K%d", b.Row)
+		b.Excel.SetColWidth(b.SheetName, "A", "C", 11)
+		b.Excel.SetColWidth(b.SheetName, "D", "F", 10)
+		b.Excel.SetColWidth(b.SheetName, "G", "G", 8)
+		b.Excel.SetColWidth(b.SheetName, "H", "H", 10)
+		b.Excel.SetColWidth(b.SheetName, "I", "I", 11)
+		b.Excel.SetColWidth(b.SheetName, "J", "J", 12)
+		b.Excel.SetColWidth(b.SheetName, "K", "K", 14)
 
 	} else {
 		// 不是打印
@@ -247,7 +248,7 @@ func (b *ProduceBillExcel) drawSubTitles() error {
 			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:H"))})
 			return nil
 		}
-		if b.Content.IsLam || b.Content.IsPaper {
+		if b.Content.IsLam {
 			drawLeft = func(rowIndex int, value string) error {
 				//左边1
 				left1Cell := fmt.Sprintf("A%d", rowIndex)
@@ -297,6 +298,56 @@ func (b *ProduceBillExcel) drawSubTitles() error {
 			}
 
 		}
+		if b.Content.IsPaper {
+			drawLeft = func(rowIndex int, value string) error {
+				//左边1
+				left1Cell := fmt.Sprintf("A%d", rowIndex)
+				err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("H%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)
+				// 设置行高
+				b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:H"))})
+				return nil
+			}
+
+			drawRight = func(rowIndex int, value string) error {
+				right1Cell := fmt.Sprintf("I%d", rowIndex)
+				err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("K%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
+			}
+
+			drawLall = func(rowIndex int, value string) error {
+				//左边1
+				left1Cell := fmt.Sprintf("A%d", rowIndex)
+				err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("K%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)
+				// 设置行高
+				b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:K"))})
+				return nil
+			}
+
+		}
 	}
 
 	//第一行
@@ -399,13 +450,15 @@ func (b *ProduceBillExcel) drawTableTitle() error {
 	} else if b.Content.IsPaper {
 		drawCol("A", "加工项目")
 		drawCol("B", "规格")
-		drawCol("C", "来纸尺寸")
-		drawCol("D", "下单数量")
-		drawCol("E", "单位")
-		drawCol("F", "单价")
-		drawCol("G", "预算金额")
-		drawCol("H", "交货时间")
-		drawCol("I", "备注")
+		drawCol("C", "纸张")
+		drawCol("D", "来纸数量")
+		drawCol("E", "来纸尺寸")
+		drawCol("F", "下单数量")
+		drawCol("G", "单位")
+		drawCol("H", "单价")
+		drawCol("I", "预算金额")
+		drawCol("J", "交货时间")
+		drawCol("K", "备注")
 	} else {
 		drawCol("A", "加工项目")
 		drawCol("B", "规格")
@@ -427,9 +480,12 @@ func (b *ProduceBillExcel) drawTableContent() error {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
 		if !b.Content.IsPrint {
 			charas = []string{"A", "B", "C", "D", "E", "F", "G", "H"}
-			if b.Content.IsLam || b.Content.IsPaper {
+			if b.Content.IsLam {
 				charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
 			}
+			if b.Content.IsPaper {
+				charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"}
+			}
 		}
 		// 获取改行最大行高
 		max := getRowHeight(values[0], b.getRangeWidth(charas[0]))
@@ -481,7 +537,7 @@ func (b *ProduceBillExcel) drawTableContent() error {
 
 			} else if b.Content.IsPaper {
 				// 对裱
-				rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, produce.PaperSize, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
+				rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, paperCount, produce.PaperSize, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
 			} else {
 				rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
 			}
@@ -519,13 +575,20 @@ func (b *ProduceBillExcel) drawTableFooter() error {
 		supplierEndCell = fmt.Sprintf("H%d", b.Row)
 		b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:E"))})
 
-		if b.Content.IsLam || b.Content.IsPaper {
+		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.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:F"))})
 
 		}
+		if b.Content.IsPaper {
+			sendToEndCell = fmt.Sprintf("H%d", b.Row)
+			supplierStartCell = fmt.Sprintf("I%d", b.Row)
+			supplierEndCell = fmt.Sprintf("K%d", b.Row)
+			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:K"))})
+
+		}
 	}
 
 	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
@@ -567,6 +630,12 @@ func (b *ProduceBillExcel) drawSupplierRemark() error {
 			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:I"))})
 
 		}
+		if b.Content.IsPaper {
+			sendToEndCell = fmt.Sprintf("K%d", b.Row)
+			// 设置行高
+			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:K"))})
+
+		}
 	}
 
 	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
@@ -603,7 +672,7 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 		image2s = "H"
 		image1e = "G"
 		image2e = "H"
-		if b.Content.IsLam || b.Content.IsPaper {
+		if b.Content.IsLam {
 			fontNum = "E"
 			fontENum = "E"
 			image1s = "F"
@@ -612,6 +681,15 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 			image2e = "I"
 
 		}
+		if b.Content.IsPaper {
+			fontNum = "G"
+			fontENum = "G"
+			image1s = "H"
+			image2s = "J"
+			image1e = "I"
+			image2e = "K"
+
+		}
 	}
 
 	fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)

+ 2 - 195
boxcost/api/plan.go

@@ -855,161 +855,6 @@ func toPdfAndSaveTask(buf *bytes.Buffer, toPdfAddr, saveTmpDir, targetPdfName st
 	wg.Done()
 }
 
-// todo 已弃用 功能稳定后删除
-func DownLoadCompBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_planId := c.Query("id")
-	compId := c.Query("compId")
-	planId, err := primitive.ObjectIDFromHex(_planId)
-	if err != nil {
-		return nil, errors.New("planId错误")
-	}
-	plan := model.ProductPlan{}
-	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionProductPlan,
-		Query:       repo.Map{"_id": planId},
-	}, &plan)
-	if !found || err != nil {
-		return nil, errors.New("数据未找到")
-	}
-	// 获取部件单据
-	curComp := &model.PackComponent{}
-	for _, comp := range plan.Pack.Components {
-		if comp.Id == compId {
-			curComp = comp
-		}
-	}
-	if curComp.Id == "" {
-		return nil, errors.New("该组件不存在")
-	}
-
-	// 获取bill
-	if len(curComp.Stages) == 0 {
-		return nil, errors.New("该组件数据不存在")
-	}
-
-	// 获取不同类型的单据id
-	billIds := make([]string, 0)
-	for _, stage := range curComp.Stages {
-		billId, _ := primitive.ObjectIDFromHex(stage.BillId)
-		if !billId.IsZero() {
-			billIds = append(billIds, fmt.Sprintf("%d_%s", stage.BillType, stage.BillId))
-		}
-	}
-
-	// 去重单据号
-	typeBillIds := removeDuplicationSort(billIds)
-	if len(typeBillIds) < 1 {
-		return nil, errors.New("未找到单据信息")
-	}
-	f := excelize.NewFile()
-	index := f.NewSheet("Sheet1")
-	f.SetActiveSheet(index)
-	f.SetDefaultFont("宋体")
-	companyName := getCompanyName(apictx)
-
-	row := 0
-	for _, tId := range typeBillIds {
-		tidArr := strings.Split(tId, "_")
-
-		var billExcel IExcel
-		// 采购
-		billId, _ := primitive.ObjectIDFromHex(tidArr[1])
-		if tidArr[0] == "1" {
-			purchase := model.PurchaseBill{}
-			found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-				CollectName: repo.CollectionBillPurchase,
-				Query:       repo.Map{"_id": billId},
-			}, &purchase)
-			if found {
-				billExcel = NewPurchaseBill(f)
-				if purchase.Reviewed == 1 {
-					if len(purchase.SignUsers) > 0 {
-						signs := []*model.Signature{}
-						repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-							CollectName: repo.CollectionSignature,
-							Query:       repo.Map{"_id": bson.M{"$in": purchase.SignUsers}},
-							Sort:        bson.M{"sort": 1},
-						}, &signs)
-						billExcel.SetSignatures(signs)
-					}
-
-				}
-				billExcel.SetContent(&purchase)
-				billExcel.SetTitle(fmt.Sprintf("%s原材料采购单", companyName))
-			}
-
-		}
-		// 工艺
-		if tidArr[0] == "2" {
-			produce := model.ProduceBill{}
-			found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-				CollectName: repo.CollectionBillProduce,
-				Query:       repo.Map{"_id": billId},
-			}, &produce)
-			if found {
-				billExcel = NewProduceBill(f)
-				if produce.Reviewed == 1 {
-					if len(produce.SignUsers) > 0 {
-						signs := []*model.Signature{}
-						repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-							CollectName: repo.CollectionSignature,
-							Query:       repo.Map{"_id": bson.M{"$in": produce.SignUsers}},
-							Sort:        bson.M{"sort": 1},
-						}, &signs)
-						billExcel.SetSignatures(signs)
-					}
-
-				}
-				billExcel.SetContent(&produce)
-				billExcel.SetTitle(fmt.Sprintf("%s加工单", companyName))
-			}
-
-		}
-		// 成品采购
-		if tidArr[0] == "3" {
-			product := model.ProductBill{}
-			found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-				CollectName: repo.CollectionBillProduct,
-				Query:       repo.Map{"_id": billId},
-			}, &product)
-			if found {
-				billExcel = NewProductBill(f)
-				if product.Reviewed == 1 {
-					if len(product.SignUsers) > 0 {
-						signs := []*model.Signature{}
-						repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-							CollectName: repo.CollectionSignature,
-							Query:       repo.Map{"_id": bson.M{"$in": product.SignUsers}},
-							Sort:        bson.M{"sort": 1},
-						}, &signs)
-						billExcel.SetSignatures(signs)
-					}
-
-				}
-				billExcel.SetContent(&product)
-				billExcel.SetTitle(companyName)
-			}
-		}
-		if billExcel == nil {
-			continue
-		}
-		billExcel.SetRow(row)
-		billExcel.Draws()
-		row = billExcel.GetRow() + 5
-	}
-
-	c.Header("Content-Type", "application/octet-stream")
-	c.Header("Content-Disposition", "attachment; filename="+"bill.xlsx")
-	c.Header("Content-Transfer-Encoding", "binary")
-
-	err = f.Write(c.Writer)
-	if err != nil {
-		return nil, err
-	}
-
-	return nil, nil
-}
-
 // 创建生产计划
 func CreateProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
@@ -1055,13 +900,6 @@ func GetProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return nil, errors.New("数据未找到")
 	}
 
-	billStates := map[string]string{}
-	billSerialNumber := map[string]string{}
-	billSendTo := map[string]string{}
-	billIsSend := map[string]bool{}
-	billReviewed := map[string]int32{}
-	billIsAck := map[string]bool{}
-
 	billData := map[string]interface{}{}
 	if plan.Pack != nil && plan.Pack.Components != nil {
 		for _, comp := range plan.Pack.Components {
@@ -1091,31 +929,6 @@ func GetProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 						if ok {
 							billData[stage.BillId] = state
 
-							// TODO 订单数据合并到billData中,修改上线时删除下面的代码。
-							billStates[stage.BillId] = state["status"].(string)
-							billSerialNumber[stage.BillId] = state["serialNumber"].(string)
-							if v, ok := state["sendTo"]; ok {
-								billSendTo[stage.BillId] = v.(string)
-							}
-
-							if v, ok := state["isSend"]; ok {
-								billIsSend[stage.BillId] = v.(bool)
-
-							} else {
-								billIsSend[stage.BillId] = false
-							}
-							if v, ok := state["reviewed"]; ok {
-								billReviewed[stage.BillId] = v.(int32)
-							} else {
-								billReviewed[stage.BillId] = -1
-							}
-							if v, ok := state["isAck"]; ok {
-								billIsAck[stage.BillId] = v.(bool)
-
-							} else {
-								billIsAck[stage.BillId] = false
-							}
-
 						}
 					}
 
@@ -1125,14 +938,8 @@ func GetProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 
 	return map[string]interface{}{
-		"plan":             plan,
-		"billStates":       billStates,
-		"billIsSend":       billIsSend,
-		"billReviewed":     billReviewed,
-		"billIsAck":        billIsAck,
-		"billSerialNumber": billSerialNumber,
-		"billSendTo":       billSendTo,
-		"billData":         billData,
+		"plan":     plan,
+		"billData": billData,
 	}, nil
 }