dashboard chart data
This commit is contained in:
@@ -59,6 +59,17 @@ class HomeController < ApplicationController
|
|||||||
|
|
||||||
def dashboard
|
def dashboard
|
||||||
@shop = Shop.first
|
@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)
|
||||||
|
@hourly_sales = Sale.hourly_sales(today)
|
||||||
|
.group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
||||||
|
.sum(:grand_total)
|
||||||
|
@employee_sales = Sale.employee_sales(today).sum(:grand_total)
|
||||||
|
@inventories = StockJournal.inventory_balances(today).sum(:balance)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|||||||
@@ -843,6 +843,28 @@ end
|
|||||||
return tax
|
return tax
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.top_products(today)
|
||||||
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||||
|
" i.price as unit_price,mi.name as product_name")
|
||||||
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
||||||
|
.where("(i.qty > 0 ) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||||
|
"and payment_status='paid' and sale_status= 'completed'")
|
||||||
|
.group('mi.name')
|
||||||
|
.order("SUM(i.qty) DESC").limit(5)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.hourly_sales(today)
|
||||||
|
query= Sale.select("grand_total").where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.employee_sales(today)
|
||||||
|
query = Sale.select("e.name as employee_name,grand_total")
|
||||||
|
.where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
|
.joins("join employees e on e.id=sales.cashier_id")
|
||||||
|
.group('e.name')
|
||||||
|
.order('e.name ASC')
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_custom_id
|
def generate_custom_id
|
||||||
|
|||||||
@@ -36,4 +36,12 @@ class StockJournal < ApplicationRecord
|
|||||||
journal.save
|
journal.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.inventory_balances(today)
|
||||||
|
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
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9 col-lg-9">
|
<div class="col-md-9 col-lg-9">
|
||||||
<h4><strong>Role Features</strong></h4>
|
<!-- <h4><strong>Role Features</strong></h4> -->
|
||||||
<!-- <p><strong>Note:</strong> The <strong>data-parent</strong> attribute makes sure that all collapsible elements under the specified parent will be closed when one of the collapsible item is shown.</p> -->
|
<!-- <p><strong>Note:</strong> The <strong>data-parent</strong> attribute makes sure that all collapsible elements under the specified parent will be closed when one of the collapsible item is shown.</p> -->
|
||||||
<div class="panel-group" id="accordion">
|
<div class="panel-group" id="accordion">
|
||||||
<% if current_user.role == 'administrator' %>
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
<div class="panel panel-default">
|
<!-- <div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h4 class="panel-title">
|
<h4 class="panel-title">
|
||||||
Administrator
|
Administrator
|
||||||
@@ -50,9 +50,46 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div> -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-heading"><h4>Top Products</h4></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<canvas id="top_products" width="400" height="200"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-heading"><h4>Inventory</h4></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<canvas id="inventory" width="400" height="200"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br><br>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-heading"><h4>Hourly Sales</h4></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<canvas id="hourly_sales" width="400" height="200"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-heading"><h4>Employee Sales</h4></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<canvas id="employee_sales" width="400" height="200"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% elsif current_user.role == 'manager' %>
|
<% elsif current_user.role == 'manager' %>
|
||||||
<div class="panel panel-default">
|
<!-- <div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h4 class="panel-title">
|
<h4 class="panel-title">
|
||||||
Manager
|
Manager
|
||||||
@@ -96,7 +133,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
<% elsif current_user.role == 'supervisour' %>
|
<% elsif current_user.role == 'supervisour' %>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
@@ -184,7 +221,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="footer" style="background-color: inherit">
|
<!-- <div class="footer" style="background-color: inherit">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="page-header center-text">
|
<div class="page-header center-text">
|
||||||
<h4 class="footer-header">
|
<h4 class="footer-header">
|
||||||
@@ -198,4 +235,195 @@
|
|||||||
<%= @shop.phone_no %>
|
<%= @shop.phone_no %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
|
<script src="js/Chart.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
var top_products = JSON.parse('<%= @top_products.to_json.html_safe %>');
|
||||||
|
var hourly_sales = JSON.parse('<%= @hourly_sales.to_json.html_safe %>');
|
||||||
|
var employee_sales = JSON.parse('<%= @employee_sales.to_json.html_safe %>');
|
||||||
|
var inventories = JSON.parse('<%= @inventories.to_json.html_safe %>');
|
||||||
|
showTopProductsChartData(top_products);
|
||||||
|
showHourlySalesChartData(hourly_sales);
|
||||||
|
showEmployeeSalesChartData(employee_sales);
|
||||||
|
showInventoryChartData(inventories);
|
||||||
|
});
|
||||||
|
|
||||||
|
function randomColorGenerator () {
|
||||||
|
return '#' + (Math.random().toString(16) + '0000000').slice(2, 8);
|
||||||
|
};
|
||||||
|
|
||||||
|
function showTopProductsChartData(top_products) {
|
||||||
|
var labels = [];
|
||||||
|
var datasets = [];
|
||||||
|
var backgroundColor = [];
|
||||||
|
|
||||||
|
if(top_products!=undefined && top_products!=''){
|
||||||
|
if(top_products.length>0){
|
||||||
|
$.each(top_products,function(k,val){
|
||||||
|
labels.push(val.product_name);
|
||||||
|
datasets.push(val.total_item);
|
||||||
|
backgroundColor.push(randomColorGenerator());
|
||||||
|
});
|
||||||
|
|
||||||
|
var chart = new Chart("top_products", {
|
||||||
|
type: 'pie',
|
||||||
|
data: {
|
||||||
|
labels: labels,
|
||||||
|
datasets: [{
|
||||||
|
data: datasets,
|
||||||
|
backgroundColor: backgroundColor
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
fontColor: 'black'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showHourlySalesChartData(hourly_sales) {
|
||||||
|
var labels = [];
|
||||||
|
var datasets = [];
|
||||||
|
var backgroundColor = [];
|
||||||
|
|
||||||
|
if(hourly_sales!=undefined && hourly_sales!=''){
|
||||||
|
if(Object.keys(hourly_sales).length > 0){
|
||||||
|
$.each(hourly_sales,function(k,val){
|
||||||
|
labels.push(k.toString());
|
||||||
|
datasets.push(val);
|
||||||
|
backgroundColor.push(randomColorGenerator());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var myChart = new Chart("hourly_sales", {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: labels,
|
||||||
|
datasets: [{
|
||||||
|
label: '',
|
||||||
|
data: datasets,
|
||||||
|
backgroundColor: backgroundColor,
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
display:false
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
xAxes: [{
|
||||||
|
stacked: true,
|
||||||
|
categorySpacing: 0,
|
||||||
|
barPercentage: 0.5
|
||||||
|
}],
|
||||||
|
yAxes: [{
|
||||||
|
stacked: true,
|
||||||
|
ticks: {
|
||||||
|
beginAtZero:true
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showEmployeeSalesChartData(employee_sales) {
|
||||||
|
var labels = [];
|
||||||
|
var datasets = [];
|
||||||
|
var backgroundColor = [];
|
||||||
|
|
||||||
|
if(employee_sales!=undefined && employee_sales!=''){
|
||||||
|
if(Object.keys(employee_sales).length > 0){
|
||||||
|
$.each(employee_sales,function(k,val){
|
||||||
|
labels.push(k.toString());
|
||||||
|
datasets.push(val);
|
||||||
|
backgroundColor.push(randomColorGenerator());
|
||||||
|
});
|
||||||
|
|
||||||
|
var myChart = new Chart("employee_sales", {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: labels,
|
||||||
|
datasets: [{
|
||||||
|
label: '',
|
||||||
|
data: datasets,
|
||||||
|
backgroundColor: backgroundColor,
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
display:false
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
xAxes: [{
|
||||||
|
stacked: true,
|
||||||
|
categorySpacing: 0,
|
||||||
|
barPercentage: 0.5
|
||||||
|
}],
|
||||||
|
yAxes: [{
|
||||||
|
stacked: true,
|
||||||
|
ticks: {
|
||||||
|
beginAtZero:true
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showInventoryChartData(inventories) {
|
||||||
|
var labels = [];
|
||||||
|
var datasets = [];
|
||||||
|
var borderColor = [];
|
||||||
|
|
||||||
|
if(inventories!=undefined && inventories!=''){
|
||||||
|
if(Object.keys(inventories).length > 0){
|
||||||
|
$.each(inventories,function(k,val){
|
||||||
|
labels.push(k.toString());
|
||||||
|
datasets.push(val);
|
||||||
|
borderColor.push(randomColorGenerator());
|
||||||
|
});
|
||||||
|
|
||||||
|
var myChart = new Chart("inventory", {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: labels,
|
||||||
|
datasets: [{
|
||||||
|
fill: false,
|
||||||
|
data: datasets,
|
||||||
|
borderColor: borderColor
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
display:false
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
xAxes: [{
|
||||||
|
stacked: true
|
||||||
|
}],
|
||||||
|
yAxes: [{
|
||||||
|
stacked: false,
|
||||||
|
ticks: {
|
||||||
|
beginAtZero:true
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
14031
public/js/Chart.js
vendored
Executable file
14031
public/js/Chart.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
10
public/js/Chart.min.js
vendored
Executable file
10
public/js/Chart.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user