From bfa13398a956d69d7dbb9f9cefe905b5dc6479af Mon Sep 17 00:00:00 2001 From: Thomas Burkhalter Date: Tue, 29 Oct 2024 13:58:43 +0100 Subject: [PATCH] Show orders without hours on closed order reports --- app/controllers/order_reports_controller.rb | 5 +++++ app/domain/order/report.rb | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/order_reports_controller.rb b/app/controllers/order_reports_controller.rb index 7fd16793..e48062fa 100644 --- a/app/controllers/order_reports_controller.rb +++ b/app/controllers/order_reports_controller.rb @@ -15,6 +15,7 @@ class OrderReportsController < ApplicationController major_risk_value] before_action :authorize_class + before_action :show_without_hours def index set_period @@ -35,6 +36,10 @@ def index private + def show_without_hours + params[:without_hours] = true if params[:closed].presence + end + def set_filter_values @departments = Department.list @clients = WorkItem.joins(:client).list diff --git a/app/domain/order/report.rb b/app/domain/order/report.rb index d9e60f0a..853bbd9a 100644 --- a/app/domain/order/report.rb +++ b/app/domain/order/report.rb @@ -45,7 +45,7 @@ def limit_value def filters_defined? filters = params.except(:action, :controller, :format, :utf8, :page, - :clear, :closed) + :clear, :closed, :without_hours) filters.present? && filters.values.any?(&:present?) end @@ -126,11 +126,20 @@ def invoices_to_hash(result) def build_entry(order, accounting_posts, hours, invoices) posts = accounting_posts[order.id] post_hours = hours.slice(*posts.keys) - return unless post_hours.values.any? { |h| h.values.sum > 0.0001 } + + return unless show_without_hours? || booked_hours?(post_hours) Order::Report::Entry.new(order, posts, post_hours, invoices[order.id]) end + def show_without_hours? + params[:without_hours].presence || false + end + + def booked_hours?(post_hours) + post_hours.values.any? { |h| h.values.sum > 0.0001 } + end + def filter_by_parent(orders) if params[:category_work_item_id].present? orders.where('? = ANY (work_items.path_ids)', params[:category_work_item_id])