Ventas->Listado->Ventas

This commit is contained in:
Juan Pablo Vial
2023-07-28 16:22:20 -04:00
parent 38383f5295
commit ef30ae67d2
52 changed files with 1496 additions and 17 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class BonoPie extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
{
parent::__construct($connection);
$this->setTable('bono_pie');
}
public function create(?array $data = null): Define\Model
{
$map = [
'pago' => [
'function' => function($data) {
return $this->pagoRepository->fetchById($data['pago']);
}
]
];
return $this->parseData(new Model\Venta\BonoPie(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['valor', 'pago'],
[$model->pago->valor, $model->pago->id]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['valor', 'pago'], $new_data);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class Credito extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
{
parent::__construct($connection);
$this->setTable('credito');
}
public function create(?array $data = null): Define\Model
{
$map = [
'pago' => [
'function' => function($data) {
return $this->pagoRepository->fetchById($data['pago']);
}
]
];
return $this->parseData(new Model\Venta\Credito(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'],
[$model->pago->banco->id, $model->pago->valor, $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class Entrega extends Ideal\Repository
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('entrega');
}
public function create(?array $data = null): Define\Model
{
$map = ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
'pago_operacion', 'pago_reserva'];
return $this->parseData(new Model\Venta\Entrega(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
'pago_operacion', 'pago_reserva'],
[$model->fecha->format('Y-m-d'), $model->operacion->valor, $model->reserva->valor,
$model->operacion->fecha('Y-m-d'), $model->reserva->fecha('Y-m-d'), $model->operacion->id,
$model->reserva->id]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion',
'fecha_fondo_reserva', 'pago_operacion', 'pago_reserva'], $new_data);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class Escritura extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
{
parent::__construct($connection);
$this->setTable('escritura');
}
public function create(?array $data = null): Define\Model
{
$map = [
'pago' => [
'function' => function($data) {
return $this->pagoRepository->fetchById($data['pago']);
}
]
];
return $this->parseData(new Model\Venta\Escritura(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'],
[$model->pago->valor, $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
use Incoviba\Repository;
class EstadoVenta extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Venta $ventaRepository,
protected TipoEstadoVenta $tipoEstadoVentaRepository)
{
parent::__construct($connection);
$this->setTable('estado_venta');
}
public function create(?array $data = null): Define\Model
{
$map = [
'venta' => [
'function' => function($data) {
return $this->ventaRepository->fetchById($data['venta']);
}
],
'estado' => [
'property' => 'tipoEstadoVenta',
'function' => function($data) {
return $this->tipoEstadoVentaRepository->fetchById($data['estado']);
}
],
'fecha' => [
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
]
];
return $this->parseData(new Model\Venta\EstadoVenta(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['venta', 'estado', 'fecha'],
[$model->venta->id, $model->tipoEstadoVenta->id, $model->fecha->format('Y-m-d')]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['venta', 'estado', 'fecha'], $new_data);
}
public function fetchByVenta(int $venta_id): array
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ?";
return $this->fetchMany($query, [$venta_id]);
}
public function fetchCurrentByVenta(int $venta_id): Define\Model
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `{$this->getTable()}` GROUP BY `venta`) e0 ON e0.`id` = a.`id`
WHERE a.`venta` = ?";
return $this->fetchOne($query, [$venta_id]);
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
@ -52,4 +53,22 @@ WHERE ptu.`proyecto` = ? AND tep.`descripcion` = 'vigente'
ORDER BY tu.`orden`, ptu.`nombre`, `unidad`.`subtipo`, LPAD(`unidad`.`descripcion`, 4, '0')";
return $this->fetchMany($query, [$proyecto_id]);
}
public function fetchByUnidad(int $unidad_id): Define\Model
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN (SELECT e1.* FROM `estado_precio` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `estado_precio` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`) ep ON ep.`precio` = a.`id`
JOIN `tipo_estado_precio` tep ON tep.`id` = ep.`estado`
WHERE `unidad` = ? AND tep.`descripcion` = 'vigente'";
return $this->fetchOne($query, [$unidad_id]);
}
public function fetchByUnidadAndDate(int $unidad_id, string $date_time): Define\Model
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN (SELECT e1.* FROM `estado_precio` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `estado_precio` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`) ep ON ep.`precio` = a.`id`
JOIN `tipo_estado_precio` tep ON tep.`id` = ep.`estado`
WHERE `unidad` = ? AND ep.`fecha` <= ? AND tep.`descripcion` = 'vigente'";
return $this->fetchOne($query, [$unidad_id, $date_time]);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class Propiedad extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Unidad $unidadRepository)
{
parent::__construct($connection);
$this->setTable('propiedad');
}
public function create(?array $data = null): Define\Model
{
$map = [
'unidad_principal' => [
'property' => 'unidades',
'function' => function($data) {
return $this->unidadRepository->fetchByPropiedad($data['id']);
}
],
'estado' => [
'function' => function($data) {
return true;
}
]
];
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
[$model->departamentos()[0]->id, null, null, 1]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class Subsidio extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
{
parent::__construct($connection);
$this->setTable('subsidio');
}
public function create(?array $data = null): Define\Model
{
$map = ['pago', 'subsidio'];
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['pago', 'subsidio'],
[$model->ahorro->id, $model->subsidio->id]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['pago', 'subsidio'], $new_data);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class TipoEstadoVenta extends Ideal\Repository
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('tipo_estado_venta');
}
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => [],
'activa' => [
'function' => function($data) {
return $data['activa'] !== 0;
}
]
];
return $this->parseData(new Model\Venta\TipoEstadoVenta(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['descripcion', 'activa'],
[$model->descripcion, $model->activa ? 1 : 0]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['descripcion', 'activa'], $new_data);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
class TipoValorCierre extends Ideal\Repository
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('tipo_valor_cierre');
}
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => []
];
return $this->parseData(new Model\Venta\TipoValorCierre(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['descripcion'],
[$model->descripcion]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['descripcion'], $new_data);
}
}

View File

@ -43,6 +43,15 @@ class Unidad extends Ideal\Repository
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
}
public function fetchByPropiedad(int $propiedad_id): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`
WHERE pu.`propiedad` = ?
GROUP BY a.`id`";
return $this->fetchMany($query, [$propiedad_id]);
}
public function fetchByCierre(int $cierre_id): array
{
$query = "SELECT a.*
@ -51,6 +60,7 @@ FROM `{$this->getTable()}` a
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
WHERE uc.`cierre` = ?
GROUP BY a.`id`
ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')";
return $this->fetchMany($query, [$cierre_id]);
}

View File

@ -0,0 +1,55 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
use Incoviba\Repository;
class ValorCierre extends Ideal\Repository
{
public function __construct(Define\Connection $connection,
protected Repository\Venta\Cierre $cierreRepository,
protected Repository\Venta\TipoValorCierre $tipoValorCierreRepository)
{
parent::__construct($connection);
$this->setTable('valor_cierre');
}
public function create(?array $data = null): Define\Model
{
$map = [
'cierre' => [
'function' => function($data) {
return $this->cierreRepository->fetchById($data['cierre']);
}
],
'tipo' => [
'property' => 'tipoValorCierre',
'function' => function($data) {
return $this->tipoValorCierreRepository->fetchById($data['tipo']);
}
],
'valor' => []
];
return $this->parseData(new Model\Venta\ValorCierre(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['cierre', 'tipo', 'valor'],
[$model->cierre->id, $model->tipoValorCierre->id, $model->valor]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['cierre', 'tipo', 'valor'], $new_data);
}
public function fetchByCierre(int $cierre_id): array
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `cierre` = ?";
return $this->fetchMany($query, [$cierre_id]);
}
}