| 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; | 
|   *] | 
| } |