fixed conflict
This commit is contained in:
@@ -36,17 +36,18 @@ class AssignedOrderItem < ApplicationRecord
|
||||
assigned_order_item.order_queue_station = order_queue_station
|
||||
assigned_order_item.print_status = false
|
||||
assigned_order_item.delivery_status = false
|
||||
assigned_order_item.shop_code =order.shop_code
|
||||
assigned_order_item.save!
|
||||
end
|
||||
|
||||
def self.assigned_order_item_by_job(order_id)
|
||||
order_item = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id,
|
||||
assigned_order_items.order_queue_station_id,
|
||||
oqs.id as station_id, oqs.station_name,
|
||||
oqs.is_active, oqpz.zone_id,
|
||||
df.name as zone, df.type as table_type,
|
||||
odt.order_id, odt.item_code, odt.item_instance_code, odt.item_name,
|
||||
odt.price, odt.qty, odt.item_order_by, odt.options,
|
||||
assigned_order_items.order_queue_station_id,
|
||||
oqs.id as station_id, oqs.station_name,
|
||||
oqs.is_active, oqpz.zone_id,
|
||||
df.name as zone, df.type as table_type,
|
||||
odt.order_id, odt.item_code, odt.item_instance_code, odt.item_name,
|
||||
odt.price, odt.qty, odt.item_order_by, odt.options,
|
||||
cus.name as customer_name, odt.created_at")
|
||||
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
|
||||
left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id
|
||||
|
||||
@@ -127,4 +127,9 @@ class Booking < ApplicationRecord
|
||||
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
|
||||
end
|
||||
end
|
||||
def generate_custom_id
|
||||
if self.booking_id.nil?
|
||||
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,9 +32,8 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_current_booking
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null
|
||||
# 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_by is null").limit(1) #and checkout_at is null
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
|
||||
booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null
|
||||
if booking.count > 0 then
|
||||
return booking[0]
|
||||
else
|
||||
@@ -43,8 +42,8 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_moved_booking
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
|
||||
booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
|
||||
|
||||
if booking.count > 0 then
|
||||
return booking[0]
|
||||
@@ -70,8 +69,8 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_current_checkout_booking
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1)
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
|
||||
booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1)
|
||||
if booking.count > 0 then
|
||||
return booking[0]
|
||||
else
|
||||
@@ -82,7 +81,7 @@ class DiningFacility < ApplicationRecord
|
||||
def get_checkout_booking
|
||||
booking = self.get_current_checkout_booking
|
||||
if booking
|
||||
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
||||
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
|
||||
free_time_min = 0
|
||||
if !lookup_checkout_time.empty?
|
||||
now = Time.now.utc
|
||||
@@ -118,11 +117,11 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.get_checkin_booking
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null")
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
|
||||
bookings = Booking.where("shop_code='#{self.shop_code}' and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null")
|
||||
arr_booking = Array.new
|
||||
if bookings
|
||||
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
||||
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
|
||||
free_time_min = 0
|
||||
if !lookup_checkout_time.empty?
|
||||
now = Time.now.utc
|
||||
|
||||
@@ -3,7 +3,6 @@ class Employee < ApplicationRecord
|
||||
has_many :commissioners
|
||||
has_many :shit_sales
|
||||
belongs_to :order_queue_station
|
||||
|
||||
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 +19,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 = Employee.find_by_emp_id_and_shop_code(emp_id,shop.shop_code)
|
||||
expiry_time = login_expiry_time(shop)
|
||||
if (user)
|
||||
#user.authenticate(password)
|
||||
if (user.authenticate(password))
|
||||
@@ -37,10 +36,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 = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code)
|
||||
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 +54,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 = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code)
|
||||
|
||||
if user
|
||||
user.token_session = nil
|
||||
@@ -73,9 +72,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 = Lookup.where("shop_code='#{shop.shop_code}'").collection_of('expiry_time')
|
||||
if !login_expiry.empty?
|
||||
login_expiry.each do |exp_time|
|
||||
if exp_time[0].downcase == "login"
|
||||
|
||||
@@ -8,7 +8,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
logger.debug saleObj.sale_items.to_json
|
||||
if !saleObj.nil?
|
||||
saleObj.sale_items.each do |item|
|
||||
found, inventory_definition = find_product_in_inventory(item)
|
||||
found, inventory_definition = find_product_in_inventory(item,saleObj.shop_code)
|
||||
if found
|
||||
check_balance(item,inventory_definition)
|
||||
end
|
||||
@@ -23,7 +23,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_product_in_inventory(item,instance_code)
|
||||
def self.find_product_in_inventory(item,shop_code=nil)
|
||||
# unless instance_code.empty?
|
||||
# instance_code = instance_code.to_s
|
||||
# instance_code[0] = ""
|
||||
@@ -36,16 +36,15 @@ class InventoryDefinition < ApplicationRecord
|
||||
# puts "found prodcut+++++++++++++++++++++++++++++++++++==="
|
||||
# puts prod.to_json
|
||||
# end
|
||||
|
||||
if product = InventoryDefinition.find_by_item_code(item.item_instance_code)
|
||||
if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code)
|
||||
if product = InventoryDefinition.find_by_item_code_and_shop_code(item.item_instance_code,shop_code)
|
||||
if stock_check_item = StockCheckItem.find_by_item_code_and_shop_code(item.item_instance_code,shop_code)
|
||||
return true, product
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_balance(item, inventory_definition) # item => saleItemOBj
|
||||
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||
stock = StockJournal.where("shop_code='#{inventory_definition.shop_code}' and item_code=?", item.item_instance_code).order("id DESC").first
|
||||
unless stock.nil?
|
||||
modify_balance(item, stock, inventory_definition)
|
||||
else
|
||||
@@ -94,7 +93,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
.order("mi.menu_category_id desc")
|
||||
end
|
||||
|
||||
def self.get_by_category(filter)
|
||||
def self.get_by_category(shop,filter)
|
||||
# THEN (SELECT min(balance) FROM stock_journals
|
||||
# least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock'
|
||||
# THEN (SELECT balance FROM stock_journals
|
||||
@@ -123,9 +122,9 @@ class InventoryDefinition < ApplicationRecord
|
||||
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
|
||||
.joins(" JOIN accounts acc ON acc.id = mi.account_id")
|
||||
.where("inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ?
|
||||
.where("inventory_definitions.shop_code='#{shop.shop_code}' and (inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ?
|
||||
OR inventory_definitions.max_stock_level LIKE ? OR sj.balance LIKE ? OR mi.name LIKE ?
|
||||
OR mii.item_instance_name LIKE ? OR mc.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%",
|
||||
OR mii.item_instance_name LIKE ? OR mc.name LIKE ?)","%#{filter}%","%#{filter}%","%#{filter}%",
|
||||
"%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
|
||||
.group("mi.menu_category_id,inventory_definitions.item_code")
|
||||
.order("balance asc, mi.name asc,acc.title desc,mi.menu_category_id desc")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Lookup < ApplicationRecord
|
||||
|
||||
has_many :accounts
|
||||
belongs_to :shop
|
||||
|
||||
def available_types
|
||||
{'Employee Roles' => 'employee_roles',
|
||||
@@ -21,10 +22,10 @@ class Lookup < ApplicationRecord
|
||||
# Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] }
|
||||
# end
|
||||
|
||||
def self.get_checkin_time_limit
|
||||
def self.get_checkin_time_limit(shop_code)
|
||||
time_limit = 5
|
||||
|
||||
lookup = Lookup.find_by_lookup_type('checkin_time_limit')
|
||||
lookup = Lookup.find_by_lookup_type_and_shop_code('checkin_time_limit',shop_code)
|
||||
if !lookup.nil?
|
||||
time_limit = lookup.value.to_i
|
||||
end
|
||||
@@ -59,39 +60,41 @@ class Lookup < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
def self.create_shift_sale_lookup
|
||||
def self.create_shift_sale_lookup(shop_code)
|
||||
@lookup = Lookup.new
|
||||
@lookup.lookup_type = 'shift_sale_items'
|
||||
@lookup.name = 'Shift Sale Items'
|
||||
@lookup.value = 0
|
||||
@lookup.shop_code = shop_code
|
||||
@lookup.save
|
||||
|
||||
return @lookup
|
||||
end
|
||||
|
||||
def self.create_reprint_receipt_lookup
|
||||
def self.create_reprint_receipt_lookup(shop_code)
|
||||
@lookup = Lookup.new
|
||||
@lookup.lookup_type = 'reprint_receipt'
|
||||
@lookup.name = 'Reprint Receipt in Report'
|
||||
@lookup.value = 0
|
||||
@lookup.shop_code = shop_code
|
||||
@lookup.save
|
||||
|
||||
return @lookup
|
||||
end
|
||||
|
||||
def self.save_shift_sale_items_settings(val)
|
||||
@lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last
|
||||
def self.save_shift_sale_items_settings(val,shop_code)
|
||||
@lookup = Lookup.where("shop_code='#{shop_code}' and lookup_type=?", 'shift_sale_items').last
|
||||
if @lookup.nil?
|
||||
@lookup = Lookup.create_shift_sale_lookup
|
||||
@lookup = Lookup.create_shift_sale_lookup(shop_code)
|
||||
end
|
||||
@lookup.value = val
|
||||
@lookup.save
|
||||
end
|
||||
|
||||
def self.shift_sale_items_lookup_value
|
||||
@lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last
|
||||
def self.shift_sale_items_lookup_value(shop_code)
|
||||
@lookup = Lookup.where("shop_code='#{shop_code}' and lookup_type=?", 'shift_sale_items').last
|
||||
if @lookup.nil?
|
||||
@lookup = Lookup.create_shift_sale_lookup
|
||||
@lookup = Lookup.create_shift_sale_lookup(shop_code)
|
||||
end
|
||||
return @lookup.value
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MembershipSetting < ApplicationRecord
|
||||
scope :active, -> { where(is_active: true) }
|
||||
|
||||
MembershipSetting = MembershipSetting.find_by_id(1)
|
||||
# MembershipSetting = MembershipSetting.find_by_id(1)
|
||||
end
|
||||
|
||||
@@ -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,shop)
|
||||
status = ""
|
||||
spreadsheet = open_spreadsheet(file)
|
||||
if spreadsheet.sheets.count > 1
|
||||
sheet_count = spreadsheet.sheets.count-1
|
||||
@@ -59,15 +59,15 @@ 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"])
|
||||
Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code)
|
||||
else
|
||||
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.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code)
|
||||
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
|
||||
@@ -92,9 +92,9 @@ class Menu < ApplicationRecord
|
||||
elsif sheet_name == "Menu"
|
||||
menu = Menu.find_by_id(row["id"])
|
||||
if menu
|
||||
Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
|
||||
Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code)
|
||||
else
|
||||
Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
|
||||
Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code)
|
||||
end
|
||||
elsif sheet_name == "Menu Category"
|
||||
# MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
|
||||
@@ -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
|
||||
@@ -141,32 +141,26 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
else
|
||||
# Menu by Menu Import
|
||||
@shop = Shop.first
|
||||
shop_code = ""
|
||||
if !@shop.nil?
|
||||
if @shop.shop_code
|
||||
shop_code = @shop.shop_code + "_"
|
||||
end
|
||||
end
|
||||
shop_code= shop.shop_code + "_"
|
||||
|
||||
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,shop_code: shop.shop_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"])
|
||||
(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,11 +182,11 @@ 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?
|
||||
account = Account.create({title: row["Account"], account_type: "0"})
|
||||
account = Account.create({title: row["Account"], account_type: "0",shop_code: shop.shop_code})
|
||||
end
|
||||
|
||||
image_path = ""
|
||||
@@ -205,22 +199,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 +225,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 +243,4 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,12 +35,14 @@ class Order < ApplicationRecord
|
||||
if self.is_extra_time && self.extra_time
|
||||
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
|
||||
:checkin_at => Time.now.utc,:checkout_at => Time.now.utc + self.extra_time.to_i,
|
||||
:checkin_by => self.employee_name,
|
||||
:booking_status => "assign" })
|
||||
:checkin_by => self.employee_name,
|
||||
:booking_status => "assign",
|
||||
:shop_code=>self.shop_code})
|
||||
else
|
||||
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
|
||||
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
|
||||
:booking_status => "assign" })
|
||||
:booking_status => "assign",
|
||||
:shop_code=>self.shop_code })
|
||||
end
|
||||
#end extra time
|
||||
|
||||
@@ -290,11 +292,11 @@ class Order < ApplicationRecord
|
||||
#Process order items and send to order queue
|
||||
def self.pay_process_order_queue(id,table_id)
|
||||
# if ENV["SERVER_MODE"] != 'cloud'
|
||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
order = Order.find(id)
|
||||
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",order.shop_code)
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(id, table_id)
|
||||
else
|
||||
order = Order.find(id)
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id)
|
||||
|
||||
@@ -136,7 +136,7 @@ class OrderItem < ApplicationRecord
|
||||
print instance_code
|
||||
end
|
||||
if self.qty != self.qty_before_last_save
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,instance_code)
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.order.shop_code)
|
||||
if found
|
||||
InventoryDefinition.check_balance(self, inventory_definition)
|
||||
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
|
||||
|
||||
@@ -16,22 +16,22 @@ 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
|
||||
|
||||
oqs_stations = OrderQueueStation.active.where("shop_code='#{order.shop_code}'")
|
||||
|
||||
|
||||
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,39 +186,39 @@ 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
|
||||
#Print order_items in 1 slip
|
||||
def print_slip(oqs, order, order_items ,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
||||
if pdf_status.nil?
|
||||
printer = PrintSetting.all.order("id ASC")
|
||||
printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").order("id ASC")
|
||||
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,34 +227,34 @@ 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)
|
||||
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code)
|
||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
||||
order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="")
|
||||
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")
|
||||
printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").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,16 +265,16 @@ 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_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||
# print when complete click
|
||||
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code)
|
||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
||||
if !assigned_items.nil?
|
||||
assigned_items.each do |order_item|
|
||||
@@ -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
|
||||
@@ -297,8 +297,8 @@ class OrderQueueStation < ApplicationRecord
|
||||
@type = (DiningFacility.find(change_to)).type
|
||||
@moved_by = current_user
|
||||
@date = DateTime.now
|
||||
@shop = Shop.first
|
||||
unique_code = "MoveTablePdf"
|
||||
@shop = Shop.find_by_shop_code(oqs.shop_code)
|
||||
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
|
||||
|
||||
@@ -40,8 +40,8 @@ class OrderReservation < ApplicationRecord
|
||||
# unless customer.valid?
|
||||
# render json: {
|
||||
# status: 422,
|
||||
# message: "Validation error",
|
||||
# errors: customer.errors
|
||||
# message: "Validation error",
|
||||
# errors: customer.errors
|
||||
# }.to_json
|
||||
# return
|
||||
# end
|
||||
@@ -53,7 +53,7 @@ class OrderReservation < ApplicationRecord
|
||||
Rails.logger.debug order_reserve.to_s
|
||||
check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reserve[:reference])
|
||||
if check_order_reservation.empty?
|
||||
OrderReservation.transaction do
|
||||
OrderReservation.transaction do
|
||||
begin
|
||||
order_reservation = OrderReservation.new
|
||||
order_reservation.order_reservation_type = order_reserve[:order_type]
|
||||
@@ -84,7 +84,7 @@ class OrderReservation < ApplicationRecord
|
||||
end
|
||||
order_reservation.save!
|
||||
if order_reserve[:order_info][:items]
|
||||
order_reserve[:order_info][:items].each do |oritem|
|
||||
order_reserve[:order_info][:items].each do |oritem|
|
||||
OrderReservationItem.process_order_reservation_item(oritem[:product_code],oritem[:item_instance_code],oritem[:product_name],oritem[:product_alt_name],
|
||||
oritem[:account_id],oritem[:qty],oritem[:price],oritem[:unit_price],
|
||||
oritem[:options],nil,order_reservation.id)
|
||||
@@ -93,13 +93,13 @@ class OrderReservation < ApplicationRecord
|
||||
if order_reserve[:delivery_info]
|
||||
Delivery.addDeliveryInfo(order_reserve[:delivery_info],order_reservation.id)
|
||||
end
|
||||
|
||||
|
||||
return order_reservation.id, true
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
raise ActiveRecord::Rollback
|
||||
|
||||
return nil, false
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
return check_order_reservation[0].id, false
|
||||
@@ -112,14 +112,14 @@ class OrderReservation < ApplicationRecord
|
||||
|
||||
items_arr = []
|
||||
count = 1
|
||||
order.order_reservation_items.each { |i|
|
||||
order.order_reservation_items.each { |i|
|
||||
i.item_instance_code = i.item_instance_code.downcase.to_s
|
||||
items = {"order_item_id": count,"item_instance_code": i.item_instance_code,"quantity": i.qty,"options": i.options}
|
||||
count += 1
|
||||
items_arr.push(items)
|
||||
}
|
||||
customer_id = order.customer_id
|
||||
|
||||
|
||||
@order = Order.new
|
||||
@order.source = "doemal_order"
|
||||
@order.order_type = "delivery"
|
||||
@@ -138,7 +138,7 @@ class OrderReservation < ApplicationRecord
|
||||
|
||||
# Order.send_customer_view(@booking)
|
||||
if @status && @booking
|
||||
|
||||
|
||||
@status, @sale = Sale.request_bill(@order,current_user,current_user)
|
||||
|
||||
#order status send to doemal
|
||||
@@ -157,7 +157,7 @@ class OrderReservation < ApplicationRecord
|
||||
def self.update_doemal_payment(order,current_user,receipt_bill)
|
||||
if(Sale.exists?(order.sale_id))
|
||||
saleObj = Sale.find(order.sale_id)
|
||||
shop_details = Shop.first
|
||||
shop_details = Shop.find_by_shop_code(order.shop_code)
|
||||
# rounding adjustment
|
||||
if shop_details.is_rounding_adj
|
||||
a = saleObj.grand_total % 25 # Modulus
|
||||
@@ -167,11 +167,11 @@ class OrderReservation < ApplicationRecord
|
||||
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)
|
||||
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
||||
end
|
||||
end
|
||||
#end rounding adjustment
|
||||
|
||||
|
||||
sale_payment = SalePayment.new
|
||||
if(order.payment_type == "cash_on_delivery")
|
||||
sale_payment.process_payment(saleObj, current_user, saleObj.grand_total, "cash")
|
||||
@@ -183,9 +183,9 @@ class OrderReservation < ApplicationRecord
|
||||
callback_response = send_status_to_ordering(order.callback_url,order.transaction_ref,DELIVERED)
|
||||
#order reservation status updated
|
||||
update_order_reservation(order.id, saleObj.sale_id, DELIVERED)
|
||||
Rails.logger.debug "@@@@ receipt_bill :: "
|
||||
Rails.logger.debug "@@@@ receipt_bill :: "
|
||||
Rails.logger.debug receipt_bill
|
||||
|
||||
|
||||
if receipt_bill == 1
|
||||
#receipt bill pdf setting
|
||||
# get printer info
|
||||
@@ -194,7 +194,7 @@ class OrderReservation < ApplicationRecord
|
||||
|
||||
shift = ShiftSale.find(saleObj.shift_sale_id)
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
shop_detail = Shop.first
|
||||
# shop_detail = Shop.first
|
||||
order_reservation = OrderReservation.get_order_reservation_info(saleObj.sale_id)
|
||||
if !cashier_terminal.nil?
|
||||
# Calculate Food and Beverage Total
|
||||
@@ -203,16 +203,16 @@ class OrderReservation < ApplicationRecord
|
||||
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,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_detail, "Paid",nil,nil,other_amount,nil,nil, order_reservation)
|
||||
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,saleObj.sale_items,saleObj,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_details, "Paid",nil,nil,other_amount,nil,nil, order_reservation)
|
||||
#receipt bill pdf setting
|
||||
|
||||
result = {:status=> true,
|
||||
:filepath => filename,
|
||||
:sale_id => saleObj.sale_id,
|
||||
:receipt_no => sale_receipt_no,
|
||||
:printer_name => printer_name,
|
||||
:printer_model => print_settings.brand_name,
|
||||
:printer_url => print_settings.api_settings ,
|
||||
result = {:status=> true,
|
||||
:filepath => filename,
|
||||
:sale_id => saleObj.sale_id,
|
||||
:receipt_no => sale_receipt_no,
|
||||
:printer_name => printer_name,
|
||||
:printer_model => print_settings.brand_name,
|
||||
:printer_url => print_settings.api_settings ,
|
||||
:message => DELIVERED }
|
||||
else
|
||||
result = {:status=> true, :message => DELIVERED }
|
||||
@@ -223,7 +223,7 @@ class OrderReservation < ApplicationRecord
|
||||
result = {:status=> true, :message => DELIVERED }
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.send_status_to_ordering(url,ref_no,status,waiting_time=nil,min_type=nil,reason=nil)
|
||||
@@ -349,12 +349,12 @@ class OrderReservation < ApplicationRecord
|
||||
shift.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
sale.payment_status = 'void'
|
||||
sale.sale_status = 'void'
|
||||
sale.save
|
||||
|
||||
# For Sale Audit
|
||||
# For Sale Audit
|
||||
if !current_user.nil?
|
||||
action_by = current_user.name
|
||||
else
|
||||
@@ -363,7 +363,7 @@ class OrderReservation < ApplicationRecord
|
||||
|
||||
approved_name = nil
|
||||
approved_by = Employee.find_by_emp_id(access_code)
|
||||
|
||||
|
||||
if !approved_by.nil?
|
||||
approved_name = approved_by.name
|
||||
end
|
||||
@@ -372,7 +372,7 @@ class OrderReservation < ApplicationRecord
|
||||
sale_audit = SaleAudit.record_audit_for_edit(sale_id,cashier_name, approved_name,remark,"SALEVOID" )
|
||||
|
||||
# update complete order items in oqs
|
||||
SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
|
||||
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
|
||||
@@ -410,7 +410,7 @@ class OrderReservation < ApplicationRecord
|
||||
if order_reservation.length > 0
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code,from:from
|
||||
@@ -428,7 +428,7 @@ class OrderReservation < ApplicationRecord
|
||||
if order_reservation.length > 0
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code,from:from
|
||||
@@ -446,7 +446,7 @@ class OrderReservation < ApplicationRecord
|
||||
if order_reservation.length > 0
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "check_order_ready_to_delivery_channel",data: order_reservation, shop_code: shop_code,from:from
|
||||
|
||||
@@ -7,7 +7,8 @@ class PaymentJournal < ApplicationRecord
|
||||
self.payment_method = payment_method
|
||||
self.payment_status = 'paid'
|
||||
self.payment_method_references = payment_method_reference
|
||||
self.created_by = current_user
|
||||
self.created_by = current_user.id
|
||||
self.shop_code = current_user.shop_code
|
||||
self.save
|
||||
end
|
||||
|
||||
@@ -16,7 +17,8 @@ class PaymentJournal < ApplicationRecord
|
||||
self.remark = remark
|
||||
self.debit_amount = amount
|
||||
self.payment_status = 'paid'
|
||||
self.created_by = current_user
|
||||
self.created_by = current_user.id
|
||||
self.shop_code = current_user.shop_code
|
||||
self.save
|
||||
end
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
end
|
||||
# end
|
||||
|
||||
shop = Shop.first
|
||||
directory_name = 'public/orders_'+shop.shop_code
|
||||
# shop = Shop.first
|
||||
directory_name = 'public/orders_'+oqs.shop_code
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf"
|
||||
@@ -80,8 +80,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
print_setting = PrintSetting.all.order("id ASC")
|
||||
order=print_query('order_summary', order_id)
|
||||
|
||||
shop = Shop.first
|
||||
directory_name = 'public/orders_'+shop.shop_code
|
||||
# shop = Shop.first
|
||||
directory_name = 'public/orders_'+oqs.shop_code
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
# For Print Per Item
|
||||
@@ -192,8 +192,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
order=print_query('booking_summary', booking_id)
|
||||
|
||||
shop = Shop.first
|
||||
directory_name = 'public/orders_'+shop.shop_code
|
||||
# shop = Shop.first
|
||||
directory_name = 'public/orders_'+oqs.shop_code
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
# For Print Per Item
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'cups'
|
||||
|
||||
class Printer::PrinterWorker
|
||||
attr_accessor :print_settings
|
||||
|
||||
|
||||
def initialize(print_settings)
|
||||
self.print_settings = print_settings
|
||||
end
|
||||
|
||||
@@ -195,7 +195,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
||||
if !printer_settings.nil?
|
||||
if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder")
|
||||
pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
||||
settings = PrintSetting.all
|
||||
settings = PrintSetting.where("shop_code='#{shop_details.shop_code}'")
|
||||
if !settings.nil?
|
||||
settings.each do |setting|
|
||||
if setting.unique_code == 'ReceiptBillPdf'
|
||||
@@ -206,7 +206,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
||||
end
|
||||
end
|
||||
|
||||
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
||||
receipt_bill_a5_pdf = Lookup.where("shop_code='#{shop_details.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
||||
if !receipt_bill_a5_pdf.empty?
|
||||
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
||||
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
||||
|
||||
@@ -33,9 +33,9 @@ class ProductCommission < ApplicationRecord
|
||||
product_commission.save
|
||||
end
|
||||
|
||||
def self.edit_product_commission(saleItemObj)
|
||||
def self.edit_product_commission(saleItemObj,shop_code)
|
||||
menu_item = MenuItem.find_by_item_code(saleItemObj.product_code)
|
||||
commission = Commission.where('product_code = ? AND is_active = ?', menu_item.id, true).take
|
||||
commission = Commission.where("shop_code='#{shop_code}' and product_code = ? AND is_active = ?", menu_item.id, true).take
|
||||
product_commission = ProductCommission.where('sale_item_id = ?', saleItemObj.id).take
|
||||
|
||||
if !product_commission.nil?
|
||||
|
||||
@@ -15,11 +15,11 @@ class Promotion < ApplicationRecord
|
||||
promo_day.include? Date.today.wday.to_s
|
||||
end
|
||||
|
||||
def self.promo_activate(saleObj)
|
||||
def self.promo_activate(saleObj,shop_code)
|
||||
current_day = Time.now.strftime("%Y-%m-%d")
|
||||
current_time = Time.now.strftime('%H:%M:%S')
|
||||
day = Date.today.wday
|
||||
promoList = is_between_promo_datetime(current_day,current_time)
|
||||
promoList = is_between_promo_datetime(current_day,current_time,shop_code)
|
||||
|
||||
promoList.each do |promo|
|
||||
if promo.is_promo_day
|
||||
@@ -30,8 +30,8 @@ class Promotion < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.is_between_promo_datetime(current_day,current_time) #database is not local time
|
||||
promoList = Promotion.where("(Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
|
||||
def self.is_between_promo_datetime(current_day,current_time,shop_code) #database is not local time
|
||||
promoList = Promotion.where("shop_code='#{shop_code}' and (Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
|
||||
return promoList
|
||||
end
|
||||
|
||||
@@ -157,7 +157,7 @@ class Promotion < ApplicationRecord
|
||||
sale_item.is_taxable = 1
|
||||
sale_item.sale = saleObj
|
||||
sale_item.save
|
||||
|
||||
|
||||
saleObj.sale_items << sale_item
|
||||
saleObj.compute_by_sale_items(saleObj.total_discount, nil, source)
|
||||
end
|
||||
|
||||
@@ -29,7 +29,6 @@ class Sale < ApplicationRecord
|
||||
scope :date_between, -> (from, to) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) }
|
||||
scope :time_between, -> (from, to) { where("TIME(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) }
|
||||
scope :along_with_sale_payments_except_void, -> { joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") }
|
||||
|
||||
def qty_of(item_instance_code)
|
||||
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
|
||||
end
|
||||
@@ -136,8 +135,8 @@ class Sale < ApplicationRecord
|
||||
order = Order.find(order_id)
|
||||
|
||||
# current cashier login
|
||||
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
||||
current_shift = ShiftSale.current_shift
|
||||
open_cashier = Employee.where("shop_code='#{order.shop_code}' and role = 'cashier' AND token_session <> ''")
|
||||
current_shift = ShiftSale.current_shift(order.shop_code)
|
||||
# shift with terminal zone
|
||||
|
||||
# set cashier
|
||||
@@ -145,12 +144,12 @@ class Sale < ApplicationRecord
|
||||
if !booking.dining_facility_id.nil?
|
||||
table = DiningFacility.find(booking.dining_facility_id)
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
|
||||
shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
|
||||
#for multiple zone with terminal
|
||||
if shift.nil?
|
||||
multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}")
|
||||
multiple_zone.each do |zone|
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
|
||||
shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
|
||||
if !shift.nil? then
|
||||
break
|
||||
end
|
||||
@@ -158,7 +157,7 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
end
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(cashier.id)
|
||||
shift = ShiftSale.current_open_shift(cashier)
|
||||
end
|
||||
# set cashier
|
||||
if shift != nil #if current login employee open shift
|
||||
@@ -170,7 +169,7 @@ class Sale < ApplicationRecord
|
||||
# table and terminal in multiple shift
|
||||
self.cashier_id = open_cashier[0].id
|
||||
self.cashier_name = open_cashier[0].name
|
||||
shift_id = ShiftSale.current_open_shift(open_cashier[0].id)
|
||||
shift_id = ShiftSale.current_open_shift(open_cashier[0])
|
||||
if shift_id
|
||||
self.shift_sale_id = shift_id.id
|
||||
else
|
||||
@@ -188,7 +187,7 @@ class Sale < ApplicationRecord
|
||||
self.requested_by = requested_by.name
|
||||
|
||||
self.requested_at = DateTime.now.utc.getlocal
|
||||
|
||||
self.shop_code = order.shop_code
|
||||
Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}"
|
||||
if order
|
||||
self.customer_id = order.customer_id
|
||||
@@ -234,15 +233,13 @@ class Sale < ApplicationRecord
|
||||
|
||||
#fOR Quick Service pay and create
|
||||
def self.request_bill(order,current_user,current_login_employee)
|
||||
if !ShiftSale.current_shift.nil?
|
||||
if !ShiftSale.current_shift(order.shop_code).nil?
|
||||
order_id = order.order_id # order_id
|
||||
bk_order = BookingOrder.find_by_order_id(order_id)
|
||||
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
||||
|
||||
if @sale_data = check_booking.sale
|
||||
# Create Sale if it doesn't exist
|
||||
# puts "current_login_employee"
|
||||
# puts current_login_employee.name
|
||||
@sale_items = SaleItem.where("sale_id=?",@sale_id)
|
||||
elsif @sale_data = Sale.generate_invoice_from_booking(check_booking,current_login_employee,current_user,order.source)
|
||||
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
|
||||
@@ -253,7 +250,7 @@ class Sale < ApplicationRecord
|
||||
# @sale_data.save
|
||||
|
||||
# Promotion Activation
|
||||
Promotion.promo_activate(@sale_data)
|
||||
Promotion.promo_activate(@sale_data,order.shop_code)
|
||||
@status = true
|
||||
return @status, @sale_data
|
||||
else
|
||||
@@ -438,7 +435,7 @@ class Sale < ApplicationRecord
|
||||
|
||||
#compute - invoice total
|
||||
def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil)
|
||||
shop = Shop.first
|
||||
# shop = Shop.first
|
||||
|
||||
#Computation Fields
|
||||
subtotal_price = 0
|
||||
@@ -505,7 +502,7 @@ class Sale < ApplicationRecord
|
||||
|
||||
# Tax Re-Calculte
|
||||
def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
|
||||
shop = Shop.first
|
||||
shop = Shop.find_by_shop_code(self.shop_code)
|
||||
|
||||
#if tax is not apply create new record
|
||||
# SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax|
|
||||
@@ -559,7 +556,7 @@ class Sale < ApplicationRecord
|
||||
|
||||
# Tax Calculate
|
||||
def apply_tax(total_taxable, order_source = nil, tax_type = nil)
|
||||
shop = Shop.first
|
||||
shop = Shop.find_by_shop_code(self.shop_code)
|
||||
|
||||
#if tax is not apply create new record
|
||||
# SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
|
||||
@@ -639,7 +636,7 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def adjust_rounding
|
||||
shop_details = Shop.first
|
||||
shop_details = Shop.find_by_shop_code(self.shop_code)
|
||||
# rounding adjustment
|
||||
if shop_details.is_rounding_adj
|
||||
new_total = Sale.get_rounding_adjustment(self.grand_total)
|
||||
@@ -655,7 +652,7 @@ class Sale < ApplicationRecord
|
||||
#Generate new Receipt No when it is not assigned
|
||||
def generate_receipt_no
|
||||
#shop_code and client_code
|
||||
shop_details = Shop.first
|
||||
shop_details = Shop.find_by_shop_code(self.shop_code)
|
||||
#Date-Shift-
|
||||
if self.receipt_no.nil?
|
||||
prefix = DateTime.now().utc
|
||||
@@ -1502,10 +1499,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 +1513,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 +1522,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)
|
||||
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 +1537,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 +1546,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)
|
||||
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,53 +1567,53 @@ 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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
|
||||
query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count")
|
||||
.where('sale_status = "completed"')
|
||||
.where("sale_status = 'completed' AND shop_code='#{shop.shop_code}'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
|
||||
query = query.date_between(from, to)
|
||||
@@ -1627,16 +1624,16 @@ 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)
|
||||
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)
|
||||
def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
|
||||
query = Sale.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")')
|
||||
.where("sales.shop_code='#{shop.shop_code}' and 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)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1646,20 +1643,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)
|
||||
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 +1667,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)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1678,9 +1675,9 @@ 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)
|
||||
def self.summary_sale_receipt(shop,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')
|
||||
.where('sale_status = "completed"')
|
||||
.where("shop_code='#{shop.shop_code}' and sale_status = 'completed'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1690,16 +1687,16 @@ 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)
|
||||
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)
|
||||
def self.total_payment_methods(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.select("distinct sp.payment_method")
|
||||
.where('sales.sale_status = "completed"')
|
||||
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'")
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
@@ -1710,19 +1707,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)
|
||||
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")
|
||||
.joins(:sale_payments)
|
||||
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
|
||||
.where("sales.shop_code='#{shop.shop_code}'")
|
||||
.completed
|
||||
|
||||
if payment_method == 'card'
|
||||
@@ -1741,15 +1739,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)
|
||||
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 +1756,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,10 +1769,10 @@ 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)
|
||||
def self.total_dinein_takeaway(shop,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")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and c.membership_id is null')
|
||||
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and c.membership_id is null")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1784,17 +1782,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)
|
||||
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)
|
||||
def self.total_membership(shop,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")
|
||||
.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))')
|
||||
.where("sales.shop_code='#{shop.shop_code}' and 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!="")
|
||||
query = query.date_between(from, to)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1804,7 +1802,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)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1857,9 +1855,10 @@ end
|
||||
# query = query.first()
|
||||
# end
|
||||
|
||||
def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.total_order(shop,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")
|
||||
.joins(:sale_orders)
|
||||
.where("shop_code='#{shop.shop_code}'")
|
||||
.completed
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
@@ -1871,7 +1870,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)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1879,11 +1878,11 @@ end
|
||||
query = query.first
|
||||
end
|
||||
|
||||
def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.total_account(shop,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")
|
||||
.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"')
|
||||
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1893,17 +1892,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)
|
||||
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)
|
||||
def self.account_data(shop,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")
|
||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}'")
|
||||
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and a.account_id ='#{account_id}'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1913,17 +1912,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)
|
||||
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)
|
||||
def self.top_items(shop,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")
|
||||
.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'")
|
||||
.where("sales.shop_code='#{shop.shop_code}' and (a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'")
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
query = query.date_between(from, to)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1933,7 +1932,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)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -1942,9 +1941,9 @@ end
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.total_foc_items(shop,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")
|
||||
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'")
|
||||
.where("sales.shop_code='#{shop.shop_code}' and 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)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -1954,7 +1953,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)
|
||||
query = query.where("sales.shift_sale_id = ?", shift.id)
|
||||
end
|
||||
end
|
||||
@@ -2016,13 +2015,13 @@ end
|
||||
query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","#{type}")
|
||||
.group("bookings.booking_id")
|
||||
end
|
||||
def self.completed_sale(type)
|
||||
def self.completed_sale(type,shop_code)
|
||||
if type == "cashier"
|
||||
type = "and orders.source = 'emenu' or orders.source = 'cashier'"
|
||||
else
|
||||
type = "and orders.source = '#{type}'"
|
||||
end
|
||||
query = Sale.all
|
||||
query = Sale.where("sales.shop_code='#{shop_code}'")
|
||||
query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id")
|
||||
.joins("join orders as orders on orders.order_id = sale_orders.order_id")
|
||||
query = query.where("sales.sale_status != 'new' AND orders.status = 'billed' #{type}")
|
||||
@@ -2085,8 +2084,7 @@ def self.get_sale_data_for_other_payment_credit(sale_id)
|
||||
end
|
||||
|
||||
def unique_tax_profiles(order_source, customer_id)
|
||||
tax_data = TaxProfile
|
||||
.where(group_type: order_source)
|
||||
tax_data = TaxProfile.where(group_type: order_source,shop_code: self.shop_code)
|
||||
|
||||
customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first
|
||||
if customer_tax_profiles.present?
|
||||
@@ -2096,7 +2094,7 @@ 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," +
|
||||
" i.price as unit_price,i.product_name")
|
||||
@@ -2105,7 +2103,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
|
||||
" and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'")
|
||||
else
|
||||
query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
|
||||
query = query.where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
|
||||
" and sale_status= 'completed'")
|
||||
end
|
||||
if !shift.nil?
|
||||
@@ -2115,7 +2113,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.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}'"+
|
||||
.where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||
" and sale_status= 'completed'")
|
||||
if !shift.nil?
|
||||
query = query.where("shift_sale_id='#{shift.id}'")
|
||||
@@ -2124,7 +2122,7 @@ 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")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -2135,11 +2133,11 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=
|
||||
if !shift.nil?
|
||||
query = query.where("shift_sale_id='#{shift.id}'")
|
||||
end
|
||||
query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
|
||||
query = query.where("shop_code='#{shop.shop_code}'").group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
|
||||
.order('receipt_date')
|
||||
else
|
||||
query = Sale.select("grand_total")
|
||||
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.where("shop_code='#{shop.shop_code}' and sale_status = 'completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = ?",today)
|
||||
if !shift.nil?
|
||||
query = query.where("shift_sale_id='#{shift.id}'")
|
||||
end
|
||||
@@ -2150,10 +2148,10 @@ 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)
|
||||
def self.employee_sale(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
query = Sale.joins(:cashier)
|
||||
.joins(:sale_payments)
|
||||
.paid.completed
|
||||
.paid.completed.where("sales.shop_code='#{shop.shop_code}'")
|
||||
if !from.nil? && !to.nil?
|
||||
query = query.date_between(from, to)
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
@@ -2474,7 +2472,7 @@ private
|
||||
def update_stock_journal
|
||||
if self.sale_status == "void" && self.sale_status_before_last_save != "void"
|
||||
self.sale_items.each do |item|
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code)
|
||||
if found
|
||||
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||
unless stock.nil?
|
||||
@@ -2487,7 +2485,7 @@ private
|
||||
end
|
||||
elsif self.sale_status == "waste" || self.sale_status == "spoile" || (self.payment_status == "foc" && self.payment_status_was != "foc")
|
||||
self.bookings.first.order_items.each do |item|
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code)
|
||||
if found
|
||||
if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id)
|
||||
stock_journal.update(remark: self.sale_status)
|
||||
|
||||
@@ -311,11 +311,11 @@ class SaleItem < ApplicationRecord
|
||||
cancel_foc = self.status_before_last_save == "foc"
|
||||
|
||||
if is_void or cancel_void or is_edit or is_foc or cancel_foc
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.sale.shop_code)
|
||||
if found
|
||||
stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first
|
||||
stock = StockJournal.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first
|
||||
unless stock.nil?
|
||||
check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first
|
||||
check_item = StockCheckItem.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first
|
||||
if is_void or cancel_void or is_edit
|
||||
if is_void
|
||||
qty = -self.qty
|
||||
|
||||
@@ -34,9 +34,9 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_kbz_pay_amount(sale_id, current_user)
|
||||
def self.get_kbz_pay_amount(sale_id, current_user,shop)
|
||||
amount = 0
|
||||
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
|
||||
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => shop.shop_code).last
|
||||
sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last
|
||||
if !sale_payment.nil? and !kbz_pay_method.nil?
|
||||
if sale_payment.payment_status == 'pending'
|
||||
@@ -136,11 +136,12 @@ class SalePayment < ApplicationRecord
|
||||
#record an payment in sale-audit
|
||||
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}"
|
||||
if payment_for
|
||||
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
|
||||
current_shift_user =Employee.find_by_id(self.sale.cashier_id)
|
||||
shift = ShiftSale.current_open_shift(current_shift_user)
|
||||
if !shift.nil?
|
||||
shift_sale_id = shift.id
|
||||
else
|
||||
shift = ShiftSale.current_shift
|
||||
shift = ShiftSale.current_shift(self.sale.shop_code)
|
||||
shift_sale_id = shift.id
|
||||
end
|
||||
|
||||
@@ -726,11 +727,12 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
# update for cashier shift
|
||||
def update_shift
|
||||
|
||||
shift = ShiftSale.current_open_shift(self.action_by.id)
|
||||
current_shift_user = Employee.find_by_id(self.action_by.id)
|
||||
shift = ShiftSale.current_open_shift(current_shift_user)
|
||||
|
||||
if shift.nil?
|
||||
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
|
||||
current_shift_user = Employee.find_by_id(self.sale.cashier_id)
|
||||
shift = ShiftSale.current_open_shift(current_shift_user)
|
||||
end
|
||||
|
||||
if !shift.nil?
|
||||
@@ -740,7 +742,7 @@ class SalePayment < ApplicationRecord
|
||||
self.sale.cashier_name = Employee.find(shift.employee_id).name
|
||||
self.sale.save
|
||||
else
|
||||
shift = ShiftSale.current_shift
|
||||
shift = ShiftSale.current_shift(self.sale.shop_code)
|
||||
shift.update(self.sale)
|
||||
self.sale.shift_sale_id = shift.id
|
||||
self.sale.cashier_id = shift.employee_id
|
||||
@@ -972,7 +974,7 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
#credit payment query
|
||||
def self.get_credit_sales(params)
|
||||
def self.get_credit_sales(params,shop_code)
|
||||
receipt_no = ""
|
||||
customer = ""
|
||||
if !params["receipt_no"].blank?
|
||||
@@ -1001,7 +1003,7 @@ class SalePayment < ApplicationRecord
|
||||
else
|
||||
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
||||
end
|
||||
query = query.group("s.receipt_no")
|
||||
query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no")
|
||||
.order("s.receipt_date ASC, s.receipt_no ASC")
|
||||
return query
|
||||
end
|
||||
|
||||
@@ -16,10 +16,11 @@ class ShiftSale < ApplicationRecord
|
||||
belongs_to :cashier_terminal
|
||||
belongs_to :employee, :foreign_key => 'employee_id'
|
||||
has_many :sales
|
||||
belongs_to :shop
|
||||
|
||||
def self.current_shift
|
||||
def self.current_shift(shop_code)
|
||||
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first
|
||||
shift = ShiftSale.where("shop_code='#{shop_code}' and shift_started_at is not null and shift_closed_at is null").first
|
||||
return shift
|
||||
end
|
||||
|
||||
@@ -28,7 +29,7 @@ class ShiftSale < ApplicationRecord
|
||||
#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 = ShiftSale.where("shop_code='#{current_user.shop_code}' and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user.id}").take
|
||||
return shift
|
||||
#end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,6 @@ class Shop < ApplicationRecord
|
||||
|
||||
# Shop Image Uploader
|
||||
mount_uploader :logo, ShopImageUploader
|
||||
|
||||
has_many :display_images
|
||||
accepts_nested_attributes_for :display_images
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
class StockCheck < ApplicationRecord
|
||||
has_many :stock_check_items
|
||||
|
||||
def create(user, reason, item_list)
|
||||
def create(user, reason, item_list,shop)
|
||||
self.reason = reason
|
||||
self.check_by = user.id
|
||||
self.check_start = Time.now
|
||||
self.check_end = Time.now
|
||||
self.shop_code = shop.shop_code
|
||||
save
|
||||
item_list.each do |item|
|
||||
stockItem = StockCheckItem.new
|
||||
|
||||
@@ -67,7 +67,7 @@ class StockCheckItem < ApplicationRecord
|
||||
return query
|
||||
end
|
||||
|
||||
def self.delete_stock_check_item(item_code)
|
||||
self.where("item_code=?", item_code).delete_all
|
||||
def self.delete_stock_check_item(item_code,shop)
|
||||
self.where("item_code=? and shop_code='#{shop.shop_code}'", item_code).delete_all
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class StockJournal < ApplicationRecord
|
||||
|
||||
belongs_to :shop
|
||||
SALES_TRANS = "sale"
|
||||
ORDER_TRANS = "order"
|
||||
STOCK_CHECK_TRANS = "stock_check"
|
||||
@@ -24,7 +24,8 @@ class StockJournal < ApplicationRecord
|
||||
inventory_definition_id: inventory_definition.id,
|
||||
remark: stock_message,
|
||||
trans_ref: trans_ref,
|
||||
trans_type: trans_type
|
||||
trans_type: trans_type,
|
||||
shop_code: inventory_definition.shop_code
|
||||
)
|
||||
end
|
||||
|
||||
@@ -32,27 +33,30 @@ class StockJournal < ApplicationRecord
|
||||
return balance.to_i - qty.to_i
|
||||
end
|
||||
|
||||
def self.from_stock_check(item)
|
||||
stock_journal = StockJournal.where('item_code=?', item.item_code).order("id DESC").first
|
||||
def self.from_stock_check(item,shop)
|
||||
stock_journal = StockJournal.where("shop_code='#{shop.shop_code}' and item_code=?", item.item_code).order("id DESC").first
|
||||
if stock_journal.nil?
|
||||
old_blance = 0
|
||||
inventory_definition_id = InventoryDefinition.find_by_item_code_and_shop_code(item.item_code,shop.shop_code).id
|
||||
else
|
||||
old_blance = stock_journal.balance
|
||||
inventory_definition_id = stock_journal.inventory_definition_id
|
||||
end
|
||||
definition_id = InventoryDefinition.find_by_item_code(item.item_code)
|
||||
# definition_id = InventoryDefinition.find_by_item_code(item.item_code)
|
||||
journal = StockJournal.new
|
||||
journal.item_code = item.item_code
|
||||
journal.inventory_definition_id = definition_id.id
|
||||
journal.inventory_definition_id = inventory_definition_id
|
||||
journal.debit = 0
|
||||
journal.credit = item.stock_count
|
||||
journal.balance = item.stock_count + old_blance.to_i
|
||||
journal.remark = StockJournal::STOCK_CHECK_TRANS
|
||||
journal.trans_ref = item.id
|
||||
journal.trans_type = StockJournal::STOCK_CHECK_TRANS
|
||||
journal.shop_code = shop.shop_code
|
||||
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")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
@@ -61,12 +65,12 @@ class StockJournal < ApplicationRecord
|
||||
else
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'")
|
||||
end
|
||||
query = query.group("mii.item_instance_name")
|
||||
query = query.where("shop_code='#{shop.shop_code}'").group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
else
|
||||
query = StockJournal.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}'")
|
||||
.where("shop_code='#{shop.shop_code}' and DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'")
|
||||
.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
end
|
||||
@@ -81,8 +85,8 @@ class StockJournal < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.delete_stock_journal(item_code)
|
||||
self.where("item_code=?", item_code).delete_all
|
||||
def self.delete_stock_journal(item_code,shop)
|
||||
self.where("item_code=? and shop_code='#{shop.shop_code}'", item_code).delete_all
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user