renhao
2023-10-18 ff1d40a1a235da7c3bdfa26070af267f19c7a3d3
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
104
105
106
107
108
109
110
111
112
113
Quintiq file version 2.0
#parent: #root
StaticMethod IterativeGeneration2 (
  GlobalOTDSOP globalOTDSOP,
  ProductInStockingPoint_MP pisp,
  Date targetDate,
  CapacityAllocationResultsRuleConfigurations carrcs,
  Number numberOfLayers,
  NewSupply firstLevelSupply,
  Real currentLayerDependentDemandQuantity
)
{
  TextBody:
  [*
    numberOfLayers++;
    //info( "目标时间:", targetDate.Format( "Y-M2-D2" ) );
    //info( pisp.Name() );
    traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispippl, pispippl.Start().Date() = targetDate ) {
      //info( "是否有供应:", pispippl.NewSupply( relsize ) > 0, "    库存:", pispippl.InventoryLevelEnd() );
      if ( numberOfLayers <> 1 and pispippl.NewSupply( relsize ) = 0 ) {
        previous := pispippl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf );
        if ( not previous.Period_MP().IsHistorical() ) {
          previousDate := previous.Start().Date();
          CapacityAllocationResults::IterativeGeneration2( globalOTDSOP,
                                                           pisp,
                                                           previousDate,
                                                           carrcs,
                                                           numberOfLayers,
                                                           firstLevelSupply,
                                                           currentLayerDependentDemandQuantity
                                                          );
        }
      } 
      
      traverse ( pispippl, NewSupply, ns, ns.Quantity() > 0 ) {
        if ( numberOfLayers = 1 ) {
          firstLevelSupply := ns;
        }
        
        ontype( ns.PeriodTask_MP() ) {
          PeriodTaskOperation as pto : {
    //        info( "Operation周期任务..." );     
            traverse ( ns, PeriodTask_MP.astype( PeriodTaskOperation ).DependentDemand, dd, dd.Quantity() > 0 ) {
              if ( numberOfLayers = 1 ) {
                currentLayerDependentDemandQuantity := ns.Quantity();
              }
              currentLayerDependentDemandQuantity := currentLayerDependentDemandQuantity                     * 
                                                     ns.ProcessOutput().astype( OperationOutput ).Quantity() *
                                                     dd.ProcessInput().astype( OperationInput ).Quantity();
    //          info( "层数:", numberOfLayers, "    当前供应的pisp:", ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    总供应值:", ns.Quantity(), "    需要供应值:", currentLayerDependentDemandQuantity,
    //                "    当前需求pisp:", dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    需求值:", currentLayerDependentDemandQuantity );
    //          info( "-----------------------------------------------------------------------------------------------------------------" );
              CapacityAllocationResults::IterativeGeneration2( globalOTDSOP,
                                                               dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP(),
                                                               targetDate,
                                                               carrcs,
                                                               numberOfLayers,
                                                               firstLevelSupply,
                                                               currentLayerDependentDemandQuantity
                                                              );
            }
            carrc := select( carrcs, Elements, carrc, carrc.PanelMaterialCode() = ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID() );
            if ( not isnull( carrc ) ) {
    //          info( "找到面板物料..." );
              globalOTDSOP.CapacityAllocationResults( relnew,
                                                      PanelBase             := pto.Operation().UnitID(),
                                                      PanelMaterialCode     := ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID(),
                                                      NumberOfPanels        := currentLayerDependentDemandQuantity,
                                                      PanelMeasurementUnit  := ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().UnitOfMeasureName(),
                                                      ModuleMaterialCode    := firstLevelSupply.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID(),
                                                      NumberOfModules       := firstLevelSupply.Quantity(),
                                                      ModuleMeasurementUnit := firstLevelSupply.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().UnitOfMeasureName(),
                                                      ModuleBase            := guard( firstLevelSupply.PeriodTask_MP().astype( PeriodTaskOperation ).Operation().UnitID(), "车道运输" ),
                                                      Division              := carrc.Division(),
                                                      RequirementDate       := firstLevelSupply.Start().Date(),
                                                      Date                  := firstLevelSupply.Start().Date(),
                                                      Description           := "",
                                                      ID                    := OS::GenerateGUIDAsString(),
                                                      ProductID             := ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID(),
                                                      StockingPointID       := ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().StockingPointID(),
                                                      UserQuantity          := currentLayerDependentDemandQuantity,
                                                      ManufacturedDate      := Date::MinDate()
                                                     );
                                                        
            }
            //info( "-----------------------------------------------------------------------------------------------------------------" );
          }
          
          PeriodTaskLaneLeg as ptll : {
            targetDependentDemand := select( ptll, DependentDemand, dd, dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID() = ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID() );
            currentLayerDependentDemandQuantity := ifexpr( numberOfLayers = 1, targetDependentDemand.Quantity(), currentLayerDependentDemandQuantity );
    //        info( "层数:", numberOfLayers,"    当前供应的pisp:", ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    总供应值:", ns.Quantity(), "    需要供应值:", currentLayerDependentDemandQuantity,
    //              "    当前需求pisp:", targetDependentDemand.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    需求值:", currentLayerDependentDemandQuantity );
    //        info( "LaneLeg周期任务..." );
            //info( "-----------------------------------------------------------------------------------------------------------------" );
            CapacityAllocationResults::IterativeGeneration2( globalOTDSOP,
                                                             targetDependentDemand.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP(),
                                                             targetDate,
                                                             carrcs,
                                                             numberOfLayers,
                                                             firstLevelSupply,
                                                             currentLayerDependentDemandQuantity
                                                            );
          }
        }
        
        if ( numberOfLayers = 1 ) {
          firstLevelSupply := null( NewSupply );
        }
      }
    }
  *]
}