<% if Region.exists_region_qecs(current_region.id, current_month) %>
NOTA:
gli incassi <%= PensionFund.label %> di <%= daterange_name(current_month) %> non si possono eseguire
perché <%= current_house.descrizione %> appartiene alla <%= "#{current_region.region_type.descrizione} di #{current_region.descrizione}" %>:
gli incassi vanno eseguiti dalla <%= iconlink_to(region_path(current_region), icon('external-link-alt'), "scheda di #{current_region.descrizione}") %>.
<% totale_importo_effettivo = 0.0 %>
<% totale_incassato = 0.0 %>
<% totale_da_incassare = 0.0 %>
<%= view_table_open %>
<%= view_table_head_open %>
<%= view_table_row_open %>
<%= view_table_head_cell_span 2 %>
<%= view_table_head_cell PensionFund.human_attribute_name(:person_id) %>
<%= view_table_head_cell ('Importo calcolato') %>
<%= view_table_head_cell PensionFund.human_attribute_name(:importo) %>
<%= view_table_head_cell ('Versato') %>
<%= view_table_head_cell ('Da incassare') %>
<%= view_table_head_cell raw(SrgPnCostcenter.label(1) + "
destinazione") %>
<%= view_table_head_cell raw(SrgCrb.label(1) + "
destinazione") %>
<%= view_table_row_close %>
<%= view_table_head_close %>
<%= view_table_body_open %>
<% members.each do |member| %>
<% if !current_house.was_member_on(member.id, current_month) %>
<% next %>
<% end %>
<% member_calcolato = 0.0 %>
<% member_effettivo = 0.0 %>
<% funds = PensionFund.where(competenza: current_month, person_id: member.id) %>
<% funds.each do |fund| %>
<% member_calcolato += fund.calc_importo %>
<% member_effettivo += fund.importo %>
<% end %>
<% member_versato = PensionFund.get_versato(current_month, member.id) %>
<% quanto_versare = member_effettivo - member_versato %>
<% totale_importo_effettivo += member_effettivo %>
<% totale_incassato += member_versato %>
<% totale_da_incassare += quanto_versare %>
<% row_code = "#{PensionFundsHelper::PrefixIncasso}#{member.id}" %>
<%= view_table_row_open %>
<%= view_table_cell ( funds.any? ? iconbutton_view(funds.first, '') : '' ) %>
<%= view_table_cell ( funds.any? ? iconbutton_edit(edit_pension_fund_path(funds.first), '') : '' ) %>
<%= view_table_cell (link_to(member.dh_person_name, person_path(member))) %>
<%= view_table_cell_right ( money_format(member_calcolato) ) %>
<%= view_table_cell_right ( money_format(member_effettivo) ) %>
<%= view_table_cell_right ( money_format(member_versato) ) %>
<%= view_table_cell_right ( money_format(quanto_versare) ) %>
<%= view_table_cell (link_to(notetext(PensionFundsHelper::PensionFund_QecFund.srg_pn_costcenter.format_for_formselect), srg_pn_costcenter_path(PensionFundsHelper::PensionFund_QecFund.srg_pn_costcenter_id))) %>
<%= view_table_cell (link_to(notetext(PensionFundsHelper::PensionFund_Crb.format_for_formselect), srg_crb_path(PensionFundsHelper::PensionFund_Crb.id))) %>
<%= view_table_row_close %>
<% end %>
<%= view_table_row_open %>
<%= view_table_cell_span_right 4, ('
TOTALI:') %>
<%= view_table_cell_right ( money_format(totale_importo_effettivo) ) %>
<%= view_table_cell_right ( money_format(totale_incassato) ) %>
<%= view_table_cell_right ( money_format(totale_da_incassare) ) %>
<%= view_table_cell (nil) %>
<%= view_table_cell (nil) %>
<%= view_table_row_close %>
<%= view_table_body_close %>
<%= view_table_close %>
<% else %>
<% totale_importo_effettivo = 0.0 %>
<% totale_incassato = 0.0 %>
<% totale_da_incassare = 0.0 %>
<%= form_tag(house_path(current_house), method: :get, remote: true) do %>
<%= hidden_field_tag :competenza, current_month %>
<%= view_table_open %>
<%= view_table_head_open %>
<%= view_table_row_open %>
<%= view_table_head_cell_span 2 %>
<%= view_table_head_cell PensionFund.human_attribute_name(:person_id) %>
<%= view_table_head_cell ('Importo calcolato') %>
<%= view_table_head_cell PensionFund.human_attribute_name(:importo) %>
<%= view_table_head_cell ('Versato') %>
<% if policy(PensionFund).update? %>
<%= view_table_head_cell ('Da incassare') %>
<% data_incasso = Date.today %>
<%= view_table_head_cell (date_input_tag(SrgPnsHelper::DataIncasso_ParamsKey, data_incasso,false,"startDate:'#{Date.today.to_dmy}'") + 'data incasso' ) %>
<% else %>
<%= view_table_head_cell ('Da incassare') %>
<% end %>
<%= view_table_head_cell raw(SrgPnCostcenter.label(1) + "
destinazione") %>
<%= view_table_head_cell raw(SrgCrb.label(1) + "
destinazione") %>
<%= view_table_row_close %>
<%= view_table_head_close %>
<%= view_table_body_open %>
<% members.each do |member| %>
<% if !current_house.was_member_on(member.id, current_month) %>
<% next %>
<% end %>
<% member_calcolato = 0.0 %>
<% member_effettivo = 0.0 %>
<% funds = PensionFund.where(competenza: current_month, person_id: member.id) %>
<% funds.each do |fund| %>
<% member_calcolato += fund.calc_importo %>
<% member_effettivo += fund.importo %>
<% end %>
<% member_versato = PensionFund.get_versato(current_month, member.id) %>
<% quanto_versare = member_effettivo - member_versato %>
<% totale_importo_effettivo += member_effettivo %>
<% totale_incassato += member_versato %>
<% totale_da_incassare += quanto_versare %>
<% row_code = "#{PensionFundsHelper::PrefixIncasso}#{member.id}" %>
<%= view_table_row_open %>
<%= view_table_cell ( funds.any? ? iconbutton_view(funds.first, '') : '' ) %>
<%= view_table_cell ( funds.any? ? iconbutton_edit(edit_pension_fund_path(funds.first), '') : '' ) %>
<%= view_table_cell (link_to(member.dh_person_name, person_path(member))) %>
<%= view_table_cell_right ( money_format(member_calcolato) ) %>
<%= view_table_cell_right ( money_format(member_effettivo) ) %>
<%= view_table_cell_right ( money_format(member_versato) ) %>
<% if policy(PensionFund).update? %>
<%= view_table_cell_right ( quanto_versare.is_zero? ? 0.0 : number_field_tag(row_code, money_format(quanto_versare), step: :any, style: 'text-align: right;' ) ) %>
<%= view_table_cell ( quanto_versare.is_zero? ? nil : iconbutton_submit(icon('euro-sign'), 'btn-success btn-xs', "Incassa", SrgPnsHelper::IncassoFondopensione, row_code) ) %>
<% else %>
<%= view_table_cell_right ( money_format(quanto_versare) ) %>
<% end %>
<%= view_table_cell (link_to(notetext(PensionFundsHelper::PensionFund_QecFund.srg_pn_costcenter.format_for_formselect), srg_pn_costcenter_path(PensionFundsHelper::PensionFund_QecFund.srg_pn_costcenter_id))) %>
<%= view_table_cell (link_to(notetext(PensionFundsHelper::PensionFund_Crb.format_for_formselect), srg_crb_path(PensionFundsHelper::PensionFund_Crb.id))) %>
<%= view_table_row_close %>
<% end %>
<%= view_table_row_open %>
<%= view_table_cell_span_right 4, ('
TOTALI:') %>
<%= view_table_cell_right ( money_format(totale_importo_effettivo) ) %>
<%= view_table_cell_right ( money_format(totale_incassato) ) %>
<% if policy(PensionFund).update? %>
<%= view_table_cell_right ( money_format(totale_da_incassare) ) %>
<% if totale_da_incassare.is_not_zero? %>
<% row_code = PensionFundsHelper::IncassaTutto %>
<%= view_table_cell ( iconbutton_submit(icon('euro-sign'), 'btn-success btn-xs', "Incassa tutti", SrgPnsHelper::IncassoFondopensione, row_code) ) %>
<% end %>
<% else %>
<%= view_table_cell_right ( money_format(totale_da_incassare) ) %>
<% end %>
<%= view_table_cell (nil) %>
<%= view_table_cell (nil) %>
<%= view_table_row_close %>
<%= view_table_body_close %>
<%= view_table_close %>
<% end %>
<% end %>