foodcourt apis for app

This commit is contained in:
Thein Lin Kyaw
2022-07-08 16:06:12 +06:30
parent 7485486868
commit 063345eae3
37 changed files with 785 additions and 171 deletions

View File

@@ -62,6 +62,19 @@ class Api::AuthenticateController < Api::ApiController
end
end
def check_emp_access_code
pin_code = params[:code]
employee = Employee.find_by_emp_id(pin_code)
if employee && (employee.role == "manager" || employee.role == "supervisor")
result = {:status=> true, :message=>"Success" }
else
result = {:status=> false, :message=>"Invalid Access Code" }
end
render :json => result.to_json
end
private
def authenticate_params
params.permit(:emp_id, :password, :session_token)
end

View File

@@ -17,14 +17,18 @@ class Api::BillController < Api::ApiController
@status = false
@error_message = "Operation failed, Could not request bill!"
else
# for Multiple Cashier by Zone
table = DiningFacility.find(booking.dining_facility_id)
order = booking.orders.first
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
unless shift = ShiftSale.current_open_shift(current_login_employee)
# for Multiple Cashier by Zone
if booking.dining_facility_id
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
else
shift = ShiftSale.current_shift
end
end
#for multiple zone with terminal
if !shift.nil?
@@ -57,22 +61,22 @@ class Api::BillController < Api::ApiController
# Bind shift sale id to sale
# @sale_data.shift_sale_id = shift_by_terminal.id
# @sale_data.save
if @sale_data
if @sale_data && booking.dining_facility_id.present?
#check checkInOut pdf print
checkout_time = Lookup.collection_of('checkout_time')
terminal = DiningFacility.find_by_id(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
terminal = DiningFacility.find_by_id(booking.dining_facility_id)
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code(unique_code)
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer,cashier_terminal , booking, table)
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, table)
end
end
@@ -159,12 +163,11 @@ class Api::BillController < Api::ApiController
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)
order = @booking.orders.first
if @sale_data = @booking.sale
@status = true
elsif @sale_data = Sale.generate_invoice_from_booking(@booking, current_login_employee, cashier, order.source,params[:current_checkin_induties_count])
elsif @sale_data = Sale.generate_invoice_from_booking(@booking, current_login_employee, cashier, order.source, params[:current_checkin_induties_count])
@status = true
else
@status = false

View File

@@ -1,14 +1,42 @@
class Api::BookingsController < Api::ApiController
# skip_before_action :authenticate
skip_before_action :authenticate
#Show customer by ID
def index
@customer = Customer.find_by(params[:id])
def index
@bookings = Booking.all
if params[:shift_id].present?
@bookings = @bookings.includes(:dining_facility, :sale, orders: :order_items)
.where()
end
end
def show
booking = Booking.find(params[:id])
if booking.dining_facility_id.to_i == params[:table_id].to_i
@booking = booking
@booking = Booking.find(params[:id])
end
def pending
@bookings = Booking.where(checkout_at: nil)
end
def billed
if shift = ShiftSale.current_shift
@bookings = Booking.includes(:sale)
.where(sales: {shift_sale_id: shift.id})
.where.not(sales: {sale_status: ['completed', 'void']})
end
end
def completed
if shift = ShiftSale.current_shift
@bookings = Booking.includes(:sale)
.where(sales: {shift_sale_id: shift.id, sale_status: ['completed']})
end
end
def void
if shift = ShiftSale.current_shift
@bookings = Booking.includes(:sale)
.where(sales: {shift_sale_id: shift.id, sale_status: ['void']})
end
end
end

View File

