add filter in dashboard and Transaction/Sale

This commit is contained in:
phyusin
2018-03-26 16:42:17 +06:30
parent 6bb833aff3
commit 4b78de3f9a
6 changed files with 972 additions and 230 deletions

View File

@@ -86,64 +86,72 @@ class HomeController < ApplicationController
today = DateTime.now.strftime('%Y-%m-%d') today = DateTime.now.strftime('%Y-%m-%d')
if !@from.nil? && !@to.nil? if !@from.nil? && !@to.nil?
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() if !@from_time.nil? && @to_time.nil?
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
else
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
end
else else
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
end end
if !@from.nil? && !@to.nil? if !@from.nil? && !@to.nil?
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() if !@from_time.nil? && @to_time.nil?
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
else
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
end
else else
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
end end
@top_products = Sale.top_products(today,@from,@to).sum('i.qty') @top_products = Sale.top_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty')
@bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty') @bottom_products = Sale.bottom_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty')
@hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total) @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total) # .sum(:grand_total)
@employee_sales = Sale.employee_sales(today,@from,@to) @employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time)
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
@inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance) @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance)
@total_sale = Sale.total_sale(today,current_user,@from,@to) @total_sale = Sale.total_sale(today,current_user,@from,@to,@from_time,@to_time)
@total_count = Sale.total_count(today,current_user,@from,@to) @total_count = Sale.total_count(today,current_user,@from,@to,@from_time,@to_time)
@total_card = Sale.total_card_sale(today,current_user,@from,@to) @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time)
@total_credit = Sale.credit_payment(today,current_user,@from,@to) @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time)
@sale_data = Array.new @sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to) @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time)
if !@total_payment_methods.nil? if !@total_payment_methods.nil?
@total_payment_methods.each do |payment| @total_payment_methods.each do |payment|
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay"
pay = Sale.payment_sale('card', today, current_user,@from,@to) pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({'card' => pay.payment_amount}) @sale_data.push({'card' => pay.payment_amount})
else else
pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to) pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({payment.payment_method => pay.payment_amount}) @sale_data.push({payment.payment_method => pay.payment_amount})
end end
end end
end end
@summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to) @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time)
@total_customer = Sale.total_customer(today,current_user,@from,@to) @total_customer = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time)
@total_dinein = Sale.total_dinein(today,current_user,@from,@to) @total_dinein = Sale.total_dinein(today,current_user,@from,@to,@from_time,@to_time)
@total_takeaway = Sale.total_takeaway(today,current_user,@from,@to) @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to,@from_time,@to_time)
@total_other_customer = Sale.total_other_customer(today,current_user,@from,@to) @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to,@from_time,@to_time)
@total_membership = Sale.total_membership(today,current_user,@from,@to) @total_membership = Sale.total_membership(today,current_user,@from,@to,@from_time,@to_time)
@total_order = Sale.total_order(today,current_user,@from,@to) @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time)
@total_accounts = Sale.total_account(today,current_user,@from,@to) @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time)
@account_data = Array.new @account_data = Array.new
if !@total_accounts.nil? if !@total_accounts.nil?
@total_accounts.each do |account| @total_accounts.each do |account|
acc = Sale.account_data(account.account_id, today,current_user,@from,@to) acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time)
if !acc.nil? if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end end
end end
end end
@top_items = Sale.top_items(today,current_user,@from,@to) @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time)
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to) @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time)
# get printer info # get printer info
@print_settings = PrintSetting.get_precision_delimiter() @print_settings = PrintSetting.get_precision_delimiter()
@@ -202,12 +210,15 @@ class HomeController < ApplicationController
to_time = params[:to_time] to_time = params[:to_time]
if from.present? && to.present? if from.present? && to.present?
f_date = DateTime.parse(from) # f_date = DateTime.parse(from)
t_date = DateTime.parse(to) # t_date = DateTime.parse(to)
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) # f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) # t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
from = f_time.beginning_of_day.utc.getlocal # from = f_time.beginning_of_day.utc.getlocal
to = t_time.end_of_day.utc.getlocal # to = t_time.end_of_day.utc.getlocal
from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d')
to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d')
end end
return from, to, from_time, to_time return from, to, from_time, to_time

View File

