Merge branch 'sqa-1804-001' of bitbucket.org:code2lab/sxrestaurant into r-1804001-01

This commit is contained in:
phyusin
2018-05-02 13:49:17 +06:30
33 changed files with 959 additions and 226 deletions

View File

@@ -78,6 +78,14 @@ class MenuCategory < ApplicationRecord
end
end
def get_sub_category
menu_category = MenuCategory.find_by_menu_category_id(self.id)
if menu_category
return true
end
return false
end
private
# def generate_menu_category_code

View File

@@ -5,9 +5,9 @@ class OrderReservation < ApplicationRecord
before_create :generate_custom_id
has_many :order_reservation_items
belongs_to :delivery
has_one :delivery
scope :latest_order, -> { order("order_reservation_id desc, requested_time asc") }
scope :latest_order, -> { order("order_reservation_id desc, created_at desc") }
SEND_TO_KITCHEN = "send_to_kitchen"
READY_TO_DELIVERY = "ready_to_deliver"
@@ -21,7 +21,7 @@ class OrderReservation < ApplicationRecord
order_reservation = OrderReservation.new
order_reservation.order_reservation_type = order_reserve[:order_type]
order_reservation.customer_id = order_reserve[:cus_info]
order_reservation.requested_time = DateTime.parse(order_reserve[:requested_time]).utc.strftime("%Y-%m-%d %H:%M:%S")
order_reservation.requested_time = Time.parse(order_reserve[:requested_time]).utc
order_reservation.callback_url = order_reserve[:callback_url]
order_reservation.transaction_ref = order_reserve[:reference]
if order_reserve[:order_info]
@@ -29,9 +29,11 @@ class OrderReservation < ApplicationRecord
order_reservation.payment_type = order_reserve[:payment_info][:payment_type]
order_reservation.payment_status = order_reserve[:payment_info][:payment_status]
order_reservation.payment_ref = order_reserve[:payment_info][:payment_ref]
order_reservation.taxes = order_reserve[:payment_info][:taxes]
order_reservation.total_amount = order_reserve[:payment_info][:sub_total]
order_reservation.total_tax = order_reserve[:payment_info][:total_tax]
order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount]
order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge]
order_reservation.grand_total = order_reserve[:payment_info][:grand_total]
order_reservation.order_remark = order_reserve[:order_info][:order_remark]
end
@@ -132,96 +134,10 @@ class OrderReservation < ApplicationRecord
result = {:status=> true, :message => DELIVERED }
return result
# rebate_amount = nil
# For Cashier by Zone
# bookings = Booking.where("sale_id='#{sale_id}'")
# 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
# For Print
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
# receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
# unique_code = "ReceiptBillPdf"
# 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)
# get member information
# rebate = MembershipSetting.find_by_rebate(1)
# credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
# if customer.membership_id != nil && rebate && credit_data.nil?
# member_info = Customer.get_member_account(customer)
# if member_info["status"] == true
# rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
# current_balance = SaleAudit.paymal_search(sale_id)
# end
# end
#orders print out
# if params[:type] == "quick_service"
# booking = Booking.find_by_sale_id(sale_id)
# if booking.dining_facility_id.to_i>0
# table_id = booking.dining_facility_id
# else
# table_id = 0
# end
# 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)
# 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
# get printer info
# print_settings=PrintSetting.find_by_unique_code(unique_code)
# Calculate Food and Beverage Total
# item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
# discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
# printer = Printer::ReceiptPrinter.new(print_settings)
# filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data)
# render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name})
#end
end
end
def self.send_status_to_ordering(url,ref_no,status)
def self.send_status_to_ordering(url,ref_no,status,waiting_time=nil)
base_url = 'https://api.doemal.com'
token = '3T-tnlYtFJ-5Z1vY6XQqxQ'
order_reservation = Lookup.collection_of("order_reservation")
@@ -240,10 +156,15 @@ class OrderReservation < ApplicationRecord
Rails.logger.debug "Doemal URL" + base_url
post_url = base_url + url
if !waiting_time.nil?
send_params = {id: ref_no, waiting_time: waiting_time, status: status}
else
send_params = {id: ref_no, status: status}
end
begin
response = HTTParty.post(post_url,
:body => { id: ref_no, status: status}.to_json,
:body => send_params.to_json,
:headers => {
'Authorization' => 'Token token='+token,
'Content-Type' => 'application/json',
@@ -263,15 +184,29 @@ class OrderReservation < ApplicationRecord
return response
end
def self.update_order_reservation(id, sale_id, status)
def self.update_order_reservation(id, sale_id, status, expected_waiting_time=nil)
order_reservation = OrderReservation.find(id)
if sale_id.present?
order_reservation.sale_id = sale_id
end
if !expected_waiting_time.nil?
order_reservation.expected_waiting_time = DateTime.parse(expected_waiting_time).utc
end
order_reservation.status = status
order_reservation.save
end
def self.get_count_on_order
order_reservation = OrderReservation.select("COUNT(order_reservation_id) as count, status").group("status")
end
def self.get_pending_orders
order_reservation = OrderReservation.select("order_reservations.*,deliveries.provider,deliveries.delivery_type")
.joins(" JOIN deliveries as del on del.order_reservation_id=order_reservations.order_reservation_id")
.where("order_reservations.status='new'")
.order("order_reservations.order_reservation_id desc, order_reservations.created_at desc")
end
private
def generate_custom_id
self.order_reservation_id = SeedGenerator.generate_id(self.class.name, "ODRS")

View File

@@ -23,6 +23,7 @@ class SalePayment < ApplicationRecord
if (amount_due >= 0)
payment_status = false
membership_data = nil
#route to payment type
case payment_method
when "cash"
@@ -52,11 +53,11 @@ class SalePayment < ApplicationRecord
when "foc"
payment_status = foc_payment
when "paymal"
payment_status = paymal_payment
payment_status,membership_data = paymal_payment
when "JunctionPay"
payment_status = junction_pay_payment
when "dinga"
payment_status = dinga_payment
payment_status,membership_data = dinga_payment
else
puts "it was something else"
end
@@ -73,7 +74,7 @@ class SalePayment < ApplicationRecord
end
end
return true, self.save
return true, self.save,membership_data
else
#record an payment in sale-audit
# remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
@@ -430,7 +431,7 @@ class SalePayment < ApplicationRecord
sale_update_payment_status(0)
end
return payment_status
return payment_status,membership_data
end
def junction_pay_payment
@@ -480,7 +481,7 @@ class SalePayment < ApplicationRecord
sale_update_payment_status(0)
end
return payment_status
return payment_status,membership_data
end