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
42
Quintiq file version 2.0
#parent: #root
FunctionOverride CalcSystemFulfilledQuantity
{
  TextBody:
  [*
    if( not this.MacroPlan().IsImporting() )
    {
      if( this.ProductInStockingPoint_MP().IsNegativeInventoryAllowed() )
      {
        // Only dependent demand of input group has optimizer fulfilled quantity.
        traverse( this, DependentDemand, d,
                  d.OptimizerFulfilledQuantity() = 0 )   // Dependent demand in input group can be fulfilled by optimizer, although negative inventory is allowed
        {
          d.SystemFulfilledQuantity( d.Quantity() );
        }
      }
      else
      {
        totalremaining := this.SupplyQuantity() - this.OptimizerFulfilledDemandQuantity() - this.OptimizerReservedQuantity();
        //we don't allow total remaining qty to go below -ve
        //although totalremaining = 0, still need to proceed with the greedy to reset the demands systemfulfilledquantity to 0
        totalremaining := maxvalue( totalremaining, 0.0 );
    
        // DEPENDENT DEMAND
        this.CalculateDependentDemandSystemFulfilledQuantity( totalremaining );
        
        // Calculate the total remaining excluding immature stock quantities because for sales demands, 
        // expired quantity has been excluded when calculating SupplyQuantity
        // it can only be fulfilled with stock that is not expired and is matured if the product has shelf-life and maturation
        totalremaining := maxvalue( totalremaining
                                    - this.ImmatureShelfLifeSupplyQuantity(), 0.0 );
        
        // SALES DEMAND
        // To minus the disaggregated sales demand in period quantity that is fulfilled by manual planning
        totalremaining := totalremaining - sum( this, DisaggregatedSalesDemandInPeriod, dsdip, dsdip.FulfilledQuantity() );
        totalremaining := maxvalue( totalremaining, 0.0 );
        this.CalculateSalesDemandSystemFulfilledQuantity( totalremaining );
      }
    }
  *]
}