Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method MPSyncDisaggregationFactor ( 
 | 
  Boolean isoverwitemanualconfig, 
 | 
  IODisaggregationFactors iodisaggregationfactors 
 | 
) 
 | 
{ 
 | 
  Description: 'Synchronization of DisaggregationFactor for MPSync' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Select a set of existing DisaggregationFactor 
 | 
    existing := selectset( this, Product_MP.DisaggregationFactor, item, true ); 
 | 
    updates := construct( DisaggregationFactors ); 
 | 
     
 | 
    // Traverse the new set of valid DisaggregationFactor 
 | 
    traverse( iodisaggregationfactors , Elements, io, io.IsValid() ) 
 | 
    { 
 | 
      productid := io.ProductID(); 
 | 
      spid := io.StockingPointID(); 
 | 
      start := io.Start(); 
 | 
      // Find existing DisaggregationFactor 
 | 
      objectinstance := DisaggregationFactor::FindDisaggregationTypeIndex( productid, spid, start ); 
 | 
      // Find existing Product_MP 
 | 
      product := Product_MP::FindProductTypeIndex( productid ); 
 | 
      // Find existing StockingPoint_MP 
 | 
      stockingpoint := StockingPoint_MP::FindStockingPointTypeIndex( spid ); 
 | 
       
 | 
      // If no existing DisaggregationFactor is found, and both Product_MP and StockingPoint_MP is valid, create one 
 | 
      if( isnull( objectinstance ) ) 
 | 
      { 
 | 
        if( not ( isnull( product ) or isnull( stockingpoint ) ) ) 
 | 
        { 
 | 
          objectinstance := DisaggregationFactor::Create( product, stockingpoint, start, io.Factor(), true ); 
 | 
        } 
 | 
      } 
 | 
      // Else if the DisaggregationFactor is not manually configured or the imported instance should overwrite manual configuration, 
 | 
      // update the existing DisaggregationFactor 
 | 
      else if( not objectinstance.IsManuallyConfigured() or isoverwitemanualconfig ) 
 | 
      { 
 | 
        // Update DisaggregationFactor 
 | 
        if( not ( isnull( product ) or isnull( stockingpoint ) ) ) 
 | 
        { 
 | 
          objectinstance.Update( product, stockingpoint, start, io.Factor(), true ); 
 | 
          updates.Add( objectinstance ); 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
     
 | 
    // Get the set of old DisaggregationFactor to be deleted 
 | 
    tobedeleteset := existing.Difference( updates ); 
 | 
     
 | 
    // Traverse the set of DisaggregationFactor to be deleted 
 | 
    // Only delete DisaggregationFactor that is not manually configured or the imported instance should overwrite manual configuration 
 | 
    traverse( tobedeleteset, Elements, ele, not ele.IsManuallyConfigured() or isoverwitemanualconfig) 
 | 
    { 
 | 
      ele.Delete(); 
 | 
    } 
 | 
  *] 
 | 
} 
 |