Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
Aung Myo
2017-10-23 14:44:29 +06:30
5 changed files with 108 additions and 55 deletions

View File

@@ -65,7 +65,7 @@ class HomeController < ApplicationController
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
@top_products = Sale.top_products(today)
@hourly_sales = Sale.hourly_sales(today)
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total)
@employee_sales = Sale.employee_sales(today).sum(:grand_total)

View File

@@ -21,43 +21,78 @@ class OrderQueueStation < ApplicationRecord
booking = Booking.find_by_dining_facility_id(dining.id)
#Assign OQS id to order Items
oqs_stations.each do |oqs|
is_auto_printed = false
oqs_order_items = []
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
# oqs_stations.each do |oqs|
# is_auto_printed = false
# oqs_order_items = []
# #Get List of 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)
# 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)
# else
# #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)
# # 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)
# # else
if (order_item.price != 0)
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
oqs_order_items.push(order_item)
end
# end
end
end
end
# Auto Printing
# if (order_item.price != 0)
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# oqs_order_items.push(order_item)
# end
# # end
# end
# end
# end
# ToDo per item per printer
OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}").find_each do |oqpbz|
if oqs.id == oqpbz.order_queue_station_id
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
is_auto_printed = false
oqs_order_items = []
if oqs.is_active
#Get List of 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)
# 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)
# else
if (order_item.price != 0)
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
oqs_order_items.push(order_item)
end
# end
end
end
end
if oqs.auto_print
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
end
end
end
end
# if oqs.id == oqpbz.order_queue_station_id
# # Auto Printing
# if oqs.auto_print
# if oqs_order_items.length > 0
# print_slip(oqs, order, oqs_order_items)
# is_auto_printed = true
# end
# end
# end
end
end
# end
end
private

View File

@@ -854,7 +854,9 @@ end
end
def self.hourly_sales(today)
query= Sale.select("grand_total").where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
query= Sale.select("grand_total")
.where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
.group("date_format(receipt_date, '%I %p')")
end
def self.employee_sales(today)

View File

@@ -2,6 +2,7 @@ class SeedGenerator < ApplicationRecord
# Generate ID for Tables
def self.generate_id(model, prefix)
seed = SeedGenerator.find_by_model(model)
next_no = seed.next
new_receipt_no = 0
if (seed.nil?)
@@ -9,38 +10,33 @@ class SeedGenerator < ApplicationRecord
seed.model = model
new_receipt_no = seed.next
seed.save
else
current_no = seed.next
seed.next = seed.next + seed.increase_by
seed.current = current_no
seed.save
# current_no = seed.next
# seed.next = seed.next + seed.increase_by
# seed.current = current_no
# seed.save
cur_val, next_val = self.update_seed(model, seed.next, seed.increase_by)
if next_no == cur_val
puts "SSS"
puts next_val
cur_val2, next_val2 = self.update_seed(model, next_val, seed.increase_by)
puts next_val2
padding_len = 15 - prefix.length
saleOrderId = prefix +"-"+ cur_val2.to_s.to_s.rjust((14-prefix.length)+1,'0')
puts saleOrderId
return saleOrderId
end
padding_len = 15 - prefix.length
saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0')
return saleOrderId
end
padding_len = 15 - prefix.length
saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
return saleOrderId
end
# Generate Receipt No
def self.new_receipt_no
seed = SeedGenerator.find_by_model("sale")
new_receipt_no = 0
if (seed.nil?)
seed = SeedGenerator.new()
seed.model = "sale"
new_receipt_no = seed.next
seed.save
else
current_no = seed.next
seed.next = seed.next
seed.current = current_no
seed.save
end
return seed.current
end
# Generate for 4 digit Code
@@ -71,4 +67,24 @@ class SeedGenerator < ApplicationRecord
next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
return next_code
end
def self.update_seed(model, current, inc)
cur_val = 0
next_val = 0
nex = current + inc
update_sql = "update seed_generators set current= #{current}, next= #{nex} where model='#{model}';";
select_sql = "select * from seed_generators where model='#{model}';"
update_result = ActiveRecord::Base.connection.execute(update_sql);
select_result = ActiveRecord::Base.connection.execute(select_sql);
select_result.each do |row|
p row
cur_val = row [3]
next_val = row[4]
end
return cur_val, next_val
end
end