| Quintiq file version 2.0 | 
| #parent: #root | 
| Method MPSyncFulfillmentRestriction ( | 
|   Boolean isoverwritemanualconfig, | 
|   IOFulfillmentRestrictions iofulfillmentrestrictions | 
| ) | 
| { | 
|   Description: 'Synchronization of FulfillmentRestriction for MPSync' | 
|   TextBody: | 
|   [* | 
|     // Select a set of existing FulfillmentRestriction | 
|     existing := selectset( this, SalesSegment_MP.FulfillmentRestriction, item, true ); | 
|     updates := construct( FulfillmentRestrictions ); | 
|      | 
|     // Traverse the new set of valid FulfillmentRestriction | 
|     traverse( iofulfillmentrestrictions, Elements, io, io.IsValid() ) | 
|     {   | 
|       // Find existing FulfillmentRestriction | 
|       objectinstance := FulfillmentRestriction::FindFulfillmentRestrictionTypeIndex( io.SalesSegmentName(), io.ProductID(), io.StartDate() ); | 
|       // Find existing SalesSegment_MP | 
|       ss := SalesSegment_MP::FindSalesSegmentTypeIndex( io.SalesSegmentName() ); | 
|       // Find existing Product_MP | 
|       product := Product_MP::FindProductTypeIndex( io.ProductID() ); | 
|                                                              | 
|       // If no existing FulfillmentRestriction is found, and there is valid SalesSegment_MP and Product_MP, create one | 
|       if( isnull( objectinstance ) ) | 
|       {  | 
|         if( not( isnull( ss ) or isnull( product ) ) ) | 
|         { | 
|           objectinstance := FulfillmentRestriction::Create( ss,  | 
|                                                             io.ProductID(),  | 
|                                                             io.StartDate(), | 
|                                                             io.EndDate() ); | 
|         } | 
|       } | 
|        | 
|       // If the FulfillmentRestriction is found or created, update the existing FulfillmentRestriction | 
|       if( not isnull( objectinstance ) ) | 
|       { | 
|         // Update FulfillmentRestriction | 
|         objectinstance.Update( io.SalesSegmentName(),  | 
|                                io.ProductID(),  | 
|                                io.StartDate(),  | 
|                                io.EndDate() ); | 
|         objectinstance.CustomUpdate( io, isoverwritemanualconfig )                        | 
|         updates.Add( objectinstance ); | 
|       } | 
|     } | 
|      | 
|     // Get the set of old FulfillmentRestriction to be deleted | 
|     tobedeleteset := existing.Difference( updates ); | 
|      | 
|     // Traverse the set of FulfillmentRestriction to be deleted | 
|     // Only delete FulfillmentRestriction if the imported instance should overwrite manual configuration | 
|     traverse( tobedeleteset, Elements, ele, isoverwritemanualconfig ) | 
|     { | 
|       ele.Delete(); | 
|     } | 
|   *] | 
| } |