separate foodcourt module

This commit is contained in:
Myat Zin Wai Maw
2019-12-02 16:10:51 +06:30
parent 09e7650452
commit cac6994ccb
113 changed files with 14365 additions and 193 deletions

View File

@@ -0,0 +1,310 @@
class Foodcourt::AddordersController < BaseFoodcourtController
# before_action :set_dining, only: [:detail]
def index
@webview = false
if check_mobile
@webview = true
end
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
@all_table = Table.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc')
@all_room = Room.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc')
end
def detail
@cashier_type = params[:type]
@webview = false
if check_mobile
@webview = true
end
display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code)
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@display_type = nil
end
# if params[:menu] == "true"
@menus = []
@menu = []
@table_id = params[:id]
@table = DiningFacility.find(@table_id)
@booking = @table.get_booking
if @booking
@booking_id = @booking.booking_id
@obj_order = @booking.orders.first
@customer = @obj_order.customer
@date = @obj_order.created_at
@order_items = @booking.order_items
end
end
def get_menu_category ()
if (params[:id])
#Pull this menu
@menu = MenuCategory.find_by_id(params[:id])
# puts @menu.menu_items[1].item_attributes.to_json
return @menu
else
MenuCategory.current_menu
end
end
def get_item_instance
@instance = MenuItemInstance.find(params[:id])
end
def get_menu()
if (params[:id])
#Pull this menu
@menu = Menu.find_by_id(params[:id])
@menu_category = MenuCategory.where("menu_id='#{@menu.id}'").order("order_by asc")
# puts @menu.menu_items[1].item_attributes.to_json
return @menu
else
Menu.current_menu
end
end
def get_menu_sub_category ()
id = params[:id]
if (id)
#Pull this menu
@sub_menu = MenuCategory.where("menu_category_id = #{id}").active
# puts @menu.menu_items[1].item_attributes.to_json
return @sub_menu
end
end
def get_all_product()
@product = Product.all
end
def create
if params[:booking_id].present?
booking = Booking.find(params[:booking_id])
end
if params[:table_id].present?
if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i
table = DiningFacility.find(params[:table_id])
booking = table.get_current_booking
end
end
is_extra_time = false
extra_time = ''
items_arr = []
JSON.parse(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
if i["parent_order_item_id"];
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
else
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
end
items_arr.push(items)
}
# begin
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
customer_id = "CUS-000000000002" # for no customer id from mobile
else
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
end
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@order.customer_id = customer_id
@order.items = items_arr
@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.shop_code =@shop.shop_code
@order.is_extra_time = is_extra_time
@order.extra_time = extra_time
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
@order.new_booking = true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
end
@status, @booking = @order.generate
if @status && @booking
#send order broadcast to order_channel
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
process_order_queue(@order.order_id,@order.table_id,@order.source)
end
end
# Order.send_customer_view(@booking)
if current_user.role != "waiter" && params[:create_type] == "create_pay"
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
# for second display
if @order.source == 'quick_service'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
end
#end
result = {:status=> @status, :data => @sale ,:current_user_role =>current_user.role}
render :json => result.to_json
end
else
result = {:status=> @status, :data => 0 }
render :json => result.to_json
end
end
# render json for http status code
def return_json_status_with_code(code, msg)
render status: code, json: {
message: msg,
booking_id: booking_id
}.to_json
end
def check_order_with_table(table_id)
table = DiningFacility.find(table_id)
if table
booking = table.get_current_booking
# puts booking
if booking
if !booking.sale_id.nil?
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
@order.new_booking = true
return false
end
else
@order.new_booking = false
@order.booking_id = booking.booking_id
return false
end
end
end
end
# this can always true
def check_order_with_booking(booking)
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
@order.new_booking = true
return false
else
@order.new_booking = false
@order.booking_id = params[:booking_id]
return false
end
end
def process_order_queue(order_id,table_id,order_source)
print_status = nil
cup_status = nil
#Send to background job for processing
order = Order.find(order_id)
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code)
if ENV["SERVER_MODE"] != 'cloud'
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
end
if print_status
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
cup_start = `#{"sudo service cups start"}`
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
end
if print_status
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
from = ""
msg = ' Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error',from:from
end
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
from = getCloudDomain #get sub domain in cloud mode
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
end
end
end
end
def check_cup_status(status)
if status.include? "Active: active (running)" || "Active: active (exited)" #"Cup Server is already running"
return true
end
return false
end
#get cloud domain
def getCloudDomain
from = ""
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain.to_s + "." + request.domain.to_s
end
return from
end
end

View File

@@ -0,0 +1,27 @@
class Foodcourt::CardPaymentsController < BaseFoodcourtController
def index
@membership_rebate_balance = 0
@membership_id = 0
if !@membership_id.nil?
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_data = SalePayment.get_paypar_account(membership_setting.gateway_url,membership_setting.auth_token,@membership_id)
if membership_data["status"]==true
membership_account_data = membership_data["data"];
membership_account_data.each do |acc_data|
if acc_data["accountable_type"] == "REBATEACCOUNT"
@membership_rebate_balance=acc_data["balance"]
else
@membership_rebate_balance = 0
end
end
else
@membership_rebate_balance = 0
end
end
end
def create
end
end

View File

@@ -0,0 +1,44 @@
class Foodcourt::CashInsController < BaseFoodcourtController
def new
end
def create
reference = params[:reference]
remark = params[:remark]
amount = params[:amount]
payment_method = params[:payment_method]
payment_method_reference = params[:payment_method_reference]
type = params[:type]
p_jour = PaymentJournal.new
p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user)
shift = ShiftSale.current_open_shift(current_user)
current_shift = ShiftSale.current_shift(@shop.shop_code)
# set cashier
if shift != nil
shift = shift
else
open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''")
if open_cashier.count>0
shift = ShiftSale.current_open_shift(open_cashier[0])
if shift
emp = Employee.find_by_id(shift.employee_id)
shift = ShiftSale.current_open_shift(emp)
else
shift = ShiftSale.current_open_shift(current_shift)
end
else
# shift = Employee.find(current_shift.employee_id).name
shift =current_shift
end
end
puts shift.to_json
shift.cash_in = shift.cash_in + amount.to_f
shift.save
end
end

View File

@@ -0,0 +1,39 @@
class Foodcourt::CashOutsController < BaseFoodcourtController
def new
end
def create
reference = params[:reference]
remark = params[:remark]
amount = params[:amount]
p_jour = PaymentJournal.new
p_jour.cash_out(reference, remark, amount, current_user)
shift = ShiftSale.current_open_shift(current_user)
current_shift = ShiftSale.current_shift(@shop.shop_code)
# set cashier
if shift != nil
shift = shift
else
open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''")
if open_cashier.count>0
shift = ShiftSale.current_open_shift(open_cashier[0])
if shift
emp = Employee.find_by_id(shift.employee_id)
shift = ShiftSale.current_open_shift(emp)
else
shift = ShiftSale.current_open_shift(current_shift)
end
else
# shift = Employee.find(current_shift.employee_id).name
shift =current_shift
end
end
shift.cash_out = shift.cash_out + amount.to_i
shift.save
end
end

View File

