陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
Quintiq file version 2.0
#parent: #root
StaticMethod GetLengthOfTimeAndTimeUnitRatio (
  String perioddefinationtimeunit,
  String timeunit,
  Number nroftimeunit,
  DateTime start,
  Duration duration
) const declarative remote as Real
{
  Description:
  [*
    Return the ratio of the period defination time unit's duration over the time unit's duration, takes length of time into consideration
    E.g., period defination time unit's duration = 1 days, time unit's duration is 1 week, length of time = 2, return (1 / 7) / 2.
    Argument time unit is get from unit capacity, unit availabilit or stocking point capacity. Same goes to length of time.
    Argument period defination time unit is unit period or stocking point period's time unit.
  *]
  TextBody:
  [*
    // soh yee Aug-26-2012 (created)
    
    factor := 1.0;
    
    // The factor will be multiplied to the "bigger" time unit. E.g., month is > week.
    if( PeriodSpecification_MP::GetTimeUnitLevel( perioddefinationtimeunit ) > PeriodSpecification_MP::GetTimeUnitLevel( timeunit ) )
    {
      factor := PeriodSpecification_MP::GetNumberOfPeriodsForDifferentTimeUnits( timeunit, perioddefinationtimeunit, start );
    }
    
    else
    {
      factor := guard( 1 / PeriodSpecification_MP::GetNumberOfPeriodsForDifferentTimeUnits( perioddefinationtimeunit, timeunit, start ), 0 );
    }
    
    // Need to find the ratio as some unit period / stocking point's duration doesn't occupy the whole time unit.
    // E.g., Apr-1-2015 to Apr-6-2015 with time unit Quarter. The duration is only few days compare to 90+ days.
    // Changed to Hours as Hours is now the smallest bucket - Nicklaus Oct-14-2016
    totalhours := PeriodSpecification_MP::GetNumberOfPeriodsForDifferentTimeUnits( Translations::MP_GlobalParameters_Hour(), perioddefinationtimeunit, start );
    durationratio := guard( duration.HoursAsReal() / totalhours, 0 );
    
    value := guard( durationratio / nroftimeunit, 0 ) * factor;
    
    
    return value;
  *]
}