fixed conflict
This commit is contained in:
@@ -32,13 +32,12 @@ class InventoryDefinition < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.check_balance(item, inventory_definition) # item => saleItemOBj
|
||||
stock = StockJournal.where('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('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
|
||||
@@ -63,6 +62,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
|
||||
|
||||
@@ -2,6 +2,8 @@ class Lookup < ApplicationRecord
|
||||
|
||||
has_many :accounts
|
||||
|
||||
scope :number_formats, -> { where(lookup_type: 'number_format')}
|
||||
|
||||
def available_types
|
||||
{'Employee Roles' => 'employee_roles',
|
||||
'Dining Facilities Status' => 'dining_facilities_status',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class MenuCategory < ApplicationRecord
|
||||
class MenuCategory < ApplicationRecord
|
||||
# before_create :generate_menu_category_code
|
||||
|
||||
belongs_to :menu
|
||||
belongs_to :menu
|
||||
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
|
||||
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
|
||||
has_many :menu_items
|
||||
@@ -38,9 +38,7 @@ class MenuCategory < ApplicationRecord
|
||||
end
|
||||
|
||||
def valid_time
|
||||
|
||||
menu_category = MenuCategory.find(self.id)
|
||||
menu = Menu.find(menu_category.menu_id)
|
||||
menu = self.menu
|
||||
|
||||
from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S"))
|
||||
to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S"))
|
||||
@@ -64,7 +62,7 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
c +=24
|
||||
current = c*3600 + current_t.min* 60 + current_t.sec
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
else # (after) noon
|
||||
@@ -77,8 +75,8 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
day = Date.today.wday
|
||||
dayresult = menu.valid_days.include?(day.to_s)
|
||||
|
||||
|
||||
|
||||
|
||||
if current.between?(from, to) && menu.valid_days.include?(day.to_s)
|
||||
return true
|
||||
else
|
||||
@@ -104,12 +102,12 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
# def generate_menu_category_code
|
||||
# self.code = SeedGenerator.generate_code(self.class.name, "C")
|
||||
# def generate_menu_category_code
|
||||
# self.code = SeedGenerator.generate_code(self.class.name, "C")
|
||||
# end
|
||||
|
||||
def self.to_csv
|
||||
|
||||
|
||||
mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << mc_attributes
|
||||
@@ -123,7 +121,3 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ class MenuItem < ApplicationRecord
|
||||
belongs_to :account
|
||||
|
||||
has_many :menu_item_sets
|
||||
has_many :item_sets, through: :menu_item_sets
|
||||
has_and_belongs_to_many :item_sets, join_table: "menu_item_sets"
|
||||
|
||||
validates_presence_of :item_code, :name, :type, :min_qty,:account_id
|
||||
validates_uniqueness_of :item_code
|
||||
|
||||
|
||||
default_scope { order('item_code asc') }
|
||||
|
||||
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }
|
||||
|
||||
@@ -125,32 +125,13 @@ class OrderItem < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_stock_journal
|
||||
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)
|
||||
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
|
||||
|
||||
1412
app/models/sale.rb
1412
app/models/sale.rb
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,8 @@ class SaleAudit < ApplicationRecord
|
||||
|
||||
belongs_to :sale
|
||||
|
||||
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?
|
||||
sale_audits.each do |sa|
|
||||
@@ -163,7 +165,7 @@ class SaleAudit < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return card_balance_amount
|
||||
end
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -225,75 +227,6 @@ class SaleItem < ApplicationRecord
|
||||
return sale_items
|
||||
end
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
if self.sale_item_id.nil?
|
||||
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")
|
||||
end
|
||||
end
|
||||
|
||||
def round_to_precision
|
||||
unit_price_fraction = self.unit_price % 1
|
||||
price_fraction = self.unit_price % 1
|
||||
# is_dining_charge = self.menu_category_code == 'DingingCharge'
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
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"
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Loader Service SFTP Start
|
||||
# Detail Sale Data
|
||||
def self.get_detail_sale_data(transaction_date)
|
||||
@@ -314,14 +247,14 @@ class SaleItem < ApplicationRecord
|
||||
sale_items.product_name as item_name,
|
||||
sale_items.qty as qty,
|
||||
CASE
|
||||
WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales'
|
||||
WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales'
|
||||
WHEN s.sale_status = 'waste' THEN 'Waste'
|
||||
WHEN s.sale_status = 'spoile' THEN 'Spoil'
|
||||
END as transaction_type,
|
||||
sale_items.price as gross_sales,
|
||||
'' as discount_code,
|
||||
CASE
|
||||
WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0
|
||||
WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0
|
||||
END as discount_amt,
|
||||
(sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) as sales,
|
||||
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21) as tax_amt,
|
||||
@@ -336,7 +269,7 @@ class SaleItem < ApplicationRecord
|
||||
'0' as is_sampling,
|
||||
'1' as tax_able,
|
||||
CASE
|
||||
WHEN s.sale_status = 'void' THEN 1 ELSE 0
|
||||
WHEN s.sale_status = 'void' THEN 1 ELSE 0
|
||||
END as is_void
|
||||
")
|
||||
.joins("LEFT JOIN sales s ON s.sale_id = sale_items.sale_id")
|
||||
@@ -347,4 +280,146 @@ class SaleItem < ApplicationRecord
|
||||
|
||||
# Loader Service SFTP End
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
if self.sale_item_id.nil?
|
||||
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")
|
||||
end
|
||||
end
|
||||
|
||||
def round_to_precision
|
||||
unit_price_fraction = self.unit_price % 1
|
||||
price_fraction = self.unit_price % 1
|
||||
# is_dining_charge = self.menu_category_code == 'DingingCharge'
|
||||
|
||||
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)
|
||||
self.unit_price = self.unit_price.round(precision)
|
||||
self.price = (self.unit_price * self.qty).round(precision)
|
||||
self.taxable_price = self.price
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_stock_journal
|
||||
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)
|
||||
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
|
||||
end
|
||||
end
|
||||
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
|
||||
puts ">> stock is greater than order qty"
|
||||
remark = "ok"
|
||||
else
|
||||
puts " << 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
|
||||
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
|
||||
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
|
||||
|
||||
@@ -6,8 +6,13 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
belongs_to :sale
|
||||
|
||||
has_one :sale_audit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id"
|
||||
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
|
||||
|
||||
scope :credits, -> { where(payment_method: 'creditnote') }
|
||||
scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) }
|
||||
|
||||
def self.sync_sale_payment_records(sale_payments)
|
||||
if !sale_payments.nil?
|
||||
sale_payments.each do |sp|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
class ShiftSale < ApplicationRecord
|
||||
belongs_to :cashier_terminal
|
||||
belongs_to :employee, :foreign_key => 'employee_id'
|
||||
has_many :sales
|
||||
|
||||
def self.current_shift
|
||||
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||
@@ -25,7 +26,7 @@ class ShiftSale < ApplicationRecord
|
||||
def self.current_open_shift(current_user)
|
||||
#if current_user
|
||||
#find open shift where is open today and is not closed and login by current cashier
|
||||
#DATE(shift_started_at)=? and
|
||||
#DATE(shift_started_at)=? and
|
||||
today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take
|
||||
return shift
|
||||
@@ -43,7 +44,7 @@ class ShiftSale < ApplicationRecord
|
||||
# status = 'updated'
|
||||
if shift_sale.nil?
|
||||
shift_sale = ShiftSale.new
|
||||
# status = 'created'
|
||||
# status = 'created'
|
||||
end
|
||||
|
||||
shift_sale.id = ss['id']
|
||||
@@ -118,7 +119,7 @@ class ShiftSale < ApplicationRecord
|
||||
credit = saleobj.get_credit_amount
|
||||
other_sales = saleobj.get_other_amount
|
||||
tax = saleobj.get_commerical_tax
|
||||
|
||||
|
||||
if type == "void"
|
||||
self.total_revenue = self.total_revenue.to_f - saleobj.total_amount.to_f
|
||||
self.total_discounts = self.total_discounts - saleobj.total_discount
|
||||
@@ -137,7 +138,7 @@ class ShiftSale < ApplicationRecord
|
||||
self.takeaway_count = self.takeaway_count - 1
|
||||
end
|
||||
|
||||
|
||||
|
||||
self.save
|
||||
end
|
||||
end
|
||||
@@ -149,11 +150,11 @@ class ShiftSale < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.get_by_shift_other_payment(shift)
|
||||
|
||||
|
||||
other_payment = Sale.select("sale_payments.payment_method as name,
|
||||
SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount,
|
||||
SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount,
|
||||
SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount,
|
||||
SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount,
|
||||
SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount,
|
||||
SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount,
|
||||
SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount,
|
||||
SUM(case when (sale_payments.payment_method='unionpay') then (sale_payments.payment_amount) else 0 end) as unionpay_amount,
|
||||
SUM(case when (sale_payments.payment_method='alipay') then (sale_payments.payment_amount) else 0 end) as alipay_amount,
|
||||
@@ -161,19 +162,19 @@ class ShiftSale < ApplicationRecord
|
||||
SUM(case when (sale_payments.payment_method='dinga') then (sale_payments.payment_amount) else 0 end) as dinga_amount,
|
||||
SUM(case when (sale_payments.payment_method='giftvoucher') then (sale_payments.payment_amount) else 0 end) as giftvoucher_amount,
|
||||
SUM(case when (sale_payments.payment_method='JunctionPay') then (sale_payments.payment_amount) else 0 end) as junctionpay_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount,
|
||||
SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount,
|
||||
SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount,
|
||||
SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id)
|
||||
end
|
||||
|
||||
def self.calculate_total_price_by_accounts(shift,type)
|
||||
query = Sale.select("acc.title as account_name," +
|
||||
query = Sale.select("acc.title as account_name," +
|
||||
"SUM(case when (acc.id=i.account_id) then (i.price) else 0 end) as total_price")
|
||||
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id "+
|
||||
"JOIN accounts acc ON acc.id = i.account_id" +
|
||||
"JOIN accounts acc ON acc.id = i.account_id" +
|
||||
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id")
|
||||
if type == 'discount'
|
||||
query = query.where("sales.shift_sale_id =? and sale_status = 'completed' and i.remark = 'Discount'", shift.id)
|
||||
@@ -187,17 +188,17 @@ class ShiftSale < ApplicationRecord
|
||||
def self.get_total_member_discount(shift)
|
||||
query = Sale.select("SUM(sales.total_discount) as member_discount")
|
||||
.where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id)
|
||||
|
||||
end
|
||||
|
||||
def self.get_total_dinein(shift)
|
||||
end
|
||||
|
||||
def self.get_total_dinein(shift)
|
||||
query = Sale.select("sum(sales.grand_total) as total_dinein_amount")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Dinein" and c.membership_id is null',shift.id)
|
||||
.first()
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_total_takeway(shift)
|
||||
def self.get_total_takeway(shift)
|
||||
query = Sale.select("sum(sales.grand_total) as total_takeway_amount")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Takeaway" and c.membership_id is null',shift.id)
|
||||
@@ -211,12 +212,12 @@ class ShiftSale < ApplicationRecord
|
||||
# .where('s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null and s.receipt_date between ? and ?',from, to)
|
||||
# end
|
||||
|
||||
def self.get_total_other_charges(shift)
|
||||
def self.get_total_other_charges(shift)
|
||||
query = SaleItem.select("sum(sale_items.qty * sale_items.unit_price) as total_other_charges_amount")
|
||||
.joins("JOIN sales as s ON s.sale_id = sale_items.sale_id")
|
||||
.where('shift_sale_id =? and s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null',shift.id)
|
||||
.first()
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(filter,from,to)
|
||||
if filter.blank?
|
||||
|
||||
@@ -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)
|
||||
@@ -52,23 +54,13 @@ class StockJournal < ApplicationRecord
|
||||
journal.save
|
||||
end
|
||||
|
||||
def self.inventory_balances(today,from,to,from_time,to_time)
|
||||
def self.inventory_balances(from,to)
|
||||
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.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
else
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
.where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'")
|
||||
.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
query = query.created_at_between(from, to)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user