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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @stock_movement_lines = StockMovementLine.all

    @stock_movement_lines = sort_by_sorting(@stock_movement_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 
        @stock_movement_lines = @stock_movement_lines.page(page).per(per_page)
      
      }
    end
  end

  def show
    @stock_movement_line = StockMovementLine.find(params[:id])

  end

  def new
    @stock_movement_line = StockMovementLine.new
  
  end

  def edit
    @stock_movement_line = StockMovementLine.find(params[:id])
    
  end

  def create
    @stock_movement_line = StockMovementLine.new(params.require(:stock_movement_line).permit!)

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

  end


  def update
    @stock_movement_line = StockMovementLine.find(params[:id])


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


  def destroy
    @stock_movement_line = StockMovementLine.find(params[:id])
    @stock_movement_line.destroy
    
  end
end
