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
Quintiq file version 2.0
#parent: #root
Method GetBaseCostPerQuantityForHour (
  const AccountAssignment aa,
  const UnitPeriod unitperiod,
  Real reqcapacity
) const declarative remote as Real
{
  Description: 'Calculate cost per hour. Table methods cannot be remote, therefore this method is created to cater the usage in remote and non-remote scope.'
  TextBody:
  [*
    // soh yee Jan-21-2015 (moved)
    value := 0.0;
    if( this.AsProcess_MP().HasCapacityTypeTimeBase() )
    {
    
      accountcost := this.GetCost( aa, unitperiod );
    
      // we still need a null check because there is a chance that no accountcost is found
      if( not isnull( accountcost ) )
      {
        cost := accountcost.Cost();
    
        //convert cost per time unit into cost per quantity
        if( reqcapacity > 0 and cost > 0 )
        {
          ratio := PeriodSpecification_MP::GetLengthOfTimeAndTimeUnitRatio( unitperiod, accountcost )
          pfactor := guard( ratio / unitperiod.Duration().HoursAsReal(), 0 );
    
          value :=  ( 1 / reqcapacity * cost )
                    * guard( unitperiod.CurrencyInPeriod().Rate(), 1.0 )
                    * pfactor;
        }
      }
    }
    
    return value;
  *]
}