Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method SynchronizeDisaggregatedSalesDemandInPeriod ( 
 | 
  Boolean isdeleteinvalid 
 | 
) 
 | 
{ 
 | 
  Description: 'Create or delete disaggregatedSDiP based on fulfillment restriction.' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Create leaf pisps 
 | 
    leafpisps := construct( ProductInStockingPoint_MPs ); 
 | 
    pisp := guard( this.AsSalesDemandInPeriodBase().ProductInStockingPoint_MP(), null( ProductInStockingPoint_MP ) ); 
 | 
     
 | 
    if( not isnull( pisp ) ) 
 | 
    { 
 | 
      traverse( pisp.Product_MP().GetLeaves(), Elements, leafproduct ) 
 | 
      {                                          
 | 
        sp := pisp.StockingPoint_MP(); 
 | 
        if( isnull( leafproduct.FindProductInStockingPoint( sp.ID() ) ) ) //pisp not found 
 | 
        { 
 | 
          leafpisp := leafproduct.AddToStockingPoint( sp ); 
 | 
          leafpisps.Add( leafpisp );     
 | 
        } 
 | 
      } 
 | 
    }  
 | 
     
 | 
    // Propagate all PISPIP to SPIP relations 
 | 
    Transaction::Transaction().Propagate( relation( ProductInStockingPointInPeriod, StockingPointInPeriod ) ); 
 | 
     
 | 
    allchild := this.AsSalesDemandInPeriodBase().GetLeafPISPIPs(); 
 | 
     
 | 
    updateddsdip := construct( DisaggregatedSalesDemandInPeriods );  
 | 
    traverse( allchild, Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispip, this.SalesDemand().GetIsProductAllowed( pispip ) ) 
 | 
    { 
 | 
      dsdip := select( this, DisaggregatedSalesDemandInPeriod, dsdip, dsdip.AsPlanningBaseSalesDemandInPeriod() = pispip ); 
 | 
      if( isnull( dsdip ) ) 
 | 
      { 
 | 
        dsdip := DisaggregatedSalesDemandInPeriod::Create( this, pispip, 0.0, false ); 
 | 
      }                                                                    
 | 
       
 | 
      updateddsdip.Add( dsdip ); 
 | 
    } 
 | 
     
 | 
    if( isdeleteinvalid ) 
 | 
    { 
 | 
      trash := selectset( this, DisaggregatedSalesDemandInPeriod, d, true ); 
 | 
      trash := trash.Difference( updateddsdip ); 
 | 
       
 | 
      DisaggregatedSalesDemandInPeriod::Delete( trash ); 
 | 
    } 
 | 
  *] 
 | 
} 
 |