chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
47
48
Quintiq file version 2.0
#parent: #root
Method SetSupplyForProcess (
  ProductInStockingPointInPeriodPlanning pispip,
  Process_MP process,
  Real userQty
)
{
  Description: 'Set supply quantity for process (operation or lane leg) for particular period. Creates period task operation or trip if not exists.'
  TextBody:
  [*
    // Get supply for the process
    // Used by supply planning matrix (web) and emulating the thin client supply planning matrix
    productionSupply := select( pispip, Supply_MP, supply, supply.Process_MP() = process );
    
    // If supply not exists, create the period task operation or trip
    if( isnull( productionSupply ) )
    {
      if( process.istype( LaneLeg ) )
      {
        pispips := construct( ProductInStockingPointInPeriodPlannings );
        pispips.Add( pispip );
        Trip::CreateWithProductInTrips( pispips, process.astype( LaneLeg ) );
      }
      else if( process.istype( Operation ) )
      {
        pispip.CreateUpdateOperationNewSupplies( process.astype( Operation ), userQty ); 
      }
      
      // Refresh the new supply so we can update the quantity
      Transaction::Transaction().Propagate();
      
      productionSupply := select( pispip, Supply_MP, supply, supply.Process_MP() = process );
    }
    
    if( not isnull( productionSupply ) )
    {
      if ( productionSupply.istype( NewSupply ) )
      {
        productionSupply.astype( NewSupply ).Update( userQty,  true );  
      }
      else
      {
        productionSupply.Update( userQty );
      }  
    }
  *]
}