auto send information for hire on hiring

This commit is contained in:
chiu 2020-03-24 22:40:22 +08:00
parent 1a985bad64
commit 9ae24ce5f9
6 changed files with 83 additions and 34 deletions

View File

@ -169,7 +169,7 @@ class PropertyHiresController < ApplicationController
email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue [] 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 = 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 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 end
redirect_to params[:url] redirect_to params[:url]
else else

View File

@ -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 = multiple_lang_tag(key_field,markup,"#{key_index}][#{field}",field_sets,custom_options,end_block,{},markup=='text_area')
a.html_safe a.html_safe
end 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 property = Property.where(id: property_id).first
if !property.nil? if !property.nil?
email_set = property.hire_email_sets.select{|v| v.field_name == field_name} 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", template:"email/#{field_name}_email.html.erb",
mail_sentdate: send_date || Time.current, mail_sentdate: send_date || Time.current,
mail_subject: t("seminar.email_#{field_name}_success"), 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) elsif !(email_set[0].disabled)
mail = Email.create(mail_to: Array(email), mail = Email.create(mail_to: Array(email),
module_app_key:"property_hire", module_app_key:"property_hire",
template:"email/#{field_name}_email.html.erb", template:"email/#{field_name}_email.html.erb",
mail_sentdate: send_date || Time.current, mail_sentdate: send_date || Time.current,
mail_subject: email_set[0].title[I18n.locale], 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 end
begin begin
mail.deliver mail.deliver

View File

@ -6,3 +6,42 @@
<% else %> <% else %>
<%= t('property_hire.email_p_hire_content') %> <%= t('property_hire.email_p_hire_content') %>
<% end %> <% end %>
<br>
<% I18n.with_locale(@data['locale']) do %>
<% if !@data['hire_id'].nil? %>
<% hire = PHire.where(id: @data['hire_id']).first %>
<table>
<thead>
<tr>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<% ['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)%>
<tr>
<td>
<%= t("property_hire.#{k}") %>:&nbsp;
</td>
<td>
<% 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 %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<% end %>
<% end %>

View File

@ -28,34 +28,34 @@
<% end %> <% end %>
<%= form_for hire, :url => "/xhr/property_hires/make_booking", html: { class: "form-horizontal" } do |f| %> <%= form_for hire, :url => "/xhr/property_hires/make_booking", html: { class: "form-horizontal" } do |f| %>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-10"> <div class="col-sm-10">
<%= 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.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;"} %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-10"> <div class="col-sm-10">
<%= 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.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;"} %>
</div> </div>
</div> </div>
<!-- ############# recurring ############# --> <!-- ############# recurring ############# -->
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-1"> <div class="col-sm-1">
<%= f.check_box :recurring %> <%= f.check_box :recurring %>
</div> </div>
</div> </div>
<div id="recurring-block" <%= hire.recurring ? "" : "style=display:none;" %>> <div id="recurring-block" <%= hire.recurring ? "" : "style=display:none;" %>>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-1"> <div class="col-sm-1">
<%= 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;"}} %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-10"> <div class="col-sm-10">
<%= f.datetime_picker :recurring_end_date, :no_label => true, :new_record => hire.new_record?, :data=>{"fv-validation" => "requiredifrecurring;", "fv-messages" => "Cannot be empty;"} %> <%= f.datetime_picker :recurring_end_date, :no_label => true, :new_record => hire.new_record?, :data=>{"fv-validation" => "requiredifrecurring;", "fv-messages" => "Cannot be empty;"} %>
</div> </div>
@ -89,37 +89,37 @@
<div class="form-group"> <div class="form-group">
<label for="" class="col-sm-2 control-label"></label> <label for="" class="col-sm-2 control-label"></label>
<div class="col-sm-10"> <div class="col-sm-10">
<a href="/xhr/property_hires/check_availability" id="check-avail-btn" class="btn btn-primary">Check Availibility</a> <a href="/xhr/property_hires/check_availability" id="check-avail-btn" class="btn btn-primary"><%= t('property_hire.check_availibility') %></a>
<img style="display: none;" width="40" src="/assets/spin.gif" id="spinner" /> <img style="display: none;" width="40" src="/assets/spin.gif" id="spinner" />
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-5"> <div class="col-sm-5">
<%= 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.text_field :hiring_person_email, :class => "form-control", :value => current_user.member_profile.email, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-5"> <div class="col-sm-5">
<%= 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.text_field :hiring_person_number, :class => "form-control", :value => current_user.member_profile.mobile_no, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-5"> <div class="col-sm-5">
<%= f.text_field :hiring_person_name, :class => "form-control", :value => (current_user.name rescue ""), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> <%= 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.hidden_field :hiring_person_id, :value => (current_user.member_profile.id.to_s rescue "") %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-5"> <div class="col-sm-5">
<%= f.text_field :reason_for_hire, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> <%= f.text_field :reason_for_hire, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<%= 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" %>
<div class="col-sm-5"> <div class="col-sm-5">
<%= f.text_area :note_for_hire, :class => "form-control" %> <%= f.text_area :note_for_hire, :class => "form-control" %>
</div> </div>

View File

@ -62,3 +62,8 @@ en:
note_for_hire: Note For Hire note_for_hire: Note For Hire
period: Period period: Period
passed: Accepted passed: Accepted
'yes': 'Yes'
'no': 'No'
wait_for_permit: 'Wait for permit'
select_interval: Select interval
check_availibility: Check Availibility

View File

@ -11,12 +11,12 @@ zh_tw:
auto_send_email_set: 自動發信設定 auto_send_email_set: 自動發信設定
email_title: 主旨 email_title: 主旨
email_content: 內文 email_content: 內文
recurring: Recurring recurring: 週期性租借
recurring_interval: Recurring Interval recurring_interval: 租借週期
recurring_interval_types: recurring_interval_types:
month: Month month:
week: Week week:
recurring_end_date: Recurring End Date recurring_end_date: 週期結束時間
save: Save save: Save
my_bookings: My Bookings my_bookings: My Bookings
settings: Settings settings: Settings
@ -29,6 +29,8 @@ zh_tw:
add_location: Add Location add_location: Add Location
unavailability: Unavailability unavailability: Unavailability
title: Property Title title: Property Title
select_interval: 選則週期
check_availibility: 檢查是否可租借
property_usage: Usage for property property_usage: Usage for property
note: Note note: Note
property_number: Property Number property_number: Property Number
@ -39,9 +41,9 @@ zh_tw:
owner_email: Owner Email owner_email: Owner Email
owner_phone: Owner Phone owner_phone: Owner Phone
price: Price price: Price
set_unavailibility: Set Unavailability set_unavailibility: 設定為不可租借
start_time: Start Time start_time: 租借開始時間
end_time: End Time end_time: 租借結束時間
weekdays: Weekdays weekdays: Weekdays
start_date: From Date start_date: From Date
end_date: To Date end_date: To Date
@ -50,15 +52,18 @@ zh_tw:
property_location: Property Location property_location: Property Location
available_for_hire: Available for hire available_for_hire: Available for hire
hire: 租借 hire: 租借
view_calendar: Calendar view_calendar: 租借紀錄
image: Property Image image: Property Image
actions: Actions actions: Actions
start_time: Hire Start Time start_time: 租借開始時間
end_time: Hire End Time end_time: 租借結束時間
hiring_person_email: Hiring Person Email hiring_person_email: 租借人電子信箱
hiring_person_number: Hiring Person Number hiring_person_number: 租借人聯絡電話
hiring_person_name: Hiring Person hiring_person_name: 租借人姓名
reason_for_hire: Reason For Hire reason_for_hire: 租借原因
note_for_hire: Note For Hire note_for_hire: 備註
period: Period period: Period
passed: Accepted passed: 租借允許
'yes':
'no':
wait_for_permit: 等待授權