chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
Method CreateProductInStockingPointInPeriod (
  ProductInStockingPoint_MPs pisps,
  Period_MPs periods,
  Boolean isondelete
)
{
  Description: 'Create product in stocking point in period base on a set of pisps and periods'
  TextBody:
  [*
    if( this.GetHasValidNrOfPISPIP() )
    {
      traverse( pisps, Elements, pisp )
      {
        firstplanning := guard( pisp.FirstPlanningPISPIP().Start(), this.StartOfPlanning() ); 
        
        earlieststart := ifexpr( this.GetIsPeriodUpdateForShelfLifeOptimizer(), 
                                 pisp.EarliestManufactureDate().DateTime(), 
                                 DateTime::MaxDateTime() ); // no new periods for opt in this case (see below)
        
        periodsforopt := selectset(  periods, 
                                     Elements, 
                                     p, p.Start() >= earlieststart 
                                     and p.Start() < firstplanning ); // only need extra historical periods
        
        // If isondelete is true, it means the product is going to become leaf when
        // it has only 1 child left, so we cannot use GetIsLeaf
        isLeaf := ifexpr( not isondelete, pisp.Product_MP().GetIsLeaf(), pisp.Product_MP().Child( relsize ) = 1 )
    
        if ( not this.GetIsPeriodUpdateForShelfLifeOptimizer() ) 
        {
          pisp.CreateProductInStockingPointInPeriod( periods, isLeaf );
        }
        else
        {
          Transaction::Transaction().Propagate( attribute( Period_MP, IsPlanning ) ); // need to know what kind of pispip to create
          traverse( periodsforopt, Elements, period, period.IsPlanning() ) //only create for planning period
          {
            ProductInStockingPointInPeriod::Create( pisp, period, isLeaf );
          }
        }
      }
    }
  *]
}