5 Commits
Author SHA1 Message Date
ricky d3b9441f25 2026.9.2 2026-09-09 21:43:55 -04:00
ricky 852d2119a0 Fix over-calculation of hours for multi-day appointments
Updates the calendar view to distribute multi-day appointment hours
across working days, capping each day at 8 hours. This prevents the
total hours from being added to every day and ensures appointments
with fewer hours than their maximum duration don't artificially
inflate daily labor totals.
2026-09-09 21:43:22 -04:00
ricky 041a6441fe 2026.9.1 2026-09-09 21:14:52 -04:00
ricky 0e54316eac Refactor indentation in view_hook_listener.rb for improved readability 2026-09-08 22:39:09 -04:00
ricky 250442db9d removed trailing / 2026-09-08 08:24:00 -04:00
4 changed files with 38 additions and 11 deletions

No files matched your search

+28 -1
View File
@@ -173,7 +173,34 @@
if event.is_a?(Issue)
event.estimated_hours.to_f
elsif event.is_a?(CustomerAppointment)
if event.respond_to?(:estimated_hours) && event.estimated_hours.present?
if event.duration.to_i > 1
# Get the total hours (fallback to duration * 8 if estimated_hours is blank)
app_total_hours = if event.respond_to?(:estimated_hours) && event.estimated_hours.present?
event.estimated_hours.to_f
else
event.duration.to_f * 8.0
end
start_date = (event.respond_to?(:date) && event.date.present? ? event.date : event.start_date).to_date
# Count how many working days occurred before the current calendar 'day'
working_day_index = 0
date_cursor = start_date
while date_cursor < day
is_weekend = non_working_days.include?(date_cursor.cwday.to_s)
is_holiday = all_holidays.any? { |h| h.occurs_on?(date_cursor) }
working_day_index += 1 unless is_weekend || is_holiday
date_cursor += 1
end
# Subtract previous days' hours (8h/day) from the total
hours_already_allocated = working_day_index * 8.0
remaining_hours = app_total_hours - hours_already_allocated
# Allocate up to 8 hours for today, but don't go below 0
[[remaining_hours, 8.0].min, 0.0].max
elsif event.respond_to?(:estimated_hours) && event.estimated_hours.present?
event.estimated_hours.to_f
else
event.duration.to_f
@@ -2,5 +2,5 @@
<p>
<% customer = context[:customer] %>
<%= link_to l(:label_add_appointment), new_customer_appointment_path(customer_id: customer.id), target: :_blank, id: :appointment_link %>
</p>\
</p>
<% end %>
+1 -1
View File
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo_calendar do
name 'Redmine QBO Calendar plugin'
author 'Rick Barrette'
description 'A plugin for Redmine to extend the capabilitys of the Redmine QuickBooks Online plugin to create customer appointments for the Redmine Calendar'
version '2026.9.0'
version '2026.9.2'
url 'https://github.com/rickbarrette/redmine_qbo_calendar'
author_url 'https://barrettefabrication.com'
requires_redmine version_or_higher: '7.0.0'
@@ -13,14 +13,14 @@ module RedmineQboCalendar
class ViewHookListener < Redmine::Hook::ViewListener
# Load the javascript and stylesheet assets
def view_layouts_base_html_head(context = {})
safe_join([
javascript_include_tag("customer_appointments", plugin: :redmine_qbo_calendar),
stylesheet_link_tag('customer_appointments', plugin: :redmine_qbo_calendar),
javascript_include_tag('https://kit.fontawesome.com/4be4394b21.js', crossorigin: 'anonymous')
])
end
# Load the javascript and stylesheet assets
def view_layouts_base_html_head(context = {})
safe_join([
javascript_include_tag("customer_appointments", plugin: :redmine_qbo_calendar),
stylesheet_link_tag('customer_appointments', plugin: :redmine_qbo_calendar),
javascript_include_tag('https://kit.fontawesome.com/4be4394b21.js', crossorigin: 'anonymous')
])
end
end
end