@@ -0,0 +1,193 @@
class Foodcourt::CustomersController < BaseFoodcourtController
load_and_authorize_resource
def index
end
# GET /crm/customers/1
# GET /crm/customers/1.json
def show
end
def get_customer
filter = params[:filter]
type = params[:type]
if filter.nil?
@crm_customers = Customer.order("customer_id").page(params[:page])
#@products = Product.order("name").page(params[:page]).per(5)
else
@crm_customers = Customer.search(filter)
# search account no from paypar
if !@crm_customers.present? && type == "card"
response = Customer.search_paypar_account_no(filter)
if response["status"] == true
@crm_customers = Customer.new
@crm_customers.name = response["customer_data"]["name"]
@crm_customers.contact_no = response["customer_data"]["phone"]
@crm_customers.email = response["customer_data"]["email"]
@crm_customers.date_of_birth = response["customer_data"]["DOB"]
@crm_customers.nrc_no = response["customer_data"]["NRC"]
@crm_customers.address = response["customer_data"]["address"]
@crm_customers.card_no = response["customer_data"]["customer_card_no"]
@crm_customers.paypar_account_no = filter
@crm_customers.membership_id = response["customer_data"]["id"]
@crm_customers.membership_type = response["customer_data"]["member_group_id"]
@crm_customers.customer_type = "Dinein"
@crm_customers.tax_profiles = ["1", "2"]
@crm_customers.save
@crm_customers = Customer.search(filter)
else
@crm_customers = [{"customer_id": response["status"],"message": response["message"] }]
end
end
end
render :json => @crm_customers.to_json
end
def add_customer
@webview = false
if check_mobile
@webview = true
end
@sale_id = params[:sale_id]
@cashier_type = params[:type]
@page = params[:dir_page]
if(@sale_id[0,3] == "SAL")
@booking = Booking.find_by_sale_id(@sale_id)
if @booking.dining_facility_id.to_i > 0
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
else
@dining_facility = nil
end
else
@booking_order = BookingOrder.find_by_order_id(@sale_id)
@booking = Booking.find(@booking_order.booking_id)
if @booking.dining_facility_id.to_i > 0
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
else
@dining_facility = nil
end
end
filter = params[:filter]
if filter.nil?
@crm_customers = Customer.order("customer_id") #.page(params[:page])
#@products = Product.order("name").page(params[:page]).per(5)
else
@crm_customers = Customer.search(filter)
end
#@crm_customers = Customer.all
@crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(20)
@crm_customer = Customer.new
@count_customer = Customer.count_customer
# @taxes = TaxProfile.where(:group_type => 'cashier')
@taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name")
.order("group_type ASC,order_by ASC")
# if flash["errors"]
# @crm_customer.valid?
# end
@membership_types = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("member_group_type")
#get paypar accountno
@paypar_accountno = Customer.where("paypar_account_no IS NOT NULL AND paypar_account_no != ''").pluck("paypar_account_no")
#for create customer on/off
@create_flag = true
lookup_customer = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('customer_settings')
if !lookup_customer.empty?
lookup_customer.each do |create_setting|
if create_setting[0].downcase == "create"
if create_setting[1] == '0' && current_login_employee.role == 'cashier'
@create_flag = false
end
end
end
end
respond_to do |format|
# format.html { render :template => "crm/customers/index" }
format.html { render action: "index"}
format.json { render json: @crm_customers }
end
end
def update_sale_by_customer
id = params[:sale_id][0,3]
customer_id = params[:customer_id]
customer = Customer.find(customer_id)
order_source = params[:type]
# Check and find with card no
# if(!customer_id.include? "CUS")
# customer = Customer.find_by_paypar_account_no(customer_id)
# if(customer != nil)
# customer_id = customer.customer_id
# end
# end
if(id == "SAL")
sale = Sale.find(params[:sale_id])
status = sale.update_attributes(customer_id: customer_id)
sale.sale_orders.each do |sale_order|
order = Order.find(sale_order.order_id)
status = order.update_attributes(customer_id: customer_id,order_type:customer.customer_type)
end
action_by = current_user.id
remark = "Assign Customer Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Customer ID ->#{customer.customer_id}- Customer Name ->#{customer.name}"
sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"ASSIGNCUSTOMER" )
else
@booking = BookingOrder.find_by_order_id(params[:sale_id])
@orders = BookingOrder.where("booking_id = ? ", @booking.booking_id)
@orders.each do |bo|
order = Order.find(bo.order_id)
status = order.update_attributes(customer_id: customer_id,order_type:customer.customer_type)
end
end
if status == true
render json: JSON.generate({:status => true})
if(id == "SAL")
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
end
else
render json: JSON.generate({:status => false, :error_message => "Record not found"})
end
end
def send_account
amount = params[:amount]
account_no = params[:account_no]
receipt_no = params[:receipt_no]
sale = Sale.find_by_receipt_no(receipt_no)
@out = []
action_by = current_user.name
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",@shop.shop_code)
if membership_setting.gateway_url
member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",@shop.shop_code)
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,sale.cashier_id, action_by,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,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" )
end
@out = membership_data
render json: JSON.generate({:status => membership_data["status"], :message => membership_data["message"]})
end
end
end
end

View File

@@ -0,0 +1,121 @@
class Foodcourt::DashboardController < BaseFoodcourtController
def index
today = DateTime.now.strftime('%Y-%m-%d')
@display_type = Lookup.where("shop_code='#{@shop.shop_code}'").find_by_lookup_type("display_type")
@sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(@shop,today,current_user)
if !@total_payment_methods.nil?
@total_payment_methods.each do |payment|
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay"
pay = Sale.payment_sale(@shop,'card', today, current_user)
@sale_data.push({'card' => pay.payment_amount})
else
pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user)
@sale_data.push({payment.payment_method => pay.payment_amount})
end
end
else
@sale_data = nil
end
@summ_sale = Sale.summary_sale_receipt(@shop,today,current_user)
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time)
# @total_other_customer = Sale.total_other_customer(today,current_user)
@total_order = Sale.total_order(@shop,today,current_user)
@total_accounts = Sale.total_account(@shop,today,current_user)
@account_data = Array.new
if !@total_accounts.nil?
@total_accounts.each do |account|
acc = Sale.account_data(@shop,account.account_id, today,current_user)
if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end
end
else
@account_data = nil
end
@top_items = Sale.top_items(@shop,today,current_user)
@total_foc_items = Sale.total_foc_items(@shop,today,current_user)
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@current_user = current_user
#dine-in cashier
dinein_cashier = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dinein_cashier')
@dinein_cashier = 0
if !dinein_cashier[0].nil?
@dinein_cashier = dinein_cashier[0][1]
end
#quick service
quick_service = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quick_service')
@quick_service = 0
if !quick_service[0].nil?
@quick_service = quick_service[0][1]
end
#fourt court
food_court = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('food_court')
@food_court = 0
@food_court_name = nil
if !food_court[0].nil?
@food_court = food_court[0][1]
@food_court_name = food_court[0][0]
end
#order reservation
order_reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation')
@order_reservation = 0
if !order_reservation.empty?
order_reservation.each do |order_reserve|
if order_reserve[0] == 'OrderReservation'
@order_reservation = order_reserve[1]
end
end
end
#dashboard settings on/off for supervisor and cashier
dashboard_settings = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dashboard_settings')
@setting_flag = true
if !dashboard_settings.empty?
dashboard_settings.each do |setting|
if setting[0].to_s.downcase == current_user.role.downcase && setting[1] == '0'
@setting_flag = false
end
end
end
#reservation
reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('reservation')
@reservation = 0
if !reservation.empty?
reservation.each do |reserve|
if reserve[0] == 'Reservation'
@reservation = reserve[1]
end
end
end
end
def get_all_menu
@menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all.where("shop_code='#{@shop.shop_code}'")
@item_attributes = MenuItemAttribute.all.load
@item_options = MenuItemOption.all.load
end
def get_credit_sales
credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code)
if !credit_sales.nil?
result = {:status=> true, :data=> credit_sales }
else
result = {:status=> false, :message=>"There is no record." }
end
render :json => result.to_json
end
end

View File

