renhao
2023-09-21 1aa9f2bb83dd9e4b7517f1cbf06b0db53979bb31
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
Quintiq file version 2.0
#parent: #root
FunctionOverride CalcQuantity
{
  TextBody:
  [*
    //For hourly buckets, SD will be linked to the last hourly bucket of the day
    value := 0.0
    if( not isnull( this.AsSalesDemandInPeriodBase() ) )
    {
      qtyToPlan := ifexpr( this.IsPostponed(),
                           this.QuantityToPlan(),
                           // if not postponed the quantity is derived from the Sales Demand
                           this.GetUnPostponedQuantity() ); // Convert to stocking point uom, same as dependent demand.
      
      postponedqty := sum( this,
                           PostponedSalesDemand,
                           sd,
                           sd.QuantityToPlan() );
      
      // We need to have this piece of code here specifically because real value
      // after arithmetic operation is inaccurate, and even when they are equal
      // subtraction can result in values which are inaccurate, so we need to force it
      // to be zero if they are equal. E.g., create two values, value1 := 0.12345 * 2, 
      // value2 := 0.2469, subtraction should net to zero, but you will get decimals
    //  value := ifexpr( qtyToPlan = postponedqty, 0.0, qtyToPlan - postponedqty );
      // Tianma 20230714: Fixed a bug where small decimal points are not tolerated
      value := ifexpr( GlobalParameters_MP::GetIsBalanceWithinAbsoluteTolerance( qtyToPlan, postponedqty, 0.0000001 ),
                       0.0,
                       qtyToPlan - postponedqty );
    }
    this.Quantity( value );
  *]
}