From 0921d720f94cd2557f9c64d74aa7c065fa56530e Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 2 Oct 2024 17:42:08 -0500 Subject: [PATCH] update consulta reportes --- app/Http/Livewire/ShowReportes.php | 50 ++++----- .../views/livewire/show-reportes.blade.php | 106 +++++++++--------- 2 files changed, 74 insertions(+), 82 deletions(-) diff --git a/app/Http/Livewire/ShowReportes.php b/app/Http/Livewire/ShowReportes.php index 058deb5..2f64235 100755 --- a/app/Http/Livewire/ShowReportes.php +++ b/app/Http/Livewire/ShowReportes.php @@ -17,54 +17,48 @@ class ShowReportes extends Component public $fecha; public $mes; public $usuario; - + public function render() { - - // $this->fechaActual = Carbon::now(); - // $this->fechaActual = Carbon::parse($this->fechaActual); - if(!empty($this->usuario)){ + 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(); + $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"){ + } 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(); - + } else { + $consulta_suma = Historiale::where('vendedor_id', auth()->user()->id)->sum('valor'); + $consulta_cantidad = Historiale::where('vendedor_id', auth()->user()->id)->count(); } - if (!empty($this->mes)) { - - $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(); + $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(); } - } - - + $distribuidores = Role::where('nombre', 'distribuidor')->orWhere('nombre', 'mayorista') + ->with(['usuarios' => function ($query) { + $query->orderBy('name', 'asc'); + }])->first(); - $distribuidores = Role::where('nombre','distribuidor')->with('usuarios')->first(); + if (!empty($this->usuario)) { + $id_user = $this->usuario; - $historial = Historiale::where('cliente_id', auth()->user()->id)->orderBy('id','DESC')->paginate(10); - //dd($historial); + $historial = Historiale::where('cliente_id', $id_user)->orderBy('id', 'DESC')->paginate(10); + } else { + $historial = Historiale::where('cliente_id', auth()->user()->id)->orderBy('id', 'DESC')->paginate(10); + } - return view('livewire.show-reportes',[ + return view('livewire.show-reportes', [ 'suma' => $consulta_suma, 'cantidad' => $consulta_cantidad, 'roles' => $distribuidores, diff --git a/resources/views/livewire/show-reportes.blade.php b/resources/views/livewire/show-reportes.blade.php index be34515..843168e 100755 --- a/resources/views/livewire/show-reportes.blade.php +++ b/resources/views/livewire/show-reportes.blade.php @@ -1,20 +1,21 @@ -
+
- + Reportes
- @if (auth()->user()->rol->nombre == "super" || auth()->user()->rol->nombre == "administrador") - + + @foreach ($roles->usuarios as $usuario) + + @endforeach - + @endif