141 lines
3.8 KiB
Ruby
141 lines
3.8 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
|
|
contract = RequestContract.find(params[:id]) rescue nil
|
|
if !contract.nil?
|
|
purchase = ContractPurchase.new
|
|
purchase.request_contract = contract
|
|
purchase.total_amount = contract.total_amount
|
|
purchase.save
|
|
end
|
|
redirect_to see_contract_admin_client_management_path(contract.id)
|
|
end
|
|
|
|
def receipts
|
|
@purchase = ContractPurchase.find(params[:id]) rescue nil
|
|
@contract = @purchase.request_contract
|
|
@total_received_amount = @purchase.total_amount_recieved
|
|
@total_adjustable_amount = @purchase.total_adjusted_amount
|
|
end
|
|
|
|
def add_receipt
|
|
@receipt = PurchaseReceipt.new
|
|
@purchase = ContractPurchase.find(params[:id]) rescue nil
|
|
end
|
|
|
|
def create_receipt
|
|
receipt = PurchaseReceipt.create(receipt_params)
|
|
redirect_to receipts_admin_client_management_path(receipt.contract_purchase.id)
|
|
end
|
|
|
|
def edit_receipt
|
|
@receipt = PurchaseReceipt.find(params[:id])
|
|
@purchase = @receipt.contract_purchase rescue nil
|
|
end
|
|
|
|
def update_receipt
|
|
receipt = PurchaseReceipt.find(params[:id])
|
|
receipt.update_attributes(receipt_params)
|
|
receipt.save
|
|
redirect_to receipts_admin_client_management_path(receipt.contract_purchase.id)
|
|
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(:created_at => "desc", :confirmed => 'desc').page(params[:page]).per(10)
|
|
end
|
|
|
|
private
|
|
|
|
def receipt_params
|
|
params.require(:purchase_receipt).permit!
|
|
end
|
|
|
|
def contract_params
|
|
params.require(:request_contract).permit!
|
|
end
|
|
|
|
def site_request_params
|
|
params.require(:site_request).permit!
|
|
end
|
|
|
|
end |