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
Quintiq file version 2.0
#parent: #root
StaticMethod GetRequiredQuantityByDurations (
  output Real remainingdays_o,
  Real durationindays,
  Real demandquantity,
  Boolean hasnonextperiod
) const declarative remote as Real
{
  Description:
  [*
    Given a number of days, period duration and a quantity. Return the quantity for the particular period by repect to the number of day and duration.
    E.g Period 1 2 3 in days, remainding day = 2, this will return the quantity * 1.
  *]
  TextBody:
  [*
    // desmondt Nov-13-2015 (created)
    value := demandquantity;
    
    numberofdaysused := minvalue( remainingdays_o, durationindays ) // If period is day, we only use 1 day
    
    // If there is no next period and the duration of the current period is shorter than the remaining days
    // Then the numberofdaysused for the ratio should be equal to the remaining days
    // (which means we keep repeating the last period for the purposes of the target calculation)
    if( hasnonextperiod
        and ( durationindays < remainingdays_o ) )
    {
      numberofdaysused := remainingdays_o;
    }
    
    ratioinday := numberofdaysused / durationindays; // The ratio of the remaining day in the period
    value := demandquantity * ratioinday;
    
    remainingdays_o := maxvalue( ( remainingdays_o - numberofdaysused ), 0 );
    
    return value;
  *]
}