@@ -21,6 +21,30 @@ class Api::CustomersController < Api::ApiController
render json: status
end
def get_customer_by_account
account_no = params[:account_no]
unless @customer = Customer.find_by(paypar_account_no: account_no);
response = Customer.search_paypar_account_no(filter)
if response["status"] == true
@customer = Customer.create({
name: response["customer_data"]["name"],
contact_no: response["customer_data"]["phone"],
email: response["customer_data"]["email"],
date_of_birth: response["customer_data"]["DOB"],
nrc_no: response["customer_data"]["NRC"],
address: response["customer_data"]["address"],
card_no: response["customer_data"]["customer_card_no"],
paypar_account_no: account_no,
membership_id: response["customer_data"]["id"],
membership_type: response["customer_data"]["member_group_id"],
customer_type: "Dinein",
tax_profiles: ["1", "2"],
})
end
end
end
def get_customer_by_phone
if @customer = Customer.find_by_contact_no(params[:contact_no])
status = true

View File

@@ -0,0 +1,25 @@
class Api::Foodcourt::BillsController < Api::ApiController
def create
Sale.transaction do
if shift = ShiftSale.current_open_shift(current_login_employee)
if booking = Booking.find(params[:booking_id])
cashier = Employee.find(shift.employee_id)
order = booking.orders.first
if @sale_data = booking.sale
@status = true
elsif @sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, cashier, order.source, params[:current_checkin_induties_count])
@status = true
else
@status = false
end
end
else
@status = false
@error_message = "No Current Open Shift"
end
end
end
end

View File

@@ -0,0 +1,36 @@
class Api::Foodcourt::OrdersController < Api::ApiController
def create
Order.transaction do
if params[:order_items].present?
if shift = ShiftSale.current_open_shift(current_login_employee)
@order = Order.new
@order.source = params[:source] || "foodcourt"
@order.order_type = params[:order_type] || "Takeaway"
@order.customer_id = params[:customer_id] || takeaway.customer_id # 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
@status, @booking = @order.generate
unless @status && @booking
@status = false
@error_message = "Create order failed, some error occurred!"
end
else
@status = false
@error_message = "No Current Open Shift!"
end
else
@status = false
@error_message = "Parameters missing!"
end
end
end
end

View File

@@ -0,0 +1,88 @@
class Api::Foodcourt::PaymentsController < Api::ApiController
def create
SalePayment.transaction do
if params[:sale_id] && params[:account_no]
@sale = Sale.find_by_sale_id(params[:sale_id])
if !@sale.nil?
if @sale.sale_status == "new"
if !params[:account_no].empty?
@status, @message = send_account_paymal(@sale.grand_total, params[:account_no], @sale.receipt_no)
if @status
sale_payment = SalePayment.new
status, @sale_payment, @membership_data = sale_payment.process_payment(@sale, current_login_employee, @sale.grand_total, "paymal",params[:account_no])
if status == true && @membership_data["status"] == true
# sale_payment = SalePayment.new
# status = sale_payment.process_payment(@sale, current_login_employee, 0, "cash")
#card_balance amount for Paymal payment
card_balance_amount, transaction_ref = SaleAudit.getCardBalanceAmount(params[:sale_id])
@status = true
@card_balance_amount = card_balance_amount
@transaction_ref = transaction_ref
@message = "Payment successful."
else
@status = false
if @membership_data
@card_balance_amount = @membership_data["card_balance_amount"]
@message = @membership_data["message"]
else
@message = "Payment failed!"
end
end
end
else
@status = false
@message = "Card No is required!"
end
else
@status = false
@message = "Already paid for '#{params[:sale_id]}'!"
end
else
@status = false
@message = "There is no sale for '#{params[:sale_id]}'!"
end
else
@status = false
@message = "Parameters missing! #{params[:sale_id]} #{params[:account_no]}"
end
end
end
private
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
end

View File

