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

@@ -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');
});

View File

@@ -76,3 +76,5 @@ select.form-control {
}
/*--- Reset --- */

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

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)

View File

@@ -16,6 +16,39 @@
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<td colspan="8">
<%= form_tag transactions_credit_notes_path, :method => :get do %>
<div class="form-group col-md-4">
<label>Enter Keywords</label>
<input type="text" name="receipt_no" class="form-control" placeholder="Receipt No/Cashier Name/Status" style="margin-right: 10px">
</div>
<div class="form-group col-md-2">
<label>Select Customer</label>
<select class="selectpicker form-control col-md-12" name="customer" style="height: 40px" >
<option value="">Select Customer</option>
<% @customers.each do |customer| %>
<option value="<%= customer.customer_id %>">
<%= customer.name %></option>
<%end %>
</select>
</div>
<div class="form-group col-md-2">
<label class="">From</label>
<input class="form-control datepicker" name="from" id="date" type="text" placeholder="From date">
</div>
<div class="form-group col-md-2">
<label class="">To</label>
<input class="form-control datepicker" name="to" id="date" type="text" placeholder="To date">
</div>
<div class="form-group col-md-1">
<label></label>
<input type="submit" value="Search" class='btn btn-primary btn-md'>
</div>
<% end %>
</td>
</tr>
<tr>
<th>Sale Id </th>
<th>Receipt no </th>
@@ -27,6 +60,8 @@
</thead>
<tbody>
<% if @sales != 0 %>
<% @sales.each do |sale| %>
<tr>
<td><%= link_to sale.sale_id, transactions_sale_path(sale) %></td>
@@ -39,7 +74,9 @@
<td> <%= sale.receipt_date.strftime("%d-%m-%Y") %> </td>
</tr>
<% end %>
<% else %>
<tr><td colspan="8"><strong><p style="text-align: center">There is no data for search....</p></strong></td></tr>
<% end %>
</tbody>
</table>
<br>

View File

@@ -13,10 +13,28 @@
<div class="col-lg-12">
<div class="main-box-body clearfix">
<%= form_tag transactions_orders_path, :method => :get do %>
<div class="input-append col-md-4 form-group pull-right">
<input type="text" name="filter" placeholder="Order ID" class="form-control input-md col-md-8">&nbsp;
<button type="submit" class="btn btn-primary btn-md">Search</button>
</div>
<div class="form-group col-md-3">
<label>Enter Keyword</label>
<input type="text" name="filter" placeholder="Order ID" class="form-control input-md">
</div>
<div class="form-group col-md-2">
<label>Items Count</label>
<input id="number" data-id='numberRangePicker' type="range" data-min="0" data-max="20" data-step="1" data-value="14"/>
</div>
<div class="form-group col-md-2">
<label class="">From</label>
<input class="form-control datepicker" name="from" id="date" type="text" placeholder="From date">
</div>
<div class="form-group col-md-2">
<label class="">To</label>
<input class="form-control datepicker" name="to" id="date" type="text" placeholder="To date">
</div>
<div class="form-group col-md-1">
<label></label>
<input type="submit" value="Search" class='btn btn-primary btn-md'>
</div>
<% end %>
<div class="table-responsive">
<table class="table table-striped">
@@ -49,7 +67,9 @@
</table>
<br>
<%= paginate @orders %>
<%if !@order.nil?%>
<%= paginate @orders %>
<%end%>
</div>
</div>
@@ -57,6 +77,5 @@
</div>

View File

@@ -19,11 +19,22 @@
<tr>
<td colspan="8">
<%= form_tag transactions_sales_path, :method => :get do %>
<div class="input-append form-group pull-right col-md-6">
<input class="datepicker col-md-3 form-control" name="date" id="date" type="text" placeholder="Receipt date" style="margin-right: 10px">
<input type="text" name="receipt_no" class="col-md-5 form-control" placeholder="Receipt No" style="margin-right: 10px">
<button type="submit" class="btn btn-primary btn">Search</button>
<div class="form-group col-md-4">
<label>Enter Keywords</label>
<input type="text" name="receipt_no" class="form-control" placeholder="Receipt No/Cashier Name/Status" style="margin-right: 10px">
</div>
<div class="form-group col-md-3">
<label class="">From</label>
<input class="form-control datepicker" name="from" id="date" type="text" placeholder="From date">
</div>
<div class="form-group col-md-3">
<label class="">To</label>
<input class="form-control datepicker" name="to" id="date" type="text" placeholder="To date">
</div>
<div class="form-group col-md-1">
<label></label>
<input type="submit" value="Search" class='btn btn-primary btn-md'>
</div>
<% end %>
</td>