Implemented repository mapper, and venta show

This commit is contained in:
Juan Pablo Vial
2023-08-08 23:53:49 -04:00
parent ef30ae67d2
commit 59825259b6
111 changed files with 2766 additions and 612 deletions

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class BonoPie extends Ideal\Repository
@ -15,13 +16,11 @@ class BonoPie extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'pago' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser())
->register('pago', (new Implement\Repository\Mapper())
->setFunction(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

View File

@ -1,13 +1,14 @@
<?php
namespace Incoviba\Repository\Venta;
use PDO;
use DateTimeImmutable;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
use PDO;
class Cierre extends Ideal\Repository
{
@ -21,30 +22,17 @@ class Cierre extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'proyecto' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['precio']))
->register('proyecto', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->proyectoRepository->fetchById($data['proyecto']);
}
],
'precio' => [],
'fecha' => [
'property' => 'dateTime',
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
],
'relacionado' => [
'function' => function($data) {
return $data['relacionado'] !== 0;
}
],
'propietario' => [
'function' => function($data) {
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha', 'dateTime'))
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'))
->register('propietario', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->propietarioRepository->fetchById($data['propietario']);
}
]
];
}));
return $this->parseData(new Model\Venta\Cierre(), $data, $map);
}

View File

@ -0,0 +1,43 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Comentario extends Ideal\Repository
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('comentario');
}
public function create(?array $data = null): Define\Model
{
$map = (new Implement\Repository\MapperParser(['texto']))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
->register('estado', new Implement\Repository\Mapper\Boolean('estado', 'activo'));
return $this->parseData(new Model\Venta\Comentario(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['fecha', 'texto', 'estado'],
[$model->fecha->format('Y-m-d'), $model->texto, $model->activo ? 1 : 0]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['fecha', 'texto', 'estado'], $new_data);
}
public function fetchByVenta(int $venta_id): array
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ? AND `estado` = 1 ORDER BY `fecha` DESC";
return $this->fetchMany($query, [$venta_id]);
}
}

View File

