From 9ae24ce5f9eee9feb418faab6edd488be83d4b9e Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 24 Mar 2020 22:40:22 +0800 Subject: [PATCH] auto send information for hire on hiring --- app/controllers/property_hires_controller.rb | 2 +- app/helpers/admin/property_hires_helper.rb | 6 +-- app/views/email/p_hire_email.html.erb | 39 ++++++++++++++++++++ app/views/property_hires/hire.html.erb | 24 ++++++------ config/locales/en.yml | 7 +++- config/locales/zh_tw.yml | 39 +++++++++++--------- 6 files changed, 83 insertions(+), 34 deletions(-) diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index 66562ee..53ac132 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -169,7 +169,7 @@ class PropertyHiresController < ApplicationController email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue [] email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0 email << hire.hiring_person_email - HireMethod.send_mail('p_hire',email,property.id) + HireMethod.send_mail('p_hire',email,property.id,nil,hire.id) end redirect_to params[:url] else diff --git a/app/helpers/admin/property_hires_helper.rb b/app/helpers/admin/property_hires_helper.rb index 56aac5a..290d2d8 100644 --- a/app/helpers/admin/property_hires_helper.rb +++ b/app/helpers/admin/property_hires_helper.rb @@ -63,7 +63,7 @@ module Admin::PropertyHiresHelper a = multiple_lang_tag(key_field,markup,"#{key_index}][#{field}",field_sets,custom_options,end_block,{},markup=='text_area') a.html_safe end - def self.send_mail(field_name,email,property_id,send_date=nil) + def self.send_mail(field_name,email,property_id,send_date=nil,hire_id=nil) property = Property.where(id: property_id).first if !property.nil? email_set = property.hire_email_sets.select{|v| v.field_name == field_name} @@ -76,14 +76,14 @@ module Admin::PropertyHiresHelper template:"email/#{field_name}_email.html.erb", mail_sentdate: send_date || Time.current, mail_subject: t("seminar.email_#{field_name}_success"), - template_data:{'property_id'=>property_id,'content'=>content,'locale'=>I18n.locale.to_s}) + template_data:{'property_id'=>property_id,'content'=>content,'locale'=>I18n.locale.to_s,'hire_id'=>hire_id}) elsif !(email_set[0].disabled) 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}) + 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}) end begin mail.deliver diff --git a/app/views/email/p_hire_email.html.erb b/app/views/email/p_hire_email.html.erb index add488e..708af9b 100644 --- a/app/views/email/p_hire_email.html.erb +++ b/app/views/email/p_hire_email.html.erb @@ -5,4 +5,43 @@ <% end %> <% else %> <%= t('property_hire.email_p_hire_content') %> +<% end %> +
+<% I18n.with_locale(@data['locale']) do %> + <% if !@data['hire_id'].nil? %> + <% hire = PHire.where(id: @data['hire_id']).first %> + + + + + + + + + <% ['hiring_person_name','hiring_person_email','start_time','end_time','recurring','recurring_interval','recurring_end_date','passed','reason_for_hire','note_for_hire'].each do |k| %> + <% v = hire.send(k) %> + <% if !v.nil? && !(k.include?('recurring') && hire.recurring != true)%> + + + + + <% end %> + <% end %> + +
+ <%= t("property_hire.#{k}") %>:  + + <% if ['start_time','end_time','recurring','recurring_interval','recurring_end_date','passed'].exclude?(k) %> + <%= v.to_s %> + <% elsif ['start_time','end_time','recurring_end_date'].include?(k) %> + <%= v.strftime('%Y/%m/%d %H:%M') rescue nil %> + <% elsif k == 'recurring_interval' %> + <%= t("property_hire.recurring_interval_types.#{v}") %> + <% elsif 'recurring' == k %> + <%= v ? t('property_hire.yes') : t('property_hire.no') %> + <% else %> + <%= v ? t('property_hire.yes') : t('property_hire.wait_for_permit') %> + <% end %> +
+ <% end %> <% end %> \ No newline at end of file diff --git a/app/views/property_hires/hire.html.erb b/app/views/property_hires/hire.html.erb index 4a157ec..035e4c3 100644 --- a/app/views/property_hires/hire.html.erb +++ b/app/views/property_hires/hire.html.erb @@ -28,34 +28,34 @@ <% end %> <%= form_for hire, :url => "/xhr/property_hires/make_booking", html: { class: "form-horizontal" } do |f| %>
- <%= f.label :start_time, t("property_hires.start_time"), :class => "col-sm-2 control-label" %> + <%= f.label :start_time, t("property_hire.start_time"), :class => "col-sm-2 control-label" %>
<%= f.datetime_picker :start_time, :no_label => true, :new_record => hire.new_record?, :data=>{"picker-type" => "range", "range" => "start", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
- <%= f.label :end_time, t("property_hires.end_time"), :class => "col-sm-2 control-label" %> + <%= f.label :end_time, t("property_hire.end_time"), :class => "col-sm-2 control-label" %>
<%= f.datetime_picker :end_time, :no_label => true, :new_record => hire.new_record?, :data=>{"picker-type" => "range", "range" => "end", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
- <%= f.label :recurring, t("property_hires.recurring"), :class => "col-sm-2 control-label" %> + <%= f.label :recurring, t("property_hire.recurring"), :class => "col-sm-2 control-label" %>
<%= f.check_box :recurring %>
>
- <%= f.label :recurring_interval, t("property_hires.recurring_interval"), :class => "col-sm-2 control-label" %> + <%= f.label :recurring_interval, t("property_hire.recurring_interval"), :class => "col-sm-2 control-label" %>
- <%= f.select :recurring_interval, PHire::INTERVALS.collect{|int| [t("property_hire.recurring_interval_types.#{int}"), int] }, {:prompt => "Select interval"}, {:data => {"fv-validation" => "requiredifrecurring;" , "fv-messages" => "Cannot be empty;"}} %> + <%= f.select :recurring_interval, PHire::INTERVALS.collect{|int| [t("property_hire.recurring_interval_types.#{int}"), int] }, {:prompt => t('property_hire.select_interval')}, {:data => {"fv-validation" => "requiredifrecurring;" , "fv-messages" => "Cannot be empty;"}} %>
- <%= f.label :recurring_end_date, t("property_hires.recurring_end_date"), :class => "col-sm-2 control-label" %> + <%= f.label :recurring_end_date, t("property_hire.recurring_end_date"), :class => "col-sm-2 control-label" %>
<%= f.datetime_picker :recurring_end_date, :no_label => true, :new_record => hire.new_record?, :data=>{"fv-validation" => "requiredifrecurring;", "fv-messages" => "Cannot be empty;"} %>
@@ -89,37 +89,37 @@
- <%= f.label :hiring_person_email, t("property_hires.hiring_person_email"), :class => "col-sm-2 control-label" %> + <%= f.label :hiring_person_email, t("property_hire.hiring_person_email"), :class => "col-sm-2 control-label" %>
<%= f.text_field :hiring_person_email, :class => "form-control", :value => current_user.member_profile.email, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
- <%= f.label :hiring_person_number, t("property_hires.hiring_person_number"), :class => "col-sm-2 control-label" %> + <%= f.label :hiring_person_number, t("property_hire.hiring_person_number"), :class => "col-sm-2 control-label" %>
<%= f.text_field :hiring_person_number, :class => "form-control", :value => current_user.member_profile.mobile_no, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
- <%= f.label :hiring_person_name, t("property_hires.hiring_person_name"), :class => "col-sm-2 control-label" %> + <%= f.label :hiring_person_name, t("property_hire.hiring_person_name"), :class => "col-sm-2 control-label" %>
<%= f.text_field :hiring_person_name, :class => "form-control", :value => (current_user.name rescue ""), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> <%= f.hidden_field :hiring_person_id, :value => (current_user.member_profile.id.to_s rescue "") %>
- <%= f.label :reason_for_hire, t("property_hires.reason_for_hire"), :class => "col-sm-2 control-label" %> + <%= f.label :reason_for_hire, t("property_hire.reason_for_hire"), :class => "col-sm-2 control-label" %>
<%= f.text_field :reason_for_hire, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
- <%= f.label :note_for_hire, t("property_hires.note_for_hire"), :class => "col-sm-2 control-label" %> + <%= f.label :note_for_hire, t("property_hire.note_for_hire"), :class => "col-sm-2 control-label" %>
<%= f.text_area :note_for_hire, :class => "form-control" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 256a218..612b409 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -61,4 +61,9 @@ en: reason_for_hire: Reason For Hire note_for_hire: Note For Hire period: Period - passed: Accepted \ No newline at end of file + passed: Accepted + 'yes': 'Yes' + 'no': 'No' + wait_for_permit: 'Wait for permit' + select_interval: Select interval + check_availibility: Check Availibility \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index d9ad9b3..3e0a4d2 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -11,12 +11,12 @@ zh_tw: auto_send_email_set: 自動發信設定 email_title: 主旨 email_content: 內文 - recurring: Recurring - recurring_interval: Recurring Interval + recurring: 週期性租借 + recurring_interval: 租借週期 recurring_interval_types: - month: Month - week: Week - recurring_end_date: Recurring End Date + month: 月 + week: 周 + recurring_end_date: 週期結束時間 save: Save my_bookings: My Bookings settings: Settings @@ -29,6 +29,8 @@ zh_tw: add_location: Add Location unavailability: Unavailability title: Property Title + select_interval: 選則週期 + check_availibility: 檢查是否可租借 property_usage: Usage for property note: Note property_number: Property Number @@ -39,9 +41,9 @@ zh_tw: owner_email: Owner Email owner_phone: Owner Phone price: Price - set_unavailibility: Set Unavailability - start_time: Start Time - end_time: End Time + set_unavailibility: 設定為不可租借 + start_time: 租借開始時間 + end_time: 租借結束時間 weekdays: Weekdays start_date: From Date end_date: To Date @@ -50,15 +52,18 @@ zh_tw: property_location: Property Location available_for_hire: Available for hire hire: 租借 - view_calendar: Calendar + view_calendar: 租借紀錄 image: Property Image actions: Actions - start_time: Hire Start Time - end_time: Hire End Time - hiring_person_email: Hiring Person Email - hiring_person_number: Hiring Person Number - hiring_person_name: Hiring Person - reason_for_hire: Reason For Hire - note_for_hire: Note For Hire + start_time: 租借開始時間 + end_time: 租借結束時間 + hiring_person_email: 租借人電子信箱 + hiring_person_number: 租借人聯絡電話 + hiring_person_name: 租借人姓名 + reason_for_hire: 租借原因 + note_for_hire: 備註 period: Period - passed: Accepted \ No newline at end of file + passed: 租借允許 + 'yes': 是 + 'no': 否 + wait_for_permit: 等待授權 \ No newline at end of file