@@ -0,0 +1,60 @@
class Api::Foodcourt::VoidController < Api::ApiController
def create
sale_id = params[:sale_id]
order_source = params[:type] || "foodcourt" #tax profile source
access_code = params[:access_code]
remark = params[:remark]
@sale = Sale.find_by_sale_id(sale_id)
if @sale.discount_type == "member_discount"
@sale.update_attributes(total_discount: 0)
@sale.compute_by_sale_items(0, nil, order_source)
end
# update count for shift @sale
if(@sale.sale_status == "completed")
if @sale.shift_sale_id != nil
shift = ShiftSale.find(@sale.shift_sale_id)
shift.calculate(sale_id, "void")
end
else
# void before @sale payment complete
if @sale.shift_sale_id != nil
shift = ShiftSale.find(@sale.shift_sale_id)
shift.total_void = shift.total_void + @sale.grand_total
shift.save
end
end
@sale.rounding_adjustment = 0.0
@sale.payment_status = 'void'
@sale.sale_status = 'void'
@sale.save
if table = @sale.booking.dining_facility
unless table.current_bookings.exists?
table.update_attributes(status: 'available')
end
end
# FOr Sale Audit
action_by = current_login_employee.name
if access_code != "null" && current_login_employee.role == "cashier"
action_by = Employee.find_by_emp_id(access_code).name
end
# remark = "Void Sale ID #{sale_id} | Receipt No #{@sale.receipt_no} | Receipt No #{@sale.receipt_no} | Table ->#{table.name}"
sale_audit = SaleAudit.record_audit_for_edit(sale_id, current_login_employee.name, action_by, remark, "SALEVOID" )
if !@sale.sale_payments.nil?
membership_response = @sale.paymal_payment_void
Rails.logger.debug "---------Paymal Payment Void response in VoidController"
Rails.logger.debug membership_response.to_json
end
@status = true
@message = "Void succeed"
end
end

View File

@@ -19,56 +19,6 @@ class Api::PaymentsController < Api::ApiController
def update
end
#create paymal payment for cashier app
def create_paymal_payment
if params[:sale_id] && params[:account_no]
@sale = Sale.find_by_sale_id(params[:sale_id])
if !@sale.nil?
if @sale.sale_status == "new"
if !params[:account_no].empty?
@status, @message = send_account_paymal(@sale.grand_total, params[:account_no], @sale.receipt_no)
if @status
sale_payment = SalePayment.new
status, @sale_payment, @membership_data = sale_payment.process_payment(@sale, current_login_employee, @sale.grand_total, "paymal",params[:account_no])
if status == true && @membership_data["status"] == true
sale_payment = SalePayment.new
status = sale_payment.process_payment(@sale, current_login_employee, 0, "cash")
#card_balance amount for Paymal payment
card_balance_amount, transaction_ref = SaleAudit.getCardBalanceAmount(params[:sale_id])
@status = true
@card_balance_amount = card_balance_amount
@transaction_ref = transaction_ref
@message = "Payment successful."
else
@status = false
if @membership_data
@card_balance_amount = @membership_data["card_balance_amount"]
@message = @membership_data["message"]
else
@message = "Payment failed!"
end
end
end
else
@status = false
@message = "Card No is required!"
end
else
@status = false
@message = "Already paid for '#{params[:sale_id]}'!"
end
else
@status = false
@message = "There is no sale for '#{params[:sale_id]}'!"
end
else
@status = false
@message = "Parameters missing! #{params[:sale_id]} #{params[:account_no]}"
end
end
#create paymal payment for online order app
def paymal_payment
if params[:account_no] && params[:key] && params[:token] && params[:sale_id]

View File

