Implemented repository mapper, and venta show
This commit is contained in:
39
app/src/Controller/Direcciones.php
Normal file
39
app/src/Controller/Direcciones.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Direcciones
|
||||
{
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Provincia $provinciaRepository, Repository\Comuna $comunaRepository, int $region_id) : ResponseInterface
|
||||
{
|
||||
$temp_provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
$comunas = [];
|
||||
foreach($temp_provincias as $provincia) {
|
||||
$temp_comunas = $comunaRepository->fetchByProvincia($provincia->id);
|
||||
$comunas = array_merge($comunas, $temp_comunas);
|
||||
}
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcoll($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$response->getBody()->write(json_encode(['comunas' => $comunas, 'total' => count($comunas)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function findComunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByDireccion($json->direccion);
|
||||
$output['comunas'] = $comunas;
|
||||
$output['total'] = count($comunas);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -14,8 +15,13 @@ class Proyectos
|
||||
}
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$response->getBody()->write(json_encode(['proyectos' => $proyectos, 'total' => count($proyectos)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use MongoDB\Driver\Server;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
@ -14,13 +17,89 @@ class Ventas
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service): ResponseInterface
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
return $view->render($response, 'ventas.show', compact('venta'));
|
||||
}
|
||||
public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface
|
||||
{
|
||||
$proyecto_nombre = urldecode($proyecto_nombre);
|
||||
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
||||
return $view->render($response, 'ventas.show', compact('venta'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$ventas = $service->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['ventas' => $ventas, 'total' => count($ventas)]));
|
||||
$output = [
|
||||
'proyecto' => [
|
||||
'id' => $proyecto_id
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $service->fetchByProyecto($proyecto_id);
|
||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
||||
$output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
|
||||
$output['total'] = count($ventas);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$response->getBody()->write(json_encode(compact('venta')));
|
||||
} catch (EmptyResult $exception) {
|
||||
$response->getBody()->write(json_encode(['error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]]));
|
||||
}
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
return $view->render($response, 'ventas.edit', compact('venta'));
|
||||
}
|
||||
public function propietario(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, Repository\Region $regionRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$propietario = $venta->propietario();
|
||||
$regiones = $regionRepository->fetchAll();
|
||||
usort($regiones, function(Model\Region $a, Model\Region $b) {
|
||||
return $a->numeracion - $b->numeracion;
|
||||
});
|
||||
return $view->render($response, 'ventas.propietarios.edit', compact('propietario', 'venta_id', 'regiones'));
|
||||
}
|
||||
public function propiedad(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$propiedad = $venta->propiedad();
|
||||
$proyecto = $venta->proyecto();
|
||||
$unidades = $unidadService->getDisponiblesByProyecto($proyecto->id);
|
||||
$tiposUnidades = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!in_array($unidad->proyectoTipoUnidad->tipoUnidad, $tiposUnidades)) {
|
||||
$tiposUnidades []= $unidad->proyectoTipoUnidad->tipoUnidad;
|
||||
}
|
||||
}
|
||||
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id'));
|
||||
}
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -12,19 +13,24 @@ class Cierres
|
||||
{
|
||||
return $view->render($response, 'ventas.cierres.list');
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Ventas\Cierre $service, int $cierre_id): ResponseInterface
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cierre $service, int $cierre_id): ResponseInterface
|
||||
{
|
||||
$cierre = $service->getById($cierre_id);
|
||||
return $view->render($response, 'ventas.cierres.show', compact('cierre'));
|
||||
}
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Cierre $service): ResponseInterface
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['cierres' => $cierres, 'total' => count($cierres)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$output['cierres'] = $cierres;
|
||||
$output['total'] = count($cierres);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
22
app/src/Controller/Ventas/Comentarios.php
Normal file
22
app/src/Controller/Ventas/Comentarios.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Comentarios
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Comentario $comentarioRepository): ResponseInterface
|
||||
{
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchAll();
|
||||
$output['comentarios'] = $comentarios;
|
||||
$output['total'] = count($comentarios);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@ -44,16 +45,19 @@ class Cuotas
|
||||
}
|
||||
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Ventas\Pago $pagoService): ResponseInterface
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'depositada' => $pagoService->depositar($cuota->pago)
|
||||
'depositada' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['depositada'] = $pagoService->depositar($cuota->pago);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
26
app/src/Controller/Ventas/Pagos.php
Normal file
26
app/src/Controller/Ventas/Pagos.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Pagos
|
||||
{
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$date = new DateTimeImmutable($json->fecha);
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$date = new DateTimeImmutable($json->fecha);
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -14,18 +15,23 @@ class Precios
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.precios.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService): ResponseInterface
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['precios' => $precios, 'total' => count($precios)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$precio = $precioService->getByUnidad($unidad_id);
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
$response->getBody()->write(json_encode(['precio' => $precio]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
15
app/src/Controller/Ventas/Propietarios.php
Normal file
15
app/src/Controller/Ventas/Propietarios.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Propietarios
|
||||
{
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Venta\Propietario $propietarioRepository, int $propietario_rut): ResponseInterface
|
||||
{
|
||||
$propietario = $propietarioRepository->fetchById($propietario_rut);
|
||||
return $view->render($response, 'ventas.propietarios.show', compact('propietario'));
|
||||
}
|
||||
}
|
@ -17,6 +17,6 @@ class Comuna extends Model
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return implode(', ', [$this->descripcion, '' . $this->provincia]);
|
||||
return $this->descripcion;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,14 @@ class Direccion extends Model
|
||||
public string $extra;
|
||||
public Comuna $comuna;
|
||||
|
||||
public function full(): string
|
||||
{
|
||||
return implode(', ', [
|
||||
"{$this}",
|
||||
$this->comuna->provincia
|
||||
]);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
@ -30,7 +38,7 @@ class Direccion extends Model
|
||||
if ($this->extra !== '') {
|
||||
$array[]= $this->extra;
|
||||
}
|
||||
$array []= '' . $this->comuna;
|
||||
$array []= $this->comuna;
|
||||
return implode(', ', $array);
|
||||
}
|
||||
}
|
||||
|
@ -5,21 +5,36 @@ use Incoviba\Common\Ideal;
|
||||
|
||||
class Proyecto extends Ideal\Model
|
||||
{
|
||||
public Inmobiliaria $inmobiliaria;
|
||||
protected Inmobiliaria $inmobiliaria;
|
||||
public string $descripcion;
|
||||
public Direccion $direccion;
|
||||
protected Direccion $direccion;
|
||||
public Proyecto\Terreno $terreno;
|
||||
public Proyecto\Superficie $superficie;
|
||||
public float $corredor;
|
||||
public int $pisos;
|
||||
public int $subterraneos;
|
||||
|
||||
public function inmobiliaria(): Inmobiliaria
|
||||
{
|
||||
if (!isset($this->inmobiliaria)) {
|
||||
$this->inmobiliaria = $this->runFactory('inmobiliaria');
|
||||
}
|
||||
return $this->inmobiliaria;
|
||||
}
|
||||
public function direccion(): Direccion
|
||||
{
|
||||
if (!isset($this->direccion)) {
|
||||
$this->direccion = $this->runFactory('direccion');
|
||||
}
|
||||
return $this->direccion;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'inmobiliaria' => $this->inmobiliaria,
|
||||
'inmobiliaria' => $this->inmobiliaria(),
|
||||
'descripcion' => $this->descripcion,
|
||||
'direccion' => $this->direccion,
|
||||
'direccion' => $this->direccion(),
|
||||
'terreno' => $this->terreno,
|
||||
'superficie' => $this->superficie,
|
||||
'corredor' => $this->corredor,
|
||||
|
20
app/src/Model/Proyecto/Elemento.php
Normal file
20
app/src/Model/Proyecto/Elemento.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Elemento extends Ideal\Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public string $abreviacion;
|
||||
public int $orden;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'abreviacion' => $this->abreviacion,
|
||||
'orden' => $this->orden
|
||||
]);
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ class ProyectoTipoUnidad extends Ideal\Model
|
||||
public float $terraza;
|
||||
public string $descripcion;
|
||||
|
||||
public array $tipologias;
|
||||
|
||||
public function superficie(): float
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza], function($sum, $item) {return $sum + $item;}, 0);
|
||||
@ -23,6 +25,23 @@ class ProyectoTipoUnidad extends Ideal\Model
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza / 2], function($sum, $item) {return $sum + $item;}, 0);
|
||||
}
|
||||
public function tipologia(): string
|
||||
{
|
||||
if (isset($this->tipologias) and count($this->tipologias) > 0) {
|
||||
$temp = [...$this->tipologias];
|
||||
usort($temp, function(Tipologia $a, Tipologia $b) {
|
||||
$el = $a->elemento->orden - $b->elemento->orden;
|
||||
if ($el === 0) {
|
||||
return strcmp($a->elemento->abreviacion, $b->elemento->abreviacion);
|
||||
}
|
||||
return $el;
|
||||
});
|
||||
return implode('/', array_map(function(Tipologia $tipologia) {
|
||||
return $tipologia->cantidad . $tipologia->elemento->abreviacion;
|
||||
}, $temp));
|
||||
}
|
||||
return $this->abreviacion;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
@ -36,7 +55,8 @@ class ProyectoTipoUnidad extends Ideal\Model
|
||||
'terraza' => $this->terraza,
|
||||
'superficie' => $this->superficie(),
|
||||
'vendible' => $this->vendible(),
|
||||
'descripcion' => $this->descripcion
|
||||
'descripcion' => $this->descripcion,
|
||||
'tipologia' => $this->tipologia()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
8
app/src/Model/Proyecto/TipoTipologia.php
Normal file
8
app/src/Model/Proyecto/TipoTipologia.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoTipologia extends Tipo
|
||||
{
|
||||
}
|
20
app/src/Model/Proyecto/Tipologia.php
Normal file
20
app/src/Model/Proyecto/Tipologia.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Tipologia extends Ideal\Model
|
||||
{
|
||||
public ProyectoTipoUnidad $proyectoTipoUnidad;
|
||||
public TipoTipologia $tipoTipologia;
|
||||
public int $cantidad;
|
||||
public Elemento $elemento;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'cantidad' => $this->cantidad,
|
||||
'elemento' => $this->elemento
|
||||
]);
|
||||
}
|
||||
}
|
@ -3,32 +3,103 @@ namespace Incoviba\Model;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Controller\Ventas;
|
||||
|
||||
class Venta extends Ideal\Model
|
||||
{
|
||||
public Venta\Propietario $propietario;
|
||||
public Venta\Propiedad $propiedad;
|
||||
public Venta\FormaPago $formaPago;
|
||||
protected Venta\Propietario $propietario;
|
||||
protected Venta\Propiedad $propiedad;
|
||||
protected Venta\FormaPago $formaPago;
|
||||
public DateTimeInterface $fecha;
|
||||
public DateTimeInterface $fechaIngreso;
|
||||
public float $valor;
|
||||
public bool $relacionado;
|
||||
protected ?Venta\Entrega $entrega;
|
||||
|
||||
public array $estados;
|
||||
public Venta\EstadoVenta $currentEstado;
|
||||
|
||||
public function propietario(): Venta\Propietario
|
||||
{
|
||||
if (!isset($this->propietario)) {
|
||||
$this->propietario = $this->runFactory('propietario');
|
||||
}
|
||||
return $this->propietario;
|
||||
}
|
||||
public function propiedad(): Venta\Propiedad
|
||||
{
|
||||
if (!isset($this->propiedad)) {
|
||||
$this->propiedad = $this->runFactory('propiedad');
|
||||
}
|
||||
return $this->propiedad;
|
||||
}
|
||||
public function formaPago(): Venta\FormaPago
|
||||
{
|
||||
if (!isset($this->formaPago)) {
|
||||
$this->formaPago = $this->runFactory('formaPago');
|
||||
}
|
||||
return $this->formaPago;
|
||||
}
|
||||
public function entrega(): ?Venta\Entrega
|
||||
{
|
||||
if (!isset($this->entrega)) {
|
||||
$this->entrega = $this->runFactory('entrega');
|
||||
}
|
||||
return $this->entrega;
|
||||
}
|
||||
|
||||
public function estados(): array
|
||||
{
|
||||
if (!isset($this->estados)) {
|
||||
$this->estados = $this->runFactory('estados');
|
||||
}
|
||||
return $this->estados;
|
||||
}
|
||||
public function currentEstado(): ?Venta\EstadoVenta
|
||||
{
|
||||
if (!isset($this->currentEstado)) {
|
||||
$this->currentEstado = $this->runFactory('currentEstado');
|
||||
}
|
||||
return $this->currentEstado;
|
||||
}
|
||||
|
||||
public function proyecto(): Proyecto
|
||||
{
|
||||
return $this->propiedad()->departamentos()[0]->proyectoTipoUnidad->proyecto;
|
||||
}
|
||||
|
||||
protected float $valor_util;
|
||||
public function util(): float
|
||||
{
|
||||
if (!isset($this->valor_util)) {
|
||||
$sum = $this->valor;
|
||||
$sum -= array_reduce($this->propiedad()->estacionamientos(), function(float $sum, Venta\Unidad $unidad) {
|
||||
return $unidad->precio($this->fecha)->valor;
|
||||
}, 0);
|
||||
$sum -= array_reduce($this->propiedad()->bodegas(), function(float $sum, Venta\Unidad $unidad) {
|
||||
return $unidad->precio($this->fecha)->valor;
|
||||
}, 0);
|
||||
$this->valor_util = $sum;
|
||||
}
|
||||
return $this->valor_util;
|
||||
}
|
||||
public function saldo(): float
|
||||
{
|
||||
return $this->valor - $this->formaPago->total();
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'propietario' => $this->propietario,
|
||||
'propiedad' => $this->propiedad,
|
||||
'forma_pago' => $this->formaPago,
|
||||
'propietario' => $this->propietario(),
|
||||
'propiedad' => $this->propiedad(),
|
||||
'forma_pago' => $this->formaPago()->ids(),
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'fecha_ingreso' => $this->fechaIngreso->format('Y-m-d'),
|
||||
'valor' => $this->valor,
|
||||
'relacionado' => $this->relacionado,
|
||||
'estados' => $this->estados,
|
||||
'current_estado' => $this->currentEstado
|
||||
'estados' => array_map(function(Venta\EstadoVenta $estado) {return $estado->id;}, $this->estados()),
|
||||
'current_estado' => $this->currentEstado()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,14 @@ use Incoviba\Common\Ideal;
|
||||
|
||||
class BonoPie extends Ideal\Model
|
||||
{
|
||||
public float $valor;
|
||||
public Pago $pago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'valor' => $this->valor,
|
||||
'pago' => $this->pago
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
21
app/src/Model/Venta/Comentario.php
Normal file
21
app/src/Model/Venta/Comentario.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Comentario extends Ideal\Model
|
||||
{
|
||||
public DateTimeInterface $fecha;
|
||||
public string $texto;
|
||||
public bool $activo;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'texto' => $this->texto,
|
||||
'activo' => $this->activo
|
||||
]);
|
||||
}
|
||||
}
|
@ -4,4 +4,13 @@ namespace Incoviba\Model\Venta;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Credito extends Ideal\Model
|
||||
{}
|
||||
{
|
||||
public Pago $pago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago' => $this->pago
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Escritura extends Ideal\Model
|
||||
{}
|
||||
{
|
||||
public Pago $pago;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago' => $this->pago,
|
||||
'fecha' => $this->fecha->format('Y-m-d')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -6,19 +6,62 @@ use JsonSerializable;
|
||||
class FormaPago implements JsonSerializable
|
||||
{
|
||||
public ?Pie $pie;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Credito $credito;
|
||||
public ?Escritura $escritura;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Subsidio $subsidio;
|
||||
public ?Credito $credito;
|
||||
public ?Pago $devolucion;
|
||||
|
||||
public function anticipo(string $moneda = Pago::UF): float
|
||||
{
|
||||
$sum = 0;
|
||||
if ($this->pie !== null) {
|
||||
$sum += $this->pie->pagado($moneda);
|
||||
if (isset($this->pie->reajuste) and $this->pie->reajuste !== null) {
|
||||
$sum += $this->pie->reajuste->valor($moneda);
|
||||
}
|
||||
}
|
||||
if ($this->escritura !== null) {
|
||||
$sum += $this->escritura->pago->valor($moneda);
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
public function total(string $moneda = Pago::UF): float
|
||||
{
|
||||
$sum = $this->anticipo($moneda);
|
||||
if (isset($this->bonoPie)) {
|
||||
$sum += $this->bonoPie->pago->valor($moneda);
|
||||
}
|
||||
if (isset($this->subsidio)) {
|
||||
$sum += $this->subsidio->ahorro->valor($moneda);
|
||||
$sum += $this->subsidio->subsidio->valor($moneda);
|
||||
}
|
||||
if (isset($this->credito)) {
|
||||
$sum += $this->credito->pago->valor($moneda);
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
public function ids(): array
|
||||
{
|
||||
return [
|
||||
'pie_id' => $this->pie?->id,
|
||||
'escritura_id' => $this->escritura?->id,
|
||||
'bono_pie_id' => $this->bonoPie?->id,
|
||||
'credito_id' => $this->credito?->id,
|
||||
'subsidio_id' => $this->subsidio?->id,
|
||||
'devolucion_id' => $this->devolucion?->id
|
||||
];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'pie' => $this->pie ?? null,
|
||||
'bono_pie' => $this->bonoPie ?? null,
|
||||
'credito' => $this->credito ?? null,
|
||||
'escritura' => $this->escritura ?? null,
|
||||
'subsidio' => $this->subsidio ?? null
|
||||
'bono_pie' => $this->bonoPie ?? null,
|
||||
'subsidio' => $this->subsidio ?? null,
|
||||
'credito' => $this->credito ?? null,
|
||||
'devolucion' => $this->devolucion ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ use Incoviba\Model\Banco;
|
||||
|
||||
class Pago extends Model
|
||||
{
|
||||
const UF = 'uf';
|
||||
const PESOS = 'pesos';
|
||||
|
||||
public float $valor;
|
||||
public ?Banco $banco;
|
||||
public ?TipoPago $tipoPago;
|
||||
@ -16,6 +19,14 @@ class Pago extends Model
|
||||
public ?string $pagador;
|
||||
public ?Pago $asociado;
|
||||
|
||||
public array $estados;
|
||||
public EstadoPago $currentEstado;
|
||||
|
||||
public function valor(string $moneda = Pago::UF): float
|
||||
{
|
||||
return $this->valor / (($moneda === Pago::UF) ? ($this->uf > 0 ? $this->uf : 1) : 1);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -13,6 +13,24 @@ class Pie extends Model
|
||||
public ?Pie $asociado;
|
||||
public ?Pago $reajuste;
|
||||
|
||||
public array $cuotasArray;
|
||||
public function cuotas(bool $pagadas = false): array
|
||||
{
|
||||
if (!$pagadas) {
|
||||
return $this->cuotasArray;
|
||||
}
|
||||
return array_filter($this->cuotasArray, function(Cuota $cuota) {
|
||||
return $cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'no pagado';
|
||||
});
|
||||
}
|
||||
|
||||
public function pagado(string $moneda = Pago::UF): float
|
||||
{
|
||||
return array_reduce($this->cuotas(true), function(float $sum, Cuota $cuota) use ($moneda) {
|
||||
return $sum + $cuota->pago->valor($moneda);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -20,6 +20,14 @@ class Propiedad extends Ideal\Model
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';});
|
||||
}
|
||||
|
||||
protected float $vendible;
|
||||
public function vendible(): float
|
||||
{
|
||||
return array_reduce($this->departamentos(), function(float $sum, Unidad $unidad) {
|
||||
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
public function summary(): string
|
||||
{
|
||||
return implode(' - ', array_merge(
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -15,6 +16,33 @@ class Unidad extends Ideal\Model
|
||||
public array $precios = [];
|
||||
public ?Precio $currentPrecio = null;
|
||||
|
||||
public function precio(DateTimeInterface $dateTime): Precio
|
||||
{
|
||||
if ($dateTime > $this->currentPrecio->current->fecha) {
|
||||
return $this->currentPrecio;
|
||||
}
|
||||
$precio = array_reduce(array_filter($this->precios, function(Precio $precio) use ($dateTime) {
|
||||
return $dateTime > $precio->current->fecha;
|
||||
}), function(?Precio $max, Precio $precio) {
|
||||
if ($max === null) {
|
||||
return $precio;
|
||||
}
|
||||
return $max->current->fecha > $precio->current->fecha ? $max : $precio;
|
||||
});
|
||||
if ($precio === null) {
|
||||
$precio = array_reduce(array_filter($this->precios, function(Precio $precio) use ($dateTime) {
|
||||
return $dateTime < $precio->current->fecha;
|
||||
}), function(?Precio $min, Precio $precio) {
|
||||
if ($min === null) {
|
||||
return $precio;
|
||||
}
|
||||
return $min->current->fecha < $precio->current->fecha ? $min : $precio;
|
||||
});
|
||||
}
|
||||
|
||||
return $precio;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Banco extends Ideal\Repository
|
||||
@ -15,9 +16,7 @@ class Banco extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'nombre' => []
|
||||
];
|
||||
$map = new Implement\Repository\MapperParser(['nombre']);
|
||||
return $this->parseData(new Model\Banco(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Comuna extends Ideal\Repository
|
||||
@ -15,14 +16,10 @@ class Comuna extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'provincia' => [
|
||||
'function' => function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('provincia', (new Implement\Repository\Mapper())->setFunction(function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}));
|
||||
return $this->parseData(new Model\Comuna(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -48,4 +45,12 @@ class Comuna extends Ideal\Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `provincia` = ?";
|
||||
return $this->fetchMany($query, [$provincia_id]);
|
||||
}
|
||||
public function fetchByDireccion(string $direccion): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `direccion` ON `direccion`.`comuna` = a.`id`
|
||||
WHERE TRIM(CONCAT_WS(' ', `direccion`.`calle`, `direccion`.`numero`, `direccion`.`extra`)) LIKE ?";
|
||||
return $this->fetchMany($query, ["%{$direccion}%"]);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,11 @@
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal\Repository;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Direccion extends Repository
|
||||
class Direccion extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Comuna $comunaRepository)
|
||||
{
|
||||
@ -15,16 +16,10 @@ class Direccion extends Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'calle' => [],
|
||||
'numero' => [],
|
||||
'extra' => [],
|
||||
'comuna' => [
|
||||
'function' => function($data) {
|
||||
return $this->comunaRepository->fetchById($data['comuna']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['calle', 'numero', 'extra']))
|
||||
->register('comuna', (new Implement\Repository\Mapper())->setFunction(function($data) {
|
||||
return $this->comunaRepository->fetchById($data['comuna']);
|
||||
}));
|
||||
return $this->parseData(new Model\Direccion(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -21,23 +22,16 @@ class Inmobiliaria extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'dv' => [],
|
||||
'razon' => [],
|
||||
'abreviacion' => [],
|
||||
'cuenta' => [],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['db', 'razon', 'abreviacion', 'cuenta']))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'sociedad' => [
|
||||
'property' => 'tipoSociedad',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('sociedad', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoSociedad')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoSociedadRepository->fetchById($data['sociedad']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Inmobiliaria(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoSociedad extends Ideal\Repository
|
||||
@ -15,10 +16,7 @@ class TipoSociedad extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'abreviacion' => []
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'abreviacion']));
|
||||
return $this->parseData(new Model\Inmobiliaria\TipoSociedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Repository;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Login extends Ideal\Repository
|
||||
@ -17,27 +18,14 @@ class Login extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'user_id' => [
|
||||
'property' => 'user',
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['selector', 'token']))
|
||||
->register('user_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('user')
|
||||
->setFunction(function($data) {
|
||||
return $this->userRepository->fetchById($data['user_id']);
|
||||
}
|
||||
],
|
||||
'selector' => [],
|
||||
'token' => [],
|
||||
'time' => [
|
||||
'property' => 'dateTime',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['time']);
|
||||
}
|
||||
],
|
||||
'status' => [
|
||||
'function' => function($data) {
|
||||
return $data['status'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
}))
|
||||
->register('time', new Implement\Repository\Mapper\DateTime('time', 'dateTime'))
|
||||
->register('status', new Implement\Repository\Mapper\Boolean('status'));
|
||||
return $this->parseData(new Model\Login(), $data, $map);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Provincia extends Ideal\Repository
|
||||
@ -15,14 +16,11 @@ class Provincia extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'region' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('region', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->regionRepository->fetchById($data['region']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Provincia(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,8 +3,8 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyecto extends Ideal\Repository
|
||||
{
|
||||
@ -16,40 +16,31 @@ class Proyecto extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'inmobiliaria' => [
|
||||
'function' => function($data) {
|
||||
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria']);
|
||||
}
|
||||
],
|
||||
'descripcion' => [],
|
||||
'direccion' => [
|
||||
'function' => function($data) {
|
||||
return $this->direccionRepository->fetchById($data['direccion']);
|
||||
}
|
||||
],
|
||||
'superficie_terreno' => [
|
||||
'property' => 'terreno',
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'corredor', 'pisos', 'subterraneos']))
|
||||
->register('inmobiliaria', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('direccion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('superficie_terreno', (new Implement\Repository\Mapper())
|
||||
->setProperty('terreno')
|
||||
->setFunction(function($data) {
|
||||
$terreno = new Model\Proyecto\Terreno();
|
||||
$terreno->superficie = $data['superficie_terreno'];
|
||||
$terreno->valor = $data['valor_terreno'];
|
||||
return $terreno;
|
||||
}
|
||||
],
|
||||
'superficie_sobre_nivel' => [
|
||||
'property' => 'superficie',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('superficie_sobre_nivel', (new Implement\Repository\Mapper())
|
||||
->setProperty('superficie')
|
||||
->setFunction(function($data) {
|
||||
$superficie = new Model\Proyecto\Superficie();
|
||||
$superficie->sobre_nivel = $data['superficie_sobre_nivel'];
|
||||
$superficie->bajo_nivel = $data['superficie_bajo_nivel'];
|
||||
return $superficie;
|
||||
}
|
||||
],
|
||||
'corredor' => [],
|
||||
'pisos' => [],
|
||||
'subterraneos' => []
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Proyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -57,7 +48,7 @@ class Proyecto extends Ideal\Repository
|
||||
$model->id = $this->saveNew(
|
||||
['inmobiliaria', 'descripcion', 'direccion', 'superficie_terreno', 'valor_terreno', 'corredor',
|
||||
'superficie_sobre_nivel', 'superficie_bajo_nivel', 'pisos', 'subterraneos'],
|
||||
[$model->inmobiliaria->rut, $model->descripcion, $model->direccion->id, $model->terreno->superficie,
|
||||
[$model->inmobiliaria()->rut, $model->descripcion, $model->direccion()->id, $model->terreno->superficie,
|
||||
$model->terreno->valor, $model->corredor, $model->superficie->sobre_nivel,
|
||||
$model->superficie->bajo_nivel, $model->pisos, $model->subterraneos]
|
||||
);
|
||||
|
34
app/src/Repository/Proyecto/Elemento.php
Normal file
34
app/src/Repository/Proyecto/Elemento.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Elemento extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_elemento');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'abreviacion', 'orden']));
|
||||
return $this->parseData(new Model\Proyecto\Elemento(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'abreviacion', 'orden'],
|
||||
[$model->descripcion, $model->abreviacion, $model->orden]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'abreviacion', 'orden'], $new_data);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -16,27 +17,18 @@ class ProyectoTipoUnidad extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'proyecto' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['nombre', 'abreviacion', 'logia', 'terraza', 'descripcion']))
|
||||
->register('proyecto', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoRepository->fetchById($data['proyecto']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoUnidad',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('tipo', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoUnidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoUnidadRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'nombre' => [],
|
||||
'abreviacion' => [],
|
||||
'm2' => [
|
||||
'property' => 'util'
|
||||
],
|
||||
'logia' => [],
|
||||
'terraza' => [],
|
||||
'descripcion' => []
|
||||
];
|
||||
}))
|
||||
->register('m2', (new Implement\Repository\Mapper())
|
||||
->setProperty('util'));
|
||||
return $this->parseData(new Model\Proyecto\ProyectoTipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
34
app/src/Repository/Proyecto/TipoTipologia.php
Normal file
34
app/src/Repository/Proyecto/TipoTipologia.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoTipologia extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipologia');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']));
|
||||
return $this->parseData(new Model\Proyecto\TipoTipologia(), $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);
|
||||
}
|
||||
}
|
58
app/src/Repository/Proyecto/Tipologia.php
Normal file
58
app/src/Repository/Proyecto/Tipologia.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Tipologia extends Ideal\Repository
|
||||
{
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected ProyectoTipoUnidad $proyectoTipoUnidadRepository,
|
||||
protected TipoTipologia $tipoTipologiaRepository,
|
||||
protected Elemento $elementoRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_tipologia');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['cantidad']))
|
||||
->register('tipo', (new Implement\Repository\Mapper())
|
||||
->setProperty('proyectoTipoUnidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoTipoUnidadRepository->fetchById($data['tipo']);
|
||||
}))
|
||||
->register('tipologia', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoTipologiaRepository->fetchById($data['tipologia']);
|
||||
}))
|
||||
->register('elemento', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->elementoRepository->fetchById($data['elemento']);
|
||||
}));
|
||||
return $this->parseData(new Model\Proyecto\Tipologia(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['tipo', 'tipologia', 'cantidad', 'elemento'],
|
||||
[$model->proyectoTipoUnidad->id, $model->tipoTipologia->id, $model->cantidad, $model->elemento->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['tipo', 'tipologia', 'cantidad', 'elemento'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyectoTipoUnidad(int $proyecto_tipo_unidad_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `tipo` = ?";
|
||||
return $this->fetchMany($query, [$proyecto_tipo_unidad_id]);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Region extends Ideal\Repository
|
||||
@ -15,11 +16,7 @@ class Region extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'numeral' => [],
|
||||
'numeracion' => []
|
||||
];
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'numeral', 'numeracion']);
|
||||
return $this->parseData(new Model\Region(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class User extends Ideal\Repository
|
||||
@ -15,15 +16,8 @@ class User extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'name' => [],
|
||||
'password' => [],
|
||||
'enabled' => [
|
||||
'function' => function($data) {
|
||||
return $data['enabled'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['name', 'password']))
|
||||
->register('enabled', new Implement\Repository\Mapper\Boolean('enabled'));
|
||||
return $this->parseData(new Model\User(), $data, $map);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,9 @@ namespace Incoviba\Repository;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Venta extends Ideal\Repository
|
||||
{
|
||||
@ -12,13 +14,13 @@ class Venta extends Ideal\Repository
|
||||
Define\Connection $connection,
|
||||
protected Venta\Propietario $propietarioRepository,
|
||||
protected Venta\Propiedad $propiedadRepository,
|
||||
protected Venta\Pie $pieRepository,
|
||||
protected Service\Venta\Pie $pieService,
|
||||
protected Venta\BonoPie $bonoPieRepository,
|
||||
protected Venta\Credito $creditoRepository,
|
||||
protected Venta\Escritura $escrituraRepository,
|
||||
protected Venta\Subsidio $subsidioRepository,
|
||||
protected Venta\Entrega $entregaRepository,
|
||||
protected Venta\Pago $pagoRepository
|
||||
protected Service\Venta\Pago $pagoService
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
@ -27,95 +29,96 @@ class Venta extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'propietario' => [
|
||||
'function' => function($data) {
|
||||
return $this->propietarioRepository->fetchById($data['propietario']);
|
||||
}
|
||||
],
|
||||
'propiedad' => [
|
||||
'function' => function($data) {
|
||||
return $this->propiedadRepository->fetchById($data['propiedad']);
|
||||
}
|
||||
],
|
||||
'pie' => [
|
||||
'property' => 'formaPago',
|
||||
'function' => function($data) {
|
||||
$fp = new Model\Venta\FormaPago();
|
||||
$map = [
|
||||
'pie' => [
|
||||
'repository' => $this->pieRepository
|
||||
],
|
||||
'bono_pie' => [
|
||||
'property' => 'bonoPie',
|
||||
'repository' => $this->bonoPieRepository
|
||||
],
|
||||
'credito' => [
|
||||
'repository' => $this->creditoRepository
|
||||
],
|
||||
'escritura' => [
|
||||
'repository' => $this->escrituraRepository
|
||||
],
|
||||
'subsidio' => [
|
||||
'repository' => $this->subsidioRepository
|
||||
]
|
||||
];
|
||||
foreach ($map as $column => $settings) {
|
||||
if ($data[$column] !== null and $data[$column] !== 0) {
|
||||
$fp->{$settings['property'] ?? $column} = $settings['repository']->fetchById($data[$column]);
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('propietario', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->propietarioRepository, 'fetchById'])
|
||||
->setArgs([$data['propietario']])))
|
||||
->register('propiedad', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->propiedadRepository, 'fetchById'])
|
||||
->setArgs([$data['propiedad']])))
|
||||
->register('pie', (new Implement\Repository\Mapper())
|
||||
->setProperty('formaPago')
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($repositories, $data) {
|
||||
$fp = new Model\Venta\FormaPago();
|
||||
$map = [
|
||||
'pie' => [
|
||||
'service' => $repositories->pieService
|
||||
],
|
||||
'bono_pie' => [
|
||||
'property' => 'bonoPie',
|
||||
'repository' => $repositories->bonoPieRepository
|
||||
],
|
||||
'credito' => [
|
||||
'repository' => $repositories->creditoRepository
|
||||
],
|
||||
'escritura' => [
|
||||
'repository' => $repositories->escrituraRepository
|
||||
],
|
||||
'subsidio' => [
|
||||
'repository' => $repositories->subsidioRepository
|
||||
],
|
||||
'devolucion' => [
|
||||
'service' => $repositories->pagoService
|
||||
]
|
||||
];
|
||||
foreach ($map as $column => $settings) {
|
||||
if ($data[$column] !== null and $data[$column] !== 0) {
|
||||
if (isset($settings['repository'])) {
|
||||
$fp->{$settings['property'] ?? $column} = $settings['repository']->fetchById($data[$column]);
|
||||
continue;
|
||||
}
|
||||
$fp->{$settings['property'] ?? $column} = $settings['service']->getById($data[$column]);
|
||||
continue;
|
||||
}
|
||||
$fp->{$settings['property'] ?? $column} = null;
|
||||
}
|
||||
}
|
||||
return $fp;
|
||||
}
|
||||
],
|
||||
'escriturado' => [
|
||||
'function' => function($data) {
|
||||
return $fp;
|
||||
})
|
||||
->setArgs([(object) [
|
||||
'pieService' => $this->pieService,
|
||||
'bonoPieRepository' => $this->bonoPieRepository,
|
||||
'creditoRepository' => $this->creditoRepository,
|
||||
'escrituraRepository' => $this->escrituraRepository,
|
||||
'subsidioRepository' => $this->subsidioRepository,
|
||||
'pagoService' => $this->pagoService
|
||||
], $data])))
|
||||
/*->register('escriturado', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $data['escritura'] !== null;
|
||||
}
|
||||
],
|
||||
'entrega' => [
|
||||
'function' => function($data) {
|
||||
if ($data['entrega'] !== null and $data['entrega'] !== 0) {
|
||||
return $this->entregaRepository->fetchById($data['entrega']);
|
||||
}
|
||||
}
|
||||
],
|
||||
'entregado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['entrega'] !== null and $data['entrega'] !== 0) {
|
||||
return $data['entrega'] !== null;
|
||||
}
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor_uf' => [
|
||||
'property' => 'valor'
|
||||
],
|
||||
//'estado' => [],
|
||||
'fecha_ingreso' => [
|
||||
'property' => 'fechaIngreso',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha_ingreso']);
|
||||
}
|
||||
],
|
||||
/*'avalchile' => [
|
||||
|
||||
],*/
|
||||
//'agente',
|
||||
//'uf',
|
||||
'relacionado' => [
|
||||
'function' => function($data) {
|
||||
return $data['relacionado'] !== 0;
|
||||
}
|
||||
],
|
||||
//'promocion',
|
||||
//'resciliacion',
|
||||
//'devolucion'
|
||||
];
|
||||
}))*/
|
||||
->register('entrega', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($entrega_id) {
|
||||
if ($entrega_id !== null and $entrega_id !== 0) {
|
||||
return $this->entregaRepository->fetchById($entrega_id);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
->setArgs([$data['entrega']])))
|
||||
/*->register('entregado', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($entrega_id) {
|
||||
if ($entrega_id !== null and $entrega_id !== 0) {
|
||||
return $entrega_id != null;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
->setArgs([$data['entrega']])))*/
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('valor_uf', (new Implement\Repository\Mapper())
|
||||
->setProperty('valor'))
|
||||
//->register('estado')
|
||||
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
|
||||
//->register('avalchile')
|
||||
//->register('agente')
|
||||
//->register('uf')
|
||||
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
|
||||
//->register('promocion')
|
||||
//->register('resciliacion')
|
||||
//->register('devolucion');
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -124,9 +127,9 @@ class Venta extends Ideal\Repository
|
||||
['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'],
|
||||
[$model->propietario->rut, $model->propiedad->id, $model->formaPago->Pie?->id, $model->formaPago->bonoPie?->id,
|
||||
$model->formaPago->credito?->id, $model->formaPago->escritura?->id, $model->formaPago->subsidio?->id,
|
||||
$model->formaPago->escritura !== null ? 1 : 0, null, 0, $model->fecha->format('Y-m-d'), $model->valor,
|
||||
[$model->propietario->rut, $model->propiedad()->id, $model->formaPago()->Pie?->id, $model->formaPago()->bonoPie?->id,
|
||||
$model->formaPago()->credito?->id, $model->formaPago()->escritura?->id, $model->formaPago()->subsidio?->id,
|
||||
$model->formaPago()->escritura !== null ? 1 : 0, null, 0, $model->fecha->format('Y-m-d'), $model->valor,
|
||||
$model->currentEstado->vigente ? 1 : 0, $model->fechaIngreso->format('Y-m-d'), '', null, 0,
|
||||
$model->relacionado ? 1 : 0, null, null, null]
|
||||
);
|
||||
@ -152,4 +155,17 @@ WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`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 (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`";
|
||||
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
43
app/src/Repository/Venta/Comentario.php
Normal file
43
app/src/Repository/Venta/Comentario.php
Normal 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]);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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` = ?";
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -17,8 +17,16 @@ class Format
|
||||
return $formatter->format($date);
|
||||
|
||||
}
|
||||
public function number(float|string $number, int $decimal_places = 0): string
|
||||
{
|
||||
return number_format($number, $decimal_places, ',', '.');
|
||||
}
|
||||
public function pesos(string $valor): string
|
||||
{
|
||||
return '$' . number_format($valor, 0, ',', '.');
|
||||
return '$ ' . $this->number($valor);
|
||||
}
|
||||
public function ufs(string $valor): string
|
||||
{
|
||||
return $this->number($valor, 2) . ' UF';
|
||||
}
|
||||
}
|
||||
|
22
app/src/Service/Proyecto/ProyectoTipoUnidad.php
Normal file
22
app/src/Service/Proyecto/ProyectoTipoUnidad.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Proyecto;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class ProyectoTipoUnidad
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadRepository,
|
||||
protected Repository\Proyecto\Tipologia $tipologiaRepository
|
||||
) {}
|
||||
|
||||
public function getById(int $proyecto_tipo_unidad_id): Model\Proyecto\ProyectoTipoUnidad
|
||||
{
|
||||
$ptu = $this->proyectoTipoUnidadRepository->fetchById($proyecto_tipo_unidad_id);
|
||||
if ($ptu->tipoUnidad->descripcion === 'departamento') {
|
||||
$ptu->tipologias = $this->tipologiaRepository->fetchByProyectoTipoUnidad($proyecto_tipo_unidad_id);
|
||||
}
|
||||
return $ptu;
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Venta
|
||||
{
|
||||
@ -10,6 +12,16 @@ class Venta
|
||||
protected Repository\Venta\EstadoVenta $estadoVentaRepository
|
||||
) {}
|
||||
|
||||
public function getById(int $venta_id): Model\Venta
|
||||
{
|
||||
return ($this->ventaRepository->fetchById($venta_id))
|
||||
->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoVentaRepository, 'fetchByVenta'])
|
||||
->setArgs([$venta_id]))
|
||||
->addFactory('currentEstado', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoVentaRepository, 'fetchCurrentByVenta'])
|
||||
->setArgs([$venta_id]));
|
||||
}
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchByProyecto($proyecto_id);
|
||||
@ -19,4 +31,11 @@ class Venta
|
||||
}
|
||||
return $ventas;
|
||||
}
|
||||
public function getByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
|
||||
{
|
||||
$venta = $this->ventaRepository->fetchByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
||||
$venta->addFactory('estados', ['callable' => [$this->estadoVentaRepository, 'fetchByVenta'], 'args' => [$venta->id]]);
|
||||
$venta->addFactory('currentEstado', ['callable' => [$this->estadoVentaRepository, 'fetchCurrentByVenta'], 'args' => [$venta->id]]);
|
||||
return $venta;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Ventas;
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Ventas;
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDOException;
|
||||
@ -28,4 +28,11 @@ class Pago
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function getById(int $pago_id): Model\Venta\Pago
|
||||
{
|
||||
$pago = $this->pagoRepository->fetchById($pago_id);
|
||||
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago_id);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
|
||||
return $pago;
|
||||
}
|
||||
}
|
20
app/src/Service/Venta/Pie.php
Normal file
20
app/src/Service/Venta/Pie.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Pie
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Pie $pieRepository,
|
||||
protected Repository\Venta\Cuota $cuotaRepository
|
||||
) {}
|
||||
|
||||
public function getById(int $pie_id): Model\Venta\Pie
|
||||
{
|
||||
$pie = $this->pieRepository->fetchById($pie_id);
|
||||
$pie->cuotasArray = $this->cuotaRepository->fetchVigenteByPie($pie_id);
|
||||
return $pie;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Ventas;
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
@ -17,11 +17,20 @@ class Precio
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
public function getByUnidad(int $unidad_id): Model\Venta\Precio
|
||||
public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio
|
||||
{
|
||||
$precio = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
$precio = $this->precioRepository->fetchVigenteByUnidad($unidad_id);
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
return $precio;
|
||||
}
|
||||
public function getByUnidad(int $unidad_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
foreach ($precios as &$precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
}
|
49
app/src/Service/Venta/Unidad.php
Normal file
49
app/src/Service/Venta/Unidad.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Unidad
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Service\Venta\Precio $precioService
|
||||
) {}
|
||||
|
||||
public function getById(int $unidad_id): Model\Venta\Unidad
|
||||
{
|
||||
$unidad = $this->unidadRepository->fetchById($unidad_id);
|
||||
$this->fillPrecios($unidad);
|
||||
return $unidad;
|
||||
}
|
||||
public function getByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
$unidades = $this->unidadRepository->fetchByPropiedad($propiedad_id);
|
||||
array_walk($unidades, [$this, 'fillPrecios']);
|
||||
return $unidades;
|
||||
}
|
||||
public function getByCierre(int $cierre_id): array
|
||||
{
|
||||
$unidades = $this->unidadRepository->fetchByCierre($cierre_id);
|
||||
array_walk($unidades, [$this, 'fillPrecios']);
|
||||
return $unidades;
|
||||
}
|
||||
public function getDisponiblesByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$unidades = $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
//array_walk($unidades, [$this, 'fillPrecios']);
|
||||
return $unidades;
|
||||
}
|
||||
|
||||
protected function fillPrecios(&$unidad): void
|
||||
{
|
||||
try {
|
||||
$unidad->precios = $this->precioService->getByUnidad($unidad->id);
|
||||
$unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id);
|
||||
} catch (EmptyResult) {
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user