add filter for dashboard
This commit is contained in:
@@ -89,8 +89,6 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def current_user
|
||||
puts "session"
|
||||
puts session[:session_token]
|
||||
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
||||
end
|
||||
|
||||
|
||||
@@ -62,60 +62,59 @@ class HomeController < ApplicationController
|
||||
end
|
||||
|
||||
def dashboard
|
||||
# puts "date range =>"
|
||||
# puts get_date_range_from_params
|
||||
|
||||
@from, @to = get_date_range_from_params
|
||||
|
||||
@shop = Shop.first
|
||||
|
||||
today = DateTime.now.strftime('%Y-%m-%d')
|
||||
@orders = Sale::where("payment_status='new' and sale_status='bill' 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()
|
||||
|
||||
@top_products = Sale.top_products(today).sum('i.qty')
|
||||
@bottom_products = Sale.bottom_products(today).sum('i.qty')
|
||||
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
|
||||
@top_products = Sale.top_products(today,@from,@to).sum('i.qty')
|
||||
@bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty')
|
||||
@hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total)
|
||||
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
||||
# .sum(:grand_total)
|
||||
@employee_sales = Sale.employee_sales(today)
|
||||
@employee_sales = Sale.employee_sales(today,@from,@to)
|
||||
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
|
||||
@inventories = StockJournal.inventory_balances(today).sum(:balance)
|
||||
@inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance)
|
||||
|
||||
@total_sale = Sale.total_sale(today,current_user)
|
||||
@total_count = Sale.total_count(today,current_user)
|
||||
@total_card = Sale.total_card_sale(today,current_user)
|
||||
@total_credit = Sale.credit_payment(today,current_user)
|
||||
@total_sale = Sale.total_sale(today,current_user,@from,@to)
|
||||
@total_count = Sale.total_count(today,current_user,@from,@to)
|
||||
@total_card = Sale.total_card_sale(today,current_user,@from,@to)
|
||||
@total_credit = Sale.credit_payment(today,current_user,@from,@to)
|
||||
|
||||
@sale_data = Array.new
|
||||
@total_payment_methods = Sale.total_payment_methods(today,current_user)
|
||||
@total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to)
|
||||
|
||||
@total_payment_methods.each do |payment|
|
||||
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb"
|
||||
pay = Sale.payment_sale('card', today, current_user)
|
||||
pay = Sale.payment_sale('card', today, current_user,@from,@to)
|
||||
@sale_data.push({'card' => pay.payment_amount})
|
||||
else
|
||||
pay = Sale.payment_sale(payment.payment_method, today, current_user)
|
||||
pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to)
|
||||
@sale_data.push({payment.payment_method => pay.payment_amount})
|
||||
end
|
||||
end
|
||||
@summ_sale = Sale.summary_sale_receipt(today,current_user)
|
||||
@total_customer = Sale.total_customer(today,current_user)
|
||||
@total_dinein = Sale.total_dinein(today,current_user)
|
||||
@total_takeaway = Sale.total_takeaway(today,current_user)
|
||||
@total_other_customer = Sale.total_other_customer(today,current_user)
|
||||
@total_membership = Sale.total_membership(today,current_user)
|
||||
@summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to)
|
||||
@total_customer = Sale.total_customer(today,current_user,@from,@to)
|
||||
@total_dinein = Sale.total_dinein(today,current_user,@from,@to)
|
||||
@total_takeaway = Sale.total_takeaway(today,current_user,@from,@to)
|
||||
@total_other_customer = Sale.total_other_customer(today,current_user,@from,@to)
|
||||
@total_membership = Sale.total_membership(today,current_user,@from,@to)
|
||||
|
||||
@total_order = Sale.total_order(today,current_user)
|
||||
@total_accounts = Sale.total_account(today,current_user)
|
||||
@total_order = Sale.total_order(today,current_user,@from,@to)
|
||||
@total_accounts = Sale.total_account(today,current_user,@from,@to)
|
||||
@account_data = Array.new
|
||||
@total_accounts.each do |account|
|
||||
acc = Sale.account_data(account.account_id, today,current_user)
|
||||
acc = Sale.account_data(account.account_id, today,current_user,@from,@to)
|
||||
if !acc.nil?
|
||||
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
||||
end
|
||||
end
|
||||
|
||||
@top_items = Sale.top_items(today,current_user)
|
||||
@total_foc_items = Sale.total_foc_items(today,current_user)
|
||||
@top_items = Sale.top_items(today,current_user,@from,@to)
|
||||
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to)
|
||||
|
||||
# get printer info
|
||||
@print_settings = PrintSetting.get_precision_delimiter()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,12 +36,20 @@ class StockJournal < ApplicationRecord
|
||||
journal.save
|
||||
end
|
||||
|
||||
def self.inventory_balances(today)
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
def self.inventory_balances(today,from,to)
|
||||
if !from.nil? && !to.nil?
|
||||
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")
|
||||
.where("stock_journals.created_at between '#{from}' and '#{to}'")
|
||||
.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
else
|
||||
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")
|
||||
.where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'")
|
||||
.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -67,21 +67,23 @@
|
||||
<!-- CPU Usage -->
|
||||
|
||||
<!-- Date range for dashboard -->
|
||||
<!-- <div class="row clearfix">
|
||||
<div class="row clearfix">
|
||||
<div class="col-lg-4 col-md-4 col-sm-4">
|
||||
<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" placeholder="From date" style="height: 35px;">
|
||||
<input data-behaviour='datepicker' class="form-control datepicker" name="from" id="from" type="text" value="<%= Time.now.utc.strftime('%d-%m-%Y') %>" placeholder="From date" style="height: 35px;">
|
||||
<span id="fromErr" style="color:red;"></span>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-4 col-sm-4">
|
||||
<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" placeholder="To date" style="height: 35px;">
|
||||
<input data-behaviour='datepicker' class="form-control datepicker" name="to" id="to" type="text" value="<%= Time.now.utc.strftime('%d-%m-%Y') %>" placeholder="To date" style="height: 35px;">
|
||||
<span id="toErr" style="color:red;"></span>
|
||||
</div>
|
||||
<div class="col-lg-2 col-md-2 col-sm-2">
|
||||
<label></label><br>
|
||||
<input type="button" value="Generate" class='btn btn-primary btn_generate'>
|
||||
</div>
|
||||
</div>
|
||||
<br> -->
|
||||
<br>
|
||||
<!-- Date range for dashboard -->
|
||||
|
||||
<div class="row">
|
||||
@@ -315,4 +317,39 @@
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
var from = '<%= @from.strftime('%d-%m-%Y') rescue '' %>';
|
||||
var to = '<%= @to.strftime('%d-%m-%Y') rescue '' %>';
|
||||
|
||||
if((from!=undefined) && (from != null) && (from != '')){
|
||||
$('#from').val(from);
|
||||
}
|
||||
if((to!=undefined) && (to != null) && (to != '')){
|
||||
$('#to').val(to);
|
||||
}
|
||||
});
|
||||
|
||||
$('.btn_generate').on('click',function(){
|
||||
var from = $("#from").val();
|
||||
var to = $("#to").val();
|
||||
if((from=='') && (to=='')){
|
||||
$('#fromErr').html("can't be blank");
|
||||
$('#toErr').html("can't be blank");
|
||||
}else if((from!='') && (to=='')){
|
||||
$('#fromErr').html("");
|
||||
$('#toErr').html("can't be blank");
|
||||
}else if((from=='') && (to!='')){
|
||||
$('#fromErr').html("can't be blank");
|
||||
$('#toErr').html("");
|
||||
}else{
|
||||
$('#fromErr').html("");
|
||||
$('#toErr').html("");
|
||||
}
|
||||
if((from!='') && (to!='')){
|
||||
window.location.href = '/dashboard?from='+from+'&to='+to;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user