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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "ventes"
  end
  
  def index
    @order_hist_lines = OrderHistLine.all

    @order_hist_lines = sort_by_sorting(@order_hist_lines, "id DESC")
    respond_to do |format|
      format.html{
      
        params[:search][:per_page] = params[:search][:per_page] || 100
        per_page = params[:search][:per_page]
        page = (params[:page] and params[:page] != "") ? params[:page] : 1 
        @order_hist_lines = @order_hist_lines.page(page).per(per_page)
      
      }
    end
  end

  def show
    @order_hist_line = OrderHistLine.find(params[:id])

  end

  def new
    @order_hist_line = OrderHistLine.new
  
  end

  def edit
    @order_hist_line = OrderHistLine.find(params[:id])
    
  end

  def create
    @order_hist_line = OrderHistLine.new(params.require(:order_hist_line).permit!)

    if @order_hist_line.save
      
    else
      render action: "new"
 
    end

  end


  def update
    @order_hist_line = OrderHistLine.find(params[:id])


    if @order_hist_line.update_attributes(params.require(:order_hist_line).permit!)
      
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @order_hist_line = OrderHistLine.find(params[:id])
    @order_hist_line.destroy
    
  end
end
