animeic 2 years ago
parent
commit
1b893402e6

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

@@ -119,9 +119,10 @@ func CreateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 	bill.UpdateTime = time.Now()
 	// 制单人数据
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
+	fmt.Println("userId:", apictx.User.Parent)
 	if !userId.IsZero() {
 		user, err := getUserById(apictx, userId)
-		if err != nil {
+		if err == nil {
 			bill.UserName = user.Name
 			bill.UserId = userId
 		}

+ 2 - 1
boxcost/api/bill.go

@@ -129,9 +129,10 @@ func CreateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	// 制单人数据
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
+	fmt.Println("userId:", apictx.User.Parent)
 	if !userId.IsZero() {
 		user, err := getUserById(apictx, userId)
-		if err != nil {
+		if err == nil {
 			bill.UserName = user.Name
 			bill.UserId = userId
 		}

+ 27 - 21
boxcost/api/report-process-excel.go

@@ -33,9 +33,10 @@ type ReportProcessExcel struct {
 func (b *ReportProcessExcel) drawTitle() error {
 	marginLeft := excelize.PageMarginLeft(0.3)
 	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("J%d", tileIndex))
+	// tileIndex := b.Offset + 1
+	b.Row++
+	startCell := fmt.Sprintf("A%d", b.Row)
+	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("J%d", b.Row))
 	if err != nil {
 		return err
 	}
@@ -50,13 +51,14 @@ func (b *ReportProcessExcel) 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 *ReportProcessExcel) 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"},
 		Font:      &excelize.Font{Size: 11}})
@@ -99,18 +101,20 @@ func (b *ReportProcessExcel) 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)
 
+	b.Row++
 	//第二行
-	drawLeft(row+1, "供应商名称:"+b.Content.Supplier)
+	drawLeft(b.Row, "供应商名称:"+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, "下单时间:"+timeformat)
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
 
+	b.Row++
 	//第三行
-	drawLeft(row+2, "产品名称:"+b.Content.ProductName)
+	drawLeft(b.Row, "产品名称:"+b.Content.ProductName)
 	status := ""
 	if b.Content.Status == "complete" {
 		status = fmt.Sprintf("已完成(%d)", b.Content.ConfirmCount)
@@ -118,18 +122,19 @@ func (b *ReportProcessExcel) drawSubTitles() error {
 	if b.Content.Status == "created" {
 		status = "进行中"
 	}
-	drawRight(row+2, "状态:"+status)
-	b.Excel.SetRowHeight(b.SheetName, row+2, 21)
+	drawRight(b.Row, "状态:"+status)
+	b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
 
 	return nil
 }
 
 func (b *ReportProcessExcel) drawTableTitle() error {
-	row := b.Offset + 5
+	// row := b.Offset + 5
+	b.Row++
 	// 品名 规格  数量 单位 单价 金额
 	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 {
@@ -158,8 +163,9 @@ func (b *ReportProcessExcel) drawTableTitle() error {
 }
 
 func (b *ReportProcessExcel) 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"}
@@ -196,8 +202,8 @@ func (b *ReportProcessExcel) drawTableContent() error {
 		orderCount := fmt.Sprintf("%d", ps.OrderCount)
 		price := fmt.Sprintf("%.3f", ps.Price)
 		b.FormatToEmpty(&price)
-		DrawRow(row, ps.Name, ps.Norm, orderCount, ps.Unit, confirmCount, price, budgetAmount, realAmount, deliveryTime, ps.Remark)
-		row++
+		DrawRow(b.Row, ps.Name, ps.Norm, orderCount, ps.Unit, confirmCount, price, budgetAmount, realAmount, deliveryTime, ps.Remark)
+		// row++
 		b.Row++
 		b.BudgetCount += b.Content.BudgetAmount
 		b.RealCount += b.Content.RealAmount

+ 11 - 17
boxcost/api/report.go

@@ -49,11 +49,14 @@ func ReportPurchaseList(c *gin.Context, apictx *ApiSession) (interface{}, error)
 func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_, _, query := UtilQueryPageSize(c)
 	// 获取采符合条件的信息
-	produces := []model.ProduceBill{}
+	produces := []*model.ProduceBill{}
+
 	err := repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillProduce,
 		Query:       handleReportQuery(query),
 	}, &produces)
+	fmt.Println(err)
+	fmt.Println(produces)
 	if err != nil || len(produces) < 1 {
 		return nil, errors.New("数据不存在")
 	}
@@ -82,7 +85,7 @@ func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
 
 	for _, produce := range produces {
 		produceExcel := NewReportProduceExcel(f)
-		produceExcel.Content = &produce
+		produceExcel.Content = produce
 
 		produceExcel.Title = fmt.Sprintf("%s加工单", companyName)
 		//设置对应的数据
@@ -159,7 +162,6 @@ func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, er
 		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
 		Border:    border,
 	})
-	// offset := 0
 	companyName := getCompanyName(apictx)
 	var budgetCount float64 = 0
 	var realCount float64 = 0
@@ -167,30 +169,22 @@ func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, er
 
 	for _, purchase := range purchases {
 		var reportBill IRPurchBill
-		// if purchase.Process != nil {
-		// 	reportBill = NewReportProcessBill(f)
+		if purchase.Process != nil {
+			reportBill = NewReportProcessBill(f)
 
-		// }
+		}
 		if len(purchase.Paper) > 0 {
 			reportBill = NewReportPurchaseExcel(f)
 		}
+		reportBill.SetRow(row)
 		reportBill.SetContent(&purchase)
 		reportBill.SetTitle(fmt.Sprintf("%s原材料采购单", companyName))
 		reportBill.Draws()
-		// budgetCount += reportBill.
-
-		// purchaseExcel := NewReportPurchaseExcel(f)
-		// purchaseExcel.Content = &purchase
-		// purchaseExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
-		// //设置对应的数据
-		// purchaseExcel.Offset = offset
-		// purchaseExcel.Draws()
 		budgetCount += purchase.BudgetAmount
 		realCount += purchase.RealAmount
-		// offset += 15
-		// row = purchaseExcel.Row
+		row = reportBill.GetRow() + 3
 	}
-	row++
+	row = row - 2
 	startCell := fmt.Sprintf("%s%d", "A", row)
 	endCell := fmt.Sprintf("%s%d", "H", row)
 	f.MergeCell(sheetName, startCell, endCell)

+ 4 - 0
boxcost/api/supplier.go

@@ -92,6 +92,10 @@ func GetSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
+	// if cate,ok := query["category"];ok{
+	// 	delete(query,"category")
+	// }
+
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionSupplier,
 		Query:       query,