add staff meal

This commit is contained in:
NyanLinHtut
2019-11-18 09:57:55 +06:30
parent 891995f531
commit 0d9e363648
13 changed files with 1291 additions and 199 deletions

View File

@@ -23,7 +23,20 @@ class InventoryDefinition < ApplicationRecord
end
end
def self.find_product_in_inventory(item)
def self.find_product_in_inventory(item,instance_code)
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(item.item_instance_code)
if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code)
return true, product

View File

@@ -125,8 +125,18 @@ 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)
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,instance_code)
if found
InventoryDefinition.check_balance(self, inventory_definition)
end

View File

@@ -942,6 +942,28 @@ def self.get_item_query(type)
# query = query.order("i.menu_category_name asc, SUM(i.qty) desc")
end
def self.get_staff_meal_query()
sale_type = "foc"
query = Sale.select("cus.name as staff_name,sales.sale_id,acc.title as account_name,
i.item_instance_code as item_code,i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total,
SUM(i.qty) as total_item,i.qty as qty," +
"i.status as status_type,i.remark as remark,"+
"i.unit_price,i.price as price,i.product_name as product_name, " +
"i.menu_category_name,i.menu_category_code as menu_category_id, " +
"date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')
as date_format")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id " +
"JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id " +
"JOIN customers cus ON cus.customer_id = sales.customer_id ")
query = query.joins(" JOIN accounts acc ON acc.id = i.account_id")
# query = query.where("#{sale_type}")
query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price")
.order("acc.title desc, i.account_id desc, i.menu_category_code desc, i.item_instance_code asc, SUM(i.qty) desc, i.unit_price asc")
# query = query.order("i.menu_category_name asc, SUM(i.qty) desc")
end
def self.get_other_charges()
query = Sale.select("i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
@@ -1048,6 +1070,111 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
end
def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_type,customer_id)
# date_type_selection = get_sql_function_for_report_type(report_type)
if account_type.blank?
account_type = ''
else
account_type = " and acc.title = '#{account_type}'"
end
unless customer_id.empty?
customer_id = customer_id.to_s
customer_id[0] = ""
customer_id = customer_id.chomp("]")
else
customer_id = '"CUS-000000000000"'
end
query = self.get_staff_meal_query()
discount_query = 0
total_card_amount = 0
total_cash_amount = 0
total_credit_amount = 0
total_foc_amount = 0
total_grand_total = 0
other_charges = 0
# if type.nil? || type == 'all' || type == "other"
# other_charges = self.get_other_charges()
# end
product = self.get_product_sale()
if shift.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a)
# if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
# end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a)
sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f
total_credit_amount += s_c.credit_amount.to_f
total_foc_amount += s_c.foc_amount.to_f
end
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
### => get all sales range in shift_sales
elsif shift_sale_range.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a)
# if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
# end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a)
sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f
total_credit_amount += s_c.credit_amount.to_f
total_foc_amount += s_c.foc_amount.to_f
end
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
else
query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",from,to)
# if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
# end
product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to)
sale_cash.each do |s_c|
total_cash_amount += s_c.cash_amount.to_f
total_card_amount += s_c.card_amount.to_f
total_credit_amount += s_c.credit_amount.to_f
total_foc_amount += s_c.foc_amount.to_f
end
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
end
return query, other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
end
def self.get_product_sale()
query = Sale.select("i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
@@ -1478,13 +1605,6 @@ end
end
def self.hourly_sales(today,current_user,from,to,from_time,to_time)
logger.debug 'hourly_sales<<<<<<<<<<<<<<<<<<<<<<<<'
logger.debug today
logger.debug current_user.to_json
logger.debug from
logger.debug to
logger.debug from_time
logger.debug to_time
if (!from.nil? && !to.nil?) && (from != "" && to!="")
if current_user.nil?
query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time)

View File

@@ -225,6 +225,59 @@ class SaleItem < ApplicationRecord
return sale_items
end
# Loader Service SFTP Start
# Detail Sale Data
def self.get_detail_sale_data(transaction_date)
query = SaleItem.select("
sale_items.sale_item_id as id,
sale_items.sale_id as parent_id,
s.receipt_no as check_num,
s.receipt_date as business_date,
s.receipt_date as transaction_date,
'' as item_seq,
sale_items.menu_category_code as category_code,
sale_items.menu_category_name as category_name,
'' as sub_category_code,
'' as sub_category_name,
'' as report_group_code,
'' as report_group_name,
sale_items.product_code as item_id,
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 = '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
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,
'' as service_charges,
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21)) as net_sales,
'0' as is_set_item,
'0' as is_staff_meal,
'0' as is_raw_wastage,
'0' as is_semi_wastage,
CASE WHEN s.sale_status = 'waste' THEN 1 ELSE 0 END as is_wastage,
CASE WHEN s.sale_status = 'spoile' THEN 1 ELSE 0 END as is_spoilage,
'0' as is_sampling,
'1' as tax_able,
CASE
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")
.joins("LEFT JOIN sale_items i ON sale_items.sale_id = i.sale_id AND sale_items.item_instance_code = i.item_instance_code AND i.status = 'Discount' AND sale_items.qty = abs(i.qty)")
.where("DATE(s.receipt_date) = ? AND s.sale_status != 'void' AND (sale_items.status NOT IN('Discount', 'void','foc') OR sale_items.status IS NULL)", transaction_date)
.order("s.receipt_no")
end
# Loader Service SFTP End
private
def generate_custom_id
if self.sale_item_id.nil?
@@ -293,58 +346,4 @@ class SaleItem < ApplicationRecord
end
end
end
# Loader Service SFTP Start
# Detail Sale Data
def self.get_detail_sale_data(transaction_date)
query = SaleItem.select("
sale_items.sale_item_id as id,
sale_items.sale_id as parent_id,
s.receipt_no as check_num,
s.receipt_date as business_date,
s.receipt_date as transaction_date,
'' as item_seq,
sale_items.menu_category_code as category_code,
sale_items.menu_category_name as category_name,
'' as sub_category_code,
'' as sub_category_name,
'' as report_group_code,
'' as report_group_name,
sale_items.product_code as item_id,
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 = '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
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,
'' as service_charges,
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21)) as net_sales,
'0' as is_set_item,
'0' as is_staff_meal,
'0' as is_raw_wastage,
'0' as is_semi_wastage,
CASE WHEN s.sale_status = 'waste' THEN 1 ELSE 0 END as is_wastage,
CASE WHEN s.sale_status = 'spoile' THEN 1 ELSE 0 END as is_spoilage,
'0' as is_sampling,
'1' as tax_able,
CASE
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")
.joins("LEFT JOIN sale_items i ON sale_items.sale_id = i.sale_id AND sale_items.item_instance_code = i.item_instance_code AND i.status = 'Discount' AND sale_items.qty = abs(i.qty)")
.where("DATE(s.receipt_date) = ? AND s.sale_status != 'void' AND (sale_items.status NOT IN('Discount', 'void','foc') OR sale_items.status IS NULL)", transaction_date)
.order("s.receipt_no")
end
# Loader Service SFTP End
end