@extends('template.template') @section('content') @php $user_id = $_GET['id']; $user = auth()->user(); use App\Models\Venda; use Carbon\Carbon; $yearAtual = isset($_GET['year']) ? $_GET['year'] : ucfirst(Carbon::now()->locale('pt_BR')->year); $ano = Carbon::now()->locale('pt_BR')->year; $monthName = ucfirst(Carbon::now()->locale('pt_BR')->monthName); // $vendas = Venda::where('user_id', $user_id)->whereRaw("year(date) = $yearAtual")->orderBy('id', 'desc')->get(); $vendas = Venda::selectRaw('MONTH(date) as month, SUM(product_value) as total_product_value, SUM(frame_value) as total_frame_value, SUM(commission) as total_commission, SUM(commission_paid) as total_commission_paid') ->where('user_id', $user_id) ->whereYear('date', $yearAtual) ->groupBy('month') ->orderBy('month', 'desc') ->get(); foreach ($vendas as $venda) { $venda->month_name = ucfirst(Carbon::create() ->month($venda->month) ->locale('pt_BR')->monthName); } $valorTotal = $vendas->sum(function ($venda) { return $venda->product_value + $venda->frame_value; }); $valorTotal = $vendas->sum('total_product_value') + $vendas->sum('total_frame_value'); $valorTotalComissoes = $vendas->sum('total_commission'); $valorTotalComissoesPagas = $vendas->sum('total_commission_paid'); @endphp
Total de vendas

{{ 'R$ ' . number_format($valorTotal, 2, ',', '.') }}

Total de comissões

{{ 'R$ ' . number_format($valorTotalComissoes, 2, ',', '.') }}

Ano de referência
HISTÓRICO DO VENDEDOR
@foreach ($vendas as $venda) @endforeach
# Vendedor Valor total Valor de comissão Recebido Pendente Mês de referência
{{ $user->id }} {{ $user->name }} {{ 'R$ ' . number_format($venda->total_product_value + $venda->total_frame_value, 2, ',', '.') }} {{ 'R$ ' . number_format($venda->total_commission, 2, ',', '.') }} {{ 'R$ ' . number_format($venda->total_commission_paid, 2, ',', '.') }} {{ 'R$ ' . number_format($venda->total_commission - $venda->total_commission_paid, 2, ',', '.') }} {{ $venda->month_name }} de {{ $yearAtual }} Visualizar
@endsection