Estado Recepcion Final en Proyecto
This commit is contained in:
@ -9,4 +9,5 @@ $app->group('/proyecto/{proyecto_id}', function($app) {
|
|||||||
$app->get('/estados[/]', [Proyectos\EstadosProyectos::class, 'byProyecto']);
|
$app->get('/estados[/]', [Proyectos\EstadosProyectos::class, 'byProyecto']);
|
||||||
$app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']);
|
$app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']);
|
||||||
$app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']);
|
$app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']);
|
||||||
|
$app->get('/recepcion[/]', [Proyectos\EstadosProyectos::class, 'recepcionByProyecto']);
|
||||||
});
|
});
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<th>Etapa</th>
|
<th>Etapa</th>
|
||||||
<th>Estado</th>
|
<th>Estado</th>
|
||||||
<th>Tiempo Total</th>
|
<th>Tiempo Total</th>
|
||||||
|
<th>Tiempo RF</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -21,6 +22,7 @@
|
|||||||
<td class="etapa"></td>
|
<td class="etapa"></td>
|
||||||
<td class="estado"></td>
|
<td class="estado"></td>
|
||||||
<td class="tiempo"></td>
|
<td class="tiempo"></td>
|
||||||
|
<td class="recepcion"></td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -38,7 +40,8 @@
|
|||||||
this.id = id
|
this.id = id
|
||||||
this.estados = {
|
this.estados = {
|
||||||
start: null,
|
start: null,
|
||||||
current: null
|
current: null,
|
||||||
|
recepcion: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get() {
|
get() {
|
||||||
@ -60,6 +63,21 @@
|
|||||||
}).then(data => {
|
}).then(data => {
|
||||||
this.estados.current = data.estado
|
this.estados.current = data.estado
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
recepcion: () => {
|
||||||
|
return fetch('{{$urls->api}}/proyecto/' + this.id + '/recepcion').then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
if (response.status === 204) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return response.json()
|
||||||
|
}
|
||||||
|
}).then(data => {
|
||||||
|
if (data === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.estados.recepcion = data.estado
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,10 +105,10 @@
|
|||||||
if (diff >= 30) {
|
if (diff >= 30) {
|
||||||
diff /= 30
|
diff /= 30
|
||||||
frame = 'meses'
|
frame = 'meses'
|
||||||
}
|
if (diff >= 12) {
|
||||||
if (diff >= 12) {
|
diff /= 12
|
||||||
diff /= 12
|
frame = 'años'
|
||||||
frame = 'años'
|
}
|
||||||
}
|
}
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
estado += ' (hace ' + Math.floor(diff) + ' ' + frame + ')'
|
estado += ' (hace ' + Math.floor(diff) + ' ' + frame + ')'
|
||||||
@ -111,83 +129,55 @@
|
|||||||
if (diff >= 30) {
|
if (diff >= 30) {
|
||||||
diff /= 30
|
diff /= 30
|
||||||
frame = 'meses'
|
frame = 'meses'
|
||||||
}
|
if (diff >= 12) {
|
||||||
if (diff >= 12) {
|
diff /= 12
|
||||||
diff /= 12
|
frame = 'años'
|
||||||
frame = 'años'
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
row.find('.tiempo').html('Hace ' + Math.floor(diff) + ' ' + frame)
|
row.find('.tiempo').html(Math.floor(diff) + ' ' + frame)
|
||||||
|
},
|
||||||
|
recepcion: () => {
|
||||||
|
if (this.estados.recepcion === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let diff = (today - new Date(this.estados.recepcion.fecha.date)) / (1000 * 60 * 60 * 24)
|
||||||
|
if (isNaN(diff) || diff === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let frame = 'dias'
|
||||||
|
if (diff >= 30) {
|
||||||
|
diff /= 30
|
||||||
|
frame = 'meses'
|
||||||
|
if (diff >= 12) {
|
||||||
|
diff /= 12
|
||||||
|
frame = 'años'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
row.find('.recepcion').html(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) {
|
function loadEstados(proyecto_id) {
|
||||||
const proyecto = new Proyecto(proyecto_id)
|
const proyecto = new Proyecto(proyecto_id)
|
||||||
const promises = []
|
const promises = []
|
||||||
promises.push(proyecto.get().start())
|
promises.push(proyecto.get().start())
|
||||||
promises.push(proyecto.get().current())
|
promises.push(proyecto.get().current())
|
||||||
|
promises.push(proyecto.get().recepcion())
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
proyecto.show().etapa()
|
proyecto.show().etapa()
|
||||||
proyecto.show().current()
|
proyecto.show().current()
|
||||||
proyecto.show().tiempo()
|
proyecto.show().tiempo()
|
||||||
|
proyecto.show().recepcion()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
@foreach ($proyectos as $proyecto)
|
@foreach ($proyectos as $proyecto)
|
||||||
loadEstados('{{$proyecto->id}}')
|
loadEstados('{{$proyecto->id}}')
|
||||||
/*getEstado('{{$proyecto->id}}')
|
|
||||||
getEstados('{{$proyecto->id}}')*/
|
|
||||||
@endforeach
|
@endforeach
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -50,4 +50,17 @@ class EstadosProyectos
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
public function recepcionByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$output = [
|
||||||
|
'proyecto_id' => $proyecto_id,
|
||||||
|
'estado' => null
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id);
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
return $this->emptyBody($response);
|
||||||
|
}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ ORDER BY a.`descripcion`";
|
|||||||
SELECT MAX(e1.`id`) AS 'id', e1.`proyecto`
|
SELECT MAX(e1.`id`) AS 'id', e1.`proyecto`
|
||||||
FROM `estado_proyecto` e1
|
FROM `estado_proyecto` e1
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT MAX(`id`) AS 'id', `proyecto`, `fecha`
|
SELECT `id`, `proyecto`, MAX(`fecha`) as 'fecha'
|
||||||
FROM `estado_proyecto`
|
FROM `estado_proyecto`
|
||||||
GROUP BY `proyecto`, `fecha`
|
GROUP BY `proyecto`, `fecha`
|
||||||
) e0 ON e1.`id` = e0.`id`
|
) e0 ON e1.`id` = e0.`id`
|
||||||
|
@ -70,4 +70,12 @@ FROM `{$this->getTable()}` a
|
|||||||
WHERE a.`proyecto` = ?";
|
WHERE a.`proyecto` = ?";
|
||||||
return $this->fetchOne($query, [$proyecto_id]);
|
return $this->fetchOne($query, [$proyecto_id]);
|
||||||
}
|
}
|
||||||
|
public function fetchRecepcionByProyecto(int $proyecto_id): Model\Proyecto\EstadoProyecto
|
||||||
|
{
|
||||||
|
$query = "SELECT a.*
|
||||||
|
FROM `{$this->getTable()}` a
|
||||||
|
JOIN `tipo_estado_proyecto` tep ON tep.`id` = a.`estado`
|
||||||
|
WHERE a.`proyecto` = ? AND tep.`descripcion` = 'Recepción Final'";
|
||||||
|
return $this->fetchOne($query, [$proyecto_id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user