diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 8918d705..263e55f7 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -1,8 +1,17 @@ class Origami::MpuController < BaseOrigamiController def index + @sale_id = params[:sale_id] end - + def create + cash = params[:amount] + sale_id = params[:sale_id] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "mpu") + end end + end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index a3831439..290a2911 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -17,11 +17,16 @@ class Origami::PaymentsController < BaseOrigamiController def show sale_id = params[:sale_id] if Sale.exists?(sale_id) + @cash = 0.0 + @other = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) @sale_data.sale_payments.each do |spay| if spay.payment_method == "cash" @cash = spay.payment_amount end + if spay.payment_method == "mpu" + @other = spay.payment_amount + end end end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index aee7ace4..ff4c49b6 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -134,7 +134,7 @@ class SalePayment < ApplicationRecord self.payment_method = method self.payment_amount = self.received_amount self.payment_reference = self.card_payment_reference - self.outstanding_amount = self.sale.grand_total- self.received_amount + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_method = self.save! diff --git a/app/views/origami/mpu/create.json.jbuilder b/app/views/origami/mpu/create.json.jbuilder new file mode 100644 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/mpu/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index 6b339e0f..d82e6cd1 100644 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -1 +1,25 @@ -Hello MPU +