Initial commit: Horux Strategy Platform
- Laravel 11 backend with API REST - React 18 + TypeScript + Vite frontend - Multi-parser architecture for accounting systems (CONTPAQi, Aspel, SAP) - 27+ financial metrics calculation - PDF report generation with Browsershot - Complete documentation (10 documents) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
109
backend/app/Models/Cuenta.php
Normal file
109
backend/app/Models/Cuenta.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Cuenta extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'balanza_id',
|
||||
'codigo',
|
||||
'nombre',
|
||||
'nivel',
|
||||
'reporte_contable_id',
|
||||
'categoria_contable_id',
|
||||
'cuenta_padre_id',
|
||||
'saldo_inicial_deudor',
|
||||
'saldo_inicial_acreedor',
|
||||
'cargos',
|
||||
'abonos',
|
||||
'saldo_final_deudor',
|
||||
'saldo_final_acreedor',
|
||||
'excluida',
|
||||
'es_cuenta_padre',
|
||||
'requiere_revision',
|
||||
'nota_revision',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'saldo_inicial_deudor' => 'decimal:2',
|
||||
'saldo_inicial_acreedor' => 'decimal:2',
|
||||
'cargos' => 'decimal:2',
|
||||
'abonos' => 'decimal:2',
|
||||
'saldo_final_deudor' => 'decimal:2',
|
||||
'saldo_final_acreedor' => 'decimal:2',
|
||||
'excluida' => 'boolean',
|
||||
'es_cuenta_padre' => 'boolean',
|
||||
'requiere_revision' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function balanza(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Balanza::class);
|
||||
}
|
||||
|
||||
public function reporteContable(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ReporteContable::class);
|
||||
}
|
||||
|
||||
public function categoriaContable(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CategoriaContable::class);
|
||||
}
|
||||
|
||||
public function cuentaPadre(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Cuenta::class, 'cuenta_padre_id');
|
||||
}
|
||||
|
||||
public function cuentasHijo(): HasMany
|
||||
{
|
||||
return $this->hasMany(Cuenta::class, 'cuenta_padre_id');
|
||||
}
|
||||
|
||||
public function getSaldoInicialNetoAttribute(): float
|
||||
{
|
||||
return $this->saldo_inicial_deudor - $this->saldo_inicial_acreedor;
|
||||
}
|
||||
|
||||
public function getSaldoFinalNetoAttribute(): float
|
||||
{
|
||||
return $this->saldo_final_deudor - $this->saldo_final_acreedor;
|
||||
}
|
||||
|
||||
public function getMovimientoNetoAttribute(): float
|
||||
{
|
||||
return $this->cargos - $this->abonos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalcula el saldo considerando solo cuentas hijo activas
|
||||
*/
|
||||
public function recalcularSaldoDesdeHijos(): void
|
||||
{
|
||||
if (!$this->es_cuenta_padre) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hijosActivos = $this->cuentasHijo()->where('excluida', false)->get();
|
||||
|
||||
$this->saldo_inicial_deudor = $hijosActivos->sum('saldo_inicial_deudor');
|
||||
$this->saldo_inicial_acreedor = $hijosActivos->sum('saldo_inicial_acreedor');
|
||||
$this->cargos = $hijosActivos->sum('cargos');
|
||||
$this->abonos = $hijosActivos->sum('abonos');
|
||||
$this->saldo_final_deudor = $hijosActivos->sum('saldo_final_deudor');
|
||||
$this->saldo_final_acreedor = $hijosActivos->sum('saldo_final_acreedor');
|
||||
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user