Guest User

Untitled

a guest
May 24th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. def show
  2. @page_title = @cliente
  3. @imoveis = @cliente.imoveis
  4. @alugueis_atuais = Aluguel.atuais.all( :conditions => { :imovel_id => @imoveis.map(&:id) } )
  5. @imoveis_alugados = Imovel.all( :conditions => {:id => @alugueis_atuais.map(&:imovel_id)})
  6. @alugueis_anteriores = @cliente.alugueis
  7. @contas = @cliente.contas.a_vencer
  8. @atendimentos = @cliente.atendimentos
  9. @contas_imoveis_all = imobiliaria_atual.contas.all( :conditions => { :referente_id => @alugueis_atuais.map(&:id), :referente_type => 'Aluguel' } )
  10. @contas_imoveis = if params[:busca_de_contas].blank?
  11. paginate(@contas_imoveis_all)
  12. else
  13. @busca = BuscaDeContas.new( params[:busca_de_contas] )
  14. @busca.imobiliaria_id = imobiliaria_atual.id
  15. @busca.cliente_id = @cliente.id
  16. @busca.alugueis = @alugueis_atuais.map(&:id)
  17. @busca.search( :page => @page, :per_page => @per_page )
  18. end
  19. @total_projetado = @contas_imoveis_all.sum(&:valor)
  20. @total_real = 0
  21. @contas_imoveis_all.each{|conta| @total_real+=conta.valor if conta.pagamento_efetuado}
  22.  
  23. @subtotais_reais = {:name => 'Sub-total Real: R$'}
  24. @subtotais_projetados = {:name => 'Sub-total Projetado: R$ '}
  25.  
  26. @imoveis_alugados.each do |imovel|
  27. alugueis = Aluguel.atuais.all( :conditions => { :imovel_id => imovel.id } )
  28. contas = imobiliaria_atual.contas.all( :conditions => { :referente_id => alugueis.map(&:id), :referente_type => 'Aluguel' } )
  29. @subtotais_projetados[imovel.id] = contas.sum(&:valor)
  30. total_real = 0
  31. contas.each{|conta| total_real+=conta.valor if conta.pagamento_efetuado}
  32. @subtotais_reais[imovel.id] = total_real
  33. end
  34. respond_to do |format|
  35. format.html
  36. format.pdf {rghost_render :pdf,
  37. :report => 'export_contas',
  38. :filename => "#{@cliente.nome}_alugueis_#{Time.now.strftime("%d-%m-%y-%H-%M")}.pdf",
  39. :type => 'charset=utf-8;header=present',
  40. :disposition => "attachment"}
  41. end
Add Comment
Please, Sign In to add comment