From 285ad93501dc01dd5aa35c8ad93b86210abb3d24 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 8 Aug 2017 09:43:58 +0630 Subject: [PATCH] update filter in sale and order and creditnote --- app/assets/javascripts/application.js | 12 +++++ app/assets/stylesheets/application.scss | 2 + .../transactions/credit_notes_controller.rb | 22 ++++++-- .../transactions/orders_controller.rb | 35 ++++++++----- .../transactions/sales_controller.rb | 51 ++++++++++++------- app/models/order.rb | 9 ++-- app/models/sale.rb | 43 ++++++++++++++-- .../transactions/credit_notes/index.html.erb | 39 +++++++++++++- app/views/transactions/orders/index.html.erb | 31 ++++++++--- app/views/transactions/sales/index.html.erb | 21 ++++++-- 10 files changed, 208 insertions(+), 57 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9adb6b75..1b22af09 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -30,3 +30,15 @@ function export_to(path) var form_params = $("#frm_report").serialize(); window.location = path+"?"+ form_params; } + + $(function () { + $('.datepicker').datepicker({ + format : 'dd-mm-yyyy', + autoclose: true + }); + $('.datepicker').attr('ReadOnly','true'); + $('.datepicker').css('cursor','pointer'); +}); + + + diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index a4fa6b9f..1c5ada90 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -76,3 +76,5 @@ select.form-control { } /*--- Reset --- */ + + diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index 0f370c96..b1a16c78 100644 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -5,9 +5,25 @@ class Transactions::CreditNotesController < ApplicationController # GET /transactions/sales.json def index - @sales = Sale.where('payment_status = ?', Sale::SALE_STATUS_OUTSTANDING) - - + @customers = Customer.all + + filter = params[:filter] + customer = params[:customer] + from = params[:from] + to = params[:to] + + if filter.nil? && from.nil? && to.nil? && customer.nil? + @sales = Sale.where('payment_status = ?', Sale::SALE_STATUS_OUTSTANDING) + puts "cccccccccccc" + else + sale = Sale.search_credit_sales(customer,filter,from,to) + if sale.count > 0 + @sales = sale + @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + else + @sales = 0 + end + end respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb index de4be3c3..4df88787 100644 --- a/app/controllers/transactions/orders_controller.rb +++ b/app/controllers/transactions/orders_controller.rb @@ -2,23 +2,30 @@ class Transactions::OrdersController < ApplicationController load_and_authorize_resource except: [:create] def index - filter = params[:filter] - if filter.nil? + filter = params[:filter] + from = params[:from] + to = params[:to] + + if filter.nil? || from.nil? || to.nil? orders = Order.order("order_id desc") else - order = Order.search(filter) - if order.count > 0 - orders = order - else - orders = Order.order("order_id desc") - - end + orders = Order.search(filter,from,to) + # if order.count > 0 + # orders = order + # else + # orders = Order.order("order_id desc") + # end end - @orders = Kaminari.paginate_array(orders).page(params[:page]).per(50) - respond_to do |format| - format.html # index.html.erb - format.json { render json: @orders } - end + + if !orders.nil? + @orders = Kaminari.paginate_array(orders).page(params[:page]).per(50) + else + @orders = [] + end + respond_to do |format| + format.html # index.html.erb + format.json { render json: @orders } + end end def show diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index eb058cac..8c33e1a3 100644 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -6,28 +6,41 @@ class Transactions::SalesController < ApplicationController # GET /transactions/sales.json def index - search_date = params[:date] - receipt_no = params[:receipt_no] - today = Date.today - - if receipt_no.nil? && search_date.nil? - @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500) - @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + receipt_no = params[:receipt_no] + from = params[:from] + to = params[:to] + + if receipt_no.nil? && from.nil? && to.nil? + @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500) + @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) else - if !search_date.blank? && receipt_no.blank? - sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') = ? and NOT sale_status = 'void' ", search_date).order("sale_id desc").limit(500).page(params[:page]) - elsif !search_date.blank? && !receipt_no.blank? - sale = Sale.where("receipt_no LIKE ? or DATE_FORMAT(receipt_date,'%d-%m-%Y') = ? and NOT sale_status = 'void' ", "%#{receipt_no}%", search_date).order("sale_id desc").limit(500).page(params[:page]) - else - sale = Sale.where("receipt_no LIKE ? and NOT sale_status = 'void' ", receipt_no).order("sale_id desc").limit(500).page(params[:page]) - end + sale = Sale.search(receipt_no,from,to) if sale.count > 0 - @sales = sale - @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) - else - @sales = 0 - end + @sales = sale + @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + else + @sales = 0 + end end + + # if receipt_no.nil? && search_date.nil? + # @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500) + # @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + # else + # if !search_date.blank? && receipt_no.blank? + # sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') = ? and NOT sale_status = 'void' ", search_date).order("sale_id desc").limit(500).page(params[:page]) + # elsif !search_date.blank? && !receipt_no.blank? + # sale = Sale.where("receipt_no LIKE ? or DATE_FORMAT(receipt_date,'%d-%m-%Y') = ? and NOT sale_status = 'void' ", "%#{receipt_no}%", search_date).order("sale_id desc").limit(500).page(params[:page]) + # else + # sale = Sale.where("receipt_no LIKE ? and NOT sale_status = 'void' ", receipt_no).order("sale_id desc").limit(500).page(params[:page]) + # end + # if sale.count > 0 + # @sales = sale + # @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + # else + # @sales = 0 + # end + # end respond_to do |format| format.html # index.html.erb diff --git a/app/models/order.rb b/app/models/order.rb index 5f96e6d6..4d54f41f 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -320,11 +320,12 @@ class Order < ApplicationRecord end - def self.search(search) - if search - where("order_id LIKE ? OR item_count ='#{search}'","%#{search}%",) + def self.search(filter,from,to) + if !from.nil? && !to.nil? + Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ?", from,to) else - find(:all) + # find(:all) + where("order_id LIKE ? OR item_count ='#{filter}'","%#{filter}%",) end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 462c8c73..4a4c451f 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -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) diff --git a/app/views/transactions/credit_notes/index.html.erb b/app/views/transactions/credit_notes/index.html.erb index fba0b52f..ac291115 100644 --- a/app/views/transactions/credit_notes/index.html.erb +++ b/app/views/transactions/credit_notes/index.html.erb @@ -16,6 +16,39 @@
+ + + @@ -27,6 +60,8 @@ + <% if @sales != 0 %> + <% @sales.each do |sale| %> @@ -39,7 +74,9 @@ <% end %> - + <% else %> + + <% end %>
+ <%= form_tag transactions_credit_notes_path, :method => :get do %> +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ <% end %> +
Sale Id Receipt no
<%= link_to sale.sale_id, transactions_sale_path(sale) %> <%= sale.receipt_date.strftime("%d-%m-%Y") %>

There is no data for search....


diff --git a/app/views/transactions/orders/index.html.erb b/app/views/transactions/orders/index.html.erb index 8463886f..21cae24a 100644 --- a/app/views/transactions/orders/index.html.erb +++ b/app/views/transactions/orders/index.html.erb @@ -13,10 +13,28 @@
<%= form_tag transactions_orders_path, :method => :get do %> -
-   - -
+
+ + +
+
+ + + +
+
+ + +
+
+ + +
+ +
+ + +
<% end %>
@@ -49,7 +67,9 @@

- <%= paginate @orders %> + <%if !@order.nil?%> + <%= paginate @orders %> + <%end%>
@@ -57,6 +77,5 @@
- diff --git a/app/views/transactions/sales/index.html.erb b/app/views/transactions/sales/index.html.erb index 2f437f3c..440989cb 100644 --- a/app/views/transactions/sales/index.html.erb +++ b/app/views/transactions/sales/index.html.erb @@ -19,11 +19,22 @@ <%= form_tag transactions_sales_path, :method => :get do %> -
- - - - +
+ + +
+
+ + +
+
+ + +
+ +
+ +
<% end %>