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
Quintiq file version 2.0
#parent: #root
Function CalcSystemFulfilledQuantity
{
  Description: 'Set fulfillment quantity greedy based on demand type'
  TextBody:
  [*
    /* gooi: looks like not needed except on leaf planning
    if( this.IsPlanning() and 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 );
    
        // SALES DEMAND
        if( this.ProductInStockingPoint_MP().IsLeaf() ) // fulfill sales demand from leaf pispip only
        {
          // To minus the disaggregated sales demand in period quantity that is fulfilled by manual planning
          totalremaining := totalremaining - sum( this, DisaggregatedSalesDemandInPeriod, dsdip, dsdip.FulfilledQuantity() );
          this.CalculateSalesDemandSystemFulfilledQuantity( totalremaining );
        }
      }
    }
  *]
}