mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-17 18:20:36 -05:00
Business report: project filter, remembered per user
- Projects picker (project tree, visible projects only) limits issues' estimated time and spent time to the chosen projects, in the totals, charts, last-year lines and months; none picked is every project - Estimates, invoices and payments have no project in QuickBooks, so they stay whole-business; the page says so while filtered (the CPI's invoiced hours included) - "Remember these projects" saves the choice in the user's Redmine preferences; the report opens with it when the address has no projects, and saving none goes back to every project Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f2cef2bc8
commit
51159d5034
5 files changed
+91
-8
No files matched your search
@@ -15,13 +15,48 @@ class QboReportsController < ApplicationController
|
||||
|
||||
before_action :authorize_global
|
||||
|
||||
# The user's preference holding the projects the report opens with
|
||||
PROJECTS_PREF = :qbo_report_project_ids
|
||||
|
||||
def index
|
||||
# Projects for the issues and spent time: the projects picker can choose some
|
||||
@projects = Project.visible.to_a
|
||||
@project_ids = report_project_ids
|
||||
@report = RedmineQboBilling::BusinessReport.new(period: params[:period].presence || 'this_year',
|
||||
from: params[:from], to: params[:to], today: User.current.today,
|
||||
week_start: RedmineQboBilling::BusinessReport.week_start_from_setting(Setting.start_of_week))
|
||||
week_start: RedmineQboBilling::BusinessReport.week_start_from_setting(Setting.start_of_week),
|
||||
project_ids: @project_ids)
|
||||
# Last year's lines on the charts
|
||||
@compare = params[:compare] == '1'
|
||||
# Syncs still running for what the report counts: its figures are incomplete until they finish
|
||||
@syncing = QboSyncStatus.by_entity(%w[Estimate Invoice Payment]).values.sort_by(&:entity)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# The form's projects (none picked is every project), or the user's saved ones when the address has none.
|
||||
# "Remember these projects" saves the form's choice. Only projects the user can see are kept.
|
||||
def report_project_ids
|
||||
visible = @projects.map(&:id)
|
||||
if params.key?(:project_ids)
|
||||
ids = Array(params[:project_ids]).map(&:to_i) & visible
|
||||
save_project_ids(ids) if params[:save_projects] == '1'
|
||||
else
|
||||
ids = saved_project_ids & visible
|
||||
end
|
||||
@saved_project_ids = saved_project_ids & visible
|
||||
ids
|
||||
end
|
||||
|
||||
def saved_project_ids
|
||||
return [] unless User.current.logged?
|
||||
Array(User.current.pref[PROJECTS_PREF]).map(&:to_i)
|
||||
end
|
||||
|
||||
def save_project_ids(ids)
|
||||
return unless User.current.logged?
|
||||
pref = User.current.pref
|
||||
pref[PROJECTS_PREF] = ids
|
||||
pref.save
|
||||
end
|
||||
end
|
||||
@@ -64,10 +64,36 @@
|
||||
<%= check_box_tag 'compare', '1', @compare, id: 'qbo-report-compare' %>
|
||||
<%= l(:label_report_compare_last_year) %>
|
||||
</label>
|
||||
<%# Projects for the issues and spent time; the blank value sends project_ids when none are picked (every project) %>
|
||||
<div class="qbo-report-projects">
|
||||
<label for="qbo-report-project-ids"><%= l(:label_project_plural) %></label>
|
||||
<%= hidden_field_tag 'project_ids[]', '', id: nil %>
|
||||
<%= select_tag 'project_ids[]',
|
||||
project_tree_options_for_select(@projects, selected: @projects.select { |p| @project_ids.include?(p.id) }),
|
||||
multiple: true, size: [[@projects.size, 3].max, 8].min, id: 'qbo-report-project-ids' %>
|
||||
<span class="qbo-report-projects-options">
|
||||
<em class="info"><%= l(:text_report_projects) %></em>
|
||||
<label>
|
||||
<%= check_box_tag 'save_projects', '1', false, id: 'qbo-report-save-projects' %>
|
||||
<%= l(:label_report_remember_projects) %>
|
||||
</label>
|
||||
<% if @saved_project_ids.any? %>
|
||||
<em class="info"><%= l(:text_report_saved_projects, projects: @projects.select { |p| @saved_project_ids.include?(p.id) }.map(&:name).join(', ')) %></em>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
<p class="qbo-report-range"><%= format_date(@report.from) %> – <%= format_date(@report.to) %></p>
|
||||
<p class="qbo-report-range">
|
||||
<%= format_date(@report.from) %> – <%= format_date(@report.to) %>
|
||||
<% if @report.projects_filtered? %>
|
||||
· <%= l(:label_project_plural) %>: <%= @projects.select { |p| @project_ids.include?(p.id) }.map(&:name).join(', ') %>
|
||||
<% end %>
|
||||
</p>
|
||||
<% if @report.projects_filtered? %>
|
||||
<p class="info qbo-report-projects-note"><%= l(:text_report_projects_filtered) %></p>
|
||||
<% end %>
|
||||
|
||||
<% if Array(@syncing).any? %>
|
||||
<% sync_labels = { 'Estimate' => l(:label_estimates), 'Invoice' => l(:label_invoices), 'Payment' => l(:label_payments) } %>
|
||||
@@ -230,6 +256,10 @@
|
||||
table.qbo-report-months tfoot td { border-top: 2px solid #ccc; }
|
||||
#qbo-report-form select, #qbo-report-form input { vertical-align: middle; }
|
||||
#qbo-report-form .qbo-report-compare { margin-left: 12px; white-space: nowrap; }
|
||||
#qbo-report-form .qbo-report-projects { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px 10px; margin-top: 8px; }
|
||||
#qbo-report-form .qbo-report-projects select { min-width: 220px; max-width: 100%; }
|
||||
#qbo-report-form .qbo-report-projects-options { display: flex; flex-direction: column; gap: 4px; }
|
||||
#qbo-report-form .qbo-report-projects-options label { white-space: nowrap; }
|
||||
.qbo-report-chart { position: relative; height: 260px; margin: 4px 4px 16px; }
|
||||
</style>
|
||||
|
||||
|
||||
Reference in new issue
Block a user