@@ -8,14 +8,23 @@ class Transactions::SalesController < ApplicationController
def index def index
receipt_no = params[:receipt_no] receipt_no = params[:receipt_no]
from = params[:from] # from = params[:from]
to = params[:to] # to = params[:to]
from, to = get_date_range_from_params
@shift = ''
if params[:shift_name].to_i != 0
@shift = ShiftSale.find(params[:shift_name])
end
if receipt_no.nil? && from.nil? && to.nil? if receipt_no.nil? && from.nil? && to.nil?
@sales = Sale.where("NOT sale_status='new'").order("sale_id desc") if @shift.blank?
@sales = Sale.where("NOT sale_status='new'").order("sale_id desc")
else
@sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc")
end
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)
else else
sale = Sale.search(receipt_no,from,to) sale = Sale.search(receipt_no,from,to,@shift)
if sale.count > 0 if sale.count > 0
@sales = sale @sales = sale
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20)
@@ -26,6 +35,12 @@ class Transactions::SalesController < ApplicationController
@receipt_no = receipt_no @receipt_no = receipt_no
@from = from @from = from
@to = to @to = to
if @shift.present?
@shift_from = @shift.shift_started_at.nil? ? '-' : @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p")
@shift_to = @shift.shift_closed_at.nil? ? '-' : @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p")
@shift_data = @shift
end
# if receipt_no.nil? && search_date.nil? # if receipt_no.nil? && search_date.nil?
# @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500) # @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500)
@@ -48,7 +63,7 @@ class Transactions::SalesController < ApplicationController
@sale_audits = [] @sale_audits = []
@sale_item_audits = [] @sale_item_audits = []
if !@sales.nil? if @sales != 0
@sales.each do |sale| @sales.each do |sale|
sale_audit = SaleAudit.where("(action = 'SALEPAYMENT' or action = 'SALEVOID') and sale_id = ? and remark IS NOT NULL",sale.sale_id) sale_audit = SaleAudit.where("(action = 'SALEPAYMENT' or action = 'SALEVOID') and sale_id = ? and remark IS NOT NULL",sale.sale_id)
if !sale_audit.nil? if !sale_audit.nil?
@@ -148,6 +163,74 @@ class Transactions::SalesController < ApplicationController
end end
end end
# date range
PERIOD = {
"today" => 0,
"yesterday" => 1,
"this_week" => 2,
"last_week" => 3,
"last_7" => 4,
"this_month" => 5,
"last_month" => 6,
"last_30" => 7,
"this_year" => 8,
"last_year" => 9
}
def get_date_range_from_params
period_type = params[:period_type]
period = params[:period]
from = params[:from]
to = params[:to]
day_ref = Time.now.utc.getlocal
if from.present? && to.present?
f_date = DateTime.parse(from)
t_date = DateTime.parse(to)
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
from = f_time.beginning_of_day.utc.getlocal
to = t_time.end_of_day.utc.getlocal
else
case period.to_i
when PERIOD["today"]
from = day_ref.beginning_of_day.utc
to = day_ref.end_of_day.utc
when PERIOD["yesterday"]
from = (day_ref - 1.day).beginning_of_day.utc
to = (day_ref - 1.day).end_of_day.utc
when PERIOD["this_week"]
from = Time.now.beginning_of_week.utc
to = Time.now.utc
when PERIOD["last_week"]
from = (day_ref - 7.day).beginning_of_week.utc
to = (day_ref - 7.day).end_of_week.utc
when PERIOD["last_7"]
from = (day_ref - 7.day).utc
to = Time.now.utc
when PERIOD["this_month"]
from = Time.now.beginning_of_month.utc
to = Time.now.utc
when PERIOD["last_month"]
from = (day_ref - 1.month).beginning_of_month.utc
to = (day_ref - 1.month).end_of_month.utc
when PERIOD["last_30"]
from = (day_ref - 30.day).utc
to = Time.now.utc
when PERIOD["this_year"]
from = Time.now.beginning_of_year.utc
to = Time.now.utc
when PERIOD["last_year"]
from = (day_ref - 1.year).beginning_of_year.utc
to = (day_ref - 1.year).end_of_year.utc
end
end
return from, to
end
def check_user def check_user
if current_user.nil? if current_user.nil?
redirect_to root_path redirect_to root_path

File diff suppressed because it is too large Load Diff

View File

@@ -36,12 +36,16 @@ class StockJournal < ApplicationRecord
journal.save journal.save
end end
def self.inventory_balances(today,from,to) def self.inventory_balances(today,from,to,from_time,to_time)
if !from.nil? && !to.nil? if !from.nil? && !to.nil?
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
.where("stock_journals.created_at between '#{from}' and '#{to}'") if !from_time.nil? && !to_time.nil?
.group("mii.item_instance_name") query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
else
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'")
end
query = query.group("mii.item_instance_name")
.order("mii.item_instance_name ASC") .order("mii.item_instance_name ASC")
else else
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")

