Merge branch 'r-1902001-01' into foodcourt

This commit is contained in:
Thein Lin Kyaw
2020-09-10 10:31:07 +06:30
184 changed files with 2672 additions and 1021 deletions

View File

@@ -804,7 +804,7 @@ class Sale < ApplicationRecord
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.sale_payments_with_audit_except_void_between(from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
.group("sale_id").to_sql
.group("sale_id")
sale_taxes = Sale.select('sales.sale_id, sale_taxes.tax_name')
.joins(:sale_taxes)
@@ -829,13 +829,13 @@ class Sale < ApplicationRecord
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale,
CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
#{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(`#{pm}`) as `#{pm}`"}.push('').join(', ')}
SUM(cash_amount) as cash_amount,
SUM(credit_amount) as credit_amount,
SUM(foc_amount) as foc_amount
SUM(`cash_amount`) as `cash_amount`,
SUM(`credit_amount`) as `credit_amount`,
SUM(`foc_amount`) as `foc_amount`
FROM (
#{sales}
#{sales.to_sql}
) as s
JOIN (#{sale_taxes.to_sql}) AS st ON s.sale_id = st.sale_id
LEFT JOIN (#{sale_taxes.to_sql}) AS st ON s.sale_id = st.sale_id
GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
return daily_total
end
@@ -1254,6 +1254,36 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range, shift, from, to, paymen
return query
end
def self.get_shift_sales_by_customer(shift_sale_range, shift, from, to, membership_type, customer_filter)
## => left join -> show all sales although no orders
query = Sale.includes(:sale_items).select("sales.*, sale_payments.*")
.select("customers.customer_id, customers.name as customer_name,customers.membership_type as membership_type, dining_facilities.name, dining_facilities.type")
.joins("INNER JOIN sale_payments ON sale_payments.sale_id = sales.sale_id")
.joins("INNER JOIN bookings ON bookings.sale_id = sales.sale_id")
.joins("LEFT JOIN dining_facilities ON dining_facilities.id = bookings.dining_facility_id")
.completed.where.not(total_amount: 0)
.group("sales.sale_id")
if customer_filter.present?
query = query.joins(sanitize_sql_array(["INNER JOIN customers ON customers.customer_id = sales.customer_id AND " +
"customers.name LIKE :filter", filter: "%#{customer_filter}%"]))
else
query = query.joins(:customer)
end
if !membership_type.blank?
query = query.where("customers.membership_type = (?)", membership_type)
end
if shift.present?
query = query.where("sales.shift_sale_id in (?)", shift.to_a)
elsif shift_sale_range.present?
query = query.where("sales.shift_sale_id in (?)", shift_sale_range.to_a)
else
query = query.where("sales.receipt_date between ? and ?", from, to)
end
return query.group_by(&:membership_type)
end
def self.get_shift_sales_by_receipt_no_detail(shift_sale_range, shift, from, to, payment_type, customer_filter)
## => left join -> show all sales although no orders
puts customer_filter