diff --git a/app/assets/javascripts/origami/unionpay.coffee b/app/assets/javascripts/origami/unionpay.coffee
new file mode 100644
index 00000000..24f83d18
--- /dev/null
+++ b/app/assets/javascripts/origami/unionpay.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/origami/unionpay.scss b/app/assets/stylesheets/origami/unionpay.scss
new file mode 100644
index 00000000..6daa3524
--- /dev/null
+++ b/app/assets/stylesheets/origami/unionpay.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the origami/unionpay controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 3c43ce0b..8e10b0e1 100755
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -155,6 +155,7 @@ class Origami::PaymentsController < BaseOrigamiController
@visacount= 0.0
@jcbcount= 0.0
@mastercount = 0.0
+ @unionpaycount = 0.0
@credit = 0.0
@sale_data = Sale.find_by_sale_id(sale_id)
@balance = 0.00
@@ -216,6 +217,8 @@ class Origami::PaymentsController < BaseOrigamiController
@jcbcount += spay.payment_amount
elsif spay.payment_method == "master"
@mastercount += spay.payment_amount
+ elsif spay.payment_method == "unionpay"
+ @unionpaycount += spay.payment_amount
elsif spay.payment_method == "creditnote"
@credit += spay.payment_amount
end
@@ -272,7 +275,7 @@ class Origami::PaymentsController < BaseOrigamiController
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
-
+
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data)
end
diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb
new file mode 100644
index 00000000..a3f7e6ed
--- /dev/null
+++ b/app/controllers/origami/unionpay_controller.rb
@@ -0,0 +1,61 @@
+class Origami::UnionpayController < BaseOrigamiController
+ def index
+ @sale_id = params[:sale_id]
+
+ # limit unionpay_amount
+ sale_data = Sale.find_by_sale_id(@sale_id)
+ total = sale_data.grand_total
+ @unionpaycount = 0
+ others = 0
+
+ @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 == "unionpay"
+ @unionpaycount = @unionpaycount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ puts "unionpaycount"
+ puts @unionpaycount
+ @can_unionpay = total - @unionpaycount - 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
+ 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]
+ 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)
+ #end rounding adjustment
+ sale_payment = SalePayment.new
+ @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay")
+ end
+ end
+end
diff --git a/app/helpers/origami/unionpay_helper.rb b/app/helpers/origami/unionpay_helper.rb
new file mode 100644
index 00000000..3911575e
--- /dev/null
+++ b/app/helpers/origami/unionpay_helper.rb
@@ -0,0 +1,2 @@
+module Origami::UnionpayHelper
+end
diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb
index 8c719825..16b1fd58 100755
--- a/app/pdf/receipt_bill_pdf.rb
+++ b/app/pdf/receipt_bill_pdf.rb
@@ -512,12 +512,12 @@ class ReceiptBillPdf < Prawn::Document
#start card sale trans data
def card_sale_data(card_data)
- move_down 5
- stroke_horizontal_rule
- move_down 5
+ if card_data != nil && !card_data.empty?
+ move_down 5
+ stroke_horizontal_rule
+ move_down 5
- y_position = cursor
- if !card_data.nil?
+ y_position = cursor
card_data.each do |data|
if data['app'] == 'CUP'
data['app'] = 'UNIONPAY'
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb
index 77770247..dfff29cc 100755
--- a/app/views/origami/payments/show.html.erb
+++ b/app/views/origami/payments/show.html.erb
@@ -182,13 +182,13 @@
<% if @visacount != 0.0 %>
-
Visa
+
VISA
<%= @visacount %>
<% else %>
<% end %>
@@ -210,17 +210,31 @@
<% if @mastercount != 0.0 %>
-
Master
+
MASTER
<%= @mastercount %>
<% else %>
<% end %>
+
+ <% if @unionpaycount != 0.0 %>
+
+
+
UNIONPAY
+
<%= @unionpaycount %>
+
+ <% else %>
+
+ <% end %>
Balance
<%= @sale_data.grand_total rescue 0 %>
@@ -303,7 +317,7 @@
}else if(payment_type=="Credit"){
$("#card_payment").hide();
$("#others_payment").hide();
- }else if(payment_type=="MPU"||payment_type=="VISA"||payment_type=="JCB"||payment_type=="Master"){
+ }else if(payment_type=="MPU"||payment_type=="VISA"||payment_type=="JCB"||payment_type=="Master" || payment_type=="UNIONPAY"){
$("#credit_payment").hide();
}
/* end check first bill or not*/
@@ -361,17 +375,18 @@
update_balance();
break;
case 'nett':
- var credit1 = $('#credit').text();
- var card1 = $('#others').text();
- var paypar1 = $('#ppamount').text();
- var visa1 = $('#visacount').text();
- var jcb1 = $('#jcbcount').text();
- var master1 = $('#mastercount').text();
- var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1);
- var total = $('#amount_due').text();
- var amt = parseFloat(total) - parseFloat(othertotal);
- $('#cash').text(parseFloat(amt).toFixed(2));
- update_balance();
+ var credit1 = $('#credit').text();
+ var card1 = $('#others').text();
+ var paypar1 = $('#ppamount').text();
+ var visa1 = $('#visacount').text();
+ var jcb1 = $('#jcbcount').text();
+ var master1 = $('#mastercount').text();
+ var unionpay1 = $('#unionpaycount').text();
+ var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1);
+ var total = $('#amount_due').text();
+ var amt = parseFloat(total) - parseFloat(othertotal);
+ $('#cash').text(parseFloat(amt).toFixed(2));
+ update_balance();
break;
}
event.handled = true;
@@ -412,6 +427,9 @@
else if(payment_type == "Master" && $('#mastercount').text()==0 && sub_total != 0.0){
swal("Opps","Please Pay with Master Payment","warning");
}
+ else if(payment_type == "UNIONPAY" && $('#unionpaycount').text()==0 && sub_total != 0.0){
+ swal("Opps","Please Pay with UNIONPAY Payment","warning");
+ }
else if(payment_type == "Credit" && $('#credit').text()==0 && sub_total != 0.0){
swal("Opps","Please Pay with Credit Payment","warning");
}else{
@@ -515,8 +533,9 @@
var visa = $('#visacount').text();
var jcb = $('#jcbcount').text();
var master = $('#mastercount').text();
+ var unionpay = $('#unionpaycount').text();
var amount_due = $('#amount_due').text();
- var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master)
+ 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);
$('#balance').text(result.toFixed(2));
}
diff --git a/app/views/origami/unionpay/create.json.jbuilder b/app/views/origami/unionpay/create.json.jbuilder
new file mode 100755
index 00000000..9767a7d8
--- /dev/null
+++ b/app/views/origami/unionpay/create.json.jbuilder
@@ -0,0 +1,5 @@
+if(@status)
+ json.status @status
+else
+ json.status false
+end
diff --git a/app/views/origami/unionpay/index.html.erb b/app/views/origami/unionpay/index.html.erb
new file mode 100755
index 00000000..37476be9
--- /dev/null
+++ b/app/views/origami/unionpay/index.html.erb
@@ -0,0 +1,247 @@
+
+
+
+
UNIONPAY Payment
+
+
+
<%= @membership_id%>
+
<%= @member_discount%>
+
<%= @sub_total%>
+
+
+
+
+
+
+ reply Back
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb
index 5f57f339..a31dcb5c 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -156,6 +156,7 @@ scope "(:locale)", locale: /en|mm/ do
post 'payment/jcb' => "jcb#create"
post 'payment/master' => "master#create"
post 'payment/visa' => "visa#create"
+ post 'payment/unionpay' => "unionpay#create"
post 'payment/paypar' => 'paypar_payments#create'
post 'payment/credit' => 'credit_payments#create'
post 'payment/voucher' => 'voucher_payments#create'
@@ -166,6 +167,7 @@ scope "(:locale)", locale: /en|mm/ do
get 'sale/:sale_id/payment/others_payment/VISA' => "visa#index"
get 'sale/:sale_id/payment/others_payment/Master' => "master#index"
get 'sale/:sale_id/payment/others_payment/JCB' => "jcb#index"
+ get 'sale/:sale_id/payment/others_payment/UNIONPAY' => "unionpay#index"
get 'sale/:sale_id/payment/others_payment/Redeem' => "redeem_payments#index"
get 'sale/:sale_id/payment/others_payment/Voucher' => "voucher#index"
diff --git a/spec/controllers/origami/unionpay_controller_spec.rb b/spec/controllers/origami/unionpay_controller_spec.rb
new file mode 100644
index 00000000..059b5577
--- /dev/null
+++ b/spec/controllers/origami/unionpay_controller_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Origami::UnionpayController, type: :controller do
+
+end
diff --git a/spec/helpers/origami/unionpay_helper_spec.rb b/spec/helpers/origami/unionpay_helper_spec.rb
new file mode 100644
index 00000000..5fce324c
--- /dev/null
+++ b/spec/helpers/origami/unionpay_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'rails_helper'
+
+# Specs in this file have access to a helper object that includes
+# the Origami::UnionpayHelper. For example:
+#
+# describe Origami::UnionpayHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# expect(helper.concat_strings("this","that")).to eq("this that")
+# end
+# end
+# end
+RSpec.describe Origami::UnionpayHelper, type: :helper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end