class GestaoDeEstoque::Relatorios::RecebimentosDeMateriaisController < ApplicationController
  include ControllerConcern

	before_action -> { verifica_modulo_na_sessao(["licitacao", "administrativo", "gestao_de_estoque"]) }
	before_action :authenticate_usuario!
	before_action :autoriza_usuario! , except: [:imprimir]

  def imprimir
    bloqueia_usuario_com_base_em :read, "gestao_de_estoque/recebimento_de_materiais"
    relatorio =  params[:relatorio]
    if respond_to? relatorio.to_s, :private
      loa = CombinePDF.new
      loa << CombinePDF.parse(send(relatorio))
      loa.number_pages(location: :bottom_right, margin_from_height: 0, number_format: '%s', font_size: 8)
      send_data loa.to_pdf, filename: "#{relatorio}.pdf", type: "application/pdf", disposition: 'inline'
    else
      redirect_to :back, alert: 'Relatório selecionado não existe'
    end
  end

  def imprimir_recebimento_de_material
    @recebimento_de_material = GestaoDeEstoque::RecebimentoDeMaterial.find(params[:recebimento_de_material_id])
    render_to_string pdf: "recebimento_de_material",
      template: "gestao_de_estoque/relatorios/recebimentos_de_materiais/imprimir_recebimento_de_material.pdf.slim",
      orientation: 'Portrait',
      disable_smart_shrinking: true,
      
      dpi: '96',
      header: {
        html: {
          template: 'layouts/_cabecalho_pdf.html.slim',
          locals: {
            titulo1: "#{@recebimento_de_material.unidade_orcamentaria.unidade_gestora.nome}",
            titulo2: "RECEBIMENTO DE MATERIAL Nº " + @recebimento_de_material.codigo
          }
        },
        spacing: 5
      },
      footer: {
				html: {
					template: 'layouts/_rodape_pdf.html.slim'
				}
			},
      margin: configuracao.margens_customizadas
  end

  def imprimir_termo_de_recebimento_provisorio
    @recebimento_de_material = GestaoDeEstoque::RecebimentoDeMaterial.find(params[:recebimento_de_material_id])
    render_to_string pdf: "recebimento_de_material",
      template: "gestao_de_estoque/relatorios/recebimentos_de_materiais/imprimir_termo_de_recebimento_provisorio.pdf.slim",
      orientation: 'Portrait',
      disable_smart_shrinking: true,
      
      dpi: '96',
      header: {
        html: {
          template: 'layouts/_cabecalho_pdf.html.slim',
          locals: {
            titulo1: "#{@recebimento_de_material.unidade_orcamentaria.unidade_gestora.nome}",
            titulo2: "RECEBIMENTO DE MATERIAL Nº " + @recebimento_de_material.codigo
          }
        },
        spacing: 5
      },
      footer: {
				html: {
					template: 'layouts/_rodape_pdf.html.slim'
				}
			},
      margin: configuracao.margens_customizadas
  end

  def imprimir_termo_de_recebimento_definitivo
    @recebimento_de_material = GestaoDeEstoque::RecebimentoDeMaterial.find(params[:recebimento_de_material_id])
    render_to_string pdf: "recebimento_de_material",
      template: "gestao_de_estoque/relatorios/recebimentos_de_materiais/imprimir_termo_de_recebimento_definitivo.pdf.slim",
      orientation: 'Portrait',
      disable_smart_shrinking: true,
      
      dpi: '96',
      header: {
        html: {
          template: 'layouts/_cabecalho_pdf.html.slim',
          locals: {
            titulo1: "#{@recebimento_de_material.unidade_orcamentaria.unidade_gestora.nome}",
            titulo2: "RECEBIMENTO DE MATERIAL Nº " + @recebimento_de_material.codigo
          }
        },
        spacing: 5
      },
      footer: {
				html: {
					template: 'layouts/_rodape_pdf.html.slim'
				}
			},
      margin: configuracao.margens_customizadas
  end

  def imprimir_termo_de_recebimento_externo_definitivo
    @recebimento_de_material = GestaoDeEstoque::RecebimentoDeMaterial.find(params[:recebimento_de_material_id])
    render_to_string pdf: "recebimento_de_material",
      template: "gestao_de_estoque/relatorios/recebimentos_de_materiais/imprimir_termo_de_recebimento_externo_definitivo.pdf.slim",
      orientation: 'Portrait',
      disable_smart_shrinking: true,
      
      dpi: '96',
      header: {
        html: {
          template: 'layouts/_cabecalho_pdf.html.slim',
          locals: {
            titulo1: "#{@recebimento_de_material.unidade_orcamentaria.unidade_gestora.nome}",
            titulo2: "RECEBIMENTO DE MATERIAL Nº " + @recebimento_de_material.codigo
          }
        },
        spacing: 5
      },
      footer: {
				html: {
					template: 'layouts/_rodape_pdf.html.slim'
				}
			},
      margin: configuracao.margens_customizadas
  end

end
