From 12eea8b58eb32aa60fa952e4ed54c4ea8e058f27 Mon Sep 17 00:00:00 2001 From: Bohung Date: Tue, 26 Oct 2021 18:45:14 +0800 Subject: [PATCH] Fix bug.(Add date and time displayed in email when choosing set availability) --- app/helpers/admin/property_hires_helper.rb | 27 +++++++++++++++------- app/models/p_hire.rb | 3 +++ app/views/email/p_hire_email.html.erb | 7 +++++- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/helpers/admin/property_hires_helper.rb b/app/helpers/admin/property_hires_helper.rb index 3542e43..8410d7b 100644 --- a/app/helpers/admin/property_hires_helper.rb +++ b/app/helpers/admin/property_hires_helper.rb @@ -139,20 +139,31 @@ module Admin::PropertyHiresHelper title = property['title'].collect{|k,v| v}.select{|v| !v.to_s.empty?}.join('/') note = property['note'].collect{|k,v| v}.select{|v| !v.to_s.empty?}.join('/') content = "title:#{title}
note:#{note}" + mail_subject = I18n.t("property_hire.email_#{field_name}_success") + email_set_content = nil + enable = false if email_set.length==0 - mail = Email.create(mail_to: Array(email), - module_app_key:"property_hire", - template:"email/#{field_name}_email.html.erb", - mail_sentdate: send_date || Time.current, - mail_subject: I18n.t("property_hire.email_#{field_name}_success"), - template_data:{'property_id'=>property_id,'content'=>content,'locale'=>I18n.locale.to_s,'hire_id'=>hire_id,'user_id'=>user_id}) + enable = true elsif !(email_set[0].disabled) + enable = true + mail_subject = email_set[0].title[I18n.locale] + email_set_content = email_set[0].content.to_yaml + end + if field_name == "p_hire" && (property.set_availability rescue false) + hire = PHire.find(hire_id) rescue nil + if hire + mail_subject += " (#{I18n.t("property_hire.hire_time")}: #{hire.date.to_s.gsub("-","/")} #{hire.time})" + end + end + if enable mail = Email.create(mail_to: Array(email), module_app_key:"property_hire", template:"email/#{field_name}_email.html.erb", mail_sentdate: send_date || Time.current, - mail_subject: email_set[0].title[I18n.locale], - template_data:{'property_id'=>property_id,'email_set_content'=>email_set[0].content.to_yaml,'content'=>content,'locale'=>I18n.locale.to_s,'hire_id'=>hire_id,'user_id'=>user_id}) + mail_subject: mail_subject, + template_data:{'property_id'=>property_id,'email_set_content'=>email_set_content,'content'=>content,'locale'=>I18n.locale.to_s,'hire_id'=>hire_id,'user_id'=>user_id}) + else + return false end begin mail.deliver diff --git a/app/models/p_hire.rb b/app/models/p_hire.rb index a744a48..c05f490 100644 --- a/app/models/p_hire.rb +++ b/app/models/p_hire.rb @@ -33,6 +33,9 @@ class PHire def property_day_setting PropertyDaySetting.find(self.property_day_setting_id) rescue nil end + def time + property_day_setting.title rescue nil + end def as_json(options = {}) startt = self.start_time endt = self.end_time diff --git a/app/views/email/p_hire_email.html.erb b/app/views/email/p_hire_email.html.erb index 6e921f0..db51134 100644 --- a/app/views/email/p_hire_email.html.erb +++ b/app/views/email/p_hire_email.html.erb @@ -28,7 +28,12 @@ <% p_hire_fields = property.p_hire_fields.map{|rf| [rf.id.to_s,rf]}.to_h fields_name = property.get_all_fields - basic_keys = ['hiring_person_name','hiring_person_email','start_time','end_time','recurring','recurring_interval','recurring_end_date','passed'] + basic_keys = [] + if (property.set_availability rescue false) + basic_keys = ['date','time','hiring_person_name','hiring_person_email','recurring','recurring_interval','recurring_end_date','passed'] + else + basic_keys = ['hiring_person_name','hiring_person_email','start_time','end_time','recurring','recurring_interval','recurring_end_date','passed'] + end fields_name = fields_name - basic_keys keys = basic_keys + fields_name keys = keys.select{|field_name| (property[field_name]["enable"] == "1" rescue true) } diff --git a/config/locales/en.yml b/config/locales/en.yml index 73d6505..573c62b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,6 +5,7 @@ en: restful_actions: fields_display_order: "Fields display order" property_hire: + hire_time: Reservation time back_to_hire_page: "Back to Reserve Page" apply_default_time_settings: Apply default time settings default_time_settings: Default time settings diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 312e738..8c92e2e 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -5,6 +5,7 @@ zh_tw: restful_actions: fields_display_order: "欄位顯示順序" property_hire: + hire_time: 預約時間 back_to_hire_page: "回到預約頁面" apply_default_time_settings: 套用預設時段設定 default_time_settings: 預設時段設定