sx cash payment api
This commit is contained in:
@@ -21,6 +21,7 @@ class Api::ApiController < ActionController::API
|
||||
|
||||
def current_login_employee
|
||||
@employee = Employee.find_by_token_session(current_token)
|
||||
puts @employee.to_json
|
||||
end
|
||||
|
||||
# def lookup_domain
|
||||
|
||||
163
app/controllers/api/payment/mobilepayment_controller.rb
Normal file
163
app/controllers/api/payment/mobilepayment_controller.rb
Normal file
@@ -0,0 +1,163 @@
|
||||
class Api::Payment::MobilepaymentController < Api::ApiController
|
||||
# skip_before_action :authenticate
|
||||
def cash
|
||||
|
||||
cash = params[:cash]
|
||||
sale_id = params[:sale_id]
|
||||
member_info = nil
|
||||
type = params[:type]
|
||||
tax_type = params[:tax_type]
|
||||
path = request.fullpath
|
||||
latest_order_no = nil
|
||||
cashier_id = params[:cashier_id]
|
||||
current_user = Employee.find(cashier_id)
|
||||
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 !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 =sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
||||
if sale_payment[0]
|
||||
@cash ={"change_amount"=>sale_payment[3],"balance_amount"=>sale_payment[4] ,"receipt_url"=>''}
|
||||
end
|
||||
@out = true,@cash
|
||||
# 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)
|
||||
|
||||
# shift = ShiftSale.current_open_shift(current_user.id)
|
||||
# if !shift.nil?
|
||||
# cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
# else
|
||||
# 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
|
||||
# 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"
|
||||
# print_settings = PrintSetting.all
|
||||
# if !print_settings.nil?
|
||||
# print_settings.each do |setting|
|
||||
# if setting.unique_code == 'ReceiptBillPdf'
|
||||
# unique_code = "ReceiptBillPdf"
|
||||
# elsif setting.unique_code == 'ReceiptBillStarPdf'
|
||||
# unique_code = "ReceiptBillStarPdf"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# 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"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# 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
|
||||
# end
|
||||
|
||||
# latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
|
||||
# if !latest_order.nil?
|
||||
# latest_order_no = latest_order.order_id
|
||||
# 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
|
||||
# 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
|
||||
|
||||
# #card_balance amount for Paymal payment
|
||||
# card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
|
||||
|
||||
# # 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)
|
||||
# other_amount = SaleItem.calculate_other_charges(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,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
|
||||
end
|
||||
end
|
||||
@@ -278,6 +278,8 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
end
|
||||
|
||||
def show
|
||||
puts current_user
|
||||
puts "Hello current_user"
|
||||
path = request.fullpath
|
||||
sale_id = params[:sale_id]
|
||||
@trans_flag = true
|
||||
|
||||
@@ -38,6 +38,7 @@ class Origami::RequestBillsController < ApplicationController
|
||||
in_duties.each do |in_duty|
|
||||
induty = InDuty.find(in_duty.id)
|
||||
induty.sale_id = @sale_id
|
||||
induty.out_time =Time.now.utc
|
||||
induty.save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,10 +70,8 @@ class Sale < ApplicationRecord
|
||||
induties_pay_amount = (current_checkin_induties_count.to_i * (distance_in_minutes / 60.0).to_f * basic_pay_amount).to_i
|
||||
create_saleitem_indutycharges(charges, current_checkin_induties_count.to_i, induties_pay_amount, booking.dining_facility.name, dining_time, order_source, basic_pay_amount)
|
||||
end
|
||||
|
||||
create_saleitem_diningcharges(charges, block_count, diningprice, booking.dining_facility.name, dining_time, order_source)
|
||||
end
|
||||
|
||||
return status, sale_id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ class SalePayment < ApplicationRecord
|
||||
#route to payment type
|
||||
case payment_method
|
||||
when "cash"
|
||||
payment_status = cash_payment(payment_for)
|
||||
payment_status ,outstanding_amount ,balance_amount = cash_payment(payment_for)
|
||||
when "creditnote"
|
||||
if !self.sale.customer_id.nil?
|
||||
payment_status = creditnote_payment(self.customer_id)
|
||||
@@ -106,7 +106,7 @@ class SalePayment < ApplicationRecord
|
||||
# end
|
||||
end
|
||||
|
||||
return true, self.save,membership_data
|
||||
return true, self.save,membership_data, outstanding_amount ,balance_amount
|
||||
else
|
||||
#record an payment in sale-audit
|
||||
remark = "Payment failed - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
|
||||
@@ -336,7 +336,16 @@ class SalePayment < ApplicationRecord
|
||||
if !payment_for
|
||||
sale_update_payment_status(self.received_amount,status)
|
||||
end
|
||||
return payment_status
|
||||
balance_amount =0.0
|
||||
outstanding_amount =0.0
|
||||
if self.sale.grand_total.to_f > self.received_amount.to_f
|
||||
balance_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||
outstanding_amount = 0.0
|
||||
else
|
||||
balance_amount = 0.0
|
||||
outstanding_amount = self.received_amount.to_f - self.sale.grand_total.to_f
|
||||
end
|
||||
return payment_status , outstanding_amount.to_i, balance_amount.to_i
|
||||
end
|
||||
|
||||
def foc_payment
|
||||
|
||||
2
app/views/api/payment/mobilepayment/cash.json.jbuilder
Normal file
2
app/views/api/payment/mobilepayment/cash.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.set! :status, @out[0]
|
||||
json.set! :data, @out[1]
|
||||
@@ -56,7 +56,9 @@ scope "(:locale)", locale: /en|mm/ do
|
||||
resources :menu_item_instances, only: [:show]
|
||||
get "item_sets" => "item_sets#index"
|
||||
end
|
||||
|
||||
namespace :payment do
|
||||
post 'mobilepayment/:cashier_id/:receipt_no/cash' =>"mobilepayment#cash"
|
||||
end
|
||||
#User request move table or bills
|
||||
post "bill/:booking_id" => "bill#create"
|
||||
post "move" => "move#create"
|
||||
|
||||
Reference in New Issue
Block a user