remove foc for other payment and show foc payment in shift sale report

This commit is contained in:
phyusin
2017-12-01 12:03:39 +06:30
parent 34450aa5d6
commit a52a671e12
3 changed files with 68 additions and 32 deletions

View File

@@ -591,11 +591,40 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
end
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
if !shift.blank?
query = ShiftSale.where("shift_sales.id =?",shift.id)
else
query = ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
end
shift_sale_data = Hash.new
query.each do |shift_sale|
foc = 0
foc_data = Sale.select("SUM(sp.payment_amount) as foc_sales")
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
.where("sales.shift_sale_id=? and sp.payment_method='foc'",shift_sale.id)
.first()
if !foc_data.foc_sales.nil? && foc_data.foc_sales > 0
shift_sale.other_sales -= foc_data.foc_sales
foc = foc_data.foc_sales
end
shift_sale_data[shift_sale.id] = {
:cashier_terminal_name => shift_sale.cashier_terminal.name,
:employee_name => shift_sale.employee.name,
:shift_started_at => shift_sale.shift_started_at,
:shift_closed_at => shift_sale.shift_closed_at,
:cash_sales => shift_sale.cash_sales,
:credit_sales => shift_sale.credit_sales,
:other_sales => shift_sale.other_sales.to_f,
:foc_sales => foc,
:grand_total => shift_sale.grand_total
}
end
return shift_sale_data.values
end
def self.get_by_shift_sale(from,to,status)