Quintiq file version 2.0
#parent: #root
Method OnOk () id:Method_DialogCreateEditFeedbackTrip_OnOk
{
  #keys: '[146140.0.216521986]'
  Body:
  [*
    // When the user click OK, we either create or edit a feedback operation
    
    data := DataHolderDialogData.Data();
    selection := DataHolderFeedbackTrips.Data().Copy();
    isbatchedit := selection.Size() > 1;
    
    // Not using Data.Attributes because ApplyChanges is not used for feedbacks
    quantity := ApplicationMacroPlanner.FormatStringToReal( EditFieldQuantityUom.Text(), 0.0 );
    description := EditFieldDescription.Text();
    arrival := DateTimeSelectorArrival.DateTime();
    originstockingpointid := DropDownListLaneLeg.Data().OriginStockingPointID(); 
    deststockingpointid := DropDownListLaneLeg.Data().DestinationStockingPointID();
    laneid := DropDownListLaneLeg.Data().LaneID();
    product := DropDownListProduct.Data(); 
    
    // New
    if( isnull( data.WrappedInstance() ) )
    {  
      FeedbackProductInTrip::Create( MacroPlan,
                                     '',  // ID of the feedback. If ID = '', the ID will take MacroPan.IDHolder().GetFeedbackID()
                                     arrival, 
                                     description,
                                     originstockingpointid,
                                     deststockingpointid,
                                     quantity,
                                     laneid,
                                     product.ID(),
                                     false ); // is from db
                                     
    }
    else
    { // Edit
      if( isbatchedit ) // Multiple feedback seleted
      {
        FeedbackProductInTrip::Update( selection, 
                                       quantity,
                                       CheckBoxBatchEditQuantity.Checked(),
                                       description,
                                       CheckBoxBatchEditDescription.Checked() );
      }
      else // Only one feedback
      {
         data.WrappedInstance().Update( arrival,
                                        description,
                                        originstockingpointid,
                                        deststockingpointid,
                                        quantity,
                                        laneid,
                                        product.ID(),
                                        false );
      }
    }
    
    Form.Close();
  *]
}
