| Quintiq file version 2.0 | 
| #parent: #root | 
| Method MPSyncProductValueAndCosts ( | 
|   Boolean isoverwritemanualconfig, | 
|   IOProductValueAndCosts ioproductvalueandcosts | 
| ) | 
| { | 
|   Description: 'Synchronization of ProductValueAndCosts for MPSync' | 
|   TextBody: | 
|   [* | 
|     // Select a set of existing ProductValueAndCost | 
|     existing := selectset( this, Product_MP.ProductValueAndCost , item, true ); | 
|     updates := construct( ProductValueAndCosts ); | 
|      | 
|     // Traverse the new set of valid ProductValueAndCost | 
|     traverse( ioproductvalueandcosts , Elements, io, io.IsValid() ) | 
|     { | 
|       indexkey := io.ID(); | 
|       // Find existing ProductValueAndCost | 
|       objectinstance := ProductValueAndCost::FindProductValueAndCostTypeIndex( indexkey ); | 
|       // Find existing Product_MP | 
|       product := Product_MP::FindProductTypeIndex( io.ProductID() ); | 
|       // Find existing Account_MP | 
|       account := Account_MP::FindAccountTypeIndex( io.AccountName() ); | 
|        | 
|       // If no existing ProductValueAndCost is found, and there's valid Product_MP and Account_MP, create one | 
|       if( isnull( objectinstance ) ) | 
|       { | 
|         if( not ( isnull( product ) or isnull( account ) ) ) | 
|         { | 
|           objectinstance := ProductValueAndCost::Create( indexkey, | 
|                                                          product,  | 
|                                                          account, | 
|                                                          io.CostDriver(), | 
|                                                          io.Start(), | 
|                                                          io.Cost(), | 
|                                                          true ).astype( ProductValueAndCost ); | 
|         } | 
|       } | 
|       // Else if the ProductValueAndCost is not manually configured or the imported instance should overwrite manual configuration, | 
|       // update the existing ProductValueAndCost | 
|       else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|       { | 
|         // Update ProductValueAndCost | 
|         if( not ( isnull( account ) ) ) | 
|         { | 
|           objectinstance.Update( account, io.CostDriver(), io.Start(), io.TimeUnit(), io.LengthOfTime(), io.Cost(), true ); | 
|            | 
|           updates.Add( objectinstance ); | 
|         } | 
|       } | 
|        | 
|       if( not isnull( objectinstance ) ) | 
|       { | 
|         // Extended method | 
|         objectinstance.CustomUpdate( io, isoverwritemanualconfig ); | 
|       } | 
|     } | 
|      | 
|     // Get the set of old ProductValueAndCost to be deleted | 
|     tobedeleteset := existing.Difference( updates ); | 
|      | 
|     // Traverse the set of ProductValueAndCost to be deleted | 
|     // Only delete ProductValueAndCost that is not manually configured or the imported instance should overwrite manual configuration | 
|     traverse( tobedeleteset, Elements, ele, | 
|               not ele.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|     { | 
|       ele.Delete(); | 
|     } | 
|   *] | 
| } |