@@ -0,0 +1,336 @@
class Foodcourt::DiscountsController < BaseFoodcourtController
authorize_resource :class => false
#discount page show from origami index with selected order
def index
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@webview = false
if check_mobile
@webview = true
end
sale_id = params[:id]
@cashier_type = params[:type]
if Sale.exists?(sale_id)
@sale_data = Sale.find(sale_id)
if @sale_data.bookings[0].dining_facility_id.to_i > 0
@table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id)
else
@table = nil
end
end
@member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code)
@accounts = Account.where("shop_code='#{@shop.shop_code}'")
end
#discount page show from origami index with selected order
def create
order_source = params[:cashier_type]
sale_id = params[:sale_id]
discount_items = JSON.parse(params[:discount_items])
overall_discount = params[:overall_discount]
sub_total = params[:sub_total]
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
if sale.bookings[0].dining_facility_id.to_i > 0
table_id = sale.bookings[0].dining_facility_id
table = DiningFacility.find(table_id)
else
table = nil
table_id = nil
end
# sale.total_discount = overall_discount.to_f
# sale.total_amount = sub_total.to_f
# sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax;
# sale.save
if discount_items.length > 0
#save sale item for discount
discount_items.each do |di|
origin_sale_item = SaleItem.find(di["id"])
sale_item = SaleItem.new
# if !origin_sale_item.nil?
# menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items
# if !menu_category.nil?
# sale_item.menu_category_code = menu_category.code
# sale_item.menu_category_name = menu_category.name
# end
# end
sale_item.menu_category_code = origin_sale_item.menu_category_code
sale_item.menu_category_name = origin_sale_item.menu_category_name
sale_item.sale_id = sale_id
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
sale_item.product_name = di["name"]
sale_item.item_instance_code = origin_sale_item.item_instance_code
sale_item.product_alt_name = ""
sale_item.status = "Discount"
sale_item.qty = -1
sale_item.unit_price = di["price"].to_f * -1
sale_item.taxable_price = di["price"]
sale_item.is_taxable = 1
sale_item.account_id = origin_sale_item.account_id
sale_item.price = di["price"]
sale_item.save
action_by = current_user.name
remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} "
sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_name, action_by,remark,"ITEMDISCOUNT" )
end
end
# Re-calc All Amount in Sale
if overall_discount.to_f > 0
action_by = current_user.name
if table.nil?
remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- no Table "
else
remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} "
end
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"OVERALLDISCOUNT" )
end
sale.compute_by_sale_items(overall_discount.to_f, nil,order_source)
if !table.nil?
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
else
result = {:status=> "Success" }
end
else
if !table.nil?
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type }
else
result = {:status=> "Please, Check Again!" }
end
end
render :json => result.to_json
end
# Remove selected discount Items
def remove_discount_items
order_source = params[:cashier_type]
sale_id = params[:sale_id]
discount_items = JSON.parse(params[:discount_items])
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
if sale.bookings[0].dining_facility_id.to_i > 0
table_id = sale.bookings[0].dining_facility_id
table = DiningFacility.find(table_id)
else
table_id = nil
table = nil
end
if discount_items.length > 0
#destroy sale item for discount
discount_items.each do |di|
sale_item = SaleItem.find(di["id"])
sale.total_amount = (sale.total_amount + sale_item.price.abs)
action_by = current_user.name
if table.nil?
remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- No Table "
else
remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} "
end
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEITEMDISCOUNT" )
sale_item.destroy
end
end
# sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
# sale.save
# Re-calc All Amount in Sale
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
if table.nil?
result = {:status=> "Success"}
else
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
end
else
if table.nil?
result = {:status=> "Please, Check Again!"}
else
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type }
end
end
render :json => result.to_json
end
# Remove all discount Items
def remove_all_discount
sale_id = params[:id]
order_source = params[:type]
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
if sale.bookings[0].dining_facility_id.to_i > 0
table_id = sale.bookings[0].dining_facility_id
table = DiningFacility.find(table_id)
table_type = table.type
else
table_id = nil
table = nil
table_type = nil
end
discount_items = []
#destroy all discount sale item
sale.sale_items.each do |si|
if si.status == "Discount" && si.price < 0
sale.total_amount = (sale.total_amount + si.price.abs)
discount_items.push(si)
end
end
# sale.total_discount = 0
# sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
# sale.save
#destroy in sale.sale_items
sale.sale_items.destroy(discount_items)
action_by = current_user.name
if table.nil?
remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- No Table"
else
remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- #{table.name} "
end
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEALLDISCOUNT" )
# Re-calc All Amount in Sale
sale.compute_by_sale_items(0, nil, order_source)
if table.nil?
result = {:status=> "Success"}
else
result = {:status=> "Success", :table_id => table_id, :dining => table.name, :table_type => table_type }
end
else
if table.nil?
result = {:status=> "Please, Check Again!"}
else
result = {:status=> "Please, Check Again!", :table_id => table_id, :dining => table.name, :table_type => table_type }
end
end
render :json => result.to_json
end
# Member Discount
def member_discount
order_source = params[:cashier_type]
sale_id = params[:sale_id]
is_card = params[:is_card]
sub_total = params[:sub_total]
tax_type = params[:tax_type]
sale = Sale.find(sale_id)
if is_card == 'true'
is_card = true
else is_card.to_s == 'false'
is_card = false
end
# Check for Card Payment
is_card_payment = SalePayment.get_sale_payments_by_card(sale.sale_payments)
# if is_card != "true"
account_types = Account.where("discount=?",true)
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
# Get Prices for each accounts (eg: food, beverage)
account_price = SaleItem.calculate_price_by_accounts(sale.sale_items)
acc_prices = Array.new;
account_types.each do |at|
account_price.each do |pc|
if pc[:name] == at.title && pc[:price]>0
str={type:pc[:name],amount:pc[:price]}
acc_prices.push(str)
end
end
end
generic_customer_id = sale.customer.membership_id
receipt_no = sale.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("member_discount")
merchant_uid = memberaction.merchant_account_id.to_s
campaign_type_id = memberaction.additional_parameter["campaign_type_id"]
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
account_no = sale.customer.paypar_account_no rescue nil
# Check for items for Paypar Cloud
if acc_prices.length > 0
begin
response = HTTParty.post(url,
:body => { account_no: account_no,
generic_customer_id:generic_customer_id ,
campaign_type_id: campaign_type_id,
receipt_no: receipt_no,
merchant_uid:merchant_uid,
campaign_method:acc_prices.to_json,
total_sale_transaction_amount: sale.grand_total,
is_card: is_card,
auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
}, :timeout => 10)
rescue HTTParty::Error
response = {"status": false, "message": "Http party error" }
rescue Net::OpenTimeout
response = {"status": false, "message": "Connection TIme out " }
rescue OpenURI::HTTPError
response = {"status": false, "message": "Can't open membership server " }
rescue SocketError
response = {"status": false, "message": "Can't open membership server " }
end
else
response = {"status": false, "message": "You have no selected discount item" }
end
Rails.logger.debug "-------------- Member Discount Osaka ---------"
Rails.logger.debug response.to_json
# Re-calc All Amount in Sale
if response["status"] == true
discount_amount = response["discount_earned"]
if response["discount_bonus_earned"]
discount_amount = discount_amount + response["discount_bonus_earned"]
end
sale.compute_by_sale_items(discount_amount, 'member_discount', order_source, tax_type)
result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type }
elsif response["status"] == "500"
result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
else
result = {:status=> response["message"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
end
render :json => result.to_json
# end #end Is Card Payment
end
end

View File

@@ -0,0 +1,201 @@
class Foodcourt::FoodCourtController < ApplicationController
# before_action :set_dining, only: [:detail]
before_action :check_user
def check_user
if current_user.nil?
redirect_to root_path
end
end
def index
today = DateTime.now
day = Date.today.wday
# if params[:menu] == "true"
@menus = []
@menu = []
# else
# @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end
@zone = Zone.all.where("shop_code='#{@shop.shop_code}' and is_active= true")
@customer = Customer.all
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@cashier_type = "food_court"
#checked quick_service only
@quick_service_only = true
lookup_dine_in = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dinein_cashier')
if !lookup_dine_in.empty?
lookup_dine_in.each do |dine_in|
if dine_in[0].downcase == "dineincashier"
if dine_in[1] == '1'
@quick_service_only = false
end
end
end
end
render "foodcourt/addorders/detail"
end
def modify_order
@cashier_type = "food_court"
today = DateTime.now
day = Date.today.wday
# if params[:menu] == "true"
@menus = []
@menu = []
# else
# @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end
if(params[:id][0,3] == "BKI")
@table_id = nil
@table = nil
@booking = Booking.find(params[:id])
else
@table_id = params[:id]
@table = DiningFacility.find(@table_id)
@booking = @table.get_booking
end
@sale_id = @booking.sale_id
if @booking
@booking_id = @booking.booking_id
@obj_order = @booking.orders.first
@customer = @obj_order.customer
@date = @obj_order.created_at
@order_items = @booking.order_items
end
render "foodcourt/addorders/detail"
end
def update_modify_order
booking = Booking.find(params[:booking_id])
sale = booking.sale
if sale && sale.sale_status != 'new'
render :json => { :status => false }
end
is_extra_time = false
extra_time = ''
cashier_type = "food_court"
items_arr = []
JSON.parse(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
if i["parent_order_item_id"]
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": i["options"]}
else
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]}
end
items_arr.push(items)
}
# begin
order = Order.new
order.source = params[:order_source]
order.order_type = params[:order_type]
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.items = items_arr
order.guest = params[:guest_info]
order.table_id = params[:table_id] # this is dining facilities's id
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
order.new_booking = false
order.booking_id = booking.booking_id
if order.generate
if sale
Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking)
render :json => { :status => true, :data => sale }
else
render :json => { :status => true, :data => 'OK' }
end
else
render :json => { :status => false }
end
end
def get_menu_category ()
if (params[:id])
puts params[:id]
#Pull this menu
@menu = MenuCategory.find_by_id(params[:id])
# puts @menu.menu_items[1].item_attributes.to_json
return @menu
else
MenuCategory.current_menu
end
end
def get_menu_sub_category ()
id = params[:id]
if (id)
#Pull this menu
@sub_menu = MenuCategory.where("menu_category_id = #{id}").active
# puts @menu.menu_items[1].item_attributes.to_json
return @sub_menu
end
end
def get_all_product()
@product = Product..where("shop_code='#{@shop.shop_code}'")
end
# render json for http status code
def return_json_status_with_code(code, msg)
render status: code, json: {
message: msg,
booking_id: booking_id
}.to_json
end
def check_order_with_table(table_id)
table = DiningFacility.find(table_id)
if table
booking = table.get_current_booking
# puts booking
if booking
if !booking.sale_id.nil?
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
@order.new_booking = true
return false
end
else
@order.new_booking = false
@order.booking_id = booking.booking_id
return false
end
end
end
end
# this can always true
def check_order_with_booking(booking)
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
@order.new_booking = true
return false
else
@order.new_booking = false
@order.booking_id = params[:booking_id]
return false
end
end
end

