Organizando y comenzando con interfaces

This commit is contained in:
2025-01-11 20:10:14 -03:00
parent 07b62a07a0
commit b87ae08b9a
52 changed files with 9492 additions and 361 deletions

View File

@@ -2,12 +2,143 @@
namespace App\Livewire\Cajas;
use App\Models\Turno;
use Illuminate\Contracts\View\View;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Number;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Computed;
use Livewire\Component;
use Livewire\WithPagination;
use Log;
use TallStackUi\Traits\Interactions;
class Index extends Component
{
public function render()
use Interactions, WithPagination;
public $modal = false;
public $fecha = null;
public $caja = null;
public $turno = null;
public array $sort = [
'column' => 'fecha',
'direction' => 'desc',
];
public function render(): View
{
return view('livewire.cajas.index');
}
public function createTurno(): void
{
$this->modal = true;
$this->fecha = now()->format('Y-m-d');
$this->caja = 1;
if (Turno::where('fecha', $this->fecha)->exists()) {
$this->turno = Turno::where('fecha', $this->fecha)->max('numero_turno') + 1;
} else {
$this->turno = 1;
}
}
public function storeTurno(): void
{
$this->validate([
'fecha' => 'required|date',
'caja' => 'required|gte:1|lte:10',
'turno' => 'required|gte:1|lte:10',
]);
$exists = Turno::where('fecha', $this->fecha)
->where('numero_caja', $this->caja)
->where('numero_turno', $this->turno)
->exists();
if ($exists) {
throw ValidationException::withMessages(['fecha' => 'Ya hay un registro para esta fecha, caja y turno']);
}
$turno = Turno::create([
'fecha' => $this->fecha,
'numero_caja' => $this->caja,
'numero_turno' => $this->turno,
]);
Session::flash('toast', ['type' => 'success', 'message' => 'Caja registrada correctamente']);
$this->redirectRoute('cajas.edit', $turno);
}
public function closeTurnoModal(): void
{
$this->modal = false;
$this->fecha = null;
$this->caja = null;
$this->turno = null;
$this->clearValidation();
}
public function confirmDelete($id): void
{
$this->dialog()->question('¿Esta seguro de eliminar este turno?', 'Se eliminara este junto a los ingresos y egresos registrados')
->confirm('Eliminar Turno', method: 'doDelete', params: $id)
->cancel()
->send();
}
public function doDelete($id): void
{
Turno::find($id)->delete();
$this->toast()->success('Turno eliminado correctamente')->send();
}
#[Computed]
public function headers(): array
{
return [
['index' => 'fecha', 'label' => 'Fecha'],
['index' => 'numero_caja', 'label' => 'Caja'],
['index' => 'numero_turno', 'label' => 'Turno'],
['index' => 'ingresos', 'label' => 'Ingresos'],
['index' => 'egresos', 'label' => 'Egresos'],
['index' => 'documentos', 'label' => 'Documento'],
['index' => 'diferencia', 'label' => 'diferencia'],
['index' => 'action', 'label' => 'Acciones'],
];
}
#[Computed]
public function rows(): LengthAwarePaginator
{
$turnos = Turno::orderBy('fecha', 'desc')
->orderBy('numero_caja', 'asc')
->orderBy('numero_turno', 'asc')
->paginate()
->through(function ($turno) {
return (object) [
'id' => $turno->id,
'fecha' => $turno->fecha->format('d-m-Y'),
'numero_caja' => $turno->numero_caja,
'numero_turno' => $turno->numero_turno,
'ingresos' => Number::currency($turno->ingresos()->sum('total')),
// 'egresos' => Number::currency(477960),
// 'documentos' => Number::currency(294717),
// 'diferencia' => Number::currency(-7544),
];
});
Log::info('', [$turnos]);
return $turnos;
}
}