Agregando calculo de efectivo
This commit is contained in:
96
app/Livewire/Cajas/Components/EfectivoComponent.php
Normal file
96
app/Livewire/Cajas/Components/EfectivoComponent.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Cajas\Components;
|
||||
|
||||
use App\Enums\TipoDocumento;
|
||||
use App\Models\CalculoFondo;
|
||||
use App\Models\Documento;
|
||||
use App\Models\Turno;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Number;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Log;
|
||||
use TallStackUi\Traits\Interactions;
|
||||
|
||||
class EfectivoComponent extends Component
|
||||
{
|
||||
use Interactions;
|
||||
|
||||
public Turno $turno;
|
||||
|
||||
#[Validate('required|numeric')]
|
||||
public $veinte_mil = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $diez_mil = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $cinco_mil = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $dos_mil = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $mil = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $quinientos = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $cien = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $cincuenta = 0;
|
||||
#[Validate('required|numeric')]
|
||||
public $diez = 0;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$efectivo = $this->turno->efectivo()->first();
|
||||
$this->veinte_mil = $efectivo->veinte_mil;
|
||||
$this->diez_mil = $efectivo->diez_mil;
|
||||
$this->cinco_mil = $efectivo->cinco_mil;
|
||||
$this->dos_mil = $efectivo->dos_mil;
|
||||
$this->mil = $efectivo->mil;
|
||||
$this->quinientos = $efectivo->quinientos;
|
||||
$this->cien = $efectivo->cien;
|
||||
$this->cincuenta = $efectivo->cincuenta;
|
||||
$this->diez = $efectivo->diez;
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.cajas.components.efectivo-component');
|
||||
}
|
||||
|
||||
public function updated($attribute): void
|
||||
{
|
||||
$this->validateOnly($attribute);
|
||||
|
||||
if ($attribute === 'veinte_mil') {
|
||||
$this->turno->efectivo()->first()->update(['veinte_mil' => $this->veinte_mil]);
|
||||
} elseif ($attribute === 'diez_mil') {
|
||||
$this->turno->efectivo()->first()->update(['diez_mil' => $this->diez_mil]);
|
||||
} elseif ($attribute === 'cinco_mil') {
|
||||
$this->turno->efectivo()->first()->update(['cinco_mil' => $this->cinco_mil]);
|
||||
} elseif ($attribute === 'dos_mil') {
|
||||
$this->turno->efectivo()->first()->update(['dos_mil' => $this->dos_mil]);
|
||||
} elseif ($attribute === 'mil') {
|
||||
$this->turno->efectivo()->first()->update(['mil' => $this->mil]);
|
||||
} elseif ($attribute === 'quinientos') {
|
||||
$this->turno->efectivo()->first()->update(['quinientos' => $this->quinientos]);
|
||||
} elseif ($attribute === 'cien') {
|
||||
$this->turno->efectivo()->first()->update(['cien' => $this->cien]);
|
||||
} elseif ($attribute === 'cincuenta') {
|
||||
$this->turno->efectivo()->first()->update(['cincuenta' => $this->cincuenta]);
|
||||
} elseif ($attribute === 'diez') {
|
||||
$this->turno->efectivo()->first()->update(['diez' => $this->diez]);
|
||||
}
|
||||
|
||||
$this->dispatch('updated_totals');
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function totalEfectivo(): int
|
||||
{
|
||||
return $this->turno->efectivo()->first()->total;
|
||||
}
|
||||
}
|
||||
@@ -50,11 +50,7 @@ class Edit extends Component
|
||||
#[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;
|
||||
return $this->turno->rendido;
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
@@ -66,7 +62,7 @@ class Edit extends Component
|
||||
#[Computed]
|
||||
public function diferencia()
|
||||
{
|
||||
return $this->rendido - $this->debeRendir;
|
||||
return $this->turno->arqueo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Livewire\Cajas;
|
||||
|
||||
use App\Models\Efectivo;
|
||||
use App\Models\Turno;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
@@ -72,6 +73,18 @@ class Index extends Component
|
||||
'numero_turno' => $this->turno,
|
||||
]);
|
||||
|
||||
$turno->efectivo()->create([
|
||||
'veinte_mil' => 0,
|
||||
'diez_mil' => 0,
|
||||
'cinco_mil' => 0,
|
||||
'dos_mil' => 0,
|
||||
'mil' => 0,
|
||||
'quinientos' => 0,
|
||||
'cien' => 0,
|
||||
'cincuenta' => 0,
|
||||
'diez' => 0,
|
||||
]);
|
||||
|
||||
Session::flash('toast', ['type' => 'success', 'message' => 'Caja registrada correctamente']);
|
||||
|
||||
$this->redirectRoute('cajas.edit', $turno);
|
||||
@@ -89,7 +102,8 @@ class Index extends Component
|
||||
|
||||
public function confirmDelete($id): void
|
||||
{
|
||||
$this->dialog()->question('¿Esta seguro de eliminar este turno?', 'Se eliminara este junto a los ingresos y egresos registrados')
|
||||
$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();
|
||||
@@ -111,8 +125,7 @@ class Index extends Component
|
||||
['index' => 'numero_turno', 'label' => 'Turno'],
|
||||
['index' => 'ingresos', 'label' => 'Ingresos'],
|
||||
['index' => 'egresos', 'label' => 'Egresos'],
|
||||
['index' => 'documentos', 'label' => 'Documento'],
|
||||
['index' => 'diferencia', 'label' => 'diferencia'],
|
||||
['index' => 'arqueo', 'label' => 'Arqueo'],
|
||||
['index' => 'action', 'label' => 'Acciones'],
|
||||
];
|
||||
}
|
||||
@@ -131,14 +144,11 @@ class Index extends Component
|
||||
'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),
|
||||
'egresos' => Number::currency($turno->egresos()->sum('valor')),
|
||||
'arqueo' => Number::currency($turno->arqueo),
|
||||
];
|
||||
});
|
||||
|
||||
Log::info('', [$turnos]);
|
||||
|
||||
return $turnos;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user