animeic 2 years ago
parent
commit
3aec59fda1
6 changed files with 107 additions and 2 deletions
  1. BIN
      boxcost/__debug_bin
  2. 0 1
      boxcost/api/bill.go
  3. 99 0
      boxcost/api/report.go
  4. 4 0
      boxcost/boxcost.log
  5. 1 1
      boxcost/db/db.go
  6. 3 0
      boxcost/db/model/bill.go

BIN
boxcost/__debug_bin


+ 0 - 1
boxcost/api/bill.go

@@ -220,7 +220,6 @@ func DownLoadBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 
 	f := excelize.NewFile()
-	// Create a new sheet.
 	index := f.NewSheet("Sheet1")
 	f.SetActiveSheet(index)
 	f.SetDefaultFont("宋体")

+ 99 - 0
boxcost/api/report.go

@@ -16,6 +16,7 @@ func Report(r *GinRouter) {
 	r.GET("/report/produce/list", ReportProduceList)
 	// 采购列表
 	r.GET("/report/purchase/list", ReportPurchaseList)
+	r.GET("/report/product/list", ReportPorductList)
 	r.GET("/report/produce/download", ReportProduceDownload)
 	r.GET("/report/purchase/download", ReportPurchaseDownload)
 }
@@ -46,6 +47,17 @@ func ReportPurchaseList(c *gin.Context, apictx *ApiSession) (interface{}, error)
 
 }
 
+func ReportPorductList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	page, size, query := UtilQueryPageSize(c)
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionBillProduct,
+		Query:       handleReportQuery(query),
+		Page:        page,
+		Size:        size,
+	})
+
+}
+
 func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_, _, query := UtilQueryPageSize(c)
 	// 获取采符合条件的信息
@@ -221,3 +233,90 @@ func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, er
 	}
 	return nil, nil
 }
+
+func ReportProductDownload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_, _, query := UtilQueryPageSize(c)
+	// 获取采符合条件的信息
+	products := []*model.ProductBill{}
+
+	err := repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionBillProduct,
+		Query:       handleReportQuery(query),
+	}, &products)
+	if err != nil || len(products) < 1 {
+		return nil, errors.New("数据不存在")
+	}
+	f := excelize.NewFile()
+	index := f.NewSheet("Sheet1")
+	sheetName := f.GetSheetName(index)
+	f.SetActiveSheet(index)
+	f.SetDefaultFont("宋体")
+
+	border := []excelize.Border{
+		{Type: "top", Style: 1, Color: "000000"},
+		{Type: "left", Style: 1, Color: "000000"},
+		{Type: "right", Style: 1, Color: "000000"},
+		{Type: "bottom", Style: 1, Color: "000000"},
+	}
+	alignCenterStyle, _ := f.NewStyle(&excelize.Style{
+		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
+		Border:    border,
+	})
+	offset := 0
+	companyName := getCompanyName(apictx)
+
+	var budgetCount float64 = 0
+	var realCount float64 = 0
+	var row int = 0
+
+	for _, product := range products {
+		produceExcel := NewReportProductBill(f)
+		produceExcel.Content = product
+
+		produceExcel.Title = fmt.Sprintf("%s成品采购单", companyName)
+		//设置对应的数据
+		produceExcel.Offset = offset
+		produceExcel.Draws()
+		budgetCount += produceExcel.BudgetCount
+		realCount += produceExcel.RealCount
+		offset += 15
+		row = produceExcel.Row
+
+	}
+	row++
+	startCell := fmt.Sprintf("%s%d", "A", row)
+	endCell := fmt.Sprintf("%s%d", "H", row)
+	f.MergeCell(sheetName, startCell, endCell)
+	f.SetCellStyle(sheetName, startCell, endCell, alignCenterStyle)
+	f.SetCellValue(sheetName, startCell, "汇总金额")
+
+	// 预算金额汇总
+	budgetCountCell := fmt.Sprintf("%s%d", "I", row)
+	budgetCountStr := ""
+	if realCount > 0 {
+		budgetCountStr = fmt.Sprintf("%.3f", budgetCount)
+	}
+	f.SetCellValue(sheetName, budgetCountCell, budgetCountStr)
+	f.SetCellStyle(sheetName, budgetCountCell, budgetCountCell, alignCenterStyle)
+
+	// 实际金额汇总
+	RealCountCell := fmt.Sprintf("%s%d", "J", row)
+
+	realCountStr := ""
+	if realCount > 0 {
+		realCountStr = fmt.Sprintf("%.3f", realCount)
+	}
+	f.SetCellValue(sheetName, RealCountCell, realCountStr)
+	f.SetCellStyle(sheetName, RealCountCell, RealCountCell, alignCenterStyle)
+
+	f.SetRowHeight(sheetName, row, 21)
+
+	c.Header("Content-Type", "application/octet-stream")
+	c.Header("Content-Disposition", "attachment; filename="+"reportProduce.xlsx")
+	c.Header("Content-Transfer-Encoding", "binary")
+	err = f.Write(c.Writer)
+	if err != nil {
+		return nil, err
+	}
+	return nil, nil
+}

+ 4 - 0
boxcost/boxcost.log

@@ -14,3 +14,7 @@
 {"level":"info","timestamp":"2023-01-18 10:09:00","message":"[<nil>]","service_name":"boxcost"}
 {"level":"info","timestamp":"2023-02-15 10:39:19","message":"[<nil>]","service_name":"boxcost"}
 {"level":"info","timestamp":"2023-02-15 10:43:36","message":"[<nil>]","service_name":"boxcost"}
+{"level":"info","timestamp":"2023-02-21 12:20:32","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: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"}

+ 1 - 1
boxcost/db/db.go

@@ -35,7 +35,7 @@ func (db *MongoDB) GetOrCreateDatabase(name string) *mongo.Database {
 }
 
 func NewMongoDB(bus *comm.NatsBus) *MongoDB {
-	inst, err := bus.NewMongoDBFromConfigDev("box-mongo")
+	inst, err := bus.NewMongoDBFromConfig("box-mongo")
 	if err != nil {
 		panic(err)
 	}

+ 3 - 0
boxcost/db/model/bill.go

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