|
@@ -1,10 +1,10 @@
|
|
package api
|
|
package api
|
|
|
|
|
|
import (
|
|
import (
|
|
- "box-cost/db/model"
|
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
"github.com/xuri/excelize/v2"
|
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
)
|
|
|
|
|
|
// 生产成本表
|
|
// 生产成本表
|
|
@@ -19,7 +19,8 @@ type PlanCostExcel struct {
|
|
|
|
|
|
AlignCenterStyle int
|
|
AlignCenterStyle int
|
|
|
|
|
|
- Content *model.ProductPlan
|
|
|
|
|
|
+ // Content *model.ProductPlan
|
|
|
|
+ Content *SupplierPlanCost
|
|
}
|
|
}
|
|
|
|
|
|
func (b *PlanCostExcel) drawTitle() error {
|
|
func (b *PlanCostExcel) drawTitle() error {
|
|
@@ -146,27 +147,140 @@ func (b *PlanCostExcel) drawTableTitle() error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (b *PlanCostExcel) drawTableContent() error {
|
|
|
|
|
|
+func (b *PlanCostExcel) drawSupplierContent() error {
|
|
|
|
+ supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
row := b.Offset + 4
|
|
row := b.Offset + 4
|
|
|
|
+ comps := b.Content.Pack.Components
|
|
|
|
+ var totalPlanPrice float32 = 0.00
|
|
|
|
+ if len(comps) > 0 {
|
|
|
|
+ for _, comp := range comps {
|
|
|
|
+ var totalOrderRealPrice float32 = 0.00
|
|
|
|
+ if len(comp.Mats) > 0 {
|
|
|
|
+ startRow := 0
|
|
|
|
+ for _, mat := range comp.Mats {
|
|
|
|
+ if mat.Supplier.SupplierInfo != nil {
|
|
|
|
+ if supplierId == mat.Supplier.SupplierInfo.Id {
|
|
|
|
+ // 材料
|
|
|
|
+ startRow = row
|
|
|
|
+ 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)
|
|
|
|
+ orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
|
|
|
|
+ b.FormatToEmpty(&orderPrice)
|
|
|
|
+ totalOrderRealPrice += mat.Supplier.OrderRealPrice
|
|
|
|
+ orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
|
|
|
|
+
|
|
|
|
+ b.FormatToEmpty(&orderRealPrice)
|
|
|
|
+ b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, orderPrice, orderRealPrice, "")
|
|
|
|
+ row++
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(mat.Crafts) > 0 {
|
|
|
|
+ for _, craft := range mat.Crafts {
|
|
|
|
+ if craft.Supplier.SupplierInfo != nil {
|
|
|
|
+ // 工序
|
|
|
|
+ if supplierId == craft.Supplier.SupplierInfo.Id {
|
|
|
|
+ startRow = row
|
|
|
|
+ craftSupplierName := craft.Supplier.SupplierInfo.Name
|
|
|
|
+ carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
|
|
|
|
+ b.FormatToEmpty(&carftOrderCount)
|
|
|
|
+ carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
|
|
|
|
+ b.FormatToEmpty(&carftHeigth)
|
|
|
|
+ carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
|
|
|
|
+ b.FormatToEmpty(&carftWidth)
|
|
|
|
+ carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
|
|
|
|
+ b.FormatToEmpty(&carftOrderPrice)
|
|
|
|
+ totalOrderRealPrice += craft.Supplier.OrderRealPrice
|
|
|
|
+ carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
|
|
|
|
+ b.FormatToEmpty(&carftOrderRealPrice)
|
|
|
|
+ b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, carftOrderPrice, carftOrderRealPrice, "")
|
|
|
|
+ row++
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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)
|
|
|
|
+ // 供应商组件汇总金额
|
|
|
|
+ startLCell := fmt.Sprintf("%s%d", "L", startRow)
|
|
|
|
+ endLCell := fmt.Sprintf("%s%d", "L", endRow)
|
|
|
|
+ b.Excel.MergeCell(b.SheetName, startLCell, endLCell)
|
|
|
|
+ err = b.Excel.SetCellStyle(b.SheetName, startLCell, endLCell, b.AlignCenterStyle)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ compTotalPrice := fmt.Sprintf("%.2f", totalOrderRealPrice)
|
|
|
|
+ b.FormatToEmpty(&compTotalPrice)
|
|
|
|
+ b.Excel.SetCellValue(b.SheetName, startLCell, compTotalPrice)
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
- var DrawRow = func(rowIndex int, values ...string) {
|
|
|
|
- charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
|
|
|
|
- for i, c := range charas {
|
|
|
|
- v := ""
|
|
|
|
- if i < len(values) {
|
|
|
|
- v = values[i]
|
|
|
|
}
|
|
}
|
|
- b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
|
|
|
|
|
|
+ totalPlanPrice += totalOrderRealPrice
|
|
|
|
+ }
|
|
|
|
+ // 生产汇总金额
|
|
|
|
+ startACell := fmt.Sprintf("%s%d", "A", row)
|
|
|
|
+ endKCell := fmt.Sprintf("%s%d", "K", row)
|
|
|
|
+ endLCell := fmt.Sprintf("%s%d", "L", row)
|
|
|
|
+ b.Excel.MergeCell(b.SheetName, startACell, endKCell)
|
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
|
|
|
|
+ b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
|
|
|
|
|
|
- val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
|
|
|
|
- b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
|
|
|
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, endLCell, endLCell, b.AlignCenterStyle)
|
|
|
|
+ planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice)
|
|
|
|
+ b.FormatToEmpty(&planTotalPrice)
|
|
|
|
+ b.Excel.SetCellValue(b.SheetName, endLCell, planTotalPrice)
|
|
|
|
|
|
- b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
|
|
|
|
+ charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
|
|
|
|
+ for i, c := range charas {
|
|
|
|
+ v := ""
|
|
|
|
+ if i < len(values) {
|
|
|
|
+ v = values[i]
|
|
}
|
|
}
|
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
|
|
|
|
+
|
|
|
|
+ val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
|
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
|
|
|
|
+
|
|
|
|
+ b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (b *PlanCostExcel) drawAllContent() error {
|
|
|
|
+ row := b.Offset + 4
|
|
|
|
+
|
|
comps := b.Content.Pack.Components
|
|
comps := b.Content.Pack.Components
|
|
if len(comps) > 0 {
|
|
if len(comps) > 0 {
|
|
- // row1 := row
|
|
|
|
for _, comp := range comps {
|
|
for _, comp := range comps {
|
|
if len(comp.Mats) > 0 {
|
|
if len(comp.Mats) > 0 {
|
|
startRow := row
|
|
startRow := row
|
|
@@ -175,7 +289,6 @@ func (b *PlanCostExcel) drawTableContent() error {
|
|
supplierName := ""
|
|
supplierName := ""
|
|
if mat.Supplier.SupplierInfo != nil {
|
|
if mat.Supplier.SupplierInfo != nil {
|
|
supplierName = mat.Supplier.SupplierInfo.Name
|
|
supplierName = mat.Supplier.SupplierInfo.Name
|
|
-
|
|
|
|
}
|
|
}
|
|
matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
|
|
matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
|
|
b.FormatToEmpty(&matHeigth)
|
|
b.FormatToEmpty(&matHeigth)
|
|
@@ -188,7 +301,7 @@ func (b *PlanCostExcel) drawTableContent() error {
|
|
|
|
|
|
orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
|
|
orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
|
|
b.FormatToEmpty(&orderRealPrice)
|
|
b.FormatToEmpty(&orderRealPrice)
|
|
- DrawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, orderPrice, orderRealPrice, "")
|
|
|
|
|
|
+ b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, orderPrice, orderRealPrice, "")
|
|
|
|
|
|
row++
|
|
row++
|
|
if len(mat.Crafts) > 0 {
|
|
if len(mat.Crafts) > 0 {
|
|
@@ -209,7 +322,7 @@ func (b *PlanCostExcel) drawTableContent() error {
|
|
b.FormatToEmpty(&carftOrderPrice)
|
|
b.FormatToEmpty(&carftOrderPrice)
|
|
carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
|
|
carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
|
|
b.FormatToEmpty(&carftOrderRealPrice)
|
|
b.FormatToEmpty(&carftOrderRealPrice)
|
|
- DrawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, carftOrderPrice, carftOrderRealPrice, "")
|
|
|
|
|
|
+ b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, carftOrderPrice, carftOrderRealPrice, "")
|
|
row++
|
|
row++
|
|
|
|
|
|
}
|
|
}
|
|
@@ -260,7 +373,12 @@ func (b *PlanCostExcel) drawTableContent() error {
|
|
func (b *PlanCostExcel) Draws() {
|
|
func (b *PlanCostExcel) Draws() {
|
|
b.drawTitle()
|
|
b.drawTitle()
|
|
b.drawTableTitle()
|
|
b.drawTableTitle()
|
|
- b.drawTableContent()
|
|
|
|
|
|
+ if b.Content.SupplierId != "" {
|
|
|
|
+ b.drawSupplierContent()
|
|
|
|
+ } else {
|
|
|
|
+ b.drawAllContent()
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
|
|
func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
|