Listado proyectos
This commit is contained in:
@ -2,5 +2,6 @@
|
||||
use Incoviba\Controller\Proyectos;
|
||||
|
||||
$app->group('/proyectos', function($app) {
|
||||
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
|
||||
$app->get('[/]', Proyectos::class);
|
||||
});
|
||||
|
@ -1,9 +1,12 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Proyectos;
|
||||
use Incoviba\Controller\API\Proyectos;
|
||||
|
||||
$app->group('/proyectos', function($app) {
|
||||
$app->get('[/]', [Proyectos::class, 'list']);
|
||||
});
|
||||
$app->group('/proyecto/{proyecto_id}', function($app) {
|
||||
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
|
||||
$app->get('/estados[/]', [Proyectos\EstadosProyectos::class, 'byProyecto']);
|
||||
$app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']);
|
||||
$app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']);
|
||||
});
|
||||
|
4
app/resources/routes/api/proyectos/estados.php
Normal file
4
app/resources/routes/api/proyectos/estados.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Proyectos\EstadosProyectos;
|
||||
|
||||
//$app->group('/estados');
|
194
app/resources/views/proyectos/list.blade.php
Normal file
194
app/resources/views/proyectos/list.blade.php
Normal file
@ -0,0 +1,194 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Proyectos</h2>
|
||||
<table class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Proyecto</th>
|
||||
<th>Inmobiliaria</th>
|
||||
<th>Etapa</th>
|
||||
<th>Estado</th>
|
||||
<th>Tiempo Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($proyectos as $proyecto)
|
||||
<tr class="proyecto" data-id="{{$proyecto->id}}">
|
||||
<td>{{$proyecto->descripcion}}</td>
|
||||
<td>{{$proyecto->inmobiliaria()->nombreCompleto()}}</td>
|
||||
<td class="etapa"></td>
|
||||
<td class="estado"></td>
|
||||
<td class="tiempo"></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Proyecto {
|
||||
id
|
||||
estados
|
||||
|
||||
constructor(id) {
|
||||
this.id = id
|
||||
this.estados = {
|
||||
start: null,
|
||||
current: null
|
||||
}
|
||||
}
|
||||
get() {
|
||||
return {
|
||||
start: () => {
|
||||
return fetch('{{$urls->api}}/proyecto/' + this.id + '/inicio').then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.estados.start = data.estado
|
||||
})
|
||||
},
|
||||
current: () => {
|
||||
return fetch('{{$urls->api}}/proyecto/' + this.id + '/estado').then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.estados.current = data.estado
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
show() {
|
||||
const row = $(".proyecto[data-id='" + this.id + "']")
|
||||
const today = new Date()
|
||||
return {
|
||||
etapa: () => {
|
||||
row.find('.etapa').html(this.estados.current.tipo_estado_proyecto.etapa.descripcion)
|
||||
},
|
||||
current: () => {
|
||||
let estado = this.estados.current.tipo_estado_proyecto.descripcion
|
||||
|
||||
if (this.estados.current.tipo_estado_proyecto.etapa.descripcion === 'Terminado') {
|
||||
row.find('.estado').html(estado)
|
||||
return
|
||||
}
|
||||
|
||||
let diff = (today - new Date(this.estados.current.fecha.date)) / (1000 * 60 * 60 * 24)
|
||||
if (isNaN(diff) || diff === 0) {
|
||||
row.find('.estado').html(estado)
|
||||
return
|
||||
}
|
||||
let frame = 'días'
|
||||
if (diff >= 30) {
|
||||
diff /= 30
|
||||
frame = 'meses'
|
||||
}
|
||||
if (diff >= 12) {
|
||||
diff /= 12
|
||||
frame = 'años'
|
||||
}
|
||||
if (diff > 0) {
|
||||
estado += ' (hace ' + Math.floor(diff) + ' ' + frame + ')'
|
||||
}
|
||||
|
||||
row.find('.estado').html(estado)
|
||||
},
|
||||
tiempo: () => {
|
||||
if (this.estados.current.tipo_estado_proyecto.etapa.descripcion === 'Terminado') {
|
||||
return
|
||||
}
|
||||
let diff = (today - new Date(this.estados.start.fecha.date)) / (1000 * 60 * 60 * 24)
|
||||
if (isNaN(diff) || diff === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
let frame = 'días'
|
||||
if (diff >= 30) {
|
||||
diff /= 30
|
||||
frame = 'meses'
|
||||
}
|
||||
if (diff >= 12) {
|
||||
diff /= 12
|
||||
frame = 'años'
|
||||
}
|
||||
|
||||
row.find('.tiempo').html('Hace ' + Math.floor(diff) + ' ' + frame)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function showTiempo(proyecto_id, tiempo) {
|
||||
if (tiempo.trim() === '') {
|
||||
return
|
||||
}
|
||||
const row = $(".proyecto[data-id='" + proyecto_id + "']")
|
||||
row.find('.tiempo').html(tiempo)
|
||||
}
|
||||
function getEstados(proyecto_id) {
|
||||
return fetch('{{$urls->api}}/proyecto/' + proyecto_id + '/estados').then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
let tiempo = 0
|
||||
const current = new Date(data.estados.at(-1).fecha.date)
|
||||
const start = new Date(data.estados[0].fecha.date)
|
||||
tiempo = (current - start) / (1000 * 60 * 60 * 24)
|
||||
if (isNaN(tiempo) || tiempo === 0) {
|
||||
return
|
||||
}
|
||||
let frame = 'días'
|
||||
if (tiempo > 30) {
|
||||
tiempo /= 30
|
||||
frame = 'meses'
|
||||
}
|
||||
if (tiempo > 12) {
|
||||
tiempo /= 12
|
||||
frame = 'años'
|
||||
}
|
||||
showTiempo(data.proyecto_id, 'Hace ' + Math.ceil(tiempo) + ' ' + frame)
|
||||
})
|
||||
}
|
||||
function showEtapa(proyecto_id, etapa) {
|
||||
const row = $(".proyecto[data-id='" + proyecto_id + "']")
|
||||
row.find('.etapa').html(etapa)
|
||||
}
|
||||
function showEstado(proyecto_id, estado) {
|
||||
const row = $(".proyecto[data-id='" + proyecto_id + "']")
|
||||
row.find('.estado').html(estado)
|
||||
}
|
||||
function getEstado(proyecto_id) {
|
||||
return fetch('{{$urls->api}}/proyecto/' + proyecto_id + '/estado').then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
showEtapa(data.proyecto_id, data.estado.tipo_estado_proyecto.etapa.descripcion)
|
||||
showEstado(data.proyecto_id, data.estado.tipo_estado_proyecto.descripcion)
|
||||
})
|
||||
}
|
||||
function loadEstados(proyecto_id) {
|
||||
const proyecto = new Proyecto(proyecto_id)
|
||||
const promises = []
|
||||
promises.push(proyecto.get().start())
|
||||
promises.push(proyecto.get().current())
|
||||
Promise.all(promises).then(() => {
|
||||
proyecto.show().etapa()
|
||||
proyecto.show().current()
|
||||
proyecto.show().tiempo()
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
@foreach ($proyectos as $proyecto)
|
||||
loadEstados('{{$proyecto->id}}')
|
||||
/*getEstado('{{$proyecto->id}}')
|
||||
getEstados('{{$proyecto->id}}')*/
|
||||
@endforeach
|
||||
})
|
||||
</script>
|
||||
@endpush
|
4
app/resources/views/proyectos/unidades.blade.php
Normal file
4
app/resources/views/proyectos/unidades.blade.php
Normal file
@ -0,0 +1,4 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
@endsection
|
46
app/src/Controller/API/Proyectos.php
Normal file
46
app/src/Controller/API/Proyectos.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
53
app/src/Controller/API/Proyectos/EstadosProyectos.php
Normal file
53
app/src/Controller/API/Proyectos/EstadosProyectos.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Proyectos;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\emptyBody;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadosProyectos
|
||||
{
|
||||
use withJson, emptyBody;
|
||||
public function byProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'estados' => []
|
||||
];
|
||||
try {
|
||||
$output['estados'] = $estadoProyectoRepository->fetchByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function currentByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'estado' => null
|
||||
];
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchCurrentByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function firstByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'estado' => null
|
||||
];
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchFirstByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -4,11 +4,13 @@ namespace Incoviba\Controller\API\Ventas;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cierres
|
||||
{
|
||||
use withJson;
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
@ -20,8 +22,7 @@ class Cierres
|
||||
$output['cierres'] = $cierres;
|
||||
$output['total'] = count($cierres);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
@ -49,7 +50,6 @@ class Cierres
|
||||
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
|
||||
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
|
||||
}
|
||||
$response->getBody()->write(json_encode(['cierres' => $output]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
return $this->withJson($response, ['cierres' => $output]);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
@ -10,21 +11,20 @@ use Incoviba\Service;
|
||||
|
||||
class Cuotas
|
||||
{
|
||||
use withJson;
|
||||
public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'cuotas' => count($cuotaRepository->fetchHoy()) ?? 0
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'cuotas' => count($cuotaRepository->fetchPendientes()) ?? 0
|
||||
];
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Format $formatService): ResponseInterface
|
||||
{
|
||||
@ -53,7 +53,6 @@ class Cuotas
|
||||
});
|
||||
$output[$key] = $day;
|
||||
}
|
||||
$response->getBody()->write(json_encode(['cuotas' => $output]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
return $this->withJson($response, ['cuotas' => $output]);
|
||||
}
|
||||
}
|
||||
|
12
app/src/Controller/API/emptyBody.php
Normal file
12
app/src/Controller/API/emptyBody.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
trait emptyBody
|
||||
{
|
||||
public function emptyBody(ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
return $response->withStatus(204);
|
||||
}
|
||||
}
|
13
app/src/Controller/API/withJson.php
Normal file
13
app/src/Controller/API/withJson.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
trait withJson
|
||||
{
|
||||
public function withJson(ResponseInterface $response, array $data = []): ResponseInterface
|
||||
{
|
||||
$response->getBody()->write(json_encode($data));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -4,48 +4,29 @@ namespace Incoviba\Controller;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'proyectos.list');
|
||||
$proyectos = $proyectoRepository->fetchAll();
|
||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
return $view->render($response, 'proyectos.list', compact('proyectos'));
|
||||
}
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Proyecto $proyectoRepository, Repository\Venta\Unidad $unidadRepository): ResponseInterface
|
||||
{
|
||||
$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');
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
$proyectos = $proyectoRepository->fetchAll();
|
||||
$proyectos = array_filter($proyectos, function(Model\Proyecto $proyecto) use ($unidadRepository) {
|
||||
$unidades = $unidadRepository->fetchByProyecto($proyecto->id);
|
||||
return count($unidades) > 0;
|
||||
});
|
||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
return $view->render($response, 'proyectos.unidades', compact('proyectos'));
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ class NotFound
|
||||
} catch (HttpNotFoundException $exception) {
|
||||
$this->logger->warning($exception);
|
||||
$response = $this->responseFactory->createResponse(404);
|
||||
if (str_contains($request->getUri()->getPath(), '/api')) {
|
||||
return $response;
|
||||
}
|
||||
return $this->view->render($response, 'not_found');
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,13 @@ class Inmobiliaria extends Model
|
||||
$this->dv
|
||||
]);
|
||||
}
|
||||
public function nombreCompleto(): string
|
||||
{
|
||||
return implode(' ', [
|
||||
$this->razon,
|
||||
$this->tipoSociedad->descripcion
|
||||
]);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ class Proyecto extends Ideal\Model
|
||||
public float $corredor;
|
||||
public int $pisos;
|
||||
public int $subterraneos;
|
||||
protected Proyecto\Etapa $etapa;
|
||||
|
||||
public function inmobiliaria(): Inmobiliaria
|
||||
{
|
||||
|
30
app/src/Model/Proyecto/EstadoProyecto.php
Normal file
30
app/src/Model/Proyecto/EstadoProyecto.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class EstadoProyecto extends Ideal\Model
|
||||
{
|
||||
protected ?Model\Proyecto $proyecto;
|
||||
public TipoEstadoProyecto $tipoEstadoProyecto;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function proyecto(): Model\Proyecto
|
||||
{
|
||||
if (!isset($this->proyecto)) {
|
||||
$this->proyecto = $this->runFactory('proyecto');
|
||||
}
|
||||
return $this->proyecto;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'proyecto' => $this->proyecto(),
|
||||
'tipo_estado_proyecto' => $this->tipoEstadoProyecto,
|
||||
'fecha' => $this->fecha
|
||||
]);
|
||||
}
|
||||
}
|
18
app/src/Model/Proyecto/Etapa.php
Normal file
18
app/src/Model/Proyecto/Etapa.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Etapa extends Ideal\Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public int $orden;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'orden' => $this->orden
|
||||
]);
|
||||
}
|
||||
}
|
18
app/src/Model/Proyecto/TipoEstadoProyecto.php
Normal file
18
app/src/Model/Proyecto/TipoEstadoProyecto.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoEstadoProyecto extends Tipo
|
||||
{
|
||||
public int $orden;
|
||||
public Etapa $etapa;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'orden' => $this->orden,
|
||||
'etapa' => $this->etapa
|
||||
]);
|
||||
}
|
||||
}
|
@ -8,7 +8,11 @@ use Incoviba\Model;
|
||||
|
||||
class Proyecto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Inmobiliaria $inmobiliariaRepository, protected Direccion $direccionRepository)
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Inmobiliaria $inmobiliariaRepository,
|
||||
protected Direccion $direccionRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('proyecto');
|
||||
|
@ -14,12 +14,12 @@ class Elemento extends Ideal\Repository
|
||||
$this->setTable('tipo_elemento');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Proyecto\Elemento
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'abreviacion', 'orden']));
|
||||
$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
|
||||
public function save(Define\Model $model): Model\Proyecto\Elemento
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'abreviacion', 'orden'],
|
||||
@ -27,7 +27,7 @@ class Elemento extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\Elemento
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'abreviacion', 'orden'], $new_data);
|
||||
}
|
||||
|
73
app/src/Repository/Proyecto/EstadoProyecto.php
Normal file
73
app/src/Repository/Proyecto/EstadoProyecto.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class EstadoProyecto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Repository\Proyecto $proyectoRepository,
|
||||
protected TipoEstadoProyecto $tipoEstadoProyectoRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_proyecto');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('proyecto', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->proyectoRepository, 'fetchById'])
|
||||
->setArgs([$data['proyecto']])))
|
||||
->register('estado', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoEstadoProyecto')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoEstadoProyectoRepository->fetchById($data['estado']);
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
;
|
||||
return $this->parseData(new Model\Proyecto\EstadoProyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$model->id = $this->saveNew(['proyecto', 'estado', 'fecha'], [
|
||||
$model->proyecto()->id,
|
||||
$model->tipoEstadoProyecto()->id,
|
||||
$model->fecha->format('Y-m-d')
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
return $this->update($model, ['proyecto', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `proyecto` = ?";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchCurrentByProyecto(int $proyecto_id): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT MAX(`id`) AS 'id', `proyecto` FROM `{$this->getTable()}` GROUP BY `proyecto`) e0 ON e0.`id` = a.`id`
|
||||
WHERE a.`proyecto` = ?";
|
||||
return $this->fetchOne($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchFirstByProyecto(int $proyecto_id): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT MIN(`id`) AS 'id', `proyecto` FROM `{$this->getTable()}` GROUP BY `proyecto`) e0 ON e0.`id` = a.`id`
|
||||
WHERE a.`proyecto` = ?";
|
||||
return $this->fetchOne($query, [$proyecto_id]);
|
||||
}
|
||||
}
|
31
app/src/Repository/Proyecto/Etapa.php
Normal file
31
app/src/Repository/Proyecto/Etapa.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Etapa extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('etapa_proyecto');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\Etapa
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'orden']);
|
||||
return $this->parseData(new Model\Proyecto\Etapa(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Proyecto\Etapa
|
||||
{
|
||||
$model->id = $this->saveNew(['descripcion', 'orden'], [$model->descripcion, $model->orden]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\Etapa
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'orden'], $new_data);
|
||||
}
|
||||
}
|
36
app/src/Repository/Proyecto/TipoEstadoProyecto.php
Normal file
36
app/src/Repository/Proyecto/TipoEstadoProyecto.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoProyecto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Etapa $etapaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_proyecto');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\TipoEstadoProyecto
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'orden']))
|
||||
->register('etapa', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->etapaRepository->fetchById($data['etapa']);
|
||||
}));
|
||||
return $this->parseData(new Model\Proyecto\TipoEstadoProyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Proyecto\TipoEstadoProyecto
|
||||
{
|
||||
$model->id = $this->saveNew(['descripcion', 'orden', 'etapa'], [$model->descripcion, $model->orden, $model->etapa->id]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\TipoEstadoProyecto
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'orden', 'etapa'], $new_data);
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
$this->setTable('estado_venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\EstadoVenta
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('venta', (new Implement\Repository\Mapper())
|
||||
@ -32,7 +32,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
->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
|
||||
public function save(Define\Model $model): Model\Venta\EstadoVenta
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['venta', 'estado', 'fecha'],
|
||||
@ -40,7 +40,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\EstadoVenta
|
||||
{
|
||||
return $this->update($model, ['venta', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
@ -50,7 +50,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ?";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
public function fetchCurrentByVenta(int $venta_id): Define\Model
|
||||
public function fetchCurrentByVenta(int $venta_id): Model\Venta\EstadoVenta
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
|
@ -1,13 +1,32 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Proyecto
|
||||
{
|
||||
public function __construct(protected Repository\Proyecto $proyectoRepository) {}
|
||||
public function __construct(
|
||||
protected Repository\Proyecto $proyectoRepository,
|
||||
protected Repository\Proyecto\EstadoProyecto $estadoProyecto
|
||||
) {}
|
||||
public function getVendibles(): array
|
||||
{
|
||||
return $this->proyectoRepository->fetchAllActive();
|
||||
}
|
||||
public function getById(int $venta_id): Model\Proyecto
|
||||
{
|
||||
return $this->process($this->proyectoRepository->fetchById($venta_id));
|
||||
}
|
||||
protected function process(Model\Proyecto $proyecto): Model\Proyecto
|
||||
{
|
||||
$proyecto->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoProyecto, 'fetchByProyecto'])
|
||||
->setArgs([$proyecto->id]));
|
||||
$proyecto->addFactory('currentEstado', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoProyecto, 'fetchCurrentByProyecto'])
|
||||
->setArgs([$proyecto->id]));
|
||||
return $proyecto;
|
||||
}
|
||||
}
|
||||
|
@ -73,8 +73,12 @@ class Venta
|
||||
|
||||
protected function process(Model\Venta $venta): Model\Venta
|
||||
{
|
||||
$venta->addFactory('estados', (new Implement\Repository\Factory())->setCallable([$this->estadoVentaRepository, 'fetchByVenta'])->setArgs([$venta->id]));
|
||||
$venta->addFactory('currentEstado', (new Implement\Repository\Factory())->setCallable([$this->estadoVentaRepository, 'fetchCurrentByVenta'])->setArgs([$venta->id]));
|
||||
$venta->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoVentaRepository, 'fetchByVenta'])
|
||||
->setArgs([$venta->id]));
|
||||
$venta->addFactory('currentEstado', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoVentaRepository, 'fetchCurrentByVenta'])
|
||||
->setArgs([$venta->id]));
|
||||
return $venta;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user