From fc3893f048da30cca9eb92d1f7f9418e84bc6cb4 Mon Sep 17 00:00:00 2001 From: Nweni Date: Sun, 11 Jun 2017 17:49:06 +0630 Subject: [PATCH] payment --- app/assets/javascripts/origami.js | 2 +- app/models/sale_payment.rb | 17 +++++++---------- app/views/origami/mpu/index.html.erb | 3 ++- app/views/origami/payments/create.json.jbuilder | 1 + app/views/origami/payments/show.html.erb | 3 ++- 5 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 app/views/origami/payments/create.json.jbuilder diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 21ec1c92..e37728c1 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -20,7 +20,7 @@ $(document).ready(function(){ $(".orders").on('click', function(){ var zone_name=$(this).find(".orders-table").text(); var receipt_no=$(this).find(".orders-receipt-no").text(); - var unique_id=$(this).find(".orders-id").text(); + var unique_id = $(this).find(".orders-id").text(); var order_status=$(this).find(".orders-order-status").text().trim(); // Enable/Disable Button diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index ff4c49b6..4b6edce8 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -106,7 +106,6 @@ class SalePayment < ApplicationRecord self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) return payment_status @@ -205,30 +204,28 @@ class SalePayment < ApplicationRecord end def sale_update_payment_status(paid_amount) - puts "sale update" #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f - self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received.to_f - all_received_amount = 0.0 - sObj = self.sale + sObj = Sale.find(self.sale_id) sObj.sale_payments.each do |spay| - puts spay - puts spay.payment_amount all_received_amount += spay.payment_amount.to_f end - puts all_received_amount - puts self.sale.grand_total + if (self.sale.grand_total <= all_received_amount) - puts " sale update ......" self.sale.payment_status = "paid" self.sale.sale_status = "completed" self.sale.save! + rebat() end end + def rebat + + end + private def generate_custom_id self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI") diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index d82e6cd1..f082dc1a 100644 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -11,12 +11,13 @@ Amount : $('#mpu_pay').on('click',function(){ var amount = $('#amount').val(); var sale_id = "<%= @sale_id %>"; - alert(amount); + $.ajax({type: "POST", url: "<%= origami_create_mpu_payment_path %>", data: "amount="+ amount + "&sale_id="+ sale_id, success:function(result){ if(result){ + alert("Payment success") window.location.href = '/origami/sale/'+ sale_id + "/payment"; } } diff --git a/app/views/origami/payments/create.json.jbuilder b/app/views/origami/payments/create.json.jbuilder new file mode 100644 index 00000000..08bf292c --- /dev/null +++ b/app/views/origami/payments/create.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index d36902fb..198b9518 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -229,7 +229,8 @@ $( document ).ready(function() { url: "<%= origami_payment_process_path %>", data: "cash="+ cash + "&sale_id=" + sale_id, success:function(result){ - alert("THANK YOU") + alert("Thank you") + window.location.href = '/origami'; } }); }