Missing categoria from cuentas

This commit is contained in:
2021-12-23 01:09:35 -03:00
parent 0378a2cf09
commit 71b4211fc3
3 changed files with 57 additions and 34 deletions

View File

@ -96,40 +96,44 @@ const transacciones = {
return
}
this.cuenta = data.cuenta
this.saldo = this.cuenta.saldo
$('#cuenta').html(this.cuenta.nombre + ' (' + this.cuenta.categoria.nombre + ')').append(
$('<i></i>').attr('class', 'square full icon').css('color', '#' + this.cuenta.tipo.color)
)
const amount = data.transacciones
const step = 50
for (let i = 0; i < amount; i += step) {
promises.push(
sendGet(_urls.api + '/cuenta/' + this.cuenta_id + '/transacciones/' + step + '/' + i)
sendGet(_urls.api + '/cuenta/' + this.cuenta_id + '/categoria').then((resp) => {
this.cuenta.categoria = resp.categoria
}).then(() => {
this.saldo = this.cuenta.saldo
$('#cuenta').html(this.cuenta.nombre + ' (' + this.cuenta.categoria.nombre + ')').append(
$('<i></i>').attr('class', 'square full icon').css('color', '#' + this.cuenta.tipo.color)
)
}
if (promises.length > 0) {
Promise.all(promises).then((data_arr) => {
this.transacciones = []
data_arr.forEach(data => {
if (data.transacciones === null || data.transacciones.length === 0) {
return
}
$.each(data.transacciones, (i, el) => {
const tr = new Transaccion(el)
tr.setCuenta(this.cuenta)
tr.setModal(this.modal)
this.transacciones.push(tr)
const amount = data.transacciones
const step = 50
for (let i = 0; i < amount; i += step) {
promises.push(
sendGet(_urls.api + '/cuenta/' + this.cuenta_id + '/transacciones/' + step + '/' + i)
)
}
if (promises.length > 0) {
Promise.all(promises).then((data_arr) => {
this.transacciones = []
data_arr.forEach(data => {
if (data.transacciones === null || data.transacciones.length === 0) {
return
}
$.each(data.transacciones, (i, el) => {
const tr = new Transaccion(el)
tr.setCuenta(this.cuenta)
tr.setModal(this.modal)
this.transacciones.push(tr)
})
})
this.transacciones.sort((a, b) => {
return (new Date(b.fecha)) - (new Date(a.fecha))
})
}).then(() => {
this.draw()
})
this.transacciones.sort((a, b) => {
return (new Date(b.fecha)) - (new Date(a.fecha))
})
}).then(() => {
} else {
this.draw()
})
} else {
this.draw()
}
}
})
})
},
cuentas: () => {
@ -141,11 +145,18 @@ const transacciones = {
}).then(() => {
const select = this.modal.find("[name='cuenta']")
$.each(this.cuentas, (i, el) => {
select.append(
$('<option></option>').attr('value', el.id).html(el.nombre + ' (' + el.categoria.nombre + ')')
)
this.get().categoria(i).then(() => {
select.append(
$('<option></option>').attr('value', el.id).html(el.nombre + ' (' + el.categoria.nombre + ')')
)
})
})
})
},
categoria: (idx) => {
return sendGet(_urls.api + '/cuenta/' + this.cuentas[idx].id + '/categoria').then((data) => {
this.cuentas[idx].categoria = data.categoria
})
}
}
},
@ -172,7 +183,7 @@ const transacciones = {
fecha: fecha,
valor: $("[name='cambio']").val()
})
sendPut(_urls.api + '/tipos/cambios/add', data1)
sendPost(_urls.api + '/tipos/cambios/add', data1)
const valor = $("[name='valor']").val()
const cuenta = $("[name='cuenta']").val()