Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method MPSyncFulfillmentTarget ( 
 | 
  Boolean isoverwritemanualconfig, 
 | 
  IOFulfillmentTargets iofulfillmenttargets 
 | 
) 
 | 
{ 
 | 
  Description: 'Synchronization of fulfillment target for MPSync' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Select a set of existing FulfillmentTarget 
 | 
    existing := selectset( this, FulfillmentTarget, item, true ); 
 | 
    updates := construct( FulfillmentTargets ); 
 | 
     
 | 
    // Traverse the new set of valid FulfillmentTarget 
 | 
    traverse( iofulfillmenttargets , Elements, io, io.IsValid() ) 
 | 
    { 
 | 
      id := io.ID(); 
 | 
      productid := io.ProductID(); 
 | 
      spid := io.StockingPointID(); 
 | 
     
 | 
      // Find existing FulfillmentTarget 
 | 
      objectinstance:= FulfillmentTarget::FindFulfillmentTargetTypeIndex( id ); 
 | 
      
 | 
      // Find existing Product_MP 
 | 
      product := Product_MP::FindProductTypeIndex( productid ); 
 | 
      // Find existing StockingPoint_MP 
 | 
      stockingpoint := StockingPoint_MP::FindStockingPointTypeIndex( spid ); 
 | 
      // Find existing SalesSegment_MP 
 | 
      salessegment := SalesSegment_MP::FindSalesSegmentTypeIndex( io.SalesSegmentName() ); 
 | 
       
 | 
      // If no existing FulfillmentTarget is found, and there is valid SalesSegment_MP, StockingPoint_MP, and Product_MP, create one 
 | 
      if( not isnull( salessegment ) or not isnull( product ) or not isnull( stockingpoint ) ) 
 | 
      { 
 | 
        if( isnull( objectinstance ) ) 
 | 
        { 
 | 
            objectinstance := FulfillmentTarget::Create( this, 
 | 
                                                         id, 
 | 
                                                         io.IsEnabled(), 
 | 
                                                         io.Name(), 
 | 
                                                         product, 
 | 
                                                         stockingpoint, 
 | 
                                                         salessegment, 
 | 
                                                         io.TargetPercentage(), 
 | 
                                                         io.Start(), 
 | 
                                                         io.End(), 
 | 
                                                         io.IsUsedForSafetyStockCalculation(), 
 | 
                                                         io.IsUsedForPlanningFulfillment(), 
 | 
                                                         true ); 
 | 
        } 
 | 
        // Else if the FulfillmentTarget is not manually configured or the imported instance should overwrite manual configuration, 
 | 
        // update the existing FulfillmentTarget 
 | 
        else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig ) 
 | 
        { 
 | 
          // Update FulfillmentTarget 
 | 
          objectinstance.Update( io.IsEnabled(), 
 | 
                                  io.Name(), 
 | 
                                  product, 
 | 
                                  stockingpoint, 
 | 
                                  salessegment, 
 | 
                                  io.TargetPercentage(), 
 | 
                                  io.Start(), 
 | 
                                  io.End(), 
 | 
                                  io.IsUsedForSafetyStockCalculation(), 
 | 
                                  io.IsUsedForPlanningFulfillment(), 
 | 
                                  true ); 
 | 
          updates.Add( objectinstance ); 
 | 
        } 
 | 
         
 | 
        if( not isnull( objectinstance ) ) 
 | 
        { 
 | 
          objectinstance.CustomUpdate( io, isoverwritemanualconfig );   
 | 
        } 
 | 
      }   
 | 
    } 
 | 
     
 | 
    // Get the set of old FulfillmentTarget to be deleted 
 | 
    tobedeleteset := existing.Difference( updates ); 
 | 
     
 | 
    // Traverse the set of FulfillmentTarget to be deleted 
 | 
    // Only delete FulfillmentTarget if the imported instance should overwrite manual configuration 
 | 
    traverse( tobedeleteset, Elements, ele, 
 | 
              not ele.IsManuallyConfigured() or isoverwritemanualconfig ) 
 | 
    { 
 | 
      ele.Delete(); 
 | 
    } 
 | 
  *] 
 | 
} 
 |