backend see contract make contract and add sites etc

This commit is contained in:
Harry Bomrah 2017-03-10 14:53:25 +08:00
parent 5c96331c7f
commit b006a18fbf
19 changed files with 432 additions and 59 deletions

View File

@ -12,18 +12,79 @@ class Admin::ClientManagementsController < OrbitAdminController
def make_contract
@site_request = SiteRequest.find(params[:id])
@user = @site_request.c_panel_user
@new_contract = RequestContract.new
@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.create(contract_params)
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 admin_client_managements_path
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
@ -31,5 +92,9 @@ class Admin::ClientManagementsController < OrbitAdminController
def contract_params
params.require(:request_contract).permit!
end
def site_request_params
params.require(:site_request).permit!
end
end

View File

@ -1,6 +1,7 @@
class RequestContract
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :new_site_cost, type: Integer, :default => 0
field :hosting_with_rulingdigital_cost, type: Integer, :default => 0
@ -10,6 +11,26 @@ class RequestContract
field :template_cost, type: Integer, :default => 0
field :customized_template_cost, type: Integer, :default => 0
field :rwd_cost, type: Integer, :default => 0
field :confirmed, type: Boolean, :default => false
mount_uploader :contract_file, AssetUploader
mount_uploader :signed_contract_file, AssetUploader
has_one :site_request
def total_amount
self.new_site_cost + self.hosting_with_rulingdigital_cost + self.service_cost + self.option_module_cost + self.customized_module_cost + self.template_cost + self.customized_template_cost + self.rwd_cost
end
def is_confirmed?
self.confirmed
end
def contract_user
self.site_request.c_panel_user
end
def get_site
self.site_request.get_site
end
end

View File

@ -14,6 +14,7 @@ class SiteRequest
field :custom_template_details
field :rwd, type: Boolean, default: false
field :sites_to_add, type: Array, default: []
field :sites_added, type: Array, default: []
field :completed, type: Boolean, :default => false
field :type
@ -26,7 +27,7 @@ class SiteRequest
self.site_id == "newsite" ? nil : RegisteredSite.find(self.site_id)
end
def get_site_type
def get_request_type
case self.type
when "newsite"
t = "New Site"

View File

@ -1,17 +1,34 @@
<tr>
<th>Sites to add :</th>
<td>
<% @site_request.sites_to_add.each_with_index do |sid,i| %>
<% site = RegisteredSite.where(:site_domain => sid).first rescue nil %>
<div>
<% if !site.nil? %>
<input type="checkbox" id="check_<%= sid %>">
<label for="check_<%= sid %>"><%= site.title %></label>
<% else %>
<span><%= sid %><span class="label label-default">Site not found</span></span>
<% end %>
<a href="http://<%= sid %>" target="_blank"><i class="icons-export"></i></a>
</div>
<%= form_for @site_request, :url => {:action => "add_sites"} do |f| %>
<% x = 0 %>
<% @site_request.sites_to_add.each_with_index do |sid,i| %>
<% site = RegisteredSite.where(:site_domain => sid).first rescue nil %>
<div>
<% if !site.nil? %>
<% x = 1 %>
<input type="checkbox" name="site_request[sites_added][]" value="<%= site.id %>" id="check_<%= i.to_s %>" >
<label for="check_<%= i %>"><%= site.title %></label>
<% else %>
<span><%= sid %><span class="label label-default">Site not found</span></span>
<% end %>
<a href="http://<%= sid %>" target="_blank"><i class="icons-export"></i></a>
</div>
<% end %>
<% @site_request.sites_added.each_with_index do |sid,i| %>
<% site = RegisteredSite.find(sid) rescue nil %>
<div>
<span><%= site.title %><span class="label label-default">Site Already Added</span></span>
<a href="http://<%= site.site_domain %>" target="_blank"><i class="icons-export"></i></a>
</div>
<% end %>
<% if x > 0 %>
<%= f.submit "Add Sites", :class => "btn btn-primary" %>
<% end %>
<% if !@site_request.completed %>
<a href="<%= complete_request_admin_client_management_path(@site_request.id) %>" class="btn btn-info">Complete Request</a>
<% end %>
<% end %>
</td>
</tr>

View File

@ -0,0 +1,20 @@
<% @contracts.each do |contract| %>
<tr>
<td><%= contract.uid %>
<td><%= contract.contract_user.name %></td>
<td>
<% case contract.site_request.type %>
<% when "newsite" %>
<span class="label label-success">New Site</span>
<% when "existing" %>
<span class="label label-warning">New Feature</span>
<div>Requested for : <a href="http://<%= contract.get_site.site_domain %>" target="_blank"><%= contract.get_site.title %></a></div>
<% end %>
</td>
<td><%= contract.created_at.strftime("%y-%m-%d %H:%M") %></td>
<td><%= (contract.confirmed ? "<span class='label label-success'>Yes</span>" : "<span class='label label-important'>No</span>").html_safe %></td>
<td>
<a href="<%= see_contract_admin_client_management_path(contract.id) %>" class="btn btn-info">View</a>
</td>
</tr>
<% end %>

