Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Quintiq file version 2.0
#parent: #root
StaticMethod UpdateAccountKPIValueInPeriod (
  KPIValues accountkpis,
  Period_MP period,
  DateTime start,
  DateTime end,
  Scenario scenario
)
{
  Description: 'Update the kpi value in period for account kpis'
  TextBody:
  [*
    // soh yee Jul-14-2014 (created)
    
    periods := construct( KPIValueInPeriods );
    
    // Account KPIs is sorted from non-children to the highest level, such that the arithmetic operation can take places for accounts with children
    traverse( accountkpis, Elements, kpivalue )
    {
      kpiname := kpivalue.KPI().Name();
      account := select( period, MacroPlan.Account_MP, a, a.Name() = kpiname );
    
      sales := 0.0;
      inventoryholding := 0.0;
      fixed := 0.0;
      nrofunits := 0.0;
      time := 0.0;
      volume := 0.0;
      staffing := 0.0;
    
      createsales := false;
      createinventoryholding := false;
      createfixed := false;
      createnrofunits := false;
      createtime := false;
      createvolume := false;
      createstaffing := false;
    
    
      // Accounts without any children.
      traverse( account, AccountAssignment, aa, aa.Account_MP().Child( relsize ) = 0 )
      {
        costdriver := aa.CostDriver();
    
        // Sales
        if( costdriver = Translations::MP_AccountAssignmentCostDriverSales() )
        {
          sales := sales + aa.GetSalesAccountValueInPeriod( period );
          
          createsales := true;
        }
    
        // Inventory holding
        else if( costdriver = Translations::MP_AccountAssignmentCostDriverInventoryHolding() )
        {
          inventoryholding := inventoryholding + aa.GetInventoryHoldingAccountValueInPeriod( period );
          
          createinventoryholding := true;
        }
    
        // Fixed
        else if( costdriver = Translations::MP_AccountAssignmentCostDriverFixed() )
        {
          fixed := fixed + aa.GetFixedAccountValueInPeriod( period );
    
          createfixed := true;
        }
    
        //Staffing
        else if( costdriver = Translations::MP_AccountAssignmentCostDriverStaffing() )
        {
          staffing := staffing + aa.GetStaffingAccountValueInPeriod( period );
                                                
          createstaffing := true;
        }
    
        // Nr of units
        else if( costdriver = Translations::MP_AccountAssignmentCostDriverNrOfUnits() )
        {
          nrofunits := nrofunits + aa.GetNrOfUnitsAccountValueInPeriod( period );
          
          createnrofunits := true;
        }
    
        // Time
        else if( costdriver = Translations::MP_AccountAssignmentCostDriverTime() )
        {
          time := time + aa.GetTimeAccountValueInPeriod( period );
          
          createtime := true;
        }
    
        // Volume
        else if( costdriver = Translations::MP_AccountAssignmentCostDriverVolume() )
        {
          volume := volume + aa.GetVolumeAccountValueInPeriod( period );
                                            
          createvolume := true;
        }
      }
     // create kpivalue in period for each of account assignment and acount kpis
      ScenarioManager::CreateKPIValueInPeriod( createsales, createinventoryholding, createfixed, 
                                               createstaffing,createnrofunits, createtime, 
                                               createvolume, kpivalue, start, end, 
                                               sales, inventoryholding, fixed, staffing, 
                                               nrofunits, time, volume, account, kpiname, periods ); 
    
    }
    
    ScenarioManager::UpdateMarginAcount( period, periods, scenario, start, end );
  *]
}