Estado Recepcion Final en Proyecto

This commit is contained in:
2023-10-19 22:43:21 -03:00
parent 54ac535a49
commit 4734417fe2
5 changed files with 75 additions and 63 deletions

View File

@ -11,6 +11,7 @@
<th>Etapa</th>
<th>Estado</th>
<th>Tiempo Total</th>
<th>Tiempo RF</th>
</tr>
</thead>
<tbody>
@ -21,6 +22,7 @@
<td class="etapa"></td>
<td class="estado"></td>
<td class="tiempo"></td>
<td class="recepcion"></td>
</tr>
@endforeach
</tbody>
@ -38,7 +40,8 @@
this.id = id
this.estados = {
start: null,
current: null
current: null,
recepcion: null
}
}
get() {
@ -60,6 +63,21 @@
}).then(data => {
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) {
diff /= 30
frame = 'meses'
}
if (diff >= 12) {
diff /= 12
frame = 'años'
if (diff >= 12) {
diff /= 12
frame = 'años'
}
}
if (diff > 0) {
estado += ' (hace ' + Math.floor(diff) + ' ' + frame + ')'
@ -111,83 +129,55 @@
if (diff >= 30) {
diff /= 30
frame = 'meses'
}
if (diff >= 12) {
diff /= 12
frame = 'años'
if (diff >= 12) {
diff /= 12
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) {
const proyecto = new Proyecto(proyecto_id)
const promises = []
promises.push(proyecto.get().start())
promises.push(proyecto.get().current())
promises.push(proyecto.get().recepcion())
Promise.all(promises).then(() => {
proyecto.show().etapa()
proyecto.show().current()
proyecto.show().tiempo()
proyecto.show().recepcion()
})
}
$(document).ready(() => {
@foreach ($proyectos as $proyecto)
loadEstados('{{$proyecto->id}}')
/*getEstado('{{$proyecto->id}}')
getEstados('{{$proyecto->id}}')*/
@endforeach
})
</script>