# -*- encoding : utf-8 -*-

class Admin::PShipTourTruckSheetLinesController < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space
  
  def admin_space
    @admin_space = "tournees"
  end
  
 
  def edit
  
    
    @p_ship_tour_truck_sheet_line = PShipTourTruckSheetLine.find(params[:id])
    @p_ship_tour_truck = @p_ship_tour_truck_sheet_line.p_ship_tour_truck
    @p_ship_tour= @p_ship_tour_truck.p_ship_tour
  end



  def update
    @p_ship_tour_truck_sheet_line = PShipTourTruckSheetLine.find(params[:id])
    @p_ship_tour_truck = @p_ship_tour_truck_sheet_line.p_ship_tour_truck
    @p_ship_tour= @p_ship_tour_truck.p_ship_tour

    if @p_ship_tour_truck_sheet_line.update_attributes(params.require(:p_ship_tour_truck_sheet_line).permit!)
      
      #redirect_to ship_return_admin_p_ship_tour_path(@p_ship_tour_truck_sheet_line.p_ship_tour_truck.p_ship_tour)
    else
     render action: "edit" 
      
    end
      
  end
  
  
  def destroy
    @p_ship_tour_truck_sheet_line = PShipTourTruckSheetLine.find(params[:id])
    @p_ship_tour_truck_sheet_line.destroy
    
    @p_sheet_line = @p_ship_tour_truck_sheet_line.p_sheet_line
    @p_sheet_line.lock = nil
    @p_sheet_line.save
    @p_sheet_line.p_customer_sheet.update_ship_status
    
    redirect_to :back
  end

end
