diff --git a/app/Http/Livewire/ShowUtilidades.php b/app/Http/Livewire/ShowUtilidades.php index d0fbd48..b0759bc 100644 --- a/app/Http/Livewire/ShowUtilidades.php +++ b/app/Http/Livewire/ShowUtilidades.php @@ -2,12 +2,62 @@ namespace App\Http\Livewire; +use App\Models\Historiale; +use App\Models\Servicio; +use Carbon\Carbon; use Livewire\Component; class ShowUtilidades extends Component { + public $promocion; + + public $servicio_id; + + public $selectedYear = null; + public $selectedMonth = null; + public $selectedDay = null; + + public function mount() + { + $today = Carbon::now(); + $this->selectedYear = $today->format('Y'); + $this->selectedMonth = $today->format('m'); + $this->selectedDay = $today->format('d'); + } + public function render() { - return view('livewire.show-utilidades'); + $query = Historiale::with('vendedor', 'tarifa', 'promocion'); + + if (!empty($this->servicio_id)) { + $query = $query->whereHas('tarifa', function ($q) { + $q->where('servicio_id', $this->servicio_id); + }); + } + + if ($this->selectedYear) { + $query = $query->whereYear('fecha_inicio', $this->selectedYear); + } + + if ($this->selectedMonth) { + $query = $query->whereMonth('fecha_inicio', $this->selectedMonth); + } + + if ($this->selectedDay) { + $query = $query->whereDay('fecha_inicio', $this->selectedDay); + } + + if ($this->promocion) { + $query = $query->whereNotNull('promocion_id'); + } else { + $query = $query->whereNotNull('tarifa_id'); + } + + $query = $query->where('estado', 'activo')->orderByDesc('created_at')->get(); + + return view('livewire.show-utilidades', [ + 'historiales' => $query, + 'servicios' => Servicio::where('estado', 'activo')->get(), + ]); } } diff --git a/app/Models/Historiale.php b/app/Models/Historiale.php index 3a7a581..49aae21 100644 --- a/app/Models/Historiale.php +++ b/app/Models/Historiale.php @@ -44,7 +44,4 @@ class Historiale extends Model public function cuentas_obsoletas(){ return $this ->belongsToMany(Cuentas::class,'logs','historial_id','cuenta_id'); } - - - } diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index b00aad2..5d25419 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -109,6 +109,7 @@ x-data="{ menuG:false}" Gestión Categorias Logs cuentas Logs recargas + Utilidades Configuración @endif

diff --git a/resources/views/livewire/show-utilidades.blade.php b/resources/views/livewire/show-utilidades.blade.php index 0bf1ae7..e968548 100644 --- a/resources/views/livewire/show-utilidades.blade.php +++ b/resources/views/livewire/show-utilidades.blade.php @@ -1,3 +1,148 @@ -
- {{-- Care about people's approval and you will be their prisoner. --}} -
+
+
+
+
+ + + + Utilidades +
+ +
+ + +
+
+ +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+

Utilidades

+
+ + + + + + + + + + + @php + $totalUtilidades = 0; + @endphp + + @foreach ($historiales as $historial) + + + + + + + + @php + $totalUtilidades += $historial->tarifa->servicio->precio / $historial->tarifa->pantallas; + @endphp + @endforeach + + + + + + + + +
Fecha inicioServicioPantallasvalorUtilidad
+ {{ $historial->fecha_inicio }} + + {{ $historial->tarifa->servicio->nombre }} + + {{ $historial->tarifa->pantallas }} + + ${{ $historial->tarifa->servicio->precio }} + + ${{ number_format($historial->tarifa->servicio->precio / $historial->tarifa->pantallas ?? 0, 2, ',', '.') }} +
+ + + + + + +

+ Utilidad Total +

+
+

+ $ {{ number_format($totalUtilidades ?? 0, 2, ',', '.') }} +

+
+
+
+
+