diff --git a/app/controllers/admin/client_managements_controller.rb b/app/controllers/admin/client_managements_controller.rb index 3d622d5..489aec2 100644 --- a/app/controllers/admin/client_managements_controller.rb +++ b/app/controllers/admin/client_managements_controller.rb @@ -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 diff --git a/app/models/contract_purchase.rb b/app/models/contract_purchase.rb new file mode 100644 index 0000000..a45dc96 --- /dev/null +++ b/app/models/contract_purchase.rb @@ -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 \ No newline at end of file diff --git a/app/models/purchase_receipt.rb b/app/models/purchase_receipt.rb new file mode 100644 index 0000000..ef1bf4f --- /dev/null +++ b/app/models/purchase_receipt.rb @@ -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 \ No newline at end of file diff --git a/app/models/request_contract.rb b/app/models/request_contract.rb index 9ec1696..0fd3417 100644 --- a/app/models/request_contract.rb +++ b/app/models/request_contract.rb @@ -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? diff --git a/app/views/admin/client_managements/_purchase_form.html.erb b/app/views/admin/client_managements/_purchase_form.html.erb new file mode 100644 index 0000000..2ced525 --- /dev/null +++ b/app/views/admin/client_managements/_purchase_form.html.erb @@ -0,0 +1,55 @@ +
<%= pr.receipt_number %> | +<%= pr.amount %> | +<%= pr.amount_received %> | +<%= pr.amount_pending %> | ++ <% if pr.is_pending? %> + Pending + <% else %> + Cleared + <% end %> + | +Edit | +
No receipts issued. | +