View File

@ -0,0 +1,24 @@
<% @site_requests.each do |request| %>
<tr>
<td><%= request.uid %>
<td><%= request.c_panel_user.name %></td>
<td>
<% case request.type %>
<% when "newsite" %>
<span class="label label-success">New Site</span>
<% when "existing" %>
<span class="label label-warning">New Feature</span>
<div>Requested for : <a href="http://<%= request.get_site.site_domain %>" target="_blank"><%= request.get_site.title %></a></div>
<% when "addsites" %>
<span class="label label-info">Sites Addition</span>
<% end %>
</td>
<td><%= request.created_at.strftime("%y-%m-%d %H:%M") %></td>
<td>
<a href="<%= admin_client_management_path(request.id) %>" class="btn btn-info">Details</a>
<% if request.request_contract != nil %>
<a href="<%= see_contract_admin_client_management_path(request.request_contract.id, :page => params[:page]) %>" class="btn btn-warning">Contract</a>
<% end %>
</td>
</tr>
<% end %>

View File

@ -79,11 +79,24 @@
</div>
</div>
<% end %>
<div>
<h3>Total Amount : <span id="total-amount">0</span> NTD.</h3>
<% if !@contract.contract_file.url.nil? %>
<a href="<%= @contract.contract_file.url %>" target="_blank">Download Contract</a>
<% end %>
<div class="control-group">
<%= f.label :contract_file, "Contract File:", :class => "control-label" %>
<div class="controls">
<%= f.file_field :contract_file %>
</div>
</div>
<%= f.hidden_field :site_request, :value => @site_request.id.to_s %>
<div>
<h3>Total Amount : <span id="total-amount"><%= @contract.new_record? ? 0 : @contract.total_amount %></span> NTD.</h3>
</div>
<% if @contract.new_record? %>
<%= f.hidden_field :site_request, :value => @site_request.id.to_s %>
<% end %>
<%= f.submit "Submit", :class => "btn btn-primary" %>
<a href="<%= see_contract_admin_client_management_path(@contract.id) %>" class="btn">Back</a>
<script type="text/javascript">
var costFields = $("form.contract-form input[type=number]"),
totalAmountDom = $("#total-amount");

View File

@ -0,0 +1,17 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% ["client_management.request_uid", "client_management.user", "client_management.request_type", "client_management.requested_on", :actions].each_with_index do |f,i| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<%= render :partial => "index" %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@site_requests), class: "pagination pagination-centered"
end
%>

View File

@ -0,0 +1,17 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% ["client_management.contract_uid", "client_management.user", "client_management.site", "client_management.created_on", "client_management.status", :actions].each_with_index do |f,i| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<%= render :partial => "contract_index" %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@contracts), class: "pagination pagination-centered"
end
%>

View File

@ -0,0 +1,48 @@
<style type="text/css">
table th{
text-align: right;
padding-right: 15px;
}
</style>
<h2>Site Id : <%= @site_request.uid %></h2>
<h2>Site type : <%= @site_request.get_request_type %></h2>
<table width="100%">
<caption><h3>User Details</h3></caption>
<% if !@user.fullname.nil? %>
<tr>
<th>Name :</th>
<td><%= @user.fullname %></td>
</tr>
<% end %>
<tr>
<th>Email :</th>
<td><%= @site_request.c_panel_user.email %></td>
</tr>
<% if !@user.phone_number.nil? %>
<tr>
<th>Phone Number :</th>
<td><%= @user.phone_number %></td>
</tr>
<% end %>
<% if !@user.address.nil? %>
<tr>
<th>Address :</th>
<td><%= @user.address %></td>
</tr>
<% end %>
<% if !@user.registered_site_ids.empty? %>
<tr>
<th>Registered Sites :</th>
<td>
<% @user.registered_sites.each do |rs| %>
<span class="label label-default"><a style="color:#fff;" href="http://<%= rs.site_domain %>" target="_blank"><%= rs.title %></a></span>
<% end %>
</td>
</tr>
<% end %>
</table>
<hr>
<%= form_for @contract, :url => {:action => :update_contract}, :html => {:class => "form-horizontal contract-form"} do |f| %>
<h3>Request Specifications</h3>
<%= render :partial => "site_spec_form", :locals => {:f => f} %>
<% end %>

View File

