added create purchase and receipts
This commit is contained in:
parent
708831e333
commit
f7737ef653
|
@ -66,6 +66,43 @@ class Admin::ClientManagementsController < OrbitAdminController
|
|||
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
|
||||
|
@ -89,6 +126,10 @@ class Admin::ClientManagementsController < OrbitAdminController
|
|||
|
||||
private
|
||||
|
||||
def receipt_params
|
||||
params.require(:purchase_receipt).permit!
|
||||
end
|
||||
|
||||
def contract_params
|
||||
params.require(:request_contract).permit!
|
||||
end
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
class ContractPurchase
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :total_amount, type: Integer, :default => 0
|
||||
|
||||
belongs_to :request_contract
|
||||
has_many :purchase_receipts
|
||||
|
||||
def total_amount_recieved
|
||||
self.purchase_receipts.sum(:amount_received)
|
||||
end
|
||||
|
||||
def total_adjusted_amount
|
||||
self.purchase_receipts.sum(:adjustable_amount)
|
||||
end
|
||||
|
||||
def cleared?
|
||||
self.total_amount == (self.total_amount_recieved + self.total_adjusted_amount)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
class PurchaseReceipt
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
mount_uploader :receipt_file, AssetUploader
|
||||
mount_uploader :received_receipt_file, AssetUploader
|
||||
|
||||
field :amount, type: Integer, :default => 0
|
||||
field :amount_received, type: Integer, :default => 0
|
||||
field :adjustable_amount, type: Integer, :default => 0
|
||||
field :adjustable_amount_detail
|
||||
field :amount_received_on, type: DateTime
|
||||
field :receipt_number
|
||||
|
||||
belongs_to :contract_purchase
|
||||
|
||||
def amount_pending
|
||||
self.amount - (self.amount_received + self.adjustable_amount)
|
||||
end
|
||||
|
||||
def is_pending?
|
||||
self.amount_pending > 0
|
||||
end
|
||||
end
|
|
@ -11,15 +11,18 @@ 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 :other
|
||||
field :other_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
|
||||
has_one :contract_purchase
|
||||
|
||||
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
|
||||
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 + self.other_cost
|
||||
end
|
||||
|
||||
def is_confirmed?
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :receipt_number, "Receipt Number:" %></span>
|
||||
<span class="content-line"><%= f.text_field :receipt_number %></span>
|
||||
</div>
|
||||
|
||||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :amount, "Amount:" %></span>
|
||||
<span class="content-line"><%= f.number_field :amount, :min => "0", :max => @purchase.total_amount %></span>
|
||||
</div>
|
||||
|
||||
<% if !@receipt.receipt_file.url.nil? %>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Receipt File:</span>
|
||||
<span class="content-line"><a href="<%= @receipt.receipt_file.url %>">Download File</a></span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :receipt_file, "Receipt File:" %></span>
|
||||
<span class="content-line"><%= f.file_field :receipt_file %></span>
|
||||
</div>
|
||||
|
||||
<% if !@receipt.new_record? %>
|
||||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :amount_received, "Amount Received:" %></span>
|
||||
<span class="content-line"><%= f.number_field :amount_received, :min => "0", :max => @receipt.amount %></span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :adjustable_amount, "Adjustable Amount:" %></span>
|
||||
<span class="content-line"><%= f.number_field :adjustable_amount, :min => "0" %></span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :adjustable_amount_detail, "Adjustable Amount Detail:" %></span>
|
||||
<span class="content-line"><%= f.text_field :adjustable_amount_detail %></span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :amount_received_on, "Amount Received On:" %></span>
|
||||
<span class="content-line"><%= f.datetime_picker :amount_received_on, :no_label => true, :new_record => @receipt.new_record? %></span>
|
||||
</div>
|
||||
<% if !@receipt.received_receipt_file.url.nil? %>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Signed Receipt File:</span>
|
||||
<span class="content-line"><a href="<%= @receipt.received_receipt_file.url %>">Download File</a></span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="line-content">
|
||||
<span class="header-line"><%= f.label :received_receipt_file, "Signed Receipt File:" %></span>
|
||||
<span class="content-line"><%= f.file_field :received_receipt_file %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if @receipt.new_record? %>
|
||||
<%= f.hidden_field :contract_purchase_id, :value => @purchase.id.to_s %>
|
||||
<% end %>
|
||||
<%= f.submit "Submit", :class => "btn btn-primary" %>
|
|
@ -89,6 +89,15 @@
|
|||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="line-content">
|
||||
<span class="header-line">
|
||||
<%= f.label :other, "Other Requirements:" %>
|
||||
<%= f.text_area :other %>
|
||||
</span>
|
||||
<span class="content-line">
|
||||
<%= f.number_field :other_cost, :min => "0" %>
|
||||
</span>
|
||||
</div>
|
||||
<% if !@contract.contract_file.url.nil? %>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Contract File :</span>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "client_management/backend" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
||||
<% end %>
|
||||
<div class="info-detail">
|
||||
<div class="info-spec">
|
||||
<%= form_for @receipt, :url => {:action => :create_receipt}, :html => {:class => "form-horizontal contract-form"} do |f| %>
|
||||
<h3 class="sub-title">Add Receipt</h3>
|
||||
<%= render :partial => "purchase_form", :locals => {:f => f} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,15 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "client_management/backend" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
||||
<% end %>
|
||||
<div class="info-detail">
|
||||
<div class="info-spec">
|
||||
<%= form_for @receipt, :url => {:action => :update_receipt}, :html => {:class => "form-horizontal contract-form"} do |f| %>
|
||||
<h3 class="sub-title">Add Receipt</h3>
|
||||
<%= render :partial => "purchase_form", :locals => {:f => f} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "client_management/backend" %>
|
||||
<% end %>
|
||||
|
||||
<div class="page-contract page-client">
|
||||
<div class="info-contract">
|
||||
<h3 class="sub-title">
|
||||
<% if @purchase.total_amount == (@total_received_amount + @total_adjustable_amount) %>
|
||||
<span class="label label-success pull-right">Received</span>
|
||||
<% else %>
|
||||
<span class="label label-important pull-right">Pending</span>
|
||||
<% end %>
|
||||
Purchase Info
|
||||
</h3>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Contract Id :</span>
|
||||
<span class="content-line"><%= @contract.uid %></span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Contract Date :</span>
|
||||
<span class="content-line"><%= @contract.created_at.strftime("%Y, %B %d") %></span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Total Amount :</span>
|
||||
<span class="content-line"><%= @purchase.total_amount %> NTD.</span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Amount Received :</span>
|
||||
<span class="content-line" style="color: green;"><%= @total_received_amount %> NTD.</span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Amount Adjusted :</span>
|
||||
<span class="content-line" style="color: indigo;"><%= @total_adjustable_amount %> NTD.</span>
|
||||
</div>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Amount Pending :</span>
|
||||
<span class="content-line" style="color: red;"><%= @purchase.total_amount - (@total_received_amount + @total_adjustable_amount) %> NTD.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<% ["client_management.receipt_number", "client_management.amount", "client_management.amount_received", "client_management.amount_pending", "client_management.receipt_status", :actions].each_with_index do |f,i| %>
|
||||
<%= thead(f) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if !@purchase.purchase_receipts.blank? %>
|
||||
<% @purchase.purchase_receipts.each do |pr| %>
|
||||
<tr>
|
||||
<td><%= pr.receipt_number %></td>
|
||||
<td><%= pr.amount %></td>
|
||||
<td style="color:green;"><%= pr.amount_received %></td>
|
||||
<td style="color:red;"><%= pr.amount_pending %></td>
|
||||
<td>
|
||||
<% if pr.is_pending? %>
|
||||
<span class="label label-important">Pending</span>
|
||||
<% else %>
|
||||
<span class="label label-success">Cleared</span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><a href="<%= edit_receipt_admin_client_management_path(pr.id) %>" class="btn btn-warning">Edit</a></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<tr>
|
||||
<td colspan="6" style="text-align: center;">No receipts issued.</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="info-contract-buttons">
|
||||
<div class="line-content button">
|
||||
<% if @purchase.total_amount > (@total_received_amount + @total_adjustable_amount) %>
|
||||
<a class="btn btn-info" href="<%= add_receipt_admin_client_management_path(@purchase.id) %>">Add Receipt</a>
|
||||
<% end %>
|
||||
<a class="btn" href="<%= see_contract_admin_client_management_path(@contract.id) %>">Back to Contract</a>
|
||||
</div>
|
||||
</div>
|
|
@ -19,6 +19,18 @@
|
|||
<%= (@contract.is_confirmed? ? "<span class='label label-success'>Yes</span>" : "<span class='label label-important'>No</span>").html_safe %>
|
||||
</span>
|
||||
</div>
|
||||
<% if !@contract.contract_purchase.nil? %>
|
||||
<div class="line-content">
|
||||
<span class="header-line">Payment Status :</span>
|
||||
<span class="content-line">
|
||||
<% if @contract.contract_purchase.cleared? %>
|
||||
<span class="label label-success">Cleared</span>
|
||||
<% else %>
|
||||
<span class="label label-important">Pending</span>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="info-contract-request">
|
||||
<h3 class="sub-title">Request</h3>
|
||||
|
@ -93,6 +105,16 @@
|
|||
<% total_amount = total_amount + amount %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if !@contract.other.nil? || @contract.other_cost > 0 %>
|
||||
<div class="line-content qt">
|
||||
<span class="header-line">
|
||||
Other Requirements : <br>
|
||||
<%= nl2br(@contract.other) %>
|
||||
</span>
|
||||
<span class="content-line"><%= @contract.other_cost %></span>
|
||||
</div>
|
||||
<% total_amount = total_amount + @contract.other_cost %>
|
||||
<% end %>
|
||||
<div class="line-content qt hr">
|
||||
<span class="header-line">Total :</span>
|
||||
<span class="content-line"><%= total_amount.to_s %></span>
|
||||
|
@ -117,12 +139,22 @@
|
|||
<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>
|
||||
<% if @contract.contract_purchase.nil? %>
|
||||
<a href="<%= make_purchase_admin_client_management_path(@contract.id) %>" class="btn btn-warning" id="make-purchase-btn">Make Purchase</a>
|
||||
<a href="<%= confirm_contract_admin_client_management_path(@contract.id, :confirm => "false") %>" class="btn btn-danger">Un-Confirm Contract</a>
|
||||
<% else %>
|
||||
<a href="<%= receipts_admin_client_management_path(@contract.contract_purchase.id) %>" class="btn btn-warning">Receipts</a>
|
||||
<% end %>
|
||||
<% 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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#make-purchase-btn").on("click",function(){
|
||||
if(!confirm("Once you create a purchase, you cannot un-confirm or edit this contract. Continue to create a purchase for this contract?")){
|
||||
return false;
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -100,7 +100,16 @@
|
|||
<% end %>
|
||||
<% total_amount = total_amount + amount %>
|
||||
<% end %>
|
||||
|
||||
<% if !@contract.other.nil? || @contract.other_cost > 0 %>
|
||||
<div class="line-contract qt">
|
||||
<span class="header-detail">
|
||||
Other Requirements : <br>
|
||||
<%= nl2br(@contract.other) %>
|
||||
</span>
|
||||
<span class="content-detail"><%= @contract.other_cost %></span>
|
||||
</div>
|
||||
<% total_amount = total_amount + @contract.other_cost %>
|
||||
<% end %>
|
||||
<div class="line-contract qt hr">
|
||||
<span class="header-detail">Total :</span>
|
||||
<span class="content-detail"><%= total_amount %></span>
|
||||
|
|
|
@ -47,3 +47,8 @@ en:
|
|||
created_on: Created On
|
||||
loading_history: Loading History
|
||||
loading_contracts: Loading Contracts
|
||||
receipt_number: Receipt Number
|
||||
amount: Total Amount
|
||||
amount_received: Amount Received
|
||||
amount_pending: Amount Pending
|
||||
receipt_status: Receipt Status
|
|
@ -47,3 +47,8 @@ zh_tw:
|
|||
created_on: Created On
|
||||
loading_history: Loading History
|
||||
loading_contracts: Loading Contracts
|
||||
receipt_number: Receipt Number
|
||||
amount: Total Amount
|
||||
amount_received: Amount Received
|
||||
amount_pending: Amount Pending
|
||||
receipt_status: Receipt Status
|
|
@ -17,6 +17,11 @@ Rails.application.routes.draw do
|
|||
get "make_purchase"
|
||||
patch "add_sites"
|
||||
get "complete_request"
|
||||
get "receipts"
|
||||
get "add_receipt"
|
||||
get "edit_receipt"
|
||||
post "create_receipt"
|
||||
patch "update_receipt"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue