lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
49
50
51
52
Quintiq file version 2.0
#parent: #root
Method CreateInventorySupply (
  structured[ProductInStockingPointInPeriod] selection,
  internal[GUIComponent] parent
) id:Method_DialogCreateEditInventorySupply_CreateInventorySupply_676
{
  #keys: '[124808.0.458558795]'
  Body:
  [*
    // Create inventory supply from PISPIP
    ValueHolderIsBatchEdit.Value( [String] false );
    Dialog.ShowHideComponentForBatchEdit( false );
    
    data := null( shadow[InventorySupply] );
    
    feedback := '';
    id := MacroPlan.IDHolder().GetInventorySupplyID();
    stockingpoint := null( StockingPoint_MP );
    owner := InventorySupply::GetDefaultOwner( MacroPlan, stockingpoint );
    // directly trying to use StartOfPlanningPeriod.StartDate could give errors
    // if none of the periods are used for planning. Thus, added a guard and a local variable.
    startOfPlanningPeriod := MacroPlan.StartOfPlanningPeriod();
    date := guard( startOfPlanningPeriod.StartDate(), Date::MinDate() );
    min_mfgdate := date;
    
    if( not isnull( selection ) and InventorySupply::CanCreate( feedback, selection ) )
    {
      pispip := selection.Element( 0 );
      owner := pispip.ProductInStockingPoint_MP().Product_MP();
      stockingpoint := pispip.ProductInStockingPoint_MP().StockingPoint_MP();
      date := selection.Element( 0 ).Start().Date();
      min_mfgdate := date;
    }
    
    data := owner.InventorySupply( relshadow,
                                   ID := id,
                                   StockingPoint_MP := stockingpoint,
                                   Date := date,
                                   ManufacturedDate := min_mfgdate );
                                     
    Dialog.Data( data );
    result := this.DoModal( parent );
    
    if ( result > 0 )
    {                                                                                                            
      //if manufactured date is restricted, default it to date of inv supply
      data.ManufacturedDate( this.GetManufacturedDateWithUIRestriction( data.ManufacturedDate(), data.Date() ) );
      data.Commit();
    }
  *]
}