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
|
||||
Reference in new issue
Block a user