Nueva estructura

This commit is contained in:
Juan Pablo Vial
2025-01-16 19:36:28 -03:00
parent 7578775fed
commit 5f31bff6e5
2 changed files with 172 additions and 111 deletions

View File

@ -8,30 +8,16 @@ use Incoviba\Model;
class Factura extends Ideal\Model
{
public Model\Venta $venta;
public int $index;
public float $proporcion;
public string $emisorRut;
public string $emisorNombre;
public string $emisorDireccion;
public string $receptorRut;
public string $receptorNombre;
public string $receptorDireccion;
public string $receptorComuna;
public Model\Persona $cliente;
public DateTimeInterface $fecha;
public array $unidades;
public int $detalleBase;
public int $detalleTerreno;
public int $detalleNeto;
public int $detalleIva;
public int $detalleBruto;
public float $detalleDescuento;
public int $detalleTotal;
public int $totalNeto;
public int $totalExento;
public int $totalIva;
public int $totalTotal;
public DateTimeInterface $fechaUF;
public float $valorUF;
public array $unidades; // [[unidad, descripcion, precio, prorrateo]]
public int $terreno;
public object $uf; // [fecha, valor]
public object $ipc; // [fecha, valor]
protected array $estados;
public function estados(): array
@ -42,6 +28,52 @@ class Factura extends Ideal\Model
return $this->estados ?? [];
}
public function total(): int
{
return round($this->venta->valor * $this->uf->valor * $this->proporcion);
}
public function bruto(): int
{
return round($this->total() - $this->terreno * $this->proporcion);
}
public function iva(): int
{
return round($this->bruto() / 1.19 * .19);
}
public function neto(): int
{
return round($this->bruto() / 1.19);
}
public function base(): int
{
return $this->neto() + $this->terreno * $this->proporcion;
}
public function detalle(): array
{
return [
'base' => $this->base(),
'terreno' => $this->terreno * $this->proporcion,
'neto' => $this->neto(),
'iva' => $this->iva(),
'bruto' => $this->bruto(),
'total' => $this->total(),
'descuento' => array_reduce($this->unidades, function($sum, $unidad) {
return $sum + $unidad->prorrateo * $this->proporcion;
})
];
}
public function totales(): array
{
return [
'neto' => array_reduce($this->unidades, function($sum, $unidad) {
return $sum + $unidad->precio * $this->proporcion;
}),
'exento' => $this->terreno * $this->proporcion,
'iva' => $this->iva(),
'total' => $this->total()
];
}
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
@ -49,37 +81,23 @@ class Factura extends Ideal\Model
'index' => $this->index,
'proporcion' => $this->proporcion,
'emisor' => [
'rut' => $this->emisorRut,
'nombre' => $this->emisorNombre,
'direccion' => $this->emisorDireccion
'rut' => $this->venta->proyecto()->inmobiliaria()->rut(),
'nombre' => $this->venta->proyecto()->inmobiliaria()->nombreCompleto(),
'direccion' => $this->venta->proyecto()->direccion(),
'comuna' => $this->venta->proyecto()->direccion()->comuna->descripcion
],
'receptor' => [
'rut' => $this->receptorRut,
'nombre' => $this->receptorNombre,
'direccion' => $this->receptorDireccion,
'comuna' => $this->receptorComuna
'rut' => $this->cliente->rutCompleto(),
'nombre' => $this->cliente->nombreCompleto(),
'direccion' => $this->cliente->datos()->direccion->simple(),
'comuna' => $this->cliente->datos()->direccion->comuna->descripcion
],
'fecha' => $this->fecha->format('Y-m-d'),
'unidades' => $this->unidades,
'detalle' => [
'base' => $this->detalleBase,
'terreno' => $this->detalleTerreno,
'neto' => $this->detalleNeto,
'iva' => $this->detalleIva,
'bruto' => $this->detalleBruto,
'descuento' => $this->detalleDescuento,
'total' => $this->detalleTotal
],
'total' => [
'neto' => $this->totalNeto,
'exento' => $this->totalExento,
'iva' => $this->totalIva,
'total' => $this->totalTotal
],
'uf' => [
'fecha' => $this->fechaUF->format('Y-m-d'),
'valor' => $this->valorUF
],
'detalle' => $this->detalle(),
'total' => $this->totales(),
'uf' => $this->uf,
'ipc' => $this->ipc,
'estados' => $this->estados()
]);
}