api for cashier app
This commit is contained in:
@@ -14,7 +14,32 @@ class Api::AuthenticateController < Api::ApiController
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Input Parameters missing."})
|
||||
end
|
||||
end
|
||||
|
||||
def create_cashier
|
||||
emp_id = params[:emp_id]
|
||||
password = params[:password]
|
||||
|
||||
if emp_id && password
|
||||
@employee = Employee.login(emp_id, password)
|
||||
if @employee && @employee.role == "cashier"
|
||||
if @employee.is_active
|
||||
shift = ShiftSale.current_open_shift(@employee.id)
|
||||
if !shift.nil?
|
||||
render json: JSON.generate({:status => true, :session_token => @employee.token_session, :name => @employee.name, :role => @employee.role})
|
||||
else
|
||||
terminals = CashierTerminal.available.is_active
|
||||
render json: JSON.generate({:status => true, :session_token => @employee.token_session, :name => @employee.name, :role => @employee.role, :error_message => "No current shift open for this employee!", :terminals => terminals.to_json})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "This employee is not active!"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Bad Emp_ID or Password."})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Input Parameters missing."})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,10 +47,8 @@ class Api::AuthenticateController < Api::ApiController
|
||||
logout_status = Employee.logout(params[:session_token])
|
||||
if logout_status
|
||||
render json: JSON.generate({:status => true})
|
||||
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Session Token Invalid or Missing"})
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -123,6 +123,73 @@ class Api::BillController < Api::ApiController
|
||||
# printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts, member_info, shop_details)
|
||||
end
|
||||
|
||||
def request_bill
|
||||
puts "order items"
|
||||
puts params[:order_items]
|
||||
|
||||
if params[:order_items]
|
||||
is_extra_time = false
|
||||
extra_time = ''
|
||||
|
||||
# params[:order_items].each { |i|
|
||||
# i["item_instance_code"] = i["item_instance_code"].downcase.to_s
|
||||
# if i["item_instance_code"].include? "ext"
|
||||
# is_extra_time = true
|
||||
# arr_exts = i["item_instance_code"].split("_")
|
||||
# if arr_exts[1].match(/^(\d)+$/)
|
||||
# time = arr_exts[1].to_i*60*i["quantity"].to_i
|
||||
# extra_time = Time.at(time)
|
||||
# end
|
||||
# end
|
||||
# }
|
||||
|
||||
@order = Order.new
|
||||
@order.source = "emenu"
|
||||
@order.order_type = "Takeaway"
|
||||
@order.customer_id = "CUS-000000000002" # for no customer id from mobile
|
||||
@order.items = params[:order_items]
|
||||
@order.guest = params[:guest_info]
|
||||
@order.table_id = params[:table_id] # this is dining facilities's id
|
||||
@order.new_booking = true
|
||||
@order.waiters = current_login_employee.name
|
||||
@order.employee_name = current_login_employee.name
|
||||
|
||||
@order.is_extra_time = is_extra_time
|
||||
@order.extra_time = extra_time
|
||||
|
||||
@status, @booking = @order.generate
|
||||
|
||||
if @status && @booking
|
||||
shift = ShiftSale.current_open_shift(current_login_employee.id)
|
||||
if !shift.nil?
|
||||
cashier = Employee.find(shift.employee_id)
|
||||
if (@booking.booking_id)
|
||||
booking_order = BookingOrder.find_by_booking_id(@booking.booking_id)
|
||||
order = Order.find(booking_order.order_id)
|
||||
|
||||
if @booking.sale_id.nil?
|
||||
@sale = Sale.new
|
||||
@status, @sale_id = @sale.generate_invoice_from_booking(@booking.booking_id, current_login_employee, cashier, order.source)
|
||||
@sale_data = Sale.find_by_sale_id(@sale_id)
|
||||
else
|
||||
@status = true
|
||||
@sale_id = @booking.sale_id
|
||||
@sale_data = Sale.find_by_sale_id(@sale_id)
|
||||
end
|
||||
end
|
||||
# Promotion.promo_activate(@sale)
|
||||
render json: JSON.generate({:status => true, :sale_id => @sale_id, :sale_data => @sale_data.to_json})
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "No Current Open Shift!"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Create order failed, some error occurred!"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Parameters missing!"})
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def bill_params
|
||||
params.permit(:booking_id, :order_id)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Api::PaymentsController < ActionController::API
|
||||
class Api::PaymentsController < Api::ApiController
|
||||
|
||||
|
||||
#Payment by Invoice ID
|
||||
@@ -18,9 +18,81 @@ class Api::PaymentsController < ActionController::API
|
||||
# Invoice No | Payment ID | External params [] (* third party references and status)
|
||||
#
|
||||
def update
|
||||
|
||||
end
|
||||
|
||||
#create paymal payment for cashier app
|
||||
def paymal_payment
|
||||
if params[:sale_id] && params[:card_no]
|
||||
sale = Sale.find_by_sale_id(params[:sale_id])
|
||||
if !sale.nil?
|
||||
if sale.sale_status == "new"
|
||||
if !params[:card_no].empty?
|
||||
@status, @message = send_account_paymal(sale.grand_total, params[:card_no], sale.receipt_no)
|
||||
if @status
|
||||
sale_payment = SalePayment.new
|
||||
status, @sale, @membership_data = sale_payment.process_payment(sale, current_login_employee, sale.grand_total, "paymal",params[:card_no])
|
||||
if status == true && @membership_data["status"] == true
|
||||
#card_balance amount for Paymal payment
|
||||
card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
|
||||
|
||||
render json: JSON.generate({:status => true, :balance_amount => card_balance_amount, :message => "Payment successfully."})
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => @membership_data["message"]})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => @message})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Card No is required!"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Already paid for '#{params[:sale_id]}'!"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "There is no sale for '#{params[:sale_id]}'!"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Parameters missing!"})
|
||||
end
|
||||
end
|
||||
|
||||
def send_account_paymal(amount, account_no, receipt_no)
|
||||
sale = Sale.find_by_receipt_no(receipt_no)
|
||||
@out = []
|
||||
action_by = current_login_employee.name
|
||||
@status = true
|
||||
@message = ""
|
||||
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
if membership_setting.gateway_url
|
||||
member_actions =MembershipAction.find_by_membership_type("get_account_balance")
|
||||
if member_actions.gateway_url
|
||||
@campaign_type_id = nil
|
||||
url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s
|
||||
merchant_uid= member_actions.merchant_account_id
|
||||
auth_token = member_actions.auth_token.to_s
|
||||
membership_data = SalePayment.get_paypar_account_data(url,membership_setting.auth_token,merchant_uid,auth_token,account_no,amount,receipt_no)
|
||||
if membership_data["status"]==true
|
||||
remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Transaction ref: #{membership_data[:transaction_ref]} | Reload amount #{membership_data[:reload_amount]} | Old Balance Amount #{membership_data[:old_balance_amount]} | DateTime : #{membership_data[:date]}"
|
||||
sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,current_login_employee.name, current_login_employee.name,remark,"PAYBYACCOUNT" )
|
||||
else
|
||||
remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Remark : #{membership_data[:message]}"
|
||||
sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,current_login_employee.name, current_login_employee.name,remark,"PAYBYACCOUNT" )
|
||||
end
|
||||
@out = membership_data
|
||||
|
||||
@status = membership_data["status"]
|
||||
@message = membership_data["message"]
|
||||
end
|
||||
else
|
||||
@status = false
|
||||
@message = "No gateway url!"
|
||||
end
|
||||
|
||||
return @status, @message
|
||||
end
|
||||
|
||||
#create paymal payment for cashier app
|
||||
|
||||
private
|
||||
def handle_payment(sale_payment)
|
||||
|
||||
|
||||
57
app/controllers/api/shifts_controller.rb
Normal file
57
app/controllers/api/shifts_controller.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
class Api::ShiftsController < Api::ApiController
|
||||
# skip_before_action :authenticate
|
||||
|
||||
|
||||
def create
|
||||
opening_balance = 0
|
||||
cashier_terminal_param = params[:cashier_terminal]
|
||||
|
||||
# Multiple Cashier
|
||||
cashier_terminal = CashierTerminal.find(cashier_terminal_param)
|
||||
if cashier_terminal.is_currently_login
|
||||
render json: JSON.generate({:status => false, :error_message => "Cashier Terminal already signin!"})
|
||||
else
|
||||
# Update Cashier Terminal
|
||||
cashier_terminal.is_currently_login = 1
|
||||
cashier_terminal.save
|
||||
|
||||
@shift_sale = ShiftSale.new
|
||||
if @shift_sale.create(opening_balance,cashier_terminal_param, current_login_employee)
|
||||
render json: JSON.generate({:status => true, :message => "Cashier Terminal successfully signin.", :shift => @shift_sale.to_json})
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Some error occurred!"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
closing_balance = 0
|
||||
shift_id = params[:shift_id]
|
||||
|
||||
@shift = ShiftSale.find_by_id(shift_id)
|
||||
if !@shift.nil?
|
||||
if @shift.shift_closed_at.nil?
|
||||
@shift.shift_closed_at = DateTime.now.utc
|
||||
@shift.closing_balance = closing_balance.to_f
|
||||
@shift.save
|
||||
|
||||
# Multiple Cashier
|
||||
cashier_terminal = @shift.cashier_terminal
|
||||
cashier_terminal.is_currently_login = 0
|
||||
cashier_terminal.save
|
||||
|
||||
logout_status = Employee.logout(params[:session_token])
|
||||
if logout_status
|
||||
render json: JSON.generate({:status => true, :message => "Shift successfully close."})
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Session Token Invalid or Missing"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Shift already close!"})
|
||||
end
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Wrong shift!"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -217,7 +217,7 @@ class HomeController < ApplicationController
|
||||
# redirect_to origami_root_path
|
||||
else
|
||||
redirect_to new_origami_shift_path
|
||||
end
|
||||
end
|
||||
elsif employee.role == "manager"
|
||||
redirect_to dashboard_path
|
||||
elsif employee.role == "waiter"
|
||||
|
||||
@@ -166,7 +166,7 @@ class Origami::CustomersController < BaseOrigamiController
|
||||
receipt_no = params[:receipt_no]
|
||||
sale = Sale.find_by_receipt_no(receipt_no)
|
||||
@out = []
|
||||
action_by = current_user.id
|
||||
action_by = current_user.name
|
||||
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
if membership_setting.gateway_url
|
||||
member_actions =MembershipAction.find_by_membership_type("get_account_balance")
|
||||
|
||||
@@ -72,18 +72,20 @@ class Origami::RequestBillsController < ApplicationController
|
||||
#check checkInOut pdf print
|
||||
check_booking = Booking.find_by_sale_id(@sale_id)
|
||||
checkout_time = Lookup.collection_of('checkout_time')
|
||||
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
|
||||
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
||||
if !check_booking.dining_facility_id.nil?
|
||||
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
|
||||
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
||||
|
||||
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
|
||||
unique_code = "CheckInOutPdf"
|
||||
printer = PrintSetting.find_by_unique_code(unique_code)
|
||||
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
|
||||
unique_code = "CheckInOutPdf"
|
||||
printer = PrintSetting.find_by_unique_code(unique_code)
|
||||
|
||||
# print when complete click
|
||||
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
||||
# print when complete click
|
||||
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
||||
|
||||
if !printer.nil?
|
||||
order_queue_printer.print_check_in_out(printer, cashier_terminal, check_booking, table)
|
||||
if !printer.nil?
|
||||
order_queue_printer.print_check_in_out(printer, cashier_terminal, check_booking, table)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ class CashierTerminal < ApplicationRecord
|
||||
has_many :zones, through: :cashier_terminal_by_zones
|
||||
|
||||
scope :available, -> {where(is_currently_login: false)}
|
||||
scope :is_active, -> {where(is_active: true)}
|
||||
|
||||
# validations
|
||||
validates_presence_of :name, :printer_name
|
||||
|
||||
@@ -336,7 +336,7 @@ class Customer < ApplicationRecord
|
||||
def self.search(search)
|
||||
if search
|
||||
# find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"])
|
||||
where("name LIKE ? OR customer_type OR contact_no LIKE ? OR card_no LIKE ? OR DATE_FORMAT(date_of_birth,'%Y-%m-%d') LIKE ? OR nrc_no LIKE ? OR gender LIKE ? OR paypar_account_no ='#{search}'", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%")
|
||||
where("name LIKE ? OR customer_type LIKE ? OR contact_no LIKE ? OR card_no LIKE ? OR DATE_FORMAT(date_of_birth,'%Y-%m-%d') LIKE ? OR nrc_no LIKE ? OR gender LIKE ? OR paypar_account_no ='#{search}'", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%")
|
||||
else
|
||||
find(:all)
|
||||
end
|
||||
|
||||
@@ -88,16 +88,18 @@ class Sale < ApplicationRecord
|
||||
|
||||
# set cashier
|
||||
if order_source.downcase == "emenu"
|
||||
table = DiningFacility.find(booking.dining_facility_id)
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
|
||||
#for multiple zone with terminal
|
||||
if shift.nil?
|
||||
multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}")
|
||||
multiple_zone.each do |zone|
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
|
||||
if !shift.nil? then
|
||||
break
|
||||
if !booking.dining_facility_id.nil?
|
||||
table = DiningFacility.find(booking.dining_facility_id)
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
|
||||
#for multiple zone with terminal
|
||||
if shift.nil?
|
||||
multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}")
|
||||
multiple_zone.each do |zone|
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
|
||||
if !shift.nil? then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -93,6 +93,13 @@ scope "(:locale)", locale: /en|mm/ do
|
||||
end
|
||||
|
||||
post "sound_effect" => "sound_effect#sound_effect"
|
||||
|
||||
#API for cashier app
|
||||
post 'authenticate_cashier' => "authenticate#create_cashier"
|
||||
post "shifts/new" => "shifts#create"
|
||||
post "shifts/close" => "shifts#update"
|
||||
post "request_bill" => "bill#request_bill"
|
||||
post "paymal_payment" => "payments#paymal_payment"
|
||||
end
|
||||
|
||||
#--------- Cashier ------------#
|
||||
|
||||
Reference in New Issue
Block a user