added reminder, new translation and sorting fix
This commit is contained in:
parent
5fde95565a
commit
946a9666c6
|
@ -41,7 +41,7 @@ class Admin::PropertyHiresController < OrbitAdminController
|
|||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
def my_bookings
|
||||
@table_fields = ["property_hire.title","property_hire.hiring_person_name", "property_hire.reason_for_hire", "property_hire.hiring_person_number", "property_hire.period", "property_hire.passed", :actions]
|
||||
@table_fields = ["property_hire.title","property_hire.hiring_person_name", "property_hire.reason_for_hire", "property_hire.hiring_person_number", "property_hire.period", "property_hire.passed", "property_hire.actions"]
|
||||
@bookings = PHire.where(:hiring_person_id => current_user.member_profile.id.to_s).desc(:created_at).page(params[:page]).per(10)
|
||||
end
|
||||
|
||||
|
@ -75,7 +75,7 @@ class Admin::PropertyHiresController < OrbitAdminController
|
|||
def show
|
||||
@table_fields = ["property_hire.hiring_person_name", "property_hire.reason_for_hire", "property_hire.hiring_person_number", "property_hire.period", "property_hire.passed", "property_hire.actions"]
|
||||
@property = Property.where(:uid => params[:id].split("-").last).first rescue nil
|
||||
@bookings = @property.p_hires.desc(:created_at).page(params[:page]).per(10)
|
||||
@bookings = @property.p_hires.desc(:start_time).page(params[:page]).per(10)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -318,7 +318,7 @@ class Admin::PropertyHiresController < OrbitAdminController
|
|||
end
|
||||
def create_set (save_flag)
|
||||
@email_set = []
|
||||
['p_hire','edit','delete'].each do |field_name|
|
||||
['p_hire','edit','delete', 'reminder'].each do |field_name|
|
||||
email_set = @property.hire_email_sets.select{|v| v.field_name==field_name}
|
||||
if email_set.length==0
|
||||
title = Hash.new
|
||||
|
|
|
@ -300,7 +300,12 @@ class PropertyHiresController < ApplicationController
|
|||
email = property.get_owner_emails
|
||||
email << hire.hiring_person_email
|
||||
email = email.select{|e| e.present?}
|
||||
# start_date = hire.start_date - hire.reminder_value.send(hire.reminder_unit) rescue nil
|
||||
Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,property.id,nil,hire.id,(current_user.id rescue nil))
|
||||
reminder_set = property.hire_email_sets.select{|v| v.field_name == "reminder"}[0]
|
||||
if reminder_set.disabled == false && (reminder_set.reminder_value != nil || reminder_set.reminder_value > 0)
|
||||
Admin::PropertyHiresHelper::HireMethod.send_mail('reminder',email,property.id,nil,hire.id,(current_user.id rescue nil))
|
||||
end
|
||||
end
|
||||
redirect_to index_page + "?method=hire_success"
|
||||
else
|
||||
|
|
|
@ -159,20 +159,27 @@ module Admin::PropertyHiresHelper
|
|||
hire = PHire.find(hire_id) rescue nil
|
||||
if hire
|
||||
mail_subject += " (#{I18n.t("property_hire.hire_time")}: #{hire.date.to_s.gsub("-","/")} #{hire.time})"
|
||||
send_date = Time.current
|
||||
end
|
||||
end
|
||||
if field_name == "reminder"
|
||||
hire = PHire.find(hire_id) rescue nil
|
||||
send_date = hire.start_time - email_set[0].reminder_value.send(email_set[0].reminder_unit) rescue nil
|
||||
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_sentdate: send_date,
|
||||
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
|
||||
if field_name != "reminder" && send_date != nil
|
||||
mail.deliver
|
||||
end
|
||||
rescue => e
|
||||
puts ["email can't deliver",e]
|
||||
end
|
||||
|
|
|
@ -5,6 +5,8 @@ class HireEmailSet
|
|||
field :field_name, type: String
|
||||
field :title
|
||||
field :content
|
||||
field :reminder_value, type: Integer, default: 0
|
||||
field :reminder_unit, type: String, default: 'month'
|
||||
field :disabled, type: Boolean, default: false
|
||||
belongs_to :property
|
||||
end
|
||||
|
|
|
@ -348,9 +348,14 @@
|
|||
<%= t('property_hire.delete') %>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="#email_set3" data-toggle="tab">
|
||||
<%= t('property_hire.reminder') %>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<% (0..2).each do |index1| %>
|
||||
<% (0..3).each do |index1| %>
|
||||
<% active_email_set = index1==0 ? ' active' : '' %>
|
||||
<div class="tab-pane<%= active_email_set %>" id="email_set<%= index1 %>" style="padding: 1.2em;">
|
||||
<table style="width:100%;">
|
||||
|
@ -364,6 +369,27 @@
|
|||
<%= check_box_tag("property[hire_email_sets][#{index1}][disabled]", true ,@email_set[index1].disabled) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% if index1 == 3 %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t('property_hire.reminder_setting') %>
|
||||
</td>
|
||||
<td>
|
||||
<% units = ['months', 'day', 'hour', 'minute'] %>
|
||||
<input type="number" name="property[hire_email_sets][3][reminder_value]" id="property_hire_email_sets_3_reminder_value" value="<%= @email_set[index1]['reminder_value'] %>">
|
||||
<select name="property[hire_email_sets][3][reminder_unit]">
|
||||
<% units.each do |unit| %>
|
||||
<option value="<%= unit %>" <%= @email_set[index1]['reminder_unit'] == unit ? "selected" : "" %> >
|
||||
<%= t("property_hire." + unit) %>
|
||||
</option>
|
||||
<% end %>
|
||||
</select>
|
||||
<%#= hire_method.show_set_field(@email_set[index1].id,@email_set[index1]['reminder_value'],'hire_email_sets',index1,'reminder_value','number_field',with_id) %>
|
||||
<%#= f.number_field :reminder_setting, :min=>0 %>
|
||||
<%#= f.select :reminder_setting_unit, options_for_select(units.map{|unit| [t("property_hire._#{unit}"), unit]},f.object.need_hire_before_unit) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t('property_hire.email_title') %>
|
||||
|
|
|
@ -35,10 +35,10 @@
|
|||
<td>
|
||||
|
||||
|
||||
<a href="<%= show_booking_details_admin_property_hire_path(p_hire, :page => params[:page]) %>" class="btn btn-info">View</a>
|
||||
<a href="<%= show_booking_details_admin_property_hire_path(p_hire, :page => params[:page]) %>" class="btn btn-info"><%= t("property_hire.view") %></a>
|
||||
|
||||
|
||||
<a href="<%= delete_booking_details_admin_property_hire_path(p_hire, :page => params[:page]) %>" class="btn btn-danger" data-method="delete" data-confirm="Are you sure?">Delete</a>
|
||||
<a href="<%= delete_booking_details_admin_property_hire_path(p_hire, :page => params[:page]) %>" class="btn btn-danger" data-method="delete" data-confirm="Are you sure?"><%= t("property_hire.delete") %></a>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
<% property = Property.where(id: @data['property_id']).first%>
|
||||
<% email_set = property.hire_email_sets.select{|v| v.field_name == 'reminder'} %>
|
||||
<% if email_set.length != 0 %>
|
||||
<% if !(email_set[0].content.nil?) %>
|
||||
<%= email_set[0].content[@data['locale']].html_safe %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= t('property_hire.email_p_hire_content') %>
|
||||
<% end %>
|
||||
<br>
|
||||
<style>
|
||||
.hire_infos td:first-child {
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
<% I18n.with_locale(@data['locale']) do %>
|
||||
<h3><%= property.title rescue nil %></h3>
|
||||
<% if !@data['hire_id'].nil? %>
|
||||
<% hire = PHire.where(id: @data['hire_id']).first %>
|
||||
<table id="hire_infos">
|
||||
<thead>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%
|
||||
p_hire_fields = property.p_hire_fields_enabled.map{|rf| [rf.id.to_s,rf]}.to_h
|
||||
fields_name = property.get_all_fields
|
||||
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 do |field_name|
|
||||
return true if field_name.include?('p_hire_fields.')
|
||||
tmp = property[field_name]
|
||||
tmp.is_a?(Hash) ? (tmp["enable"] == "1") : true
|
||||
end
|
||||
p_hire_fields = property.p_hire_fields_enabled.map{|rf| [rf.id.to_s,rf]}.to_h
|
||||
has_p_hire_fields = p_hire_fields.count != 0
|
||||
tmp_keys = []
|
||||
all_trans = keys.map do |k|
|
||||
if has_p_hire_fields && k.include?("p_hire_fields")
|
||||
tmp_keys << k.sub("p_hire_fields.",'')
|
||||
nil
|
||||
else
|
||||
tmp_keys << k
|
||||
property.custom_text(k,"name")
|
||||
end
|
||||
end
|
||||
%>
|
||||
<% p_hire_field_values = hire.p_hire_field_values.to_a %>
|
||||
<% keys.each_with_index do |k,i| %>
|
||||
<% if has_p_hire_fields && k.include?("p_hire_fields")
|
||||
p_hire_field_id = tmp_keys[i]
|
||||
v = p_hire_field_values.select{|v| v.p_hire_field_id.to_s == p_hire_field_id}.first
|
||||
field_info = v.get_field_value rescue {}
|
||||
if field_info["title"].present? && !field_info["value"].nil?
|
||||
all_trans[i] = field_info["title"]
|
||||
v = field_info["value"]
|
||||
end
|
||||
else
|
||||
v = hire.send(k)
|
||||
end
|
||||
%>
|
||||
<% if !v.nil? && !(k.include?('recurring') && hire.recurring != true)%>
|
||||
<tr>
|
||||
<td>
|
||||
<%= all_trans[i] %>:
|
||||
</td>
|
||||
<td>
|
||||
<% if ['start_time','end_time','recurring','recurring_interval','recurring_end_date','passed'].exclude?(k) %>
|
||||
<%= v.to_s.html_safe %>
|
||||
<% 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 %>
|
|
@ -95,13 +95,17 @@ en:
|
|||
enable_notes_selector: Enable Note field selector
|
||||
editor: Editor
|
||||
email_p_hire_success: Reserve Success
|
||||
email_reminder_success: Reminder Success
|
||||
email_edit_success: 'Property Hire Module:Edit Success'
|
||||
email_delete_success: 'Property Hire Module:Delete Success'
|
||||
email_p_hire_content: Reserve Success
|
||||
email_edit_content: 'Property Hire Module:Edit Success'
|
||||
email_delete_content: 'Property Hire Module:Delete Success'
|
||||
email_reminder_content: 'Property Hire Module:Email Reminder Content'
|
||||
edit: Edit
|
||||
delete: Delete
|
||||
reminder: Reminder
|
||||
reminder_setting: Reminder Setting
|
||||
auto_send_email_set: Auto Send Email Setting
|
||||
email_title: Email Title
|
||||
email_content: Email Content
|
||||
|
|
|
@ -119,13 +119,17 @@ zh_tw:
|
|||
enable_notes_selector: 啟用備註選項
|
||||
editor: 編輯者
|
||||
email_p_hire_success: 預約成功
|
||||
email_reminder_success: Reminder Success
|
||||
email_edit_success: '租借模組:編輯成功'
|
||||
email_delete_success: '租借模組:刪除成功'
|
||||
email_p_hire_content: 預約成功
|
||||
email_edit_content: '租借模組:編輯成功'
|
||||
email_delete_content: '租借模組:刪除成功'
|
||||
email_reminder_content: 'Property Hire Module:Email Reminder Content'
|
||||
edit: 編輯
|
||||
delete: 刪除
|
||||
reminder: Reminder
|
||||
reminder_setting: Reminder Setting
|
||||
auto_send_email_set: 自動發信設定
|
||||
email_title: 主旨
|
||||
email_content: 內文
|
||||
|
|
Loading…
Reference in New Issue