View File

@@ -0,0 +1,168 @@
class Foodcourt::HomeController < BaseFoodcourtController
authorize_resource :class => false
before_action :set_dining, only: [:show]
def index
@webview = check_mobile
@tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name")
@occupied_table = DiningFacility.where("shop_code='#{@shop.shop_code}' and status='occupied'").count
@shift = ShiftSale.current_open_shift(current_user)
end
# origami table detail
def show
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@webview = check_mobile
@tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name")
@shift = ShiftSale.current_open_shift(current_user)
@status_order = ""
@status_sale = ""
@sale_array = Array.new
@membership = MembershipSetting.find_by_shop_code(@shop.shop_code)
@payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'")
@dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ")
#@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'")
@order_items = Array.new
@dining_booking.each do |booking|
if booking.sale_id.nil? && booking.booking_status != 'moved'
@order_items = Array.new
# @assigned_order_items = Array.new
if booking.booking_orders.empty?
@booking = booking
else
booking.booking_orders.each do |booking_order|
order = Order.find(booking_order.order_id)
if (order.status == "new")
@obj_order = order
@customer = order.customer
@date = order.created_at
@booking= booking
order.order_items.each do |item|
@order_items.push(item)
# assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id)
# if !assigned_order_items.nil?
# @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id})
# end
end
@account_arr = Array.new
if @customer.tax_profiles
accounts = @customer.tax_profiles
@account_arr =[]
accounts.each do |acc|
account = TaxProfile.find_by_id(acc)
if !account.nil?
@account_arr.push(account)
end
end
end
end
end
end
@status_order = 'order'
else
sale = Sale.find(booking.sale_id)
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste'
@sale_array.push(sale)
if @status_order == 'order'
@status_order = 'sale'
end
@booking= booking
@date = sale.created_at
@status_sale = 'sale'
@obj_sale = sale
@customer = sale.customer
accounts = @customer.tax_profiles
@account_arr =[]
accounts.each do |acc|
account = TaxProfile.find_by_id(acc)
if !account.nil?
@account_arr.push(account)
end
end
end
@sale_taxes = []
sale_taxes = SaleTax.where("sale_id = ?", sale.sale_id)
if !sale_taxes.empty?
sale_taxes.each do |sale_tax|
@sale_taxes.push(sale_tax)
end
end
end
end
#for bank integration
@checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')
@checkout_alert_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_alert_time')
accounts = TaxProfile.where("shop_code='#{@shop.shop_code}' and group_type = ?","cashier").order("order_by ASC")
@tax_arr =[]
accounts.each do |acc|
@tax_arr.push(acc.name)
end
lookup_spit_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]
end
#for edit order on/off
@edit_order_origami = true
lookup_edit_order = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('edit_order')
if !lookup_edit_order.empty?
lookup_edit_order.each do |edit_order|
if edit_order[0].downcase == "editorderorigami"
if edit_order[1] == '0' && (current_login_employee.role == 'cashier' || current_login_employee.role == 'waiter')
@edit_order_origami = false
end
end
end
end
#for changable on/off
@changable_tax = true
lookup_changable_tax = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('changable_tax')
if !lookup_changable_tax.empty?
lookup_changable_tax.each do |changable_tax|
if changable_tax[0].downcase == "change"
if changable_tax[1] == '0'
@changable_tax = false
end
end
end
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 set_dining
@dining = DiningFacility.find(params[:dining_id])
end
end

View File

@@ -0,0 +1,96 @@
class Foodcourt::OrdersController < BaseFoodcourtController
def show
@webview = false
if check_mobile
@webview = true
end
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@order = Order.find(params[:order_id])
booking = Booking.select('bookings.booking_id, bookings.dining_facility_id')
.joins(" JOIN booking_orders as bo on bo.booking_id = bookings.booking_id")
.where("bo.order_id='#{params[:order_id]}'").first()
@booking = Array.new
if !booking.nil?
if booking.dining_facility_id.to_i > 0
dining_facilities = DiningFacility.find_by_id(booking.dining_facility_id)
@booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => dining_facilities.type})
else
@booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => nil})
end
end
@customers = Customer.pluck("customer_id, name")
#for split bill
lookup_spit_bill = Lookup.collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]
end
sale_order = SaleOrder.find_by_order_id(@order.order_id)
if sale_order
unless sale_order.sale_id.nil?
sale = Sale.find(sale_order.sale_id)
@sale_status = sale.sale_status
end
end
@order.order_items.each_with_index do |item, order_item_index|
if !item.set_menu_items.nil?
instance_item_sets = JSON.parse(item.set_menu_items)
arr_instance_item_sets = Array.new
instance_item_sets.each do |instance_item|
item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
arr_instance_item_sets.push(item_instance_name)
item.price = item.price.to_f + instance_item["price"].to_f
end
@order.order_items[order_item_index].set_menu_items = arr_instance_item_sets
end
end
# bookings = Booking.all
# if !bookings.today.nil?
# @order_items_count = Hash.new
# bookings.each do |booking|
# if booking.sale_id.nil? && booking.booking_status != 'moved'
# if !booking.booking_orders.empty?
# booking.booking_orders.each do |booking_order|
# order = Order.find(booking_order.order_id)
# if !order.order_items.empty?
# if !@order_items_count.key?(booking.dining_facility_id)
# @order_items_count.store(booking.dining_facility_id, order.order_items.count)
# else
# @order_items_count[booking.dining_facility_id] += order.order_items.count
# end
# end
# end
# end
# else
# if !booking.sale_id.nil?
# sale = Sale.find(booking.sale_id)
# if sale.sale_status !='completed'
# if !@order_items_count.key?(booking.dining_facility_id)
# @order_items_count.store(booking.dining_facility_id, sale.sale_items.count)
# else
# @order_items_count[booking.dining_facility_id] = sale.sale_items.count
# end
# end
# end
# end
# end
# end
end
def app_orders
@bookings = Booking.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins("JOIN orders ON orders.order_id=booking_orders.order_id")
.where("orders.source='app' and bookings.shop_code='#{@shop.shop_code}'").order("created_at desc")
end
def app_order_by_booking
end
end

View File

@@ -0,0 +1,85 @@
class Foodcourt::OtherChargesController < BaseFoodcourtController
authorize_resource :class => false
def index
@webview = false
if check_mobile
@webview = true
end
sale_id = params[:sale_id]
@cashier_type = params[:type]
if Sale.exists?(sale_id)
@sale_data = Sale.find(sale_id)
if @sale_data.bookings[0].dining_facility_id.to_i > 0
@table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id)
else
@table = nil
end
end
end
def create
sale_id = params[:sale_id]
other_charges_items = JSON.parse(params[:other_charges_items])
sub_total = params[:sub_total]
cashier_type = params[:cashier_type]
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
if sale.bookings[0].dining_facility_id.to_i > 0
table_id = sale.bookings[0].dining_facility_id
table = DiningFacility.find(table_id)
else
table_id = nil
table = nil
end
# sale.total_amount = sub_total.to_f
# sale.grand_total = sub_total.to_f + sale.total_tax;
# sale.save
if other_charges_items.length > 0
#save sale item for discount
other_charges_items.each do |di|
# origin_sale_item = SaleItem.find(di["id"])
sale_item = SaleItem.new
sale_item.sale_id = sale_id
sale_item.menu_category_code = "0.0"
sale_item.menu_category_name = "Other Charges"
sale_item.product_code = "Other Charges"
sale_item.product_name = "*" + di["name"]
sale_item.product_alt_name = ""
sale_item.status = "Other Charges"
sale_item.qty = 1
sale_item.unit_price = di["price"]
sale_item.taxable_price = di["price"] * 1
sale_item.is_taxable = di["is_taxable"]
sale_item.account_id = 0
sale_item.price = di["price"] * 1
sale_item.save
action_by = current_user.name
if table.nil?
remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->"
else
remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->#{table.name}"
end
sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_name, action_by,remark,"ADDOTHERCHARGES" )
end
end
# Re-calc All Amount in Sale
sale.compute_by_sale_items(sale.total_discount, nil, cashier_type)
end
if !table.nil?
dining = {:table_id => table_id, :table_type => table.type }
render :json => dining.to_json
end
end
end

