Skip to content

Commit

Permalink
Graficos
Browse files Browse the repository at this point in the history
  • Loading branch information
weltonwms committed Oct 8, 2017
1 parent ad7cf12 commit 89163c7
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 5 deletions.
32 changes: 32 additions & 0 deletions app/Dash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Dash extends Model
{
public static function getProdutosMaisVendidos()
{
return \DB::table("vendas as v")
->join('produtos as p', 'p.id', '=', 'v.produto_id')
->selectRaw("SUM(v.qtd) as soma_qtd, v.produto_id, p.descricao")
->groupBy('v.produto_id')
->orderBy('soma_qtd','DESC')
->limit(8)
->get();

}

public static function getProdutosMaiorLucro()
{
return \DB::table(\DB::raw(" (SELECT id, produto_id, valor_compra, valor_venda, qtd, ((valor_venda - valor_compra)*qtd) as lucro FROM vendas ) as v"))
->join('produtos as p', 'p.id', '=', 'v.produto_id')
->selectRaw("v.produto_id, SUM(v.lucro) as total_lucro, p.descricao")
->groupBy('v.produto_id')
->orderBy('total_lucro','DESC')
->limit(8)
->get();

}
}
17 changes: 17 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Dash;

class HomeController extends Controller
{
Expand All @@ -25,4 +26,20 @@ public function index()
{
return view('home');
}

public function produtosMaisVendidos()
{
$produtos=Dash::getProdutosMaisVendidos();
$lista['quantidades']=$produtos->pluck('soma_qtd');
$lista['produtos']=$produtos->pluck('descricao');
return $lista;
}

public function produtosMaiorLucro()
{
$produtos=Dash::getProdutosMaiorLucro();
$lista['lucros']=$produtos->pluck('total_lucro');
$lista['produtos']=$produtos->pluck('descricao');
return $lista;
}
}
10 changes: 10 additions & 0 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ div.dataTables_wrapper div.dataTables_length {
font-size: 12px;
}

.panel-login.panel-danger>.panel-heading{
background-color: #CB282E;
color:#fff;
font-weight: 900;
}

.panel-login.panel-danger {
border-color: #CB282E;
}

97 changes: 97 additions & 0 deletions public/js/dash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

function loadChart1(data) {
var p1 = document.getElementById("p1");
var myChart1 = new Chart(p1, {
type: 'horizontalBar',
data: {
labels: data.produtos,
datasets: [{
label: 'qtd Vendida',
data: data.quantidades,
backgroundColor: 'rgba(51,122,183, 0.5)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
title: {
display: true,
text: 'Produtos Mais Vendidos (top 8)',
},
legend: {
display: false,
}
}
});
}



function loadChart2(data) {
var p2 = document.getElementById("p2");

var myChart2 = new Chart(p2, {
type: 'horizontalBar',
data: {
labels: data.produtos,
datasets: [{
label: 'Lucro Total Obtido',
data: data.lucros,
backgroundColor: 'rgba(51,122,183, 0.5)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
title: {
display: true,
text: 'Produtos que Renderam Mais Lucro(top 8)',
},
legend: {
display: false,
}
}
});
}





$.ajax({
method: "GET",
url: base_url + "produtosMaisVendidos",
dataType: "Json",
success: function (data) {
console.log(data.quantidades);
loadChart1(data);
}
});

$.ajax({
method: "GET",
url: base_url + "produtosMaiorLucro",
dataType: "Json",
success: function (data) {
console.log(data.quantidades);
loadChart2(data);
}
});






10 changes: 10 additions & 0 deletions public/plugins/chart.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
<section class='page-login'>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="text-center">
<img src="{{asset('imgs/logo.png')}}"/>
</div>

</div>

</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-danger panel-login">
<div class="panel-heading">Login</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('login') }}">
Expand Down
23 changes: 19 additions & 4 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@


<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="panel-heading">Produtos com mais Saída</div>

<div class="panel-body">
You are logged in!
<canvas id="p1" ></canvas>
</div>
</div>
</div>

<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Produtos com Maior Lucro</div>

<div class="panel-body">
<canvas id="p2" ></canvas>
</div>
</div>
</div>
</div>

@endsection
@endsection

@push('scripts')
<script src="{{ asset('plugins/chart.min.js') }}"></script>
<script src="{{ asset('js/dash.js') }}"></script>
@endpush
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
Route::post('logout', 'Auth\LoginController@logout')->name('logout');

Route::get('/home', 'HomeController@index')->name('home');
Route::get('/produtosMaisVendidos', 'HomeController@produtosMaisVendidos');
Route::get('/produtosMaiorLucro', 'HomeController@produtosMaiorLucro');

Route::group(['middleware' => 'auth'], function()
{
Expand Down

0 comments on commit 89163c7

Please sign in to comment.