fixed conflict after merch dev for current shop

This commit is contained in:
Nweni
2019-12-02 19:30:24 +06:30
92 changed files with 1611 additions and 350 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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]

View File

@@ -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 = []

View File

@@ -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
@@ -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

View File

@@ -38,8 +38,9 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
# end
# shop = Shop.first
directory_name = 'public/orders_'+oqs.shop_code
shop = Shop.current_shop
directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf"
@@ -80,8 +81,9 @@ 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_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item
@@ -192,8 +194,9 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
order=print_query('booking_summary', booking_id)
# shop = Shop.first
directory_name = 'public/orders_'+oqs.shop_code
shop = Shop.current_shop
directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item

View File

@@ -1,4 +1,3 @@
class Room < DiningFacility
has_many :bookings, :foreign_key => 'dining_facility_id'
end

View File

@@ -440,7 +440,8 @@ 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.current_shop
#Computation Fields
subtotal_price = 0
@@ -507,7 +508,8 @@ class Sale < ApplicationRecord
# Tax Re-Calculte
def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
shop = Shop.find_by_shop_code(self.shop_code)
shop = Shop.current_shop
#if tax is not apply create new record
# SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax|
@@ -627,7 +629,8 @@ class Sale < ApplicationRecord
# Tax Calculate
def apply_tax(total_taxable, order_source = nil, tax_type = nil)
shop = Shop.find_by_shop_code(self.shop_code)
shop = Shop.current_shop
#if tax is not apply create new record
# SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
@@ -645,7 +648,7 @@ class Sale < ApplicationRecord
order_source = "cashier"
end
# tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id)
# tax_data = TaxProfile.unscope(:order).where("group_type=?",order_source).pluck(:id)
# customer = Customer.find(self.customer_id).tax_profiles
tax_profiles = unique_tax_profiles(order_source, self.customer_id)
@@ -710,7 +713,8 @@ class Sale < ApplicationRecord
end
def adjust_rounding
shop_details = Shop.find_by_shop_code(self.shop_code)
shop_details = Shop.current_shop
# rounding adjustment
if shop_details.is_rounding_adj
new_total = Sale.get_rounding_adjustment(self.grand_total)
@@ -726,7 +730,8 @@ class Sale < ApplicationRecord
#Generate new Receipt No when it is not assigned
def generate_receipt_no
#shop_code and client_code
shop_details = Shop.find_by_shop_code(self.shop_code)
shop_details = Shop.current_shop
#Date-Shift-
if self.receipt_no.nil?
prefix = DateTime.now().utc
@@ -1239,7 +1244,7 @@ end
#product sale report query
def self.get_menu_item_query(order_by)
query = MenuItem.unscoped.select("acc.id as account_id,
query = MenuItem.unscope(:order).select("acc.id as account_id,
acc.title as account_name,
mii.item_instance_code as item_code, " +
"(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," +
@@ -1588,6 +1593,8 @@ end
if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1613,6 +1620,8 @@ end
if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1649,6 +1658,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1668,6 +1679,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1691,6 +1704,8 @@ end
if (!from.nil? && !to.nil?)
query = query.merge(Sale.receipt_date_between(from, to))
else
query = query.merge(Sale.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day))
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1710,6 +1725,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1730,6 +1747,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1760,6 +1779,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1812,6 +1833,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1832,6 +1855,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1899,6 +1924,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1919,6 +1946,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1939,6 +1968,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1960,6 +1991,8 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -2112,6 +2145,8 @@ def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil, curr
.paid.completed.where("sales.shop_code='#{current_shop.shop_code}'")
if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end
if !shift.nil?

View File

@@ -399,11 +399,12 @@ class SaleItem < ApplicationRecord
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
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
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

View File

@@ -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