Agregando calculo de efectivo
This commit is contained in:
@@ -31,7 +31,7 @@ COPY supervisord.conf /etc/supervisord.conf
|
||||
COPY entrypoint.sh /etc/entrypoint.sh
|
||||
COPY ./ ./
|
||||
|
||||
RUN chown -R www-data:www-data /var/www/html \
|
||||
RUN chown -R www-data:www-data /var/www \
|
||||
&& composer dump-autoload \
|
||||
&& npm install \
|
||||
&& npm run build \
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,17 +12,30 @@ class Efectivo extends Model
|
||||
|
||||
protected $table = 'efectivos';
|
||||
|
||||
public function getTotal(): Attribute {
|
||||
protected $fillable = [
|
||||
'veinte_mil',
|
||||
'diez_mil',
|
||||
'cinco_mil',
|
||||
'dos_mil',
|
||||
'mil',
|
||||
'quinientos',
|
||||
'cien',
|
||||
'cincuenta',
|
||||
'diez',
|
||||
];
|
||||
|
||||
public function total(): 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;
|
||||
return $this->veinte_mil
|
||||
+ $this->diez_mil
|
||||
+ $this->cinco_mil
|
||||
+ $this->dos_mil
|
||||
+ $this->mil
|
||||
+ $this->quinientos
|
||||
+ $this->cien
|
||||
+ $this->cincuenta
|
||||
+ $this->diez;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@@ -19,24 +20,46 @@ class Turno extends Model
|
||||
'fecha' => 'date',
|
||||
];
|
||||
|
||||
public function ingresos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Ingreso::class, 'turno_id');
|
||||
}
|
||||
public function egresos(): HasMany
|
||||
{
|
||||
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');
|
||||
}
|
||||
public function calculosFondo(): HasMany
|
||||
{
|
||||
return $this->hasMany(CalculoFondo::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function rendido(): Attribute
|
||||
{
|
||||
return Attribute::get(function () {
|
||||
$documentos = $this->documentos()->sum('valor');
|
||||
$egresos = $this->egresos()->sum('valor');
|
||||
$efectivo = $this->efectivo()->first()?->total ?? 0;
|
||||
|
||||
return $documentos + $efectivo + $egresos;
|
||||
});
|
||||
}
|
||||
|
||||
public function documentos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Documento::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function egresos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Egreso::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function efectivo(): HasOne
|
||||
{
|
||||
return $this->hasOne(Efectivo::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function arqueo(): Attribute
|
||||
{
|
||||
return Attribute::get(function () {
|
||||
return $this->rendido - $this->ingresos()->sum('total');
|
||||
});
|
||||
}
|
||||
|
||||
public function ingresos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Ingreso::class, 'turno_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
@use(Illuminate\Support\Number)
|
||||
|
||||
<div>
|
||||
<div class="grid grid-cols-[auto,minmax(0,1fr)] gap-4 items-baseline">
|
||||
<x-label>$20.000</x-label>
|
||||
<x-input type="number" wire:model.blur="veinte_mil"/>
|
||||
<x-label>$10.000</x-label>
|
||||
<x-input type="number" wire:model.blur="diez_mil"/>
|
||||
<x-label>$5.000</x-label>
|
||||
<x-input type="number" wire:model.blur="cinco_mil"/>
|
||||
<x-label>$2.000</x-label>
|
||||
<x-input type="number" wire:model.blur="dos_mil"/>
|
||||
<x-label>$1.000</x-label>
|
||||
<x-input type="number" wire:model.blur="mil"/>
|
||||
<x-label>$500</x-label>
|
||||
<x-input type="number" wire:model.blur="quinientos"/>
|
||||
<x-label>$100</x-label>
|
||||
<x-input type="number" wire:model.blur="cien"/>
|
||||
<x-label>$50</x-label>
|
||||
<x-input type="number" wire:model.blur="cincuenta"/>
|
||||
<x-label>$10</x-label>
|
||||
<x-input type="number" wire:model.blur="diez"/>
|
||||
<hr class="border-b my-4 col-span-full"/>
|
||||
<x-label>Total</x-label>
|
||||
<x-input value="{{Number::currency($this->totalEfectivo)}}" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,7 +41,7 @@
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Documentos">
|
||||
<x-slot:left>
|
||||
<x-icon name="receipt" class="w-4 h-4"/>
|
||||
<x-icon name="credit-card" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.documentos-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
@@ -51,6 +51,12 @@
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.calculo-fondo-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
<x-tab.items tab="Efectivo">
|
||||
<x-slot:left>
|
||||
<x-icon name="currency-dollar" class="w-4 h-4"/>
|
||||
</x-slot:left>
|
||||
<livewire:cajas.components.efectivo-component :turno="$turno"/>
|
||||
</x-tab.items>
|
||||
</x-tab>
|
||||
|
||||
<x-card class="space-y-4">
|
||||
@@ -60,7 +66,7 @@
|
||||
<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'}}"
|
||||
<x-input label="Diferencia" class="font-bold {{$this->diferencia < 0 ? 'text-red-500' : 'text-green-500'}}"
|
||||
value="{{Number::currency($this->diferencia)}}" readonly/>
|
||||
</x-card>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user