From 82cec4139c89f817bb05cf6435db11200d7c273d Mon Sep 17 00:00:00 2001 From: bohung Date: Fri, 22 Jul 2022 09:43:01 +0800 Subject: [PATCH] Fix bug. --- app/models/p_hire.rb | 12 +++++++++--- app/models/property.rb | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/p_hire.rb b/app/models/p_hire.rb index 803703f..323a96e 100644 --- a/app/models/p_hire.rb +++ b/app/models/p_hire.rb @@ -123,17 +123,23 @@ class PHire datet = re.date interval = 1.send(re.recurring_interval) rescue 0 if interval != 0 + org_start = re.start_time @start_date = re.start_time recurring_end_date = re.recurring_end_date new_end_date = [recurring_end_date,end_date].min @end_date = re.end_time if @start_date < start_date add_interval = nil + period_str = nil if re.recurring_interval == "week" - add_interval = ((start_date - @start_date).to_i / 7).send("week") + period_str = 'week' + add_interval = ((start_date - @start_date - 1.day).to_i / 7.day) else - add_interval = ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month) - 1).send("month") + period_str = 'month' + add_interval = ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month) - 1) end + add_interval = 0 if add_interval < 0 + add_interval = add_interval.send(period_str) @start_date += add_interval @end_date += add_interval end @@ -148,7 +154,7 @@ class PHire next end end - if @start_date >= start_date + if @start_date >= start_date && @start_date != org_start @recurring << re.as_json({:startt=>@start_date,:endt=>@end_date,:datet=>datet}) end @start_date += interval diff --git a/app/models/property.rb b/app/models/property.rb index 98721ec..3cbcc44 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -485,7 +485,7 @@ class Property fields_name.each do |field_name| if has_p_hire_fields && field_name.include?("p_hire_fields") rf = p_hire_fields[field_name.sub("p_hire_fields.",'')] - if rf.markup != 'hint_text' && rf.to_require + if rf && rf.markup != 'hint_text' && rf.to_require v = booking_p["p_hire_field_values_attributes"][form_index.to_s]['value'] if cross_lang_types.include?(rf.markup) || rf.get_data["cross_lang"] == "true" if v.blank?