View File

@@ -68,24 +68,46 @@
<!-- Date range for dashboard --> <!-- Date range for dashboard -->
<div class="row clearfix"> <div class="row clearfix">
<%
if !@from.nil?
from_date = DateTime.parse(@from).utc.getlocal.strftime("%d-%m-%Y")
else
from_date = Time.now.utc.getlocal.strftime('%d-%m-%Y')
end
if !@to.nil?
to_date = DateTime.parse(@to).utc.getlocal.strftime("%d-%m-%Y")
else
to_date = Time.now.utc.getlocal.strftime('%d-%m-%Y')
end
if !@from_time.nil?
from_time = @from_time
else
from_time = ''
end
if !@to_time.nil?
to_time = @to_time
else
to_time = ''
end
%>
<div class="col-lg-3 col-md-3 col-sm-3"> <div class="col-lg-3 col-md-3 col-sm-3">
<label class="font-14"><%= t("views.right_panel.detail.from") %></label> <label class="font-14"><%= t("views.right_panel.detail.from") %></label>
<input data-behaviour='datepicker' class="form-control datepicker" name="from" id="from" type="text" value="<%= Time.now.utc.getlocal.strftime('%d-%m-%Y') %>" placeholder="From date" style="height: 35px;"> <input data-behaviour='datepicker' class="form-control datepicker" name="from" id="from" type="text" value="<%= from_date %>" placeholder="From date" style="height: 35px;">
<span id="fromErr" style="color:red;"></span> <span id="fromErr" style="color:red;"></span>
</div> </div>
<div class="col-lg-3 col-md-3 col-sm-3"> <div class="col-lg-3 col-md-3 col-sm-3">
<label class="font-14"><%= t("views.right_panel.detail.to") %></label> <label class="font-14"><%= t("views.right_panel.detail.to") %></label>
<input data-behaviour='datepicker' class="form-control datepicker" name="to" id="to" type="text" value="<%= Time.now.utc.getlocal.strftime('%d-%m-%Y') %>" placeholder="To date" style="height: 35px;"> <input data-behaviour='datepicker' class="form-control datepicker" name="to" id="to" type="text" value="<%= to_date %>" placeholder="To date" style="height: 35px;">
<span id="toErr" style="color:red;"></span> <span id="toErr" style="color:red;"></span>
</div> </div>
<div class="col-lg-2 col-md-2 col-sm-2"> <div class="col-lg-2 col-md-2 col-sm-2">
<label class="font-14"><%= t("views.right_panel.detail.from_time") %></label> <label class="font-14"><%= t("views.right_panel.detail.from_time") %></label>
<input data-behaviour='timepicker' class="form-control timepicker" name="from_time" id="from_time" type="text" value="" placeholder="From Time" style="height: 35px;"> <input data-behaviour='timepicker' class="form-control timepicker" name="from_time" id="from_time" type="text" value="<%= from_time %>" placeholder="From Time" style="height: 35px;">
<span id="from_timeErr" style="color:red;"></span> <span id="from_timeErr" style="color:red;"></span>
</div> </div>
<div class="col-lg-2 col-md-2 col-sm-2"> <div class="col-lg-2 col-md-2 col-sm-2">
<label class="font-14"><%= t("views.right_panel.detail.to_time") %></label> <label class="font-14"><%= t("views.right_panel.detail.to_time") %></label>
<input data-behaviour='timepicker' class="form-control timepicker" name="to_time" id="to_time" type="text" value="" placeholder="To time" style="height: 35px;"> <input data-behaviour='timepicker' class="form-control timepicker" name="to_time" id="to_time" type="text" value="<%= to_time %>" placeholder="To time" style="height: 35px;">
<span id="to_timeErr" style="color:red;"></span> <span id="to_timeErr" style="color:red;"></span>
</div> </div>
<div class="col-lg-2 col-md-2 col-sm-2"> <div class="col-lg-2 col-md-2 col-sm-2">

View File

