yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
Method GetBaseCostForHour (
  UnitAccount unitaccount
) declarative remote as Real
{
  Description:
  [*
    The cost calculated base on time.
    e.g: 100/Day,trip duration 5 days, cost = 100 * 5 = 500
  *]
  TextBody:
  [*
    // desmondt Jun-1-2015 (created)
    value := 0.0;
    
    if( this.HasValidDeparture() )
    {
      accountcost := this.LaneLeg().GetCost( unitaccount, this.DepartureUnitPeriod() );
      // 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( cost > 0 )
        {
          ratio := PeriodSpecification_MP::GetLengthOfTimeAndTimeUnitRatio( this.DepartureUnitPeriod(), accountcost )
          pfactor := guard( ratio / this.DepartureUnitPeriod().Duration().HoursAsReal(), 0 );
    
          value := cost
                   * pfactor
                   * guard( this.DepartureUnitPeriod().CurrencyInPeriod().Rate(), 1.0 )
                   * this.LeadTime().HoursAsReal();
        }
      }
    }
    
    return value;
  *]
}