limj
2023-10-24 93652435728de839582440eefd5122c281181d35
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
Quintiq file version 2.0
#parent: #root
Method GetLastAllowedPostponementPeriodEnd () declarative as DateTime
{
  Description: 'Calculate period end of last allowed period where planning SDiPs are allowed to postpone to'
  TextBody:
  [*
    value := DateTime::MinDateTime();
    macroplanEnd := this.MasterSalesDemand().MacroPlan().End();
    haseffectivepostponementspecification := guard( this.MasterSalesDemand().SalesSegment_MP().HasEffectivePostponementSpecification(), false ); 
    
    if( haseffectivepostponementspecification )
    {
      ps := this.PostponementSpecification();
      
      // Use SDiP EndDate to find as Period_MP end date might not be the same with SDiP End
      if( not isnull( ps ) )
      {
        effectiveEnd := this.EndDate().DateTime();
        // If start = end (e.g CustomerOrder which only has start date), have the End based on PISPIP End else logic has less period to postpone to
        if( this.StartDate() = this.EndDate() and not isnull( this.AsSalesDemandInPeriodBase() ) )
        {
          effectiveEnd := this.AsSalesDemandInPeriodBase().End(); 
        }
        value := PeriodSpecification_MP::GetStartOfNextPeriod( effectiveEnd, 
                                                               ps.MaxTimeUnit(), 
                                                               ps.MaxNrOfTimeUnit() );
      }
    }
    
    // Postponement period horizon end must not exceed planning horizon end
    value := minvalue( value, macroplanEnd );  
    
    return value;
  *]
}