# encoding: utf-8 class Admin::VenueManagementsController < Admin::VenueAdminController require 'axlsx' helper Admin::VenueManagementsFieldHelper before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings, :venue_management_memorabilias, :venue_management_bills, :venue_management_contracts] def initialize super @app_title = "venue_management" end def filter_fields(categories) { :category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}} } end def index @categories = @module_app.categories.enabled @filter_fields = filter_fields(@categories) @table_fields = [ :category, 'vm_inviting.type', 'venue_management.title', "venue_management.contractor", 'venue_management.event_during', 'venue_management.signup_during', 'venue_management.inviting_history', 'venue_management.contract_history', 'venue_management.memorabilia', 'venue_management.bills', 'venue_management.export' ] @filter_fields["vm_inviting.type"] = @module_app.tags.map{|t| {:title => t.name,:id => t.id} } if !params[:sort].blank? if params[:sort] == 'event_during' sort = {:venue_management_start_date.to_sym=>params[:order]} elsif params[:sort] == 'signup_during' sort = {:signup_start_date.to_sym=>params[:order]} else sort = {params[:sort].to_sym=>params[:order]} end else sort = {:signup_start_date=>"desc"} end filter_tags = params[:filters][:type].to_a rescue [] if filter_tags.empty? @venue_managements = VenueManagementMain.all.order_by(sort).with_categories(filters("category")) @venue_managements = search_data(@venue_managements,[:title]).page(params[:page]).per(10) else @venue_managements = VenueManagementMain.all.order_by(sort).with_categories(filters("category")) @venue_managements = search_data(@venue_managements,[:title]) @venue_management_inviting_ids = @venue_managements.map{|v| v.venue_management_invitings.desc(:id).first.id rescue ""} @venue_management_ids = VenueManagementInviting.where(:id.in=>@venue_management_inviting_ids).with_tags(filter_tags).map{|v| v.venue_management_main_id} @venue_managements = VenueManagementMain.where(:id.in=>@venue_management_ids).page(params[:page]).per(10) end if request.xhr? render :partial => "index" end end def print_pdf time_now = Time.now venue_management = VenueManagementMain.find(params[:id]) if !venue_management.registration_status.blank? && venue_management.signup_start_date <= time_now && ( venue_management.signup_end_date.nil? || venue_management.signup_end_date+1 >= time_now ) sign_up = ('' + t('venue_management.signup') + '').html_safe elsif venue_management.registration_status.blank? sign_up = t('venue_management.sign_up_not_open') elsif venue_management.signup_start_date > time_now sign_up = t('venue_management.sign_up_not_yet') else sign_up = t('venue_management.sign_up_overdue') end if !venue_management.registration_status.blank? && venue_management.registration_status.include?('C') && venue_management.contribute_start_date <= time_now && ( venue_management.contribute_end_date.nil? || venue_management.contribute_end_date+1 >= time_now ) if !@@session[:venue_management_signup_id].blank? if @@session[:venue_management_main_id] == venue_management.id contribute_action = ('' + t('venue_management_signup.uploads') + '').html_safe else contribute_action = ('' + t('venue_management_signup.con_login') + '').html_safe end else contribute_action = ('' + t('venue_management_signup.con_login') + '').html_safe end end @venue_management = venue_management @sign_up = sign_up @contribute_action = contribute_action @time_now = time_now @contribute_time_range = VenueManagementMain.time_range(venue_management.contribute_start_date, venue_management.contribute_end_date) @sign_up_time_range = venue_management.display_signup_during @venue_management_time_range = venue_management.display_event_during @params = params @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" if params[:type] == "print" render "print_pdf" , :layout => false end end def export @protocol = (request.referer.blank? ? "http" : URI(request.referer).scheme) @host = "#{@protocol}://#{request.host_with_port}" @venue_management = VenueManagementMain.find(params[:id]) @venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => params[:id]) @site_in_use_locales = Site.first.in_use_locales filename = @venue_management.title.to_s.strip + "_export.xlsx" respond_to do |format| format.xlsx { response.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"' } end end def new @member = nil @managers = nil @contractors = nil @coordinators = nil @venue_management = VenueManagementMain.new create_set (false) @signup_sets = @venue_management.venue_management_signup_field_sets @submission_set = @venue_management.venue_management_submission_field_sets @custom_set = @venue_management.venue_management_signup_field_customs @venue_management_items = VenueManagementItem.all @review = @venue_management.venue_management_reviews.new() end def create venue_management_main_params = venue_management_params if !venue_management_main_params['venue_management_links_attributes'].nil? venue_management_main_params['venue_management_links_attributes'].each do |idx,link| venue_management_main_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? end end venue_management_signup_set_params = venue_management_main_params['venue_management_signup_field_sets'] venue_management_submission_set_params = venue_management_main_params['venue_management_submission_field_sets'] venue_management_email_sets_params = venue_management_main_params['venue_management_email_sets'] venue_management_main_params.delete(:venue_management_signup_field_sets) venue_management_main_params.delete(:venue_management_submission_field_sets) venue_management_main_params.delete(:venue_management_email_sets) venue_management = VenueManagementMain.new(venue_management_main_params) venue_management.create_user_id = current_user.id venue_management.update_user_id = current_user.id venue_management.save #venue_management_signup_set_params.each do |key,value| # venue_management.venue_management_signup_field_sets.create(value) #end #venue_management_submission_set_params.each do |key,value| # venue_management.venue_management_submission_field_sets.create(value) #end venue_management_email_sets_params.each do |key,value| venue_management.venue_management_email_sets.create(value) end redirect_to params['referer_url'] end def edit @venue_management_items = VenueManagementItem.all @venue_management = VenueManagementMain.where(id: params[:id]).first @venue_management.venue_management_signup_field_sets.each do |signup_field_set| if !(VenueManagementSignup.attribute_names.include? signup_field_set.field_name) && signup_field_set.field_name != 'recaptcha' signup_field_set.delete end end @venue_management.venue_management_submission_field_sets.each do |submission_field_set| if !(VenueManagementSignupContribute.attribute_names.include? submission_field_set.field_name) submission_field_set.delete end end @venue_management.venue_management_signup_field_customs.each do |custom_set| if !(@venue_management.venue_management_signup_fields.collect(&:id).include? custom_set.venue_management_signup_field_id) custom_set.delete end end create_set (true) @signup_sets = @venue_management.venue_management_signup_field_sets @submission_set = @venue_management.venue_management_submission_field_sets @custom_set = @venue_management.venue_management_signup_field_customs if @venue_management.venue_management_reviews.first.nil? @review = @venue_management.venue_management_reviews.new() else @review = @venue_management.venue_management_reviews.first end @member = MemberProfile.find(@review.reviewer_id) rescue nil @managers = MemberProfile.find(@venue_management.manager_ids) rescue nil @contractors = MemberProfile.find(@venue_management.contractor_ids) rescue nil @coordinators = MemberProfile.find(@venue_management.coordinator_ids) rescue nil end def update params[:venue_management_main][:registration_status] = (params[:venue_management_main][:registration_status] ? params[:venue_management_main][:registration_status] : []) uid = params[:id].split('-').last @venue_management = VenueManagementMain.find_by(:uid=>uid) if params[:venue_management_main][:venue_management_signup_fields] venue_management_params[:venue_management_signup_fields].each do |a| @field_name = 'venue_management_main' field_status = a.last[:id].present? @attribute_field = VenueManagementSignupField.add_venue_management_signup_field(@venue_management, a.last, a.last[:id], field_status) @attribute = @venue_management end flash.now[:notice] = "Updated Fields" @venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true} redirect_to admin_venue_managements_path elsif params[:venue_management_main][:venue_management_submission_fields] params[:venue_management_main][:venue_management_submission_fields].each do |a| @field_name = 'venue_management_main' field_status = a.last[:id].present? @attribute_field = VenueManagementSubmissionField.add_venue_management_signup_field(@venue_management, a.last, a.last[:id], field_status) @attribute = @venue_management end flash.now[:notice] = "Updated Fields" @venue_management.venue_management_submission_fields.each{|t| t.destroy if t["to_delete"] == true} redirect_to admin_venue_managements_path else venue_management_main_params = venue_management_params if !venue_management_main_params['venue_management_links_attributes'].nil? venue_management_main_params['venue_management_links_attributes'].each do |idx,link| venue_management_main_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? end end @venue_management.update_user_id = current_user.id if @venue_management.update_attributes(venue_management_main_params) @venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true} redirect_to params['referer_url'] else flash.now[:error] = t('update.error.category') flash.keep redirect_to action: :edit, :id =>@venue_management.id.to_s end end end def set_write_off @venue_management.donation_write_off_status = true @venue_management.save redirect_to "/admin/venue_managements?page=#{params['page']}" end def destroy @venue_management.destroy redirect_to "/admin/venue_managements" end def venue_management_signup_field @field_name = 'venue_management_main' @attribute = VenueManagementMain.find(params[:id]) @attribute_type = 'venue_management' @class = 'venue_managements' end def venue_management_submission_field @field_name = 'venue_management_main' @attribute = VenueManagementMain.find(params[:id]) @attribute_type = 'venue_management' @class = 'venue_managements' end def venue_management_signup if !params[:search].blank? @venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => @venue_management.id, :name=>params[:search]).page(params[:page]).per(10) else @venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => @venue_management.id).page(params[:page]).per(10) end end def edit_venue_management_signup @venue_management_signup = VenueManagementSignup.find(params[:id]) @venue_management = VenueManagementMain.find(@venue_management_signup.venue_management_main_id) end def delete_venue_management_signup @venue_management_signup = VenueManagementSignup.find(params[:id]) @venue_management_id = @venue_management_signup.venue_management_main_id @venue_management_signup.destroy redirect_to "/admin/venue_managements/@venue_management_id.to_s/venue_management_signup" end def venue_management_invitings @table_fields = [ 'vm_inviting.case_no', 'vm_inviting.type', 'vm_inviting.publish_times', 'vm_inviting.start_end', 'vm_inviting.rents', 'vm_inviting.royalty', 'vm_inviting.house_land_tax_payer', 'vm_inviting.contractor_manager', 'vm_inviting.bid_result', ] filter_tags = params[:filters]["type"].to_a rescue [] @invitings = @venue_management.venue_management_invitings.with_tags(filter_tags).page(params[:page]).per(10) @tags = @module_app.tags @filter_fields = {} @filter_fields['vm_inviting.type'] = @tags.map{|t| {:title => t.name,:id => t.id} } @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" if request.xhr? render :partial => 'admin/venue_management_invitings/index' end end def venue_management_memorabilias @table_fields = [ 'vm_memorabilia.case_no', 'vm_memorabilia.event_date', 'vm_memorabilia.details', ] @memorabilias = @venue_management.venue_management_memorabilias.page(params[:page]).per(10) @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" end def venue_management_bills @table_fields = [ "contractor", "accounting_month", "bill_type", "caculation_basis", "reason", "total_amount", "pay_date", "pay_method", "note" ] @bills = @venue_management.venue_management_bills.page(params[:page]).per(10) @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" end def venue_management_contracts @table_fields = [ 'vm_contract.case_no', 'vm_inviting.type', 'vm_contract.vendor', 'vm_inviting.rents', 'vm_inviting.royalty', 'vm_contract.start_end', 'vm_contract.renewal_permission', 'vm_contract.note', ] @contracts = @venue_management.venue_management_contracts.page(params[:page]).per(10) @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" end private def set_venue_management @venue_management = VenueManagementMain.find(params[:id]) end def venue_management_params params.require(:venue_management_main).permit! end def create_set (save_flag) VenueManagementSignup.attribute_names.each do |attr_signup| if !(['_id', 'created_at', 'updated_at','venue_management_main_id'].include? attr_signup) signup_set = @venue_management.venue_management_signup_field_sets.select{|v| v.field_name==attr_signup } if signup_set.length==0 if ['status','name','tel','phone','email','password'].include? attr_signup disabled = false else disabled = true end if ['status','name','tel'].include? attr_signup hidden = false else hidden = true end name1 = Hash.new now_locale = I18n.locale I18n.available_locales.each do |locale| I18n.locale = locale name1[locale] = t("venue_management_signup.#{attr_signup}") end I18n.locale = now_locale if save_flag @venue_management.venue_management_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1) else @venue_management.venue_management_signup_field_sets.new(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1) end end end end signup_set = @venue_management.venue_management_signup_field_sets.select{|v| v.field_name== 'recaptcha' } if signup_set.length==0 name1 = Hash.new now_locale = I18n.locale I18n.available_locales.each do |locale| I18n.locale = locale name1[locale] = t("venue_management_signup.recaptcha") end I18n.locale = now_locale if save_flag @venue_management.venue_management_signup_field_sets.create(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true) else @venue_management.venue_management_signup_field_sets.new(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true) end end VenueManagementSignupContribute.attribute_names.each do |attr_submission| if !(['_id', 'created_at', 'updated_at','venue_management_signup_id'].include? attr_submission) signup_set = @venue_management.venue_management_submission_field_sets.select{|v| v.field_name==attr_submission } if signup_set.length==0 name1 = Hash.new now_locale = I18n.locale I18n.available_locales.each do |locale| I18n.locale = locale name1[locale] = t("venue_management_signup.#{attr_submission}") end I18n.locale = now_locale if save_flag @venue_management.venue_management_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1) else @venue_management.venue_management_submission_field_sets.new(field_name:attr_submission,name:name1,placeholder:name1) end end end end @venue_management.venue_management_signup_fields.all.map{|v| v}.each do |field| set = @venue_management.venue_management_signup_field_customs.select{|v| v.venue_management_signup_field_id==field.id} if set.length == 0 @venue_management.venue_management_signup_field_customs.create(venue_management_signup_field_id:field.id) end end @email_set = [] ['signup','submission','add_file','edit_file'].each do |field_name| email_set = @venue_management.venue_management_email_sets.select{|v| v.field_name==field_name} if email_set.length==0 title = Hash.new content = Hash.new now_locale = I18n.locale I18n.available_locales.each do |locale| I18n.locale = locale title[locale] = t("venue_management.email_#{field_name}_success") content[locale] = t("venue_management.email_#{field_name}_content") end I18n.locale = now_locale if save_flag email_set = @venue_management.venue_management_email_sets.create(field_name:field_name,title:title,content:content) else email_set = @venue_management.venue_management_email_sets.new(field_name:field_name,title:title,content:content) end else email_set = email_set[0] end @email_set << email_set end end end