View File

@@ -0,0 +1,97 @@
class Foodcourt::PaymalController < BaseFoodcourtController
def index
@sale_id = params[:sale_id]
payment_method = params[:payment_method]
@cashier_type = params[:type]
@membership_rebate_balance=0
sale_data = Sale.find_by_sale_id(@sale_id)
@receipt_no = sale_data.receipt_no
# @shop = Shop.first
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else
new_total = sale_data.grand_total
end
@rounding_adj = new_total-sale_data.grand_total
# @rounding_adj = sale_data.rounding_adjustment
@payparcount = 0
others = 0
sale_data.sale_payments.each do |sale_payment|
if sale_payment.payment_method == "paypar"
@payparcount = @payparcount + sale_payment.payment_amount
else
others = others + sale_payment.payment_amount
end
end
@payment_prices = sale_data.grand_total - @payparcount -others
if sale_data
if sale_data.customer_id
customer_data= Customer.find_by_customer_id(sale_data.customer_id)
if customer_data
@membership_id = customer_data.membership_id
if !@membership_id.nil?
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",@shop.shop_code)
if membership_setting.gateway_url
member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",@shop.shop_code)
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(url,membership_setting.auth_token,@membership_id,@campaign_type_id,merchant_uid,auth_token)
if membership_data["status"]==true
@membership_rebate_balance=membership_data["balance"]
@out = true, @membership_rebate_balance,@membership_id
end
else
@out =false,0
end
else
@out = false,0
end
else
@out = false, 0
end
else
@out = false, 0
end
else
@out = false, 0
end
else
@out = false, 0
end
@out = false, 0
end
def create
cash = params[:payment_amount]
sale_id = params[:sale_id]
transaction_ref = params[:transaction_ref]
account_no = params[:account_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
# shop_details = Shop.first
# rounding adjustment
# if shop_details.is_rounding_adj
# new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
# rounding_adj = new_total-saleObj.grand_total
# saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
# end
# saleObj = Sale.find(sale_id)
sale_payment = SalePayment.new
status, @sale,@membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal",account_no)
if status == true && @membership_data["status"] == true
@out = true, "Success!"
else
@out =false, @membership_data["message"]
end
end
end
end

View File

@@ -0,0 +1,691 @@
class Foodcourt::PaymentsController < BaseFoodcourtController
authorize_resource :class => false
def index
end
def create
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
is_kbz = params[:is_kbz]
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.is_rounding_adj
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
rounding_adj = new_total - saleObj.grand_total
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
end
end
#end rounding adjustment
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
sale_payment.process_payment(saleObj, current_user, cash, "cash")
else
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
end
# end
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)
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.where("shop_code='#{@shop.shop_code}'").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"
# else
end
end
end
end
customer= Customer.find(saleObj.customer_id)
# get member information
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
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 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,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id)
# get printer info
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_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, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, 'Foodcourt',current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref)
#end
end
logger.debug 'saleObj++++++++++++++++++++++++++'
logger.debug saleObj.to_json
if !saleObj.nil?
# InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
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 show
display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code)
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@display_type = nil
end
path = request.fullpath
sale_id = params[:sale_id]
@trans_flag = true
if params[:type] == "transaction"
@trans_flag = false
@cashier_type = "cashier"
else
@cashier_type = params[:type]
end
if path.include? ("credit_payment")
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id)
end
@member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code)
@membership_rebate_balance=0
if Sale.exists?(sale_id)
@cash = 0.0
@kbz_pay_amount = 0.0
@other = 0.0
@ppamount = 0.0
@visacount= 0.0
@jcbcount= 0.0
@mastercount = 0.0
@unionpaycount = 0.0
@alipaycount = 0.0
@junctionpaycount = 0.0
@credit = 0.0
@paymalcount = 0.0
@dingacount = 0.0
@giftvouchercount = 0.0
@sale_data = Sale.find_by_sale_id(sale_id)
@balance = 0
@accountable_type = ''
@table_no = ''
@dining = ''
@other_payment = 0.0
@pdf_view = nil
@lookup_pdf = Lookup.find_by_lookup_type_and_shop_code("ReceiptPdfView",@shop.shop_code)
if !@lookup_pdf.nil?
@pdf_view = @lookup_pdf.value
end
amount = SalePayment.get_kbz_pay_amount(sale_id, current_user,@shop)
@kbz_pay_amount += amount.to_f
#for changable on/off
@changable_tax = true
lookup_changable_tax = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('changable_tax')
if !lookup_changable_tax.empty?
lookup_changable_tax.each do |changable_tax|
if changable_tax[0].downcase == "change"
if changable_tax[1] == '0'
@changable_tax = false
end
end
end
end
# @shop = shop_detail #show shop info
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")
saleObj = Sale.find(sale_id)
#total customer with individual total amount
@individual_total = Array.new
if !saleObj.equal_persons.nil?
per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i
@individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f })
end
# rounding adjustment
# if @shop.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
# else
# @rounding_adj = @sale_data.rounding_adjustment
# end
# else
# @rounding_adj = @sale_data.rounding_adjustment
# end
#end rounding adjustment
# rounding adjustment
if @shop.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)
@sale_data.grand_total = new_total
@sale_data.old_grand_total = saleObj.grand_total
@sale_data.rounding_adjustment = @rounding_adj
else
@rounding_adj = @sale_data.rounding_adjustment
end
else
@rounding_adj = @sale_data.rounding_adjustment
end
#end rounding adjustment
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
#get customer amount
@customer = Customer.find(@sale_data.customer_id)
# accounts = @customer.tax_profiles
accounts = TaxProfile.where("group_type = ? and shop_code='#{@shop.shop_code}'",@cashier_type).order("order_by ASC")
@account_arr =[]
@tax_arr =[]
accounts.each do |acc|
account = TaxProfile.find(acc.id)
# @account_arr.push(account)
@tax_arr.push(account.name)
end
sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id)
if !sale_taxes.empty?
sale_taxes.each do |sale_tax|
@account_arr.push(sale_tax)
end
end
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
# get member information
if @customer.membership_id != nil && rebate
response = Customer.get_member_account(@customer)
if response["status"]==true
response["account_data"].each do |res|
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
@balance = @balance.to_f + res["balance"].to_f
# @accountable_type = res["accountable_type"]
@accountable_type = "Rebate Balance"
end
end
end
end
#end customer amount
#paymal payment
@sale_data.bookings.each do |sbk|
if sbk.dining_facility_id.to_i >0
df = DiningFacility.find(sbk.dining_facility_id)
@table_no = df.type + ' ' + df.name
@checkin_time = sbk.checkin_at
@dining = df
break
else
@table_no = nil
@checkin_time = nil
@dining = nil
end
end
if path.include? ("credit_payment")
@sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data)
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
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
def reprint
sale_id = params[:sale_id]
member_info = nil
latest_order_no = nil
saleObj = Sale.find(sale_id)
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
booking = Booking.find_by_sale_id(sale_id)
latest_order = booking.booking_orders.joins(" JOIN orders ON orders.order_id = booking_orders.order_id").where("orders.source = 'quick_service'").order("order_id DESC").limit(1).first()
if !latest_order.nil?
latest_order_no = latest_order.order_id
end
# if bookings.count > 1
# # for Multiple Booking
# table = DiningFacility.find(bookings[0].dining_facility_id)
# else
# table = DiningFacility.find(bookings[0].dining_facility_id)
# end
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
if bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(bookings[0].dining_facility_id)
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
else
shift = ShiftSale.find(saleObj.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
end
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
unique_code = "ReceiptBillPdf"
if !receipt_bill_a5_pdf.empty?
receipt_bill_a5_pdf.each do |receipt_bilA5|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
if receipt_bilA5[1] == '1'
unique_code = "ReceiptBillA5Pdf"
else
unique_code = "ReceiptBillPdf"
end
end
end
end
customer= Customer.find(saleObj.customer_id)
#shop detail
#shop_detail = Shop.first
# get member information
rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
current_balance = SaleAudit.paymal_search(sale_id)
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,transaction_ref= SaleAudit.getCardBalanceAmount(sale_id)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# Calculate price_by_accounts
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(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, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref)
result = {
:status => true,
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# Mobile Print
render :json => result.to_json
# end
end
def foc
cash = params[:cash]
sale_id = params[:sale_id]
sub_total = params[:sub_total]
remark = params[:remark]
member_info = nil
rebate_amount = nil
current_balance = nil
order_source = params[:type]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
#calculate cash acmount
cash = saleObj.total_amount
if saleObj.discount_type == "member_discount"
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
saleObj.compute_by_sale_items(0, nil, order_source)
end
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
bookings = Booking.where("sale_id='#{sale_id}'")
if bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(bookings[0].dining_facility_id)
type = 'payment'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
if bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(bookings[0].dining_facility_id)
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
else
shift = ShiftSale.find(saleObj.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
end
# Re-call Sale Data
saleObj = Sale.find(sale_id)
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
# unique_code = "ReceiptBillPdf"
customer= Customer.find(saleObj.customer_id)
#shop detail
#shop_detail = Shop.first
printer = PrintSetting.where("shop_code='#{@shop.shop_code}'")
unique_code="ReceiptBillPdf"
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'ReceiptBillPdf'
unique_code="ReceiptBillPdf"
elsif printer_setting.unique_code == 'ReceiptBillA5Pdf'
unique_code="ReceiptBillA5Pdf"
elsif printer_setting.unique_code == 'ReceiptBillStarPdf'
unique_code="ReceiptBillStarPdf"
end
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_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(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = 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, "FOC",nil,nil,other_amount,nil,nil,nil,nil)
result = {
:status => true,
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# Mobile Print
render :json => result.to_json
if params[:type] == "quick_service"
booking = Booking.find_by_sale_id(sale_id)
if booking.dining_facility_id.to_i>0
table_id = booking.dining_facility_id
else
table_id = 0
end
booking.booking_orders.each do |order|
Order.pay_process_order_queue(order.order_id,table_id)
end
end
# end
if !saleObj.nil?
#InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
end
end
end
def rounding_adj
saleObj = Sale.find(params[:sale_id])
if @shop.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
#print function for receipt
def print
filename = params[:filename]
receipt_no = params[:receipt_no]
printer_name = params[:printer_name]
cashier_type = params[:type]
if cashier_type.strip.downcase == "doemal_order"
unique_code = "ReceiptBillOrderPdf"
else
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
unique_code = "ReceiptBillPdf"
print_settings = PrintSetting.where("shop_code='#{@shop.shop_code}'")
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"
# else
# unique_code = "ReceiptBillPdf"
end
end
end
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)
result = {
:status => true,
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
Rails.logger.debug "$$$$$$$$$ result ::"
Rails.logger.debug result
# Mobile Print
render :json => result.to_json
# render :json => {status: true}
end
#changable tax for sale
def change_tax
sale_id = params[:sale_id]
order_source = params[:cashier_type]
tax_type = params[:tax_type]
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.total_discount, nil, order_source, tax_type)
render json: JSON.generate({:status => true})
end
#get cloud domain
def getCloudDomain
from = ""
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain.to_s + "." + request.domain.to_s
end
return from
end
end

View File

@@ -0,0 +1,32 @@
class Foodcourt::PayparPaymentsController < BaseFoodcourtController
def create
sale_id = params[:sale_id]
@cashier_type = params[:type]
redeem_amount = params[:redeem_amount]
membership_id = params[:membership_id]
payment_method = "paypar"
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
# shop_details = Shop.first
# rounding adjustment
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
rounding_adj = new_total-saleObj.grand_total
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
end
sale_payment = SalePayment.new
status,msg =sale_payment.process_payment(saleObj, current_user, redeem_amount,payment_method)
if status == true
@out = true, "Success!"
else
@out =false, "Please try again payment!"
end
else
@out = false, "There has no sale record!"
end
end
end

View File

@@ -0,0 +1,113 @@
class Foodcourt::RequestBillsController < ApplicationController
before_action :check_user
def check_user
if current_user.nil?
redirect_to root_path
end
end
# Print Request Bill and add to sale tables
def print
if !ShiftSale.current_shift(@shop.shop_code).nil?
order_id = params[:id] # order_id
order = Order.find(order_id)
booking = order.booking
if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil?
@status = false
@error_message = "Operation failed, Could not request bill!"
else
table = DiningFacility.find_by(id: booking.dining_facility_id)
if sale_data = booking.sale
@status = true
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
@status = true
# in-duty update
in_duties = InDuty.where("booking_id=?", booking.id)
if !in_duties.empty?
in_duties.each do |in_duty|
induty = InDuty.find(in_duty.id)
induty.sale_id = sale_data.sale_id
induty.out_time = Time.now.utc
induty.save
end
end
end
# Bind shift sale id to sale
# @sale_data.shift_sale_id = shift.id
# @sale_data.save
action_by = current_user.name
type = "REQUEST_BILL"
remark = "Request bill Receipt No #{sale_data.receipt_no}"
sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type )
# Promotion Activation
Promotion.promo_activate(sale_data,@shop.shop_code)
#bill channel
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
if order.source == "cashier" || order.source == "quick_service"
ActionCable.server.broadcast "bill_channel",table: table, from: from
end
if order.source == "quick_service" || order.source == "food_court"
result = {:status=> @status, :data => sale_data.sale_id }
render :json => result.to_json
else
#check checkInOut pdf print
checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')
if !booking.dining_facility_id.nil?
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
unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_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)
end
end
end
end
end
@status = true
else
@status = false
@error_message = "No Current Open Shift for This Employee"
end
# Not Use for these printed bill cannot give customer
# unique_code = "ReceiptBillPdf"
# #shop detail
# shop_details = Shop.find(1)
# # customer= Customer.where('customer_id=' +.customer_id)
# customer= Customer.find(@sale_data.customer_id)
# # get member information
# member_info = Customer.get_member_account(customer)
# # get printer info
# print_settings=PrintSetting.find_by_unique_code(unique_code)
# # find order id by sale id
# # sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# # Calculate price_by_accounts
# item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
# printer = Printer::ReceiptPrinter.new(print_settings)
# printer.print_receipt_bill(print_settings, false, nil,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
end
end

View File

@@ -0,0 +1,232 @@
class Foodcourt::SaleEditController < BaseFoodcourtController
authorize_resource class: false
# Index for sale item void OR edit
def edit
sale_id = params[:sale_id]
if params[:table_id]
@table_id = params[:table_id]
@table_type = DiningFacility.find(@table_id).type
else
@table_id = nil
@table_type = nil
end
@cashier_type = params[:type]
@saleobj = Sale.find(sale_id)
end
# create item void. make duplicate old record and update qty and price
def item_void
saleitemId = params[:sale_item_id]
remark = params[:remark]
access_code = params[:access_code]
order_source = params[:type]
saleitemObj = SaleItem.find(saleitemId)
saleitemObj.status = 'void'
saleitemObj.remark = remark
saleitemObj.save
@newsaleitem = SaleItem.new
@newsaleitem = saleitemObj.dup
# @newsaleitem.save
@newsaleitem.qty = saleitemObj.qty * -1
@newsaleitem.price = saleitemObj.price * -1
@newsaleitem.is_taxable = 1
@newsaleitem.taxable_price = saleitemObj.taxable_price * -1
@newsaleitem.product_name = saleitemObj.product_name + ' (VOID)'
@newsaleitem.remark = remark
@newsaleitem.save
# re-calc tax
saleObj = Sale.find(saleitemObj.sale_id)
# booking = Booking.find_by_sale_id(saleitemObj.sale_id)
# booking.booking_orders.each do |bo|
# order = Order.find(bo.order_id)
# order.order_items.each do |o|
# if saleitemObj.product_code == o.item_code
# o.qty = saleitemObj.qty * -1
# o.price = saleitemObj.price * -1
# o.save
# end
# end
# end
# FOr Sale Audit
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id(access_code).name
end
remark = "Void Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}"
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMVOID" )
saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source)
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
end
def item_foc
saleitemId = params[:sale_item_id]
remark = params[:remark]
access_code = params[:access_code]
order_source = params[:type]
saleitemObj = SaleItem.find(saleitemId)
saleitemObj.status = 'foc'
saleitemObj.remark = remark
saleitemObj.save
@newsaleitem = saleitemObj.dup
@newsaleitem.qty = saleitemObj.qty * -1
@newsaleitem.unit_price = saleitemObj.unit_price * 1
@newsaleitem.taxable_price = saleitemObj.taxable_price * -1
@newsaleitem.price = saleitemObj.price * -1
@newsaleitem.product_name = saleitemObj.product_name + ' (FOC)'
@newsaleitem.remark = remark
@newsaleitem.save
# re-calc tax
saleObj = Sale.find(saleitemObj.sale_id)
order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
order = Order.find(order_id)
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id(access_code).name
end
remark = "FOC Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}Receipt No #{saleObj.receipt_no}"
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMFOC" )
saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source)
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
end
# def item_edit
# saleitemId = params[:sale_item_id]
# update_qty = params[:update_qty]
# update_price = params[:update_price]
# saleitemObj = SaleItem.find(saleitemId)
# saleitemObj.status = 'void'
# saleitemObj.save
# @newsaleitem = SaleItem.new
# @newsaleitem = saleitemObj.dup
# @newsaleitem.save
# @newsaleitem.qty = update_qty
# @newsaleitem.price = update_price
# @newsaleitem.unit_price = update_price
# @newsaleitem.taxable_price = update_price
# @newsaleitem.is_taxable = 0
# @newsaleitem.remark = 'edit'
# @newsaleitem.product_name = saleitemObj.product_name + " - updated"
# @newsaleitem.save
# end
def item_edit
saleitemId = params[:sale_item_id]
update_qty = params[:update_qty]
update_price = params[:update_price]
access_code = params[:access_code]
order_source = params[:type]
saleitemObj = SaleItem.find(saleitemId)
original_qty = saleitemObj.qty
original_price = saleitemObj.unit_price
sale = Sale.find(saleitemObj.sale_id)
saleitemObj.qty = update_qty
saleitemObj.price = update_qty.to_f * update_price.to_f
saleitemObj.unit_price = update_price
saleitemObj.taxable_price = update_qty.to_f * update_price.to_f
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id(access_code).name
end
remark = "Update From Qty=>#{original_qty} Price=>[#{original_price}] to qty=>#{update_qty} Price =>[#{saleitemObj.price}]| Receipt No #{sale.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}"
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMEDIT" )
# saleitemObj.remark = 'edit'
unless saleitemObj.product_name.include? 'UPDATED'
saleitemObj.product_name = saleitemObj.product_name + ' (UPDATED)'
end
saleitemObj.save
# re-calc tax
# saleObj = Sale.find(saleitemObj.sale_id)
# order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
# order = Order.find(order_id)
# order.order_items.each do |o|
# if saleitemObj.product_code == o.item_code
# o.qty = update_qty
# o.price = update_price
# o.save
# end
# end
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
ProductCommission.edit_product_commission(saleitemObj,sale.shop_code)
end
# make cancel void item
def item_void_cancel
saleitemId = params[:sale_item_id]
access_code = params[:access_code]
order_source = params[:type]
saleitemObj = SaleItem.find(saleitemId)
saleObj = saleitemObj.sale
saleObj.sale_items.where(product_code: saleitemObj.product_code)
.where(qty: saleitemObj.qty.abs)
.where(unit_price: saleitemObj.unit_price)
.where(status: saleitemObj.status).first.update(status: nil, remark: nil)
saleitemObj.destroy
# re-calc tax
order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
order = Order.find(order_id)
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id(access_code).name
end
remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}"
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" )
saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source)
ProductCommission.remove_product_commission(saleitemObj)
end
# remove all void items
def cancel_all_void
sale_id = params[:sale_id]
order_source = params[:type]
saleObj = Sale.find(sale_id)
saleObj.sale_items.each do |item|
if item.qty.to_i < 0
item.destroy
else
item.status = nil
end
item.save
ProductCommission.remove_product_commission(item)
end
saleObj.sale_items.reset
# re-calc tax
saleObj.compute_by_sale_items(saleObj.total_discount,nil, order_source)
end
def apply_void
sale_id = params[:sale_id]
order_source = params[:type]
saleObj = Sale.find(sale_id)
saleObj.compute_without_void(order_source)
saleObj.sale_items.each do |item|
ProductCommission.remove_product_commission(item)
end
end
end

