administradores y editores puedes crear distribuidores

This commit is contained in:
Felipe
2024-06-14 09:22:22 -05:00
parent 195cff6d62
commit 5b1acb7bba
2 changed files with 118 additions and 79 deletions
+7 -1
View File
@@ -120,7 +120,13 @@ class ShowUsuarios extends Component
$consulta_tarifas = TarifaPromo::with('rol')->where('promocion_id', $this->servicio_modTarifas)->get();
}
$this->roles = Role::get();
if (Auth::user()->rol->nombre == "super") {
$this->roles = Role::get();
}else{
$this->roles = Role::where('nombre', '=', 'distribuidor')->get();
}
return view('livewire.show-usuarios', [
'usuarios' => $consulta_usuarios,
+111 -78
View File
@@ -22,17 +22,27 @@
<div class="bg-[#f5f5f5] md:w-full m-auto p-2 md:p-5 rounded-lg relative mb-4">
<div class="md:flex gap-4 justify-center my-2 items-center text-center">
<div class="flex text-sm">
<x-icon-arrow-right/>
<x-icon-arrow-right />
Usuario
</div>
<div class="flex gap-4">
@if (auth()->user()->rol->nombre !== 'administrador' && auth()->user()->rol->nombre !== 'editor')
<a x-on:click="add = !add" class="justify-center flex px-4 py-2 rounded-lg cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8] mb-3 md:mb-0">Añadir
@if (auth()->user()->rol->nombre === 'administrador' ||
auth()->user()->rol->nombre === 'editor' ||
auth()->user()->rol->nombre === 'super')
<a x-on:click="add = !add"
class="justify-center flex px-4 py-2 rounded-lg cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8] mb-3 md:mb-0">Añadir
usuario
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve" class="w-[0.87rem] ml-2">
<path d="M480,224H288V32c0-17.673-14.327-32-32-32s-32,14.327-32,32v192H32c-17.673,0-32,14.327-32,32s14.327,32,32,32h192v192 c0,17.673,14.327,32,32,32s32-14.327,32-32V288h192c17.673,0,32-14.327,32-32S497.673,224,480,224z" fill="#ffffff" />
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512"
style="enable-background:new 0 0 512 512;" xml:space="preserve" class="w-[0.87rem] ml-2">
<path
d="M480,224H288V32c0-17.673-14.327-32-32-32s-32,14.327-32,32v192H32c-17.673,0-32,14.327-32,32s14.327,32,32,32h192v192 c0,17.673,14.327,32,32,32s32-14.327,32-32V288h192c17.673,0,32-14.327,32-32S497.673,224,480,224z"
fill="#ffffff" />
</svg>
</a>
@endif
@if (auth()->user()->rol->nombre === 'super')
<a x-on:click="modTarifas = true"
class="justify-center flex px-4 py-2 rounded-lg cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8]">Mod.
tarifas promos.
@@ -50,10 +60,16 @@
</div>
<div class="flex relative text-sm mx-auto w-64 md:w-auto my-2">
<input id="buscar" type="search" wire:model="buscar" placeholder="Buscar" class=" shadow-sm border-2 active:border-neutral-200 focus:ring-0 border-neutral-200 w-64 md:w-auto rounded-md pr-7 py-1 m-auto focus:border-neutral-300 focus:outline-none focus:shadow-outline">
<svg class="w-5 absolute top-2 right-3" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" class="w-4 absolute" x="0" y="0" viewBox="0 0 24 24" style="enable-background:new 0 0 512 512;rotate: 90deg;" xml:space="preserve" class="">
<input id="buscar" type="search" wire:model="buscar" placeholder="Buscar"
class=" shadow-sm border-2 active:border-neutral-200 focus:ring-0 border-neutral-200 w-64 md:w-auto rounded-md pr-7 py-1 m-auto focus:border-neutral-300 focus:outline-none focus:shadow-outline">
<svg class="w-5 absolute top-2 right-3" xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" class="w-4 absolute"
x="0" y="0" viewBox="0 0 24 24" style="enable-background:new 0 0 512 512;rotate: 90deg;"
xml:space="preserve" class="">
<g id="Layer_31" data-name="Layer 31">
<path d="m21.71 20.29-5.4-5.39a7.92 7.92 0 0 0 1.69-4.9 8 8 0 1 0 -8 8 7.92 7.92 0 0 0 4.9-1.69l5.39 5.4a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42zm-17.71-10.29a6 6 0 1 1 6 6 6 6 0 0 1 -6-6z" fill="#b221fd" data-original="#000000" class=""></path>
<path
d="m21.71 20.29-5.4-5.39a7.92 7.92 0 0 0 1.69-4.9 8 8 0 1 0 -8 8 7.92 7.92 0 0 0 4.9-1.69l5.39 5.4a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42zm-17.71-10.29a6 6 0 1 1 6 6 6 6 0 0 1 -6-6z"
fill="#b221fd" data-original="#000000" class=""></path>
</g>
</svg>
</div>
@@ -71,29 +87,29 @@
<th class="font-normal">Ventas</th>
<th class="font-normal">Saldo</th>
@if (auth()->user()->rol->nombre == 'super')
<th class="font-normal"></th>
<th class="font-normal"></th>
<th class="rounded-r-lg font-normal"></th>
@endif
<th class="rounded-r-lg font-normal"></th>
</tr>
</x-slot>
<x-slot name="tbody">
@foreach ($usuarios as $usuario)
<tr class="border-gray-200 text-left" x-data="{ openOption: false }">
<td>{{$usuario->name ?? '' }}</td>
<td>{{$usuario->email ?? '' }}</td>
<td>{{$usuario->rol->nombre ?? '' }}</td>
<td>{{$usuario->historiales_venta_count ?? '' }}</td>
@if(!empty($usuario->saldo->valor))
<td>{{number_format($usuario->saldo->valor) ?? '' }}</td>
@else
<td></td>
@endif
<tr class="border-gray-200 text-left" x-data="{ openOption: false }">
<td>{{ $usuario->name ?? '' }}</td>
<td>{{ $usuario->email ?? '' }}</td>
<td>{{ $usuario->rol->nombre ?? '' }}</td>
<td>{{ $usuario->historiales_venta_count ?? '' }}</td>
@if (!empty($usuario->saldo->valor))
<td>{{ number_format($usuario->saldo->valor) ?? '' }}</td>
@else
<td></td>
@endif
@if (auth()->user()->rol->nombre == 'super')
<td>
<button wire:click="saldo({{ $usuario->id }})" class="justify-center text-sm flex px-2 py-1 rounded-lg cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8] mb-0 md:mb-0">Recargar</button>
</td>
@endif
@if (auth()->user()->rol->nombre == 'super')
<td>
<button wire:click="saldo({{ $usuario->id }})"
class="justify-center text-sm flex px-2 py-1 rounded-lg cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8] mb-0 md:mb-0">Recargar</button>
</td>
<td>
<button x-on:click="openOption=!openOption">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
@@ -104,33 +120,33 @@
</button>
<div x-cloak x-show="openOption" @click.away="openOption = false"
class="sm:absolute bg-white text-center w-[8rem] rounded-[1rem] border-b border-gray-200 shadow-lg right-10">
<button x-on:click="openOption=false" wire:click="editar({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 hover:rounded-t-[1rem]">Editar</button>
<button x-on:click="openOption=!openOption"
wire:click="editarPassword({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Editar
password</button>
<button x-on:click="openOption=false" wire:click="saldo({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Agregar
saldo</button>
<button x-on:click="openOption=false"
wire:click="saldodesc({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Descontar
saldo</button>
<button x-on:click="openOption=false,gestion=true"
wire:click="gestionar({{ $usuario->id }},'{{ $usuario->rol_id }}','{{ $usuario->name }}')"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Precio
servicio</button>
<button x-on:click="openOption=false,gestionPromo=true"
wire:click="gestionarPromociones({{ $usuario->id }},'{{ $usuario->name }}')"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Precio
promocion</button>
<button x-on:click="openOption=false"
wire:click="eliminar({{ $usuario->id }})"
class="text-white w-full py-1 bg-red-400 rounded-b-[1rem] hover:bg-red-600 hover:rounded-b-[1rem]">Eliminar</button>
</div>
class="sm:absolute bg-white text-center w-[8rem] rounded-[1rem] border-b border-gray-200 shadow-lg right-10">
<button x-on:click="openOption=false" wire:click="editar({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 hover:rounded-t-[1rem]">Editar</button>
<button x-on:click="openOption=!openOption"
wire:click="editarPassword({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Editar
password</button>
<button x-on:click="openOption=false" wire:click="saldo({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Agregar
saldo</button>
<button x-on:click="openOption=false" wire:click="saldodesc({{ $usuario->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Descontar
saldo</button>
<button x-on:click="openOption=false,gestion=true"
wire:click="gestionar({{ $usuario->id }},'{{ $usuario->rol_id }}','{{ $usuario->name }}')"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Precio
servicio</button>
<button x-on:click="openOption=false,gestionPromo=true"
wire:click="gestionarPromociones({{ $usuario->id }},'{{ $usuario->name }}')"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 ">Precio
promocion</button>
<button x-on:click="openOption=false" wire:click="eliminar({{ $usuario->id }})"
class="text-white w-full py-1 bg-red-400 rounded-b-[1rem] hover:bg-red-600 hover:rounded-b-[1rem]">Eliminar</button>
</div>
</td>
@endif
</tr>
@endforeach
</x-slot>
@@ -143,13 +159,16 @@
<div x-cloak x-show="gestion" x-transition:enter="transition duration-350"
x-transition:enter-start="opacity-0 scale-100" x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition duration-350" x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-100" class="absolute backdrop-blur-sm bg-black/20 left-0 bottom-0 top-0 right-0 h-full">
x-transition:leave-end="opacity-0 scale-100"
class="absolute backdrop-blur-sm bg-black/20 left-0 bottom-0 top-0 right-0 h-full">
<div class="grid h-full place-items-center ">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4 rounded-[1rem] shadow-md">
<p class="text-gray-500 mb-2"> Personalización de precios para {{ $usuario_nombre }} </p>
<div class="flex mb-4">
<input id="buscar_servicio" type="search" wire:model="buscar_servicio" placeholder="Buscar servicio" class="w-full md:w-auto shadow-md border-2 active:border-neutral-200 focus:ring-0 border-neutral-200 rounded-[0.8rem] px-4 py-1 m-auto focus:border-neutral-300 focus:outline-none focus:shadow-outline">
<input id="buscar_servicio" type="search" wire:model="buscar_servicio"
placeholder="Buscar servicio"
class="w-full md:w-auto shadow-md border-2 active:border-neutral-200 focus:ring-0 border-neutral-200 rounded-[0.8rem] px-4 py-1 m-auto focus:border-neutral-300 focus:outline-none focus:shadow-outline">
</div>
<div>
@@ -237,9 +256,11 @@
</td>
@if ($usuarioTarifa->visible !== 'true')
<td class="pl-[2rem] flex"><input type="checkbox" disabled readonly checked class="mx-auto p-2 rounded-full text-black"></td>
<td class="pl-[2rem] flex"><input type="checkbox" disabled readonly
checked class="mx-auto p-2 rounded-full text-black"></td>
@else
<td class="pl-[2rem] flex"><input type="checkbox" disabled readonly class="mx-auto p-2 rounded-full text-black"></td>
<td class="pl-[2rem] flex"><input type="checkbox" disabled readonly
class="mx-auto p-2 rounded-full text-black"></td>
@endif
<td class="pl-[2rem]">${{ $usuarioTarifa->precio ?? '' }}</td>
@@ -589,17 +610,20 @@
Monto a recargar
</div>
<div>
<input type="text" min="0" name="monto" wire:model="valor_recargar" placeholder="$100.000" required class="border-2 w-1/2 md:w-auto mb-2 border-neutral-200 rounded-[0.8rem] shadow apperance-none focus:border-neutral-300 focus:ring-0 py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" oninput="formatInput(this)">
<input type="text" min="0" name="monto" wire:model="valor_recargar"
placeholder="$100.000" required
class="border-2 w-1/2 md:w-auto mb-2 border-neutral-200 rounded-[0.8rem] shadow apperance-none focus:border-neutral-300 focus:ring-0 py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
oninput="formatInput(this)">
<div class="flex text-sm justify-center">Tu valor total seria: $<p>
@php
$valor_recargar = str_replace([',', '.'], '', $valor_recargar);
@endphp
@if(!empty($valor_recargar))
{{ number_format((int)$saldo_actual + (int)$valor_recargar) }}
@php
$valor_recargar = str_replace([',', '.'], '', $valor_recargar);
@endphp
@if (!empty($valor_recargar))
{{ number_format((int) $saldo_actual + (int) $valor_recargar) }}
@else
{{ number_format((int)$saldo_actual)}}
{{ number_format((int) $saldo_actual) }}
@endif
</p>
</div>
@@ -647,7 +671,7 @@
class="border-2 w-1/2 md:w-auto mb-2 border-neutral-200 rounded-[0.8rem] shadow apperance-none focus:border-neutral-300 focus:ring-0 py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<div class="flex text-sm justify-center">Tu valor total seria: $<p>
{{ number_format((int)$saldo_actual - (int)$valor_recargar) }}
{{ number_format((int) $saldo_actual - (int) $valor_recargar) }}
</p>
</div>
</div>
@@ -693,7 +717,8 @@
<div class="grid grid-cols-3 gap-2 text-left">
<div class="w-full">
<label class="text-gray-500 text-sm">Rol</label>
<select name="roles" id="roles" wire:model.debounce.500ms="roles_modTarifas" class="w-full border-2 border-neutral-200 rounded-lg focus:ring-0 shadow apperance-none focus:border-neutral-300 py-2 pl-2 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<select name="roles" id="roles" wire:model.debounce.500ms="roles_modTarifas"
class="w-full border-2 border-neutral-200 rounded-lg focus:ring-0 shadow apperance-none focus:border-neutral-300 py-2 pl-2 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<option value="" selected>Roles</option>
@foreach ($roles as $rol)
<option value="{{ $rol->id }}">{{ $rol->nombre ?? '' }}</option>
@@ -703,12 +728,16 @@
<div class="w-full">
<label class="text-gray-500 text-sm">Precio</label>
<input type="number" id="precio_modTarifas" wire:model="precio_modTarifas" min="0" class="w-full border-2 border-neutral-200 rounded-lg focus:ring-0 shadow apperance-none focus:border-neutral-300 py-2 pl-2 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<input type="number" id="precio_modTarifas" wire:model="precio_modTarifas"
min="0"
class="w-full border-2 border-neutral-200 rounded-lg focus:ring-0 shadow apperance-none focus:border-neutral-300 py-2 pl-2 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="w-full">
<label class="text-gray-500 text-sm">Utilidad</label>
<input type="text" type="number" id="utilidad" wire:model="utilidad" min="0" class="w-full border-2 border-neutral-200 rounded-lg focus:ring-0 shadow apperance-none focus:border-neutral-300 py-2 pl-2 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<input type="text" type="number" id="utilidad" wire:model="utilidad"
min="0"
class="w-full border-2 border-neutral-200 rounded-lg focus:ring-0 shadow apperance-none focus:border-neutral-300 py-2 pl-2 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
</div>
@@ -719,7 +748,8 @@
class="border-2 border-neutral-200 focus:ring-0 shadow apperance-none focus:border-neutral-300 text-[#B221FD] leading-tight focus:outline-none focus:shadow-outline">
</div>
<span>
<button wire:click="updateTarifas" type="button" class="inline-flex justify-center w-full md:w-auto rounded-md border border-transparent px-4 py-1 sm:mb-[0] mb-2 text-white bg-[#B221FD] hover:bg-[#7a02b8] focus:shadow-outline-green ease-in-out sm-text-sm sm-leading-5">Añadir</button>
<button wire:click="updateTarifas" type="button"
class="inline-flex justify-center w-full md:w-auto rounded-md border border-transparent px-4 py-1 sm:mb-[0] mb-2 text-white bg-[#B221FD] hover:bg-[#7a02b8] focus:shadow-outline-green ease-in-out sm-text-sm sm-leading-5">Añadir</button>
</span>
</div>
@@ -750,7 +780,8 @@
<td class="pl-[1rem]">{{ number_format($tarifa->precio) ?? 0 }}</td>
<td class="pl-[1rem]">{{ number_format($tarifa->utilidad) ?? 0 }}</td>
<td class="pl-[1rem]">
<button wire:click="editarTarifa({{ $tarifa }})" class="justify-center flex px-3 py-2 rounded-lg text-xs cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8]">Editar</button>
<button wire:click="editarTarifa({{ $tarifa }})"
class="justify-center flex px-3 py-2 rounded-lg text-xs cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8]">Editar</button>
</td>
</tr>
@endforeach
@@ -770,7 +801,11 @@
</div>
</div>
<div x-cloak x-show="editarTarifaRol" x-transition:enter="transition duration-350" x-transition:enter-start="opacity-0 scale-100" x-transition:enter-end="opacity-100 scale-100" x-transition:leave="transition duration-350" x-transition:leave-start="opacity-100 scale-100" x-transition:leave-end="opacity-0 scale-100" class="fixed backdrop-blur-sm bg-black/20 left-0 bottom-0 top-0 right-0 h-full z-20">
<div x-cloak x-show="editarTarifaRol" x-transition:enter="transition duration-350"
x-transition:enter-start="opacity-0 scale-100" x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition duration-350" x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-100"
class="fixed backdrop-blur-sm bg-black/20 left-0 bottom-0 top-0 right-0 h-full z-20">
<div class="grid h-full place-items-center">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4 rounded-[1rem] shadow-md">
@if ($informacionTarifaRol)
@@ -779,7 +814,8 @@
<div class="grid grid-cols-3 gap-2 text-left mb-4">
<div class="w-[6rem]">
<label class="text-gray-500 text-sm">Rol</label>
<select name="roles" id="roles" wire:model.debounce.500ms="roles_modTarifas"
<select name="roles" id="roles"
wire:model.debounce.500ms="roles_modTarifas"
class="border-2 border-neutral-200 rounded-[0.8rem] shadow apperance-none focus:border-neutral-300 focus:ring-0 w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<option value="" selected>Roles</option>
@foreach ($roles as $rol)
@@ -803,7 +839,8 @@
<div class="mb-4 grid grid-cols-2">
<div class="flex m-auto items-center">
<label class="text-gray-500 text-sm mr-2">Activa</label>
<input type="checkbox" id="estadoTarifa" wire:model="estadoTarifa" class="border-2 border-neutral-200 focus:ring-0 shadow apperance-none focus:border-neutral-300 text-[#B221FD] leading-tight focus:outline-none focus:shadow-outline">
<input type="checkbox" id="estadoTarifa" wire:model="estadoTarifa"
class="border-2 border-neutral-200 focus:ring-0 shadow apperance-none focus:border-neutral-300 text-[#B221FD] leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-3 mt-3 flex justify-end">
<span>
@@ -833,14 +870,10 @@
<script>
function formatInput(input) {
let unformattedValue = input.value.replace(/\D/g, '');
let formattedValue = unformattedValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
input.value = formattedValue;
}
</script>
</div>