-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
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
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(); | ||
|
||
} | ||
} |
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
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
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
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); | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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