View File

@@ -0,0 +1,78 @@
class Foodcourt::SalesController < BaseFoodcourtController
def show
@webview = false
if check_mobile
@webview = true
end
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name")
@sale = Sale.find(params[:sale_id])
@order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id
@booking = BookingOrder.find_by_order_id(@order).booking_id
if Booking.find(@booking).dining_facility_id.to_i>0
@table_id = Booking.find(@booking).dining_facility_id
@dining = DiningFacility.find(@table_id)
else
@table_id = nil
@dining = nil
end
end
def add_to_existing_invoice
dining = params[:dining_id]
sale_id = params[:sale_id]
tax_type = params[:tax_type]
sale_data = []
table = DiningFacility.find(dining)
existing_booking = Booking.find_by_sale_id(sale_id)
table.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ").each do |booking|
if booking.sale_id.nil?
order_array = []
booking.booking_orders.each do |booking_order|
booking.booking_status = 'moved'
order = Order.find(booking_order.order_id)
order.status = 'billed'
order.order_items.each do |item|
item.order_item_status = 'billed'
end
# create sale item
saleobj = Sale.find(sale_id)
order.order_items.each do |orer_item|
saleobj.add_item (orer_item)
if !orer_item.set_menu_items.nil?
saleobj.add_sub_item(orer_item.set_menu_items)
end
sale_data.push(orer_item)
end
# Re-compute for add
saleobj.compute(order.source,tax_type)
saleobj.save
order.save
booking.save
order_array.push(order.order_id)
end
receipt_no = Sale.find(sale_id).receipt_no
action_by = current_user.name
type = "ADD_TO_EXISTING"
remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no} in #{table.name}"
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
booking_order = BookingOrder.where('booking_id=?',booking)
booking_order.each do |bo|
bo.booking_id = existing_booking.booking_id
bo.save
end
end
end
end
end

