75 lines
2.4 KiB
PHP
Executable File
75 lines
2.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use App\Models\Historiale;
|
|
use App\Models\Role;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Component;
|
|
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
|
use Livewire\WithPagination;
|
|
|
|
class ShowReportes extends Component
|
|
{
|
|
use LivewireAlert;
|
|
use WithPagination;
|
|
|
|
public $fecha;
|
|
public $mes;
|
|
public $usuario;
|
|
|
|
public function render()
|
|
{
|
|
|
|
// $this->fechaActual = Carbon::now();
|
|
// $this->fechaActual = Carbon::parse($this->fechaActual);
|
|
if(!empty($this->usuario)){
|
|
$id_user = $this->usuario;
|
|
|
|
$consulta_suma = Historiale::where('vendedor_id', $id_user)->sum('valor');
|
|
$consulta_cantidad = Historiale::where('vendedor_id', $id_user)->count();
|
|
|
|
if (!empty($this->mes)) {
|
|
|
|
$consulta_suma = Historiale::where('vendedor_id', $id_user)->whereMonth('created_at',$this->mes)->sum('valor');
|
|
$consulta_cantidad = Historiale::where('vendedor_id', $id_user)->whereMonth('created_at',$this->mes)->count();
|
|
}
|
|
|
|
|
|
}elseif(empty($this->usuario)){
|
|
if(auth()->user()->rol->nombre == "super" || auth()->user()->rol->nombre == "administrador"){
|
|
$consulta_suma = Historiale::sum('valor');
|
|
$consulta_cantidad = Historiale::count();
|
|
}else{
|
|
|
|
$consulta_suma = Historiale::where('vendedor_id', auth()->user()->id)->whereMonth('created_at',$this->mes)->sum('valor');
|
|
$consulta_cantidad = Historiale::where('vendedor_id', auth()->user()->id)->whereMonth('created_at',$this->mes)->count();
|
|
|
|
}
|
|
|
|
|
|
if (!empty($this->mes)) {
|
|
|
|
$consulta_suma = Historiale::whereMonth('created_at',$this->mes)->sum('valor');
|
|
$consulta_cantidad = Historiale::whereMonth('created_at',$this->mes)->count();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$distribuidores = Role::where('nombre','distribuidor')->with('usuarios')->first();
|
|
|
|
$historial = Historiale::where('cliente_id', auth()->user()->id)->orderBy('id','DESC')->paginate(10);
|
|
//dd($historial);
|
|
|
|
return view('livewire.show-reportes',[
|
|
'suma' => $consulta_suma,
|
|
'cantidad' => $consulta_cantidad,
|
|
'roles' => $distribuidores,
|
|
'historiales' => $historial,
|
|
]);
|
|
}
|
|
}
|