update filter in sale and order and creditnote

This commit is contained in:
Aung Myo
2017-08-08 09:43:58 +06:30
parent 35d1ec59cb
commit 285ad93501
10 changed files with 208 additions and 57 deletions

View File

@@ -378,13 +378,46 @@ class Sale < ApplicationRecord
end
end
def self.search(search)
if search
# find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"])
where("receipt_no LIKE ?", "%#{search}%",)
def self.search(filter,from,to)
if filter.blank?
keyword = ''
else
find(:all)
keyword = "receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%"
end
if from.present? && to.present?
sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and NOT sale_status = 'void' ", from,to)
query = sale.where(keyword)
else
where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%",)
end
end
def self.search_credit_sales(customer,filter,from,to)
if filter.blank?
keyword = ''
else
keyword = "and receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%"
end
if customer.blank?
custo = ''
else
custo = "and customer_id = '#{customer}'"
end
if from.present? && to.present?
sale = Sale.all.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and sp.payment_method = 'creditnote' #{keyword} #{custo}", from,to)
else
sale = Sale.all.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.where("sp.payment_method =? #{keyword} #{custo}",'creditnote')
end
end
def self.get_rounding_adjustment(num)