test
This commit is contained in:
@@ -3,7 +3,7 @@ class Employee < ApplicationRecord
|
||||
has_many :commissioners
|
||||
has_many :shit_sales
|
||||
belongs_to :order_queue_station
|
||||
|
||||
belongs_to :shop
|
||||
validates_presence_of :name, :role
|
||||
validates_presence_of :password, :on => [:create]
|
||||
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
|
||||
@@ -20,9 +20,9 @@ class Employee < ApplicationRecord
|
||||
Employee.select("id, name").map { |e| [e.name, e.id] }
|
||||
end
|
||||
|
||||
def self.login(emp_id, password)
|
||||
user = Employee.find_by_emp_id(emp_id)
|
||||
expiry_time = login_expiry_time
|
||||
def self.login(shop,emp_id, password)
|
||||
user = shop.employees.find_by_emp_id(emp_id)
|
||||
expiry_time = login_expiry_time(shop)
|
||||
if (user)
|
||||
#user.authenticate(password)
|
||||
if (user.authenticate(password))
|
||||
@@ -37,10 +37,10 @@ class Employee < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
def self.authenticate_by_token(session_token)
|
||||
def self.authenticate_by_token(session_token,shop)
|
||||
if (session_token)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
expiry_time = login_expiry_time
|
||||
user = shop.employees.find_by_token_session(session_token)
|
||||
expiry_time = login_expiry_time(shop)
|
||||
|
||||
if user && user.session_expiry.utc > DateTime.now.utc
|
||||
#Extend the login time each time authenticatation take place
|
||||
@@ -55,9 +55,9 @@ class Employee < ApplicationRecord
|
||||
return false
|
||||
end
|
||||
|
||||
def self.logout(session_token)
|
||||
def self.logout(shop,session_token)
|
||||
if (session_token)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
user = shop.employees.find_by_token_session(session_token)
|
||||
|
||||
if user
|
||||
user.token_session = nil
|
||||
@@ -73,9 +73,9 @@ class Employee < ApplicationRecord
|
||||
retry
|
||||
end
|
||||
|
||||
def self.login_expiry_time
|
||||
def self.login_expiry_time(shop)
|
||||
expiry_time = 30
|
||||
login_expiry = Lookup.collection_of('expiry_time')
|
||||
login_expiry = shop.lookups.collection_of('expiry_time')
|
||||
if !login_expiry.empty?
|
||||
login_expiry.each do |exp_time|
|
||||
if exp_time[0].downcase == "login"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Lookup < ApplicationRecord
|
||||
|
||||
has_many :accounts
|
||||
belongs_to :shop
|
||||
|
||||
def available_types
|
||||
{'Employee Roles' => 'employee_roles',
|
||||
|
||||
@@ -30,13 +30,13 @@ class Menu < ApplicationRecord
|
||||
cats = MenuCategory.where("menu_id=?",menu.id)
|
||||
cats.each do |cat|
|
||||
abc = MenuCategory.destroyCategory(cat)
|
||||
end
|
||||
end
|
||||
menu.destroy
|
||||
return false
|
||||
end
|
||||
|
||||
def self.to_csv
|
||||
m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
|
||||
m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
|
||||
CSV.generate(headers: true, row_sep: "\r\n") do |csv|
|
||||
csv << m_attributes
|
||||
menu = Menu.all
|
||||
@@ -46,8 +46,8 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.import(file, created_by)
|
||||
status = ""
|
||||
def self.import(file, created_by)
|
||||
status = ""
|
||||
spreadsheet = open_spreadsheet(file)
|
||||
if spreadsheet.sheets.count > 1
|
||||
sheet_count = spreadsheet.sheets.count-1
|
||||
@@ -59,7 +59,7 @@ class Menu < ApplicationRecord
|
||||
row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose]
|
||||
if sheet_name == "Account"
|
||||
# Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
|
||||
account = Account.find_by_id(row["id"])
|
||||
account = Account.find_by_id(row["id"])
|
||||
if account
|
||||
Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
|
||||
else
|
||||
@@ -67,7 +67,7 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
elsif sheet_name == "Item Set"
|
||||
# ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
|
||||
item_set = ItemSet.find_by_id(row["id"])
|
||||
item_set = ItemSet.find_by_id(row["id"])
|
||||
if item_set
|
||||
ItemSet.create( name: row["name"], alt_name: row["alt_name"], min_selectable_qty: row["min_selectable_qty"], max_selectable_qty: row["max_selectable_qty"])
|
||||
else
|
||||
@@ -128,7 +128,7 @@ class Menu < ApplicationRecord
|
||||
else
|
||||
MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
|
||||
end
|
||||
elsif sheet_name == "Menu Item Set"
|
||||
elsif sheet_name == "Menu Item Set"
|
||||
# MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
|
||||
menu_item_set = MenuItemSet.find_by_id(row["id"])
|
||||
if menu_item_set
|
||||
@@ -149,24 +149,24 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
sheet = spreadsheet.sheet(0)
|
||||
sheet = spreadsheet.sheet(0)
|
||||
menu = sheet.row(1)[1]
|
||||
is_ordering = sheet.row(1)[3]?sheet.row(1)[3]:0
|
||||
|
||||
imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by})
|
||||
imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by})
|
||||
|
||||
(4..sheet.last_row).each do |ii|
|
||||
row = Hash[[sheet.row(3),sheet.row(ii)].transpose]
|
||||
menu_cat = MenuCategory.find_by_code(row["Category Code"])
|
||||
(4..sheet.last_row).each do |ii|
|
||||
row = Hash[[sheet.row(3),sheet.row(ii)].transpose]
|
||||
menu_cat = MenuCategory.find_by_code(row["Category Code"])
|
||||
if !menu_cat
|
||||
menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1})
|
||||
menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1})
|
||||
end
|
||||
|
||||
# Menu Item Attributes
|
||||
item_attrs = []
|
||||
if !row["Attributes"].nil?
|
||||
attributes = row["Attributes"].split(',')
|
||||
attributes.each do |attr|
|
||||
attributes.each do |attr|
|
||||
attribute = MenuItemAttribute.find_by_name(attr)
|
||||
if attribute.nil?
|
||||
attribute = MenuItemAttribute.create({ attribute_type:"any", name: attr.capitalize, value: attr.downcase })
|
||||
@@ -188,7 +188,7 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
menu_itm = MenuItem.find_by_item_code(row["Item Code"])
|
||||
menu_itm = MenuItem.find_by_item_code(row["Item Code"])
|
||||
if !menu_itm
|
||||
account = Account.find_by_title(row["Account"])
|
||||
if account.nil?
|
||||
@@ -205,22 +205,22 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
|
||||
instance_attr = []
|
||||
menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"])
|
||||
menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"])
|
||||
if !menu_inst
|
||||
instance_name = ''
|
||||
if !row["Instance Name"].nil?
|
||||
if !row["Instance Name"].nil?
|
||||
instance_name = row["Instance Name"]
|
||||
end
|
||||
|
||||
if !row["Attributes"].nil?
|
||||
if !row["Instance Attribute"].nil?
|
||||
if !row["Instance Attribute"].nil?
|
||||
attributes = row["Attributes"].split(',')
|
||||
instance_attributes = row["Instance Attribute"].split(',')
|
||||
attributes.each do |attr|
|
||||
attributes.each do |attr|
|
||||
if attr == instance_attributes[0]
|
||||
ins_attr = MenuItemAttribute.find_by_name(attr)
|
||||
instance_attr.push(ins_attr.id)
|
||||
end
|
||||
instance_attr.push(ins_attr.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -231,7 +231,7 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
imported_instance = MenuItemInstance.create(menu_item_id: menu_itm.id, item_instance_code: row["Instance Code"], item_instance_name: instance_name, item_attributes: instance_attr, price: row["Price"], is_on_promotion: false, promotion_price: 0, is_available: true, is_default: is_default)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# if status == ''
|
||||
status="Menu Imported!"
|
||||
@@ -249,4 +249,4 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
class OrderQueueStation < ApplicationRecord
|
||||
has_many :assigned_order_items
|
||||
has_many :order_items
|
||||
has_many :order_queue_process_by_zones
|
||||
has_many :order_queue_process_by_zones
|
||||
has_many :zones, through: :order_queue_process_by_zones
|
||||
belongs_to :employee
|
||||
|
||||
@@ -17,21 +17,21 @@ class OrderQueueStation < ApplicationRecord
|
||||
def process_order (order, table_id, order_source = nil, pdf_status = nil ,change_to=nil,current_user=nil)
|
||||
|
||||
oqs_stations = OrderQueueStation.active
|
||||
|
||||
|
||||
|
||||
order_items = order.order_items
|
||||
|
||||
if table_id.to_i > 0
|
||||
# get dining
|
||||
dining = DiningFacility.find(table_id)
|
||||
# get dining
|
||||
dining = DiningFacility.find(table_id)
|
||||
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}")
|
||||
booking = Booking.find_by_dining_facility_id(dining.id)
|
||||
|
||||
|
||||
# ToDo per item per printer
|
||||
|
||||
oqs_by_zones.each do |oqpbz|
|
||||
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
|
||||
is_auto_printed = false
|
||||
is_auto_printed = false
|
||||
oqs_order_items = []
|
||||
|
||||
if oqs.is_active
|
||||
@@ -44,22 +44,22 @@ class OrderQueueStation < ApplicationRecord
|
||||
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)
|
||||
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
||||
# else
|
||||
|
||||
|
||||
if (order_item.qty > 0)
|
||||
if pdf_status.nil?
|
||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
|
||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
|
||||
end
|
||||
oqs_order_items.push(order_item)
|
||||
end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if oqs.auto_print && order_source != "quick_service"
|
||||
if oqs_order_items.length > 0
|
||||
if oqs_order_items.length > 0
|
||||
if oqs.cut_per_item
|
||||
print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
|
||||
else
|
||||
@@ -67,12 +67,12 @@ class OrderQueueStation < ApplicationRecord
|
||||
end
|
||||
is_auto_printed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
oqs_stations.each do |oqs|
|
||||
is_auto_printed = false
|
||||
is_auto_printed = false
|
||||
oqs_order_items = []
|
||||
|
||||
if oqs.is_active
|
||||
@@ -85,39 +85,39 @@ class OrderQueueStation < ApplicationRecord
|
||||
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)
|
||||
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
||||
# else
|
||||
|
||||
|
||||
if (order_item.qty > 0)
|
||||
if pdf_status.nil?
|
||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
|
||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
|
||||
end
|
||||
oqs_order_items.push(order_item)
|
||||
end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if oqs.auto_print && order_source != "quick_service"
|
||||
if oqs_order_items.length > 0
|
||||
if oqs_order_items.length > 0
|
||||
if oqs.cut_per_item
|
||||
print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
|
||||
else
|
||||
else
|
||||
print_slip(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
|
||||
end
|
||||
is_auto_printed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end #end else
|
||||
end #end else
|
||||
end
|
||||
|
||||
def pay_process_order_queue (order_id, table_id)
|
||||
def pay_process_order_queue (order_id, table_id)
|
||||
|
||||
oqs_stations = OrderQueueStation.active
|
||||
|
||||
|
||||
order = Order.find(order_id)
|
||||
order_items = order.order_items
|
||||
|
||||
@@ -129,22 +129,22 @@ class OrderQueueStation < ApplicationRecord
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
# if ENV["SERVER_MODE"] == 'cloud'
|
||||
# from = request.subdomain + "." + request.domain
|
||||
# else
|
||||
# else
|
||||
# from = ""
|
||||
# end
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
||||
|
||||
if table_id.to_i > 0
|
||||
# get dining
|
||||
dining = DiningFacility.find(table_id)
|
||||
# get dining
|
||||
dining = DiningFacility.find(table_id)
|
||||
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}")
|
||||
booking = Booking.find_by_dining_facility_id(dining.id)
|
||||
|
||||
booking = Booking.find_by_dining_facility_id(dining.id)
|
||||
|
||||
# ToDo per item per printer
|
||||
|
||||
oqs_by_zones.each do |oqpbz|
|
||||
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
|
||||
is_auto_printed = false
|
||||
is_auto_printed = false
|
||||
oqs_order_items = []
|
||||
|
||||
if oqs.is_active
|
||||
@@ -157,26 +157,26 @@ class OrderQueueStation < ApplicationRecord
|
||||
if (pq_item == order_item.item_code)
|
||||
if (order_item.qty > 0)
|
||||
oqs_order_items.push(order_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if oqs.auto_print
|
||||
if oqs_order_items.length > 0
|
||||
if oqs_order_items.length > 0
|
||||
if oqs.cut_per_item
|
||||
print_slip_item(oqs, order, oqs_order_items)
|
||||
else
|
||||
else
|
||||
print_slip(oqs, order, oqs_order_items)
|
||||
end
|
||||
is_auto_printed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
oqs_stations.each do |oqs|
|
||||
is_auto_printed = false
|
||||
is_auto_printed = false
|
||||
oqs_order_items = []
|
||||
|
||||
if oqs.is_active
|
||||
@@ -186,27 +186,27 @@ class OrderQueueStation < ApplicationRecord
|
||||
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 (pq_item == order_item.item_code)
|
||||
if (order_item.qty > 0)
|
||||
oqs_order_items.push(order_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if oqs.auto_print
|
||||
if oqs_order_items.length > 0
|
||||
if oqs_order_items.length > 0
|
||||
if oqs.cut_per_item
|
||||
print_slip_item(oqs, order, oqs_order_items)
|
||||
else
|
||||
else
|
||||
print_slip(oqs, order, oqs_order_items)
|
||||
end
|
||||
is_auto_printed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end #end else
|
||||
end #end else
|
||||
end
|
||||
|
||||
private
|
||||
@@ -217,8 +217,8 @@ class OrderQueueStation < ApplicationRecord
|
||||
unique_code="OrderSummaryPdf"
|
||||
|
||||
if !printer.empty?
|
||||
printer.each do |printer_setting|
|
||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
||||
printer.each do |printer_setting|
|
||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
||||
unique_code="OrderSummaryPdf"
|
||||
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
|
||||
unique_code="OrderSummarySlimPdf"
|
||||
@@ -227,12 +227,12 @@ class OrderQueueStation < ApplicationRecord
|
||||
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
|
||||
unique_code="OrderSummaryCustomisePdf"
|
||||
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
|
||||
unique_code="OrderSummarySetCustomisePdf"
|
||||
unique_code="OrderSummarySetCustomisePdf"
|
||||
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
|
||||
unique_code="OrderSummarySlimCustomisePdf"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
||||
@@ -240,21 +240,21 @@ class OrderQueueStation < ApplicationRecord
|
||||
else
|
||||
move_print_pdf(change_to,current_user,table_id,order_items,oqs)
|
||||
end
|
||||
|
||||
|
||||
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
|
||||
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
|
||||
end
|
||||
|
||||
#Print order_item in 1 slip per item
|
||||
def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
||||
|
||||
|
||||
if pdf_status.nil?
|
||||
printer = PrintSetting.all.order("id ASC")
|
||||
unique_code="OrderItemPdf"
|
||||
|
||||
if !printer.empty?
|
||||
printer.each do |printer_setting|
|
||||
if printer_setting.unique_code == 'OrderItemPdf'
|
||||
if printer_setting.unique_code == 'OrderItemPdf'
|
||||
unique_code="OrderItemPdf"
|
||||
elsif printer_setting.unique_code == 'OrderItemStarPdf'
|
||||
unique_code="OrderItemStarPdf"
|
||||
@@ -265,15 +265,15 @@ class OrderQueueStation < ApplicationRecord
|
||||
elsif printer_setting.unique_code == 'OrderItemCustomisePdf'
|
||||
unique_code="OrderItemCustomisePdf"
|
||||
elsif printer_setting.unique_code == 'OrderSetItemCustomisePdf'
|
||||
unique_code="OrderSetItemCustomisePdf"
|
||||
unique_code="OrderSetItemCustomisePdf"
|
||||
elsif printer_setting.unique_code == 'OrderItemSlimCustomisePdf'
|
||||
unique_code="OrderItemSlimCustomisePdf"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
|
||||
# print when complete click
|
||||
# print when complete click
|
||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
||||
if !assigned_items.nil?
|
||||
@@ -284,7 +284,7 @@ class OrderQueueStation < ApplicationRecord
|
||||
else
|
||||
move_print_pdf(change_to,current_user,table_id,assigned_items,oqs)
|
||||
end
|
||||
|
||||
|
||||
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
|
||||
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
|
||||
end
|
||||
@@ -298,7 +298,7 @@ class OrderQueueStation < ApplicationRecord
|
||||
@moved_by = current_user
|
||||
@date = DateTime.now
|
||||
@shop = Shop.first
|
||||
unique_code = "MoveTablePdf"
|
||||
unique_code = "MoveTablePdf"
|
||||
# pdf_no = PrintSetting.where(:unique_code => unique_code).count
|
||||
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
||||
# printer_array = []
|
||||
@@ -307,10 +307,10 @@ class OrderQueueStation < ApplicationRecord
|
||||
# for i in 0..pdf_no
|
||||
# if i != pdf_no
|
||||
# print_settings = printer_array[i]
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by,order_items,oqs)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ class Sale < ApplicationRecord
|
||||
belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee"
|
||||
belongs_to :customer, :optional => true
|
||||
belongs_to :shift_sale
|
||||
belongs_to :shop
|
||||
has_many :sale_items
|
||||
has_many :sale_discount_items
|
||||
has_many :sale_discounts
|
||||
@@ -1502,10 +1503,10 @@ end
|
||||
return tax
|
||||
end
|
||||
|
||||
def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type)
|
||||
def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type,shop)
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
if current_user.nil?
|
||||
query = Sale.top_bottom(today,nil,from,to,from_time,to_time)
|
||||
query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time)
|
||||
|
||||
if type == "top"
|
||||
query = query.group('i.product_name')
|
||||
@@ -1516,7 +1517,7 @@ end
|
||||
end
|
||||
else
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
||||
query = Sale.top_bottom(today,nil,from,to,from_time,to_time)
|
||||
query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time)
|
||||
if type == "top"
|
||||
query = query.group('i.product_name')
|
||||
.order("SUM(i.qty) DESC").limit(20)
|
||||
@@ -1525,9 +1526,9 @@ end
|
||||
.order("SUM(i.qty) ASC").limit(20)
|
||||
end
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
if !shift.nil?
|
||||
query = Sale.top_bottom(today,shift,from,to,from_time,to_time)
|
||||
query = Sale.top_bottom(shop,today,shift,from,to,from_time,to_time)
|
||||
if type == "top"
|
||||
query = query.group('i.product_name')
|
||||
.order("SUM(i.qty) DESC").limit(20)
|
||||
@@ -1540,7 +1541,7 @@ end
|
||||
end
|
||||
else
|
||||
if current_user.nil?
|
||||
query = Sale.top_bottom(today).group('i.product_name')
|
||||
query = Sale.top_bottom(shop,today).group('i.product_name')
|
||||
|
||||
if type == "top"
|
||||
query = query.order("SUM(i.qty) DESC").limit(20)
|
||||
@@ -1549,16 +1550,16 @@ end
|
||||
end
|
||||
else
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
||||
query = Sale.top_bottom(today).group('i.product_name')
|
||||
query = Sale.top_bottom(shop,today).group('i.product_name')
|
||||
if type == "top"
|
||||
query = query.order("SUM(i.qty) DESC").limit(20)
|
||||
elsif type == "bottom"
|
||||
query = query.order("SUM(i.qty) ASC").limit(20)
|
||||
end
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
if !shift.nil?
|
||||
query = Sale.top_bottom(today,shift).group('i.product_name')
|
||||
query = Sale.top_bottom(shop,today,shift).group('i.product_name')
|
||||
if type == "top"
|
||||
query = query.order("SUM(i.qty) DESC").limit(20)
|
||||
elsif type == "bottom"
|
||||
@@ -1570,52 +1571,52 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
def self.hourly_sales(today,current_user,from,to,from_time,to_time)
|
||||
def self.hourly_sales(today,current_user,from,to,from_time,to_time,shop)
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
if current_user.nil?
|
||||
query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time)
|
||||
query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time)
|
||||
else
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
||||
query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time)
|
||||
query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time)
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
if !shift.nil?
|
||||
query = Sale.hourly_sale_data(today,shift,from,to,from_time,to_time)
|
||||
query = Sale.hourly_sale_data(shop,today,shift,from,to,from_time,to_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if current_user.nil?
|
||||
query = Sale.hourly_sale_data(today)
|
||||
query = Sale.hourly_sale_data(shop,today)
|
||||
else
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
||||
query = Sale.hourly_sale_data(today)
|
||||
query = Sale.hourly_sale_data(shop,today)
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
if !shift.nil?
|
||||
query = Sale.hourly_sale_data(today,shift)
|
||||
query = Sale.hourly_sale_data(shop,today,shift)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.employee_sales(today,current_user,from,to,from_time,to_time)
|
||||
def self.employee_sales(today,current_user,from,to,from_time,to_time,shop)
|
||||
shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
ShiftSale.current_open_shift(current_user.id)
|
||||
ShiftSale.current_open_shift(current_user.id,shop)
|
||||
end
|
||||
|
||||
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
|
||||
|
||||
query = employee_sale(today, shift, from, to, from_time, to_time)
|
||||
query = employee_sale(shop,today, shift, from, to, from_time, to_time)
|
||||
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
|
||||
.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount,
|
||||
CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card'
|
||||
ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name")
|
||||
end
|
||||
|
||||
def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count")
|
||||
def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
|
||||
query = shop.sales.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count")
|
||||
.where('sale_status = "completed"')
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
|
||||
@@ -1627,15 +1628,15 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
return query
|
||||
end
|
||||
|
||||
def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||
def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
|
||||
query = shop.sales.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||
.where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")')
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
@@ -1646,20 +1647,20 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
query = query.sum("sp.payment_amount")
|
||||
end
|
||||
|
||||
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
|
||||
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
|
||||
|
||||
query = SalePayment.credits
|
||||
.joins(:sale)
|
||||
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sale_payments.sale_id")
|
||||
.where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed')
|
||||
.where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',shop.shop_code)
|
||||
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.merge(Sale.date_between(from, to))
|
||||
@@ -1670,7 +1671,7 @@ end
|
||||
query = query.merge(Sale.date_on(today))
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1678,8 +1679,8 @@ end
|
||||
return query.sum("sale_payments.payment_amount - IFNULL(payments_for_credits.payment_amount, 0)")
|
||||
end
|
||||
|
||||
def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||
def self.summary_sale_receipt(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||
.where('sale_status = "completed"')
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
@@ -1690,15 +1691,15 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
query = query.first()
|
||||
end
|
||||
|
||||
def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("distinct sp.payment_method")
|
||||
def self.total_payment_methods(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select("distinct sp.payment_method")
|
||||
.where('sales.sale_status = "completed"')
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
@@ -1710,17 +1711,17 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
return query
|
||||
end
|
||||
|
||||
def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.payment_sale(shop,payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
|
||||
|
||||
query = Sale.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount")
|
||||
query = shop.sales.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount")
|
||||
.joins(:sale_payments)
|
||||
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
|
||||
.completed
|
||||
@@ -1741,15 +1742,15 @@ end
|
||||
end
|
||||
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
query.first
|
||||
end
|
||||
|
||||
def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
total_dinein_takeaway = self.total_dinein_takeaway(today,current_user,from,to,from_time,to_time)
|
||||
def self.total_customer(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
total_dinein_takeaway = self.total_dinein_takeaway(shop,today,current_user,from,to,from_time,to_time)
|
||||
dinein_cnt = 0
|
||||
takeaway_cnt = 0
|
||||
if !total_dinein_takeaway.nil?
|
||||
@@ -1758,7 +1759,7 @@ end
|
||||
takeaway_cnt = total_dinein_takeaway[0].total_take_cus
|
||||
end
|
||||
end
|
||||
membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time)
|
||||
membership_cnt = self.total_membership(shop,today,current_user,from,to,from_time,to_time)
|
||||
member_cnt = 0
|
||||
if !membership_cnt.nil?
|
||||
member_cnt = membership_cnt.total_memb_cus
|
||||
@@ -1771,8 +1772,8 @@ end
|
||||
return total_cus, dinein_cnt, takeaway_cnt, member_cnt
|
||||
end
|
||||
|
||||
def self.total_dinein_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus")
|
||||
def self.total_dinein_takeaway(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and c.membership_id is null')
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
@@ -1784,15 +1785,15 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
query = query.first()
|
||||
end
|
||||
|
||||
def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||
def self.total_membership(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))')
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
@@ -1804,7 +1805,7 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1857,8 +1858,8 @@ end
|
||||
# query = query.first()
|
||||
# end
|
||||
|
||||
def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("count(distinct sale_orders.order_id) as total_order")
|
||||
def self.total_order(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select("count(distinct sale_orders.order_id) as total_order")
|
||||
.joins(:sale_orders)
|
||||
.completed
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
@@ -1871,7 +1872,7 @@ end
|
||||
end
|
||||
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1879,8 +1880,8 @@ end
|
||||
query = query.first
|
||||
end
|
||||
|
||||
def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||
def self.total_account(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select("distinct b.id as account_id, b.title as title")
|
||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||
.where('sales.sale_status = "completed"')
|
||||
@@ -1893,15 +1894,15 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
return query
|
||||
end
|
||||
|
||||
def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||
def self.account_data(shop,account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
@@ -1913,15 +1914,15 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
query = query.first
|
||||
end
|
||||
|
||||
def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||
def self.top_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
@@ -1933,7 +1934,7 @@ end
|
||||
query = query.date_on(today)
|
||||
end
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if shift = ShiftSale.current_open_shift(current_user.id,shop)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1942,8 +1943,8 @@ end
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
def self.total_foc_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
@@ -2096,9 +2097,9 @@ def unique_tax_profiles(order_source, customer_id)
|
||||
return tax_data
|
||||
end
|
||||
|
||||
def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.top_bottom(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
if !from.nil? && !to.nil?
|
||||
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||
query = shop.sales.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||
" i.price as unit_price,i.product_name")
|
||||
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -2112,7 +2113,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = query.where("shift_sale_id='#{shift.id}'")
|
||||
end
|
||||
else
|
||||
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||
query = shop.sales.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||
" i.price as unit_price,i.product_name")
|
||||
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
|
||||
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||
@@ -2124,9 +2125,9 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
return query
|
||||
end
|
||||
|
||||
def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.hourly_sale_data(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
if !from.nil? && !to.nil?
|
||||
query = Sale.select("grand_total")
|
||||
query = shop.sales.select("grand_total")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
|
||||
else
|
||||
@@ -2138,7 +2139,7 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=
|
||||
query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
|
||||
.order('receipt_date')
|
||||
else
|
||||
query = Sale.select("grand_total")
|
||||
query = shop.sales.select("grand_total")
|
||||
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||
if !shift.nil?
|
||||
query = query.where("shift_sale_id='#{shift.id}'")
|
||||
@@ -2150,8 +2151,8 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=
|
||||
return query
|
||||
end
|
||||
|
||||
def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.joins(:cashier)
|
||||
def self.employee_sale(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = shop.sales.joins(:cashier)
|
||||
.joins(:sale_payments)
|
||||
.paid.completed
|
||||
if !from.nil? && !to.nil?
|
||||
|
||||
@@ -16,6 +16,7 @@ class ShiftSale < ApplicationRecord
|
||||
belongs_to :cashier_terminal
|
||||
belongs_to :employee, :foreign_key => 'employee_id'
|
||||
has_many :sales
|
||||
belongs_to :shop
|
||||
|
||||
def self.current_shift
|
||||
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||
@@ -23,12 +24,12 @@ class ShiftSale < ApplicationRecord
|
||||
return shift
|
||||
end
|
||||
|
||||
def self.current_open_shift(current_user)
|
||||
def self.current_open_shift(current_user,shop)
|
||||
#if current_user
|
||||
#find open shift where is open today and is not closed and login by current cashier
|
||||
#DATE(shift_started_at)=? and
|
||||
today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take
|
||||
shift = shop.shift_sales.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take
|
||||
return shift
|
||||
#end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,36 @@ class Shop < ApplicationRecord
|
||||
|
||||
# Shop Image Uploader
|
||||
mount_uploader :logo, ShopImageUploader
|
||||
|
||||
has_many :accounts
|
||||
has_many :bookings
|
||||
has_many :cashier_terminals
|
||||
has_many :commissioners
|
||||
has_many :commissions
|
||||
has_many :customers
|
||||
has_many :dining_facilities
|
||||
has_many :dining_queues
|
||||
has_many :employees
|
||||
has_many :inventory_definitions
|
||||
has_many :item_sets
|
||||
has_many :lookups
|
||||
has_many :membership_settings
|
||||
has_many :menus
|
||||
has_many :order_queue_stations
|
||||
has_many :orders
|
||||
has_many :payment_journals
|
||||
has_many :payment_method_settings
|
||||
has_many :print_settings
|
||||
has_many :sales
|
||||
has_many :products
|
||||
has_many :promotions
|
||||
has_many :seed_generators
|
||||
has_many :stock_checks
|
||||
has_many :stock_journals
|
||||
has_many :surveys
|
||||
has_many :tax_profiles
|
||||
has_many :zones
|
||||
has_many :display_images
|
||||
has_many :shift_sales
|
||||
accepts_nested_attributes_for :display_images
|
||||
|
||||
def file_data=(input_data)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class StockJournal < ApplicationRecord
|
||||
|
||||
belongs_to :shop
|
||||
SALES_TRANS = "sale"
|
||||
ORDER_TRANS = "order"
|
||||
STOCK_CHECK_TRANS = "stock_check"
|
||||
@@ -52,9 +52,9 @@ class StockJournal < ApplicationRecord
|
||||
journal.save
|
||||
end
|
||||
|
||||
def self.inventory_balances(today,from,to,from_time,to_time)
|
||||
def self.inventory_balances(today,from,to,from_time,to_time,shop)
|
||||
if !from.nil? && !to.nil?
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
query = shop.stock_journals.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
|
||||
@@ -64,7 +64,7 @@ class StockJournal < ApplicationRecord
|
||||
query = query.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
else
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
query = shop.stock_journals.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
.where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'")
|
||||
.group("mii.item_instance_name")
|
||||
|
||||
Reference in New Issue
Block a user