change query for transactions/order and transactions/bookings, transactions/credit

This commit is contained in:
phyusin
2017-11-27 18:16:46 +06:30
parent 9ad9e9ae57
commit ad34002789
8 changed files with 19 additions and 21 deletions

View File

@@ -363,18 +363,18 @@ class Order < ApplicationRecord
end
def self.search(filter,from,to,count)
if count.to_i > 0
item_count = "and item_count = '#{count}'"
def self.search(filter,from,to)
if filter.blank?
keyword = ''
else
item_count = ''
keyword = "order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%"
end
if from.present? && to.present?
Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ? #{item_count}", from,to)
elsif !from.present? && !to.present? && count.present?
Order.where("item_count = '#{count}'")
if from.present? && to.present?
order = Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ?", from,to)
query = order.where(keyword)
else
Order.where("order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",)
where("order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%")
end
end

View File

@@ -449,7 +449,7 @@ class Sale < ApplicationRecord
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}%",)
where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%")
end
end