73 lines
1.9 KiB
PHP
Executable File
73 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use App\Models\Historiale;
|
|
use App\Models\Role;
|
|
use App\Models\Servicio;
|
|
use Carbon\Carbon;
|
|
use Livewire\Component;
|
|
|
|
class ShowUtilidades extends Component
|
|
{
|
|
public $promocion = 1;
|
|
|
|
public $servicio_id;
|
|
public $rol_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()
|
|
{
|
|
$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');
|
|
}
|
|
|
|
if ($this->rol_id) {
|
|
$query = $query->whereHas('vendedor', function ($q) {
|
|
$q->where('rol_id', $this->rol_id);
|
|
});
|
|
}
|
|
|
|
$query = $query->where('estado', 'activo')->orderByDesc('created_at')->get();
|
|
|
|
return view('livewire.show-utilidades', [
|
|
'historiales' => $query,
|
|
'servicios' => Servicio::where('estado', 'activo')->get(),
|
|
'roles' => Role::get(),
|
|
]);
|
|
}
|
|
}
|