module Licitacao
class ItensDoLoteDoPedidoController < ApplicationController
	include ControllerConcern
	before_action :authenticate_usuario!
	before_action :autoriza_usuario!
	before_action :set_item_do_lote_do_pedido, only: [:show, :edit, :update, :destroy]

	# GET /licitacao/itens_do_lote_do_pedido
	def index
		@q = ItemDoLoteDoPedido.order(:id).search(params[:q])
		@itens_do_lote_do_pedido = @q.result(distinct: false).paginate(page: params[:page], per_page: 10)
	end

	# GET /licitacao/itens_do_lote_do_pedido/1
	def show
	end

	# GET /licitacao/itens_do_lote_do_pedido/new
	def new
		@item_do_lote_do_pedido = ItemDoLoteDoPedido.new
	end

	# GET /licitacao/itens_do_lote_do_pedido/1/edit
	def edit
	end

	# POST /licitacao/itens_do_lote_do_pedido
	def create
		@item_do_lote_do_pedido = ItemDoLoteDoPedido.new(item_do_lote_do_pedido_params)

		if @item_do_lote_do_pedido.save
			redirect_to @item_do_lote_do_pedido, notice: 'Item do lote do pedido foi criado(a) com sucesso.'
		else
			render :new
		end
	end

	# PATCH/PUT /licitacao/itens_do_lote_do_pedido/1
	def update
		if @item_do_lote_do_pedido.update( item_do_lote_do_pedido_params )
			redirect_to @item_do_lote_do_pedido, notice: 'Item do lote do pedido foi atualizado(a) com sucesso.'
		else
			render :edit
		end
	end

	# DELETE /licitacao/itens_do_lote_do_pedido/1
	def destroy
		mensagem = apaga_e_retorna_mensagem(@item_do_lote_do_pedido)
		redirect_to licitacao_itens_do_lote_do_pedido_url, mensagem
	end

	private
	def set_item_do_lote_do_pedido
		@item_do_lote_do_pedido = ItemDoLoteDoPedido.find( params[:id] )
	end

	# Permite apenas os parâmetros específicos
	def item_do_lote_do_pedido_params
		params.require(:licitacao_item_do_lote_do_pedido).permit(:lote_do_pedido_id, :item_do_pedido_id, :ordem)
		
	end
end
end
