From fa125df35579b03e96c483e8203d5405357c0c48 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 16 Mar 2018 18:37:54 +0630 Subject: [PATCH] add junction pay --- .../origami/junction_pay_controller.rb | 58 ++++ .../origami/payments_controller.rb | 11 +- app/models/sale_payment.rb | 18 ++ app/views/origami/home/show.html.erb | 2 +- .../origami/junction_pay/create.json.jbuilder | 5 + app/views/origami/junction_pay/index.html.erb | 259 ++++++++++++++++++ app/views/origami/payments/show.html.erb | 22 +- config/routes.rb | 2 + 8 files changed, 369 insertions(+), 8 deletions(-) create mode 100644 app/controllers/origami/junction_pay_controller.rb create mode 100755 app/views/origami/junction_pay/create.json.jbuilder create mode 100755 app/views/origami/junction_pay/index.html.erb diff --git a/app/controllers/origami/junction_pay_controller.rb b/app/controllers/origami/junction_pay_controller.rb new file mode 100644 index 00000000..c02461aa --- /dev/null +++ b/app/controllers/origami/junction_pay_controller.rb @@ -0,0 +1,58 @@ +class Origami::JunctionPayController < BaseOrigamiController + + def index + @sale_id = params[:sale_id] + @cashier_type = params[:type] + # limit jcb_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = sale_data.grand_total + @junction_pay_count = 0 + others = 0 + @cashier_id = current_user.emp_id + + @payment_method_setting_nav = PaymentMethodSetting.all + @shop = Shop::ShopDetail + 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 == "JunctionPay" + @junction_pay_count = @junction_pay_count + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_junction_pay = total - @junction_pay_count - 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 + + def create + cash = params[:amount] + sale_id = params[:sale_id] + 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, "JunctionPay") + end + end + +end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index fc07f966..1b4bd5bb 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -27,7 +27,7 @@ class Origami::PaymentsController < BaseOrigamiController cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) end - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf # Print for First Bill to Customer unique_code = "ReceiptBillPdf" @@ -89,7 +89,7 @@ class Origami::PaymentsController < BaseOrigamiController # Mobile Print render :json => result.to_json - end + # end end def create @@ -138,7 +138,7 @@ class Origami::PaymentsController < BaseOrigamiController end # For Print - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf unique_code = "ReceiptBillPdf" if !receipt_bill_a5_pdf.empty? @@ -202,8 +202,8 @@ class Origami::PaymentsController < BaseOrigamiController booking.booking_orders.each do |order| Order.pay_process_order_queue(order.order_id,table_id) end + # end end - end end end @@ -221,6 +221,7 @@ class Origami::PaymentsController < BaseOrigamiController @jcbcount= 0.0 @mastercount = 0.0 @unionpaycount = 0.0 + @junctionpaycount = 0.0 @credit = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) @balance = 0.00 @@ -333,6 +334,8 @@ class Origami::PaymentsController < BaseOrigamiController @mastercount += spay.payment_amount elsif spay.payment_method == "unionpay" @unionpaycount += spay.payment_amount + elsif spay.payment_method == "junctionpay" + @unionpaycount += spay.payment_amount elsif spay.payment_method == "creditnote" @credit += spay.payment_amount end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5809dc0f..c49f30a7 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -48,6 +48,8 @@ class SalePayment < ApplicationRecord payment_status = paypar_payment when "foc" payment_status = foc_payment + when "JunctionPay" + payment_status = junction_pay_payment else puts "it was something else" end @@ -297,6 +299,22 @@ class SalePayment < ApplicationRecord end + def junction_pay_payment + payment_status = false + + #Next time - validate if the vochure number is valid - within + self.payment_method = "JunctionPay" + self.payment_amount = self.received_amount + self.payment_reference = self.voucher_no + self.outstanding_amount = self.sale.grand_total- self.received_amount + self.payment_status = "paid" + payment_method = self.save! + sale_update_payment_status(self.received_amount) + + return payment_status + + end + def sale_update_payment_status(paid_amount,check_foc = false) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 5f0245a9..571758be 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -691,7 +691,7 @@ createReceiptNoInFirstBillData(receipt_no,""); // console.log(result); - code2lab.printBill(result.filepath, result.printer_model, result.printer_url); + // code2lab.printBill(result.filepath, result.printer_model, result.printer_url); location.reload(); } }); diff --git a/app/views/origami/junction_pay/create.json.jbuilder b/app/views/origami/junction_pay/create.json.jbuilder new file mode 100755 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/junction_pay/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/junction_pay/index.html.erb b/app/views/origami/junction_pay/index.html.erb new file mode 100755 index 00000000..4e371f76 --- /dev/null +++ b/app/views/origami/junction_pay/index.html.erb @@ -0,0 +1,259 @@ +
+ + +
+
+ + + +
+
+
+
+ + +
+
+
+ +
+
+ + <%@can_junction_pay = @can_junction_pay +@rounding_adj%> + +
+
+
+ <% if @jcbcount != 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 2deb9c0c..84ff842d 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -265,6 +265,20 @@
<%= number_with_precision(0, precision: precision.to_i ) %>
<% end %> + + <% 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 ) %>
@@ -488,10 +502,7 @@ var customer_name = "<%= @customer.name %>"; payment_type = ''; if ($("#server_mode").val() != "cloud") { // first bill not used in cloud - console.log("ssssssssssss") payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment"); - console.log(member_id); - console.log(member_discount); if (member_id && member_discount) { if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){ $("#credit_payment").hide(); @@ -562,6 +573,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 == "JUNCTIONPAY" && $('#junctionpaycount').text()==0 && sub_total != 0.0){ + swal("Oops","Please Pay with JUNCTIONPAY Payment","warning"); + } else if(payment_type == "Credit" && $('#credit').text()==0 && sub_total != 0.0){ swal("Oops","Please Pay with Credit Payment","warning"); }else{ @@ -837,6 +851,7 @@ var customer_name = "<%= @customer.name %>"; var jcb1 = $('#jcbcount').text(); var master1 = $('#mastercount').text(); var unionpay1 = $('#unionpaycount').text(); + var junctionpay1 = $('#junctionpaycount').text(); var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1); var total = $('#amount_due').text(); var amt = 0; @@ -865,6 +880,7 @@ var customer_name = "<%= @customer.name %>"; var jcb = $('#jcbcount').text(); var master = $('#mastercount').text(); var unionpay = $('#unionpaycount').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) var result = parseFloat(amount_due) - parseFloat(total); diff --git a/config/routes.rb b/config/routes.rb index 21395c32..57cd404f 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -177,6 +177,7 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/master' => "master#create" post 'payment/visa' => "visa#create" post 'payment/unionpay' => "unionpay#create" + post 'payment/junctionpay' => "junction_pay#create" post 'payment/paypar' => 'paypar_payments#create' post 'payment/credit' => 'credit_payments#create' post 'payment/voucher' => 'voucher_payments#create' @@ -188,6 +189,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/Master' => "master#index" get 'sale/:sale_id/:type/payment/others_payment/JCB' => "jcb#index" get 'sale/:sale_id/:type/payment/others_payment/UNIONPAY' => "unionpay#index" + get 'sale/:sale_id/:type/payment/others_payment/JUNCTIONPAY' => "junction_pay#index" get 'sale/:sale_id/:type/payment/others_payment/Redeem' => "redeem_payments#index" get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index"