admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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 );
  *]
}