Conflict fix din settings_backend

This commit is contained in:
Phyo
2017-06-19 15:24:15 +06:30
46 changed files with 634 additions and 288 deletions

View File

@@ -9,28 +9,8 @@ class Customer < ApplicationRecord
validates_presence_of :name, :contact_no, :email
validates :contact_no, uniqueness: true
validates :email, uniqueness: true
paginates_per 50
# def self.get_member_group
# membership = MembershipSetting.find_by_membership_type("paypar_url")
# memberaction = MembershipAction.find_by_membership_type("get_all_member_group")
# app_token = membership.auth_token.to_s
# url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# response = HTTParty.get(url,
# :body => { app_token: app_token}.to_json,
# :headers => {
# 'Content-Type' => 'application/json',
# 'Accept' => 'application/json'
# }
# )
# puts response.body, response.code, response.message, response.headers.inspect
# return response;
# end
paginates_per 50
def self.get_member_account(customer)
membership = MembershipSetting.find_by_membership_type("paypar_url")
@@ -38,13 +18,19 @@ class Customer < ApplicationRecord
merchant_uid = memberaction.merchant_account_id.to_s
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# urltest =self.url_exist?(url)
begin
response = HTTParty.get(url, :body => { membership_id: customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
},
:timeout => 10
)
rescue Net::OpenTimeout
response = { status: false }
end
return response;
@@ -59,6 +45,35 @@ class Customer < ApplicationRecord
end
end
# require "net/http"
# def self.url_exist?(url_string)
# url = URI.parse(url_string)
# req = Net::HTTP.new(url.host, url.port)
# puts "hhhhhhhhhhhh"
# puts req.to_json
# req.use_ssl = (url.scheme == 'https')
# puts "aaaaaaaaaaaa"
# puts req.use_ssl?
# path = url.path if url.path.present?
# puts "bbbbbbbbbbbbb"
# puts path
# res = req.request_head(path || '/')
# puts "cccccccccccccc"
# puts res.to_json
# puts "ddddddddd"
# puts res.kind_of?(Net::HTTPRedirection)
# if res.kind_of?(Net::HTTPRedirection)
# url_exist?(res['location']) # Go after any redirect and make sure you can access the redirected URL
# else
# ! %W(4 5).include?(res.code[0]) # Not from 4xx or 5xx families
# end
# rescue Errno::ENOENT
# false #false if can't find the server
# end
# def self.search(search)
# where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",)
# end

View File

@@ -9,8 +9,24 @@ class DiningFacility < ApplicationRecord
scope :active, -> {where(is_active: true)}
def get_current_booking
puts "enter booking"
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
puts "enter booking"
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
if booking.count > 0 then
return booking[0].booking_id
else
return nil
end
end
def get_new_booking
# query for new
# if status
# to ask when req bill booking_status?
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1)
# else
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1)
# end
if booking.count > 0 then
return booking[0].booking_id

View File

@@ -1,7 +1,9 @@
class DiningQueue < ApplicationRecord
belongs_to :dining_facility, :optional => true
def self.generate_queue_no
queue_no = DiningQueue.all.count + 1
today = DateTime.now.strftime('%Y-%m-%d')
dining_queues = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? ", today).order("queue_no desc")
queue_no = dining_queues.count + 1
return queue_no
end
end
end

View File

@@ -199,7 +199,7 @@ class Order < ApplicationRecord
#Process order items and send to order queue
def process_order_queue
#Send to background job for processing
OrderQueueProcessorJob.perform_later(self.id)
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
end
@@ -231,7 +231,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id")
.where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true)
.group("bookings.booking_id")
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id")
# For PG
# booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true
# sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id
@@ -246,7 +246,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id")
.where("sales.sale_status='completed'")
.group("sales.sale_id,bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id")
.group("sales.sale_id")
# For PG
#bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id
end
@@ -262,7 +262,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id")
.where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true)
.group("bookings.booking_id")
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id")
# For PG
# booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true
# sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id

View File