@ -3,11 +3,13 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Service;
class Credito extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
public function __construct(Define\Connection $connection, protected Service\Venta\Pago $pagoService)
{
parent::__construct($connection);
$this->setTable('credito');
@ -15,13 +17,11 @@ class Credito extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'pago' => [
'function' => function($data) {
return $this->pagoRepository->fetchById($data['pago']);
}
]
];
$map = (new Implement\Repository\MapperParser())
->register('pago', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->pagoService->getById($data['pago']);
}));
return $this->parseData(new Model\Venta\Credito(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -1,17 +1,23 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use PDO;
use DateTimeImmutable;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class Cuota extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pie $pieRepository, protected Repository\Banco $bancoRepository, protected Pago $pagoRepository)
public function __construct(
Define\Connection $connection,
protected Pie $pieRepository,
protected Repository\Banco $bancoRepository,
protected Service\Venta\Pago $pagoService
)
{
parent::__construct($connection);
$this->setTable('cuota');
@ -19,68 +25,33 @@ class Cuota extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'pie' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'numero']))
->register('pie', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->pieRepository->fetchById($data['pie']);
}
],
'fecha' => [
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
],
'valor' => [],
'estado' => [
'function' => function($data) {
return $data['estado'] !== 0;
}
],
'banco' => [
'function' => function($data) {
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
->register('estado', new Implement\Repository\Mapper\Boolean('estado'))
->register('banco', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['banco'] === null or $data['banco'] === '') {
return null;
}
return $this->bancoRepository->fetchById($data['banco']);
}
],
'fecha_pago' => [
'property' => 'fechaPago',
'function' => function($data) {
if ($data['fecha_pago'] === null) {
return null;
}
return new DateTimeImmutable($data['fecha_pago']);
}
],
'abonado' => [
'function' => function($data) {
if ($data['abonado'] === null) {
return null;
}
return $data['abonado'] !== 0;
}
],
'fecha_abonado' => [
'property' => 'fechaAbonado',
'function' => function($data) {
if ($data['fecha_abonado'] === null) {
return null;
}
return new DateTimeImmutable($data['fecha_abonado']);
}
],
'uf' => [],
'pago' => [
'function' => function($data) {
}))
->register('fecha_pago', (new Implement\Repository\Mapper\DateTime('fecha_pago', 'fechaPago'))
->setDefault(null))
->register('abonado', (new Implement\Repository\Mapper\Boolean('abonado'))
->setDefault(null))
->register('fecha_abonado', (new Implement\Repository\Mapper\DateTime('fecha_abonado', 'fechaAbonado'))
->setDefault(null))
->register('pago', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['pago'] === null) {
return null;
}
return $this->pagoRepository->fetchById($data['pago']);
}
],
'numero' => []
];
return $this->pagoService->getById($data['pago']);
}));
return $this->parseData(new Model\Venta\Cuota(), $data, $map);
}
@ -158,4 +129,14 @@ GROUP BY `pago`.`fecha`, `proyecto`.`descripcion`
ORDER BY `pago`.`fecha`, `proyecto`.`descripcion`";
return $this->fetchAsArray($query);
}
public function fetchVigenteByPie(int $pie_id): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `pago` ON `pago`.`id` = a.`pago`
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
WHERE a.`pie` = ? AND tep.`active` = 1";
return $this->fetchMany($query, [$pie_id]);
}
}

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Entrega extends Ideal\Repository
@ -15,8 +16,8 @@ class Entrega extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
'pago_operacion', 'pago_reserva'];
$map = new Implement\Repository\MapperParser(['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

View File

@ -1,13 +1,16 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Service;
class Escritura extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
public function __construct(Define\Connection $connection, protected Service\Venta\Pago $pagoService)
{
parent::__construct($connection);
$this->setTable('escritura');
@ -15,20 +18,19 @@ class Escritura extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'pago' => [
'function' => function($data) {
return $this->pagoRepository->fetchById($data['pago']);
}
]
];
$map = (new Implement\Repository\MapperParser())
->register('pago', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->pagoService->getById($data['pago']);
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
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]
[$model->pago->valor, $model->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
);
return $model;
}

View File

@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -17,24 +18,17 @@ class EstadoCierre extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'cierre' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser())
->register('cierre', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->cierreRepository->fetchById($data['cierre']);
}
],
'tipo' => [
'property' => 'tipoEstadoCierre',
'function' => function($data) {
}))
->register('tipo', (new Implement\Repository\Mapper())
->setProperty('tipoEstadoCierre')
->setFunction(function($data) {
return $this->tipoEstadoCierreRepository->fetchById($data['tipo']);
}
],
'fecha' => [
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
]
];
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
return $this->parseData(new Model\Venta\EstadoCierre(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -19,24 +20,17 @@ class EstadoPago extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'pago' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser())
->register('pago', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->pagoRepository->fetchById($data['pago']);
}
],
'estado' => [
'property' => 'tipoEstadoPago',
'function' => function($data) {
}))
->register('estado', (new Implement\Repository\Mapper())
->setProperty('tipoEstadoPago')
->setFunction(function($data) {
return $this->tipoEstadoPagoRepository->fetchById($data['estado']);
}
],
'fecha' => [
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
]
];
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
return $this->parseData(new Model\Venta\EstadoPago(), $data, $map);
}
@ -59,6 +53,14 @@ class EstadoPago extends Ideal\Repository
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ?";
return $this->fetchMany($query, [$pago_id]);
}
public function fetchCurrentByPago(int $pago_id): Define\Model
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `{$this->getTable()}` GROUP BY `pago`) e0 ON e0.`id` = a.`id`
WHERE a.`pago` = ?";
return $this->fetchOne($query, [$pago_id]);
}
public function fetchByPagoAndEstado(int $pago_id, int $estado_id): Define\Model
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ? AND `estado` = ?";

View File

