Agregando documentos

This commit is contained in:
2025-01-12 02:03:23 -03:00
parent b87ae08b9a
commit e3fb7259b9
11 changed files with 314 additions and 22 deletions

View File

@@ -0,0 +1,130 @@
<?php
namespace App\Livewire\Cajas\Components;
use App\Enums\TipoDocumento;
use App\Models\Documento;
use App\Models\Turno;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\Number;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Validate;
use Livewire\Component;
use TallStackUi\Traits\Interactions;
class DocumentosComponent extends Component
{
use Interactions;
public Turno $turno;
#[Validate('required')]
public $tipo = null;
#[Validate('nullable')]
public $descripcion = null;
#[Validate('required|numeric')]
public $valor = null;
public $currentDocumento = null;
public function mount(): void
{
$this->tipo = TipoDocumento::cases()[0];
}
public function render(): View
{
return view('livewire.cajas.components.documentos-component');
}
public function save(): void
{
$this->validate();
if ($this->currentDocumento) {
Documento::where('id', $this->currentDocumento)->update([
'tipo_documento' => $this->tipo,
'descripcion' => $this->descripcion,
'valor' => $this->valor,
]);
} else {
$this->turno->documentos()->create([
'tipo_documento' => $this->tipo,
'descripcion' => $this->descripcion,
'valor' => $this->valor,
]);
}
if ($this->currentDocumento) {
$this->toast()->success('Exito!', 'Documento modificado correctamente')->send();
} else {
$this->toast()->success('Exito!', 'Documento guardado correctamente')->send();
}
$this->currentDocumento = null;
$this->descripcion = null;
$this->valor = null;
$this->dispatch('updated_totals');
}
public function edit($id): void
{
$this->currentDocumento = $id;
$documento = Documento::find($id);
$this->tipo = $documento->tipo_documento;
$this->descripcion = $documento->descripcion;
$this->valor = $documento->valor;
}
public function confirmDelete($id): void
{
$this->dialog()->question('¿Esta seguro de eliminar este documento?', 'No podrá recuperarlo')
->confirm('Eliminar Documento', method: 'delete', params: $id)
->cancel()
->send();
}
public function delete($id): void
{
Documento::where('id', $id)->delete();
$this->toast()->success('Documento eliminado correctamente')->send();
$this->dispatch('updated_totals');
}
#[Computed]
public function headers(): array
{
return [
['index' => 'tipo_documento', 'label' => 'Tipo Documento'],
['index' => 'descripcion', 'label' => 'Descripción'],
['index' => 'valor', 'label' => 'Total'],
['index' => 'action', 'label' => 'Acciones'],
];
}
#[Computed]
public function rows(): Collection
{
return $this->turno->documentos()
->orderBy('created_at', 'asc')
->get();
}
#[Computed]
public function tipos(): array
{
return TipoDocumento::cases();
}
#[Computed]
public function totalDocumentos(): string
{
return Number::currency($this->turno->documentos()->sum('valor'));
}
}

View File

@@ -76,6 +76,8 @@ class EgresosComponent extends Component
$this->numero = null;
$this->descripcion = null;
$this->valor = null;
$this->dispatch('updated_totals');
}
public function edit($id): void
@@ -102,6 +104,7 @@ class EgresosComponent extends Component
Egreso::where('id', $id)->delete();
$this->toast()->success('Egreso eliminado correctamente')->send();
$this->dispatch('updated_totals');
}
#[Computed]

View File

@@ -78,6 +78,8 @@ class IngresosComponent extends Component
$this->ingreso_inicial = null;
$this->ingreso_final = null;
$this->total = null;
$this->dispatch('updated_totals');
}
public function edit($id): void
@@ -104,6 +106,7 @@ class IngresosComponent extends Component
Ingreso::where('id', $id)->delete();
$this->toast()->success('Ingreso eliminado correctamente')->send();
$this->dispatch('updated_totals');
}
#[Computed]

View File

@@ -4,6 +4,9 @@ namespace App\Livewire\Cajas;
use App\Models\Turno;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Number;
use Livewire\Attributes\Computed;
use Livewire\Attributes\On;
use Livewire\Attributes\Url;
use Livewire\Component;
@@ -18,4 +21,69 @@ class Edit extends Component
{
return view('livewire.cajas.edit');
}
#[On('updated_totals')]
public function recalculateTotals(): void
{
unset($this->totalIngresos);
}
/*
private void fillResumen() {
long totalEfectivo = efectivo.getTotal();
long totalDocumentos = repos.documento.getTotalOfTurno(state.getTurno());
long totalIngresos = repos.ingreso.getTotalOfTurno(state.getTurno());
long totalEgresos = repos.egreso.getTotalTurno(state.getTurno());
long rendido = totalDocumentos + totalEfectivo + totalEgresos;
long diferencia = rendido - totalIngresos;
view.setResumenEfectivo(totalEfectivo);
view.setResumenDocumentos(totalDocumentos);
view.setResumenEgreso(totalEgresos);
view.setResumenRendido(rendido);
view.setResumenDebeRendir(totalIngresos);
view.setResumenDiferencia(diferencia);
}
*/
#[Computed]
public function totalEfectivo()
{
return $this->turno->efectivo()->first()?->total ?? 0;
}
#[Computed]
public function totalEgresos()
{
return $this->turno->egresos()->sum('valor');
}
#[Computed]
public function totalDocumentos()
{
return $this->turno->documentos()->sum('valor');
}
#[Computed]
public function rendido()
{
$documentos = $this->turno->documentos()->sum('valor');
$egresos = $this->turno->egresos()->sum('valor');
$efectivo = $this->turno->efectivo()->first()?->total ?? 0;
return $documentos + $efectivo + $egresos;
}
#[Computed]
public function debeRendir() {
return $this->turno->ingresos()->sum('total');
}
#[Computed]
public function diferencia() {
return $this->rendido - $this->debeRendir;
}
}