class Admin::VenueManagementBillsController < Admin::VenueAdminController include Admin::VenueManagementsHelper include ActionView::Helpers::FormOptionsHelper #include ActionView::Helpers::FormTagHelper #don't include this helper,or you will got an error when using redirect_to and url_for #include ActionView::Helpers::FormHelper #don't include this helper,or you will got an error when using redirect_to and url_for include VenueAdminHelper include ActionView::Context before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_venue_management_bill, only: [:edit, :update, :destroy] 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 @table_fields = [ 'venue_management.title', "contractor", "accounting_month", "bill_type", "caculation_basis", "reason", "total_amount", "pay_date", "pay_method", "note" ] @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 = "
" @filter_fields['vm_bill.bill_type'] = bill_type_select_str @filter_fields['vm_bill.accounting_month'] = ('') 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? if accounting_month_start != 0 && accounting_month_end != 0 @bills = VenueManagementBill.where(:accounting_month.gt=>accounting_month_start,:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) elsif accounting_month_start != 0 @bills = VenueManagementBill.where(:accounting_month.gt=>accounting_month_start).page(params[:page]).per(10) elsif accounting_month_end != 0 @bills = VenueManagementBill.where(:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) end 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 if @bills.nil? @bills = VenueManagementBill.all.page(params[:page]).per(10) end @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" if request.xhr? render '_index' end 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 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 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 def render_html(code,pass_variables={}) render_to_string(:inline=>code,:locals=>pass_variables) 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