# frozen_string_literal: true class Admin::VenueManagementInvitingsController < Admin::VenueAdminController include Admin::VenueManagementsHelper before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_venue_management_inviting, only: [:edit, :update, :destroy] def initialize super @app_title = 'venue_management' end def index @table_fields = [ 'venue_management.title', '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', 'vm_inviting.details' ] @tags = @module_app.tags @filter_fields = {} @filter_fields['vm_inviting.type'] = @tags.map{|t| {:title => t.name,:id => t.id} } @filter_fields['vm_inviting.start_end'] = ('
'+ (render_html('<%= org_datetime_picker("filters[start_date]", {:no_label => true, :format=>"yyyy/MM/dd", :new_record=>false, :value=>(DateTime.parse(params[:filters]["start_date"]) rescue nil)}) %>')) + "
~
" + (render_html('<%= org_datetime_picker("filters[end_date]", {:no_label => true, :format=>"yyyy/MM/dd", :new_record=>false, :value=>(DateTime.parse(params[:filters]["end_date"]) rescue nil)}) %>' ) ) + render_html("<%= submit_tag(I18n.t('venue_management.search')) %>") + '
') filter_tags = params[:filters]["type"].to_a rescue [] start_date = DateTime.parse(params[:filters]["start_date"]) rescue 0 end_date = DateTime.parse(params[:filters]["end_date"]) rescue 0 @invitings = VenueManagementInviting.with_tags(filter_tags).order(updated_at: :desc).page(params[:page]).per(10) if @invitings.nil? if start_date != 0 && end_date != 0 @invitings = VenueManagementInviting.where(:start_date.gte=>start_date,:end_date.lte=>end_date).page(params[:page]).per(10) elsif start_date != 0 @invitings = VenueManagementInviting.where(:start_date.gte=>start_date).page(params[:page]).per(10) elsif end_date != 0 @invitings = VenueManagementInviting.where(:end_date.lte=>end_date).page(params[:page]).per(10) end else if start_date != 0 && end_date != 0 @invitings = @invitings.where(:start_date.gte=>start_date,:end_date.lte=>end_date).page(params[:page]).per(10) elsif start_date != 0 @invitings = @invitings.where(:start_date.gte=>start_date).page(params[:page]).per(10) elsif end_date != 0 @invitings = @invitings.where(:end_date.lte=>end_date).page(params[:page]).per(10) end end @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" if request.xhr? render :partial => 'index' end end def new @venue_management = VenueManagementMain.find(params[:id]) @venue_management_inviting = @venue_management.venue_management_invitings.build end def create @venue_management_inviting = VenueManagementInviting.new(venue_management_inviting_params) @venue_management_inviting.save redirect_to params['referer_url'] end def edit @venue_management = VenueManagementMain.find(@venue_management_inviting.venue_management_main_id) end def update @venue_management_inviting.update_attributes(venue_management_inviting_params) redirect_to venue_management_invitings_admin_venue_management_path(@venue_management_inviting.venue_management_main_id) end def destroy @venue_management_main_id = @venue_management_inviting.venue_management_main_id @venue_management_inviting.destroy redirect_to venue_management_invitings_admin_venue_management_path(@venue_management_main_id) end def render_html(code,pass_variables={}) render_to_string(:inline=>code,:locals=>pass_variables) end def export filename = "" filter_tags = params[:filters]["type"].to_a rescue [] start_date = DateTime.parse(params[:filters]["start_date"]) rescue 0 end_date = DateTime.parse(params[:filters]["end_date"]) rescue 0 @invitings = VenueManagementInviting.with_tags(filter_tags).order(updated_at: :desc).page(params[:page]).per(10) filename += (I18n.t("vm_inviting.type") + ": #{Tag.where(:id.in=>filter_tags).map{|t| t.name}.join(',')}") if !filter_tags.blank? if start_date != 0 && end_date != 0 filename += (I18n.t("vm_inviting.start_end") + ": #{start_date}~#{end_date}") if filename.blank? @invitings = @invitings.where(:start_date.gte=>start_date,:end_date.lte=>end_date).page(params[:page]).per(10) elsif start_date != 0 filename += (I18n.t("vm_inviting.start_end") + ": #{start_date}~") if filename.blank? @invitings = @invitings.where(:start_date.gte=>start_date).page(params[:page]).per(10) elsif end_date != 0 filename += (I18n.t("vm_inviting.start_end") + ": ~#{end_date}") if filename.blank? @invitings = @invitings.where(:end_date.lte=>end_date).page(params[:page]).per(10) end if params[:id].present? filename = "#{VenueManagementMain.find(params[:id]).title rescue ''}_export_invitings" if filename.blank? @invitings = @invitings.where(:venue_management_main_id=>params[:id]) end @invitings = @invitings.page(1).per(@invitings.count) @protocol = (request.referer.blank? ? "http" : URI(request.referer).scheme) @host = "#{@protocol}://#{request.host_with_port}" @site_in_use_locales = Site.first.in_use_locales filename = "export_invitings" if filename.blank? filename = filename + "_export.xlsx" @id = params[:id] respond_to do |format| format.xlsx { response.headers['Content-Transfer-Encoding'] = 'binary' response.headers['Content-Type'] = 'binary/octet-stream' response.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"' } end render :layout => false end private def set_venue_management_inviting @venue_management_inviting = VenueManagementInviting.find(params[:id]) end def venue_management_inviting_params inviting_params = params.require(:venue_management_inviting).permit! inviting_params["tags"] = [] if inviting_params["tags"].nil? return inviting_params end end