admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Quintiq file version 2.0
#parent: #root
StaticMethod CreateOrUpdateForStockingPointInPeriod (
  StockingPointInPeriod stockingpointinperiod,
  Real maxcapacity,
  Boolean isthisperiodonwards
)
{
  Description: "Create or update the stocking point capacity when we want only the particular stocking point in period user's value ( get from stocking point capacity ) change."
  TextBody:
  [*
    // soh yee Feb-20-2013 (modified)
    // This method will be used to change the max capacity based on product capacity for stocking point in period too.
    
    stockingpointcapacity := stockingpointinperiod.StockingPointCapacity();
    stockingpoint := stockingpointinperiod.StockingPoint_MP();
    
    /*
    Case1: all stocking point in period are referring to Jan, max capacity 100.
    stocking point in period     sp capacity
      Jan                        Jan, 100
      Feb
      Mar
      Apr
    
    Case2: when user edit max capacity of the stocking point in period via context menu in spip list on Mar (max capacity = 200), (a) and (b) are created.
    stocking point in period     sp capacity
      Jan                        Jan, 100
      Feb                        Mar, 200 (a)
      Mar                        Apr, 100 (b)
      Apr
    
    
    Case3: when user edit max capacity for Mar via context menu in spip list again (now set max capacity = 300), (a) is updated.
    stocking point in period     sp capacity
      Jan                        Jan, 100
      Feb                        Mar, 300 (a)
      Mar                        Apr, 100 (b)
      Apr
    
    
    Special case: When the scenario have parallel periods, for example Weeks and Days.
    stocking point in period     sp capacity
    Week 1 (isbase)              Week 1
    Week 2 (isbase)              Week 2
    Week 3 (not base)            Day 1, Day 2, Day 3, Day 5, Day 6, Day 7
    Week 4 (not base)            Day 1, Day 2, Day 3, Day 5, Day 6, Day 7
    */
    
    nextspip := stockingpointinperiod.Next();
    nextstockingpointcapacity := guard( nextspip.StockingPointCapacity(), null( StockingPointCapacity ) );
    
    // Get all period dimension children's stocking point capacity, for handling special case and when isthisperiodonwads is true
    spcapacitys := selectset( stockingpoint, StockingPointCapacity, sc,
                              sc.Start() >= stockingpointinperiod.Start().Date()
                              and ( sc.Start() < stockingpointinperiod.Period_MP().EndDate() // Ignore the end if isthisperiodonwards
                                    or isthisperiodonwards ) );
    // To handle special case
    if( spcapacitys.Size() > 0
        and not isnull( nextspip ) )
    {
      lastchildsc := null( StockingPointCapacity );
      
      // If have next sc, we want to shift the last sc from the childsc as next period sc
      if( not isthisperiodonwards )
      {
        // Shift the last sc of the child period to next period
        lastchildsc := maxselect( stockingpoint, StockingPointCapacity, sc, stockingpointinperiod.End().Date() >= sc.Start(), sc.Start() );
      
        if( StockingPointCapacity::IsPrimaryKeysUnique( stockingpoint, nextspip.Start().Date(), null( StockingPointCapacity ) ) )
        {
          // Keep all value except the start, to handle period > day where it have uc start in the middle of the period
          // We will shift the last sc to next period
          lastchildsc.Update( lastchildsc.StockingPoint_MP(),
                              nextspip.Start().Date(),
                              lastchildsc.MaxCapacity(),
                              false ); // it is an operation from UI
        }
      }
    
      // Delete all sc except the shifted one (also for handle isthisperiodonwads for week 3, 4 Day 1~7 for the given example)
      traverse( spcapacitys, Elements, e,
                e <> stockingpointcapacity
                and e <> lastchildsc )
      {
        e.Delete();
      }
    
      // Propogate the relation to unit period quantity.
      // This is needed for the following checking.
      Transaction::Transaction().Propagate();
    }
    
    if( not isthisperiodonwards
        and not isnull( nextspip )
        and nextstockingpointcapacity = stockingpointcapacity
        and StockingPointCapacity::IsPrimaryKeysUnique( stockingpoint, nextspip.Start().Date(), null( StockingPointCapacity ) ) )
    {
      // Case2: creating (b)
      StockingPointCapacity::Create( stockingpoint,
                                     nextspip.Start().Date(),
                                     guard( stockingpointcapacity.MaxCapacity(), nextspip.MaxCapacity() ),
                                     false ); // it is an manual operation from UI
    
    
      // Propogate the relation to stocking point in periods.
      // This is needed for the following checking.
      Transaction::Transaction().Propagate();
    }
    
    // Create a new stocking point capacity for that particular stocking point in period if it does not bind to any stocking point capacity, or if it already has a stocking point capacity,
    // the related stocking point capacity doesn't have the same start as the stocking point in period.
    if( not stockingpointinperiod.HasStockingPointCapacity()
        or StockingPointCapacity::IsPrimaryKeysUnique( stockingpoint, stockingpointinperiod.Start().Date(), null( StockingPointCapacity ) ) )
    {
      // Case2: creating (a)
      StockingPointCapacity::Create( stockingpoint,
                                     stockingpointinperiod.Start().Date(),
                                     maxcapacity,
                                     false ); // operation from UI is Manual
    }
    
    else
    {
      // Case3, (a) is updated.
      // The to-be created stocking point capacity has the same primary keys with existing data. Therefore, we update it instead of creating a new data to avoid duplication.
      stockingpointcapacity.Update( stockingpoint,
                                    stockingpointcapacity.Start(),
                                    maxcapacity,
                                    false ); // operation from UI is Manual 
    }
  *]
}