Agregando documentos
This commit is contained in:
@@ -4,8 +4,8 @@ namespace App\Enums;
|
||||
|
||||
enum TipoDocumento: string
|
||||
{
|
||||
case ChequesDia = 'Cheques al Dia';
|
||||
case TarjetasCredito = 'Tarjetas de Credito';
|
||||
case TarjetasDebito = 'Tarjetas de Debito';
|
||||
case ChequesDia = 'Cheques al Dia';
|
||||
case Retiro = 'Retiro';
|
||||
}
|
||||
|
||||
130
app/Livewire/Cajas/Components/DocumentosComponent.php
Normal file
130
app/Livewire/Cajas/Components/DocumentosComponent.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,4 +15,10 @@ class Documento extends Model
|
||||
protected $casts = [
|
||||
'tipo_documento' => TipoDocumento::class,
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'tipo_documento',
|
||||
'valor',
|
||||
'descripcion'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@@ -10,4 +11,18 @@ class Efectivo extends Model
|
||||
use HasUlids;
|
||||
|
||||
protected $table = 'efectivos';
|
||||
|
||||
public function getTotal(): Attribute {
|
||||
return Attribute::get(function () {
|
||||
return $this->veinte_mil
|
||||
+ $this->diez_mil
|
||||
+ $this->cinco_mil
|
||||
+ $this->dos_mil
|
||||
+ $this->mil
|
||||
+ $this->quinientos
|
||||
+ $this->cien
|
||||
+ $this->cincuenta
|
||||
+ $this->diez;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Turno extends Model
|
||||
{
|
||||
@@ -26,4 +27,12 @@ class Turno extends Model
|
||||
{
|
||||
return $this->hasMany(Egreso::class, 'turno_id');
|
||||
}
|
||||
public function documentos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Documento::class, 'turno_id');
|
||||
}
|
||||
public function efectivo(): HasOne
|
||||
{
|
||||
return $this->hasOne(Efectivo::class, 'turno_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ return new class extends Migration
|
||||
|
||||
Schema::create('documentos', function (Blueprint $table) {
|
||||
$table->ulid('id')->primary();
|
||||
$table->text('descripcion');
|
||||
$table->text('descripcion')->nullable();
|
||||
$table->bigInteger('valor');
|
||||
$table->text('tipo_documento');
|
||||
$table->foreignUlid('turno_id')->constrained('turnos')->cascadeOnDelete();
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<div>
|
||||
<form wire:submit.prevent="save" class="grid lg:grid-cols-[repeat(3,minmax(0,2fr))_1fr] gap-2 mb-4 items-end">
|
||||
<x-select.styled label="Tipo Documento" :options="$this->tipos" wire:model="tipo" id="tipo" required
|
||||
searchable invalidate/>
|
||||
<x-input label="Descripción" wire:model="descripcion" invalidate/>
|
||||
<x-input label="Total" wire:model="valor" invalidate/>
|
||||
|
||||
<x-button type="submit">
|
||||
@if($this->currentDocumento)
|
||||
Guardar
|
||||
@else
|
||||
Agregar
|
||||
@endif
|
||||
</x-button>
|
||||
|
||||
|
||||
<p class="text-sm font-medium text-red-500">
|
||||
@error('tipo'){{$message}}@enderror
|
||||
</p>
|
||||
<p class="text-sm font-medium text-red-500">
|
||||
@error('descripcion'){{$message}}@enderror
|
||||
</p>
|
||||
<p class="text-sm font-medium text-red-500">
|
||||
@error('valor'){{$message}}@enderror
|
||||
</p>
|
||||
|
||||
</form>
|
||||
<x-table striped :headers="$this->headers" :rows="$this->rows">
|
||||
@interact('column_action', $row)
|
||||
<x-button.circle icon="edit" wire:click="edit('{{$row->id}}')" :key="uniqid()"/>
|
||||
<x-button.circle icon="trash" color="red" wire:click="confirmDelete('{{$row->id}}')" :key="uniqid()"/>
|
||||
@endinteract
|
||||
</x-table>
|
||||
|
||||
<div class="mt-4">
|
||||
<p class="text-xl">Documentos Totales: <span class="font-bold">{{$this->totalDocumentos}}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,3 +1,4 @@
|
||||
@use(Illuminate\Support\Number)
|
||||
<div>
|
||||
<div class="flex gap-2 justify-between items-baseline">
|
||||
<x-title>
|
||||
@@ -24,24 +25,43 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<x-tab wire:model="tab">
|
||||
<x-tab.items tab="Ingresos">
|
||||
<x-slot:left>
|
||||
<x-icon name="plus" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.ingresos-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Egresos">
|
||||
<x-slot:left>
|
||||
<x-icon name="minus" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.egresos-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Arqueo">
|
||||
<x-slot:left>
|
||||
<x-icon name="plus-minus" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
Arqueo
|
||||
</x-tab.items>
|
||||
</x-tab>
|
||||
<div class="grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)] gap-4 items-start">
|
||||
<x-tab wire:model="tab">
|
||||
<x-tab.items tab="Ingresos">
|
||||
<x-slot:left>
|
||||
<x-icon name="plus" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.ingresos-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Egresos">
|
||||
<x-slot:left>
|
||||
<x-icon name="minus" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.egresos-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Documentos">
|
||||
<x-slot:left>
|
||||
<x-icon name="receipt" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.documentos-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Arqueo">
|
||||
<x-slot:left>
|
||||
<x-icon name="plus-minus" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
Arqueo
|
||||
</x-tab.items>
|
||||
</x-tab>
|
||||
|
||||
<x-card class="space-y-4">
|
||||
<x-input label="Total Efectivo" value="{{Number::currency($this->totalEfectivo)}}" readonly/>
|
||||
<x-input label="Total Egresos" value="{{Number::currency($this->totalEgresos)}}" readonly/>
|
||||
<x-input label="Total Documento" value="{{Number::currency($this->totalDocumentos)}}" readonly/>
|
||||
<hr class="border-b-1 my-4"/>
|
||||
<x-input label="Rendido" value="{{Number::currency($this->rendido)}}" readonly/>
|
||||
<x-input label="Debe Rendir" value="{{Number::currency($this->debeRendir)}}" readonly/>
|
||||
<x-input label="Diferencia" class="{{$this->diferencia < 0 ? 'text-red-500' : 'text-green-500'}}"
|
||||
value="{{Number::currency($this->diferencia)}}" readonly/>
|
||||
</x-card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user