| Quintiq file version 2.0 | 
| #parent: #root | 
| MethodOverride TransformDataToSetObject ( | 
|   Object object_i, | 
|   LibDEF_SetObject setObject_i | 
| ) | 
| { | 
|   TextBody: | 
|   [* | 
|     salesDemandInPeriod         := object_i.astype( BaseSalesDemandInPeriod ); | 
|     manufacturingDemand := setObject_i.astype( LibDEC_ManufacturingDemand ); | 
|     salesDemand := salesDemandInPeriod.AsPlanningSalesDemandInPeriod(); | 
|     // find the other sales demand with same ProductID, CommercialSegmentName and StockingPointID (LocationID) | 
|     // and sort them by period Start | 
|     sortedSalesDemandInPeriodSet := selectsortedset( salesDemandInPeriod,  | 
|                                                      ProductInStockingPoint_MP.ProductInStockingPointInPeriodPlanning.SalesDemandInPeriodBase, sdip, | 
|                                                      not sdip.MasterSalesDemand().IsSoftDeleted() and | 
|                                                      sdip.SalesSegmentName() = salesDemandInPeriod.SalesSegmentName(), | 
|                                                      sdip.ProductInStockingPointInPeriodPlanning().Period_MP().Start(), | 
|                                                      sdip.PriorityName() ); | 
|      | 
|     manufacturingDemandId := DataTransformationManufacturingDemand::FormatManufacturingDemandID( salesDemand.ID() ); | 
|      | 
|     dateTimeVector   := DateTimeVector::Construct(); | 
|     quantities1Vector := RealVector::Construct(); | 
|     quantities2Vector := RealVector::Construct();  // meant for HIGH priority | 
|     dummyRealVector := RealVector::Construct(); | 
|      | 
|     // Default to NORMAL priority. After that: once HIGH always HIGH. | 
|     priority   := DataTransformationManufacturingDemand::SalesDemandPriorityName_Normal(); | 
|     currencyID := salesDemand.CurrencyID(); | 
|     prevsdip := null( BaseSalesDemandInPeriod ); | 
|     last := sortedSalesDemandInPeriodSet.Size() - 1; | 
|     i := 0; | 
|     traverse( sortedSalesDemandInPeriodSet, Elements, basesdip ) | 
|     { | 
|       if ( not isnull( prevsdip ) and basesdip.ProductInStockingPointInPeriodPlanning().Period_MP() = prevsdip.ProductInStockingPointInPeriodPlanning().Period_MP() ) | 
|       { | 
|        // update last entry of quantiy with aggregation | 
|         lastindex := quantities1Vector.Size() - 1; | 
|         newquantity := quantities1Vector.Get( lastindex ) + basesdip.FulfilledQuantity(); | 
|         quantities1Vector.Set( lastindex, newquantity );   | 
|       } | 
|       else | 
|       { | 
|         dateTimeVector.Append( basesdip.ProductInStockingPointInPeriodPlanning().Period_MP().Start() ); | 
|         quantities1Vector.Append( basesdip.FulfilledQuantity() ); | 
|          | 
|         if( basesdip.PriorityName() = DataTransformationManufacturingDemand::SalesDemandPriorityName_High() ) | 
|         { | 
|           quantities2Vector.Append( basesdip.FulfilledQuantity() ) | 
|           priority := DataTransformationManufacturingDemand::SalesDemandPriorityName_High(); | 
|         }  | 
|         else | 
|         { | 
|           quantities2Vector.Append( 0.0 );   | 
|         } | 
|                | 
|       } | 
|        | 
|       if ( i = last ) | 
|       { | 
|         // pad end date to the end of the vector | 
|         dateTimeVector.Append( basesdip.ProductInStockingPointInPeriodPlanning().Period_MP().End() ); | 
|         // pad 0 to the end of the vectors | 
|         quantities1Vector.Append( 0.0 ); | 
|         quantities2Vector.Append( 0.0 );   | 
|       } | 
|        | 
|       prevsdip := basesdip; | 
|       i++; | 
|     } | 
|      | 
|     //If ALL SD's folded into a single Demand Object have the SAME CurrencyID, then use that one (this should be most commong case). | 
|     // - Otherwise, use the constant "none" | 
|     hasSameCurrencyID := equal( sortedSalesDemandInPeriodSet, Elements.MasterSalesDemand, sd, true, sd.CurrencyID()  ); | 
|      | 
|     if( not hasSameCurrencyID ) | 
|     { | 
|       currencyID := DataTransformationManufacturingDemand::CurrencyID_None(); | 
|     } | 
|      | 
|     manufacturingDemand.ID(     manufacturingDemandId ); | 
|     manufacturingDemand.Update( salesDemandInPeriod.ProductID(), // use SalesDemandInPeriod.ProdutID as SalesDemand might not be from leaf product  | 
|                                 salesDemandInPeriod.StockingPointID(), | 
|                                 salesDemandInPeriod.SalesSegmentName(), | 
|                                 dateTimeVector, | 
|                                 quantities1Vector, | 
|                                 quantities2Vector, | 
|                                 dummyRealVector, | 
|                                 salesDemand.UnitOfMeasureName(), | 
|                                 currencyID, | 
|                                 priority ); | 
|   *] | 
| } |