Auth, Login, Home, Venta->Listados->Precios
This commit is contained in:
82
app/src/Repository/Venta/Cierre.php
Normal file
82
app/src/Repository/Venta/Cierre.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use PDO;
|
||||
|
||||
class Cierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection,
|
||||
protected Repository\Proyecto $proyectoRepository,
|
||||
protected Repository\Venta\Propietario $propietarioRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'proyecto' => [
|
||||
'function' => 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) {
|
||||
return $this->propietarioRepository->fetchById($data['propietario']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Cierre(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['proyecto', 'precio', 'fecha', 'relacionado', 'propietario'],
|
||||
[$model->proyecto->id, $model->precio, $model->fecha->format('Y-m-d H:i:s'), $model->relacionado ? 1 : 0, $model->propietario->rut]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['proyecto', 'precio', 'fecha', 'relacionado', 'propietario'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchDatosVigentes(): array
|
||||
{
|
||||
$query = "
|
||||
SELECT `proyecto`.`descripcion` AS 'Proyecto', tec.`descripcion` AS 'Estado', COUNT(a.`id`) AS 'Cantidad'
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.*
|
||||
FROM `estado_cierre` e1
|
||||
JOIN (SELECT MAX(`id`) AS id, `cierre` FROM `estado_cierre` GROUP BY `cierre`) e0 ON e0.`id` = e1.`id`) ec ON ec.`cierre` = a.`id`
|
||||
JOIN `tipo_estado_cierre` tec ON tec.`id` = ec.`tipo`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = a.`proyecto`
|
||||
GROUP BY `proyecto`.`descripcion`, tec.`descripcion`";
|
||||
$results = $this->connection->execute($query)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new EmptyResult($query);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
161
app/src/Repository/Venta/Cuota.php
Normal file
161
app/src/Repository/Venta/Cuota.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cuota extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pie $pieRepository, protected Repository\Banco $bancoRepository, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('cuota');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pie' => [
|
||||
'function' => 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) {
|
||||
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) {
|
||||
if ($data['pago'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'numero' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Cuota(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pie', 'fecha', 'valor', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abonado', 'uf', 'pago', 'numero'],
|
||||
[$model->pie->id, $model->fecha->format('Y-m-d H:i:s'), $model->valor, $model->estado ? 1 : 0, $model?->banco->id,
|
||||
$model?->fechaPago->format('Y-m-d H:i:s'), $model?->abonado ? 1 : 0, $model?->fechaAbonado->format('Y-m-d H:i:s'),
|
||||
$model?->uf, $model?->pago->id, $model?->numero]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['pie', 'fecha', 'valor', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abonado', 'uf', 'pago', 'numero'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchHoy(): 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`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` = CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchPendientes(): array
|
||||
{
|
||||
$query = "SELECT a.`id` AS 'cuota_id', `venta`.`id` AS 'venta_id', `proyecto`.`descripcion` AS 'Proyecto', `unidad`.`descripcion` AS 'Departamento',
|
||||
`pago`.`valor` AS 'Valor', `pago`.`fecha`, CONCAT_WS(' - ', a.`numero`, `pie`.`cuotas`) AS 'Numero', `banco`.`nombre` AS 'Banco',
|
||||
CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) AS 'Propietario'
|
||||
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`
|
||||
JOIN `pie` ON `pie`.`id` = a.`pie`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
JOIN `propietario` ON `propietario`.`rut` = `venta`.`propietario`
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = `venta`.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
JOIN `banco` ON `banco`.`id` = `pago`.`banco`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` < CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
ORDER BY `pago`.`fecha` DESC";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
public function fetchDatosPorVencer(): array
|
||||
{
|
||||
$query = "SELECT `pago`.`fecha` AS 'Fecha', `proyecto`.`descripcion` AS 'Proyecto', COUNT(a.`id`) AS 'Cantidad'
|
||||
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`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = `venta`.`propiedad` AND pu.`principal` = 1
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` BETWEEN DATE_ADD(CURDATE(), INTERVAL 1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 1 MONTH)
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
GROUP BY `pago`.`fecha`, `proyecto`.`descripcion`
|
||||
ORDER BY `pago`.`fecha`, `proyecto`.`descripcion`";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
}
|
67
app/src/Repository/Venta/EstadoPago.php
Normal file
67
app/src/Repository/Venta/EstadoPago.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoPago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(protected Define\Connection $connection,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoPago',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoPagoRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoPago(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pago', 'estado', 'fecha'],
|
||||
[$model->pago->id, $model->tipoEstadoPago->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['pago', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPago(int $pago_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ?";
|
||||
return $this->fetchMany($query, [$pago_id]);
|
||||
}
|
||||
public function fetchByPagoAndEstado(int $pago_id, int $estado_id): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ? AND `estado` = ?";
|
||||
return $this->fetchOne($query, [$pago_id, $estado_id]);
|
||||
}
|
||||
}
|
65
app/src/Repository/Venta/EstadoPrecio.php
Normal file
65
app/src/Repository/Venta/EstadoPrecio.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoPrecio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\TipoEstadoPrecio $tipoEstadoPrecioRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_precio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'precio' => [
|
||||
'function' => function($data) {
|
||||
return $this->precioRepository->fetchById($data['precio']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoPrecio',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoPrecioRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoPrecio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['precio', 'estado', 'fecha'],
|
||||
[$model->precio->id, $model->tipoEstadoPrecio->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['precio', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPrecio(int $precio_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `precio` = ?";
|
||||
return $this->fetchMany($query, [$precio_id]);
|
||||
}
|
||||
public function fetchCurrentByPrecio(int $precio_id): Define\Model
|
||||
{
|
||||
$query = "SELECT e1.*
|
||||
FROM `{$this->getTable()}` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `{$this->getTable()}` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`
|
||||
WHERE e1.`precio` = ?";
|
||||
return $this->fetchOne($query, [$precio_id]);
|
||||
}
|
||||
}
|
73
app/src/Repository/Venta/Pago.php
Normal file
73
app/src/Repository/Venta/Pago.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Pago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Banco $bancoRepository, protected TipoPago $tipoPagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'valor' => [],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
if ($data['banco'] === null or $data['banco'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoPago',
|
||||
'function' => 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) {
|
||||
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
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'],
|
||||
[$model->valor, $model?->banco->id, $model?->tipoPago->id, $model?->identificador, $model?->fecha->format('Y-m-d H:i:s'), $model?->uf, $model?->pagador, $model?->asociado->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data);
|
||||
}
|
||||
}
|
60
app/src/Repository/Venta/Pie.php
Normal file
60
app/src/Repository/Venta/Pie.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Pie extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('pie');
|
||||
}
|
||||
|
||||
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) {
|
||||
if ($data['asociado'] === null or $data['asociado'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['asociado']);
|
||||
}
|
||||
],
|
||||
'reajuste' => [
|
||||
'function' => 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
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'],
|
||||
[$model->fecha->format('Y-m-d H:i:s'), $model->valor, $model?->uf, $model->cuotas, $model?->asociado->id, $model?->reajuste->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], $new_data);
|
||||
}
|
||||
}
|
55
app/src/Repository/Venta/Precio.php
Normal file
55
app/src/Repository/Venta/Precio.php
Normal 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 Precio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Unidad $unidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('precio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'unidad' => [
|
||||
'function' => 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
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad', 'valor'],
|
||||
[$model->unidad->id, $model->valor]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['unidad', 'valor'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyecto(int $proyecto_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`
|
||||
JOIN `unidad` ON `unidad`.`id` = a.`unidad`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
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]);
|
||||
}
|
||||
}
|
82
app/src/Repository/Venta/Propietario.php
Normal file
82
app/src/Repository/Venta/Propietario.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Propietario extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Direccion $direccionRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propietario');
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'rut';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'dv' => [],
|
||||
'nombres' => [],
|
||||
'apellido_paterno' => [
|
||||
'property' => 'apellidos',
|
||||
'function' => function($data) {
|
||||
$arr = [
|
||||
'paterno' => $data['apellido_paterno']
|
||||
];
|
||||
if ($data['apellido_materno'] !== '') {
|
||||
$arr['materno'] = $data['apellido_materno'];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
],
|
||||
'direccion' => [
|
||||
'property' => 'datos',
|
||||
'function' => 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) {
|
||||
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;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Propietario(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->rut = $this->saveNew(
|
||||
['dv', 'nombres', 'apellido_paterno', 'apellido_materno'],
|
||||
[$model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno']]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['dv', 'nombres', 'apellido_paterno', 'apellido_materno'], $new_data);
|
||||
}
|
||||
}
|
40
app/src/Repository/Venta/TipoEstadoPago.php
Normal file
40
app/src/Repository/Venta/TipoEstadoPago.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['descripcion' => []];
|
||||
return $this->parseData(new Model\Venta\TipoEstadoPago(), $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);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
}
|
35
app/src/Repository/Venta/TipoEstadoPrecio.php
Normal file
35
app/src/Repository/Venta/TipoEstadoPrecio.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPrecio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_precio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoEstadoPrecio(), $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);
|
||||
}
|
||||
}
|
35
app/src/Repository/Venta/TipoPago.php
Normal file
35
app/src/Repository/Venta/TipoPago.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoPago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoPago(), $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);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/TipoUnidad.php
Normal file
39
app/src/Repository/Venta/TipoUnidad.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class TipoUnidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_unidad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'orden' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'orden'],
|
||||
[$model->descripcion, $model->orden]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'orden'], $new_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
47
app/src/Repository/Venta/Unidad.php
Normal file
47
app/src/Repository/Venta/Unidad.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Unidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('unidad');
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Unidad(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'],
|
||||
[$model->subtipo, $model->piso, $model->descripcion, $model->orientacion, $model->proyectoTipoUnidad->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user