lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
Quintiq file version 2.0
#parent: #root
Method AddInventoryValue (
  String scenarioname,
  MacroPlan macroplan,
  InventoryValueAndCosts inventoryvalues,
  Boolean isactual
)
{
  Description: 'Create separated method to ease the calculation of start and end'
  TextBody:
  [*
    startofplanning:= macroplan.StartOfPlanning(); 
    
    traverse( inventoryvalues, Elements, inv )
    {
     start := inv.Start().DateTime();
     end := inv.End().DateTime();
     currency := inv.AccountAssignment().Currency_MP();
     product := inv.Product_MP().Name();
     stockingpoint := inv.StockingPoint_MP().Name();
     cost := inv.Cost();
     if ( currency.IsBase() )
     {
        if ( not isactual )
        {
          start := maxvalue( startofplanning, start )
          this.AddPlannedItemCostForExport( scenarioname, product, stockingpoint, start, end, cost );
        }
        else
        {
          end := minvalue( end, startofplanning );
          this.AddActualItemCostForExport( product, stockingpoint, start, end, cost )
        }  
     }    
     
     else
     {
       currencyrates := currency.GetCurrencyRates( inv.Start(), inv.End() );
       i := 0;
       traverse( currencyrates, Elements, rate )
       {
         start := maxvalue( inv.Start().DateTime(), rate.Start().DateTime() );
         end := guard( currencyrates.Element(i+1).Start().DateTime(), inv.End().DateTime() );
         end := minvalue( inv.End().DateTime(), end );
         cost := inv.Cost() * rate.Rate();
         // if inventoryvaluecost cost with end > start of planning
         if ( not isactual and end > startofplanning )
         {
          start := maxvalue( start, startofplanning );
          this.AddPlannedItemCostForExport( scenarioname, product, stockingpoint, start, end, cost );
         }
         else
         {
          end := minvalue( end, startofplanning );
          this.AddActualItemCostForExport( product, stockingpoint, start, end, cost );
         }
        
         i := i +1;
       }
     }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}