View File

@@ -0,0 +1,34 @@
class Foodcourt::SecondDisplayController < BaseFoodcourtController
def index
@display_images = DisplayImage.all
end
def show
end
def customer_view
display_type = Lookup.find_by_lookup_type("display_type")
if !display_type.nil? && display_type.value.to_i == 2
if params[:status]!= "billed"
tax_profiles = TaxProfile.all.order("order_by asc")
else
tax_profiles = nil
end
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from
end
# end
end
#Shop Name in Navbor
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# end
end

View File

@@ -0,0 +1,158 @@
class Foodcourt::ShiftsController < BaseFoodcourtController
def index
end
def show
@cashier_type = params[:type]
@shift = ShiftSale.current_open_shift(current_user)
#for bank integration
bank_integration = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('bank_integration')
@bank_integration = 0
if !bank_integration[0].nil?
@bank_integration = bank_integration[0][1]
end
end
def new
@float = Lookup.where('lookup_type=?','float_value')
@terminal = CashierTerminal.available.where("shop_code='#{@shop.shop_code}'")
end
def create
opening_balance = params[:opening_balance]
cashier_terminal_param = params[:cashier_terminal]
# Multiple Cashier
cashier_terminal = CashierTerminal.find(cashier_terminal_param)
if cashier_terminal.is_currently_login
respond_to do |format|
format.html { redirect_to settings_order_queue_stations_url, notice: 'Cashier Terminal already signin!' }
end
end
# Update Cashier Terminal
cashier_terminal.is_currently_login = 1
cashier_terminal.save
@shift_sale = ShiftSale.new
@shift_sale.create(opening_balance,cashier_terminal_param, current_user)
end
def update_shift
closing_balance = params[:closing_balance]
shift_id = params[:shift_id]
@shift = ShiftSale.find_by_id(shift_id)
if @shift
@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
#add shift_sale_id to card_settle_trans
bank_integration = Lookup.find_by_lookup_type_and_shop_code('bank_integration',@shop.shop_code)
if !bank_integration.nil?
card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL'])
card_settle_trans.each do |data|
card_sett_trans = CardSettleTran.find(data.id)
card_sett_trans.shift_sale_id = @shift.id
card_sett_trans.save()
end
end
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
# if !close_cashier_print[0].nil?
# @close_cashier_print = close_cashier_print[0][1]
# end
close_cashier_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings")
unique_code = "CloseCashierPdf"
if !close_cashier_pdf.empty?
close_cashier_pdf.each do |close_cashier|
if close_cashier[0] == 'CloseCashierCustomisePdf'
if close_cashier[1] == '1'
unique_code="CloseCashierCustomisePdf"
else
unique_code="CloseCashierPdf"
end
end
end
end
shop_details = shop_detail
#get tax
shift_obj = ShiftSale.where('id =?',@shift.id)
sale_items = ''
@lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code)
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_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'")
@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
# get printer info
print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::CashierStationPrinter.new(print_settings)
# print close cashier setting
close_cashier_print = Lookup.collection_of('close_cashier_print')
if close_cashier_print.empty?
@settings_lookup = Lookup.new(lookup_type: "close_cashier_print", name: "CloseCashierPrint", value: "1")
@settings_lookup.save
end
find_close_cashier_print = Lookup.collection_of('close_cashier_print')
if find_close_cashier_print[0][1].to_i > 0
printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
end
end
end
Employee.logout(@shop,session[:session_token])
session[:session_token] = nil
end
def edit
end
def sale_summary
@shift = ShiftSale.current_open_shift(current_user)
# @shift = ShiftSale.find_by_id(shift_id)
if @shift
#get tax
shift_obj = ShiftSale.where('id =?',@shift.id)
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'")
#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)
end
end
end

