venue_management/app/controllers/admin/venue_management_bills_cont...

85 lines
2.6 KiB
Ruby
Raw Normal View History

2020-09-08 06:12:14 +00:00
class Admin::VenueManagementBillsController < Admin::VenueAdminController
include Admin::VenueManagementsHelper
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 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"
]
@bills = VenueManagementBill.all.page(params[:page]).per(10)
@venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue ""
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