customer sales report tax fixed
This commit is contained in:
@@ -1225,7 +1225,7 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range, shift, from, to, paymen
|
||||
if payment_type.blank?
|
||||
payment_type = ''
|
||||
else
|
||||
payment_type = " and sale_payments.payment_method = '#{payment_type}'"
|
||||
payment_type = "sale_payments.payment_method = '#{payment_type}'"
|
||||
end
|
||||
|
||||
query = Sale.includes(:sale_items).select("sales.*, sale_payments.*")
|
||||
@@ -1235,7 +1235,9 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range, shift, from, to, paymen
|
||||
.joins("LEFT JOIN dining_facilities ON dining_facilities.id = bookings.dining_facility_id")
|
||||
.completed.where.not(total_amount: 0)
|
||||
.group("sales.sale_id")
|
||||
|
||||
if payment_type != ''
|
||||
query = query.where("#{payment_type} and sale_payments.payment_amount!=0")
|
||||
end
|
||||
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}%"]))
|
||||
@@ -1440,6 +1442,31 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_separate_tax_by_customer(shift_sale_range, shift, from, to, payment_type,customer_filter, membership_type=nil)
|
||||
|
||||
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
||||
.where("sale_status= 'completed'")
|
||||
.joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id")
|
||||
.group("sale_taxes.tax_name")
|
||||
.order("sale_taxes.tax_name desc")
|
||||
if payment_type.present?
|
||||
query = query.joins("JOIN sale_payments ON sale_payments.sale_id = sale_taxes.sale_id AND sale_payments.payment_method = '#{payment_type}' and sale_payments.payment_amount!=0")
|
||||
end
|
||||
|
||||
query = query.joins("INNER JOIN customers ON customers.customer_id = sales.customer_id
|
||||
#{sanitize_sql_array(['AND customers.name LIKE :filter', filter: "%#{customer_filter}%"]) if customer_filter.present?}
|
||||
#{sanitize_sql_array(['AND customers.membership_type = :type', type: membership_type]) if membership_type.present?}")
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
def self.get_payment_method_by_shift(shift,from,to,payment_type)
|
||||
payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user