client_management/app/controllers/admin/client_managements_controll...

100 lines
2.6 KiB
Ruby

class Admin::ClientManagementsController < OrbitAdminController
def index
@site_requests = SiteRequest.where(:completed => false).order_by(sort).page(params[:page]).per(10)
end
def show
@site_request = SiteRequest.find(params[:id])
@user = @site_request.c_panel_user
end
def make_contract
@site_request = SiteRequest.find(params[:id])
@user = @site_request.c_panel_user
@contract = RequestContract.new
end
def complete_request
site_request = SiteRequest.find(params[:id])
site_request.completed = true
site_request.save
redirect_to admin_client_management_path(site_request.id)
end
def create_contract
rc = RequestContract.new(contract_params)
rc.save
sr = SiteRequest.find(contract_params[:site_request])
sr.request_contract = rc
sr.completed = true
sr.save
redirect_to see_contract_admin_client_management_path(rc.id)
end
def update_contract
contract = RequestContract.find(params[:id])
contract.update_attributes(contract_params)
contract.save
redirect_to see_contract_admin_client_management_path(contract.id)
end
def edit_contract
@contract = RequestContract.find(params[:id])
@site_request = @contract.site_request
@user = @site_request.c_panel_user
end
def see_contract
@contract = RequestContract.find(params[:id])
@site_request = @contract.site_request
end
def completed_requests
@site_requests = SiteRequest.where(:completed => true).order_by(sort).page(params[:page]).per(10)
end
def confirm_contract
contract = RequestContract.find(params[:id])
if params["confirm"] == "true"
contract.confirmed = true
elsif params["confirm"] == "false"
contract.confirmed = false
end
contract.save
redirect_to see_contract_admin_client_management_path(contract.id)
end
def make_purchase
end
def add_sites
sr = SiteRequest.find(params[:id])
sr.update_attributes(site_request_params)
user = CPanelUser.find(sr.c_panel_user.id)
site_request_params[:sites_added].each do |sid|
site = RegisteredSite.find(sid)
sr.sites_to_add.delete(site.site_domain)
user.registered_site_ids << site.id
end
sr.completed = true
sr.save
user.save
redirect_to admin_client_management_path(sr.id)
end
def contracts
@contracts = RequestContract.all.order_by(:confirmed => 'desc', :created_at => "desc").page(params[:page]).per(10)
end
private
def contract_params
params.require(:request_contract).permit!
end
def site_request_params
params.require(:site_request).permit!
end
end