mirror of
https://github.com/we-promise/sure.git
synced 2026-04-20 12:34:12 +00:00
Merge pull request #370 from we-promise/copilot/fix-custom-range-error
Fix 500 error when custom date range end date precedes start date
This commit is contained in:
@@ -11,6 +11,9 @@ class ReportsController < ApplicationController
|
||||
@start_date = parse_date_param(:start_date) || default_start_date
|
||||
@end_date = parse_date_param(:end_date) || default_end_date
|
||||
|
||||
# Validate and fix date range if end_date is before start_date
|
||||
validate_and_fix_date_range(show_flash: true)
|
||||
|
||||
# Build the period
|
||||
@period = Period.custom(start_date: @start_date, end_date: @end_date)
|
||||
@previous_period = build_previous_period
|
||||
@@ -41,6 +44,11 @@ class ReportsController < ApplicationController
|
||||
@period_type = params[:period_type]&.to_sym || :monthly
|
||||
@start_date = parse_date_param(:start_date) || default_start_date
|
||||
@end_date = parse_date_param(:end_date) || default_end_date
|
||||
|
||||
# Validate and fix date range if end_date is before start_date
|
||||
# Don't show flash message since we're returning CSV data
|
||||
validate_and_fix_date_range(show_flash: false)
|
||||
|
||||
@period = Period.custom(start_date: @start_date, end_date: @end_date)
|
||||
|
||||
# Build monthly breakdown data for export
|
||||
@@ -93,6 +101,14 @@ class ReportsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def validate_and_fix_date_range(show_flash: false)
|
||||
return unless @start_date > @end_date
|
||||
|
||||
# Swap the dates to maintain user's intended date range
|
||||
@start_date, @end_date = @end_date, @start_date
|
||||
flash.now[:alert] = t("reports.invalid_date_range") if show_flash
|
||||
end
|
||||
|
||||
def ensure_money(value)
|
||||
return value if value.is_a?(Money)
|
||||
# Value is numeric (BigDecimal or Integer) in dollars - pass directly to Money.new
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%# Flash messages %>
|
||||
<% if flash[:alert].present? %>
|
||||
<div class="p-3 rounded-lg bg-destructive-surface text-sm text-destructive">
|
||||
<%= flash[:alert] %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%# Period Navigation Tabs %>
|
||||
<div class="flex items-center gap-2 overflow-x-auto pb-2">
|
||||
<%= render DS::Link.new(
|
||||
|
||||
Reference in New Issue
Block a user