-
-
Save farr433/23a8b77febcf539976c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@section('widgetSales4Weeks') | |
<div class="col-lg-8"> | |
<div class="panel panel-default"> | |
<div class="panel-heading"> | |
<i class="fa fa-bar-chart-o fa-fw"></i> Store Numbers (The dates are the first day of the week) | |
<div class="pull-right"> | |
<div class="btn-group"> | |
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown"> | |
Focus | |
<span class="caret"></span> | |
</button> | |
<ul class="dropdown-menu pull-right" role="menu"> | |
<li><a href="#" onclick="drawSales()">Sales</a> | |
</li> | |
<li><a href="#" onclick="drawLabor()">Efficiency</a> | |
</li> | |
<li><a href="#" onclick="drawCOGS()">COGS</a> | |
</li> | |
<li class="divider"></li> | |
<li><a href="#" onclick="comingSoon()">More Options</a> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<!-- /.panel-heading --> | |
<div class="panel-body"> | |
<div id="chart_div"></div> | |
<div class="table-responsive"> | |
<table class="table table-striped table-bordered table-hover" id="example"> | |
<thead> | |
<tr> | |
<th>Store</th> | |
<th>Week Start</th> | |
<th id="focus">Sales</th> | |
</tr> | |
</thead> | |
</table> | |
</div> | |
</div> | |
<!-- /.panel-body --> | |
</div> | |
</div> | |
@columnchart('weekSales', 'chart_div') | |
<!-- /#wrapper --> | |
<script type="text/javascript"> | |
var table = ""; | |
$(document).ready(function () { | |
var jaffa = ''; | |
table = $('#example').dataTable({ | |
"ajax": { | |
"url": "{{ URL::route('get4WeekSales') }}", | |
"type": "POST" | |
}, | |
"columns": [ | |
{ "data": "store" }, | |
{ "data": "weekStart" }, | |
{ "data": "sales" }, | |
] | |
}); | |
}); | |
function drawSales() | |
{ | |
document.getElementById('focus').innerHTML = 'Store Sales'; | |
var jsonData = $.ajax({ | |
url: "{{ URL::route('getAllStoresWeekSales') }}", | |
type: 'POST', | |
dataType: 'json', | |
async: false | |
}).responseText; | |
jsonData = JSON.parse(jsonData); | |
var tableData = JSON.parse(jsonData['table']); | |
var arrayLength = tableData.data.length; | |
lava.loadData('weekSales', jsonData['graph'], function (chart) { | |
console.log(chart); | |
}); | |
//redraw the data table | |
table.fnClearTable(); | |
for (i = 0; i < arrayLength; i++) | |
{ | |
$('#example').dataTable().fnAddData(tableData.data[i]); | |
} | |
} | |
function drawLabor() | |
{ | |
document.getElementById('focus').innerHTML = 'Labor Efficiency'; | |
var jsonData = $.ajax({ | |
url: "{{ URL::route('getAllStoresWeekLabor') }}", | |
type: 'POST', | |
dataType: 'json', | |
async: false | |
}).responseText; | |
jsonData = JSON.parse(jsonData); | |
var tableData = JSON.parse(jsonData['table']); | |
var arrayLength = tableData.data.length; | |
lava.loadData('weekSales', jsonData['graph'], function (chart) {}); | |
//redraw the data table | |
table.fnClearTable(); | |
for (i = 0; i < arrayLength; i++) | |
{ | |
$('#example').dataTable().fnAddData(tableData.data[i]); | |
} | |
} | |
</script> | |
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ReportHelperController extends BaseController | |
{ | |
public function getAllStoreSalesGraph($start, $end) | |
{ | |
//Initially loaded data | |
//Sales graph | |
$sales = ReportStoreSale::whereBetween('start_date', array($start, $end))->get(); | |
foreach($sales as $sale) | |
{ | |
$rowData[$sale->start_date][$sale->location_id] = $sale->sales_amount; | |
$rowData['locations'][] = $sale->location_id; | |
$rowData['dates'][] = $sale->start_date; | |
} | |
$weekSales = Lava::DataTable(); | |
$formatter = Lava::NumberFormat(array( | |
'pattern' => '###,###', | |
'prefix' => '$', | |
)); | |
$weekSales->addDateColumn('Week Start'); | |
foreach(array_unique($rowData['locations']) as $location) | |
{ | |
$weekSales->addNumberColumn(SettingsLocationDef::find($location)->name, $formatter); | |
} | |
foreach(array_unique($rowData['dates']) as $startDate) | |
{ | |
$data = array(); | |
$data[] = $startDate; | |
foreach(array_unique($rowData['locations']) as $location) | |
{ | |
$data[] = $rowData[$startDate][$location]; | |
} | |
$weekSales->addRow($data); | |
$start = strtotime($start); | |
$start = date('Y-m-d', strtotime('+ 7 Days', $start)); | |
} | |
$columnChart = Lava::ColumnChart('weekSales') | |
->setOptions(array( | |
'datatable' => $weekSales, | |
'title' => 'Company Performance', | |
'titleTextStyle' => Lava::TextStyle(array( | |
'color' => '#eb6b2c', | |
'fontSize' => 14 | |
)),)); | |
return $columnChart; | |
} | |
public function getAllStoresWeekLabor() | |
{ | |
//Used by the drawLabor function | |
$start = date('Y-m-d', strtotime("Monday - 6 weeks")); | |
$end = date('Y-m-d'); | |
$dataTableArray = array(); | |
//Labor graph | |
$labors = ReportStoreLabor::whereBetween('start_date', array($start, $end))->get(); | |
foreach($labors as $labor) | |
{ | |
$laborDollarTotal = $labor->labor_dollar + $labor->modifier;//Total labor dollar amount | |
$laborHourTotal = $labor->original_hours + $labor->overtime_hours; | |
$currentSales = ReportStoreSale::where('start_date', '=', $labor->start_date)->where('location_id', '=', $labor->location_id)->first(); | |
if(count($currentSales) > 0) | |
{ | |
$efficiency = number_format(($currentSales->sales_amount / $laborHourTotal), 2); | |
} | |
else | |
{ | |
$efficiency = 0; | |
} | |
$rowData[$labor->start_date][$labor->location_id] = $efficiency; | |
$rowData['locations'][] = $labor->location_id; | |
$rowData['dates'][] = $labor->start_date; | |
$dataTableArray['data'][] = array( | |
'store' => $labor->location_id, | |
'weekStart' => $labor->start_date, | |
'sales' => $efficiency | |
); | |
} | |
$weekSales = Lava::DataTable(); | |
$formatter = Lava::NumberFormat(array( | |
'pattern' => '###,###', | |
'prefix' => '$', | |
)); | |
$weekSales->addDateColumn('Week Start'); | |
foreach(array_unique($rowData['locations']) as $location) | |
{ | |
$weekSales->addNumberColumn(SettingsLocationDef::find($location)->name, $formatter); | |
} | |
foreach(array_unique($rowData['dates']) as $startDate) | |
{ | |
$data = array(); | |
$data[] = $startDate; | |
foreach(array_unique($rowData['locations']) as $location) | |
{ | |
$data[] = $rowData[$startDate][$location]; | |
} | |
$weekSales->addRow($data); | |
$start = strtotime($start); | |
$start = date('Y-m-d', strtotime('+ 7 Days', $start)); | |
} | |
$columnChart = Lava::ColumnChart('weekSales') | |
->setOptions(array( | |
'datatable' => $weekSales, | |
'title' => 'Company Performance', | |
'titleTextStyle' => Lava::TextStyle(array( | |
'color' => '#eb6b2c', | |
'fontSize' => 14 | |
)),)); | |
$jsonData['graph'] = $weekSales->toJson(); | |
$jsonData['table'] = json_encode($dataTableArray); | |
return $jsonData; | |
} | |
public function getAllStoresWeekSales() | |
{ | |
//used by drawSales function | |
$start = date('Y-m-d', strtotime("Monday - 6 weeks")); | |
$end = date('Y-m-d'); | |
$dataTableArray = array(); | |
//Get Sales Records | |
$sales = ReportStoreSale::whereBetween('start_date', array($start, $end))->get(); | |
foreach($sales as $sale) | |
{ | |
$rowData[$sale->start_date][$sale->location_id] = $sale->sales_amount; | |
$rowData['locations'][] = $sale->location_id; | |
$rowData['dates'][] = $sale->start_date; | |
$dataTableArray['data'][] = array( | |
'store' => $sale->location_id, | |
'weekStart' => $sale->start_date, | |
'sales' => '$'. number_format($sale->sales_amount,2) | |
); | |
} | |
//Create the sales data table | |
$weekSales = Lava::DataTable(); | |
//Format the sales column | |
$formatter = Lava::NumberFormat(array( | |
'pattern' => '###,###', | |
'prefix' => '$', | |
)); | |
//Create a date column | |
$weekSales->addDateColumn('Week Start'); | |
foreach(array_unique($rowData['locations']) as $location) | |
{ | |
//Create the store's column | |
$weekSales->addNumberColumn(SettingsLocationDef::find($location)->name, $formatter); | |
} | |
//Get each store's record for one day at a time | |
foreach(array_unique($rowData['dates']) as $startDate) | |
{ | |
$data = array(); | |
$data[] = $startDate; | |
foreach(array_unique($rowData['locations']) as $location) | |
{ | |
$data[] = $rowData[$startDate][$location]; | |
} | |
$weekSales->addRow($data); | |
$start = strtotime($start); | |
$start = date('Y-m-d', strtotime('+ 7 Days', $start)); | |
} | |
$columnChart = Lava::ColumnChart('weekSales') | |
->setOptions(array( | |
'datatable' => $weekSales, | |
'title' => 'Company Performance', | |
'titleTextStyle' => Lava::TextStyle(array( | |
'color' => '#eb6b2c', | |
'fontSize' => 14 | |
)),)); | |
$jsonData['graph'] = $weekSales->toJson(); | |
$jsonData['table'] = json_encode($dataTableArray); | |
return $jsonData; | |
} | |
public function getAllStoresSalesBetweenTable() | |
{ | |
$start = date('Y-m-d', strtotime("-4 weeks")); | |
$end = date('Y-m-d'); | |
$sales = ReportStoreSale::whereBetween('start_date', array($start, $end))->get(); | |
$dataTableArray = array(); | |
//Construct Data Table | |
foreach ($sales as $sale) | |
{ | |
$dataTableArray['data'][] = array( | |
'store' => $sale->location_id, | |
'weekStart' => $sale->start_date, | |
'sales' => $sale->sales_amount | |
); | |
} | |
return json_encode($dataTableArray); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment