fixed conflit
This commit is contained in:
@@ -29,7 +29,7 @@ class Ability
|
||||
can :manage, Order
|
||||
can :manage, Booking
|
||||
can :manage, Sale
|
||||
|
||||
|
||||
|
||||
can :manage, Customer
|
||||
can :manage, DiningQueue
|
||||
@@ -57,8 +57,8 @@ class Ability
|
||||
can :show, :product_sale
|
||||
|
||||
can :get_customer, Customer
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
|
||||
can :index, :other_charge
|
||||
can :create, :other_charge
|
||||
@@ -73,11 +73,11 @@ class Ability
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
can :foc, :payment
|
||||
can :print, :payment
|
||||
can :foc, :payment
|
||||
can :print, :payment
|
||||
can :change_tax, :payment
|
||||
|
||||
can :move_dining, :movetable
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
|
||||
can :move_dining, :moveroom
|
||||
@@ -123,11 +123,11 @@ class Ability
|
||||
can :print, :print
|
||||
can :print_order_summary, :print
|
||||
|
||||
can :read, ShiftSale
|
||||
can :update, ShiftSale
|
||||
can :read, ShiftSale
|
||||
can :update, ShiftSale
|
||||
|
||||
elsif user.role == "cashier" || user.role =="foodcourt_cashier"
|
||||
|
||||
elsif user.role == "cashier"
|
||||
|
||||
# can :overall_void, :void
|
||||
can :index, :home
|
||||
can :show, :home
|
||||
@@ -136,10 +136,10 @@ class Ability
|
||||
can :update, Order
|
||||
can :manage, Booking
|
||||
can :manage, OrderQueueStation
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
|
||||
can :manage, Customer
|
||||
can :manage, Customer
|
||||
|
||||
can :manage, OrderReservation
|
||||
|
||||
@@ -160,11 +160,11 @@ class Ability
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
can :foc, :payment
|
||||
can :foc, :payment
|
||||
can :print, :payment
|
||||
can :change_tax, :payment
|
||||
|
||||
can :move_dining, :movetable
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
|
||||
can :move_dining, :moveroom
|
||||
@@ -204,7 +204,7 @@ class Ability
|
||||
can :item_edit, :sale_edit
|
||||
|
||||
can :overall_void, :void
|
||||
|
||||
|
||||
elsif user.role == "account"
|
||||
|
||||
can :index, :dailysale
|
||||
@@ -228,14 +228,14 @@ class Ability
|
||||
|
||||
elsif user.role == "supervisor"
|
||||
can :manage, Employee
|
||||
|
||||
|
||||
can :edit, :sale_edit
|
||||
can :item_void, :sale_edit
|
||||
can :item_foc, :sale_edit
|
||||
can :item_edit, :sale_edit
|
||||
can :item_void_cancel, :sale_edit
|
||||
can :cancel_all_void, :sale_edit
|
||||
can :apply_void, :sale_edit
|
||||
can :cancel_all_void, :sale_edit
|
||||
can :apply_void, :sale_edit
|
||||
can :overall_void, :void
|
||||
|
||||
can :index, :other_charge
|
||||
@@ -246,7 +246,7 @@ class Ability
|
||||
can :remove_all_discount, :discount
|
||||
can :member_discount, :discount
|
||||
|
||||
can :move_dining, :movetable
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
|
||||
can :move_dining, :moveroom
|
||||
@@ -297,9 +297,9 @@ class Ability
|
||||
|
||||
elsif user.role == "waiter"
|
||||
can :index, :home
|
||||
can :show, :home
|
||||
can :show, :home
|
||||
|
||||
can :manage, Customer
|
||||
can :manage, Customer
|
||||
can :get_customer, Customer
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
@@ -313,7 +313,7 @@ class Ability
|
||||
can :member_discount, :discount
|
||||
|
||||
#ability for move table
|
||||
can :move_dining, :movetable
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
|
||||
can :move_dining, :moveroom
|
||||
@@ -339,7 +339,7 @@ class Ability
|
||||
can :print_order_summary, :print
|
||||
|
||||
elsif user.role == "kitchen"
|
||||
|
||||
|
||||
#oqs Home
|
||||
can :manage, OrderQueueStation
|
||||
can :index, :home
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
|
||||
def self.inherited(subclass)
|
||||
super
|
||||
|
||||
return unless subclass.superclass == self
|
||||
return unless subclass.column_names.include? 'shop_id'
|
||||
|
||||
subclass.class_eval do
|
||||
acts_as_tenant(:shop)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ class DiningCharge < ApplicationRecord
|
||||
end
|
||||
return block_count, price
|
||||
else
|
||||
puts "<<<<<<<< NO"
|
||||
Rails.logger.info "Params not enough"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -32,50 +32,27 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_current_booking
|
||||
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
|
||||
return nil
|
||||
end
|
||||
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null
|
||||
end
|
||||
|
||||
def get_moved_booking
|
||||
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)
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
Booking.where(dining_facility_id: self.id, booking_status: 'moved', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
|
||||
|
||||
if booking.count > 0 then
|
||||
return booking[0]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_new_booking
|
||||
# query for new
|
||||
# if status
|
||||
# to ask when req bill booking_status?
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1)
|
||||
# else
|
||||
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1)
|
||||
# end
|
||||
|
||||
if booking.count > 0 then
|
||||
return booking[0].booking_id
|
||||
else
|
||||
return nil
|
||||
end
|
||||
Booking.where(dining_facility_id: self.id, booking_status: 'assign', sale_id: nil, checkout_at: nil).first
|
||||
end
|
||||
|
||||
def get_current_checkout_booking
|
||||
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
|
||||
return nil
|
||||
end
|
||||
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
|
||||
|
||||
end
|
||||
|
||||
def get_checkout_booking
|
||||
@@ -117,8 +94,10 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.get_checkin_booking
|
||||
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")
|
||||
|
||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||
bookings = Booking.where(booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago)
|
||||
|
||||
arr_booking = Array.new
|
||||
if bookings
|
||||
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
|
||||
|
||||
@@ -3,6 +3,7 @@ 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
|
||||
@@ -19,9 +20,9 @@ class Employee < ApplicationRecord
|
||||
Employee.select("id, name").map { |e| [e.name, e.id] }
|
||||
end
|
||||
|
||||
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)
|
||||
def self.login(emp_id, password)
|
||||
user = Employee.find_by_emp_id(emp_id)
|
||||
expiry_time = login_expiry_time
|
||||
if (user)
|
||||
#user.authenticate(password)
|
||||
if (user.authenticate(password))
|
||||
@@ -36,10 +37,10 @@ class Employee < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
def self.authenticate_by_token(session_token,shop)
|
||||
def self.authenticate_by_token(session_token)
|
||||
if (session_token)
|
||||
user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code)
|
||||
expiry_time = login_expiry_time(shop)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
expiry_time = login_expiry_time
|
||||
|
||||
if user && user.session_expiry.utc > DateTime.now.utc
|
||||
#Extend the login time each time authenticatation take place
|
||||
@@ -54,9 +55,9 @@ class Employee < ApplicationRecord
|
||||
return false
|
||||
end
|
||||
|
||||
def self.logout(shop,session_token)
|
||||
def self.logout(session_token)
|
||||
if (session_token)
|
||||
user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
|
||||
if user
|
||||
user.token_session = nil
|
||||
@@ -72,9 +73,9 @@ class Employee < ApplicationRecord
|
||||
retry
|
||||
end
|
||||
|
||||
def self.login_expiry_time(shop)
|
||||
def self.login_expiry_time
|
||||
expiry_time = 30
|
||||
login_expiry = Lookup.where("shop_code='#{shop.shop_code}'").collection_of('expiry_time')
|
||||
login_expiry = Lookup.collection_of('expiry_time')
|
||||
if !login_expiry.empty?
|
||||
login_expiry.each do |exp_time|
|
||||
if exp_time[0].downcase == "login"
|
||||
|
||||
@@ -23,34 +23,23 @@ class InventoryDefinition < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_product_in_inventory(item,shop_code=nil)
|
||||
# unless instance_code.empty?
|
||||
# instance_code = instance_code.to_s
|
||||
# instance_code[0] = ""
|
||||
# instance_code = instance_code.chomp("]")
|
||||
# else
|
||||
# instance_code = '"0"'
|
||||
# end
|
||||
#
|
||||
# if prod = InventoryDefinition.where("item_code IN(#{instance_code})")
|
||||
# puts "found prodcut+++++++++++++++++++++++++++++++++++==="
|
||||
# puts prod.to_json
|
||||
# end
|
||||
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)
|
||||
|
||||
def self.find_product_in_inventory(item)
|
||||
if product = InventoryDefinition.find_by_item_code_and_shop_code(item.item_instance_code,Shop.current_shop.shop_code)
|
||||
if stock_check_item = StockCheckItem.find_by_item_code_and_shop_code(item.item_instance_code,Shop.current_shop.shop_code)
|
||||
return true, product
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_balance(item, inventory_definition) # item => saleItemOBj
|
||||
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
|
||||
puts "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OUT OF STOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
|
||||
StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS)
|
||||
end
|
||||
|
||||
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
|
||||
StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS)
|
||||
end
|
||||
end
|
||||
|
||||
def self.modify_balance(item, stock, inventory_definition) #saleitemObj
|
||||
@@ -75,6 +64,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
elsif item.is_a? SaleItem
|
||||
trans_type = StockJournal::SALES_TRANS
|
||||
end
|
||||
# StockJournal.add_to_journal(instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type)
|
||||
StockJournal.add_to_journal(item.item_instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type)
|
||||
check_item.different = check_item.different - qty
|
||||
check_item.save
|
||||
|
||||
@@ -3,13 +3,13 @@ class KbzPay
|
||||
KBZ_PAY = 'KBZPay'
|
||||
|
||||
def self.pay(amount, receipt_no, url, key, app_id, code)
|
||||
shop = Shop.first
|
||||
shop = Shop.current_shop
|
||||
prefix = shop.shop_code
|
||||
receipt_no = "#{prefix}#{receipt_no}"
|
||||
|
||||
datetime = DateTime.now.strftime("%d%m%Y%H%M")
|
||||
kbz_app_id = app_id
|
||||
kbz_merch_code = code
|
||||
kbz_merch_code = code
|
||||
kbz_api_key = key
|
||||
kbz_provider_url = "#{url}/precreate"
|
||||
|
||||
@@ -58,17 +58,17 @@ class KbzPay
|
||||
# Rails.logger.debug result['Response']
|
||||
return false, result['Response']
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def self.query(receipt_no, current_user, url, key, app_id, code)
|
||||
shop = Shop.first
|
||||
shop = Shop.current_shop
|
||||
prefix = shop.shop_code
|
||||
receipt_no = "#{prefix}#{receipt_no}"
|
||||
amount = 0
|
||||
datetime = DateTime.now.strftime("%d%m%Y%H%M")
|
||||
kbz_app_id = app_id
|
||||
kbz_merch_code = code
|
||||
kbz_merch_code = code
|
||||
kbz_api_key = key
|
||||
kbz_provider_url = "#{url}/queryorder"
|
||||
|
||||
@@ -122,7 +122,7 @@ class KbzPay
|
||||
|
||||
# return true, "successfully paid by KBZ PAY"
|
||||
elsif result['Response']['trade_status'] == "PAY_FAILED"
|
||||
|
||||
|
||||
# return false, "pay failed by KBZ PAY"
|
||||
elsif result['Response']['trade_status'] == "WAIT_PAY"
|
||||
# return false , "Waiting to pay by KBZ PAY"
|
||||
@@ -135,4 +135,4 @@ class KbzPay
|
||||
return amount
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,22 +18,22 @@ class License
|
||||
if (server != "")
|
||||
self.class.base_uri server
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# For Cloud
|
||||
def detail_with_local_cache(lookup)
|
||||
def detail_with_local_cache(lookup)
|
||||
aes = MyAesCrypt.new
|
||||
aes_key, aes_iv = aes.export_to_file(lookup)
|
||||
|
||||
aes_key, aes_iv = aes.export_to_file(lookup)
|
||||
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "#{lookup}:license:#{aes_key}:hostname"
|
||||
cache_key = "#{lookup}:license:#{aes_key}:hostname"
|
||||
|
||||
cache_license = nil
|
||||
|
||||
##Get redis connection from connection pool
|
||||
redis = Redis.new
|
||||
cache_license = redis.get(cache_key)
|
||||
|
||||
cache_license = redis.get(cache_key)
|
||||
|
||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
if cache_license.nil?
|
||||
##change the d/e key
|
||||
@@ -41,12 +41,13 @@ class License
|
||||
@params = { query: { lookup_type: self.server_mode, lookup: lookup, iv_key: aes_iv} }
|
||||
response = self.class.get("/subdomain", @params)
|
||||
@license = response.parsed_response
|
||||
Rails.logger.info "License Response - " + response.parsed_response.to_s
|
||||
|
||||
if (@license["status"] == true)
|
||||
assign(aes_key, aes_iv)
|
||||
|
||||
# Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
|
||||
#Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
|
||||
redis = Redis.new
|
||||
redis.set(cache_key, Marshal.dump(@license))
|
||||
# redis.sadd("License:cache:keys", cache_key)
|
||||
@@ -59,36 +60,36 @@ class License
|
||||
|
||||
return true
|
||||
end
|
||||
else
|
||||
else
|
||||
@license = Marshal.load(cache_license)
|
||||
assign(aes_key, aes_iv)
|
||||
# Rails.logger.info 'API License'
|
||||
# Rails.logger.info 'API License'
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
# For Local System
|
||||
def detail_with_local_file()
|
||||
def detail_with_local_file()
|
||||
renewal_date_str = read_license("renewable_date")
|
||||
if check_expiring(renewal_date_str)
|
||||
# return for all ok
|
||||
if check_expiring(renewal_date_str)
|
||||
# return for all ok
|
||||
return 1
|
||||
else
|
||||
has_license = verify_license()
|
||||
if has_license
|
||||
# return for expiring
|
||||
# return for expiring
|
||||
return 2
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
# end
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
# License Activation
|
||||
def license_activate (shop, license_key, db_host, db_schema, db_user, db_password)
|
||||
aes = MyAesCrypt.new
|
||||
aes_key, aes_iv = aes.export_key(license_key)
|
||||
aes = MyAesCrypt.new
|
||||
aes_key, aes_iv = aes.export_key(license_key)
|
||||
|
||||
@params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } }
|
||||
response = self.class.get("/activate", @params)
|
||||
@@ -96,21 +97,21 @@ class License
|
||||
|
||||
if (@activate["status"])
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "shop:#{@activate["shop_name"]}"
|
||||
cache_key = "shop:#{@activate["shop_name"]}"
|
||||
|
||||
cache_license = nil
|
||||
cache_license = nil
|
||||
|
||||
##Get redis connection from connection pool
|
||||
redis = Redis.new
|
||||
cache_license = redis.get(cache_key)
|
||||
cache_license = redis.get(cache_key)
|
||||
|
||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
|
||||
if cache_license.nil?
|
||||
cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] }
|
||||
if cache_license.nil?
|
||||
cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] }
|
||||
redis = Redis.new
|
||||
redis.set(cache_key, Marshal.dump(cache))
|
||||
end
|
||||
end
|
||||
|
||||
Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
|
||||
@@ -120,21 +121,21 @@ class License
|
||||
sym_path = File.expand_path("~/symmetric/")
|
||||
|
||||
response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password)
|
||||
|
||||
|
||||
if(response[:status])
|
||||
response = run_symmetric(sym_path)
|
||||
end
|
||||
end
|
||||
else
|
||||
response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"}
|
||||
end
|
||||
end
|
||||
return response
|
||||
end
|
||||
|
||||
def verify_license
|
||||
api_token = read_license_no_decrypt("api_token")
|
||||
def verify_license
|
||||
api_token = read_license_no_decrypt("api_token")
|
||||
@params = { query: {lookup_type: "application", api_token: api_token} }
|
||||
|
||||
|
||||
begin
|
||||
response = self.class.get("/verify", @params)
|
||||
@varified = response.parsed_response
|
||||
@@ -145,7 +146,7 @@ class License
|
||||
end
|
||||
else
|
||||
delete_license_file
|
||||
end
|
||||
end
|
||||
|
||||
rescue SocketError => e
|
||||
Rails.logger.debug "In SocketError No Internet connection ! "
|
||||
@@ -159,21 +160,21 @@ class License
|
||||
rescue OpenURI::HTTPError
|
||||
Rails.logger.debug "Can't connect server"
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
# Check Expired before 30 days
|
||||
def check_expiring(renewal_date_str)
|
||||
def check_expiring(renewal_date_str)
|
||||
if !renewal_date_str.empty?
|
||||
renewal_date = DateTime.parse(renewal_date_str)
|
||||
renewal_date = DateTime.parse(renewal_date_str)
|
||||
renewal_date > Date.today.advance(:days => 30)
|
||||
end
|
||||
end
|
||||
|
||||
# Check License expired date from PROVISION SERVER
|
||||
def check_expired(renewal_date_str)
|
||||
def check_expired(renewal_date_str)
|
||||
expired_date_str = read_license("renewable_date")
|
||||
renewal_date = DateTime.parse(renewal_date_str)
|
||||
if(renewal_date_str != expired_date_str)
|
||||
@@ -186,32 +187,32 @@ class License
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Check License File exists
|
||||
def self.check_license_file
|
||||
return File.exist?("config/license.yml")
|
||||
return File.exist?("config/license.yml")
|
||||
end
|
||||
|
||||
# read line by key for license file
|
||||
def read_license(key_name)
|
||||
decrypted_line = ""
|
||||
def read_license(key_name)
|
||||
decrypted_line = ""
|
||||
key, iv = get_redis_key()
|
||||
|
||||
if File.exist?("config/license.yml")
|
||||
if File.exist?("config/license.yml")
|
||||
File.open("config/license.yml").each do |line|
|
||||
if line.include? (key_name)
|
||||
decrypted_line_array = line.split(": ")
|
||||
if line.include? (key_name)
|
||||
decrypted_line_array = line.split(": ")
|
||||
decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return decrypted_line
|
||||
end
|
||||
|
||||
# read line by key for license file without decrypt
|
||||
def read_license_no_decrypt(key)
|
||||
decrypted_line = ""
|
||||
if File.exist?("config/license.yml")
|
||||
if File.exist?("config/license.yml")
|
||||
File.open("config/license.yml").each do |line|
|
||||
if line.include? (key)
|
||||
decrypted_line_array = line.split(": ")
|
||||
@@ -226,18 +227,18 @@ class License
|
||||
def update_license(content, new_content)
|
||||
key, iv = get_redis_key()
|
||||
|
||||
if !new_content.include? "=="
|
||||
if !new_content.include? "=="
|
||||
crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||
end
|
||||
|
||||
|
||||
content_str = read_license_no_decrypt(content)
|
||||
if File.exist?("config/license.yml")
|
||||
if File.exist?("config/license.yml")
|
||||
file_str = File.read("config/license.yml")
|
||||
new_file_str = file_str.gsub(content_str, encode_str(crypted_str))
|
||||
|
||||
# To write changes to the file, use:
|
||||
File.open("config/license.yml", "w") {|file| file.puts new_file_str }
|
||||
|
||||
|
||||
# File.open("config/license.yml").each do |line|
|
||||
# new_file_str = line.gsub(content, crypted_str)
|
||||
# f.put
|
||||
@@ -247,33 +248,33 @@ class License
|
||||
|
||||
# Re-get keys
|
||||
def get_key
|
||||
api_token = read_license_no_decrypt("api_token")
|
||||
shop_name = read_license_no_decrypt("shop_name")
|
||||
api_token = read_license_no_decrypt("api_token")
|
||||
shop_name = read_license_no_decrypt("shop_name")
|
||||
@params = { query: {lookup_type: "application", api_token: api_token } }
|
||||
response = self.class.get("/get_key", @params)
|
||||
@data = response.parsed_response
|
||||
|
||||
|
||||
if (@data["status"])
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "shop:#{shop_name.chomp}"
|
||||
cache_key = "shop:#{shop_name.chomp}"
|
||||
|
||||
cache_license = nil
|
||||
cache_license = nil
|
||||
|
||||
##Get redis connection from connection pool
|
||||
redis = Redis.new
|
||||
cache_license = redis.get(cache_key)
|
||||
cache_license = redis.get(cache_key)
|
||||
|
||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
|
||||
if cache_license.nil?
|
||||
cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["renewable_date"] }
|
||||
if cache_license.nil?
|
||||
cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["renewable_date"] }
|
||||
redis = Redis.new
|
||||
redis.set(cache_key, Marshal.dump(cache))
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def get_redis_key
|
||||
@@ -281,18 +282,18 @@ class License
|
||||
key = ""
|
||||
shop = read_license_no_decrypt("shop_name")
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "shop:#{shop.chomp}"
|
||||
cache_key = "shop:#{shop.chomp}"
|
||||
|
||||
cache_shop = nil
|
||||
cache_shop = nil
|
||||
|
||||
##Get redis connection from connection pool
|
||||
redis = Redis.new
|
||||
cache_shop = redis.get(cache_key)
|
||||
cache_shop = redis.get(cache_key)
|
||||
|
||||
if !cache_shop.nil?
|
||||
@shop = Marshal.load(cache_shop)
|
||||
key = @shop["key"]
|
||||
iv = @shop["iv"]
|
||||
if !cache_shop.nil?
|
||||
@shop = Marshal.load(cache_shop)
|
||||
key = @shop["key"]
|
||||
iv = @shop["iv"]
|
||||
end
|
||||
return key, iv
|
||||
end
|
||||
@@ -307,13 +308,13 @@ class License
|
||||
|
||||
# License File Creation
|
||||
def create_license_file(response_data)
|
||||
if File.exist?("config/license.yml")
|
||||
if File.exist?("config/license.yml")
|
||||
delete_license_file
|
||||
end
|
||||
|
||||
begin
|
||||
# Licese File Creation
|
||||
File.open("config/license.yml", "w") do |f|
|
||||
File.open("config/license.yml", "w") do |f|
|
||||
f.puts("iv_key: #{response_data['iv_key']}")
|
||||
f.puts("shop_name: #{response_data['shop_name']}")
|
||||
f.puts("email: #{response_data['email']}")
|
||||
@@ -325,11 +326,11 @@ class License
|
||||
f.puts("dbusername: #{response_data['dbusername']}")
|
||||
f.puts("dbpassword: #{response_data['dbpassword']}")
|
||||
f.puts("api_token: #{response_data['api_token']}")
|
||||
f.puts("app_token: #{response_data['app_token']}")
|
||||
f.puts("app_token: #{response_data['app_token']}")
|
||||
f.puts("plan_sku: #{response_data['plan_sku']}")
|
||||
f.puts("renewable_date: #{response_data['renewable_date']}")
|
||||
f.puts("plan_name: #{response_data['plan_name']}")
|
||||
end
|
||||
end
|
||||
rescue IOError
|
||||
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
|
||||
end
|
||||
@@ -352,15 +353,15 @@ class License
|
||||
f.write("group.id=sx\n")
|
||||
f.write("external.id=000\n")
|
||||
f.write("job.purge.period.time.ms=7200000\n")
|
||||
f.write("job.routing.period.time.ms=5000\n")
|
||||
f.write("job.push.period.time.ms=10000\n")
|
||||
f.write("job.pull.period.time.ms=10000\n")
|
||||
f.write("initial.load.create.first=true\n")
|
||||
f.write("job.routing.period.time.ms=5000\n")
|
||||
f.write("job.push.period.time.ms=10000\n")
|
||||
f.write("job.pull.period.time.ms=10000\n")
|
||||
f.write("initial.load.create.first=true\n")
|
||||
f.write("initial.load.use.extract.job.enabled=true\n")
|
||||
f.write("rest.api.enable=true\n")
|
||||
f.close
|
||||
f.close
|
||||
|
||||
# read from license file
|
||||
# read from license file
|
||||
# shop_name = read_license_no_decrypt("shop_name")
|
||||
shop_name = "cloud"
|
||||
dbhost = read_license("dbhost")
|
||||
@@ -378,12 +379,12 @@ class License
|
||||
f.write("registration.url=http://#{db_host}:31415/sync/sx\n")
|
||||
f.write("group.id=cloud\n")
|
||||
f.write("external.id=001\n")
|
||||
f.write("job.routing.period.time.ms=5000\n")
|
||||
f.write("job.push.period.time.ms=10000\n")
|
||||
f.write("job.routing.period.time.ms=5000\n")
|
||||
f.write("job.push.period.time.ms=10000\n")
|
||||
f.write("job.pull.period.time.ms=10000\n")
|
||||
f.write("rest.api.enable=true\n")
|
||||
# f.write("initial.load.create.first=true\n")
|
||||
# f.write("initial.load.use.extract.job.enabled=true\n")
|
||||
# f.write("initial.load.create.first=true\n")
|
||||
# f.write("initial.load.use.extract.job.enabled=true\n")
|
||||
f.close
|
||||
rescue IOError
|
||||
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
|
||||
@@ -392,12 +393,12 @@ class License
|
||||
end
|
||||
end
|
||||
|
||||
# Run Symmetric
|
||||
# Run Symmetric
|
||||
def run_symmetric(sym_path)
|
||||
# check_sym_proc_str = `#{sym_path + "bin/sym_service status"}`
|
||||
# check_sym_proc_str = check_sym_proc_str.split("\n")
|
||||
# sym_install_status = check_sym_proc_str[0].split(": ")
|
||||
|
||||
|
||||
check_sym_proc_str = `#{"sudo service SymmetricDS status"}`
|
||||
|
||||
# Check Sym Installed
|
||||
@@ -412,7 +413,7 @@ class License
|
||||
check_sym_table = system("sudo " + sym_path + "/bin/symadmin --engine sx create-sym-tables")
|
||||
if check_sym_table
|
||||
sym_sql = Rails.root + "db/sym_master.sql"
|
||||
|
||||
|
||||
if File.exist? (sym_sql)
|
||||
# Import Sym Sql to db and start sym
|
||||
run_sym_sql = system("sudo " + sym_path + "/bin/dbimport --engine sx " + sym_sql.to_s)
|
||||
@@ -427,7 +428,7 @@ class License
|
||||
else
|
||||
response = { "status": false, "message": "Activation is success but Cannot create Sym Tables. \n Please contact code2lab call center!"}
|
||||
end
|
||||
else
|
||||
else
|
||||
response = { "status": false, "message": "Activation is success but Symmetric not running. \n Please contact code2lab call center!"}
|
||||
end
|
||||
end
|
||||
@@ -435,7 +436,7 @@ class License
|
||||
# Check Symmetric Running
|
||||
def check_sym_running(status, sym_path)
|
||||
# Run Sym Service
|
||||
# if status.include? "Server is already running"
|
||||
# if status.include? "Server is already running"
|
||||
# return true
|
||||
# elsif status.include? "false"
|
||||
# sym_start_str = `#{sym_path + "bin/sym_service start"}`
|
||||
@@ -443,9 +444,9 @@ class License
|
||||
# return true
|
||||
# else
|
||||
# check_sym_running(sym_start_status[0])
|
||||
# end
|
||||
# end
|
||||
# else
|
||||
# return true
|
||||
# return true
|
||||
# end
|
||||
|
||||
if status.include? "Active: active (running)" || "Active: active (exited)" #"Server is already running"
|
||||
@@ -456,15 +457,15 @@ class License
|
||||
|
||||
# Delete License File
|
||||
def delete_license_file
|
||||
File.delete("config/license.yml") if File.exist?("config/license.yml")
|
||||
File.delete("config/license.yml") if File.exist?("config/license.yml")
|
||||
end
|
||||
|
||||
# Assign db info for Cloud
|
||||
def assign(aes_key, aes_iv)
|
||||
def assign(aes_key, aes_iv)
|
||||
key = Base64.decode64(aes_key)
|
||||
iv = Base64.decode64(aes_iv)
|
||||
|
||||
if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] )
|
||||
|
||||
if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] )
|
||||
host = Base64.decode64(@license["dbhost"])
|
||||
dbschema = Base64.decode64(@license["dbschema"])
|
||||
dbusername = Base64.decode64(@license["dbusername"])
|
||||
@@ -473,8 +474,8 @@ class License
|
||||
self.dbhost = AESCrypt.decrypt_data(host, key, iv, ENV['CIPHER_TYPE'])
|
||||
self.dbschema = AESCrypt.decrypt_data(dbschema, key, iv, ENV['CIPHER_TYPE'])
|
||||
self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE'])
|
||||
self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE'])
|
||||
self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE'])
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,10 @@ class Lookup < ApplicationRecord
|
||||
has_many :accounts
|
||||
belongs_to :shop
|
||||
|
||||
scope :number_formats, -> { where(lookup_type: 'number_format')}
|
||||
|
||||
TIME_LIMIT = 5
|
||||
|
||||
def available_types
|
||||
{'Employee Roles' => 'employee_roles',
|
||||
'Dining Facilities Status' => 'dining_facilities_status',
|
||||
@@ -22,15 +26,15 @@ 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(shop_code)
|
||||
time_limit = 5
|
||||
|
||||
lookup = Lookup.find_by_lookup_type_and_shop_code('checkin_time_limit',shop_code)
|
||||
if !lookup.nil?
|
||||
time_limit = lookup.value.to_i
|
||||
end
|
||||
def self.time_limit
|
||||
TIME_LIMIT
|
||||
end
|
||||
|
||||
return time_limit
|
||||
|
||||
def self.get_checkin_time_limit
|
||||
return RequestStore[:checkin_time_limit] if RequestStore[:checkin_time_limit]
|
||||
RequestStore[:checkin_time_limit] = Lookup.find_by_lookup_type('checkin_time_limit').value.to_i rescue time_limit
|
||||
end
|
||||
|
||||
def self.sync_url
|
||||
@@ -57,7 +61,6 @@ class Lookup < ApplicationRecord
|
||||
|
||||
def self.collection_of(type)
|
||||
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
|
||||
|
||||
end
|
||||
|
||||
def self.create_shift_sale_lookup(shop_code)
|
||||
|
||||
@@ -141,7 +141,14 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
else
|
||||
# Menu by Menu Import
|
||||
shop_code= shop.shop_code + "_"
|
||||
|
||||
@shop = Shop.current_shop
|
||||
shop_code = ""
|
||||
if !@shop.nil?
|
||||
if @shop.shop_code
|
||||
shop_code = @shop.shop_code + "_"
|
||||
end
|
||||
end
|
||||
|
||||
sheet = spreadsheet.sheet(0)
|
||||
menu = sheet.row(1)[1]
|
||||
|
||||
@@ -591,5 +591,19 @@ class Order < ApplicationRecord
|
||||
Rails.logger.debug '...... order sync completed .....'
|
||||
end
|
||||
end
|
||||
def self.send_message(phone, order_id,shop_name)
|
||||
url = "http://smspoh.com/api/http/send?key=5QfyN0OtGsFXnOqwtpVAGZCyPGP28nbX_Nm_oPsUw2ybq714T_951ycz3Ypl5URA&message=Your order "+order_id.to_s+" is ready to pick up ,thanks from "+shop_name.to_s+"&recipients="+ phone.to_s
|
||||
|
||||
begin
|
||||
@result = HTTParty.get(url.to_str)
|
||||
rescue HTTParty::Error
|
||||
response = {status: false, message: "Can't open membership server "}
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false , message: "Can't open membership server "}
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false, message: "Can't open membership server "}
|
||||
rescue SocketError
|
||||
response = { status: false, message: "Can't open membership server "}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -125,42 +125,14 @@ class OrderItem < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_stock_journal
|
||||
if self.set_menu_items.present?
|
||||
puts "set menu itemsssssssss???????????????????????????????"
|
||||
puts items = JSON.parse(self.set_menu_items)
|
||||
instance_code = Array.new
|
||||
count = 0
|
||||
items.each { |i|
|
||||
instance_code.push(i["item_instance_code"])
|
||||
}
|
||||
print instance_code
|
||||
end
|
||||
if self.qty != self.qty_before_last_save
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.order.shop_code)
|
||||
if found
|
||||
InventoryDefinition.check_balance(self, inventory_definition)
|
||||
|
||||
unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code)
|
||||
if self.qty != self.qty_before_last_save
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
|
||||
if found
|
||||
InventoryDefinition.check_balance(self, inventory_definition)
|
||||
end
|
||||
end
|
||||
end
|
||||
# if self.qty > self.qty_was
|
||||
# credit = 0
|
||||
# debit = self.qty.to_i - self.qty_was.to_i
|
||||
# else
|
||||
# credit = self.qty_was.to_i - self.qty.to_i
|
||||
# debit = 0
|
||||
# end
|
||||
# if credit != debit
|
||||
# defination = InventoryDefinition.find_by_item_code(self.item_instance_code)
|
||||
# stock = StockJournal.where('item_code = ?', self.item_instance_code).order("id DESC").first
|
||||
# journal = StockJournal.create(
|
||||
# item_code: self.item_instance_code,
|
||||
# credit: credit,
|
||||
# debit: debit,
|
||||
# balance: stock.balance - debit + credit,
|
||||
# inventory_definition_id: defination.id,
|
||||
# remark: 'ok',
|
||||
# trans_ref: self.order.id,
|
||||
# trans_type: StockJournal::SALES_TRANS
|
||||
# )
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -297,8 +297,9 @@ class OrderQueueStation < ApplicationRecord
|
||||
@type = (DiningFacility.find(change_to)).type
|
||||
@moved_by = current_user
|
||||
@date = DateTime.now
|
||||
@shop = Shop.find_by_shop_code(oqs.shop_code)
|
||||
unique_code = "MoveTablePdf"
|
||||
|
||||
@shop = Shop.current_shop
|
||||
unique_code = "MoveTablePdf"
|
||||
# pdf_no = PrintSetting.where(:unique_code => unique_code).count
|
||||
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
||||
# printer_array = []
|
||||
|
||||
@@ -157,7 +157,8 @@ 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.find_by_shop_code(order.shop_code)
|
||||
|
||||
shop_details = Shop.current_shop
|
||||
# rounding adjustment
|
||||
if shop_details.is_rounding_adj
|
||||
a = saleObj.grand_total % 25 # Modulus
|
||||
@@ -194,7 +195,8 @@ 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.current_shop
|
||||
order_reservation = OrderReservation.get_order_reservation_info(saleObj.sale_id)
|
||||
if !cashier_terminal.nil?
|
||||
# Calculate Food and Beverage Total
|
||||
@@ -203,7 +205,7 @@ 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_details, "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,nil)
|
||||
#receipt bill pdf setting
|
||||
|
||||
result = {:status=> true,
|
||||
@@ -400,7 +402,7 @@ class OrderReservation < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.check_new_order
|
||||
shop = Shop.find_by_id(1)
|
||||
shop = Shop.current_shop
|
||||
if !shop.shop_code.nil?
|
||||
shop_code = shop.shop_code
|
||||
else
|
||||
@@ -418,7 +420,7 @@ class OrderReservation < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.check_order_send_to_kitchen
|
||||
shop = Shop.find_by_id(1)
|
||||
shop = Shop.current_shop
|
||||
if !shop.shop_code.nil?
|
||||
shop_code = shop.shop_code
|
||||
else
|
||||
@@ -436,7 +438,7 @@ class OrderReservation < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.check_order_ready_to_delivery
|
||||
shop = Shop.find_by_id(1)
|
||||
shop = Shop.current_shop
|
||||
if !shop.shop_code.nil?
|
||||
shop_code = shop.shop_code
|
||||
else
|
||||
|
||||
@@ -38,7 +38,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
end
|
||||
# end
|
||||
|
||||
# shop = Shop.first
|
||||
|
||||
# shop = Shop.current_shop
|
||||
directory_name = 'public/orders_'+oqs.shop_code
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
@@ -80,8 +81,10 @@ 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_'+oqs.shop_code
|
||||
|
||||
# shop = Shop.current_shop
|
||||
directory_name = 'public/orders_'+ oqs.shop_code
|
||||
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
# For Print Per Item
|
||||
@@ -192,7 +195,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
order=print_query('booking_summary', booking_id)
|
||||
|
||||
# shop = Shop.first
|
||||
|
||||
# shop = Shop.current_shop
|
||||
directory_name = 'public/orders_'+oqs.shop_code
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
@@ -294,7 +298,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
# Query for OQS with status
|
||||
def print_query(type, id)
|
||||
if type == "order_item"
|
||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
||||
OrderItem.select("orders.source,cus.contact_no,rder_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
@@ -304,7 +308,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
.where("order_items.order_items_id = '#{ id }'")
|
||||
.group("order_items.item_code")
|
||||
elsif type == "order_summary"
|
||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
||||
OrderItem.select("orders.source,cus.contact_no,order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
@@ -315,7 +319,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
.group("order_items.order_items_id")
|
||||
else
|
||||
# order summary for booking
|
||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
||||
OrderItem.select("orders.source,cus.contact_no,order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
|
||||
@@ -188,20 +188,20 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
||||
end
|
||||
|
||||
#Bill Receipt Print
|
||||
def print_receipt_bill(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation)
|
||||
def print_receipt_bill(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation,transaction_ref)
|
||||
#Use CUPS service
|
||||
#Generate PDF
|
||||
#Print
|
||||
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)
|
||||
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,transaction_ref)
|
||||
settings = PrintSetting.where("shop_code='#{shop_details.shop_code}'")
|
||||
if !settings.nil?
|
||||
settings.each do |setting|
|
||||
if setting.unique_code == 'ReceiptBillPdf'
|
||||
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)
|
||||
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,transaction_ref)
|
||||
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
||||
pdf = ReceiptBillStarPdf.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)
|
||||
pdf = ReceiptBillStarPdf.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,transaction_ref)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -211,7 +211,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
||||
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
||||
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
||||
if receipt_bilA5[1] == '1'
|
||||
pdf = ReceiptBillA5Pdf.new(printer_settings, 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)
|
||||
pdf = ReceiptBillA5Pdf.new(printer_settings, 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,transaction_ref)
|
||||
# else
|
||||
# pdf = ReceiptBillPdf.new(printer_settings, 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)
|
||||
end
|
||||
|
||||
@@ -15,11 +15,11 @@ class Promotion < ApplicationRecord
|
||||
promo_day.include? Date.today.wday.to_s
|
||||
end
|
||||
|
||||
def self.promo_activate(saleObj,shop_code)
|
||||
def self.promo_activate(saleObj)
|
||||
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,shop_code)
|
||||
promoList = is_between_promo_datetime(current_day,current_time)
|
||||
|
||||
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,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)
|
||||
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)
|
||||
return promoList
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
class Room < DiningFacility
|
||||
|
||||
has_many :bookings, :foreign_key => 'dining_facility_id'
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ class SaleAudit < ApplicationRecord
|
||||
|
||||
belongs_to :sale
|
||||
|
||||
belongs_to :credit_payment, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment"
|
||||
belongs_to :sale_payments_for_credit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment"
|
||||
|
||||
def self.sync_sale_audit_records(sale_audits)
|
||||
if !sale_audits.nil?
|
||||
@@ -150,6 +150,7 @@ class SaleAudit < ApplicationRecord
|
||||
|
||||
def self.getCardBalanceAmount(sale_id)
|
||||
card_balance_amount = 0
|
||||
transaction_ref =''
|
||||
sale_audits = SaleAudit.where("sale_id='#{sale_id}' AND action='PAYMAL'")
|
||||
if !sale_audits.nil?
|
||||
sale_audits.each do |sale_audit|
|
||||
@@ -159,6 +160,7 @@ class SaleAudit < ApplicationRecord
|
||||
if remark[0]
|
||||
if remark[0]["status"]
|
||||
card_balance_amount = remark[0]["card_balance_amount"]
|
||||
transaction_ref = remark[0]["transaction_ref"]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -166,7 +168,7 @@ class SaleAudit < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
return card_balance_amount
|
||||
return card_balance_amount,transaction_ref
|
||||
end
|
||||
|
||||
def self.valid_json(json)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class SaleItem < ApplicationRecord
|
||||
include NumberFormattable
|
||||
self.primary_key = "sale_item_id"
|
||||
|
||||
#primary key - need to be unique generated for multiple shops
|
||||
@@ -13,6 +14,7 @@ class SaleItem < ApplicationRecord
|
||||
|
||||
before_validation :round_to_precision
|
||||
after_update :update_stock_journal
|
||||
after_save :update_stock_journal_set_item
|
||||
|
||||
# Add Sale Items
|
||||
def self.add_sale_items(sale_items)
|
||||
@@ -293,8 +295,6 @@ class SaleItem < ApplicationRecord
|
||||
if self.unit_price != self.unit_price_was || self.price != self.price_was
|
||||
if unit_price_fraction > 0 || price_fraction > 0
|
||||
if ['Discount', 'promotion'].include?(self.status)
|
||||
precision = PrintSetting.get_precision_delimiter().precision.to_i
|
||||
|
||||
self.unit_price = self.unit_price.round(precision)
|
||||
self.price = (self.unit_price * self.qty).round(precision)
|
||||
self.taxable_price = self.price
|
||||
@@ -304,40 +304,42 @@ class SaleItem < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_stock_journal
|
||||
is_void = self.status == "void" && self.status_before_last_save != "void"
|
||||
cancel_void = self.status_before_last_save == "void" && self.status.nil?
|
||||
is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save
|
||||
is_foc = self.status == "foc" && self.status_before_last_save != "foc"
|
||||
cancel_foc = self.status_before_last_save == "foc"
|
||||
unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code)
|
||||
is_void = self.status == "void" && self.status_before_last_save != "void"
|
||||
cancel_void = self.status_before_last_save == "void" && self.status.nil?
|
||||
is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save
|
||||
is_foc = self.status == "foc" && self.status_before_last_save != "foc"
|
||||
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,self.sale.shop_code)
|
||||
if found
|
||||
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("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
|
||||
remark = "void"
|
||||
elsif cancel_void
|
||||
qty = self.qty
|
||||
remark = "cancel void"
|
||||
elsif is_edit
|
||||
qty = self.qty - self.qty_before_last_save
|
||||
remark = "edit"
|
||||
end
|
||||
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
|
||||
check_item.different = check_item.different + qty
|
||||
check_item.save
|
||||
else is_foc or cancel_foc
|
||||
qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit")
|
||||
if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id
|
||||
if stock_journal = StockJournal.find_by_trans_ref(order_item_id)
|
||||
if is_foc
|
||||
stock_journal.update(remark: "foc")
|
||||
elsif cancel_foc
|
||||
stock_journal.update(remark: "cancel_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)
|
||||
if found
|
||||
stock = StockJournal.where('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
|
||||
if is_void or cancel_void or is_edit
|
||||
if is_void
|
||||
qty = -self.qty
|
||||
remark = "void"
|
||||
elsif cancel_void
|
||||
qty = self.qty
|
||||
remark = "cancel void"
|
||||
elsif is_edit
|
||||
qty = self.qty - self.qty_before_last_save
|
||||
remark = "edit"
|
||||
end
|
||||
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
|
||||
check_item.different = check_item.different + qty
|
||||
check_item.save
|
||||
else is_foc or cancel_foc
|
||||
qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit")
|
||||
if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id
|
||||
if stock_journal = StockJournal.find_by_trans_ref(order_item_id)
|
||||
if is_foc
|
||||
stock_journal.update(remark: "foc")
|
||||
elsif cancel_foc
|
||||
stock_journal.update(remark: "cancel_foc")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -346,4 +348,80 @@ class SaleItem < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_stock_journal_set_item
|
||||
is_void = self.status == "void" && self.status_before_last_save != "void" && self.qty > 0
|
||||
cancel_void = self.status_before_last_save == "void" && self.status.nil?
|
||||
is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save
|
||||
is_foc = self.status == "foc" && self.status_before_last_save != "foc"
|
||||
cancel_foc = self.status_before_last_save == "foc"
|
||||
|
||||
is_waste = self.status == "waste"
|
||||
is_spoile = self.status == "spoile"
|
||||
|
||||
if MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code)
|
||||
if self.qty == 1 && self.qty != self.qty_before_last_save
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
|
||||
if found
|
||||
stock = StockJournal.where('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
|
||||
if self.qty.to_i >= 0
|
||||
qty = self.qty - self.qty_was
|
||||
if stock.balance.to_i >= qty
|
||||
Rails.logger.info ">> stock is greater than order qty"
|
||||
remark = "ok"
|
||||
else
|
||||
Rails.logger.info " << stock is less than order qty"
|
||||
remark = "out of stock"
|
||||
end
|
||||
end
|
||||
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
|
||||
check_item.different = check_item.different - qty
|
||||
check_item.save
|
||||
else
|
||||
StockJournal.add_to_journal(self.item_instance_code, self.qty, 0, "out of stock", inventory_definition, self.id, StockJournal::SALES_TRANS)
|
||||
end
|
||||
end
|
||||
elsif is_void or cancel_void or is_edit
|
||||
if is_void
|
||||
qty = -self.qty
|
||||
remark = "void"
|
||||
elsif cancel_void
|
||||
qty = self.qty
|
||||
remark = "cancel void"
|
||||
elsif is_edit
|
||||
qty = self.qty - self.qty_before_last_save
|
||||
remark = "edit"
|
||||
end
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
|
||||
if found
|
||||
stock = StockJournal.where('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
|
||||
|
||||
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
|
||||
check_item.different = check_item.different + qty
|
||||
check_item.save
|
||||
end
|
||||
end
|
||||
elsif is_foc or cancel_foc
|
||||
qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit")
|
||||
if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code).order(id: :desc).first
|
||||
if is_foc
|
||||
stock_journal.update(remark: "foc")
|
||||
elsif cancel_foc
|
||||
stock_journal.update(remark: "cancel_foc")
|
||||
end
|
||||
end
|
||||
elsif is_waste or is_spoile
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
|
||||
if found
|
||||
if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code)
|
||||
stock_journal.update(remark: self.status)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,8 +70,6 @@ class SalePayment < ApplicationRecord
|
||||
self.sale = invoice
|
||||
self.received_amount = cash_amount
|
||||
self.payment_reference = remark
|
||||
# puts action_by
|
||||
# puts "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
self.action_by = action_by
|
||||
#get all payment for this invoices
|
||||
if payment_for
|
||||
@@ -87,7 +85,7 @@ class SalePayment < ApplicationRecord
|
||||
amount_due = amount_due - payment.payment_amount
|
||||
end
|
||||
end
|
||||
if (amount_due >= 0)
|
||||
if (amount_due > 0)
|
||||
payment_status = false
|
||||
membership_data = nil
|
||||
#route to payment type
|
||||
@@ -227,14 +225,14 @@ class SalePayment < ApplicationRecord
|
||||
'Accept' => 'application/json; version=3'
|
||||
}, :timeout => 10
|
||||
)
|
||||
rescue Errno::ECONNREFUSED
|
||||
response = { "status" => false, "message" => "Can't open membership server"}
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false }
|
||||
|
||||
response = { "status" => false, "message" => "No internet connection " }
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false}
|
||||
|
||||
response = { "status" => false, "message" => "No internet connection "}
|
||||
rescue SocketError
|
||||
response = { status: false}
|
||||
response = { "status" => false, "message" => "No internet connection "}
|
||||
end
|
||||
Rails.logger.debug "Get Paypar Account "
|
||||
Rails.logger.debug response.to_json
|
||||
@@ -242,10 +240,7 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id)
|
||||
# membership_actions_data = MembershipAction.find_by_membership_type("redeem");
|
||||
membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem")
|
||||
puts "This is membership_actions_data"
|
||||
puts membership_actions_data.to_json
|
||||
if !membership_actions_data.nil?
|
||||
|
||||
url = paypar_url.to_s + membership_actions_data.gateway_url.to_s
|
||||
@@ -335,7 +330,6 @@ class SalePayment < ApplicationRecord
|
||||
auth_token:auth_token}.to_json
|
||||
end
|
||||
|
||||
puts params
|
||||
# Control for Paypar Cloud
|
||||
begin
|
||||
response = HTTParty.post(url,
|
||||
@@ -539,11 +533,8 @@ class SalePayment < ApplicationRecord
|
||||
payment_status = false
|
||||
|
||||
#Next time - validate if the vochure number is valid - within
|
||||
# customer_data = Customer.find_by_customer_id(self.sale.customer_id)
|
||||
account_no = self.payment_reference
|
||||
# if account_no.to_i <= 0
|
||||
# account_no = customer_data.membership_id
|
||||
# end
|
||||
# self.sale.customer.update_attributes(paypar_account_no: )
|
||||
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",self.sale.shop_code)
|
||||
membership_data = SalePayment.create_payment(membership_setting.gateway_url,"PAYMAL",account_no,self.received_amount,self.sale.sale_id)
|
||||
|
||||
@@ -554,7 +545,7 @@ class SalePayment < ApplicationRecord
|
||||
if membership_data["status"]==true
|
||||
self.payment_method = "paymal"
|
||||
self.payment_amount = self.received_amount
|
||||
self.payment_reference = self.voucher_no
|
||||
# self.payment_reference = self.voucher_no
|
||||
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||
self.payment_status = "paid"
|
||||
payment_status = self.save!
|
||||
@@ -783,27 +774,14 @@ class SalePayment < ApplicationRecord
|
||||
def table_update_status(sale_obj)
|
||||
status = true
|
||||
sale_count = 0
|
||||
booking = Booking.find_by_sale_id(sale_obj.id)
|
||||
if booking
|
||||
if booking = sale_obj.bookings[0]
|
||||
if booking.dining_facility_id.to_i > 0
|
||||
table = DiningFacility.find(booking.dining_facility_id)
|
||||
bookings = table.bookings
|
||||
bookings.each do |tablebooking|
|
||||
if tablebooking.booking_status != 'moved'
|
||||
if tablebooking.sale_id
|
||||
if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste'
|
||||
status = false
|
||||
sale_count += 1
|
||||
else
|
||||
status = true
|
||||
end
|
||||
else
|
||||
status = false
|
||||
sale_count += 1
|
||||
end
|
||||
end
|
||||
table = booking.dining_facility
|
||||
if Booking.left_joins(:sale).where(dining_facility_id: booking.dining_facility_id).where.not(booking_status: 'moved').where("sales.sale_status NOT IN ('completed', 'void', 'spoile', 'waste') OR sales.sale_status IS NULL").exists?
|
||||
status = false
|
||||
end
|
||||
if status && sale_count == 0
|
||||
|
||||
if status
|
||||
table.update_attributes(status: "available")
|
||||
# table.status = "available"
|
||||
# table.save
|
||||
@@ -975,38 +953,34 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
#credit payment query
|
||||
|
||||
def self.get_credit_sales(params,shop_code)
|
||||
receipt_no = ""
|
||||
customer = ""
|
||||
if !params["receipt_no"].blank?
|
||||
receipt_no = " and s.receipt_no LIKE '%#{params["receipt_no"]}%'"
|
||||
payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount")
|
||||
.select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount")
|
||||
|
||||
credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name")
|
||||
.select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name")
|
||||
.joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders)
|
||||
.completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount and sales.shop_code=?",shop_code)
|
||||
.group(:receipt_no)
|
||||
.order(:receipt_date).order(:receipt_no)
|
||||
|
||||
if params["receipt_no"].present?
|
||||
credit_sales = credit_sales.where("sales.receipt_no LIKE ?", "%#{params["receipt_no"]}%")
|
||||
|
||||
end
|
||||
|
||||
if !params["customer_id"].blank?
|
||||
customer = " and s.customer_id = '#{params["customer_id"]}'"
|
||||
if params["customer_id"].present?
|
||||
credit_sales = credit_sales.where("sales.customer_id = ?", params["customer_id"])
|
||||
end
|
||||
|
||||
order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=s.sale_id GROUP BY so.sale_id)"
|
||||
|
||||
query = SalePayment.select("s.receipt_no, sale_payments.sale_payment_id,
|
||||
sale_payments.payment_method,
|
||||
SUM(sale_payments.payment_amount) as payment_amount,
|
||||
s.receipt_date as sale_date,
|
||||
s.sale_id,
|
||||
s.cashier_name as cashier_name, c.name as customer_name")
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.joins("INNER JOIN customers c ON c.customer_id = s.customer_id")
|
||||
|
||||
if params[:type].nil?
|
||||
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' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
||||
elsif params[:type] == "cashier"
|
||||
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]}' OR #{order_source_query}='emenu' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
||||
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}")
|
||||
if params[:type].present?
|
||||
sources = []
|
||||
sources << params[:type]
|
||||
sources << 'emenu' if params[:type] == 'cashier'
|
||||
credit_sales = credit_sales.where("orders.source IN (?)", sources)
|
||||
end
|
||||
query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no")
|
||||
.order("s.receipt_date ASC, s.receipt_no ASC")
|
||||
return query
|
||||
|
||||
end
|
||||
|
||||
def self.get_credit_amount_due_left(sale_id)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class SaleTax < ApplicationRecord
|
||||
include NumberFormattable
|
||||
self.primary_key = "sale_tax_id"
|
||||
|
||||
#primary key - need to be unique generated for multiple shops
|
||||
@@ -44,7 +45,6 @@ class SaleTax < ApplicationRecord
|
||||
def round_to_precision
|
||||
if self.tax_payable_amount != self.tax_payable_amount_was
|
||||
if self.tax_payable_amount % 1 > 0
|
||||
precision = PrintSetting.get_precision_delimiter().precision.to_i
|
||||
self.tax_payable_amount = self.tax_payable_amount.round(precision)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,11 +16,10 @@ class ShiftSale < ApplicationRecord
|
||||
belongs_to :cashier_terminal
|
||||
belongs_to :employee, :foreign_key => 'employee_id'
|
||||
has_many :sales
|
||||
belongs_to :shop
|
||||
|
||||
def self.current_shift(shop_code)
|
||||
def self.current_shift
|
||||
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||
shift = ShiftSale.where("shop_code='#{shop_code}' and shift_started_at is not null and shift_closed_at is null").first
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first
|
||||
return shift
|
||||
end
|
||||
|
||||
@@ -84,6 +83,7 @@ class ShiftSale < ApplicationRecord
|
||||
self.shift_started_at = DateTime.now
|
||||
self.employee_id = current_user.id
|
||||
self.opening_balance = opening_balance
|
||||
self.shop_code = current_user.shop_code
|
||||
self.other_sales = 0
|
||||
self.save
|
||||
end
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
class Shop < ApplicationRecord
|
||||
#ShopDetail = Shop.find_by_id(1)
|
||||
#ShopDetail = Shop.current_shop
|
||||
|
||||
# Shop Image Uploader
|
||||
|
||||
mount_uploader :logo, ShopImageUploader
|
||||
has_many :display_images
|
||||
|
||||
accepts_nested_attributes_for :display_images
|
||||
|
||||
def file_data=(input_data)
|
||||
self.data = input_data.read
|
||||
end
|
||||
|
||||
def self.current_shop
|
||||
ActsAsTenant.current_tenant
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,8 @@ class StockJournal < ApplicationRecord
|
||||
ORDER_TRANS = "order"
|
||||
STOCK_CHECK_TRANS = "stock_check"
|
||||
|
||||
scope :created_at_between, -> (from, to) { where(created_at: from..to)}
|
||||
|
||||
def self.add_to_journal(item_instance_code, qty, old_balance, stock_message, inventory_definition, trans_ref, trans_type) # item => saleObj | balance => Stock journal
|
||||
|
||||
balance = calculate_balance(old_balance, qty)
|
||||
@@ -56,23 +58,14 @@ class StockJournal < ApplicationRecord
|
||||
journal.save
|
||||
end
|
||||
|
||||
def self.inventory_balances(today,from,to,from_time,to_time,shop)
|
||||
|
||||
def self.inventory_balances(from,to, current_shop)
|
||||
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")
|
||||
.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
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")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
|
||||
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.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("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")
|
||||
query = query.created_at_between(from, to)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
class VerifyNumber < ApplicationRecord
|
||||
class VerifyNumber
|
||||
|
||||
def self.send_message(phone, pin)
|
||||
|
||||
url = "http://smspoh.com/api/http/send?key=5QfyN0OtGsFXnOqwtpVAGZCyPGP28nbX_Nm_oPsUw2ybq714T_951ycz3Ypl5URA&message=Doemal,+Pin+Code:+"+pin.to_s+"&recipients="+ phone.to_s
|
||||
url = "http://smspoh.com/api/http/send?key=5QfyN0OtGsFXnOqwtpVAGZCyPGP28nbX_Nm_oPsUw2ybq714T_951ycz3Ypl5URA&message=Local Kitchen,+Pin+Code:+"+pin.to_s+"&recipients="+ phone.to_s
|
||||
|
||||
puts url
|
||||
begin
|
||||
@result = HTTParty.get(url.to_str)
|
||||
|
||||
@@ -18,7 +17,6 @@ class VerifyNumber < ApplicationRecord
|
||||
response = { status: false, message: "Can't open membership server "}
|
||||
end
|
||||
puts @result
|
||||
puts "<><><><><><<><>><><"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user