Quintiq file version 2.0
#parent: #root
Method EditPostponedSalesDemandCostFromListProductInStockingPointInPeriod (
  internal[GUIComponent] parent,
  structured[ProductInStockingPointInPeriodPlanning] selection
) id:Method_DialogCreateEditPostponedSalesDemandCost_EditPostponedSalesDemandCostFromListProductInStockingPointInPeriod
{
  #keys: '[108486.0.1971276166]'
  Body:
  [*
    // Edit the cost of the selection pispip from periods list
    
    Dialog.EnableDisableComponent( true );
    
    // Need this for excluding itself in pre-condition primary keys checking.
    data := shadow( selection.Element( 0 ).PostponedSalesDemandCost() );
    pisp := selection.Element( 0 ).ProductInStockingPoint_MP();
    product := pisp.Product_MP();
    stockingpoint := pisp.StockingPoint_MP();
    
    // In case selection.Element( 0 ) doesn't bind to any inventory specification, calling SetDefaultValue method will return null error.
    // Check start in case of editing from PISPIP later than the existing PSDC, the Start date will be off if we pass in existing PSDC
    if( isnull( data )
        or data.Start() <> selection.Element( 0 ).Start().Date() )
    {
      data := selection.Element( 0 ).ProductInStockingPoint_MP().Product_MP().PostponedSalesDemandCost( relshadow, ProductID := product.ID(), StockingPointID := stockingpoint.ID(), Start := selection.Element( 0 ).Start().Date() );
    }
    
    data.StockingPoint_MP( relset, selection.Element( 0 ).ProductInStockingPoint_MP().StockingPoint_MP() );
    
    Dialog.Data( data );
    
    // Need this so that when the pispip doesn't not have an postponed sd cost, the fields in this Dialog will not be blank.
    Dialog.SetDefaultValue( selection.Element( 0 ) );
    
    result := this.DoModal( parent );
    
    if ( result > 0 )
    {
      PostponedSalesDemandCost::CreateOrUpdateForPISPIPs( selection,
                                                          data.Penalty() );
    
    }
  *]
}
