Compare commits
3 Commits
d8a81db78b
...
c2a3192b32
Author | SHA1 | Date | |
---|---|---|---|
c2a3192b32 | |||
0d558b7980 | |||
e4328d8604 |
15
adminer-compose.yml
Normal file
15
adminer-compose.yml
Normal file
@ -0,0 +1,15 @@
|
||||
services:
|
||||
adminer:
|
||||
profiles:
|
||||
- db
|
||||
container_name: incoviba_adminer
|
||||
image: adminer
|
||||
restart: unless-stopped
|
||||
env_file: ${APP_PATH:-.}/.adminer.env
|
||||
networks:
|
||||
- adminer_network
|
||||
ports:
|
||||
- "8083:8080"
|
||||
|
||||
networks:
|
||||
adminer_network: {}
|
@ -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');
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Cierres;
|
||||
use Incoviba\Controller\API\Ventas\Cierres;
|
||||
|
||||
$app->group('/cierres', function($app) {
|
||||
$app->get('/vigentes[/]', [Cierres::class, 'vigentes']);
|
||||
$app->post('[/]', [Cierres::class, 'proyecto']);
|
||||
});
|
||||
|
8
app/resources/routes/api/ventas/cuotas.php
Normal file
8
app/resources/routes/api/ventas/cuotas.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Ventas\Cuotas;
|
||||
|
||||
$app->group('/cuotas', function($app) {
|
||||
$app->get('/hoy[/]', [Cuotas::class, 'hoy']);
|
||||
$app->get('/pendiente[/]', [Cuotas::class, 'pendiente']);
|
||||
$app->get('/vencer[/]', [Cuotas::class, 'porVencer']);
|
||||
});
|
@ -4,23 +4,83 @@
|
||||
<div class="ui container">
|
||||
<h4 class="ui header">Bienvenid@ {{$user->name}}</h4>
|
||||
<div class="ui basic fitted segment">
|
||||
@if ($cuotas_hoy > 0)
|
||||
Existe{{$cuotas_hoy > 1 ? 'n' : ''}} {{$cuotas_hoy}} deposito{{$cuotas_hoy > 1 ? 's' : ''}} para hoy.
|
||||
<br />
|
||||
@endif
|
||||
@if ($cuotas_pendientes > 0)
|
||||
<a href="{{$urls->base}}/ventas/cuotas/pendientes">
|
||||
Existe{{$cuotas_pendientes > 1 ? 'n' : ''}} {{$cuotas_pendientes}} cuota{{$cuotas_pendientes > 1 ? 's' : ''}} pendiente{{$cuotas_pendientes > 1 ? 's' : ''}}. <i class="right arrow icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
<span id="cuotas_hoy"></span>
|
||||
<span id="cuotas_pendientes"></span>
|
||||
</div>
|
||||
<div class="ui two column grid">
|
||||
<div class="column">
|
||||
@include('home.cuotas_por_vencer')
|
||||
</div>
|
||||
<div class="column">
|
||||
Alertas
|
||||
</div>
|
||||
<div class="column">
|
||||
@include('home.cierres_vigentes')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const cuotas = {
|
||||
get: function() {
|
||||
return {
|
||||
hoy: () => {
|
||||
const span = $('#cuotas_hoy')
|
||||
return fetch('{{$urls->api}}/ventas/cuotas/hoy').then(response => {
|
||||
span.html('')
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
let output = 'Existe'
|
||||
if (data.cuotas > 1) {
|
||||
output += 'n'
|
||||
}
|
||||
output += ' ' + data.cuotas + ' deposito'
|
||||
if (data.cuotas > 1) {
|
||||
output += 's'
|
||||
}
|
||||
output += ' para hoy.<br />'
|
||||
span.html(output)
|
||||
})
|
||||
},
|
||||
pendiente: () => {
|
||||
const span = $('#cuotas_pendientes')
|
||||
return fetch('{{$urls->api}}/ventas/cuotas/pendiente').then(response => {
|
||||
span.html('')
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const link = $('<a></a>').attr('href', '{{$urls->base}}/ventas/cuotas/pendientes')
|
||||
let output = 'Existe'
|
||||
if (data.cuotas > 1) {
|
||||
output += 'n'
|
||||
}
|
||||
output += ' ' + data.cuotas + ' cuota'
|
||||
if (data.cuotas > 1) {
|
||||
output += 's'
|
||||
}
|
||||
output += ' pendiente'
|
||||
if (data.cuotas > 1) {
|
||||
output += 's'
|
||||
}
|
||||
output += ' por cobrar. <i class="right arrow icon"></i>'
|
||||
link.html(output)
|
||||
span.html(link)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
run: function() {
|
||||
this.get().hoy()
|
||||
this.get().pendiente()
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
cuotas.run()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -1,24 +1,59 @@
|
||||
<h4 class="ui dividing header">Cierres Vigentes</h4>
|
||||
<div class="ui divided list">
|
||||
@foreach($cierres_vigentes as $proyecto => $estados)
|
||||
<div class="item">
|
||||
<div class="ui feed">
|
||||
<div class="date">
|
||||
<strong>{{$proyecto}}</strong> [{{$estados['total']}}]
|
||||
</div>
|
||||
<div class="event">
|
||||
<div class="content">Promesados</div>
|
||||
<div class="meta">{{$estados['promesados']}}</div>
|
||||
</div>
|
||||
<div class="event">
|
||||
<div class="content">Pendientes</div>
|
||||
<div class="meta">{{$estados['pendientes']}}</div>
|
||||
</div>
|
||||
<div class="event">
|
||||
<div class="content">Rechazados</div>
|
||||
<div class="meta">{{$estados['rechazados']}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="ui divided list" id="cierres_vigentes"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const cierres_vigentes = {
|
||||
get: function() {
|
||||
const list = $('#cierres_vigentes')
|
||||
list.html('')
|
||||
list.append(
|
||||
$('<div><div>').addClass('ui inline active loader')
|
||||
)
|
||||
fetch('{{$urls->api}}/ventas/cierres/vigentes').then(response => {
|
||||
list.html('')
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.draw(data.cierres)
|
||||
})
|
||||
},
|
||||
draw: function(cierres) {
|
||||
const list = $('#cierres_vigentes')
|
||||
Object.entries(cierres).forEach(([proyecto, estados]) => {
|
||||
const item = $('<div></div>').addClass('item')
|
||||
const feed = $('<div></div>').addClass('ui feed')
|
||||
feed.append(
|
||||
$('<div></div>').addClass('date').append(
|
||||
$('<strong></strong>').html(proyecto).append('[' + estados['total'] + ']')
|
||||
)
|
||||
).append(
|
||||
$('<div></div>').addClass('event').append(
|
||||
$('<div></div>').addClass('content').html('Promesados')
|
||||
).append(
|
||||
$('<div></div>').addClass('meta').html(estados['promesados'])
|
||||
)
|
||||
).append(
|
||||
$('<div></div>').addClass('event').append(
|
||||
$('<div></div>').addClass('content').html('Pendientes')
|
||||
).append(
|
||||
$('<div></div>').addClass('meta').html(estados['pendientes'])
|
||||
)
|
||||
).append(
|
||||
$('<div></div>').addClass('event').append(
|
||||
$('<div></div>').addClass('content').html('Rechazados')
|
||||
).append(
|
||||
$('<div></div>').addClass('meta').html(estados['rechazados'])
|
||||
)
|
||||
)
|
||||
item.append(feed)
|
||||
list.append(item)
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
cierres_vigentes.get()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -1,22 +1,52 @@
|
||||
<h4 class="ui dividing header">Cuotas Por Vencer</h4>
|
||||
<div class="ui divided list">
|
||||
@foreach ($cuotas_por_vencer as $date => $proyectos)
|
||||
<div class="item">
|
||||
<div class="ui feed">
|
||||
<div class="date">
|
||||
<strong>{{$format->localDate($date, "EEE. dd 'de' MMMM 'de' yyyy", true)}}</strong>
|
||||
</div>
|
||||
@foreach ($proyectos as $proyecto => $cuotas)
|
||||
<div class="event">
|
||||
<div class="content">
|
||||
<span class="ui small text">
|
||||
{{$proyecto}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="meta">{{$cuotas}}</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="ui divided list" id="cuotas_por_vencer"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const cuotas_por_vencer = {
|
||||
get: function() {
|
||||
const list = $('#cuotas_por_vencer')
|
||||
list.html('')
|
||||
list.append(
|
||||
$('<div><div>').addClass('ui inline active loader')
|
||||
)
|
||||
return fetch('{{$urls->api}}/ventas/cuotas/vencer').then(response => {
|
||||
list.html('')
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.draw(data.cuotas)
|
||||
})
|
||||
},
|
||||
draw: function(cuotas) {
|
||||
const list = $('#cuotas_por_vencer')
|
||||
Object.entries(cuotas).forEach(([fecha, proyectos]) => {
|
||||
const item = $('<div></div>').addClass('item')
|
||||
const feed = $('<div></div>').addClass('ui feed')
|
||||
feed.append(
|
||||
$('<div></div>').addClass('date').append(
|
||||
$('<strong></strong>').html(fecha)
|
||||
)
|
||||
)
|
||||
Object.entries(proyectos).forEach(([proyecto, cuotas]) => {
|
||||
const event = $('<div></div>').addClass('event')
|
||||
event.append(
|
||||
$('<div></div>').addClass('content').append(
|
||||
$('<span></span>').addClass('ui small text').html(proyecto)
|
||||
)
|
||||
).append(
|
||||
$('<div></div>').addClass('meta').html(cuotas)
|
||||
)
|
||||
feed.append(event)
|
||||
})
|
||||
item.append(feed)
|
||||
list.append(item)
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
cuotas_por_vencer.get()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
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
|
@ -71,6 +71,8 @@
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').append(unidad)
|
||||
).append(
|
||||
$('<td></td>').append(this.unidad.descripcion.padStart(4, '0'))
|
||||
).append(
|
||||
$('<td></td>').append(propietario)
|
||||
).append(
|
||||
@ -160,7 +162,23 @@
|
||||
table.append(thead).append(tbody)
|
||||
parent.append(table)
|
||||
|
||||
this.table = new DataTable(table)
|
||||
this.table = new DataTable(table, {
|
||||
order: [
|
||||
[0, 'asc'],
|
||||
[2, 'asc']
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
target: 2,
|
||||
visible: false,
|
||||
searchable: false
|
||||
},
|
||||
{
|
||||
target: 1,
|
||||
orderData: [2]
|
||||
}
|
||||
]
|
||||
})
|
||||
},
|
||||
head: () => {
|
||||
return $('<thead></thead>').append(
|
||||
@ -168,6 +186,8 @@
|
||||
$('<th></th>').html('Proyecto')
|
||||
).append(
|
||||
$('<th></th>').html('Unidad')
|
||||
).append(
|
||||
$('<th></th>').html('Unidad [Sort]')
|
||||
).append(
|
||||
$('<th></th>').html('Propietario')
|
||||
).append(
|
||||
|
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);
|
||||
}
|
||||
}
|
55
app/src/Controller/API/Ventas/Cierres.php
Normal file
55
app/src/Controller/API/Ventas/Cierres.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
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();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$output['cierres'] = $cierres;
|
||||
$output['total'] = count($cierres);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
$cierres = $cierreRepository->fetchDatosVigentes();
|
||||
$output = [];
|
||||
$estados = [
|
||||
'revisado' => 'pendientes',
|
||||
'rechazado' => 'rechazados',
|
||||
'aprobado' => 'pendientes',
|
||||
'vendido' => 'promesados',
|
||||
'abandonado' => 'rechazados',
|
||||
'promesado' => 'promesados',
|
||||
'resciliado' => 'rechazados'
|
||||
];
|
||||
foreach ($cierres as $row) {
|
||||
if (!isset($output[$row['Proyecto']])) {
|
||||
$output[$row['Proyecto']] = [
|
||||
'promesados' => 0,
|
||||
'pendientes' => 0,
|
||||
'rechazados' => 0,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
$estado = $estados[$row['Estado']];
|
||||
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
|
||||
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
|
||||
}
|
||||
return $this->withJson($response, ['cierres' => $output]);
|
||||
}
|
||||
}
|
58
app/src/Controller/API/Ventas/Cuotas.php
Normal file
58
app/src/Controller/API/Ventas/Cuotas.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
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;
|
||||
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
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'cuotas' => count($cuotaRepository->fetchPendientes()) ?? 0
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Format $formatService): ResponseInterface
|
||||
{
|
||||
$cuotas = $cuotaRepository->fetchDatosPorVencer();
|
||||
$output = [];
|
||||
foreach ($cuotas as $row) {
|
||||
$fecha = $row['Fecha'];
|
||||
$date = new DateTimeImmutable($fecha);
|
||||
if (($weekday = $date->format('N')) > 5) {
|
||||
$day_diff = 7 - $weekday + 1;
|
||||
$date = $date->add(new DateInterval("P{$day_diff}D"));
|
||||
$fecha = $date->format('Y-m-d');
|
||||
}
|
||||
$key = $formatService->localDate($fecha, "EEE. dd 'de' MMMM 'de' yyyy", true);
|
||||
if (!isset($output[$key])) {
|
||||
$output[$key] = [];
|
||||
}
|
||||
if (!isset($output[$key][$row['Proyecto']])) {
|
||||
$output[$key][$row['Proyecto']] = 0;
|
||||
}
|
||||
$output[$key][$row['Proyecto']] += $row['Cantidad'];
|
||||
}
|
||||
foreach ($output as $key => $day) {
|
||||
uksort($day, function($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
$output[$key] = $day;
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
@ -11,10 +11,10 @@ use Incoviba\Repository;
|
||||
|
||||
class Base
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
|
||||
{
|
||||
if ($service->isIn()) {
|
||||
return $this->home($response, $view, $cuotaRepository, $cierreRepository);
|
||||
return $this->home($response, $view);
|
||||
}
|
||||
return $this->login($response, $view);
|
||||
}
|
||||
@ -22,72 +22,12 @@ class Base
|
||||
{
|
||||
return $view->render($response, 'construccion');
|
||||
}
|
||||
protected function home(ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
protected function home(ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
$cuotas_hoy = count($cuotaRepository->fetchHoy()) ?? 0;
|
||||
$cuotas_pendientes = count($cuotaRepository->fetchPendientes()) ?? 0;
|
||||
$cuotas_por_vencer = $this->getCuotasPorVencer($cuotaRepository);
|
||||
$cierres_vigentes = $this->getCierresVigentes($cierreRepository);
|
||||
return $view->render($response, 'home', compact('cuotas_hoy', 'cuotas_pendientes', 'cuotas_por_vencer', 'cierres_vigentes'));
|
||||
return $view->render($response, 'home');
|
||||
}
|
||||
protected function login(ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'guest');
|
||||
}
|
||||
protected function getCuotasPorVencer(Repository\Venta\Cuota $cuotaRepository): array
|
||||
{
|
||||
$cuotas = $cuotaRepository->fetchDatosPorVencer();
|
||||
$output = [];
|
||||
foreach ($cuotas as $row) {
|
||||
$fecha = $row['Fecha'];
|
||||
$date = new DateTimeImmutable($fecha);
|
||||
if (($weekday = $date->format('N')) > 5) {
|
||||
$day_diff = 7 - $weekday + 1;
|
||||
$date = $date->add(new DateInterval("P{$day_diff}D"));
|
||||
$fecha = $date->format('Y-m-d');
|
||||
}
|
||||
if (!isset($output[$fecha])) {
|
||||
$output[$fecha] = [];
|
||||
}
|
||||
if (!isset($output[$fecha][$row['Proyecto']])) {
|
||||
$output[$fecha][$row['Proyecto']] = 0;
|
||||
}
|
||||
$output[$fecha][$row['Proyecto']] += $row['Cantidad'];
|
||||
}
|
||||
foreach ($output as $fecha => $day) {
|
||||
uksort($day, function($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
$output[$fecha] = $day;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
protected function getCierresVigentes(Repository\Venta\Cierre $cierreRepository): array
|
||||
{
|
||||
$cierres = $cierreRepository->fetchDatosVigentes();
|
||||
$output = [];
|
||||
$estados = [
|
||||
'revisado' => 'pendientes',
|
||||
'rechazado' => 'rechazados',
|
||||
'aprobado' => 'pendientes',
|
||||
'vendido' => 'promesados',
|
||||
'abandonado' => 'rechazados',
|
||||
'promesado' => 'promesados',
|
||||
'resciliado' => 'rechazados'
|
||||
];
|
||||
foreach ($cierres as $row) {
|
||||
if (!isset($output[$row['Proyecto']])) {
|
||||
$output[$row['Proyecto']] = [
|
||||
'promesados' => 0,
|
||||
'pendientes' => 0,
|
||||
'rechazados' => 0,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
$estado = $estados[$row['Estado']];
|
||||
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
|
||||
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,11 @@ x-restart: &restart
|
||||
restart: unless-stopped
|
||||
|
||||
services:
|
||||
web:
|
||||
proxy:
|
||||
profiles:
|
||||
- app
|
||||
image: nginx:alpine
|
||||
container_name: incoviba_web
|
||||
container_name: incoviba_proxy
|
||||
<<: *restart
|
||||
ports:
|
||||
- "${APP_PORT}:80"
|
||||
@ -17,11 +17,11 @@ services:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./logs/proxy:/logs
|
||||
|
||||
php:
|
||||
web:
|
||||
profiles:
|
||||
- app
|
||||
build: .
|
||||
container_name: incoviba_php
|
||||
container_name: incoviba_web
|
||||
<<: *restart
|
||||
env_file:
|
||||
- ${APP_PATH:-.}/.env
|
||||
@ -45,18 +45,6 @@ services:
|
||||
- default
|
||||
- adminer_network
|
||||
|
||||
adminer:
|
||||
profiles:
|
||||
- db
|
||||
image: adminer:latest
|
||||
container_name: incoviba_adminer
|
||||
<<: *restart
|
||||
env_file: ${APP_PATH:-.}/.adminer.env
|
||||
networks:
|
||||
- adminer_network
|
||||
ports:
|
||||
- "8083:8080"
|
||||
|
||||
python:
|
||||
profiles:
|
||||
- python
|
||||
|
@ -18,6 +18,6 @@ server {
|
||||
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_read_timeout 3600;
|
||||
fastcgi_pass php:9000;
|
||||
fastcgi_pass web:9000;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user