@ -7,30 +7,7 @@
</tr>
</thead>
<tbody>
<% @site_requests.each do |request| %>
<tr>
<td><%= request.uid %>
<td><%= request.c_panel_user.name %></td>
<td>
<% case request.type %>
<% when "newsite" %>
<span class="label label-success">New Site</span>
<% when "existing" %>
<span class="label label-warning">New Feature</span>
<div>Requested for : <a href="http://<%= request.get_site.site_domain %>" target="_blank"><%= request.get_site.title %></a></div>
<% when "addsites" %>
<span class="label label-info">Sites Addition</span>
<% end %>
</td>
<td><%= request.created_at.strftime("%y-%m-%d %H:%M") %></td>
<td>
<a href="<%= admin_client_management_path(request.id) %>" class="btn btn-info">Details</a>
<% if request.request_contract != nil %>
<a href="#" class="btn btn-warning">Contract</a>
<% end %>
</td>
</tr>
<% end %>
<%= render :partial => "index" %>
</tbody>
</table>
<%=

View File

@ -5,7 +5,7 @@
}
</style>
<h2>Site Id : <%= @site_request.uid %></h2>
<h2>Site type : <%= @site_request.get_site_type %></h2>
<h2>Site type : <%= @site_request.get_request_type %></h2>
<table width="100%">
<caption><h3>User Details</h3></caption>
<% if !@user.fullname.nil? %>
@ -42,7 +42,7 @@
<% end %>
</table>
<hr>
<%= form_for @new_contract, :url => {:action => :create_contract}, :html => {:class => "form-horizontal contract-form"} do |f| %>
<%= form_for @contract, :url => {:action => :create_contract}, :html => {:class => "form-horizontal contract-form"} do |f| %>
<h3>Request Specifications</h3>
<%= render :partial => "site_spec_form", :locals => {:f => f} %>
<% end %>

View File

@ -0,0 +1,109 @@
<style type="text/css">
table th{
text-align: right;
padding-right: 15px;
}
</style>
<h2>Contract Id : <%= @contract.uid %></h2>
<h4> <%= @contract.created_at.strftime("%Y-%m-%d") %> </h4>
<h4>Confirmed : <%= (@contract.is_confirmed? ? "<span class='label label-success'>Yes</span>" : "<span class='label label-important'>No</span>").html_safe %></h4>
<table>
<caption>Request</caption>
<tr>
<th>Type :</th>
<td><%= @site_request.get_request_type %></td>
</tr>
</table>
<% if @site_request.type == "existing" %>
<table >
<caption>Site Details</caption>
<tr>
<th>Site ID :</th>
<td><%= @site_request.get_site.uid %></td>
</tr>
<tr>
<th>Site Name : </th>
<td><%= @site_request.get_site.title %></td>
</tr>
<tr>
<th>Site Domain : </th>
<td><%= @site_request.get_site.site_domain %></td>
</tr>
</table>
<% end %>
<table >
<caption>Contract Files</caption>
<% if !@contract.contract_file.url.nil? %>
<tr>
<th>Contract :</th>
<td><a href="<%= @contract.contract_file.url %>" target="_blank">Download</a></td>
</tr>
<% end %>
<% if !@contract.signed_contract_file.url.nil? %>
<tr>
<th>Signed Contract :</th>
<td><a href="<%= @contract.signed_contract_file.url %>" target="_blank">Download</a></td>
</tr>
<% end %>
</table>
<table width="50%">
<caption>Quotaion</caption>
<tr>
<td><b>Item</b></td>
<td><b>Cost in NTD.</b></td>
</tr>
<% total_amount = 0 %>
<% ["new_site_cost","hosting_with_rulingdigital_cost","service_cost","option_module_cost","customized_module_cost","template_cost","customized_template_cost","rwd_cost"].each do |attrib| %>
<% amount = @contract.send(attrib.to_sym) %>
<% if amount > 0 %>
<tr>
<td>
<%= t("client_management.#{attrib}") %>
<% if attrib == "option_module_cost" %>
<ol>
<% rsm = RegisteredModule.find(@site_request.optional_modules) %>
<% rsm.each do |rs|%>
<li><%= rs.name %></li>
<% end %>
</ol>
<% end %>
</td>
<td><%= amount %></td>
</tr>
<% total_amount = total_amount + amount %>
<% end %>
<% end %>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr>
<td><strong>Total :</strong></td>
<td><strong><%= total_amount.to_s %> NTD.</strong></td>
</tr>
<tr>
<td colspan="2"><hr></td>
</tr>
</table>
<%= form_for @contract, :url => {:action => "update_contract"}, :html => {:class => "form-horizontal"} do |f| %>
<div class="control-group">
<%= f.label :signed_contract_file, "Signed Contract File:", :class => "control-label" %>
<div class="controls">
<%= f.file_field :signed_contract_file %>
</div>
</div>
<%= f.submit "Upload", :class => "btn-small btn-primary" %>
<% end %>
<% if !@contract.is_confirmed? %>
<a href="<%= edit_contract_admin_client_management_path(@contract.id) %>" class="btn btn-warning">Edit Contract</a>
<a href="<%= confirm_contract_admin_client_management_path(@contract.id, :confirm => "true") %>" class="btn btn-success">Confirm Contract</a>
<% else %>
<a href="<%= make_purchase_admin_client_management_path(@contract.id) %>" class="btn btn-warning">Make Purchase</a>
<a href="<%= confirm_contract_admin_client_management_path(@contract.id, :confirm => "false") %>" class="btn btn-danger">Un-Confirm Contract</a>
<% end %>
<a href="#" class="btn btn-info">Export Contract</a>
<a href="<%= admin_client_managements_completed_requests_path(:page => params[:page]) %>" class="btn">Back</a>

