From bf0f76ebc7ba539ce9dfc4b98cc7357b017ef2f4 Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 10 Jul 2018 18:12:25 +0630 Subject: [PATCH] credit payment function --- app/assets/javascripts/origami.js | 26 ++- app/controllers/origami/alipay_controller.rb | 24 +- .../origami/credit_payments_controller.rb | 10 +- .../origami/credit_sales_controller.rb | 6 +- .../origami/dashboard_controller.rb | 20 +- app/controllers/origami/jcb_controller.rb | 23 +- app/controllers/origami/master_controller.rb | 21 +- app/controllers/origami/mpu_controller.rb | 25 +- .../origami/others_payments_controller.rb | 7 +- .../origami/payments_controller.rb | 208 +++++++++-------- .../origami/unionpay_controller.rb | 23 +- app/controllers/origami/visa_controller.rb | 25 +- app/models/sale.rb | 27 +-- app/models/sale_payment.rb | 166 ++++++++++++-- app/views/origami/alipay/index.html.erb | 37 ++- app/views/origami/credit_sales/show.html.erb | 7 +- app/views/origami/home/index.html.erb | 2 +- app/views/origami/home/show.html.erb | 2 +- app/views/origami/jcb/index.html.erb | 37 ++- app/views/origami/master/index.html.erb | 149 +++++++----- app/views/origami/mpu/index.html.erb | 36 ++- app/views/origami/orders/show.html.erb | 2 +- .../origami/others_payments/index.html.erb | 14 +- app/views/origami/payments/show.html.erb | 154 ++++++++----- app/views/origami/rooms/show.html.erb | 2 +- app/views/origami/sales/show.html.erb | 2 +- app/views/origami/unionpay/index.html.erb | 216 ++++++++++-------- app/views/origami/visa/index.html.erb | 38 ++- config/routes.rb | 32 ++- 29 files changed, 879 insertions(+), 462 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 2ae1a664..9db79038 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -228,8 +228,8 @@ $(document).on('turbolinks:load', function() { }); $(document).on("click", ".credit_detail",function(){ - var sale_payment_id = $(this).attr("data-id"); - window.location.href = "/origami/cashier/credit_sales/"+sale_payment_id; + var sale_id = $(this).attr("data-id"); + window.location.href = "/origami/cashier/credit_sales/"+sale_id; }); }); @@ -391,7 +391,11 @@ function resCardSaleTrans(card_sale_trans_id,cmd_type,payment_type, bnk_bill_amo closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment/others_payment/"+payment_type; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/"+url_param+"/others_payment/"+payment_type; }); } } @@ -415,7 +419,11 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+"/payment"; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+"/"+url_param; }); } } @@ -435,8 +443,12 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment/others_payment/"+payment_type; - }); + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/"+url_param+"/others_payment/"+payment_type; + }); } } //end CB ECR integration @@ -555,7 +567,7 @@ function getCreditSales(filter, customer){ var receipt_date = sale_date.getFullYear() +'-'+ (sale_date.getMonth() > 10 ? sale_date.getMonth() : '0' + sale_date.getMonth()) +'-'+ (sale_date.getDate() > 10 ? sale_date.getDate() : '0' + sale_date.getDate()); $('.tbd_credit_lists').append(html_credit_items.formatUnicorn({ 'key':i, - 'sale_payment_id':credit_sales[i].sale_payment_id, + 'sale_id':credit_sales[i].sale_id, 'receipt_date':receipt_date +" "+timeFormat(sale_date), 'receipt_no':credit_sales[i].receipt_no, 'cashier_name':credit_sales[i].cashier_name, diff --git a/app/controllers/origami/alipay_controller.rb b/app/controllers/origami/alipay_controller.rb index d3b7c488..cbf54855 100644 --- a/app/controllers/origami/alipay_controller.rb +++ b/app/controllers/origami/alipay_controller.rb @@ -2,8 +2,13 @@ class Origami::AlipayController < BaseOrigamiController def index @sale_id = params[:sale_id] @cashier_type = params[:type] + path = request.fullpath # limit alipay_amount - sale_data = Sale.find_by_sale_id(@sale_id) + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end total = 0 @alipaycount = 0 @shop = Shop.first @@ -24,8 +29,13 @@ class Origami::AlipayController < BaseOrigamiController new_total = sale_data.grand_total end @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| + if path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end + + sale_payment_data.each do |sale_payment| if sale_payment.payment_method == "alipay" @alipaycount = @alipaycount + sale_payment.payment_amount else @@ -64,8 +74,14 @@ class Origami::AlipayController < BaseOrigamiController # end # saleObj = Sale.find(sale_id) + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end + sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "alipay",ref_no,payment_for) end end diff --git a/app/controllers/origami/credit_payments_controller.rb b/app/controllers/origami/credit_payments_controller.rb index 1aab35a5..e0789261 100755 --- a/app/controllers/origami/credit_payments_controller.rb +++ b/app/controllers/origami/credit_payments_controller.rb @@ -35,11 +35,11 @@ class Origami::CreditPaymentsController < BaseOrigamiController shop_details = Shop.first # 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 + # 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 diff --git a/app/controllers/origami/credit_sales_controller.rb b/app/controllers/origami/credit_sales_controller.rb index 6ecf3a46..8a836e96 100644 --- a/app/controllers/origami/credit_sales_controller.rb +++ b/app/controllers/origami/credit_sales_controller.rb @@ -12,8 +12,10 @@ class Origami::CreditSalesController < BaseOrigamiController @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") - @sale_payment = SalePayment.find_by_sale_payment_id(params[:sale_payment_id]) - @sale = Sale.find_by_sale_id(@sale_payment.sale_id) + @sale = Sale.find_by_sale_id(params[:sale_id]) + @sale_payment = SalePayment.select("SUM(payment_amount) as payment_amount") + .where("sale_id = ? and payment_method=?", @sale.sale_id, "creditnote") + @sale_taxes = [] sale_taxes = SaleTax.where("sale_id = ?", @sale.sale_id) if !sale_taxes.empty? diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index c2c77384..97ba21e4 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -4,23 +4,7 @@ class Origami::DashboardController < BaseOrigamiController @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') - # @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - # @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - - # @top_products = Sale.top_products(today).sum('i.qty') - # @bottom_products = Sale.bottom_products(today).sum('i.qty') - # @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) - # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') - # .sum(:grand_total) - # @employee_sales = Sale.employee_sales(today) - # .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') - # @inventories = StockJournal.inventory_balances(today).sum(:balance) - - # @total_sale = Sale.total_sale(today,current_user) - # @total_count = Sale.total_count(today,current_user) - # @total_card = Sale.total_card_sale(today,current_user) - # @total_credit = Sale.credit_payment(today,current_user) - + @display_type = Lookup.find_by_lookup_type("display_type") @sale_data = Array.new @@ -92,7 +76,7 @@ def get_all_menu end def get_credit_sales - credit_sales = Sale.get_credit_sales(params) + credit_sales = SalePayment.get_credit_sales(params) if !credit_sales.nil? result = {:status=> true, :data=> credit_sales } else diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index dece303a..8c55dbad 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -3,8 +3,13 @@ class Origami::JcbController < BaseOrigamiController def index @sale_id = params[:sale_id] @cashier_type = params[:type] + path = request.fullpath # limit jcb_amount - sale_data = Sale.find_by_sale_id(@sale_id) + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end total = 0 @jcbcount = 0 @shop = Shop.first @@ -25,8 +30,13 @@ class Origami::JcbController < BaseOrigamiController new_total = sale_data.grand_total end @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| + if path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end + + sale_payment_data.each do |sale_payment| if sale_payment.payment_method == "jcb" @jcbcount = @jcbcount + sale_payment.payment_amount else @@ -66,8 +76,13 @@ class Origami::JcbController < BaseOrigamiController # end # saleObj = Sale.find(sale_id) + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb",ref_no,payment_for) end end diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 1e4c972d..517347aa 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -3,8 +3,13 @@ class Origami::MasterController < BaseOrigamiController def index @sale_id = params[:sale_id] @cashier_type = params[:type] + path = request.fullpath # limit master_amount - sale_data = Sale.find_by_sale_id(@sale_id) + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end total = 0 @mastercount = 0 @shop = Shop.first @@ -25,8 +30,13 @@ class Origami::MasterController < BaseOrigamiController new_total = sale_data.grand_total end @rounding_adj = new_total-sale_data.grand_total + if path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end - sale_data.sale_payments.each do |sale_payment| + sale_payment_data.each do |sale_payment| if sale_payment.payment_method == "master" @mastercount = @mastercount + sale_payment.payment_amount else @@ -63,8 +73,13 @@ class Origami::MasterController < BaseOrigamiController # end # saleObj = Sale.find(sale_id) + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master",ref_no,payment_for) end end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 234cebaa..8301ee59 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -2,8 +2,13 @@ class Origami::MpuController < BaseOrigamiController def index @sale_id = params[:sale_id] @cashier_type = params[:type] + path = request.fullpath # limit mpu_amount - sale_data = Sale.find_by_sale_id(@sale_id) + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end total = 0 @mpucount = 0 @shop = Shop.first @@ -18,14 +23,19 @@ class Origami::MpuController < BaseOrigamiController others = 0 - if @shop.is_rounding_adj + if @shop.is_rounding_adj && (!path.include? ("credit_payment")) 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 path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end + + sale_payment_data.each do |sale_payment| if sale_payment.payment_method == "mpu" @mpucount = @mpucount + sale_payment.payment_amount else @@ -64,8 +74,13 @@ class Origami::MpuController < BaseOrigamiController # end # saleObj = Sale.find(sale_id) + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "mpu",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "mpu",ref_no,payment_for) end end diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb index e4a39662..3d95bbb0 100755 --- a/app/controllers/origami/others_payments_controller.rb +++ b/app/controllers/origami/others_payments_controller.rb @@ -3,7 +3,12 @@ class Origami::OthersPaymentsController < BaseOrigamiController @membership_rebate_balance = 0 @sale_id = params[:sale_id] @cashier_type = params[:type] - @payment_method_setting = PaymentMethodSetting.all + path = request.fullpath + if path.include? ("credit_payment") + @payment_method_setting = PaymentMethodSetting.where("LOWER(payment_method) in ('mpu','visa','master','jcb','unionpay','alipay') and is_active='1'") + else + @payment_method_setting = PaymentMethodSetting.all + end @rebate = MembershipSetting.find_by_rebate(1) @sale_data = Sale.find_by_sale_id(@sale_id) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index dd172af6..9022d85e 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -98,135 +98,142 @@ class Origami::PaymentsController < BaseOrigamiController member_info = nil type = params[:type] tax_type = params[:tax_type] + path = request.fullpath if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) #shop_detail = Shop.first # rounding adjustment - if shop_detail.is_rounding_adj - a = saleObj.grand_total % 25 # Modulus - b = saleObj.grand_total / 25 # Division - #not calculate rounding if modulus is 0 and division is even - #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - 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) + if !path.include? ("credit_payment") + if shop_detail.is_rounding_adj + a = saleObj.grand_total % 25 # Modulus + b = saleObj.grand_total / 25 # Division + #not calculate rounding if modulus is 0 and division is even + #calculate rounding if modulus is zero or not zero and division are not even + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + 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 end end #end rounding adjustment sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, current_user.name, cash, "cash") - - rebate_amount = nil - - # For Cashier by Zone - # bookings = Booking.where("sale_id='#{sale_id}'") - bookings = Booking.find_by_sale_id(sale_id) - if bookings.dining_facility_id.to_i > 0 - table = DiningFacility.find(bookings.dining_facility_id) - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) - - type = 'payment' - from = getCloudDomain #get sub domain in cloud mode - ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + if path.include? ("credit_payment") + sale_payment.process_payment(saleObj, current_user.name, cash, "cash", nil, true) else - shift = ShiftSale.find(saleObj.shift_sale_id) - cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + sale_payment.process_payment(saleObj, current_user.name, cash, "cash") end - # For Print - # 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? - receipt_bill_a5_pdf.each do |receipt_bilA5| - if receipt_bilA5[0] == 'ReceiptBillA5Pdf' - if receipt_bilA5[1] == '1' - unique_code = "ReceiptBillA5Pdf" - else - unique_code = "ReceiptBillPdf" + if !path.include? ("credit_payment") + rebate_amount = nil + + # For Cashier by Zone + # bookings = Booking.where("sale_id='#{sale_id}'") + bookings = Booking.find_by_sale_id(sale_id) + if bookings.dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings.dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + + type = 'payment' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + + # For Print + # 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? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + unique_code = "ReceiptBillA5Pdf" + else + unique_code = "ReceiptBillPdf" + end end end end - end - customer= Customer.find(saleObj.customer_id) + customer= Customer.find(saleObj.customer_id) - # get member information - rebate = MembershipSetting.find_by_rebate(1) - credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') - - if customer.membership_id != nil && rebate && credit_data.nil? - member_info = Customer.get_member_account(customer) - - if member_info["status"] == true - rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) - current_balance = SaleAudit.paymal_search(sale_id) - end - end - - #orders print out - if params[:type] == "quick_service" - booking = Booking.find_by_sale_id(sale_id) - if booking.dining_facility_id.to_i>0 - table_id = booking.dining_facility_id - else - table_id = 0 + # get member information + rebate = MembershipSetting.find_by_rebate(1) + credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') + + if customer.membership_id != nil && rebate && credit_data.nil? + member_info = Customer.get_member_account(customer) + + if member_info["status"] == true + rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) + current_balance = SaleAudit.paymal_search(sale_id) + end end - booking.booking_orders.each do |order| - # Order.pay_process_order_queue(order.order_id, table_id) - oqs = OrderQueueStation.new - oqs.pay_process_order_queue(order.order_id, table_id) + #orders print out + if params[:type] == "quick_service" + booking = Booking.find_by_sale_id(sale_id) + if booking.dining_facility_id.to_i>0 + table_id = booking.dining_facility_id + else + table_id = 0 + end + + booking.booking_orders.each do |order| + # Order.pay_process_order_queue(order.order_id, table_id) + oqs = OrderQueueStation.new + oqs.pay_process_order_queue(order.order_id, table_id) - assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id) - from = getCloudDomain #get sub domain in cloud mode - ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from + assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id) + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from + end + + end + + #for card sale data + card_data = Array.new + card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) + if !card_sale_trans_ref_no.nil? + card_sale_trans_ref_no.each do |cash_sale_trans| + card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s + card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s + card_no = cash_sale_trans.pan.last(4) + card_no = card_no.rjust(19,"**** **** **** ") + card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id}) + end end - end + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + # Calculate Food and Beverage Total + 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) - #for card sale data - card_data = Array.new - card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) - if !card_sale_trans_ref_no.nil? - card_sale_trans_ref_no.each do |cash_sale_trans| - card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s - card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s - card_no = cash_sale_trans.pan.last(4) - card_no = card_no.rjust(19,"**** **** **** ") - card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id}) - end - end - - # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) - # Calculate Food and Beverage Total - 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) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data) - printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data) + render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) - render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) - - #end + #end + end end end def show - if params[:sale_id] - sale_id = params[:sale_id] - end + path = request.fullpath + sale_id = params[:sale_id] @cashier_type = params[:type] - if params[:sale_payment_id] - sale_payment_id = params[:sale_payment_id] - @sale_payment = SalePayment.find(params[:sale_payment_id]) - sale_id = @sale_payment.sale_id + if path.include? ("credit_payment") + @sale_payment = SalePayment.select("SUM(payment_amount) as payment_amount") + .where("sale_id = ? and payment_method=?", sale_id, "creditnote") end @member_discount = MembershipSetting.find_by_discount(1) @@ -358,7 +365,12 @@ class Origami::PaymentsController < BaseOrigamiController end end - @sale_data.sale_payments.each do |spay| + if path.include? ("credit_payment") + @sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data) + else + @sale_payment_data = @sale_data.sale_payments + end + @sale_payment_data.each do |spay| if spay.payment_method == "cash" @cash = spay.payment_amount end diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 2bb5b0cf..daa7ac47 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -2,8 +2,13 @@ class Origami::UnionpayController < BaseOrigamiController def index @sale_id = params[:sale_id] @cashier_type = params[:type] + path = request.fullpath # limit unionpay_amount - sale_data = Sale.find_by_sale_id(@sale_id) + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end total = 0 @unionpaycount = 0 @shop = Shop.first @@ -23,8 +28,13 @@ class Origami::UnionpayController < BaseOrigamiController new_total = sale_data.grand_total end @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| + if path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end + + sale_payment_data.each do |sale_payment| if sale_payment.payment_method == "unionpay" @unionpaycount = @unionpaycount + sale_payment.payment_amount else @@ -62,8 +72,13 @@ class Origami::UnionpayController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay",ref_no,payment_for) end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index 4dc0912a..18e6e159 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -2,8 +2,13 @@ class Origami::VisaController < BaseOrigamiController def index @sale_id = params[:sale_id] @cashier_type = params[:type] - # limit visa_amount - sale_data = Sale.find_by_sale_id(@sale_id) + path = request.fullpath + # limit mpu_amount + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end total = 0 @visacount = 0 @shop = Shop.first @@ -23,8 +28,13 @@ class Origami::VisaController < BaseOrigamiController new_total = sale_data.grand_total end @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| + if path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end + + sale_payment_data.each do |sale_payment| if sale_payment.payment_method == "visa" @visacount = @visacount + sale_payment.payment_amount else @@ -62,8 +72,13 @@ class Origami::VisaController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa",ref_no,payment_for) end end diff --git a/app/models/sale.rb b/app/models/sale.rb index a6358e82..1d1f5b56 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1238,7 +1238,7 @@ end credit = 0.0 self.sale_payments.each do |pay| if pay.payment_method == 'creditnote' - credit = pay.payment_amount + credit += pay.payment_amount end end return credit @@ -2568,25 +2568,12 @@ def self.all_receipt_details return query end -def self.get_credit_sales(params) - receipt_no = "" - customer = "" - if !params["receipt_no"].blank? - receipt_no = " and s.receipt_no LIKE '%#{params["receipt_no"]}%'" - end - - if !params["customer_id"].blank? - customer = " and s.customer_id = '#{params["customer_id"]}'" - end - - query = SalePayment.select("s.receipt_no, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount,s.receipt_date as sale_date, - s.cashier_name as cashier_name, c.name as customer_name") - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .joins("INNER JOIN customers c ON c.customer_id = s.customer_id") - - query = query.where("payment_method='creditnote' and s.sale_status = 'completed' #{receipt_no} #{customer}") - .order("s.receipt_date ASC, s.receipt_no ASC") - +def self.get_sale_data_for_other_payment_credit(sale_id) + query = Sale.select("sales.sale_id,sales.receipt_no,sales.customer_id,SUM(sp.payment_amount) as total_amount,SUM(sp.payment_amount) as grand_total") + .joins(" JOIN sale_payments sp on sp.sale_id=sales.sale_id") + .where("sp.payment_method ='creditnote' and sales.sale_id='#{sale_id}'") + .group("sales.sale_id") + .first return query end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 9b52c248..b6133e82 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -8,14 +8,21 @@ class SalePayment < ApplicationRecord attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status - def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil) + def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil,payment_for=false) self.sale = invoice self.received_amount = cash_amount self.payment_reference = remark - amount_due = invoice.grand_total #get all payment for this invoices - invoice.sale_payments.each do |payment| + if payment_for + invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice) + amount_due = get_credit_total_left[0] ? get_credit_total_left[0].payment_amount.to_f : 0 + else + invoice_sale_payments = invoice.sale_payments + amount_due = invoice.grand_total + end + + invoice_sale_payments.each do |payment| if (payment.payment_status == "paid" ) amount_due = amount_due - payment.payment_amount end @@ -27,23 +34,23 @@ class SalePayment < ApplicationRecord #route to payment type case payment_method when "cash" - payment_status = cash_payment + payment_status = cash_payment(payment_for) when "creditnote" if !self.sale.customer_id.nil? payment_status = creditnote_payment(self.customer_id) end when "visa" - payment_status = external_terminal_card_payment(:visa) + payment_status = external_terminal_card_payment(:visa, payment_for) when "master" - payment_status = external_terminal_card_payment(:master) + payment_status = external_terminal_card_payment(:master, payment_for) when "jcb" - payment_status = external_terminal_card_payment(:jcb) + payment_status = external_terminal_card_payment(:jcb, payment_for) when "mpu" - payment_status = external_terminal_card_payment(:mpu) + payment_status = external_terminal_card_payment(:mpu, payment_for) when "unionpay" - payment_status = external_terminal_card_payment(:unionpay) + payment_status = external_terminal_card_payment(:unionpay, payment_for) when "alipay" - payment_status = external_terminal_card_payment(:alipay) + payment_status = external_terminal_card_payment(:alipay, payment_for) when "vochure" payment_status = vochure_payment when "giftcard" @@ -65,8 +72,22 @@ class SalePayment < ApplicationRecord end #record an payment in sale-audit - # remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" - sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) + remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" + if payment_for + shift = ShiftSale.current_open_shift(self.sale.cashier_id) + if !shift.nil? + shift_sale_id = shift.id + else + shift = ShiftSale.current_shift + shift_sale_id = shift.id + end + + remark = "#{self.sale_payment_id}||#{shift_sale_id} -> #{remark}" + + sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) + else + sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) + end # update complete order items in oqs booking = Booking.find_by_sale_id(sale_id) @@ -82,7 +103,7 @@ class SalePayment < ApplicationRecord return true, self.save,membership_data else #record an payment in sale-audit - # remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" + remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by) return false, "No outstanding Amount" @@ -280,21 +301,29 @@ class SalePayment < ApplicationRecord end private - def cash_payment + def cash_payment(payment_for=false) status = false sale_payments_data = SalePayment.find_by_sale_id(self.sale_id) if sale_payments_data.nil? status = true end - + payment_status = false self.payment_method = "cash" self.payment_amount = self.received_amount - self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + if !payment_for + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + else + credit_sale_payment = get_credit_total_left[0] ? get_credit_total_left[0].payment_amount.to_f : 0 ###need to calculate creditnote total in here + self.outstanding_amount = credit_sale_payment - self.received_amount.to_f + end self.payment_status = "paid" payment_method = self.save! - - sale_update_payment_status(self.received_amount,status) + if payment_for + update_shift_for_credit_payment + else + sale_update_payment_status(self.received_amount,status) + end return payment_status end @@ -333,15 +362,24 @@ class SalePayment < ApplicationRecord return payment_status end - def external_terminal_card_payment(method) + def external_terminal_card_payment(method, payment_for=false) payment_status = false self.payment_method = method self.payment_amount = self.received_amount # self.payment_reference = self.card_payment_reference - self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + if !payment_for + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + else + credit_payment = get_credit_total_left ###need to calculate creditnote total in here + self.outstanding_amount = credit_payment[0].payment_amount.to_f - self.received_amount.to_f + end self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) + if payment_for + update_shift_for_credit_payment + else + sale_update_payment_status(self.received_amount) + end return payment_status end @@ -594,6 +632,33 @@ class SalePayment < ApplicationRecord end end + # update for shift with credit payment + def update_shift_for_credit_payment + shift = ShiftSale.find_by_id(self.sale.shift_sale_id) + if !shift.nil? + credit_payment_left = get_credit_payment_left[0].payment_amount.to_f + if self.payment_method == "cash" + if credit_payment_left == 0 || credit_payment_left >= self.received_amount.to_f + shift.cash_sales = shift.cash_sales.to_f + self.received_amount.to_f + else + shift.cash_sales = shift.cash_sales.to_f + credit_payment_left + extra_changed_amount = self.received_amount.to_f - credit_payment_left + self.sale.amount_received = self.sale.amount_received.to_f + extra_changed_amount.to_f + self.sale.amount_changed = self.sale.amount_changed.to_f + extra_changed_amount.to_f + self.sale.save! + end + else + shift.other_sales = shift.other_sales.to_f + self.received_amount.to_f + end + if credit_payment_left == 0 || credit_payment_left >= self.received_amount.to_f + shift.credit_sales = shift.credit_sales.to_f - self.received_amount.to_f + else + shift.cash_sales = shift.credit_sales.to_f - credit_payment_left + end + shift.save + end + end + def table_update_status(sale_obj) status = true sale_count = 0 @@ -775,6 +840,65 @@ class SalePayment < ApplicationRecord end + #credit payment query + def self.get_credit_sales(params) + receipt_no = "" + customer = "" + if !params["receipt_no"].blank? + receipt_no = " and s.receipt_no LIKE '%#{params["receipt_no"]}%'" + end + + if !params["customer_id"].blank? + customer = " and s.customer_id = '#{params["customer_id"]}'" + end + + query = SalePayment.select("s.receipt_no, sale_payments.sale_payment_id, + sale_payments.payment_method, + SUM(sale_payments.payment_amount) as payment_amount, + s.receipt_date as sale_date, + s.sale_id, + s.cashier_name as cashier_name, c.name as customer_name") + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .joins("INNER JOIN customers c ON c.customer_id = s.customer_id") + .where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' #{receipt_no} #{customer}") + .group("s.receipt_no") + .order("s.receipt_date ASC, s.receipt_no ASC") + return query + end + + def get_credit_total_left + query = SalePayment.select("(SUM(sale_payments.payment_amount) - + (CASE WHEN SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id + THEN SUM(sale_payments.payment_amount) ELSE 0 END)) as payment_amount") + .joins(" LEFT JOIN sale_audits sa on SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id") + .where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{self.sale_id}'") + .group("sale_payments.sale_id") + return query + end + + def self.get_sale_payment_for_credit(sale_data) + query = sale_data.sale_payments + .joins(" JOIN sale_audits sa on SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id") + .where("sa.action='SALEPAYMENT' AND sa.remark IS NOT NULL + AND sale_payments.payment_method!='cash' + AND DATE_FORMAT(sale_payments.created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(sale_payments.created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' + ") + .group("sale_payments.sale_payment_id") + return query + end + + def get_credit_payment_left + query = SalePayment.select("(CASE WHEN (SUM(payment_amount) - (SELECT SUM(payment_amount) + from sale_payments + join sale_audits on SUBSTRING_INDEX(remark,'||',1)=sale_payment_id + where sale_payments.sale_id = '#{self.sale_id}')) > 0 THEN (SUM(payment_amount) - (SELECT SUM(payment_amount) + from sale_payments + join sale_audits on SUBSTRING_INDEX(remark,'||',1)=sale_payment_id + where sale_payments.sale_id = '#{self.sale_id}')) ELSE 0 END) as payment_amount") + .where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{self.sale_id}'") + return query + end + private def generate_custom_id self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI") diff --git a/app/views/origami/alipay/index.html.erb b/app/views/origami/alipay/index.html.erb index 4298183d..198413ca 100755 --- a/app/views/origami/alipay/index.html.erb +++ b/app/views/origami/alipay/index.html.erb @@ -116,7 +116,7 @@
- +
@@ -146,7 +146,11 @@ closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/payment/others_payment"; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/"+url_param+"/others_payment"; }); } } @@ -181,8 +185,8 @@ $('#amount').html("0.0"); break; case 'del' : - var cash=$('#amount').text(); - $('#amount').text(cash.substr(0,cash.length-1)); + var cash=$('#amount').text() > 0 ? $('#amount').text() : 0; + $('#amount').text((cash > 0 && cash.substr(0,cash.length-1) > 0) ? cash.substr(0,cash.length-1) : 0); break; case 'nett': var remain_amount = $('#validamount').val(); @@ -223,8 +227,14 @@ if(bank_integration == '1'){ pay_withBank("SALE", "alipay", amount, sale_id, receipt_no,cashier_type); }else{ + if(location.pathname.includes("credit_payment")){ + var url = "<%= origami_credit_payment_alipay_path %>"; + }else{ + var url = "<%= origami_payment_alipay_path %>"; + } + $.ajax({type: "POST", - url: "<%= origami_payment_alipay_path %>", + url: url, data: "amount="+ amount + "&sale_id="+ sale_id, success:function(result){ if(result){ @@ -236,7 +246,11 @@ closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/payment"; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/"+url_param; }); } } @@ -250,6 +264,15 @@ swal ( "Oops" , "Enter Amount!" , "error" ); } } - }) + }); + + $('#back').on('click',function(){ + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+'<%= @sale_id %>'+'/<%= @cashier_type %>/'+url_param; + // window.location.href = '/origami/sale/' + sale_id + "/cashier/payment"; + }); diff --git a/app/views/origami/credit_sales/show.html.erb b/app/views/origami/credit_sales/show.html.erb index bdee34ff..da5831fb 100755 --- a/app/views/origami/credit_sales/show.html.erb +++ b/app/views/origami/credit_sales/show.html.erb @@ -290,7 +290,7 @@ Credit Amount: - <%= @sale_payment.payment_amount rescue 0%> + <%= @sale_payment[0].payment_amount rescue 0%> @@ -309,7 +309,7 @@ diff --git a/app/views/origami/master/index.html.erb b/app/views/origami/master/index.html.erb index 09f27bd4..55c4d415 100755 --- a/app/views/origami/master/index.html.erb +++ b/app/views/origami/master/index.html.erb @@ -31,41 +31,41 @@ <% end %> -
-
- - <%@can_master = @can_master +@rounding_adj%> - +
+
+ + <%@can_master = @can_master +@rounding_adj%> + +
+
+
+ <% if @mastercount != 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +

- <% if @mastercount != 0 %> -
-
- - -
-
-
- <% end %>
- - -
+ +
0.0

-
-
- -
0.0
-
-
-
@@ -115,23 +115,23 @@
- +
diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index aa7dabb9..39b06f61 100755 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -116,7 +116,7 @@
- +
@@ -148,7 +148,11 @@ closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/payment/others_payment"; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/"+url_param+"/others_payment"; }); } } @@ -183,8 +187,8 @@ $('#amount').html("0.0"); break; case 'del' : - var cash=$('#amount').text(); - $('#amount').text(cash.substr(0,cash.length-1)); + var cash=$('#amount').text() > 0 ? $('#amount').text() : 0; + $('#amount').text((cash > 0 && cash.substr(0,cash.length-1) > 0) ? cash.substr(0,cash.length-1) : 0); break; case 'nett': var remain_amount = $('#validamount').val(); @@ -225,8 +229,13 @@ if(bank_integration == '1'){ pay_withBank("SALE", "mpu", amount, sale_id, receipt_no,cashier_type); }else{ + if(location.pathname.includes("credit_payment")){ + var url = "<%= origami_credit_payment_mpu_path %>"; + }else{ + var url = "<%= origami_payment_mpu_path %>"; + } $.ajax({type: "POST", - url: "<%= origami_payment_mpu_path %>", + url: url, data: "amount="+ amount + "&sale_id="+ sale_id, success:function(result){ if(result){ @@ -238,7 +247,11 @@ closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/payment"; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+ "/"+url_param; }); } } @@ -252,6 +265,15 @@ swal ( "Oops" , "Enter Amount!" , "error" ); } } - }) + }); + + $('#back').on('click',function(){ + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+'<%= @sale_id %>'+'/<%= @cashier_type %>/'+url_param; + // window.location.href = '/origami/sale/' + sale_id + "/cashier/payment"; + }); diff --git a/app/views/origami/orders/show.html.erb b/app/views/origami/orders/show.html.erb index a74089bb..1ed8bd4f 100755 --- a/app/views/origami/orders/show.html.erb +++ b/app/views/origami/orders/show.html.erb @@ -270,7 +270,7 @@ diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 3ca59c2e..16b3a709 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -118,7 +118,9 @@ <% else %> No Tax <% end %>
- + <%if @sale_payment.nil? %> + + <% end %> <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> @@ -164,21 +166,21 @@
-
Amount Due
+
Amount Due <% if !@sale_payment.nil? %>( Credit )<% end %>
<% if @sale_payment.nil? %> <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> <% else %> - <%= number_with_precision(@sale_payment.payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%> + <%= number_with_precision(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%> <% end %> @@ -206,12 +208,16 @@ <% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %>
Other Payments
-
<%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %>
+
+ <%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> +
<% else %>
Other Payments
-
<%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %>
+
+ <%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> +
<% end %>
@@ -399,22 +405,26 @@ <% if current_login_employee.role == "cashier" %> - <% if @other_payment <= 0%> + <% if @other_payment <= 0 && @sale_payment.nil? %> FOC <%end %> - Void - Waste - Spoile + <% if @sale_payment.nil? %> + Void + Waste + Spoile + <% end %> <% else %> - <% if @other_payment <= 0%> + <% if @other_payment <= 0 && @sale_payment.nil?%> - + <% if @sale_payment.nil? %> + + + <% end %> <% end %> -<% if @cashier_type=="quick_service" %> +<% if @cashier_type=="quick_service" && @sale_payment.nil? %>
@@ -710,7 +720,7 @@ var pdf_view = '<%=@pdf_view%>'; customer_display_view(null,"reload"); var sale_id = $('#sale_id').text(); if (cashier_type=="cashier") { - window.location.href = '/origami/table/'+ dining_id; + window.location.href = '/origami/table/'+ dining_id; }else{ window.location.href = '/origami/quick_service/pending_order/'+sale_id; } @@ -738,7 +748,11 @@ var pdf_view = '<%=@pdf_view%>'; $('#card_payment').click(function() { localStorage.setItem("cash",$('#cash').text() ); var sale_id = $('#sale_id').text(); - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment/others_payment" + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/"+url_param+"/others_payment"; return false; }); @@ -799,8 +813,15 @@ var pdf_view = '<%=@pdf_view%>'; // $("#pdfModal").on('shown.bs.modal', function () { // $('#pdfModal').focus() }).modal({show : true, backdrop : false, keyboard : false}); + /* check credit payment or not*/ + if(location.pathname.includes("credit_payment")){ + var url = "<%= origami_credit_payment_cash_path %>"; + }else{ + var url = "<%= origami_payment_cash_path %>"; + } + $.ajax({type: "POST", - url: "<%= origami_payment_cash_path %>", + url: url, data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type, success:function(result){ /* start delete receipt no in first bill*/ @@ -819,28 +840,31 @@ var pdf_view = '<%=@pdf_view%>'; } $("#loading_wrapper" ).hide(); - - //PDF lightbox data - var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); - $("#sale_receipt_no").val(result.receipt_no); - $("#filename").val(result.filename); - $("#printer_name").val(result.printer_name); - $("#receipt_pdf").attr("src", pdfPath); - $("#changed_amount").text(""); - if($('#balance').text() < 0){ - <% if precision.to_i > 0 %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); - <% else %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); - <% end %> - } - - if (pdf_view == 1) { - $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); - $("#pdfModalLabel").text("Sale Completed"); + if(location.pathname.includes("credit_payment")){ + payment_success_alert(); }else{ - //PDF lightbox data - print_receipt(); + //PDF lightbox data + var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); + $("#sale_receipt_no").val(result.receipt_no); + $("#filename").val(result.filename); + $("#printer_name").val(result.printer_name); + $("#receipt_pdf").attr("src", pdfPath); + $("#changed_amount").text(""); + if($('#balance').text() < 0){ + <% if precision.to_i > 0 %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); + <% else %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); + <% end %> + } + + if (pdf_view == 1) { + $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); + $("#pdfModalLabel").text("Sale Completed"); + }else{ + //PDF lightbox data + print_receipt(); + } } } }); @@ -948,7 +972,7 @@ var pdf_view = '<%=@pdf_view%>'; $(document).on('click', '.cashier_number', function(event){ if(event.handled !== true) { var original_value; - original_value = $('#cash').text(); + original_value = parseFloat($('#cash').text()); var input_type = $(this).attr("data-type"); @@ -1110,33 +1134,37 @@ var pdf_view = '<%=@pdf_view%>'; customer_display_view(null,"reload"); } }else{ - var title = "Payment Successful!"; - if($('#balance').text() < 0){ - var text = 'Changed amount ' + $('#balance').text() * (-1); - }else{ - $('#pay').text("Pay"); - var text = 'Thank You !'; - } - - swal({ - title: "Payment Successful!", - text: text, - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - if (cashier_type=="cashier") { - window.location.href = '/origami'; - }else{ - window.location.href = '/origami/quick_service'; - customer_display_view(null,"reload"); - } - }); + payment_success_alert(); } } }); } + + function payment_success_alert(){ + var title = "Payment Successful!"; + if($('#balance').text() < 0){ + var text = 'Changed amount ' + $('#balance').text() * (-1); + }else{ + $('#pay').text("Pay"); + var text = 'Thank You !'; + } + + swal({ + title: "Payment Successful!", + text: text, + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + if (cashier_type=="cashier") { + window.location.href = '/origami'; + }else{ + window.location.href = '/origami/quick_service'; + customer_display_view(null,"reload"); + } + }); + } $(".btn_pdf_close").on('click',function(){ diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 1914e3f0..f776e524 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -729,7 +729,7 @@ + }else{ + if (amount>0) { + swal ( "Oops" , "Paid Amount is over!" , "error" ); + }else{ + swal ( "Oops" , "Enter Amount!" , "error" ); + } + } + }); + + $('#back').on('click',function(){ + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+'<%= @sale_id %>'+'/<%= @cashier_type %>/'+url_param; + // window.location.href = '/origami/sale/' + sale_id + "/cashier/payment"; + }); + diff --git a/app/views/origami/visa/index.html.erb b/app/views/origami/visa/index.html.erb index 9101b9fe..51db7fa0 100755 --- a/app/views/origami/visa/index.html.erb +++ b/app/views/origami/visa/index.html.erb @@ -115,7 +115,7 @@
- +
@@ -146,7 +146,11 @@ closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment/others_payment"; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/"+url_param+"/others_payment"; }); } } @@ -181,8 +185,8 @@ $('#amount').html("0.0"); break; case 'del' : - var cash=$('#amount').text(); - $('#amount').text(cash.substr(0,cash.length-1)); + var cash=$('#amount').text() > 0 ? $('#amount').text() : 0; + $('#amount').text((cash > 0 && cash.substr(0,cash.length-1) > 0) ? cash.substr(0,cash.length-1) : 0); break; case 'nett': var remain_amount = $('#validamount').val(); @@ -200,8 +204,8 @@ var reference_no = $('#reference_no').val(); var sale_id = "<%= @sale_id %>"; var receipt_no = "<%= @receipt_no %>"; - console.log(amount); - console.log($("#validamount").attr("value")); + // console.log(amount); + // console.log($("#validamount").attr("value")); $("#reference_no_Err").html(""); if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) && amount > 0){ $(this).off("click"); @@ -224,8 +228,13 @@ pay_withBank("SALE", "visa", amount, sale_id, receipt_no,cashier_type); } else{ + if(location.pathname.includes("credit_payment")){ + var url = "<%= origami_credit_payment_visa_path %>"; + }else{ + var url = "<%= origami_payment_visa_path %>"; + } $.ajax({type: "POST", - url: "<%= origami_payment_visa_path %>", + url: url, data: "amount="+ amount + "&sale_id="+ sale_id, success:function(result){ if(result){ @@ -237,7 +246,11 @@ closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/"+url_param; }); } } @@ -251,4 +264,13 @@ } } }); + + $('#back').on('click',function(){ + var url_param = "payment"; + if(location.pathname.includes("credit_payment")){ + url_param = "credit_payment"; + } + window.location.href = '/origami/sale/'+'<%= @sale_id %>'+'/<%= @cashier_type %>/'+url_param; + // window.location.href = '/origami/sale/' + sale_id + "/cashier/payment"; + }); diff --git a/config/routes.rb b/config/routes.rb index ad66f6e3..95ff6ccd 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -289,8 +289,36 @@ scope "(:locale)", locale: /en|mm/ do #credit payment routes post '/:type/credit_sales' => "dashboard#get_credit_sales", :as => "get_credit_sales", :defaults => { :format => 'json' } - get '/:type/credit_sales/:sale_payment_id' => "credit_sales#show" - get 'sale/:sale_payment_id/:type/credit_sales' => "payments#show" + get '/:type/credit_sales/:sale_id' => "credit_sales#show" + get 'sale/:sale_id/:type/credit_payment' => "payments#show" + + post 'credit_payment/cash' => 'payments#create' + post 'credit_payment/mpu' => "mpu#create" + post 'credit_payment/jcb' => "jcb#create" + post 'credit_payment/master' => "master#create" + post 'credit_payment/visa' => "visa#create" + post 'credit_payment/unionpay' => "unionpay#create" + post 'credit_payment/paypar' => 'paypar_payments#create' + post 'credit_payment/voucher' => 'voucher_payments#create' + post 'credit_payment/paymal' => 'paymal#create' + post 'credit_payment/alipay' => 'alipay#create' + post 'credit_payment/junctionpay' => 'junction_pay#create' + post 'credit_payment/dinga' => 'dinga#create' + post 'credit_payment/gift_voucher' => 'gift_voucher#create' + + get 'sale/:sale_id/:type/credit_payment/others_payment' => "others_payments#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/MPU' => "mpu#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/VISA' => "visa#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/Master' => "master#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/JCB' => "jcb#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/PAYMAL' => "paymal#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/UNIONPAY' => "unionpay#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/Redeem' => "redeem_payments#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/Voucher' => "voucher#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/JunctionPay' => "junction_pay#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/Alipay' => "alipay#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/DINGA' => "dinga#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/GiftVoucher' => "gift_voucher#index" end #--------- Waiter/Ordering Station ------------#