update consulta reportes

This commit is contained in:
Felipe
2024-10-02 17:42:08 -05:00
parent 3c2e34c063
commit 0921d720f9
2 changed files with 74 additions and 82 deletions
+23 -29
View File
@@ -20,51 +20,45 @@ class ShowReportes extends Component
public function render() public function render()
{ {
if (!empty($this->usuario)) {
// $this->fechaActual = Carbon::now();
// $this->fechaActual = Carbon::parse($this->fechaActual);
if(!empty($this->usuario)){
$id_user = $this->usuario; $id_user = $this->usuario;
$consulta_suma = Historiale::where('vendedor_id', $id_user)->sum('valor'); $consulta_suma = Historiale::where('vendedor_id', $id_user)->sum('valor');
$consulta_cantidad = Historiale::where('vendedor_id', $id_user)->count(); $consulta_cantidad = Historiale::where('vendedor_id', $id_user)->count();
if (!empty($this->mes)) { if (!empty($this->mes)) {
$consulta_suma = Historiale::where('vendedor_id', $id_user)->whereMonth('created_at', $this->mes)->sum('valor');
$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_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_suma = Historiale::sum('valor');
$consulta_cantidad = Historiale::count(); $consulta_cantidad = Historiale::count();
}else{ } else {
$consulta_suma = Historiale::where('vendedor_id', auth()->user()->id)->sum('valor');
$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)->count();
$consulta_cantidad = Historiale::where('vendedor_id', auth()->user()->id)->whereMonth('created_at',$this->mes)->count();
} }
if (!empty($this->mes)) { if (!empty($this->mes)) {
$consulta_suma = Historiale::where('vendedor_id', auth()->user()->id)->whereMonth('created_at', $this->mes)->sum('valor');
$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_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();
if (!empty($this->usuario)) {
$id_user = $this->usuario;
$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', [
$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, 'suma' => $consulta_suma,
'cantidad' => $consulta_cantidad, 'cantidad' => $consulta_cantidad,
'roles' => $distribuidores, 'roles' => $distribuidores,
@@ -1,17 +1,18 @@
<div class="bg-white overflow-y-auto md:w-[95%] m-auto p-2 md:p-5 rounded-[1.2rem] border-b border-gray-200 shadow-md relative h-[95%] "> <div
class="bg-white overflow-y-auto md:w-[95%] m-auto p-2 md:p-5 rounded-[1.2rem] border-b border-gray-200 shadow-md relative h-[95%] ">
<div class="flex justify-between my-2 items-center mb-4"> <div class="flex justify-between my-2 items-center mb-4">
<div class="flex items-center md:gap-4"> <div class="flex items-center md:gap-4">
<div class="flex text-sm"> <div class="flex text-sm">
<x-icon-arrow-right/> <x-icon-arrow-right />
Reportes Reportes
</div> </div>
</div> </div>
@if (auth()->user()->rol->nombre == "super" || auth()->user()->rol->nombre == "administrador") @if (auth()->user()->rol->nombre == 'super' || auth()->user()->rol->nombre == 'administrador')
<select wire:model="usuario" name="usr" id="usr" <select wire:model="usuario" name="usr" id="usr"
class="lg:w-1/6 border-2 border-neutral-200 rounded-[0.8rem] shadow apperance-none ring-0 focus:ring-0 focus:border-neutral-300 py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"> class="lg:w-1/6 border-2 border-neutral-200 rounded-[0.8rem] shadow apperance-none ring-0 focus:ring-0 focus:border-neutral-300 py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<option value="">Total</option> <option value="">Total</option>
@foreach($roles->usuarios as $usuario) @foreach ($roles->usuarios as $usuario)
<option value="{{$usuario->id}}">{{$usuario->name}}</option> <option value="{{ $usuario->id }}">{{ $usuario->name }}</option>
@endforeach @endforeach
</select> </select>
@@ -67,30 +68,28 @@
<th class="rounded-l-lg font-normal pl-[1rem] md:pl-[2rem]">Fecha</th> <th class="rounded-l-lg font-normal pl-[1rem] md:pl-[2rem]">Fecha</th>
<th class="font-normal sm:pl-[2rem] hidden sm:table-cell">Valor</th> <th class="font-normal sm:pl-[2rem] hidden sm:table-cell">Valor</th>
<th class="font-normal sm:pl-[2rem] hidden sm:table-cell">Estado</th> <th class="font-normal sm:pl-[2rem] hidden sm:table-cell">Estado</th>
<th class="rounded-r-lg font-normal pr-[1rem] pl-[1rem] sm:pr-[2rem] sm:pl-[2rem] ">Detalle</th> <th class="rounded-r-lg font-normal pr-[1rem] pl-[1rem] sm:pr-[2rem] sm:pl-[2rem] ">Detalle</th>
</tr> </tr>
</thead> </thead>
<tbody class="text-gray-500 select-none pr-4 sm:pr-2"> <tbody class="text-gray-500 select-none pr-4 sm:pr-2">
@foreach ($historiales as $historial) @foreach ($historiales as $historial)
<tr class="border-gray-200 text-left w-full sm:pl-4 " x-data="{openOption:false}"> <tr class="border-gray-200 text-left w-full sm:pl-4 " x-data="{ openOption: false }">
<td class="sm:pl-[2rem]">
<td class="sm:pl-[2rem] hidden sm:table-cell"> {{ $historial->fecha_inicio }}
{{$historial->fecha_inicio}}
</td> </td>
<td class="sm:pl-[2rem] hidden sm:table-cell"> <td class="sm:pl-[2rem] hidden sm:table-cell">
{{$historial->valor}} {{ $historial->valor }}
</td> </td>
<td class=" pl-[1rem] sm:pl-[2rem]"> <td class=" pl-[1rem] hidden sm:table-cell">
{{$historial->estado}} {{ $historial->estado }}
</td> </td>
<td class="md:pl-[2rem] md:pr-[2rem]"> <td class="md:pl-[2rem] md:pr-[2rem]">
@if(!empty($historial->tarifa_id)) @if (!empty($historial->tarifa_id))
{{$historial->tarifa->pantallas ?? ''}} {{ $historial->tarifa->servicio->nombre ?? ''}} {{ $historial->tarifa->pantallas ?? '' }} {{ $historial->tarifa->servicio->nombre ?? '' }}
@endif @endif
@if(!empty($historial->promocion_id)) @if (!empty($historial->promocion_id))
{{ $historial->promocion->nombre ?? ''}} {{ $historial->promocion->nombre ?? '' }}
@endif @endif
</td> </td>
</tr> </tr>
@@ -98,5 +97,4 @@
</tbody> </tbody>
</table> </table>
{{ $historiales->links() }} {{ $historiales->links() }}
</div> </div>