View File

@@ -0,0 +1,112 @@
class Foodcourt::SurveysController < BaseFoodcourtController
def new
@webview = false
if check_mobile
@webview = true
end
@survey = Survey.new
@id = params[:id]
@cashier_type = params[:type]
if(@id[0,3] == "SAL")
@sale = Sale.find(@id)
@receipt_no = @sale.receipt_no
@grand_total = @sale.grand_total
@booking = Booking.find_by_sale_id(@id)
if @booking.dining_facility_id.to_i>0
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
@table_type = @dining_facility.type
@survey_data = Survey.find_by_dining_name_and_shop_code(@dining_facility.name,@shop.shop_code)
survey_process = Survey.find_by_receipt_no_and_shop_code(@receipt_no,@shop.shop_code)
if !survey_process.nil?
@survey_data = survey_process
end
else
@dining_facility = nil
@table_type = nil
end
else
@dining_facility = DiningFacility.find(@id)
@table_type = @dining_facility.type
@receipt_no = nil
@grand_total = nil
@survey_data = Survey.find_by_dining_name_and_receipt_no_and_shop_code(@dining_facility.name,nil,@shop.shop_code)
end
end
def create
@type = params[:cashier_type]
@sale_id = params[:sale_id]
if params[:table_id].to_i>0
@dining_facility = DiningFacility.find(params[:table_id])
if params[:sale_id].to_i > 0
# cashier_zone = CashierTerminalByZone.find_by_zone_id(@dining_facility.zone_id)
# shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
# set cashier
open_cashier = Employee.where("role = 'cashier' AND token_session <> '' and shop_code='#{@shop.shop_code}'")
current_shift = ShiftSale.current_shift(@shop.shop_code)
current_shift_user =Employee.find_by_id(current_user.employee_id)
if open_cashier.count>0
shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0])
else
shift_by_terminal = ShiftSale.current_open_shift(current_shift_user)
end
else
sale = Sale.find(@sale_id)
shift = ShiftSale.find(sale.shift_sale_id)
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil)
end
else
sale = Sale.find(@sale_id)
shift = ShiftSale.find(sale.shift_sale_id)
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil)
end
if @type == "quick_service" || @type == "food_court"
@url = "/foodcourt/sale/"+@sale_id+"/"+@type+"/payment"
else
@url = "/foodcourt/"+@dining_facility.type.downcase+"/"+params[:table_id]
end
if params[:survey_id].nil? || params[:survey_id] == ""
@survey = Survey.new(survey_params)
@survey.shift_id = shift_by_terminal.id
@survey.foreigner = params["survey"]["foreigner"].to_json
@survey.shop_code = @shop.shop_code
# respond_to do |format|
if @survey.save
redirect_to @url
end
# end
else
survey = Survey.find_by_id(params[:survey_id])
survey.child = params["survey"]["child"]
survey.adult = params["survey"]["adult"]
survey.male = params["survey"]["male"]
survey.female = params["survey"]["female"]
survey.local = params["survey"]["local"]
survey.dining_name = params["survey"]["dining_name"]
survey.receipt_no = params["survey"]["receipt_no"]
survey.shift_id = shift_by_terminal.id
survey.created_by = params["survey"]["created_by"]
survey.total_customer = params["survey"]["total_customer"]
survey.total_amount = params["survey"]["total_amount"]
survey.foreigner = params["survey"]["foreigner"].to_json
if survey.save!
redirect_to @url
end
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def survey_params
params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id)
end
end

View File

@@ -0,0 +1,171 @@
class Foodcourt::VoidController < BaseFoodcourtController
authorize_resource :class => false
def overall_void
sale_id = params[:sale_id]
remark = params[:remark]
order_source = params[:type] #tax profile source
access_code = params[:access_code]
if Sale.exists?(sale_id)
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
# No Need
# bookings = sale.bookings
# bookings.each do |booking|
# orders = booking.orders
# orders.each do |order|
# # order.status = 'void'
# end
# end
if sale.bookings[0].dining_facility_id.to_i > 0
table_avaliable = true
table_count = 0
table = sale.bookings[0].dining_facility
table.bookings.each do |booking|
if booking.booking_status != 'moved'
if booking.sale_id
if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste'
table_avaliable = false
table_count += 1
else
table_avaliable = true
end
else
table_avaliable = false
table_count += 1
end
end
end
if table_avaliable && table_count == 0
table.status = 'available'
table.save
end
else
table = nil
end
# FOr Sale Audit
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_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_user.name, action_by,remark,"SALEVOID" )
# For Print
member_info = nil
rebate_amount = nil
current_balance = nil
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
if bookings.count > 1
# for Multiple Booking
if bookings[0].dining_facility_id.to_i>0
table = DiningFacility.find(bookings[0].dining_facility_id)
end
end
if bookings[0].dining_facility_id.to_i > 0
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
else
shift = ShiftSale.find(sale.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
# get printer info
# print_settings = PrintSetting.find_by_unique_code('ReceiptBillPdf') # SaleItemsPdf
#
# if !print_settings.nil?
# unique_code = 'ReceiptBillPdf'
# elsif
# unique_code = 'ReceiptBillStarPdf'
# end
customer= Customer.find(sale.customer_id)
# get member information
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
# current_balance = SaleAudit.paymal_search(sale_id)
current_balance = 0
end
printer = PrintSetting.where("shop_code='#{@shop.shop_code}'")
unique_code="ReceiptBillPdf"
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'ReceiptBillPdf'
unique_code="ReceiptBillPdf"
elsif printer_setting.unique_code == 'ReceiptBillA5Pdf'
unique_code="ReceiptBillA5Pdf"
elsif printer_setting.unique_code == 'ReceiptBillStarPdf'
unique_code="ReceiptBillStarPdf"
end
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil)
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# Mobile Print
render :json => result.to_json
# end
#end print
# update complete order items in oqs
SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
aoi.delivery_status = 1
aoi.save
end
end
end
end
end

View File

@@ -0,0 +1,145 @@
class Foodcourt::WasteSpoileController < BaseFoodcourtController
def waste_and_spoilage
sale_id = params[:sale_id]
remark = params[:remark]
order_source = params[:type]
access_code = params[:access_code] #tax profile source
if Sale.exists?(sale_id)
sale = Sale.find_by_sale_id(sale_id)
SaleTax.where("sale_id='#{sale_id}'").find_each do |existing_tax|
existing_tax.delete
end
sale.update_attributes(total_discount: 0,total_tax: 0,grand_total: sale.total_amount,rounding_adjustment:0)
sale.payment_status = remark
sale.sale_status = remark
sale.save
# add to sale item with foc
# sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null")
sale.sale_items.each do|item|
# SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price)
item.status = remark
item.remark = remark
item.save
end
if sale.bookings[0].dining_facility_id.to_i > 0
table_avaliable = true
table_count = 0
table = sale.bookings[0].dining_facility
table.bookings.each do |booking|
if booking.booking_status != 'moved'
if booking.sale_id
if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste'
table_avaliable = false
table_count += 1
else
table_avaliable = true
end
else
table_avaliable = false
table_count += 1
end
end
end
if table_avaliable && table_count == 0
table.status = 'available'
table.save
end
else
table = nil
end
# FOr Sale Audit
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_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_user.name, action_by,remark,remark )
# For Print
member_info = nil
rebate_amount = nil
current_balance = nil
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
if bookings.count > 1
# for Multiple Booking
if bookings[0].dining_facility_id.to_i>0
table = DiningFacility.find(bookings[0].dining_facility_id)
end
end
if bookings[0].dining_facility_id.to_i > 0
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
else
shift = ShiftSale.find(sale.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
# unique_code = "ReceiptBillPdf"
customer= Customer.find(sale.customer_id)
# get member information
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
# current_balance = SaleAudit.paymal_search(sale_id)
current_balance = 0
end
printer = PrintSetting.where("shop_code='#{@shop.shop_code}'")
unique_code="ReceiptBillPdf"
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'ReceiptBillPdf'
unique_code="ReceiptBillPdf"
elsif printer_setting.unique_code == 'ReceiptBillA5Pdf'
unique_code="ReceiptBillA5Pdf"
elsif printer_setting.unique_code == 'ReceiptBillStarPdf'
unique_code="ReceiptBillStarPdf"
end
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil,nil)
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# Mobile Print
render :json => result.to_json
# end
#end print
# update complete order items in oqs
SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
aoi.delivery_status = 1
aoi.save
end
end
end
end
end