lazhen
2024-07-01 bce35410b00e2b7228ab5409744e173f2726b8d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Quintiq file version 2.0
#parent: #root
StaticMethod RefreshOfflinePlan (
  MacroPlan macroPlan
)
{
  TextBody:
  [*
    macroPlan.OfflinePlanRow( relflush );
    macroPlan.OfflinePlanColumn( relflush );
    
    // 生成下线计划表
    traverse ( macroPlan, Unit, u, u.HasCapacityTypeTime() and u.Name() = "ZP4-M3" ) {
      // 创建产线行
      macroPlan.OfflinePlanRow( relnew, ProductionLine := u.ID(), ProductID := "", Type := "0" );
      
      traverse ( u, Operation, o ) {
        traverse ( o, PeriodTaskOperation.NewSupply, ns ) {
          // 找行
          oprQuantity := OfflinePlanRow::FindOfflinePlanRowTypeIndex( u.ID(), ns.AsProductionSupply().ProductInStockingPoint_MP().ProductID(), "1" );
          oprOrder    := OfflinePlanRow::FindOfflinePlanRowTypeIndex( u.ID(), ns.AsProductionSupply().ProductInStockingPoint_MP().ProductID(), "2" );
          if ( isnull( oprQuantity ) and isnull( oprOrder ) ) {
            oprQuantity := macroPlan.OfflinePlanRow( relnew, ProductionLine := u.ID(), ProductID := ns.AsProductionSupply().ProductInStockingPoint_MP().ProductID(), Type := "1" );
            oprOrder    := macroPlan.OfflinePlanRow( relnew, ProductionLine := u.ID(), ProductID := ns.AsProductionSupply().ProductInStockingPoint_MP().ProductID(), Type := "2" );
          }
          
          // 找列
          opc := OfflinePlanColumn::FindOfflinePlanColumnTypeIndex( ns.Start().Date() );
          if ( isnull( opc ) ) {
            opc := macroPlan.OfflinePlanColumn( relnew, ColumnDate := ns.Start().Date() );
          }
          
          // 赋值单元格
          cellQuantity := opc.OfflinePlanCell( relnew, Value := [String]ns.Quantity().Round( 0 ), Shift := ns.PeriodTask_MP().UnitPeriod().astype( UnitPeriodTimeBase ).ShiftPattern().Name() );
          cellQuantity.OfflinePlanRow( relset, oprQuantity );
          cellOrder := opc.OfflinePlanCell( relnew, Value := "单号" );
          cellOrder.OfflinePlanRow( relset, oprOrder );
        }
      }
      
      // 创建总量行
      macroPlan.OfflinePlanRow( relnew, ProductionLine := u.ID(), ProductID := "Z", Type := "3" );
      // 创建班次行
      macroPlan.OfflinePlanRow( relnew, ProductionLine := u.ID(), ProductID := "Z", Type := "4" );
    }
    
    // 创建产品列&类型列
    productOPC := macroPlan.OfflinePlanColumn( relnew, ColumnDate := macroPlan.StartOfPlanning().Date() - 2 );
    typeOPC    := macroPlan.OfflinePlanColumn( relnew, ColumnDate := macroPlan.StartOfPlanning().Date() - 1 );
    traverse ( macroPlan, OfflinePlanRow, opr ) {
      if ( opr.Type() = "0" ) {
        productLineCell := productOPC.OfflinePlanCell( relnew, Value := opr.ProductionLine() );
        productLineCell.OfflinePlanRow( relset, opr );
      } else if( opr.Type() = "1" ) {
        productCell := productOPC.OfflinePlanCell( relnew, Value := opr.ProductID() );
        productCell.OfflinePlanRow( relset, opr );
        typeCell    := typeOPC.OfflinePlanCell( relnew, Value :=  "Quantity" );
        typeCell.OfflinePlanRow( relset, opr );
      } else if ( opr.Type() = "2" ) {
        typeCell    := typeOPC.OfflinePlanCell( relnew, Value :=  "Order" );
        typeCell.OfflinePlanRow( relset, opr );
      } else if ( opr.Type() = "3" ) {
        totalCell := productOPC.OfflinePlanCell( relnew, Value := "合计" );
        totalCell.OfflinePlanRow( relset, opr );
        totalCell := typeOPC.OfflinePlanCell( relnew, Value :=  "总量" );
        totalCell.OfflinePlanRow( relset, opr );
      } else if ( opr.Type() = "4" ) {
        shiftCell := typeOPC.OfflinePlanCell( relnew, Value :=  "班次" );
        shiftCell.OfflinePlanRow( relset, opr );
      }
    }
    
    // 补全总量和班次
    totalOPRs := selectset( macroPlan, OfflinePlanRow, tempOPR, tempOPR.Type() = "3" );
    shiftOPRs := selectset( macroPlan, OfflinePlanRow, tempOPR, tempOPR.Type() = "4" );
    traverse ( macroPlan, OfflinePlanColumn, opc, opc.OfflinePlanCell( relsize ) > 0 and opc.ColumnDate() >= macroPlan.StartOfPlanning().Date() ) {
      traverse ( totalOPRs, Elements, totalOPR ) {
        total     := sum( opc, OfflinePlanCell, tempOPC, tempOPC.OfflinePlanRow().ProductionLine() = totalOPR.ProductionLine() and tempOPC.OfflinePlanRow().Type() = "1", [Real]tempOPC.Value() );
        totalCell := opc.OfflinePlanCell( relnew, Value := [String]total );
        totalCell.OfflinePlanRow( relset, totalOPR );
      }
      
      traverse ( shiftOPRs, Elements, shiftOPR ) {
        shift := select( opc, OfflinePlanCell, tempOPC, tempOPC.OfflinePlanRow().ProductionLine() = shiftOPR.ProductionLine() and tempOPC.OfflinePlanRow().Type() = "1" ); 
        if ( not isnull( shift ) ) {
          shiftCell := opc.OfflinePlanCell( relnew, Value := shift.Shift() );
          shiftCell.OfflinePlanRow( relset, shiftOPR );
        }
      }
    }
    
    // 补全时间列
    indexDate := macroPlan.StartOfPlanning().Date();
    endDate   := Date::Construct( indexDate.Year(), 12, 31 );
    while ( indexDate <= endDate ) {
      opc := OfflinePlanColumn::FindOfflinePlanColumnTypeIndex( indexDate );
      if ( isnull( opc ) ) {
        opc := macroPlan.OfflinePlanColumn( relnew, ColumnDate := indexDate );
      }
      indexDate := indexDate + 1;
    }
  *]
}