From 5816a48d3250f3dc94c38773f4454a515c483e79 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 18 Apr 2018 14:40:53 +0630 Subject: [PATCH] update dinga and paymal --- .../origami/customers_controller.rb | 2 ++ app/controllers/origami/dinga_controller.rb | 25 ++++++------- app/controllers/origami/paymal_controller.rb | 3 +- app/models/sale_payment.rb | 21 ++++++++--- app/views/origami/dinga/index.html.erb | 36 ++++++++++--------- .../origami/order_reservation/index.html.erb | 2 +- app/views/origami/payments/show.html.erb | 19 +++++----- 7 files changed, 64 insertions(+), 44 deletions(-) diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index fefb973e..537703a1 100755 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -169,6 +169,8 @@ class Origami::CustomersController < BaseOrigamiController sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" ) end @out = membership_data + + render json: JSON.generate({:status => membership_data["status"], :message => membership_data["message"]}) end end end diff --git a/app/controllers/origami/dinga_controller.rb b/app/controllers/origami/dinga_controller.rb index 448b39dd..586403f9 100644 --- a/app/controllers/origami/dinga_controller.rb +++ b/app/controllers/origami/dinga_controller.rb @@ -4,32 +4,32 @@ class Origami::DingaController < BaseOrigamiController payment_method = params[:payment_method] @cashier_type = params[:type] @membership_rebate_balance=0 - sale_data = Sale.find_by_sale_id(@sale_id) - @receipt_no = sale_data.receipt_no + @sale_data = Sale.find_by_sale_id(@sale_id) + @receipt_no = @sale_data.receipt_no @shop = Shop.first # if @shop.is_rounding_adj - # new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + # new_total = Sale.get_rounding_adjustment(@sale_data.grand_total) # else - # new_total = sale_data.grand_total + # new_total = @sale_data.grand_total # end - # @rounding_adj = new_total-sale_data.grand_total - @rounding_adj = sale_data.rounding_adjustment + # @rounding_adj = new_total-@sale_data.grand_total + @rounding_adj = @sale_data.rounding_adjustment @payparcount = 0 others = 0 - sale_data.sale_payments.each do |sale_payment| + @sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "dinga" @payparcount = @payparcount + sale_payment.payment_amount else others = others + sale_payment.payment_amount end end - @payment_prices = sale_data.grand_total - @payparcount -others + @payment_prices = @sale_data.grand_total - @payparcount -others - if sale_data - if sale_data.customer_id - customer_data= Customer.find_by_customer_id(sale_data.customer_id) + if @sale_data + if @sale_data.customer_id + customer_data= Customer.find_by_customer_id(@sale_data.customer_id) if customer_data @membership_id = customer_data.membership_id if !@membership_id.nil? @@ -73,6 +73,7 @@ def create cash = params[:payment_amount] sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] + account_no = params[:account_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop.first @@ -85,7 +86,7 @@ def create # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - status, @sale = sale_payment.process_payment(saleObj, @user, cash, "dinga",transaction_ref) + status, @sale = sale_payment.process_payment(saleObj, @user, cash, "dinga",account_no) if status == true @out = true, "Success!" else diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb index 65af0c3b..499a0625 100644 --- a/app/controllers/origami/paymal_controller.rb +++ b/app/controllers/origami/paymal_controller.rb @@ -73,6 +73,7 @@ def create cash = params[:payment_amount] sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] + account_no = params[:account_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop.first @@ -86,7 +87,7 @@ def create # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - status, @sale = sale_payment.process_payment(saleObj, @user, cash, "paymal",transaction_ref) + status, @sale = sale_payment.process_payment(saleObj, @user, cash, "paymal",account_no) if status == true @out = true, "Success!" else diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 201a1b57..50599f68 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -214,7 +214,7 @@ class SalePayment < ApplicationRecord # Control for Paypar Cloud begin response = HTTParty.post(url, - :body => { membership_id:membership_id, + :body => { account_no:membership_id, amount:received_amount, receipt_no:sale_data.receipt_no, merchant_uid:merchant_uid, @@ -242,7 +242,7 @@ class SalePayment < ApplicationRecord response =false; end - Rails.logger.debug "Payment response" + Rails.logger.debug "Create Payment response" Rails.logger.debug response.to_json return response; @@ -391,8 +391,13 @@ class SalePayment < ApplicationRecord #Next time - validate if the vochure number is valid - within customer_data = Customer.find_by_customer_id(self.sale.customer_id) + + account_no = self.payment_reference + if account_no == 0 + account_no = customer_data.customer_id + end membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) + membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,self.received_amount,self.sale.sale_id) #record an payment in sale-audit remark = "#{membership_data} PayMal Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " @@ -433,9 +438,17 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within + customer_data = Customer.find_by_customer_id(self.sale.customer_id) + + account_no = self.payment_reference + if account_no == 0 + account_no = customer_data.customer_id + end + + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) + membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,self.received_amount,self.sale.sale_id) #record an payment in sale-audit remark = "#{membership_data} Dinga Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " diff --git a/app/views/origami/dinga/index.html.erb b/app/views/origami/dinga/index.html.erb index 6a4fc12b..1bd18f39 100644 --- a/app/views/origami/dinga/index.html.erb +++ b/app/views/origami/dinga/index.html.erb @@ -46,6 +46,8 @@ + +
DINGA
- <% if @paymalcount != 0.0 %> + <% if @dingacount != 0.0 %>
<%= number_with_precision(@dingacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %>
<%= number_with_precision(0, precision: precision.to_i ) %>