|
@@ -18,6 +18,7 @@ type PlanCostExcel struct {
|
|
|
SheetName string
|
|
|
|
|
|
AlignCenterStyle int
|
|
|
+ Row int
|
|
|
|
|
|
// Content *model.ProductPlan
|
|
|
Content *SupplierPlanCost
|
|
@@ -308,10 +309,12 @@ func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
|
|
|
func (b *PlanCostExcel) drawAllContent() error {
|
|
|
row := b.Offset + 4
|
|
|
comps := b.Content.Pack.Components
|
|
|
+ var totalPlanPrice float32 = 0.00
|
|
|
var confirmTotalPlanPrice float64 = 0.00
|
|
|
if len(comps) > 0 {
|
|
|
for _, comp := range comps {
|
|
|
var totalConfirmRealPrice float64 = 0.00
|
|
|
+ var totalOrderRealPrice float32 = 0.00
|
|
|
if len(comp.Mats) > 0 {
|
|
|
startRow := row
|
|
|
for _, mat := range comp.Mats {
|
|
@@ -334,6 +337,7 @@ func (b *PlanCostExcel) drawAllContent() error {
|
|
|
orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
|
|
|
b.FormatToEmpty(&orderPrice)
|
|
|
orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
|
|
|
+ totalOrderRealPrice += mat.Supplier.OrderRealPrice
|
|
|
b.FormatToEmpty(&orderRealPrice)
|
|
|
// 实际金额
|
|
|
confirmPrice := mat.Supplier.OrderPrice * float64(mat.ConfirmCount)
|
|
@@ -369,6 +373,8 @@ func (b *PlanCostExcel) drawAllContent() error {
|
|
|
|
|
|
// 实际金额
|
|
|
confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.ConfirmCount)
|
|
|
+
|
|
|
+ totalOrderRealPrice += craft.Supplier.OrderRealPrice
|
|
|
totalConfirmRealPrice += confirmCraftPrice
|
|
|
confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
|
|
|
b.FormatToEmpty(&confirmCraftRealPrice)
|
|
@@ -391,28 +397,104 @@ func (b *PlanCostExcel) drawAllContent() error {
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
|
|
|
}
|
|
|
+
|
|
|
+ // 实际
|
|
|
+ confirmTotalPlanPrice += totalConfirmRealPrice
|
|
|
+
|
|
|
+ // 预算
|
|
|
+ totalPlanPrice += totalOrderRealPrice
|
|
|
}
|
|
|
+ }
|
|
|
+ if len(b.Content.Process) > 0 {
|
|
|
// 生产汇总金额
|
|
|
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, "生产计划汇总金额")
|
|
|
+ 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+1)
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
|
|
|
- // 生产预算汇总
|
|
|
- b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
|
|
|
- planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice)
|
|
|
- b.FormatToEmpty(&planTotalPrice)
|
|
|
- b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
|
|
|
+ return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+ }
|
|
|
+
|
|
|
+ drawCol("B", "C", "材料/工序")
|
|
|
+ drawCol("D", "D", "供应商名称")
|
|
|
+ drawCol("E", "G", "规格")
|
|
|
+ drawCol("H", "H", "单位")
|
|
|
+ drawCol("I", "I", "下单数量")
|
|
|
+ drawCol("J", "J", "实际数量")
|
|
|
+ drawCol("K", "K", "单价")
|
|
|
+ drawCol("L", "L", "预算金额")
|
|
|
+ drawCol("M", "M", "实际金额")
|
|
|
+ row++
|
|
|
+
|
|
|
+ var DrawRow = func(rowIndex int, values ...string) {
|
|
|
+ charas := []string{"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"}
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, ps := range b.Content.Process {
|
|
|
+ count := fmt.Sprintf("%d", ps.Count)
|
|
|
+ confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
|
|
|
+ price := fmt.Sprintf("%.2f", ps.Price)
|
|
|
+ b.FormatToEmpty(&price)
|
|
|
+ budgetAmountf := ps.Price * float64(ps.Count)
|
|
|
+ budgetAmount := fmt.Sprintf("%.2f", budgetAmountf)
|
|
|
+ b.FormatToEmpty(&budgetAmount)
|
|
|
+ realAmountf := ps.Price * float64(ps.ConfirmCount)
|
|
|
+ realAmount := fmt.Sprintf("%.2f", realAmountf)
|
|
|
+ b.FormatToEmpty(&realAmount)
|
|
|
+ confirmTotalPlanPrice += realAmountf
|
|
|
+ totalPlanPrice += float32(budgetAmountf)
|
|
|
+
|
|
|
+ DrawRow(row, ps.Name, ps.Supplier, ps.Norm, ps.Unit, count, confirmCount, price, budgetAmount, realAmount)
|
|
|
+ row++
|
|
|
+ }
|
|
|
|
|
|
- // 生产实际汇总
|
|
|
- b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
|
|
|
- planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
|
|
|
- b.FormatToEmpty(&planConfirmTotalPrice)
|
|
|
- b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
|
|
|
}
|
|
|
+ // 生产汇总金额
|
|
|
+ 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)
|
|
|
+ // planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice) //
|
|
|
+ planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice) //
|
|
|
+ b.FormatToEmpty(&planTotalPrice)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
|
|
|
+
|
|
|
+ // 生产实际汇总
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
|
|
|
+ planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
|
|
|
+ b.FormatToEmpty(&planConfirmTotalPrice)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
|
|
|
|
|
|
return nil
|
|
|
}
|