| Quintiq file version 2.0 | 
| #parent: #root | 
| Method GetSalesDemandInPeriods () declarative as owning BaseSalesDemandInPeriods | 
| { | 
|   Description: 'Related Sales Demand In Periods with this service level' | 
|   TextBody: | 
|   [* | 
|     // edz1 Jul-8-2016 (created) | 
|      | 
|     hasproduct := not isnull( this.Product_MP() ); | 
|     hasstockingpoint := not isnull( this.StockingPoint_MP() ); | 
|     hassalessegment := not isnull( this.SalesSegment_MP() );  | 
|      | 
|     salesdemandsinperiods := construct( BaseSalesDemandInPeriods ); | 
|     pispips := construct( ProductInStockingPointInPeriods ); | 
|      | 
|     if( hasproduct ) | 
|     { | 
|       if( hasstockingpoint ) | 
|       { | 
|           if( hassalessegment ) // hasproduct=true, hasstockingpoint=true, hassalessegment=true | 
|           { | 
|               salesdemandsinperiods := selectset( this, | 
|                                                   SalesSegment_MP.AllChildrenOfActiveSalesLevel.AsChildren.SalesDemandInPeriod,   //TODOVincent   //get all SDIP via active level SalesSegments   | 
|                                                   sdip, | 
|                                                   sdip.NeedsToBePlanned(), | 
|                                                   this.Product_MP().IsParentOf( sdip.SalesDemand().Product_MP() )                    // matching prod/parent prod. | 
|                                                   and sdip.ProductInStockingPoint_MP().StockingPoint_MP() = this.StockingPoint_MP()  // matching stockingpoint                 | 
|                                                   and Period_MP::IsInPeriod( sdip.AsSalesDemandInPeriodBase().Start(),         | 
|                                                                              sdip.AsSalesDemandInPeriodBase().End(), | 
|                                                                              this.StartDateTime(), | 
|                                                                              this.EndDateTime() ) | 
|                                                 ); | 
|           } | 
|           else // hasproduct=true, hasstockingpoint=true, hassalessegment=false | 
|           { | 
|               pispips := selectset( this,  | 
|                                     Product_MP.AllChildren.AsChildren.ProductInStockingPoint_MP.ProductInStockingPointInPeriod,     //get all PISPIPs of all children Products | 
|                                     pispip, | 
|                                     pispip.ProductInStockingPoint_MP().StockingPoint_MP() = this.StockingPoint_MP()                 // matching stockingpoint | 
|                                     and Period_MP::IsInPeriod( this.StartDateTime(),                                             // matching start/end | 
|                                                                this.EndDateTime(),  | 
|                                                                pispip.Start(),  | 
|                                                                pispip.End() )  | 
|                                   ); | 
|                                                                  | 
|               salesdemandsinperiods := selectset( pispips,  | 
|                                                   Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ).PlanningBaseSalesDemandInPeriod,  | 
|                                                   sdip,  | 
|                                                   sdip.NeedsToBePlanned()  | 
|                                                 ); | 
|           } | 
|       } | 
|       else if( hassalessegment ) // hasproduct=true, hasstockingpoint=false, hassalessegment=true | 
|       { | 
|           salesdemandsinperiods := selectset( this, | 
|                                               SalesSegment_MP.AllChildrenOfActiveSalesLevel.AsChildren.SalesDemandInPeriod,    //get all SDIP via active level SalesSegments | 
|                                               sdip, | 
|                                               sdip.NeedsToBePlanned(), | 
|                                               this.Product_MP().IsParentOf( sdip.SalesDemand().Product_MP() )                  //matching prod/parent prod. | 
|                                               and Period_MP::IsInPeriod( sdip.AsSalesDemandInPeriodBase().Start(),        //matching start/end | 
|                                                                          sdip.AsSalesDemandInPeriodBase().End(), | 
|                                                                          this.StartDateTime(), | 
|                                                                          this.EndDateTime() ) | 
|                                             ); | 
|       } | 
|       else  // hasproduct=true, hasstockingpoint=false, hassalessegment=false | 
|       { | 
|           pispips := selectset ( this,  | 
|                                  Product_MP.AllChildren.AsChildren.ProductInStockingPoint_MP.ProductInStockingPointInPeriod,  // get all PISPIPs of all children Products | 
|                                  pispip,               | 
|                                  Period_MP::IsInPeriod( this.StartDateTime(),                                              // matching start/end | 
|                                                         this.EndDateTime(),  | 
|                                                         pispip.Start(),  | 
|                                                         pispip.End() )               | 
|                                ); | 
|           salesdemandsinperiods := selectset( pispips,  | 
|                                               Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ).PlanningBaseSalesDemandInPeriod,  | 
|                                               sdip,  | 
|                                               sdip.NeedsToBePlanned()  | 
|                                             ); | 
|       } | 
|     } | 
|     else if( hasstockingpoint ) | 
|     { | 
|       if( hassalessegment ) // hasproduct=false, hasstockingpoint=true, hassalessegment=true | 
|       { | 
|         salesdemandsinperiods := selectset( this, | 
|                                             SalesSegment_MP.AllChildrenOfActiveSalesLevel.AsChildren.SalesDemandInPeriod,    // get all SDIP via active level SalesSegments | 
|                                             sd, | 
|                                             sd.NeedsToBePlanned(), | 
|                                             this.StockingPoint_MP() = sd.ProductInStockingPoint_MP().StockingPoint_MP()      // matching stockingpoint | 
|                                             and Period_MP::IsInPeriod( sd.AsSalesDemandInPeriodBase().Start(),          // matching start/end | 
|                                                                        sd.AsSalesDemandInPeriodBase().End(), | 
|                                                                        this.StartDateTime(), | 
|                                                                        this.EndDateTime() ) | 
|                                           ); | 
|       } | 
|       else // hasproduct=false, hasstockingpooint=true, hassalessegment=false | 
|       { | 
|         pispips := selectset ( this, | 
|                                StockingPoint_MP.ProductInStockingPoint_MP.ProductInStockingPointInPeriod,   // get all PISPIPs via StockingPoint | 
|                                pispip, | 
|                                Period_MP::IsInPeriod( this.StartDateTime(),                              // matching start/end | 
|                                                       this.EndDateTime(),  | 
|                                                       pispip.Start(),  | 
|                                                       pispip.End() ) | 
|                              ); | 
|         salesdemandsinperiods := selectset( pispips,  | 
|                                             Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ).PlanningBaseSalesDemandInPeriod,  | 
|                                             sdip,  | 
|                                             sdip.NeedsToBePlanned()  | 
|                                           ); | 
|       } | 
|     } | 
|     else // hasproduct=false, hasstockingpoint=false, hassalessegment=true | 
|     { | 
|       salesdemandsinperiods := selectset( this, | 
|                                           SalesSegment_MP.AllChildrenOfActiveSalesLevel.AsChildren.SalesDemandInPeriod,    // get all SD via active level SalesSegments | 
|                                           sdip, | 
|                                           sdip.NeedsToBePlanned(), | 
|                                           Period_MP::IsInPeriod( sdip.AsSalesDemandInPeriodBase().Start(),           // matching start/end | 
|                                                                  sdip.AsSalesDemandInPeriodBase().End(), | 
|                                                                  this.StartDateTime(), | 
|                                                                  this.EndDateTime() ) | 
|                                         ); | 
|     } | 
|      | 
|     return &salesdemandsinperiods; | 
|   *] | 
| } |