<% if @fp_fp_nilYear %> <% year = Date.today.year %> <% else %> <% year = @fp_valueYear %> <% end %> PROSPETTO ANNUALE <%= EmoMonth.label.upcase %>
anno <%= year.to_s %>
Campo "Totale mese" per persona, raggruppato per Cassa/Settore
Secondo il filtro
Aggiornato al <%= Date.today.to_dmy %>

<% dates = (1..12).map{|d| DateTime.new(year, d, 1) } %> <% months = I18n.t("date.month_names").drop(1) %> <% functions = EmoFunction.left_joins(:emo_sector).left_joins(:emo_fund).order('emo_funds.codice, emo_sectors.descrizione').pluck(:emo_fund_id, :emo_sector_id).uniq %> <% months.each do |month| %> <% end %> <% totals = Hash[(1..12).map{ |d| [DateTime.new(year, d, 1), 0] } ] %> <% functions.each do |function| %> <% functiontotal = 0 %> <% functiontotals = Hash[(1..12).map{ |d| [DateTime.new(year, d, 1), 0] } ] %> <% fund_id = function[0].to_i %> <% fund = EmoFund.find(fund_id) %> <% sector_id = function[1].to_i %> <% sector = EmoSector.find(sector_id) %> <% emofunctions = EmoFunction.where(emo_sector_id: sector_id, emo_fund_id: fund_id).order(:descrizione) %> <% count_rows_not_null = 0 %> <% emofunctions.each do |emofunction| %> <% rowtotal = 0 %> <% values = Hash[(1..12).map{ |d| [DateTime.new(year, d, 1), 0] } ] %> <% count_month_values_not_null = 0 %> <% dates.each do |date| %> <% value = EmoMonth.search(@filter_params, true).where(competenza: date, emo_function_id: emofunction.id).sum(:totalemese_importo) %> <% if value.blank? %> <% value = 0 %> <% end %> <% values[date] = value %> <% count_month_values_not_null += 1 if value.is_not_zero? %> <% end %> <% if count_month_values_not_null > 0 %> <% count_rows_not_null += 1 %> <% if count_rows_not_null == 1 %> <% end %> <% dates.each do |date| %> <% value = values[date] %> <% rowtotal += value %> <% totals[date] += value %> <% functiontotal += value %> <% functiontotals[date] += value %> <% end %> <% end %> <% end %> <% if count_rows_not_null > 0 %> <% dates.each do |date| %> <% end %> <% end %> <% end %> <% bigtotal = 0 %> <% dates.each do |date| %> <% bigtotal += totals[date] %> <% end %>
Cassa/Settore<%= month %>TOTALE
annuale
persona
<%= "#{fund.codice}/#{sector.descrizione}" %>
<%= "#{emofunction.person.dh_person_name}: #{emofunction.descrizione}" %><%= money_format_zero(value) %><%= money_format_zero(rowtotal) %>
subtotali mese del settore:<%= money_format_zero(functiontotals[date]) %><%= money_format_zero(functiontotal) %>
totali mese delle funzioni:<%= money_format_zero(totals[date]) %><%= money_format_zero(bigtotal) %>