<% html_title l(:label_business_report) %> <% money = @report.money %> <% hours = @report.hours %> <% ratios = @report.ratios %> <% max_money = [money[:estimates][:total], money[:invoices][:total], money[:payments][:total]].max.to_f %> <% max_hours = hours.values.max.to_f %> <% bar = ->(value, max) { max > 0 ? (value.to_f / max * 100).round(1) : 0 } %> <% fmt_hours = ->(h) { format('%.1f', h.to_f) } %> <% pct = ->(v) { v.nil? ? '–' : "#{v}%" } %>

<%= l(:label_business_report) %>

<%= form_tag qbo_reports_path, method: :get, id: 'qbo-report-form' do %>
<%= l(:label_report_period) %> <%= select_tag 'period', options_for_select(RedmineQboBilling::BusinessReport::PERIODS.map { |p| [l("label_report_period_#{p}"), p] }, @report.period), id: 'qbo-report-period' %> <%= date_field_tag 'from', @report.from.iso8601, id: 'qbo-report-from' %> – <%= date_field_tag 'to', @report.to.iso8601, id: 'qbo-report-to' %> <%= submit_tag l(:button_apply), name: nil %>
<% end %>

<%= format_date(@report.from) %> – <%= format_date(@report.to) %>

<% if Array(@syncing).any? %> <% sync_labels = { 'Estimate' => l(:label_estimates), 'Invoice' => l(:label_invoices), 'Payment' => l(:label_payments) } %>
<%= l(:text_report_syncing) %>
<%= javascript_tag do %> // Refresh while QuickBooks is syncing, so the figures fill in setTimeout(function () { window.location.reload(); }, 30000); <% end %> <% end %> <% if @report.unsynced_count > 0 %>

<%= l(:text_report_needs_sync, count: @report.unsynced_count) %>

<% end %>

<%= l(:label_report_money) %>

<% [[:estimates, l(:label_report_estimates_written)], [:invoices, l(:label_report_invoices_written)], [:payments, l(:label_report_payments_received)]].each do |key, label| %> <% end %>
<%= label %> (<%= money[key][:count] %>)
<%= number_to_currency(money[key][:total]) %>

<%= l(:label_report_invoiced_of_estimated) %>: <%= pct.call(ratios[:invoiced_of_estimated]) %>
<%= l(:label_report_collected_of_invoiced) %>: <%= pct.call(ratios[:collected_of_invoiced]) %>
<%= l(:label_report_open_balance) %>: <%= number_to_currency(money[:invoices][:balance]) %>

<%= l(:label_report_hours) %>

<% [[:estimate_hours, l(:label_report_estimate_hours)], [:issue_hours, l(:label_report_issue_hours)], [:invoice_hours, l(:label_report_invoice_hours)], [:spent_hours, l(:label_report_spent_hours)]].each do |key, label| %> <% end %>
<%= label %>
<%= fmt_hours.call(hours[key]) %>
<% cpi_badge = lambda do |cpi| level = RedmineQboBilling::BusinessReport.cpi_level(cpi) content_tag(:span, cpi.nil? ? '–' : format('%.2f', cpi), class: "qbo-cpi qbo-cpi-#{level || 'none'}") end %>

<%= l(:label_report_cpi) %> <%= cpi_badge.call(@report.cpi) %> <%= l(:text_report_cpi) %>

<%= l(:label_report_spent_of_estimated) %>: <%= pct.call(ratios[:spent_of_estimated]) %>

<%= l(:label_report_by_month) %>

<% @report.months.each do |row| %> <% end %>
<%= l(:label_month) %> <%= l(:label_report_estimates_written) %> <%= l(:label_report_invoices_written) %> <%= l(:label_report_payments_received) %> <%= l(:label_report_estimate_hours) %> <%= l(:label_report_issue_hours) %> <%= l(:label_report_invoice_hours) %> <%= l(:label_report_spent_hours) %> <%= l(:label_report_cpi_short) %>
<%= ::I18n.t('date.abbr_month_names')[row[:month].month] %> <%= row[:month].year %> <%= number_to_currency(row[:estimates]) %> <%= number_to_currency(row[:invoices]) %> <%= number_to_currency(row[:payments]) %> <%= fmt_hours.call(row[:estimate_hours]) %> <%= fmt_hours.call(row[:issue_hours]) %> <%= fmt_hours.call(row[:invoice_hours]) %> <%= fmt_hours.call(row[:spent_hours]) %> <%= cpi_badge.call(RedmineQboBilling::BusinessReport.cpi(row[:invoice_hours], row[:spent_hours])) %>
<%= l(:label_total) %> <%= number_to_currency(money[:estimates][:total]) %> <%= number_to_currency(money[:invoices][:total]) %> <%= number_to_currency(money[:payments][:total]) %> <%= fmt_hours.call(hours[:estimate_hours]) %> <%= fmt_hours.call(hours[:issue_hours]) %> <%= fmt_hours.call(hours[:invoice_hours]) %> <%= fmt_hours.call(hours[:spent_hours]) %> <%= cpi_badge.call(@report.cpi) %>

<%= l(:text_report_notes) %>

<%= javascript_tag do %> $(function() { var $period = $('#qbo-report-period'), $dates = $('#qbo-report-from, #qbo-report-to'); // Picking a preset fills its dates on Apply; changing a date switches to Custom $dates.on('change', function() { $period.val('custom'); }); $period.on('change', function() { if ($period.val() !== 'custom') { $('#qbo-report-form').submit(); } }); }); <% end %>