Agregando calculo de fondo
This commit is contained in:
131
app/Livewire/Cajas/Components/CalculoFondoComponent.php
Normal file
131
app/Livewire/Cajas/Components/CalculoFondoComponent.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?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 CalculoFondoComponent extends Component
|
||||
{
|
||||
use Interactions;
|
||||
|
||||
public Turno $turno;
|
||||
|
||||
#[Validate('required|numeric')]
|
||||
public $fondo = null;
|
||||
|
||||
#[Validate('nullable')]
|
||||
public $descripcion = null;
|
||||
|
||||
#[Validate('required|numeric')]
|
||||
public $valor = null;
|
||||
|
||||
public $currentCalculo = null;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->fondo = $this->turno->fondo;
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.cajas.components.calculo-fondo-component');
|
||||
}
|
||||
|
||||
public function updatedFondo(): void
|
||||
{
|
||||
$this->validateOnly('fondo');
|
||||
$this->turno->update(['fondo' => $this->fondo]);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$this->validateOnly('descripcion');
|
||||
$this->validateOnly('valor');
|
||||
|
||||
if ($this->currentCalculo) {
|
||||
CalculoFondo::where('id', $this->currentCalculo)->update([
|
||||
'descripcion' => $this->descripcion,
|
||||
'valor' => $this->valor,
|
||||
]);
|
||||
} else {
|
||||
$this->turno->calculosFondo()->create([
|
||||
'descripcion' => $this->descripcion,
|
||||
'valor' => $this->valor,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->currentCalculo) {
|
||||
$this->toast()->success('Exito!', 'Registro modificado correctamente')->send();
|
||||
} else {
|
||||
$this->toast()->success('Exito!', 'Registro guardado correctamente')->send();
|
||||
}
|
||||
|
||||
$this->currentCalculo = null;
|
||||
$this->descripcion = null;
|
||||
$this->valor = null;
|
||||
|
||||
$this->dispatch('updated_totals');
|
||||
}
|
||||
|
||||
public function edit($id): void
|
||||
{
|
||||
$this->currentCalculo = $id;
|
||||
$calculo = CalculoFondo::find($id);
|
||||
|
||||
$this->descripcion = $calculo->descripcion;
|
||||
$this->valor = $calculo->valor;
|
||||
}
|
||||
|
||||
public function confirmDelete($id): void
|
||||
{
|
||||
$this->dialog()->question('¿Esta seguro de eliminar este registro?', 'No podrá recuperarlo')
|
||||
->confirm('Eliminar Registro', method: 'delete', params: $id)
|
||||
->cancel()
|
||||
->send();
|
||||
}
|
||||
|
||||
public function delete($id): void
|
||||
{
|
||||
CalculoFondo::where('id', $id)->delete();
|
||||
|
||||
$this->toast()->success('Registro eliminado correctamente')->send();
|
||||
$this->dispatch('updated_totals');
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function headers(): array
|
||||
{
|
||||
return [
|
||||
['index' => 'valor', 'label' => 'Total'],
|
||||
['index' => 'descripcion', 'label' => 'Descripción'],
|
||||
['index' => 'action', 'label' => 'Acciones'],
|
||||
];
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function rows(): Collection
|
||||
{
|
||||
return $this->turno->calculosFondo()
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function totalCalculo(): int
|
||||
{
|
||||
return $this->turno->calculosFondo()->sum('valor');
|
||||
}
|
||||
}
|
||||
@@ -28,26 +28,6 @@ class Edit extends Component
|
||||
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()
|
||||
{
|
||||
@@ -59,6 +39,7 @@ class Edit extends Component
|
||||
{
|
||||
return $this->turno->egresos()->sum('valor');
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function totalDocumentos()
|
||||
{
|
||||
@@ -77,12 +58,14 @@ class Edit extends Component
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function debeRendir() {
|
||||
public function debeRendir()
|
||||
{
|
||||
return $this->turno->ingresos()->sum('total');
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function diferencia() {
|
||||
public function diferencia()
|
||||
{
|
||||
return $this->rendido - $this->debeRendir;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,4 +10,6 @@ class CalculoFondo extends Model
|
||||
use HasUlids;
|
||||
|
||||
protected $table = 'calculo_fondos';
|
||||
|
||||
protected $fillable = ['valor', 'descripcion'];
|
||||
}
|
||||
|
||||
@@ -35,4 +35,8 @@ class Turno extends Model
|
||||
{
|
||||
return $this->hasOne(Efectivo::class, 'turno_id');
|
||||
}
|
||||
public function calculosFondo(): HasMany
|
||||
{
|
||||
return $this->hasMany(CalculoFondo::class, 'turno_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,27 +5,28 @@ namespace App\Providers;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Number;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use TallStackUi\Facades\TallStackUi;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$isProduction = app()->isProduction();
|
||||
|
||||
Model::shouldBeStrict(! $isProduction);
|
||||
|
||||
Model::shouldBeStrict(!app()->isProduction());
|
||||
Number::useLocale('es-CL');
|
||||
Number::useCurrency('CLP');
|
||||
|
||||
$this->personalize();
|
||||
}
|
||||
|
||||
public function personalize()
|
||||
{
|
||||
TallStackUi::personalize()
|
||||
->table()
|
||||
->block('table.td', 'dark:text-dark-300 whitespace-nowrap px-3 py-1 text-sm text-gray-500');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
@@ -23,7 +22,7 @@ return new class extends Migration
|
||||
Schema::create('calculo_fondos', function (Blueprint $table) {
|
||||
$table->ulid('id')->primary();
|
||||
$table->bigInteger('valor');
|
||||
$table->text('descripcion');
|
||||
$table->text('descripcion')->nullable();
|
||||
$table->foreignUlid('turno_id')->constrained('turnos')->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
@use(Illuminate\Support\Number)
|
||||
<div>
|
||||
<form wire:submit.prevent="save" class="grid lg:grid-cols-[repeat(2,minmax(0,2fr))_1fr] gap-2 mb-4 items-end">
|
||||
<x-input label="Total" wire:model="valor" invalidate/>
|
||||
<x-input label="Descripción" wire:model="descripcion" invalidate/>
|
||||
|
||||
<x-button type="submit">
|
||||
@if($this->currentCalculo)
|
||||
Guardar
|
||||
@else
|
||||
Agregar
|
||||
@endif
|
||||
</x-button>
|
||||
|
||||
<p class="text-sm font-medium text-red-500">
|
||||
@error('valor'){{$message}}@enderror
|
||||
</p>
|
||||
<p class="text-sm font-medium text-red-500">
|
||||
@error('descripcion'){{$message}}@enderror
|
||||
</p>
|
||||
|
||||
</form>
|
||||
<x-table striped :headers="$this->headers" :rows="$this->rows">
|
||||
@interact('column_valor', $row)
|
||||
{{Number::currency($row->valor)}}
|
||||
@endinteract
|
||||
@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 grid lg:grid-cols-3 gap-4">
|
||||
<x-input label="Fondo" type="number" wire:model.live.debounce="fondo"/>
|
||||
<x-input label="Suma de Dinero" value="{{Number::currency($this->totalCalculo)}}" readonly/>
|
||||
<x-input label="Deposito" value="{{Number::currency($this->totalCalculo - (is_numeric($fondo) ? $fondo : 0))}}"
|
||||
readonly/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,3 +1,4 @@
|
||||
@use(Illuminate\Support\Number)
|
||||
<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
|
||||
@@ -26,6 +27,9 @@
|
||||
|
||||
</form>
|
||||
<x-table striped :headers="$this->headers" :rows="$this->rows">
|
||||
@interact('column_valor', $row)
|
||||
{{Number::currency($row->valor)}}
|
||||
@endinteract
|
||||
@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()"/>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@use(Illuminate\Support\Number)
|
||||
<div>
|
||||
<form wire:submit.prevent="save" class="grid lg:grid-cols-[repeat(4,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
|
||||
@@ -30,6 +31,9 @@
|
||||
|
||||
</form>
|
||||
<x-table striped :headers="$this->headers" :rows="$this->rows">
|
||||
@interact('column_valor', $row)
|
||||
{{Number::currency($row->valor)}}
|
||||
@endinteract
|
||||
@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()"/>
|
||||
|
||||
@@ -45,11 +45,11 @@
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.documentos-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Arqueo">
|
||||
<x-tab.items tab="Calculo de Fondo">
|
||||
<x-slot:left>
|
||||
<x-icon name="plus-minus" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
Arqueo
|
||||
<livewire:cajas.components.calculo-fondo-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
</x-tab>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user