|
@@ -2,6 +2,7 @@ package api
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
)
|
|
@@ -19,7 +20,7 @@ type PlanSummaryExcel struct {
|
|
|
func (b *PlanSummaryExcel) drawTitle() error {
|
|
|
b.Row++
|
|
|
startCell := fmt.Sprintf("A%d", b.Row)
|
|
|
- err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("P%d", b.Row))
|
|
|
+ err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("S%d", b.Row))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -127,11 +128,14 @@ func (b *PlanSummaryExcel) drawTableTitle() error {
|
|
|
drawCol("N", "下单单价")
|
|
|
drawCol("O", "预算金额")
|
|
|
drawCol("P", "实际金额")
|
|
|
+ drawCol("Q", "订单编号")
|
|
|
+ drawCol("R", "下单日期")
|
|
|
+ drawCol("S", "备注")
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (b *PlanSummaryExcel) drawRow(rowIndex int, values ...string) {
|
|
|
- charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}
|
|
|
+ charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S"}
|
|
|
for i, c := range charas {
|
|
|
v := ""
|
|
|
if i < len(values) {
|
|
@@ -168,7 +172,7 @@ func (b *PlanSummaryExcel) drawAllContent() error {
|
|
|
var perRealPrice float64 = 0.00
|
|
|
if len(comp.Stages) > 0 {
|
|
|
startRow := b.Row
|
|
|
- // cates := map[string][]int{}
|
|
|
+ cates := map[string][]int{}
|
|
|
for _, stage := range comp.Stages {
|
|
|
matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
|
|
|
b.FormatToEmpty(&matHeigth)
|
|
@@ -247,14 +251,33 @@ func (b *PlanSummaryExcel) drawAllContent() error {
|
|
|
stageStatus = "未生成订单"
|
|
|
}
|
|
|
}
|
|
|
+ // 订单存在时,订单号和下单时间// 合并相同的订单,记录row方便合并
|
|
|
+ if len(stage.BillId) == 24 {
|
|
|
+ billFlag := fmt.Sprintf("%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"))
|
|
|
+ cates[billFlag] = append(cates[billFlag], b.Row)
|
|
|
+ }
|
|
|
|
|
|
- b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice)
|
|
|
+ b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm,
|
|
|
+ matHeigth, matWidth, unit, price, budgetPrice, realPrice, "-", "-", stage.Remark)
|
|
|
// if stage.SupplierInfo != nil {
|
|
|
// cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
|
|
|
|
|
|
// }
|
|
|
b.Row++
|
|
|
}
|
|
|
+ for billFlag, cate := range cates {
|
|
|
+ billInfo := strings.Split(billFlag, "_")
|
|
|
+
|
|
|
+ if len(billInfo) == 2 {
|
|
|
+ mergeStartRow := cate[0]
|
|
|
+ mergeEndRow := cate[len(cate)-1]
|
|
|
+ b.Excel.MergeCell(b.SheetName, fmt.Sprintf("Q%d", mergeStartRow), fmt.Sprintf("Q%d", mergeEndRow))
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("Q%d", mergeEndRow), billInfo[0])
|
|
|
+ b.Excel.MergeCell(b.SheetName, fmt.Sprintf("R%d", mergeStartRow), fmt.Sprintf("R%d", mergeEndRow))
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("R%d", mergeEndRow), billInfo[1])
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
// for supplierName, cate := range cates {
|
|
|
// mergeStartRow := cate[0]
|
|
@@ -345,7 +368,7 @@ func (b *PlanSummaryExcel) drawSupplierContent() error {
|
|
|
var perRealPrice float64 = 0.00
|
|
|
if len(comp.Stages) > 0 {
|
|
|
startRow := 0
|
|
|
- // cates := map[string][]int{}
|
|
|
+ cates := map[string][]int{}
|
|
|
for _, stage := range comp.Stages {
|
|
|
if stage.SupplierInfo != nil {
|
|
|
if b.Content.SupplierId == stage.SupplierInfo.Id {
|
|
@@ -433,8 +456,13 @@ func (b *PlanSummaryExcel) drawSupplierContent() error {
|
|
|
stageStatus = "未生成订单"
|
|
|
}
|
|
|
}
|
|
|
+ if len(stage.BillId) == 24 {
|
|
|
+ billFlag := fmt.Sprintf("%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"))
|
|
|
+ cates[billFlag] = append(cates[billFlag], b.Row)
|
|
|
+ }
|
|
|
|
|
|
- b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice)
|
|
|
+ b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit),
|
|
|
+ stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice, "-", "-", stage.Remark)
|
|
|
// if stage.SupplierInfo != nil {
|
|
|
// cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
|
|
|
|
|
@@ -445,6 +473,18 @@ func (b *PlanSummaryExcel) drawSupplierContent() error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ for billFlag, cate := range cates {
|
|
|
+ billInfo := strings.Split(billFlag, "_")
|
|
|
+ if len(billInfo) == 2 {
|
|
|
+ mergeStartRow := cate[0]
|
|
|
+ mergeEndRow := cate[len(cate)-1]
|
|
|
+ b.Excel.MergeCell(b.SheetName, fmt.Sprintf("Q%d", mergeStartRow), fmt.Sprintf("Q%d", mergeEndRow))
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("Q%d", mergeEndRow), billInfo[0])
|
|
|
+ b.Excel.MergeCell(b.SheetName, fmt.Sprintf("R%d", mergeStartRow), fmt.Sprintf("R%d", mergeEndRow))
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("R%d", mergeEndRow), billInfo[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 合并同一供应商名
|
|
|
// for supplierName, cate := range cates {
|
|
|
// mergeStartRow := cate[0]
|
|
@@ -569,7 +609,9 @@ func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
|
|
|
f.SetColWidth(b.SheetName, "H", "H", 25)
|
|
|
f.SetColWidth(b.SheetName, "I", "L", 16)
|
|
|
f.SetColWidth(b.SheetName, "M", "M", 10)
|
|
|
- f.SetColWidth(b.SheetName, "N", "P", 16)
|
|
|
+ f.SetColWidth(b.SheetName, "N", "P", 13)
|
|
|
+ f.SetColWidth(b.SheetName, "Q", "R", 16)
|
|
|
+ f.SetColWidth(b.SheetName, "S", "S", 20)
|
|
|
f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
|
|
|
return b
|
|
|
}
|