@@ -10,26 +10,29 @@ class OrderQueueStation < ApplicationRecord
scope :active, -> {where(is_active: true)}
def process_order (order)
def process_order (order, table_id)
oqs_stations = OrderQueueStation.active
dining=DiningFacility.find(table_id)
oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id)
order_items = order.order_items
#Assign OQS id to order Items
oqs_stations.each do |oqs|
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
#Same Order_items can appear in two location.
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
if oqs.id == oqpbz.order_queue_station_id
#Same Order_items can appear in two location.
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
end
end
end
end
end
end
#Print OQS where printing is require

View File

@@ -1,25 +1,44 @@
class Printer::OrderQueuePrinter < Printer::PrinterWorker
def print_order_item(printer_name,order_id, item_code)
def print_order_item(oqs,order_id, item_code)
#Use CUPS service
#Generate PDF
#Print
order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code)
pdf = OrderItemPdf.new(order_item[0])
pdf.render_file "tmp/receipt.pdf"
self.print("tmp/receipt.pdf", printer_name)
if oqs.print_copy
self.print("tmp/receipt.pdf", oqs.printer_name)
self.print("tmp/receipt.pdf", oqs.printer_name)
else
self.print("tmp/receipt.pdf", oqs.printer_name)
end
end
def print_order_summary(printer_name,order_id)
def print_order_summary(oqs,order_id)
#Use CUPS service
#Generate PDF
#Print
order=print_query('order_summary',order_id)
filename = "tmp/order_summary_#{order_id}" + ".pdf"
pdf = OrderSummaryPdf.new(order)
pdf.render_file filename
self.print(filename, printer_name)
# For Print Per Item
if oqs.cut_per_item
order.each do|odi|
pdf = OrderItemPdf.new(odi)
pdf.render_file "tmp/receipt.pdf"
if oqs.print_copy
self.print("tmp/receipt.pdf", oqs.printer_name)
self.print("tmp/receipt.pdf", oqs.printer_name)
else
self.print("tmp/receipt.pdf", oqs.printer_name)
end
end
# For Print Order Summary
else
filename = "tmp/order_summary_#{order_id}" + ".pdf"
pdf = OrderSummaryPdf.new(order)
pdf.render_file filename
self.print(filename, oqs.printer_name)
end
end
# Query for OQS with status

View File

@@ -52,7 +52,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
self.print(filename)
end
def print_receipt_payment_by_foc(sale_id)
#Use CUPS service
#Generate PDF
@@ -70,6 +70,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Generate PDF
#Print
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info)
pdf.render_file "tmp/receipt_bill.pdf"
self.print("tmp/receipt_bill.pdf")
end

View File

@@ -23,6 +23,8 @@ class Sale < ApplicationRecord
if (booking)
Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s
#get all order attached to this booking and combine into 1 invoice
puts booking.booking_orders.length
booking.booking_orders.each do |order|
if booking.sale_id
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by)
@@ -199,7 +201,7 @@ class Sale < ApplicationRecord
#tax_profile - list by order_by
tax_profiles = TaxProfile.all.order("order_by asc")
#Creat new tax records
# #Creat new tax records
tax_profiles.each do |tax|
sale_tax = SaleTax.new(:sale => self)
sale_tax.tax_name = tax.name

View File

@@ -30,6 +30,7 @@ class SaleItem < ApplicationRecord
# end
end
# Calculate food total and beverage total
def self.calculate_food_beverage(sale_items)
food_prices=0
beverage_prices=0
@@ -45,6 +46,7 @@ class SaleItem < ApplicationRecord
return food_prices, beverage_prices
end
# get food price or beverage price for item
def self.get_price(sale_item_id)
food_price=0
beverage_price=0

View File

@@ -265,13 +265,17 @@ class SalePayment < ApplicationRecord
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
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id,
begin
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id,
receipt_no: receipt_no,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
})
puts "haha"
}, :timeout => 10)
rescue Net::OpenTimeout
response = { status: false }
end
puts response.to_json
end
end