@@ -17,17 +17,41 @@
<td colspan="8"> <td colspan="8">
<%= form_tag transactions_sales_path, :method => :get do %> <%= form_tag transactions_sales_path, :method => :get do %>
<div class="row clearfix"> <div class="row clearfix">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<label><%= t("views.right_panel.detail.enter_keyboards") %></label> <label><%= t("views.right_panel.detail.enter_keyboards") %></label>
<input type="text" id="receipt_no" name="receipt_no" class="form-control" placeholder="Receipt No/Cashier Name/Status" style="margin-right: 10px"> <input type="text" id="receipt_no" name="receipt_no" class="form-control" placeholder="Receipt No/Cashier Name/Status" style="margin-right: 10px;height: 34px;">
</div> </div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
<label class=""><%= t("views.right_panel.detail.from") %></label> <div class="col-lg-2 col-md-2 col-sm-2">
<input class="form-control datepicker" name="from" id="from" type="text" placeholder="From date"> <label class="font-14"><%= t("views.right_panel.detail.select_period") %></label>
<select name="period" id="sel_period" class="form-control">
<option value=""><%= t("views.right_panel.detail.select_period") %></option>
<option value="0">Today</option>
<option value="1">Yesterday</option>
<option value="2">This week</option>
<option value="3">Last week</option>
<option value="4">Last 7 days</option>
<option value="5">This month</option>
<option value="6">Last month</option>
<option value="7">Last 30 days</option>
<option value="8">This year</option>
<option value="9">Last year</option>
</select>
</div> </div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<label class=""><%= t("views.right_panel.detail.from") %></label>
<input class="form-control datepicker" name="from" id="from" type="text" placeholder="From date" style="height: 34px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<label class=""><%= t("views.right_panel.detail.to") %></label> <label class=""><%= t("views.right_panel.detail.to") %></label>
<input class="form-control datepicker" name="to" id="to" type="text" placeholder="To date"> <input class="form-control datepicker" name="to" id="to" type="text" placeholder="To date" style="height: 34px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<label class="font-14"><%= t("views.right_panel.detail.all_shift") %></label>
<select class="form-control select" name="shift_name" id="shift_name" >
</select>
</div> </div>
<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1"> <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
@@ -98,7 +122,7 @@
</tr> </tr>
<% end %> <% end %>
<% else %> <% else %>
<tr><td colspan="8"><strong><p style="text-align: center">There is no data for search....</p></strong></td></tr> <tr><td colspan="10"><strong><p style="text-align: center">There is no data for search....</p></strong></td></tr>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
@@ -116,9 +140,107 @@
<script type="text/javascript"> <script type="text/javascript">
$(function(){ $(function(){
$("#receipt_no").val("<%=params[:receipt_no]%>"); $('#receipt_no').val("<%= params[:receipt_no] %>");
$("#from").val("<%=params[:from]%>"); $('#from').val("<%= params[:from] %>");
$("#to").val("<%=params[:to]%>"); $('#to').val("<%= params[:to] %>");
$('#sel_period').val("<%= params[:period] %>");
var check_arr = [];
search_by_period();
$('#sel_period').change(function(){
search_by_period();
});
function search_by_period(){
var period = $('#sel_period').val();
var period_type = 0;
var from = "";
var to = "";
show_shift_name(period,period_type,from,to,'shift_item');
}
// OK button is clicked
$('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){
new_date = new Date(date) ;
month = parseInt(new_date.getMonth()+1)
from = new_date.getDate() + "-" + month + "-" + new_date.getFullYear();
$('#from').val(from);
search_by_date();
});
$('#to').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){
new_date = new Date(date) ;
month = parseInt(new_date.getMonth()+1)
to = new_date.getDate() + "-" + month + "-" + new_date.getFullYear();
$('#to').val(to);
search_by_date();
});
function search_by_date(){
from = $("#from").val();
to = $("#to").val();
var period = 0;
var period_type = 1;
if(to != '' && from != ''){
shift_name = from + ',' + to;
check_arr.push(to);
console.log(check_arr.length)
if(check_arr.length == 1){
show_shift_name(period,period_type,from,to,'shift_item');
}
if(check_arr.length == 3){
check_arr = [];
}
}
}
function show_shift_name(period,period_type,from,to,shift_item){
var shift = $('#shift_name');
if (from == '' && to == '') {
from = $("#from").val();
to = $("#to").val();
}
shift.empty();
var str = '';
var param_shift = '';
var param_shift = '<%= params[:shift_name] rescue '-'%>';
url = '<%= reports_get_shift_by_date_path %>';
$.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){
str = '<option value="0">--- All Shift ---</option>';
$(data.message).each(function(index){
var local_date = data.message[index].local_opening_date + ' - ' + data.message[index].local_closing_date;
var sh_date = data.message[index].opening_date + ' - ' + data.message[index].closing_date;
var shift_id = data.message[index].shift_id ;
if(param_shift != ''){
if(shift_id == param_shift){
selected = 'selected = "selected"';
}
else{
selected = '';
}
}else{
selected = '';
}
str += '<option value="'+ shift_id +'" '+ selected +'>' + local_date + '</option>';
// console.log(sh_date)
})
shift.append(str);
});
}
}); });
</script> </script>