@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -17,24 +18,17 @@ class EstadoPrecio extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'precio' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser())
->register('precio', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->precioRepository->fetchById($data['precio']);
}
],
'estado' => [
'property' => 'tipoEstadoPrecio',
'function' => function($data) {
}))
->register('estado', (new Implement\Repository\Mapper())
->setProperty('tipoEstadoPrecio')
->setFunction(function($data) {
return $this->tipoEstadoPrecioRepository->fetchById($data['estado']);
}
],
'fecha' => [
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
]
];
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
return $this->parseData(new Model\Venta\EstadoPrecio(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -18,24 +19,17 @@ class EstadoVenta extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'venta' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser())
->register('venta', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->ventaRepository->fetchById($data['venta']);
}
],
'estado' => [
'property' => 'tipoEstadoVenta',
'function' => function($data) {
}))
->register('estado', (new Implement\Repository\Mapper())
->setProperty('tipoEstadoVenta')
->setFunction(function($data) {
return $this->tipoEstadoVentaRepository->fetchById($data['estado']);
}
],
'fecha' => [
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
]
];
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
return $this->parseData(new Model\Venta\EstadoVenta(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -17,45 +18,31 @@ class Pago extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'valor' => [],
'banco' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['valor', 'identificador', 'uf', 'pagador']))
->register('banco', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['banco'] === null or $data['banco'] === 0) {
return null;
}
return $this->bancoRepository->fetchById($data['banco']);
}
],
'tipo' => [
'property' => 'tipoPago',
'function' => function($data) {
}))
->register('tipo', (new Implement\Repository\Mapper())
->setProperty('tipoPago')
->setFunction(function($data) {
if ($data['tipo'] === null) {
return null;
}
return $this->tipoPagoRepository->fetchById($data['tipo']);
}
],
'identificador' => [],
'fecha' => [
'function' => function($data) {
if ($data['fecha'] === null) {
return null;
}
return new DateTimeImmutable($data['fecha']);
}
],
'uf' => [],
'pagador' => [],
'asociado' => [
'function' => function($data) {
}))
->register('fecha', (new Implement\Repository\Mapper\DateTime('fecha'))
->setDefault(null))
->register('asociado', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['asociado'] === null) {
return null;
}
return $this->fetchById($data['asociado']);
}
]
];
}));
return $this->parseData(new Model\Venta\Pago(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -4,8 +4,8 @@ namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class Pie extends Ideal\Repository
{
@ -17,32 +17,22 @@ class Pie extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'fecha' => [
'function' => function($data) {
return new DateTimeImmutable($data['fecha']);
}
],
'valor' => [],
'uf' => [],
'cuotas' => [],
'asociado' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'cuotas']))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
->register('asociado', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['asociado'] === null or $data['asociado'] === 0) {
return null;
}
return $this->fetchById($data['asociado']);
}
],
'reajuste' => [
'function' => function($data) {
}))
->register('reajuste', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['reajuste'] === null or $data['reajuste'] === 0) {
return null;
}
return $this->pagoRepository->fetchById($data['reajuste']);
}
]
];
}));
return $this->parseData(new Model\Venta\Pie(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -1,9 +1,9 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -17,14 +17,11 @@ class Precio extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'unidad' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['valor']))
->register('unidad', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->unidadRepository->fetchById($data['unidad']);
}
],
'valor' => []
];
}));
return $this->parseData(new Model\Venta\Precio(), $data, $map);
}
public function save(Define\Model $model): Define\Model
@ -53,7 +50,16 @@ 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
public function fetchByUnidad(int $unidad_id): array
{
$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` = ?";
return $this->fetchMany($query, [$unidad_id]);
}
public function fetchVigenteByUnidad(int $unidad_id): Define\Model
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a

View File

@ -3,11 +3,13 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Service;
class Propiedad extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Unidad $unidadRepository)
public function __construct(Define\Connection $connection, protected Service\Venta\Unidad $unidadService)
{
parent::__construct($connection);
$this->setTable('propiedad');
@ -15,19 +17,13 @@ class Propiedad extends Ideal\Repository
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;
}
]
];
$map = (new Implement\Repository\MapperParser())
->register('unidad_principal', (new Implement\Repository\Mapper())
->setProperty('unidades')
->setFunction(function($data) {
return $this->unidadService->getByPropiedad($data['id']);
}))
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -21,12 +22,10 @@ class Propietario extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'dv' => [],
'nombres' => [],
'apellido_paterno' => [
'property' => 'apellidos',
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['dv', 'nombres']))
->register('apellido_paterno', (new Implement\Repository\Mapper())
->setProperty('apellidos')
->setFunction(function($data) {
$arr = [
'paterno' => $data['apellido_paterno']
];
@ -34,35 +33,25 @@ class Propietario extends Ideal\Repository
$arr['materno'] = $data['apellido_materno'];
}
return $arr;
}
],
'direccion' => [
'property' => 'datos',
'function' => function($data) {
}))
->register('direccion', (new Implement\Repository\Mapper())
->setProperty('datos')
->setFunction(function($data) {
$datos = new Model\Venta\Datos();
if ($data['direccion'] !== null and $data['direccion'] !== 0) {
$datos->direccion = $this->direccionRepository->fetchById($data['direccion']);
}
return $datos;
}
],
'representante' => [
'function' => function($data) {
}))
->register('representante', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['representante'] === null or $data['representante'] === 0) {
return null;
}
return $this->fetchById($data['representante']);
}
],
'otro' => [
'function' => function($data) {
if ($data['otro'] === null) {
return null;
}
return $data['otro'] !== 0;
}
]
];
}))
->register('otro', (new Implement\Repository\Mapper\Boolean('otro'))
->setDefault(null));
return $this->parseData(new Model\Venta\Propietario(), $data, $map);
}

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Subsidio extends Ideal\Repository
@ -15,7 +16,7 @@ class Subsidio extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = ['pago', 'subsidio'];
$map = new Implement\Repository\MapperParser(['pago', 'subsidio']);
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class TipoEstadoCierre extends Ideal\Repository
@ -15,14 +16,8 @@ class TipoEstadoCierre extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => [],
'vigente' => [
'function' => function($data) {
return $data['vigente'] != 0;
}
]
];
$map = (new Implement\Repository\MapperParser(['descripcion']))
->register('vigente', new Implement\Repository\Mapper\Boolean('vigente'));
return $this->parseData(new Model\Venta\TipoEstadoCierre(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,7 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Repository;
use Incoviba\Common\Implement;
use Incoviba\Model;
class TipoEstadoPago extends Ideal\Repository
@ -16,7 +16,7 @@ class TipoEstadoPago extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = ['descripcion' => []];
$map = new Implement\Repository\MapperParser(['descripcion']);
return $this->parseData(new Model\Venta\TipoEstadoPago(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class TipoEstadoPrecio extends Ideal\Repository
@ -15,9 +16,7 @@ class TipoEstadoPrecio extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => []
];
$map = new Implement\Repository\MapperParser(['descripcion']);
return $this->parseData(new Model\Venta\TipoEstadoPrecio(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class TipoEstadoVenta extends Ideal\Repository
@ -15,14 +16,8 @@ class TipoEstadoVenta extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => [],
'activa' => [
'function' => function($data) {
return $data['activa'] !== 0;
}
]
];
$map = (new Implement\Repository\MapperParser(['descripcion']))
->register('activa', new Implement\Repository\Mapper\Boolean('activa'));
return $this->parseData(new Model\Venta\TipoEstadoVenta(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class TipoPago extends Ideal\Repository
@ -15,9 +16,7 @@ class TipoPago extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => []
];
$map = new Implement\Repository\MapperParser(['descripcion']);
return $this->parseData(new Model\Venta\TipoPago(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,8 +3,8 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class TipoUnidad extends Ideal\Repository
{
@ -16,10 +16,7 @@ class TipoUnidad extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => [],
'orden' => []
];
$map = new Implement\Repository\MapperParser(['descripcion', 'orden']);
return $this->parseData(new Model\Venta\TipoUnidad(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
class TipoValorCierre extends Ideal\Repository
@ -15,9 +16,7 @@ class TipoValorCierre extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'descripcion' => []
];
$map = new Implement\Repository\MapperParser(['descripcion']);
return $this->parseData(new Model\Venta\TipoValorCierre(), $data, $map);
}
public function save(Define\Model $model): Define\Model

View File

@ -3,12 +3,13 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class Unidad extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadRepository)
public function __construct(Define\Connection $connection, protected Service\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadService)
{
parent::__construct($connection);
$this->setTable('unidad');
@ -16,18 +17,12 @@ class Unidad extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'subtipo' => [],
'piso' => [],
'descripcion' => [],
'orientacion' => [],
'pt' => [
'property' => 'proyectoTipoUnidad',
'function' => function($data) {
return $this->proyectoTipoUnidadRepository->fetchById($data['pt']);
}
]
];
$map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion']))
->register('pt', (new Implement\Repository\Mapper())
->setProperty('proyectoTipoUnidad')
->setFunction(function($data) {
return $this->proyectoTipoUnidadService->getById($data['pt']);
}));
return $this->parseData(new Model\Venta\Unidad(), $data, $map);
}
public function save(Define\Model $model): Define\Model
@ -64,4 +59,28 @@ GROUP BY a.`id`
ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')";
return $this->fetchMany($query, [$cierre_id]);
}
public function fetchByProyecto(int $proyecto_id): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
WHERE ptu.`proyecto` = ?
ORDER BY tu.`orden`";
return $this->fetchMany($query, [$proyecto_id]);
}
public function fetchDisponiblesByProyecto(int $proyecto_id): array
{
$query = "SELECT DISTINCT a.*
FROM `{$this->getTable()}` a
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
LEFT OUTER JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`
LEFT OUTER JOIN `venta` ON `venta`.`propiedad` = `pu`.`propiedad`
LEFT OUTER JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) as 'id', `venta` FROM `estado_venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
WHERE ptu.`proyecto` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)
ORDER BY tu.`orden`";
return $this->fetchMany($query, [$proyecto_id]);
}
}

View File

@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -18,20 +19,16 @@ class ValorCierre extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'cierre' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['valor']))
->register('cierre', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->cierreRepository->fetchById($data['cierre']);
}
],
'tipo' => [
'property' => 'tipoValorCierre',
'function' => function($data) {
}))
->register('tipo', (new Implement\Repository\Mapper())
->setProperty('tipoValorCierre')
->setFunction(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