2020-09-08 06:12:14 +00:00
|
|
|
class Admin::VenueManagementBillsController < Admin::VenueAdminController
|
|
|
|
include Admin::VenueManagementsHelper
|
2020-10-14 01:48:38 +00:00
|
|
|
include ActionView::Helpers::FormOptionsHelper
|
|
|
|
include ActionView::Helpers::FormTagHelper
|
|
|
|
include ActionView::Helpers::FormHelper
|
|
|
|
include VenueAdminHelper
|
|
|
|
include ActionView::Context
|
2020-09-08 06:12:14 +00:00
|
|
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
|
|
|
before_action :set_venue_management_bill, only: [:edit, :update, :destroy]
|
2020-10-14 01:48:38 +00:00
|
|
|
def objectify_options(options)
|
|
|
|
@default_options = {}
|
|
|
|
@default_options.merge(options)
|
|
|
|
end
|
2020-09-08 06:12:14 +00:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = 'venue_management'
|
|
|
|
end
|
2020-10-14 01:48:38 +00:00
|
|
|
def filter_fields(categories)
|
|
|
|
{
|
|
|
|
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
def text_field(object_name , options = {})
|
|
|
|
text_field_tag(object_name, options[:value], options)
|
|
|
|
end
|
2020-09-08 06:12:14 +00:00
|
|
|
def index
|
|
|
|
@table_fields = [
|
|
|
|
'venue_management.title',
|
|
|
|
"contractor",
|
|
|
|
"accounting_month",
|
|
|
|
"bill_type",
|
|
|
|
"caculation_basis",
|
|
|
|
"reason",
|
2020-10-05 16:09:17 +00:00
|
|
|
"total_amount",
|
2020-09-08 06:12:14 +00:00
|
|
|
"pay_date",
|
|
|
|
"pay_method",
|
|
|
|
"note"
|
|
|
|
]
|
2020-10-14 01:48:38 +00:00
|
|
|
@bills = nil
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories)
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@filter_fields['vm_inviting.type'] = @tags.map{|t| {:title => t.name,:id => t.id} }
|
|
|
|
bill_type_select_str = "<div class=\"controls\"><form>"
|
|
|
|
value_bill_typeA = params[:filters]["bill_typeA"] rescue "0"
|
|
|
|
value_bill_typeB = params[:filters]["bill_typeB"] rescue "0"
|
|
|
|
bill_type_select_str += (select_tag "filters[bill_typeA]", options_for_select(VenueManagementBill::BILLTYPE.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] },value_bill_typeA) ,{:onchange=>"var $this=this;(function(){var obj=#{VenueManagementBill::BILLTYPE.map{|k,v| [k,v.map{|vv| [vv,I18n.t("vm_bill.#{vv}")]}.to_h]}.to_h.to_s.gsub('=>',':')};$($this).siblings('select').html($.map(obj[$this.value],function(v,k){return \'<option value=\"\'+k+\'\">\'+v+\'</option>\'}).join(\' \'))})()"})
|
|
|
|
bill_typeB = (params[:filters]["bill_typeA"].blank? rescue true) ? VenueManagementBill::BILLTYPE.values.first : VenueManagementBill::BILLTYPE[params[:filters]["bill_typeA"]]
|
|
|
|
bill_type_select_str += (select_tag "filters[bill_typeB]", options_for_select(bill_typeB.map { |v| [ I18n.t("vm_bill.#{v}"), v ] },value_bill_typeB) , {:onchange=> "var $this=this;(function(){if($this.value == 'other') $('#bill_other_field').removeClass('hidden');else $('#bill_other_field').addClass('hidden');})()"})
|
|
|
|
bill_type_select_str += submit_tag(I18n.t('venue_management.search'))
|
|
|
|
bill_type_select_str += "</form></div>"
|
|
|
|
@filter_fields['vm_bill.bill_type'] = bill_type_select_str
|
|
|
|
@filter_fields['vm_bill.accounting_month'] = ('<form><div class="controls"><div style="float: left;">'+
|
|
|
|
(org_datetime_picker("filters[accounting_month_start]", {:no_label => true, :format=>"yyyy/MM", :new_record=>false, :value=>(DateTime.parse(params[:filters]["accounting_month_start"]) rescue nil)})) +
|
|
|
|
"</div><span style=\"float: left;\">~</span><div style=\"float: left;\">" +
|
|
|
|
(org_datetime_picker("filters[accounting_month_end]", {:no_label => true, :format=>"yyyy/MM", :new_record=>false, :value=>(DateTime.parse(params[:filters]["accounting_month_end"]) rescue nil)})) +
|
|
|
|
submit_tag(I18n.t('venue_management.search')) +
|
|
|
|
'</div></div></form>')
|
|
|
|
filter_tags = params[:filters]["type"].to_a rescue []
|
|
|
|
@main_ids = nil
|
|
|
|
if !filter_tags.blank?
|
|
|
|
@main_ids = VenueManagementInviting.with_tags(filter_tags).pluck(:venue_management_main_id)
|
|
|
|
if !filters("category").blank?
|
|
|
|
@main_ids = VenueManagementMain.where(:id.in=>@main_ids).with_categories(filters("category")).pluck(:id)
|
|
|
|
end
|
|
|
|
elsif !filters("category").blank?
|
|
|
|
@main_ids = VenueManagementMain.all.with_categories(filters("category")).pluck(:id)
|
|
|
|
end
|
|
|
|
if ( !params[:filters]["bill_typeA"].blank? rescue false)
|
|
|
|
@bills = VenueManagementBill.where(:bill_typeA=>params[:filters]["bill_typeA"],:bill_typeB=>params[:filters]["bill_typeB"]).page(params[:page]).per(10)
|
|
|
|
end
|
|
|
|
accounting_month_start = DateTime.parse(params[:filters]["accounting_month_start"]) rescue 0
|
|
|
|
accounting_month_end = DateTime.parse(params[:filters]["accounting_month_end"]) rescue 0
|
|
|
|
if @bills.nil?
|
|
|
|
@bills = VenueManagementBill.where(:accounting_month.gt=>accounting_month_start,:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10)
|
|
|
|
else
|
|
|
|
if accounting_month_start != 0 && accounting_month_end != 0
|
|
|
|
@bills = @bills.where(:accounting_month.gt=>accounting_month_start,:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10)
|
|
|
|
elsif accounting_month_start != 0
|
|
|
|
@bills = @bills.where(:accounting_month.gt=>accounting_month_start).page(params[:page]).per(10)
|
|
|
|
elsif accounting_month_end != 0
|
|
|
|
@bills = @bills.where(:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if !@main_ids.nil?
|
|
|
|
@bills = @bills.where(:venue_management_main_id.in=>@main_ids).page(params[:page]).per(10)
|
|
|
|
end
|
2020-09-08 06:12:14 +00:00
|
|
|
@venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue ""
|
2020-10-14 01:48:38 +00:00
|
|
|
if request.xhr?
|
|
|
|
render '_index'
|
|
|
|
end
|
2020-09-08 06:12:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@venue_management = VenueManagementMain.find(params[:id])
|
|
|
|
@venue_management_bill = VenueManagementBill.new(venue_management_main_id: params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@venue_management_bill = VenueManagementBill.new(venue_management_bill_params)
|
|
|
|
@venue_management_bill.save
|
|
|
|
|
|
|
|
redirect_to params['referer_url']
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@venue_management = VenueManagementMain.find(@venue_management_bill.venue_management_main_id)
|
|
|
|
end
|
2020-10-05 16:09:17 +00:00
|
|
|
def copy
|
|
|
|
@venue_management_bill_to_copy = VenueManagementBill.find(params[:id])
|
|
|
|
attributes = @venue_management_bill_to_copy.attributes.except("_id","updated_at","created_at")
|
|
|
|
VenueManagementBill.fields.each do |k,v|
|
|
|
|
if v.options[:localize]
|
|
|
|
attributes.delete k
|
|
|
|
attributes[k+"_translations"] = @venue_management_bill_to_copy[k]
|
|
|
|
elsif attributes[k].class == Hash
|
|
|
|
attributes[k] = BSON::Document.new(attributes[k])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@venue_management_bill = VenueManagementBill.new(attributes)
|
|
|
|
#render :html =>attributes and return
|
|
|
|
@venue_management = VenueManagementMain.find(@venue_management_bill_to_copy.venue_management_main_id)
|
|
|
|
end
|
2020-09-08 06:12:14 +00:00
|
|
|
def update
|
|
|
|
@venue_management_bill.update_attributes(venue_management_bill_params)
|
|
|
|
|
|
|
|
redirect_to venue_management_bills_admin_venue_management_path(@venue_management_bill.venue_management_main_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@venue_management_main_id = @venue_management_bill.venue_management_main_id
|
|
|
|
@venue_management_bill.destroy
|
|
|
|
|
|
|
|
redirect_to venue_management_bills_admin_venue_management_path(@venue_management_main_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_venue_management_bill
|
|
|
|
@venue_management_bill = VenueManagementBill.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def venue_management_bill_params
|
|
|
|
params.require(:venue_management_bill).permit!
|
|
|
|
end
|
|
|
|
def venue_management_bill_params
|
|
|
|
params.require(:venue_management_bill).permit!
|
|
|
|
end
|
|
|
|
end
|