|
@@ -4,6 +4,7 @@ import (
|
|
|
"fmt"
|
|
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
|
|
|
|
// 生产成本表
|
|
@@ -19,7 +20,6 @@ type PlanCostExcel struct {
|
|
|
|
|
|
AlignCenterStyle int
|
|
|
|
|
|
- // Content *model.ProductPlan
|
|
|
Content *SupplierPlanCost
|
|
|
}
|
|
|
|
|
@@ -157,302 +157,137 @@ func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// func (b *PlanCostExcel) drawSupplierContent() error {
|
|
|
-// b.Row += 2
|
|
|
-// supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// comps := b.Content.Pack.Components
|
|
|
-// // 预算金额汇总
|
|
|
-// var totalOrderRealPrice float64 = 0.00
|
|
|
-// // 实际金额汇总
|
|
|
-// var totalRealPrice float64 = 0.00
|
|
|
-// if len(comps) > 0 {
|
|
|
-// for _, comp := range comps {
|
|
|
-// var perOrderRealPrice float64 = 0.00
|
|
|
-// var perRealPrice float64 = 0.00
|
|
|
-
|
|
|
-// if len(comp.Stages) > 0 {
|
|
|
-// startRow := 0
|
|
|
-// for _, mat := range comp.Mats {
|
|
|
-// if mat.Supplier.SupplierInfo != nil {
|
|
|
-// if supplierId == mat.Supplier.SupplierInfo.Id {
|
|
|
-// // 材料
|
|
|
-// if startRow == 0 {
|
|
|
-// startRow = row
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// supplierName := ""
|
|
|
-// if mat.Supplier.SupplierInfo != nil {
|
|
|
-// supplierName = mat.Supplier.SupplierInfo.Name
|
|
|
-// }
|
|
|
-// matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
|
|
|
-// b.FormatToEmpty(&matHeigth)
|
|
|
-// matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
|
|
|
-// b.FormatToEmpty(&matWidth)
|
|
|
-// orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
|
|
|
-// b.FormatToEmpty(&orderCount)
|
|
|
-
|
|
|
-// // 实际数量
|
|
|
-// confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
|
|
|
-// b.FormatToEmpty(&confirmCount)
|
|
|
-// // 单价
|
|
|
-// orderPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderPrice)
|
|
|
-// b.FormatToEmpty(&orderPrice)
|
|
|
-// // 预算金额
|
|
|
-// orderRealPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderRealPrice)
|
|
|
-// perOrderRealPrice += mat.Supplier.OrderRealPrice
|
|
|
-// b.FormatToEmpty(&orderRealPrice)
|
|
|
-// // 实际金额
|
|
|
-// perRealPrice += mat.RealPrice
|
|
|
-// realPrice := fmt.Sprintf("%.3f", mat.RealPrice)
|
|
|
-// b.FormatToEmpty(&realPrice)
|
|
|
-// if mat.MatInfo.Unit == "吨" || mat.MatInfo.Unit == "平方米" {
|
|
|
-// mat.MatInfo.Unit = "张"
|
|
|
-// }
|
|
|
-
|
|
|
-// b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, realPrice)
|
|
|
-
|
|
|
-// row++
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// if len(mat.Crafts) > 0 {
|
|
|
-// // 实际数量、预算数量
|
|
|
-// // mergeStartRow := row
|
|
|
-// // mergeEndRow := row
|
|
|
-// cates := map[string]MergeRow{}
|
|
|
-// for _, craft := range mat.Crafts {
|
|
|
-// if craft.Supplier.SupplierInfo != nil { // 外箱材料报错
|
|
|
-// // 工序
|
|
|
-// if supplierId == craft.Supplier.SupplierInfo.Id {
|
|
|
-// if startRow == 0 {
|
|
|
-// startRow = row
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// supplierName := ""
|
|
|
-// if craft.Supplier.SupplierInfo != nil {
|
|
|
-// supplierName = craft.Supplier.SupplierInfo.Name
|
|
|
-// }
|
|
|
-
|
|
|
-// orderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
|
|
|
-// b.FormatToEmpty(&orderCount)
|
|
|
-// carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
|
|
|
-// b.FormatToEmpty(&carftHeigth)
|
|
|
-// carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
|
|
|
-// b.FormatToEmpty(&carftWidth)
|
|
|
-
|
|
|
-// // 实际数量
|
|
|
-// confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
|
|
|
-// b.FormatToEmpty(&confirmCount)
|
|
|
-// price := fmt.Sprintf("%.3f", craft.Supplier.OrderPrice)
|
|
|
-// b.FormatToEmpty(&price)
|
|
|
-
|
|
|
-// // 预算金额
|
|
|
-// budgetAmount := ""
|
|
|
-// b.FormatToEmpty(&budgetAmount)
|
|
|
-
|
|
|
-// // 实际金额 在外层合并单元格
|
|
|
-// realAmount := ""
|
|
|
-
|
|
|
-// if craft.CraftInfo.Unit == "吨" || craft.CraftInfo.Unit == "平方米" {
|
|
|
-// craft.CraftInfo.Unit = "张"
|
|
|
-// }
|
|
|
-
|
|
|
-// b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
|
|
|
-// // mergeEndRow = row
|
|
|
-// category := craft.CraftInfo.Category
|
|
|
-// cates[category] = MergeRow{
|
|
|
-// Rows: append(cates[category].Rows, row),
|
|
|
-// RealAmount: craft.RealPrice,
|
|
|
-// BudgetAmount: craft.Supplier.OrderRealPrice,
|
|
|
-// }
|
|
|
-
|
|
|
-// row++
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// fmt.Println(cates)
|
|
|
-// for _, cate := range cates {
|
|
|
-// mergeStartRow := cate.Rows[0]
|
|
|
-// mergeEndRow := cate.Rows[len(cate.Rows)-1]
|
|
|
-// orderRealPrice := cate.BudgetAmount
|
|
|
-// realPrice := cate.RealAmount
|
|
|
-// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
|
|
|
-// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), orderRealPrice)
|
|
|
-// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
|
|
|
-// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), realPrice)
|
|
|
-// perRealPrice += realPrice
|
|
|
-// perOrderRealPrice += orderRealPrice
|
|
|
-// }
|
|
|
-// // 多个工序 合并预算价格、实际价格
|
|
|
-// // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
|
|
|
-// // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), mat.Crafts[0].Supplier.OrderRealPrice)
|
|
|
-// // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
|
|
|
-// // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), mat.Crafts[0].RealPrice)
|
|
|
-// // perRealPrice += mat.Crafts[0].RealPrice
|
|
|
-// // perOrderRealPrice += mat.Crafts[0].Supplier.OrderRealPrice
|
|
|
-
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if startRow != 0 {
|
|
|
-// endRow := row - 1
|
|
|
-// // 组件名字
|
|
|
-// startACell := fmt.Sprintf("%s%d", "A", startRow)
|
|
|
-// endACell := fmt.Sprintf("%s%d", "A", endRow)
|
|
|
-// b.Excel.MergeCell(b.SheetName, startACell, endACell)
|
|
|
-
|
|
|
-// err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-// // 预算
|
|
|
-// totalOrderRealPrice += perOrderRealPrice
|
|
|
-// // 预算
|
|
|
-// totalRealPrice += perRealPrice
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// // 工序数据
|
|
|
-// if b.Content.Process != nil {
|
|
|
-// if len(b.Content.Process) > 0 {
|
|
|
-// isSupplier := false
|
|
|
-// for _, ps := range b.Content.Process {
|
|
|
-// if supplierId == ps.Supplier.SupplierInfo.Id {
|
|
|
-// isSupplier = true
|
|
|
-// break
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// if isSupplier {
|
|
|
-// // 生产汇总金额
|
|
|
-// startACell := fmt.Sprintf("%s%d", "A", row)
|
|
|
-// endMCell := fmt.Sprintf("%s%d", "K", row)
|
|
|
-// b.Excel.MergeCell(b.SheetName, startACell, endMCell)
|
|
|
-// b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
|
|
|
-// b.Excel.SetCellValue(b.SheetName, startACell, "额外工序")
|
|
|
-// row++
|
|
|
-// // 工序 外箱 手工费 表头
|
|
|
-// var drawCol = func(startCell, endCell string, value string) error {
|
|
|
-// left1Cell := fmt.Sprintf("%s%d", startCell, row)
|
|
|
-// left2Cell := fmt.Sprintf("%s%d", endCell, row)
|
|
|
-// err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-
|
|
|
-// return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
-// }
|
|
|
-
|
|
|
-// drawCol("A", "A", "")
|
|
|
-// drawCol("B", "C", "材料/工序")
|
|
|
-// drawCol("D", "E", "供应商名称")
|
|
|
-// drawCol("F", "G", "规格")
|
|
|
-// drawCol("H", "H", "单位")
|
|
|
-// drawCol("I", "I", "下单数量")
|
|
|
-// drawCol("J", "J", "实际数量")
|
|
|
-// drawCol("K", "K", "单价")
|
|
|
-// drawCol("L", "L", "预算金额")
|
|
|
-// drawCol("M", "M", "实际金额")
|
|
|
-// row++
|
|
|
-// if len(b.Content.Process) > 0 {
|
|
|
-// for _, ps := range b.Content.Process {
|
|
|
-// orderCount := fmt.Sprintf("%.3f", ps.Supplier.OrderCount)
|
|
|
-// confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
|
|
|
-// price := fmt.Sprintf("%.3f", ps.Supplier.OrderPrice)
|
|
|
-// b.FormatToEmpty(&price)
|
|
|
-// totalOrderRealPrice += ps.Supplier.OrderRealPrice
|
|
|
-// totalRealPrice += ps.RealPrice
|
|
|
-// orderRealPrice := fmt.Sprintf("%.3f", ps.Supplier.OrderRealPrice)
|
|
|
-// b.FormatToEmpty(&orderRealPrice)
|
|
|
-// realPrice := fmt.Sprintf("%.3f", ps.RealPrice)
|
|
|
-// supplierName := ""
|
|
|
-// if ps.Supplier.SupplierInfo != nil {
|
|
|
-// supplierName = ps.Supplier.SupplierInfo.Name
|
|
|
-// }
|
|
|
-
|
|
|
-// b.drawRow(row, "", "", "", "", "", "", "", ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
|
|
|
-
|
|
|
-// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "B", row), fmt.Sprintf("%s%d", "C", row))
|
|
|
-// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "B", row), ps.ProcessInfo.Name)
|
|
|
-
|
|
|
-// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "D", row), fmt.Sprintf("%s%d", "E", row))
|
|
|
-// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "D", row), supplierName)
|
|
|
-
|
|
|
-// b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "F", row), fmt.Sprintf("%s%d", "G", row))
|
|
|
-// b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "F", row), ps.ProcessInfo.Norm)
|
|
|
-
|
|
|
-// row++
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// // 生产汇总金额
|
|
|
-// startACell := fmt.Sprintf("%s%d", "A", row)
|
|
|
-// endKCell := fmt.Sprintf("%s%d", "K", row)
|
|
|
-// LCell := fmt.Sprintf("%s%d", "L", row)
|
|
|
-// MCell := fmt.Sprintf("%s%d", "M", row)
|
|
|
-// b.Excel.MergeCell(b.SheetName, startACell, endKCell)
|
|
|
-// b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
|
|
|
-// b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
|
|
|
-
|
|
|
-// // 生产预算汇总
|
|
|
-// b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
|
|
|
-// planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderRealPrice)
|
|
|
-// b.FormatToEmpty(&planOrderRealPrice)
|
|
|
-// b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
|
|
|
-
|
|
|
-// // 生产实际汇总
|
|
|
-// b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
|
|
|
-// planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
|
|
|
-// b.FormatToEmpty(&planRealPrice)
|
|
|
-// b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
|
|
|
-
|
|
|
-// return nil
|
|
|
-// }
|
|
|
+func (b *PlanCostExcel) drawSupplierContent() error {
|
|
|
+ b.Row += 2
|
|
|
+ supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ comps := b.Content.Pack.Components
|
|
|
+ // 预算金额汇总
|
|
|
+ var totalBudgetPrice float64 = 0.00
|
|
|
+ // 实际金额汇总
|
|
|
+ var totalRealPrice float64 = 0.00
|
|
|
+ if len(comps) > 0 {
|
|
|
+ for _, comp := range comps {
|
|
|
+ var perBudgetPrice float64 = 0.00
|
|
|
+ var perRealPrice float64 = 0.00
|
|
|
+
|
|
|
+ if len(comp.Stages) > 0 {
|
|
|
+ startRow := 0
|
|
|
+ cates := map[string][]int{}
|
|
|
+ for _, stage := range comp.Stages {
|
|
|
+ if stage.SupplierInfo != nil {
|
|
|
+ if supplierId == stage.SupplierInfo.Id {
|
|
|
+ // 材料
|
|
|
+ if startRow == 0 {
|
|
|
+ startRow = b.Row
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
|
|
|
+ b.FormatToEmpty(&matHeigth)
|
|
|
+ matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
|
|
|
+ b.FormatToEmpty(&matWidth)
|
|
|
+ orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
|
|
|
+ b.FormatToEmpty(&orderCount)
|
|
|
+
|
|
|
+ // 实际数量
|
|
|
+ realCount := fmt.Sprintf("%d", stage.RealCount)
|
|
|
+ b.FormatToEmpty(&realCount)
|
|
|
+ // 单价
|
|
|
+ price := fmt.Sprintf("%.3f", stage.OrderPrice)
|
|
|
+ b.FormatToEmpty(&price)
|
|
|
+ // 预算金额
|
|
|
+ budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
|
|
|
+ perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
|
|
|
+ b.FormatToEmpty(&budgetPrice)
|
|
|
+ // 实际金额
|
|
|
+ perRealPrice += stage.OrderPrice * float64(stage.RealCount)
|
|
|
+ realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.RealCount))
|
|
|
+ b.FormatToEmpty(&realPrice)
|
|
|
+ if stage.Unit == "吨" || stage.Unit == "平方米" {
|
|
|
+ stage.Unit = "张"
|
|
|
+ }
|
|
|
+
|
|
|
+ b.drawRow(b.Row, "", stage.Name, "", "", stage.Norm, matHeigth, matWidth, stage.Unit, orderCount, realCount, price, budgetPrice, realPrice)
|
|
|
+ cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
|
|
|
+ b.Row++
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并同一供应商名
|
|
|
+ for supplierName, cate := range cates {
|
|
|
+ mergeStartRow := cate[0]
|
|
|
+ mergeEndRow := cate[len(cate)-1]
|
|
|
+ b.Excel.MergeCell(b.SheetName, fmt.Sprintf("D%d", mergeStartRow), fmt.Sprintf("D%d", mergeEndRow))
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("D%d", mergeEndRow), supplierName)
|
|
|
+ }
|
|
|
+ if startRow != 0 {
|
|
|
+ endRow := b.Row - 1
|
|
|
+ // 组件名字
|
|
|
+ startACell := fmt.Sprintf("%s%d", "A", startRow)
|
|
|
+ endACell := fmt.Sprintf("%s%d", "A", endRow)
|
|
|
+ b.Excel.MergeCell(b.SheetName, startACell, endACell)
|
|
|
+
|
|
|
+ err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // 预算
|
|
|
+ totalBudgetPrice += perBudgetPrice
|
|
|
+ // 预算
|
|
|
+ totalRealPrice += perRealPrice
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生产汇总金额
|
|
|
+ startACell := fmt.Sprintf("%s%d", "A", b.Row)
|
|
|
+ endKCell := fmt.Sprintf("%s%d", "K", b.Row)
|
|
|
+ LCell := fmt.Sprintf("%s%d", "L", b.Row)
|
|
|
+ MCell := fmt.Sprintf("%s%d", "M", b.Row)
|
|
|
+ b.Excel.MergeCell(b.SheetName, startACell, endKCell)
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
|
|
|
+
|
|
|
+ // 生产预算汇总
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
|
|
|
+ planOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
|
|
|
+ b.FormatToEmpty(&planOrderRealPrice)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
|
|
|
+
|
|
|
+ // 生产实际汇总
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
|
|
|
+ planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
|
|
|
+ b.FormatToEmpty(&planRealPrice)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
|
|
|
func (b *PlanCostExcel) drawAllContent() error {
|
|
|
b.Row += 2
|
|
|
comps := b.Content.Pack.Components
|
|
|
// 预算金额汇总
|
|
|
- var totalOrderPrice float64 = 0.00
|
|
|
+ var totalBudgetPrice float64 = 0.00
|
|
|
// 实际金额汇总
|
|
|
var totalRealPrice float64 = 0.00
|
|
|
if len(comps) > 0 {
|
|
|
for _, comp := range comps {
|
|
|
- var perOrderPrice float64 = 0.00
|
|
|
+ var perBudgetPrice float64 = 0.00
|
|
|
var perRealPrice float64 = 0.00
|
|
|
if len(comp.Stages) > 0 {
|
|
|
startRow := b.Row
|
|
|
+ cates := map[string][]int{}
|
|
|
for _, stage := range comp.Stages {
|
|
|
- // 材料
|
|
|
- supplierName := ""
|
|
|
- if stage.SupplierInfo != nil {
|
|
|
- supplierName = stage.SupplierInfo.Name
|
|
|
- }
|
|
|
matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
|
|
|
b.FormatToEmpty(&matHeigth)
|
|
|
matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
|
|
@@ -464,24 +299,33 @@ func (b *PlanCostExcel) drawAllContent() error {
|
|
|
realCount := fmt.Sprintf("%d", stage.RealCount)
|
|
|
b.FormatToEmpty(&realCount)
|
|
|
// 单价
|
|
|
- price := fmt.Sprintf("%.3f", stage.Price)
|
|
|
+ price := fmt.Sprintf("%.3f", stage.OrderPrice)
|
|
|
b.FormatToEmpty(&price)
|
|
|
// 预算金额
|
|
|
- orderPrice := fmt.Sprintf("%.3f", stage.OrderPrice)
|
|
|
- perOrderPrice += stage.OrderPrice
|
|
|
- b.FormatToEmpty(&orderPrice)
|
|
|
+ budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
|
|
|
+ perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
|
|
|
+ b.FormatToEmpty(&budgetPrice)
|
|
|
// 实际金额
|
|
|
- perRealPrice += stage.RealPrice
|
|
|
+ perRealPrice += stage.OrderPrice * float64(stage.RealCount)
|
|
|
realPrice := fmt.Sprintf("%.3f", stage.RealPrice)
|
|
|
b.FormatToEmpty(&realPrice)
|
|
|
if stage.Unit == "吨" || stage.Unit == "平方米" {
|
|
|
stage.Unit = "张"
|
|
|
}
|
|
|
- b.drawRow(b.Row, "", stage.Name, "", supplierName, stage.Norm, matHeigth, matWidth, stage.Unit, orderCount, realCount, price, orderPrice, realPrice)
|
|
|
-
|
|
|
+ b.drawRow(b.Row, "", stage.Name, "", "", stage.Norm, matHeigth, matWidth, stage.Unit, orderCount, realCount, price, budgetPrice, realPrice)
|
|
|
+ cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
|
|
|
b.Row++
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ // 合并同一供应商名
|
|
|
+ for supplierName, cate := range cates {
|
|
|
+ mergeStartRow := cate[0]
|
|
|
+ mergeEndRow := cate[len(cate)-1]
|
|
|
+ b.Excel.MergeCell(b.SheetName, fmt.Sprintf("D%d", mergeStartRow), fmt.Sprintf("D%d", mergeEndRow))
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("D%d", mergeEndRow), supplierName)
|
|
|
+ }
|
|
|
+
|
|
|
endRow := b.Row - 1
|
|
|
// 组件名字
|
|
|
startACell := fmt.Sprintf("%s%d", "A", startRow)
|
|
@@ -495,7 +339,7 @@ func (b *PlanCostExcel) drawAllContent() error {
|
|
|
}
|
|
|
|
|
|
// 预算
|
|
|
- totalOrderPrice += perOrderPrice
|
|
|
+ totalBudgetPrice += perBudgetPrice
|
|
|
// 实际金额
|
|
|
totalRealPrice += perRealPrice
|
|
|
}
|
|
@@ -510,7 +354,7 @@ func (b *PlanCostExcel) drawAllContent() error {
|
|
|
|
|
|
// 生产预算汇总
|
|
|
b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
|
|
|
- planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderPrice)
|
|
|
+ planOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
|
|
|
b.FormatToEmpty(&planOrderRealPrice)
|
|
|
b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
|
|
|
|
|
@@ -526,12 +370,11 @@ func (b *PlanCostExcel) drawAllContent() error {
|
|
|
func (b *PlanCostExcel) Draws() {
|
|
|
b.drawTitle()
|
|
|
b.drawTableTitle()
|
|
|
- // if b.Content.SupplierId != "" {
|
|
|
- // b.drawSupplierContent()
|
|
|
- // } else {
|
|
|
- // b.drawAllContent()
|
|
|
- // }
|
|
|
- b.drawAllContent()
|
|
|
+ if b.Content.SupplierId != "" {
|
|
|
+ b.drawSupplierContent()
|
|
|
+ } else {
|
|
|
+ b.drawAllContent()
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|