finished report for all
This commit is contained in:
@@ -503,84 +503,18 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
|
||||
|
||||
|
||||
case report_type.to_i
|
||||
when REPORT_TYPE["daily"]
|
||||
return query
|
||||
when REPORT_TYPE["monthly"]
|
||||
|
||||
return query.group("MONTH(date)")
|
||||
when REPORT_TYPE["yearly"]
|
||||
return query.group("YEAR(date)")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.get_by_shiftsales(from,to)
|
||||
return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
|
||||
def self.get_by_shiftsales(from,to,shift)
|
||||
if !shift.blank?
|
||||
ShiftSale.where("id =?",shift.id)
|
||||
else
|
||||
ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
|
||||
end
|
||||
end
|
||||
|
||||
# def self.get_by_shiftsales(from,to)
|
||||
# shift_sales = ShiftSale.select('shift_sales.id, cs.name as cashier_station_name, shift_sales.shift_started_at as opening_date, shift_sales.shift_closeed_at as closing_date')
|
||||
# .joins(" INNER JOIN cashier_terminals cs ON cs.id = shift_sales.cashier_terminal_id")
|
||||
# .where("shift_sales.employee_id = ? and (shift_sales.shift_started_at between ? and ? OR shift_sales.shift_closeed_at between ? and ? )", employee, from, to, from, to)
|
||||
# .order("shift_sales.id DESC")
|
||||
|
||||
# sale_arr = Array.new
|
||||
# shift_sales.each do |shift|
|
||||
# all_total= Sale.select("grand_total,sr.payment_method, sr.payment_amount, rounding_adjustment")
|
||||
# .joins("join employees e on sales.cashier_id = e.id join shift_sales sh on sh.id = sales.shift_sale_id")
|
||||
# .joins("INNER JOIN (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sr ON sr.sale_id = sales.sale_id")
|
||||
# .where("sales.shift_sale_id =? and sales.sale_status = 'completed' and sales.total_amount != 0",shift.id)
|
||||
|
||||
# void = Sale.select("SUM(sales.grand_total) AS grand_total")
|
||||
# .joins("join shift_sales sh on sh.id = sales.shift_sale_id")
|
||||
# .where('sales.sale_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id)
|
||||
# .sum(:grand_total)
|
||||
# cash = all_total.select('sr.payment_method')
|
||||
# .where('sr.payment_method = "cash"')
|
||||
# .sum(:amount)
|
||||
|
||||
# credit = all_total.where('sr.payment_method = "creditnote"')
|
||||
# .sum(:amount)
|
||||
|
||||
# accept_credit = all_total.select('ci.amout')
|
||||
# .joins("INNER JOIN credit_items ci ON ci.sale_id = sales.id")
|
||||
# .where('sr.payment_method = "creditnote"')
|
||||
# .sum(:amout)
|
||||
|
||||
|
||||
|
||||
# foc = all_total.where('sales.payment_method = "foc" and sales.sale_status = "completed"')
|
||||
# .sum(:grand_total)
|
||||
|
||||
# card = all_total.select('payment_method')
|
||||
# .where('sr.payment_method = "card"')
|
||||
# .sum(:amount).to_f
|
||||
|
||||
# rounding_adj = all_total.sum(:rounding_adjustment)
|
||||
|
||||
# discount = all_total.sum(:discount_amount)
|
||||
# void = void.nil? ? 0 : void
|
||||
# cash = cash.nil? ? 0 : cash
|
||||
# credit = credit.nil? ? 0 : credit
|
||||
# foc = foc.nil? ? 0 : foc
|
||||
# card = card.nil? ? 0 : card
|
||||
# accept_credit = accept_credit.nil? ? 0 : accept_credit
|
||||
# # all_payments = void.to_d + cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d
|
||||
# all_payments = cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d
|
||||
# payments = { void_amount: void, cash_amount: cash, credit_amount: credit,accept_credit_amount: accept_credit, foc_amount: foc, card_amount: card, grand_total: all_payments , cashier_station_name: shift.cashier_station_name, opening_date: shift.opening_date, closing_date: shift.closing_date, rounding_adj: rounding_adj }
|
||||
|
||||
# sale_arr.push(payments)
|
||||
# end
|
||||
|
||||
# return sale_arr
|
||||
# end
|
||||
|
||||
# def self.get_receipt_no_list(from,to)
|
||||
# sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
|
||||
# end
|
||||
|
||||
def self.get_by_shift_sale(from,to,status)
|
||||
query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date,shift_closed_at As closing_date," +
|
||||
" grand_total AS grand_total, cash_sales AS cash," +
|
||||
@@ -604,7 +538,7 @@ def self.get_item_query()
|
||||
end
|
||||
|
||||
|
||||
def self.get_by_shift_items(shift_sale_range, shift, from, to, status, report_type)
|
||||
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
|
||||
# date_type_selection = get_sql_function_for_report_type(report_type)
|
||||
|
||||
@@ -616,11 +550,12 @@ def self.get_item_query()
|
||||
total_foc_amount = 0
|
||||
total_grand_total = 0
|
||||
|
||||
if shift == '[]'
|
||||
if shift.blank?
|
||||
### => get all sales range in shift_sales
|
||||
query = query.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)
|
||||
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') then (sale_ - sales.amount_changed) else 0 end) as card_amount,
|
||||
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') 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")
|
||||
@@ -633,11 +568,11 @@ def self.get_item_query()
|
||||
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
|
||||
|
||||
elsif shift_sale_range == '[]'
|
||||
else
|
||||
query = query.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)
|
||||
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') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
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') 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")
|
||||
@@ -649,31 +584,38 @@ def self.get_item_query()
|
||||
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("receipt_date between ? and ? and sale_status=?",from,to,'completed')
|
||||
sale_cash = Sale.select("sales.total_discount as total_discount,
|
||||
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') 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' ", 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
|
||||
discount_query = s_c.total_discount.to_f
|
||||
end
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
end
|
||||
|
||||
return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total
|
||||
end
|
||||
return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
||||
end
|
||||
|
||||
def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type)
|
||||
## => left join -> show all sales although no orders
|
||||
if payment_type.blank?
|
||||
payment_type = ''
|
||||
else
|
||||
if payment_type == 'card'
|
||||
payment_type = " and 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'"
|
||||
else
|
||||
payment_type = " and sale_payments.payment_method = '#{payment_type}'"
|
||||
end
|
||||
end
|
||||
query = Sale.all
|
||||
if shift.present?
|
||||
query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sales.total_amount != 0", shift.to_a)
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.group("sales.sale_id")
|
||||
|
||||
else
|
||||
query = query .where("sale_status=? #{payment_type} and sales.shift_sale_id in (?)","completed",shift_sale_range.to_a)
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.group("sales.sale_id")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.get_separate_tax(from,to,payment_method=nil)
|
||||
|
||||
@@ -692,7 +634,7 @@ end
|
||||
cash = 0.0
|
||||
self.sale_payments.each do |pay|
|
||||
if pay.payment_method == 'cash'
|
||||
cash = pay.payment_amount
|
||||
cash = pay.payment_amount-self.amount_changed
|
||||
end
|
||||
end
|
||||
return cash
|
||||
|
||||
Reference in New Issue
Block a user