mirror of
https://github.com/rickbarrette/redmine_qbo_calendar.git
synced 2026-10-03 20:40:43 -04:00
Add holiday management functionality with CRUD operations
- Implement HolidaysController for managing holidays - Create Holiday model with validation for recurrence types - Add holiday form and views for creating, editing, and listing holidays - Integrate holiday checks into customer appointment scheduling - Update locale file for holiday-related labels and error messages - Add migration for holidays table - Update plugin version and add holidays to admin menu
This commit is contained in:
1 parent
9a8787c3da
commit
167e956457
12 files changed
+407
-9
No files matched your search
@@ -18,6 +18,9 @@ class CustomerAppointment < ActiveRecord::Base
|
||||
|
||||
validates :subject, presence: true
|
||||
validates :date, presence: true
|
||||
|
||||
# Prevent scheduling on non-working days or holidays
|
||||
validate :validate_working_day
|
||||
|
||||
normalizes :subject, with: ->(subject) { subject.strip.titleize }
|
||||
|
||||
@@ -115,6 +118,23 @@ class CustomerAppointment < ActiveRecord::Base
|
||||
Rails.logger.info "[CustomerAppointment] #{msg}"
|
||||
end
|
||||
|
||||
# Validates that the appointment date does not land on a weekend or holiday
|
||||
def validate_working_day
|
||||
return if date.blank?
|
||||
|
||||
target_date = date.to_date
|
||||
non_working_days = Setting.non_working_week_days || []
|
||||
|
||||
if non_working_days.include?(target_date.cwday.to_s)
|
||||
errors.add(:date, :invalid, message: I18n.t(:error_non_working_day))
|
||||
elsif defined?(Holiday)
|
||||
matched_holiday = Holiday.all.find { |h| h.occurs_on?(target_date) }
|
||||
if matched_holiday.present?
|
||||
errors.add(:date, :invalid, message: I18n.t(:error_holiday, name: matched_holiday.name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Helper to parse item name across Quickbooks::Model::Line and Hash structures
|
||||
def extract_item_name(line)
|
||||
if line.respond_to?(:sales_line_item_detail) && line.sales_line_item_detail.present?
|
||||
|
||||
Reference in new issue
Block a user