# frozen_string_literal: true class Admin::VenueManagementContractsController < OrbitAdminController include Admin::VenueManagementsHelper before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_venue_management_contract, only: [:edit, :update, :destroy] def initialize super @app_title = 'venue_management' end def index @table_fields = [ 'venue_management.title', 'vm_contract.case_no', 'vm_contract.vendor', 'vm_contract.start_end', 'vm_contract.renewal_permission', 'vm_contract.note', ] @contracts = VenueManagementContract.order(updated_at: :desc).page(params[:page]).per(10) end def new @venue_management = VenueManagementMain.find(params[:id]) @venue_management_contract = @venue_management.venue_management_contracts.build end def create @venue_management_contract = VenueManagementContract.new(venue_management_contract_params) inviting = VenueManagementInviting.find_by(id: venue_management_contract_params[:venue_management_inviting_id]) assign_inviting_attrs(@venue_management_contract, inviting) @venue_management_contract.save redirect_to params['referer_url'] end def edit @venue_management = VenueManagementMain.find(@venue_management_contract.venue_management_main_id) end def update inviting = VenueManagementInviting.find_by(id: venue_management_contract_params[:venue_management_inviting_id]) assign_inviting_attrs(@venue_management_contract, inviting) @venue_management_contract.update_attributes(venue_management_contract_params) redirect_to venue_management_contracts_admin_venue_management_path(@venue_management_contract.venue_management_main_id) end def destroy @venue_management_main_id = @venue_management_contract.venue_management_main_id @venue_management_contract.destroy redirect_to venue_management_contracts_admin_venue_management_path(@venue_management_main_id) end private def assign_inviting_attrs(contract, inviting) %i(case_no publish_times start_date end_date close_date bid_date evaluation_date early_rent operation_rent royalty contractor_manager house_tax_payer land_tax_payer bid_result details).each do |attr| contract[attr] = inviting.send(attr) end end def set_venue_management_contract @venue_management_contract = VenueManagementContract.find(params[:id]) end def venue_management_contract_params params.require(:venue_management_contract).permit! end end