| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod ConvertToFulfillmentGoal ( | 
|   MacroPlan macroplan, | 
|   Boolean isimportservicelevel | 
| ) | 
| { | 
|   Description: 'This method mainly to convert data from 2016 Q4 to 2017 Q1 service level that with isusedForPlanningFulfillment, once the data converted the method can be removed' | 
|   TextBody: | 
|   [* | 
|     // This method mainly to convert data from 2016 Q4 to 2017 Q1 service level that with isusedForPlanningFulfillment, once the data converted the method can be removed | 
|     if( isimportservicelevel) | 
|     { | 
|       // Traverse all ServiceLevels of the passed in MacroPlan that has IsUsedForPlanningFulfillment = TRUE | 
|       traverse( macroplan, ServiceLevel, servicelevel, servicelevel.IsUsedForPlanningFulfillment() ) | 
|       { | 
|         // Find Product_MP, StockingPoint_MP, & SalesSegment_MP with the IDs from the current ServiceLevel | 
|         product := Product_MP::FindProductTypeIndex( servicelevel.ProductID() ); | 
|         stockingpoint := StockingPoint_MP::FindStockingPointTypeIndex( servicelevel.StockingPointID() ); | 
|         salessegment := SalesSegment_MP::FindSalesSegmentTypeIndex( servicelevel.SalesSegmentName() ); | 
|      | 
|         // Try to find a FulfillmentTarget that matches the data from the current ServiceLevel | 
|         fulfillmenttarget := select ( macroplan,  | 
|                                       FulfillmentTarget, | 
|                                       f, | 
|                                       f.StockingPointID() = servicelevel.StockingPointID() | 
|                                       and f.ProductID()= servicelevel.ProductID() | 
|                                       and f.SalesSegmentName()= servicelevel.SalesSegmentName() | 
|                                       and f.Start() = servicelevel.Start() | 
|                                       and f.End() = servicelevel.End() | 
|                                       and f.TargetPercentage() = servicelevel.TargetPercentage() ); | 
|                                        | 
|         // Create the FulfillmentTarget with data from the current ServiceLevel if no existing FulfillmentTarget is found | 
|         if( isnull( fulfillmenttarget ) ) | 
|         { | 
|           FulfillmentTarget::Create( macroplan,  | 
|                                      servicelevel.ID(), | 
|                                      servicelevel.IsEnabled(), | 
|                                      servicelevel.Name(), | 
|                                      product, | 
|                                      stockingpoint, | 
|                                      salessegment, | 
|                                      servicelevel.TargetPercentage(), | 
|                                      servicelevel.Start(), | 
|                                      servicelevel.End(), | 
|                                      false, | 
|                                      true, | 
|                                      servicelevel.IsManuallyConfigured()); | 
|                                       | 
|         } | 
|          | 
|         // Delete the current ServiceLevel | 
|         servicelevel.Delete(); | 
|       } | 
|     } | 
|   *] | 
| } |