current shop

This commit is contained in:
Nweni
2019-12-03 13:43:26 +06:30
parent 417d64ecae
commit e0b912bfa0
18 changed files with 98 additions and 111 deletions

View File

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

View File

@@ -25,8 +25,8 @@ class InventoryDefinition < ApplicationRecord
def self.find_product_in_inventory(item)
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)
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

View File

@@ -1585,7 +1585,6 @@ end
def self.top_bottom_products(current_user,from,to,type,current_shop)
puts @current_shop
query = Sale.joins("JOIN sale_items ON sale_items.sale_id = sales.sale_id")
.completed
.where("qty > 0 AND price > 0 AND shop_code='#{current_shop.shop_code}'")
@@ -1768,7 +1767,6 @@ end
query = Sale.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount")
.joins(:sale_payments)
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
.where("sales.shop_code='#{shop.shop_code}'")
.completed
if payment_method == 'card'