View File

@ -4,8 +4,8 @@
padding-right: 15px;
}
</style>
<h2>Site Id : <%= @site_request.uid %></h2>
<h2>Site type : <%= @site_request.get_site_type %></h2>
<h2>Request ID : <%= @site_request.uid %></h2>
<h2>Request type : <%= @site_request.get_request_type %></h2>
<table width="100%">
<caption><h3>User Details</h3></caption>
<% if !@user.fullname.nil? %>
@ -54,19 +54,14 @@
<% end %>
</table>
<% if @site_request.request_contract %>
<% if @site_request.request_contract.nil? %>
<% case @site_request.type %>
<% when "newsite" %>
<% when "existing","newsite" %>
<a class="btn btn-primary" href="<%= make_contract_admin_client_management_path(@site_request.id) %>">Make Contract</a>
<% when "existing" %>
<a class="btn btn-primary" href="<%= make_contract_admin_client_management_path(@site_request.id) %>">Make Contract</a>
<% when "addsites" %>
<% end %>
<% else %>
<% when "newsite" %>
<a class="btn btn-primary" href="<%= edit_contract_admin_client_management_path(@site_request.id) %>">Edit Contract</a>
<% when "existing" %>
<a class="btn btn-primary" href="<%= edit_contract_admin_client_management_path(@site_request.id) %>">Edit Contract</a>
<% when "addsites" %>
<% case @site_request.type %>
<% when "existing","newsite" %>
<a class="btn btn-primary" href="<%= see_contract_admin_client_management_path(@site_request.request_contract.id) %>">View Contract</a>
<% end %>
<% end %>

View File

@ -30,4 +30,18 @@ en:
user: User
request_type: Request Type
requested_on: Requested On
request_uid: Request ID
request_uid: Request ID
new_site_cost: New Site
hosting_with_rulingdigital_cost: Hosting
service_cost: Maintainance
option_module_cost: Optional Module(s)
customized_module_cost: Customized Module
template_cost: Template
customized_template_cost: Customized Template
rwd_cost: RWD
new_requests: New Requests
completed_requests: Completed Requests
contracts: Contracts
contract_uid: Contract ID
site: Site
created_on: Created On

View File

@ -30,4 +30,18 @@ zh_tw:
user: User
request_type: Request Type
requested_on: Requested On
request_uid: Request ID
request_uid: Request ID
new_site_cost: New Site
hosting_with_rulingdigital_cost: Hosting
service_cost: Maintainance
option_module_cost: Optional Module(s)
customized_module_cost: Customized Module
template_cost: Template
customized_template_cost: Customized Template
rwd_cost: RWD
new_requests: New Requests
completed_requests: Completed Requests
contracts: Contracts
contract_uid: Contract ID
site: Site
created_on: Created On

View File

@ -3,11 +3,20 @@ Rails.application.routes.draw do
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
get "client_managements/completed_requests", to: 'client_managements#completed_requests'
get "client_managements/contracts", to: 'client_managements#contracts'
resources :client_managements do
member do
get "make_contract"
post "create_contract"
get "edit_contract"
get "see_contract"
patch "update_contract"
get "confirm_contract"
get "make_purchase"
patch "add_sites"
get "complete_request"
end
end
end

View File

@ -15,12 +15,24 @@ module ClientManagement
active_for_controllers (['admin/client_managements'])
head_link_path "admin_client_managements_path"
context_link 'all',
context_link 'client_management.new_requests',
:link_path=>"admin_client_managements_path" ,
:priority=>1,
:active_for_action=>{'admin/client_managements'=>"index"},
:available_for => 'users'
context_link 'client_management.completed_requests',
:link_path=>"admin_client_managements_completed_requests_path" ,
:priority=>1,
:active_for_action=>{'admin/client_managements'=>"completed_requests"},
:available_for => 'users'
context_link 'client_management.contracts',
:link_path=>"admin_client_managements_contracts_path" ,
:priority=>1,
:active_for_action=>{'admin/client_managements'=>"contracts"},
:available_for => 'users'
end
end
end