陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
Quintiq file version 2.0
#parent: #root
Method CreateTestData
{
  Description: 'Create test data in MacroPlan and 2 new optimizer strategies in ScenarioManager'
  TextBody:
  [*
    keys := DatasetController::Find( DatasetFindOptions::Construct( this.GetUTFDatasetname() ) );
    if ( keys.Size() = 0 )     
    {
       wait := stream[Void]::Wait( Duration::Seconds( 15 ) );
       this->After( wait )->CreateTestData()
    }
    else
    {                             
     opt := DatasetFindOptions::Construct( this.GetUTFDatasetname() );                               
     mp := MDSMacroPlan::Find( opt );  
     mp->( macroplan )
     {
        macroplan.PeriodSpecification_MP( relflush );
        uom := macroplan.FindUnitOfMeasure( "Ton" );
        currency := macroplan.FindCurrency( "EUR" );
        sop := macroplan.StartOfPlanning().Date();
        sopyear := sop.Year();
        unitname := "Production";
        spname := "SP";
        isfromdb := false;
        jan5Start := Date::Construct( sopyear, 1, 5 );
        jan8Start := Date::Construct( sopyear, 1, 8 );
        priority := "Normal";
        salessegmentname := "All sales segment";
        
        gp := macroplan.GlobalParameters_MP();
        gp.IsUsableIfExpiredWithinPeriod( true );
        gp.IsUsableIfMatureWithinPeriod( true );
        
        PeriodSpecification_MP::Create( "wk", macroplan, "Week", 1, macroplan.StartOfPlanning(), 2, 6, false, true, isfromdb ); 
        //Create 2 Products
        outputA := Product_MP::Create( macroplan, "Output A","","Output A", uom.Name(), false, "", true, 7.0, false, 0.0, false, false, false, isfromdb );
        outputB := Product_MP::Create( macroplan, "Output B","","Output B", uom.Name(), false, "", true, 7.0, false, 0.0, false, false, false, isfromdb );
        // Create entities ( Unit and Stockingpoint )
        unit := Unit::Create( unitname, macroplan, unitname , uom, null( Unit ), "Infinite", "", null( SupplyChainView ), 0,0, isfromdb );
        sp := StockingPoint_MP::Create( spname, macroplan,unit, spname, "ORANGE SP", uom, currency, false, Date::MinDate(), Date::MaxDate(),null( Group ), "", "", "", "", isfromdb );
        // Create stockingpoint capacity
        sp.SetCapacityFromPeriodOnwards( Date::Construct( sopyear -1, 12, 18 ), 100.0 );
        
        // Create ActualProductInStockingPointInPeriod
        ActualProductInStockingPointInPeriod::Create( macroplan, outputB, sp, Date::Construct( sopyear -1, 12, 26 ), Date::Construct( sopyear -1, 12, 25 ), 100.0, "", isfromdb );
        // Create routing, routingstep, operation and operation cost
        routing := Routing::Create( macroplan, unitname, unitname, Date::MinDate(), Date::MaxDate(), true, isfromdb )
        units := construct( Units );
        units.Add( unit);
        operations := routing.CreateRoutingStepAndAddUnits( units );
        operation := operations.Element( 0 );
        account := select(  macroplan, Account_MP, acc, acc.Name() = 'Operating cost', true );
        OperationCost::Create( "1", operation, account, "Volume", sop, "Day", 1, 10.0, isfromdb ); 
        OperationBOM::Create( operation, outputA.ID(), spname, false, 1, false, 1.0, 1.0, 1.0, isfromdb, false );
        OperationBOM::Create( operation, outputB.ID(), spname, false, 1, false, 1.0, 1.0, 1.0, isfromdb, false ); 
        // Create 3 Forecasts
        Forecast::Create( outputA, sp, "1", jan5Start, jan5Start + 1, 100.0, 1000.0, priority, salessegmentname,currency.ID(), uom.Name(),0.0, false, isfromdb );
        Forecast::Create( outputA, sp, "2", jan8Start, jan8Start + 7, 100.0, 1.0, priority, salessegmentname,currency.ID(), uom.Name(),0.0, false, isfromdb );
        Forecast::Create( outputB, sp, "3", sop, jan8Start, 100.0, 1.0, priority, salessegmentname,currency.ID(), uom.Name(),0.0, false, isfromdb );
        
        // Create 2 new strategies
        scenariomanager := this.GetScenarioManagerStream()
        scenariomanager->( sm )
        {
         // Copy from default strategy
          strategy1 := this->CopyStategy( 'Default', sm, "Early expired 1" )
          strategy := strategy1->( strategy1)
          {
            // Deactivate all the goals
            traverse( strategy1, KPIWeight.KPI, kpi )
            {
              this.DeactivateGoal( strategy1, kpi.Name() );
            }
            // Only activate the following goals
            this.ActivateGoal( strategy1, "Stocking point capacity", 1, 1.0 );
            this.ActivateGoal( strategy1, "Unit capacity", 1, 1.0 );
            this.ActivateGoal( strategy1, "Fulfillment", 2, 1.0 );
            this.ActivateGoal( strategy1, "Inventory holding cost", 3, 1.0 );
            this.ActivateGoal( strategy1, "Operating cost", 3, 1.0 );
            this.ActivateGoal( strategy1, "Sales", 3, 1.0 );
            return strategy1;
           
          }
         strategy->( strategy1)
         {
            // Copy strategy Early expired 1 into Early expired 2
            strategy2 := this.CopyStategy( "Early expired 1", sm, "Early expired 2" );
            // Activate the following goal on top of goals from Early expired 1
            this.ActivateGoal( strategy2, "Total expired quantity", 1, 1.0 );
         }
       }
     } 
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}