Quintiq file version 2.0
#parent: #root
Method CreateOrEditActualFromUnitPeriodList (
  internal[GUIComponent] parent,
  structured[UnitPeriod] unitperiods
) id:Method_DialogCreateEditActualUnitPeriod_CreateOrEditActualFromUnitPeriodList
{
  #keys: '[113694.1.369549217]'
  Body:
  [*
    // Create/Edit actual unit period in unit period list
    
    unitperiod := unitperiods.Element( 0 );
    
    // Check if selected unit period is time base, we have precondition to check if all the selection is same type.
    istimebase := unitperiod.Unit().HasCapacityTypeTimeBase();
    isbatchedit := unitperiods.Size() > 1;
    
    Dialog.ShowHideComponents( istimebase, isbatchedit );
    
    data := shadow( unitperiod.ActualUnitPeriod() );
    if( isnull( data ) )
    {
      data := MacroPlan.Actual( relshadow,
                                ActualUnitPeriod,
                                UnitID := unitperiod.Unit().ID(),
                                Date := unitperiod.StartDate(),
                                UnitPeriod := unitperiod ); // Use to display UOM and instance text for validate input
    }
    
    Dialog.Data( data );
    
    result := this.DoModal( parent );
    
    if( result > 0 )
    {
      ActualUnitPeriod::CreateOrUpdateForUnitPeriods( unitperiods,
                                                      CheckBoxBatchEditUtilization.Checked(),
                                                      data.ActualUtilizationPercentage(),
                                                      CheckBoxBatchEditTotalAvailableQuantity.Checked(),
                                                      data.ActualTotalAvailableQuantity(),
                                                      CheckBoxBatchEditTotalAvailableDuration.Checked(),
                                                      data.ActualTotalAvailableDuration(),
                                                      CheckBoxBatchEditDescription.Checked(),
                                                      data.Description() );
    }
  *]
}