@@ -1,34 +1,34 @@
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!"})
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)
@status = true
@message = "Cashier Terminal successfully signin."
# render json: JSON.generate({:status => true, :message => "Cashier Terminal successfully signin.", :shift => ActiveSupport::JSON.encode(@shift_sale)})
else
# Update Cashier Terminal
cashier_terminal.is_currently_login = 1
cashier_terminal.save
@status = false
@error_message = "Some error occurred!"
# render json: JSON.generate({:status => false, :error_message => "Some error occurred!"})
end
end
end
@shift_sale = ShiftSale.new
if @shift_sale.create(opening_balance,cashier_terminal_param, current_login_employee)
@status = true
@message = "Cashier Terminal successfully signin."
# render json: JSON.generate({:status => true, :message => "Cashier Terminal successfully signin.", :shift => ActiveSupport::JSON.encode(@shift_sale)})
else
@status = false
@error_message = "Some error occurred!"
# render json: JSON.generate({:status => false, :error_message => "Some error occurred!"})
end
end
end
def update
def update
closing_balance = 0
shift_id = params[:shift_id]
@@ -36,26 +36,55 @@ class Api::ShiftsController < Api::ApiController
if !@shift.nil?
if @shift.shift_closed_at.nil?
@shift.shift_closed_at = DateTime.now.utc
@shift.closing_balance = closing_balance.to_f
@shift.closing_balance = closing_balance.to_f
@shift.save
# Multiple Cashier
cashier_terminal = @shift.cashier_terminal
cashier_terminal = @shift.cashier_terminal
cashier_terminal.is_currently_login = 0
cashier_terminal.save
@shop = current_shop
@lookup = Lookup.shift_sale_items_lookup_value
if @lookup.to_i == 1
@sale_items = Sale.get_shift_sale_items(@shift.id)
other_charges = Sale.get_other_charges()
@total_other_charges_info = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",@shift)
end
@sale_taxes = Sale.get_separate_tax(@shift,from=nil,to=nil,type='')
@total_waste = Sale.get_total_waste(shift_id).sum(:grand_total)
@total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total)
#other payment details for mpu or visa like card
@other_payment = ShiftSale.get_by_shift_other_payment(@shift)
# Calculate price_by_accounts
@total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount')
@total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount')
@total_member_discount = ShiftSale.get_total_member_discount(@shift)
@total_dinein = ShiftSale.get_total_dinein(@shift).total_dinein_amount
@total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount
@total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount
@total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments
@payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method")
logout_status = Employee.logout(current_token)
if logout_status
render json: JSON.generate({:status => true, :message => "Shift close successfully."})
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!"})
@status = true
@message = "Shift close successfully."
else
@status = false
@message = "Session Token Invalid or Missing"
end
else
@status = false
@message = "Shift already close!"
end
else
render json: JSON.generate({:status => false, :error_message => "Wrong shift!"})
@status = false
@message = "Wrong shift!"
end
end
end

View File

@@ -20,13 +20,13 @@ class Foodcourt::AddordersController < BaseFoodcourtController
@webview = true
end
display_type = Lookup.find_by_lookup_type("display_type")
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@display_type = nil
end
@menus = []
@menu = []
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@display_type = nil
end
@menus = []
@menu = []
@table_id = params[:id]
@table = DiningFacility.find(@table_id)

View File

@@ -106,6 +106,10 @@ class Foodcourt::OrdersController < BaseFoodcourtController
@menus = []
@menu = []
@zone = Zone.all
@tables = Table.active.order('status desc')
@rooms = Room.active.order('status desc')
if params[:id].include? "BKI"
@table_id = nil
@table = nil
@@ -272,7 +276,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController
end
else
respond_to do |format|
format.json {
format.json {
render :json => { :status => false, :error_message => "No Current Open Shift for This Employee" } }
end
end

View File

@@ -88,7 +88,6 @@ class Foodcourt::ShiftsController < BaseFoodcourtController
end
shop_details = current_shop
#get tax
shift_obj = ShiftSale.where('id =?',@shift.id)
sale_items = ''
@lookup = Lookup.shift_sale_items_lookup_value
if @lookup.to_i == 1
@@ -96,7 +95,7 @@ class Foodcourt::ShiftsController < BaseFoodcourtController
other_charges = Sale.get_other_charges()
@total_other_charges_info = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",@shift)
end
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='')
@sale_taxes = Sale.get_separate_tax(@shift,from=nil,to=nil,type='')
@total_waste = Sale.get_total_waste(shift_id).sum(:grand_total)
@total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total)
#other payment details for mpu or visa like card