| Quintiq file version 2.0 | 
| #parent: #root | 
| Method MPSyncRecipeWithEffectiveDate ( | 
|   Boolean isoverwitemanualconfig, | 
|   IORecipeWithEffectiveDates iorecipewitheffectivedates | 
| ) | 
| { | 
|   Description: 'Synchronization of RecipeWithEffectiveDate for MPSync' | 
|   TextBody: | 
|   [* | 
|     // Select a set of existing RecipeWithEffectiveDate | 
|     existing := selectset( this, Product_MP.RecipeWithEffectiveDate, item, true ); | 
|     updates := construct( RecipeWithEffectiveDates ); | 
|      | 
|     // Traverse the new set of valid RecipeWithEffectiveDate | 
|     traverse( iorecipewitheffectivedates , Elements, io, io.IsValid() ) | 
|     { | 
|       // Find existing RecipeWithEffectiveDate | 
|       objectinstance := RecipeWithEffectiveDate::FindRecipeWithEffectiveDateInProductTypeIndex( io.ProductID(), io.RecipeName(), io.EffectiveDate() ); | 
|       // Find existing Product_MP | 
|       product := Product_MP::FindProductTypeIndex( io.ProductID() ); | 
|        | 
|       // If no existing RecipeWithEffectiveDate is found, and there's valid Product_MP, create one | 
|       if( not isnull( product ) ) | 
|       { | 
|         if( isnull( objectinstance ) ) | 
|         { | 
|           objectinstance := RecipeWithEffectiveDate::Create( product, | 
|                                                              io.RecipeName(), | 
|                                                              io.EffectiveDate(), | 
|                                                              true );                                               | 
|         } | 
|         // Else if the RecipeWithEffectiveDate is not manually configured or the imported instance should overwrite manual configuration, | 
|         // update the existing RecipeWithEffectiveDate | 
|         else if( not objectinstance.IsManuallyConfigured() or isoverwitemanualconfig ) | 
|         { | 
|           // Update RecipeWithEffectiveDate | 
|           objectinstance.Update( product, | 
|                                  io.RecipeName(), | 
|                                  io.EffectiveDate(), | 
|                                  true ); | 
|      | 
|           updates.Add( objectinstance ); | 
|         } | 
|          | 
|         if( not isnull( objectinstance ) ) | 
|         { | 
|           // Extended method | 
|           objectinstance.CustomUpdate( io, isoverwitemanualconfig ); | 
|         } | 
|       } | 
|     } | 
|      | 
|     // Get the set of old RecipeWithEffectiveDate to be deleted | 
|     tobedeleteset := existing.Difference( updates ); | 
|      | 
|     // Traverse the set of RecipeWithEffectiveDate to be deleted | 
|     // Only delete RecipeWithEffectiveDate that is not manually configured or the imported instance should overwrite manual configuration | 
|     traverse( tobedeleteset, Elements, ele, | 
|               not ele.IsManuallyConfigured() or isoverwitemanualconfig ) | 
|     { | 
|       ele.Delete(); | 
|     } | 
|   *] | 
| } |