From 6a9fd67bff40d8fd8489f127e0da05d0009efc9a Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 30 Mar 2018 15:24:51 +0630 Subject: [PATCH] check payment method --- app/assets/javascripts/origami.js | 2 +- app/controllers/api/payments_controller.rb | 11 + app/controllers/origami/alipay_controller.rb | 77 ++++++ app/controllers/origami/jcb_controller.rb | 3 +- app/controllers/origami/master_controller.rb | 3 +- app/controllers/origami/mpu_controller.rb | 3 +- .../origami/payments_controller.rb | 3 + .../origami/unionpay_controller.rb | 3 +- app/controllers/origami/visa_controller.rb | 3 +- app/models/sale_payment.rb | 4 +- app/views/origami/alipay/create.json.jbuilder | 5 + app/views/origami/alipay/index.html.erb | 258 ++++++++++++++++++ app/views/origami/payments/show.html.erb | 119 ++++---- config/locales/en.yml | 3 + config/locales/mm.yml | 3 + config/routes.rb | 4 + .../origami/alipay_controller_spec.rb | 5 + 17 files changed, 456 insertions(+), 53 deletions(-) create mode 100644 app/controllers/origami/alipay_controller.rb create mode 100755 app/views/origami/alipay/create.json.jbuilder create mode 100755 app/views/origami/alipay/index.html.erb create mode 100644 spec/controllers/origami/alipay_controller_spec.rb diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 7388529b..f2219711 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -323,7 +323,7 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun if(jobj.STATUS == "Approved"){ $.ajax({type: "POST", url: "/origami/payment/"+payment_type, - data: "amount="+ bnk_bill_amount + "&sale_id="+ sale_id, + data: "amount="+ bnk_bill_amount + "&sale_id="+ sale_id + "&ref_no=" + jobj.REFNUM, success:function(result){ if(result){ swal({ diff --git a/app/controllers/api/payments_controller.rb b/app/controllers/api/payments_controller.rb index 39219c6b..459589ed 100755 --- a/app/controllers/api/payments_controller.rb +++ b/app/controllers/api/payments_controller.rb @@ -84,6 +84,17 @@ class Api::PaymentsController < ActionController::API sale_payment.payment_reference = params[:payment_reference] #TODO: implement paypar implementation @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name) + when "JunctionPay" + sale_payment.payment_method = "JunctionPay" + sale_payment.received_amount = params[:amount] + sale_payment.customer_id = params[:customer_id] + sale_payment.payment_reference = params[:vochure_no] + @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name) + when "alipay" + sale_payment.payment_method = "alipay" + sale_payment.received_amount = params[:amount] + sale_payment.payment_reference = params[:payment_reference] + @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee.name) end end end diff --git a/app/controllers/origami/alipay_controller.rb b/app/controllers/origami/alipay_controller.rb new file mode 100644 index 00000000..3f449856 --- /dev/null +++ b/app/controllers/origami/alipay_controller.rb @@ -0,0 +1,77 @@ +class Origami::AlipayController < BaseOrigamiController + def index + @sale_id = params[:sale_id] + @cashier_type = params[:type] + # limit alipay_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = 0 + @alipaycount = 0 + @shop = Shop::ShopDetail + @rounding_adj = 0 + @can_alipay = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "alipay" + @alipaycount = @alipaycount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_alipay = total - @alipaycount - others + + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no + end + + bank_integration = Lookup.collection_of('bank_integration') + @bank_integration = 0 + if !bank_integration[0].nil? + @bank_integration = bank_integration[0][1] + end + end + + def create + cash = params[:amount] + sale_id = params[:sale_id] + ref_no = params[:ref_no] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + shop_details = Shop::ShopDetail + + # rounding adjustment + # if shop_details.is_rounding_adj + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # rounding_adj = new_total-saleObj.grand_total + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # end + + # saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no) + end + end + + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end +end diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index 5c06f9fe..315af34a 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -52,6 +52,7 @@ class Origami::JcbController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -65,7 +66,7 @@ class Origami::JcbController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb",ref_no) end end diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 858d0125..dc3a83d9 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -50,6 +50,7 @@ class Origami::MasterController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -63,7 +64,7 @@ class Origami::MasterController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master",ref_no) end end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 1b125bda..7d3ded34 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -51,6 +51,7 @@ class Origami::MpuController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -64,7 +65,7 @@ class Origami::MpuController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "mpu") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no) end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 5397c7f0..c31dd44d 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -226,6 +226,7 @@ class Origami::PaymentsController < BaseOrigamiController @jcbcount= 0.0 @mastercount = 0.0 @unionpaycount = 0.0 + @alipaycount = 0.0 @junctionpaycount = 0.0 @credit = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) @@ -346,6 +347,8 @@ class Origami::PaymentsController < BaseOrigamiController @junctionpaycount += spay.payment_amount elsif spay.payment_method == "creditnote" @credit += spay.payment_amount + elsif spay.payment_method == "alipay" + @alipaycount += spay.payment_amount end end end diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 7213af6d..ec941a20 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -48,6 +48,7 @@ class Origami::UnionpayController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -62,7 +63,7 @@ class Origami::UnionpayController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay",ref_no) end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index 346b66d1..8cc2bbe3 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -48,6 +48,7 @@ class Origami::VisaController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail @@ -62,7 +63,7 @@ class Origami::VisaController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa") + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa",ref_no) end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 3ff4697e..6b08a9fa 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -51,6 +51,8 @@ class SalePayment < ApplicationRecord payment_status = foc_payment when "JunctionPay" payment_status = junction_pay_payment + when "alipay" + payment_status = external_terminal_card_payment(:alipay) else puts "it was something else" end @@ -230,7 +232,7 @@ class SalePayment < ApplicationRecord payment_status = false self.payment_method = method self.payment_amount = self.received_amount - self.payment_reference = self.card_payment_reference + # self.payment_reference = self.card_payment_reference 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/alipay/create.json.jbuilder b/app/views/origami/alipay/create.json.jbuilder new file mode 100755 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/alipay/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/alipay/index.html.erb b/app/views/origami/alipay/index.html.erb new file mode 100755 index 00000000..a9959512 --- /dev/null +++ b/app/views/origami/alipay/index.html.erb @@ -0,0 +1,258 @@ +
+ + +
+
+ + + +
+
+
+ <% if @bank_integration == '1' %> +
+
+ + +
+
+
+ <% end %> +
+
+ + <%@can_alipay = @can_alipay +@rounding_adj%> + +
+
+
+ <% if @alipaycount != 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+
+
+ +
0.0
+
+
+
+
+
+
+
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+
+
+
+ +
+ + +
+
+
+ + diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index eb3eefe3..c33b6493 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -182,103 +182,125 @@
<% if @other != 0.0 %> -
-
-
MPU
-
<%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
-
+
<% else %> - + <% if @ppamount != 0.0 %>
-
-
Redeem
-
<%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
-
<% else %> - <% end %> + <% if @visacount != 0.0 %>
-
-
VISA
-
<%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
-
<% else %> - <% end %> + <% if @jcbcount != 0.0 %>
-
-
JCB
-
<%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
-
<% else %> - <% end %> + <% if @mastercount != 0.0 %>
-
-
MASTER
-
<%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
-
<% else %> - <% end %> + <% if @unionpaycount != 0.0 %>
-
-
UNIONPAY
-
<%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
-
<% else %> + + + <% if @alipaycount != 0.0 %> +
+ <% else %> + + <% if @junctionpaycount != 0.0 %>
-
-
JUNCTION PAY
-
<%= number_with_precision(@junctionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
-
<% else %> - <% end %> + +
Balance
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
@@ -584,6 +606,9 @@ var customer_name = "<%= @customer.name %>"; else if(payment_type == "UNIONPAY" && $('#unionpaycount').text()==0 && sub_total != 0.0){ swal("Oops","Please Pay with UNIONPAY Payment","warning"); } + else if(payment_type == "Alipay" && $('#alipaycount').text()==0 && sub_total != 0.0){ + swal("Oops","Please Pay with Alipay Payment","warning"); + } else if(payment_type == "JUNCTIONPAY" && $('#junctionpaycount').text()==0 && sub_total != 0.0){ swal("Oops","Please Pay with JUNCTIONPAY Payment","warning"); } @@ -866,8 +891,9 @@ var customer_name = "<%= @customer.name %>"; var jcb1 = $('#jcbcount').text(); var master1 = $('#mastercount').text(); var unionpay1 = $('#unionpaycount').text(); + var alipay1 = $('#alipaycount').text(); var junctionpay1 = $('#junctionpaycount').text(); - var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(junctionpay1); + var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1); var total = $('#amount_due').text(); var amt = 0; <% if precision.to_i > 0 %>; @@ -895,9 +921,10 @@ var customer_name = "<%= @customer.name %>"; var jcb = $('#jcbcount').text(); var master = $('#mastercount').text(); var unionpay = $('#unionpaycount').text(); + var alipay = $('#alipaycount').text(); var junctionpay = $('#junctionpaycount').text(); var amount_due = $('#amount_due').text(); - var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(junctionpay) + var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(alipay) + parseFloat(junctionpay) var result = parseFloat(amount_due) - parseFloat(total); <% if precision.to_i > 0 %> $('#balance').text(parseFloat(result).toFixed(<%= precision %>)); diff --git a/config/locales/en.yml b/config/locales/en.yml index 84a7b03a..dba88aee 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -122,6 +122,8 @@ en: mpu: "MPU" jcb: "JCB" visa: "VISA" + master: "MASTER" + alipay: "Alipay" credit: "CREDIT" other_payment: "Other Payment" percentage: "PERCENTAGE" @@ -412,6 +414,7 @@ en: redeem_sales: "Redeem Sales" cash_sales: "Cash Sales" credit_sales: "Credit Sales" + alipay_sales: "Alipay Sales" foc_sales: "FOC Sales" foc_item: "Item FOC" net_amount: "Net Amount" diff --git a/config/locales/mm.yml b/config/locales/mm.yml index f18136c4..e06733e9 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -117,6 +117,8 @@ mm: mpu: "MPU" jcb: "JCB" visa: "VISA" + master: "MASTER" + alipay: "Alipay" credit: "အကြွေး" other_payment: "အခြားငွေပေးဆောင်မှုများ" percentage: "ရာခိုင်နှုန်း" @@ -404,6 +406,7 @@ mm: master_sales: "Master ရောင်းရငွေ" visa_sales: "Visa ရောင်းရငွေ" jcb_sales: "JCB ရောင်းရငွေ" + alipay_sales: "Alipay ရောင်းရငွေ" redeem_sales: "ဆုကြေးပြန်သုံးငွေနှင့် ရောင်းရငွေ" cash_sales: "ငွေသား ရောင်းရငွေ" credit_sales: "အကြွေး ရောင်းရငွေ" diff --git a/config/routes.rb b/config/routes.rb index 233d7e04..6416f236 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -181,6 +181,8 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/paypar' => 'paypar_payments#create' post 'payment/credit' => 'credit_payments#create' post 'payment/voucher' => 'voucher_payments#create' + post 'payment/alipay' => 'alipay#create' + post 'payment/junctionpay' => 'junctionpay#create' get 'sale/:sale_id/:type/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/:type/payment/others_payment' => "others_payments#index" @@ -191,6 +193,8 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/UNIONPAY' => "unionpay#index" get 'sale/:sale_id/:type/payment/others_payment/Redeem' => "redeem_payments#index" get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/JunctionPay' => "junction_pay#index" + get 'sale/:sale_id/:type/payment/others_payment/Alipay' => "alipay#index" #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void' diff --git a/spec/controllers/origami/alipay_controller_spec.rb b/spec/controllers/origami/alipay_controller_spec.rb new file mode 100644 index 00000000..5994c9fa --- /dev/null +++ b/spec/controllers/origami/alipay_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Origami::AlipayController, type: :controller do + +end