Quintiq file version 2.0
#parent: #root
Method New (
  FormInventoryCosts formInventoryCosts,
  structured[ProductInStockingPoint_MP] pisp,
  Account_MP account
) id:Method_DialogCreateEditInventoryCost_New
{
  #keys: '[145730.0.2100900206]'
  Body:
  [*
    // Create new inventory costs for one or more PISPs
    if( isnull( account ) )
    {
      if( DataHolderSelectedAccounts.Data().Size() > 0 )
      {
        account := DataHolderSelectedAccounts.Data().Element( 0 );
      }
      else
      {
        account := MacroPlan.GetDefaultAccount( Form.GetCostType() );
      }
    }
    
    if( pisp.Size() = 0 )
    {
      // Select one pisp & populate into dialog
      filteredpisp := select( DataHolderPISP.Data(), Elements, e, e.IsLeaf() );
      pisp.Add( filteredpisp );
    }
    
    // Create shadow obj & set default value when creating new cost
    firstPisp := pisp.First();
    obj := firstPisp.Product_MP().InventoryValueAndCost( relshadow,
                                                         ID := MacroPlan.IDHolder().GetInventoryValueAndHoldingCostID(),
                                                         ProductID := firstPisp.ProductID(),
                                                         StockingPointID := firstPisp.StockingPointID(),
                                                         AccountName := account.Name(),
                                                         Account_MP := account,
                                                         CostDriver := account.DefaultCostDriver(),
                                                         Cost := account.DefaultCost(),
                                                         StockingPoint_MP := firstPisp.StockingPoint_MP(),
                                                         LengthOfTime := account.DefaultLengthOfTime(),
                                                         TimeUnit := account.DefaultTimeUnit(),
                                                         Start := MacroPlan.StartOfPlanning().Date() );
                            
    DataHolderDialogData.Data( &obj );
    DataHolderPISPs.Data( pisp.Copy() );
    DataHolderForm.Data( formInventoryCosts ); // Form that opens the dialog, to select the newly created object in list
    
    this.Initialize();
  *]
}
