diff --git a/README.md b/README.md index d3f2199f..9df29b68 100755 --- a/README.md +++ b/README.md @@ -287,6 +287,12 @@ For Online Order Receipt Setting For Close Cashier Print Settings settings/lookups => {type:close_cashier_print, name:CloseCashierPrint, value: {0 or 1} } +For Second Display View Setting +settings/lookups => {type:display_type, name: Display Type, value: 2} + +For show total before tax in receipt bill +settings/lookups => {type:show_total_before_tax, name:Show Total Before Tax, value: {0 or 1}} + * ToDo list 1. Migration diff --git a/app/assets/javascripts/channels/second_display_view.js b/app/assets/javascripts/channels/second_display_view.js index 721b098f..2e32201e 100644 --- a/app/assets/javascripts/channels/second_display_view.js +++ b/app/assets/javascripts/channels/second_display_view.js @@ -40,6 +40,7 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', { // } d_option = items[i].opt; + console.log(d_option) if (items[i].click_type != "add_icon"){ option_name = "-"+items[i].options; data_option = items[i].options ; @@ -54,7 +55,8 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', { $(item_row).each(function(j){ var item_code = $(item_row[j]).attr('data-code'); var instance_code = $(item_row[j]).attr('data-instance-code'); - var r_option = $(item_row[j]).attr('data-options'); + var r_option = $(item_row[j]).attr('data-opt'); + console.log(r_option) if (item_code == items[i].item_code && instance_code == items[i].instance_code && r_option==d_option) { if (qty > 1) { qty = parseInt($(item_row[j]).children('#item_qty').text()) + qty; diff --git a/app/controllers/api/payment/callback_controller.rb b/app/controllers/api/payment/callback_controller.rb index c2acb4d8..89162fc4 100644 --- a/app/controllers/api/payment/callback_controller.rb +++ b/app/controllers/api/payment/callback_controller.rb @@ -9,6 +9,9 @@ class Api::Payment::CallbackController < Api::ApiController total_amount = params[:Request][:total_amount] if trade_status == "PAY_SUCCESS" merch_order_id = params[:Request][:merch_order_id] + + status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, 'kbzpay', merch_order_id) + render json: JSON.generate({:status => status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index cb9fe88f..b15062d6 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -102,18 +102,20 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - #TODO :: KBZPAY ( QR ) # On/Off setting ( show or not qr ) # qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD" - kbz_pay_setting = PaymentMethodSetting.where(:payment_method => 'KBZPay').last + kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last status = false qr = nil - if !kbz_pay_setting.nil? - if kbz_pay_setting.is_active == true - status, qr = KbzPay.pay(sale_data.grand_total, sale_data.receipt_no) + if !kbz_pay_method.nil? + if kbz_pay_method.is_active == true + sale_payment = SalePayment.new + sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending') + + status, qr = KbzPay.pay(sale_data.grand_total, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters) end end @@ -125,6 +127,8 @@ class Origami::PaymentsController < BaseOrigamiController :printer_url => print_settings.api_settings } + # status, qr = KbzPay.query(sale_payment.sale_payment_id) + # Mobile Print render :json => result.to_json # end @@ -138,6 +142,7 @@ class Origami::PaymentsController < BaseOrigamiController tax_type = params[:tax_type] path = request.fullpath latest_order_no = nil + is_kbz = params[:is_kbz] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) @@ -159,12 +164,24 @@ class Origami::PaymentsController < BaseOrigamiController end #end rounding adjustment - sale_payment = SalePayment.new - if path.include? ("credit_payment") - sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true) + # if pay_from = 'kbzpay' + # salePayment = SalePayment.find(sale_payment_id) + # salePayment.process_kbz_payment(salePayment.sale_id, sale_data.grand_total, cash, 'paid') + # else + sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last + if is_kbz == 'false' + Rails.logger.info '################ CASH PAYMENT #################' + sale_payment = SalePayment.new + if path.include? ("credit_payment") + sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true) + else + sale_payment.process_payment(saleObj, current_user, cash, "cash") + end else - sale_payment.process_payment(saleObj, current_user, cash, "cash") + sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user) end + + # end if !path.include? ("credit_payment") rebate_amount = nil @@ -234,7 +251,7 @@ class Origami::PaymentsController < BaseOrigamiController end #orders print out - if params[:type] == "quick_service" + if 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 @@ -285,13 +302,22 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, 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,other_amount,latest_order_no,card_balance_amount,nil) - 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 + + # status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, nil, nil) + 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 + # def kbz_query + # sale_id = params[:sale_id] + # table_id = params[:table_id] + # sp = SalePayment.where('sale_id=?', sale_id).last + # status, table_id = KbzPay.query(sp.sale_payment_id) + # render json: JSON.generate({:status => status, :table_id => table_id, :message => @message}) + # end + def show display_type = Lookup.find_by_lookup_type("display_type") if !display_type.nil? && display_type.value.to_i ==2 @@ -318,6 +344,7 @@ class Origami::PaymentsController < BaseOrigamiController if Sale.exists?(sale_id) @cash = 0.0 + @kbz_pay_amount = 0.0 @other = 0.0 @ppamount = 0.0 @visacount= 0.0 @@ -342,6 +369,9 @@ class Origami::PaymentsController < BaseOrigamiController @pdf_view = @lookup_pdf.value end + amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) + @kbz_pay_amount += amount.to_f + #for changable on/off @changable_tax = true lookup_changable_tax = Lookup.collection_of('changable_tax') @@ -464,39 +494,40 @@ class Origami::PaymentsController < BaseOrigamiController else @sale_payment_data = SalePayment.get_sale_payments(@sale_data) end - @sale_payment_data.each do |spay| - if spay.payment_method == "cash" - @cash += spay.payment_amount - end - if spay.payment_method !="creditnote" - @other_payment += spay.payment_amount - end + @sale_payment_data.each do |spay| + if spay.payment_method == "cash" + @cash += spay.payment_amount + end + if spay.payment_method !="creditnote" + @other_payment += spay.payment_amount + end + + if spay.payment_method == "mpu" + @other += spay.payment_amount + elsif spay.payment_method == "paypar" + @ppamount += spay.payment_amount + elsif spay.payment_method == "visa" + @visacount += spay.payment_amount + elsif spay.payment_method == "jcb" + @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 == "JunctionPay" + @junctionpaycount += spay.payment_amount + elsif spay.payment_method == "creditnote" + @credit += spay.payment_amount + elsif spay.payment_method == "paymal" + @paymalcount += spay.payment_amount + elsif spay.payment_method == "alipay" + @alipaycount += spay.payment_amount + elsif spay.payment_method == "dinga" + @dingacount += spay.payment_amount + elsif spay.payment_method == "giftvoucher" + @giftvouchercount += spay.payment_amount + end - if spay.payment_method == "mpu" - @other += spay.payment_amount - elsif spay.payment_method == "paypar" - @ppamount += spay.payment_amount - elsif spay.payment_method == "visa" - @visacount += spay.payment_amount - elsif spay.payment_method == "jcb" - @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 == "JunctionPay" - @junctionpaycount += spay.payment_amount - elsif spay.payment_method == "creditnote" - @credit += spay.payment_amount - elsif spay.payment_method == "paymal" - @paymalcount += spay.payment_amount - elsif spay.payment_method == "alipay" - @alipaycount += spay.payment_amount - elsif spay.payment_method == "dinga" - @dingacount += spay.payment_amount - elsif spay.payment_method == "giftvoucher" - @giftvouchercount += spay.payment_amount - end end end end @@ -586,6 +617,7 @@ class Origami::PaymentsController < BaseOrigamiController other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) result = { diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index 0e94c7c4..7082e44c 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -30,7 +30,7 @@ class Origami::TableInvoicesController < BaseOrigamiController end def show - puts 'Catch me if you can.......................' + # puts 'Catch me if you can.......................' @table = DiningFacility.find(params[:table_id]) @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index 659b51e4..414c4e07 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -2,7 +2,7 @@ class Reports::PaymentMethodController < BaseReportController # authorize_resource :class => false def index - @payments = [["All Payment",''],["Cash Payment","cash"], ["Credit Payment","creditnote"], + @payments = [["All Payment",''],["Cash Payment","cash"], ["KBZ Payment", KbzPay::KBZ_PAY], ["Credit Payment","creditnote"], ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"], ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], ["Alipay Payment","alipay"],["Paymal Payment", "paymal"],["Dinga Payment","dinga"], diff --git a/app/models/kbz_pay.rb b/app/models/kbz_pay.rb index 2fb740f2..90fbac14 100644 --- a/app/models/kbz_pay.rb +++ b/app/models/kbz_pay.rb @@ -1,39 +1,47 @@ class KbzPay - def self.pay(amount, receipt_no) + KBZ_PAY = 'KBZPay' + + def self.pay(amount, receipt_no, url, key, app_id, code) datetime = DateTime.now.strftime("%d%m%Y%H%M") - kbz_app_id = "kp1e78f7efddca190042638341afb88d" - kbz_merch_code = "200004" + kbz_app_id = app_id + kbz_merch_code = code + # kbz_app_id = "kp1e78f7efddca190042638341afb88d" + # kbz_merch_code = "200004" kbz_method = 'kbz.payment.precreate' kbz_trade_type = "PAY_BY_QRCODE" - kbz_api_key = "code2lab123456" + kbz_api_key = key + # kbz_api_key = "code2lab123456" kbz_version = "1.0" - kbz_provider_url = "http://api.kbzpay.com/payment/gateway/uat/precreate" + kbz_provider_url = url + # kbz_provider_url = "http://api.kbzpay.com/payment/gateway/uat/precreate" kbz_currency = "MMK" kbz_callback_url = "https://staging-v2.doemal.com/api/v3/ordering/kbz_callback" nounce_str = SecureRandom.base64(32).first(32).upcase - params = "appid="+kbz_app_id+"&merch_code="+kbz_merch_code+"&merch_order_id="+receipt_no.to_s+"&method="+kbz_method+"&nonce_str="+nounce_str.to_s+"¬ify_url="+ kbz_callback_url + "×tamp="+datetime+"&total_amount="+amount.to_s+"&trade_type="+kbz_trade_type+"&trans_currency="+ kbz_currency+"&version="+kbz_version+"&key="+kbz_api_key + params = "appid="+kbz_app_id+"&merch_code="+kbz_merch_code+"&merch_order_id="+receipt_no.to_s+"&method="+kbz_method+"&nonce_str="+nounce_str.to_s+"¬ify_url="+ kbz_callback_url + "&timeout_express=20m×tamp="+datetime+"&total_amount="+amount.to_s+"&trade_type="+kbz_trade_type+"&trans_currency="+ kbz_currency+"&version="+kbz_version+"&key="+kbz_api_key Rails.logger.info params sign = Digest::SHA256.hexdigest(params) - str = {"timestamp": datetime, - "method": kbz_method, - "notify_url": kbz_callback_url, - "nonce_str": nounce_str.to_s, - "sign_type": "SHA256", - "sign": sign, - "version": kbz_version, - "biz_content": { - "merch_order_id": receipt_no, - "merch_code": kbz_merch_code, - "appid": kbz_app_id, - "trade_type": kbz_trade_type, - "total_amount": amount.to_s, - "trans_currency": kbz_currency - } - } + str = { + "timestamp": datetime, + "method": kbz_method, + "notify_url": kbz_callback_url, + "nonce_str": nounce_str.to_s, + "sign_type": "SHA256", + "sign": sign, + "version": kbz_version, + "biz_content": { + "merch_order_id": receipt_no, + "merch_code": kbz_merch_code, + "appid": kbz_app_id, + "trade_type": kbz_trade_type, + "total_amount": amount.to_s, + "timeout_express": "20m", + "trans_currency": kbz_currency + } + } result = HTTParty.post(kbz_provider_url, :body => { :Request => str}.to_json, @@ -51,4 +59,71 @@ class KbzPay end -end + def self.query(receipt_no, current_user) + amount = 0 + datetime = DateTime.now.strftime("%d%m%Y%H%M") + kbz_app_id = "kp1e78f7efddca190042638341afb88d" + kbz_merch_code = "200004" + kbz_method = 'kbz.payment.queryorder' + kbz_trade_type = "APP" + kbz_api_key = "code2lab123456" + kbz_version = "1.0" + kbz_provider_url = "http://api.kbzpay.com/payment/gateway/uat/queryorder" + kbz_currency = "MMK" + kbz_callback_url = "https://staging-v2.doemal.com/api/v3/ordering/kbz_callback" + nounce_str = SecureRandom.base64(32).first(32).upcase + + params = "appid="+kbz_app_id+"&merch_code="+kbz_merch_code+"&merch_order_id="+receipt_no.to_s+"&method="+kbz_method+"&nonce_str="+nounce_str.to_s+"×tamp="+datetime+"&version="+kbz_version+"&key="+kbz_api_key + + Rails.logger.info params + sign = Digest::SHA256.hexdigest(params) + str = {"timestamp": datetime, + "method": kbz_method, + "nonce_str": nounce_str.to_s, + "sign_type": "SHA256", + "sign": sign, + "version": kbz_version, + "biz_content": { + "merch_order_id": receipt_no, + "merch_code": kbz_merch_code, + "appid": kbz_app_id + } + } + + result = HTTParty.post(kbz_provider_url, + :body => { :Request => str}.to_json, + :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } + ) + Rails.logger.info result + Rails.logger.info "........................." + if result['Response']['result'] == "SUCCESS" + if result['Response']['trade_status'] == "PAY_SUCCESS" + merch_order_id = result['Response']['merch_order_id'] + cash = result['Response']['total_amount'] + + sp = SalePayment.find(merch_order_id) + if !sp.nil? + if sp.payment_status == 'pending' + saleObj = Sale.find(sp.sale_id) + if sp.process_payment(saleObj, current_user, cash, KbzPay::KBZ_PAY) + amount = cash + end + end + end + + # return true, "successfully paid by KBZ PAY" + elsif result['Response']['trade_status'] == "PAY_FAILED" + + # return false, "pay failed by KBZ PAY" + elsif result['Response']['trade_status'] == "WAIT_PAY" + # return false , "Waiting to pay by KBZ PAY" + end + else + #FAIL result + # return false, "pay by KBZ PAY has failed" + end + + return amount + end + +end \ No newline at end of file diff --git a/app/models/payment.rb b/app/models/payment.rb new file mode 100644 index 00000000..8635cbdb --- /dev/null +++ b/app/models/payment.rb @@ -0,0 +1,6 @@ +class Payment + + # def self.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, pay_from, sale_payment_id) + + # end +end \ No newline at end of file diff --git a/app/models/sale.rb b/app/models/sale.rb index b6f98b2a..779c21c6 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -921,6 +921,7 @@ def self.daily_sales_list(from,to) AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') = DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d')" payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, + SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount, SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount, SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount, SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount, @@ -970,6 +971,7 @@ def self.daily_sales_list(from,to) :paypar_amount => pay.paypar_amount, :unionpay_amount => pay.unionpay_amount, :alipay_amount => pay.alipay_amount, + :kbzpay_amount => pay.kbzpay_amount, :paymal_amount => pay.paymal_amount, :dinga_amount => pay.dinga_amount, :junctionpay_amount => pay.junctionpay_amount, @@ -1453,6 +1455,7 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount, SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount, SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount, + SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount, SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount, SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount, SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount, diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 7a7b6f4b..3e4fc085 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -34,7 +34,7 @@ class SaleOrder < ApplicationRecord private def generate_sale_order_id # self.class.name - saleOrderId = SeedGenerator.generate_id(self.class.name, "SOI") + saleOrderId = SeedGenerator.generate_id(self.class.name, 'SOI') self.sale_order_id = saleOrderId end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 1cfb53f3..53d9f1cc 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -29,6 +29,37 @@ class SalePayment < ApplicationRecord end end + def self.get_kbz_pay_amount(sale_id, current_user) + amount = 0 + sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last + if !sale_payment.nil? + if sale_payment.payment_status == 'pending' + amount = KbzPay.query(sale_payment.id, current_user) + elsif sale_payment.payment_status == 'paid' + amount = sale_payment.payment_amount + end + end + + return amount + end + + def process_kbz_payment(sale_id, grand_total, pay_amount, status) + if status == 'pending' + SalePayment.where("sale_id=? and payment_method=? and payment_status=?", sale_id, KbzPay::KBZ_PAY, 'pending').update_all(:payment_status => 'dead') + end + + self.sale_id = sale_id + self.payment_method = KbzPay::KBZ_PAY + self.payment_amount = self.payment_amount.to_i + pay_amount.to_i + if grand_total > 0 + self.outstanding_amount = grand_total.to_i - pay_amount.to_i + else + self.outstanding_amount = self.outstanding_amount.to_i - pay_amount.to_i + end + self.payment_status = status + return self.save + end + def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil,payment_for=false) self.sale = invoice self.received_amount = cash_amount @@ -90,8 +121,8 @@ class SalePayment < ApplicationRecord payment_status,membership_data = dinga_payment when "GiftVoucher" payment_status = giftvoucher_payment - when "KbzPay" - payment_status = giftvoucher_payment + when KbzPay::KBZ_PAY + payment_status = kbz_payment else puts "it was something else" end @@ -146,6 +177,11 @@ class SalePayment < ApplicationRecord end + def kbz_edit_sale_payment(amt, action_by) + self.action_by = action_by + sale_update_payment_status(amt) + end + def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token) # Control for Paypar Cloud begin @@ -346,6 +382,7 @@ class SalePayment < ApplicationRecord end payment_status = false + self.payment_method = "cash" self.payment_amount = self.received_amount if !payment_for @@ -354,8 +391,10 @@ class SalePayment < ApplicationRecord credit_sale_payment = SalePayment.get_credit_total_left(self.sale_id)[0] ? SalePayment.get_credit_total_left(self.sale_id)[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_status = self.save! + if !payment_for sale_update_payment_status(self.received_amount,status) end @@ -586,11 +625,13 @@ class SalePayment < ApplicationRecord def kbz_payment payment_status = false - status, response = KbzPay.pay(amount, receipt_no) - if status - payment_status = true - return - end + self.payment_amount = self.received_amount + self.payment_reference = self.payment_reference + self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f + self.payment_status = "paid" + payment_status = self.save! + # sale_update_payment_status(self.received_amount) + return payment_status end def sale_update_payment_status(paid_amount,check_foc = false) @@ -602,6 +643,7 @@ class SalePayment < ApplicationRecord sObj = Sale.find(self.sale_id) is_credit = 0 is_foc = 0 + is_kbz_pay = 0 method_status = false sObj.sale_payments.each do |spay| all_received_amount += spay.payment_amount.to_f @@ -611,7 +653,10 @@ class SalePayment < ApplicationRecord if spay.payment_method == "foc" is_foc = 1 end - if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" + if spay.payment_method == KbzPay::KBZ_PAY + is_kbz_pay = 1 + end + if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" || spay.payment_method == KbzPay::KBZ_PAY method_status = true end end @@ -629,6 +674,10 @@ class SalePayment < ApplicationRecord self.sale.payment_status = "foc" end + if is_kbz_pay == 1 + self.sale.payment_status = 'paid' + end + self.sale.sale_status = "completed" if MembershipSetting.find_by_rebate(1) && is_foc == 0 && is_credit == 0 diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 59294700..1749e1b8 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -157,6 +157,7 @@ class ShiftSale < ApplicationRecord SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount, SUM(case when (sale_payments.payment_method='unionpay') then (sale_payments.payment_amount) else 0 end) as unionpay_amount, SUM(case when (sale_payments.payment_method='alipay') then (sale_payments.payment_amount) else 0 end) as alipay_amount, + SUM(case when (sale_payments.payment_method='KBZPay') then (sale_payments.payment_amount) else 0 end) as kbzpay_amount, SUM(case when (sale_payments.payment_method='dinga') then (sale_payments.payment_amount) else 0 end) as dinga_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then (sale_payments.payment_amount) else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='JunctionPay') then (sale_payments.payment_amount) else 0 end) as junctionpay_amount, diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 9ff2f17a..d4564291 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -244,6 +244,16 @@ class CloseCashierPdf < Prawn::Document end end + if other.kbzpay_amount && other.kbzpay_amount.to_f > 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "KBZ Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end + if other.junctionpay_amount && other.junctionpay_amount.to_f > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 445a3f84..2a99e9f9 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -4,7 +4,7 @@ class ReceiptBillPdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move - + def initialize(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height @@ -105,9 +105,9 @@ class ReceiptBillPdf < Prawn::Document end if kbz_pay_status - pay_by_kbzpay(printed_status, qr_code) + kbzpay_qr_generator(printed_status, qr_code) end - + footer(printed_status) end @@ -135,7 +135,7 @@ class ReceiptBillPdf < Prawn::Document text "OrderNo : #{ latest_order_no }", :size => self.header_font_size,:align => :left end move_down line_move - + # move_down 2 y_position = cursor bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do @@ -152,7 +152,7 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right end @@ -170,7 +170,7 @@ class ReceiptBillPdf < Prawn::Document end # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do - # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } + # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" , # :size => self.item_font_size,:align => :right # end @@ -207,7 +207,7 @@ class ReceiptBillPdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - + if precision.to_i > 0 item_name_width = (self.item_width+self.price_width) item_qty_front_width = (self.item_width+self.price_width) + 5 @@ -224,18 +224,18 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor move_down line_move - sub_total = 0.0 + @sub_total = 0.0 total_qty = 0.0 show_price = Lookup.find_by_lookup_type("show_price") sale_items.each do |item| - # check for item not to show - + # check for item not to show + if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 - total_qty += item.qty + total_qty += item.qty else if item.price != 0 - total_qty += item.qty + total_qty += item.qty end end end @@ -248,13 +248,13 @@ class ReceiptBillPdf < Prawn::Document # total_price = -item.price #item.qty*item.unit_price - comment for room charges # price = -item.unit_price # else - sub_total += item.price #(item.qty*item.unit_price) - comment for room charges + @sub_total += item.price #(item.qty*item.unit_price) - comment for room charges qty = item.qty total_price = item.price #item.qty*item.unit_price - comment for room charges price = item.unit_price - + # end - + if !show_price.nil? && show_price.value.to_i>0 item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -263,7 +263,7 @@ class ReceiptBillPdf < Prawn::Document item_row(item,precision,delimiter,product_name,price,qty ,total_price) end end - + end stroke_horizontal_rule @@ -274,7 +274,7 @@ class ReceiptBillPdf < Prawn::Document text "Sub Total", :size => self.item_font_size,:align => :left end text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -297,10 +297,10 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width) do text "#{product_name}", :size => self.item_font_size,:align => :left end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -333,22 +333,78 @@ class ReceiptBillPdf < Prawn::Document text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end + service_tax_desc = "" + service_tax_amount = 0 + service_tax_rate = 0 + com_tax_desc = "" + com_tax_amount = 0 + com_tax_rate = 0 if sale_data.sale_taxes.length > 0 incl_tax = "" if sale_data.tax_type == "inclusive" incl_tax = "Incl." end - sale_data.sale_taxes.each do |st| - move_down line_move - y_position = cursor + find_lookup = Lookup.find_by_lookup_type('show_total_before_tax') + if find_lookup.nil? || find_lookup == nil + lookup = Lookup.new(lookup_type: 'show_total_before_tax', name: 'Show Total Before Tax', value: '0') + lookup.save + end + check_lookup_type = Lookup.find_by_lookup_type('show_total_before_tax') + if check_lookup_type.value == '1' + sale_data.sale_taxes.each do |st| + if (st.tax_name.include? "Service") + service_tax_desc = st.tax_name + service_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + if incl_tax + service_tax_rate = st.tax_rate.to_i + end + end + if (st.tax_name.include? "Commercial") + com_tax_desc = st.tax_name + com_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + if incl_tax + com_tax_rate = st.tax_rate.to_i + end + end + end + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + move_down line_move + y_position = cursor + stroke_horizontal_rule + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Total Before Tax", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{service_tax_amount.to_i + @sub_total.to_i}" , :size => self.item_font_size,:align => :right + end + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + else + sale_data.sale_taxes.each do |st| + move_down line_move + y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + end end else @@ -373,7 +429,7 @@ class ReceiptBillPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right - end + end end move_down line_move @@ -386,11 +442,11 @@ class ReceiptBillPdf < Prawn::Document text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move - - sale_payment(sale_data,precision,delimiter) + + sale_payment(sale_data,precision,delimiter) end - def sale_payment(sale_data,precision,delimiter) + def sale_payment(sale_data,precision,delimiter) stroke_horizontal_rule #move_down line_move sql = "SELECT SUM(payment_amount) @@ -422,13 +478,13 @@ class ReceiptBillPdf < Prawn::Document text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left end end - + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end - if sale_data.amount_received > 0 + if sale_data.amount_received > 0 y_position = cursor move_down line_move bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do @@ -443,7 +499,7 @@ class ReceiptBillPdf < Prawn::Document # show member information def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) - if rebate_amount != nil + if rebate_amount != nil if rebate_amount["status"] == true stroke_horizontal_rule total = 0 @@ -472,8 +528,8 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - - end + + end # Total Rebate Amount if birthday if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate" rebate_balance = rebate_balance + res["deposit"] @@ -485,7 +541,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - end + end #end Total rebate if birthday end @@ -508,7 +564,7 @@ class ReceiptBillPdf < Prawn::Document text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end - + end end @@ -518,7 +574,7 @@ class ReceiptBillPdf < Prawn::Document if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" total_balance = total_balance + res["balance"] - + end end move_down line_move @@ -530,7 +586,7 @@ class ReceiptBillPdf < Prawn::Document text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end - + end def customer(customer_name) @@ -560,7 +616,7 @@ class ReceiptBillPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right - end + end move_down line_move end end @@ -577,7 +633,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - move_down line_move + move_down line_move end end @@ -589,7 +645,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - move_down line_move + move_down line_move end #individual payment per person @@ -629,17 +685,17 @@ class ReceiptBillPdf < Prawn::Document JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id where sa.sale_id='#{sale_data.sale_id}')) = 0 - THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| + THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| if payment.payment_method == "creditnote" y_position = cursor stroke_horizontal_rule - + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 70 stroke_horizontal_rule end - + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center @@ -656,7 +712,7 @@ class ReceiptBillPdf < Prawn::Document move_down 70 stroke_horizontal_rule end - + if sale_data.payment_status == "foc" bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 73 @@ -667,9 +723,9 @@ class ReceiptBillPdf < Prawn::Document move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center end - end + end end - + end def shop_note(shop) @@ -679,20 +735,22 @@ class ReceiptBillPdf < Prawn::Document move_down line_move y_position = cursor - - text "#{shop.note}", :size => self.item_font_size, :align => :left + + text "#{shop.note}", :size => self.item_font_size, :align => :left move_down line_move end - def pay_by_kbzpay(status, qr_code) + def kbzpay_qr_generator(status, qr_code) if status == 'Frt' move_down line_move move_down line_move - text "KBZ Pay", :size => self.header_font_size+2, :align => :center + text "Scan to pay with KBZ Pay", :size => self.header_font_size, :align => :center + move_down line_move + print_qr_code(qr_code, pos: [39, cursor], extent: 161, stroke: false, dot: 1000) + move_down line_move + text "This QR code will be expired after 20 minutes.", :size => self.item_font_size, :align => :center move_down line_move - print_qr_code(qr_code, pos: [30, cursor], extent: 160, stroke: false, dot: 1000) - # stroke_horizontal_rule move_down line_move end end @@ -706,10 +764,10 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :left - end + end move_down line_move end @@ -747,7 +805,7 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right end @@ -771,4 +829,4 @@ class ReceiptBillPdf < Prawn::Document end return status end -end \ No newline at end of file +end diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index eff2812b..03fe1943 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -540,6 +540,8 @@ + + @@ -1072,6 +1074,24 @@ } }); + // $('#kbz_query').on('click', function(){ + // var sale_id = $('#sale_id').val(); + // var dining_id = "<%= @dining.id %>"; + // // window.location.href = '/origami/payment/kbz_query/'+ sale_id; + // $.ajax({ + // type: 'POST', + // data: 'table_id='+dining_id, + // url: '/origami/payment/kbz_query/'+sale_id, + // success: function(result){ + // if (result.status == true) { + // window.location.href = '/origami'; + // }else{ + // location.reload() + // } + // } + // }) + // }) + // Bill Request $('#request_bills').click(function () { var order_id = $('#save_order_id').attr('data-order'); diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 6c86805b..ab62eb7e 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -201,7 +201,14 @@ <% else %>
<% end %> - <% 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 %> + <% if @kbz_pay_amount > 0.0 %> +