Refresh and edit transacciones
This commit is contained in:
@ -50,7 +50,7 @@ class Transaccion {
|
|||||||
).append(
|
).append(
|
||||||
$('<td></td>').attr('class', 'right aligned').html(format.format(saldo))
|
$('<td></td>').attr('class', 'right aligned').html(format.format(saldo))
|
||||||
).append(
|
).append(
|
||||||
$('<td></td>').attr('class', 'right aligned')/*.append(
|
$('<td></td>').attr('class', 'right aligned').append(
|
||||||
$('<button></button>').attr('class', 'ui tiny circular icon button').append(
|
$('<button></button>').attr('class', 'ui tiny circular icon button').append(
|
||||||
$('<i></i>').attr('class', 'edit icon')
|
$('<i></i>').attr('class', 'edit icon')
|
||||||
).click((e) => {
|
).click((e) => {
|
||||||
@ -58,7 +58,7 @@ class Transaccion {
|
|||||||
this.edit()
|
this.edit()
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
)*/.append(
|
).append(
|
||||||
$('<button></button>').attr('class', 'ui tiny circular red icon button').append(
|
$('<button></button>').attr('class', 'ui tiny circular red icon button').append(
|
||||||
$('<i></i>').attr('class', 'remove icon')
|
$('<i></i>').attr('class', 'remove icon')
|
||||||
).click((e) => {
|
).click((e) => {
|
||||||
@ -71,7 +71,15 @@ class Transaccion {
|
|||||||
}
|
}
|
||||||
edit() {
|
edit() {
|
||||||
const form = this.modal.find('form')
|
const form = this.modal.find('form')
|
||||||
form.find("[name='fecha']")
|
form.trigger('reset')
|
||||||
|
form.find("[name='id']").val(this.id)
|
||||||
|
form.find(".ui.calendar").calendar('set date', new Date(this.fecha.fecha))
|
||||||
|
form.find("[name='cuenta']").dropdown('set selected', (this.isDebito()) ? this.credito_id : this.credito_id)
|
||||||
|
form.find("[name='glosa']").val(this.glosa)
|
||||||
|
form.find("[name='detalle']").val(this.detalle)
|
||||||
|
form.find("[name='valor']").val(((this.isDebito()) ? -1 : 1) * this.valor.valor)
|
||||||
|
modalToEdit(this.modal)
|
||||||
|
this.modal.modal('show')
|
||||||
}
|
}
|
||||||
remove() {
|
remove() {
|
||||||
sendDelete(_urls.api + '/transaccion/' + this.id + '/delete').then(() => {
|
sendDelete(_urls.api + '/transaccion/' + this.id + '/delete').then(() => {
|
||||||
@ -90,6 +98,7 @@ const transacciones = {
|
|||||||
get: function() {
|
get: function() {
|
||||||
return {
|
return {
|
||||||
transacciones: () => {
|
transacciones: () => {
|
||||||
|
this.draw().loading()
|
||||||
let promises = []
|
let promises = []
|
||||||
sendGet(_urls.api + '/cuenta/' + this.cuenta_id + '/transacciones/amount').then((data) => {
|
sendGet(_urls.api + '/cuenta/' + this.cuenta_id + '/transacciones/amount').then((data) => {
|
||||||
if (data.cuenta === null) {
|
if (data.cuenta === null) {
|
||||||
@ -128,10 +137,10 @@ const transacciones = {
|
|||||||
return (new Date(b.fecha)) - (new Date(a.fecha))
|
return (new Date(b.fecha)) - (new Date(a.fecha))
|
||||||
})
|
})
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.draw()
|
this.draw().table()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.draw()
|
this.draw().table()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -161,13 +170,30 @@ const transacciones = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
draw: function() {
|
draw: function() {
|
||||||
const format = Intl.NumberFormat('es-CL', {style: 'currency', currency: this.cuenta.moneda.codigo})
|
return {
|
||||||
const parent = $(this.id)
|
loading: () => {
|
||||||
parent.html('')
|
const parent = $(this.id)
|
||||||
$.each(this.transacciones, (i, el) => {
|
parent.html('')
|
||||||
parent.append(el.draw({saldo: this.saldo, format: format}))
|
parent.append(
|
||||||
this.saldo = this.saldo + parseInt(el.valor.valor) * ((el.isIncrement()) ? 1 : -1)
|
$('<tr></tr>').append(
|
||||||
})
|
$('<td></td>').attr('colspan', 7).append(
|
||||||
|
$('<div></div>').attr('class', 'ui active dimmer').append(
|
||||||
|
$('<div></div>').attr('class', 'ui indeterminate elastic text loader').html('Buscando los datos')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
table: () => {
|
||||||
|
const format = Intl.NumberFormat('es-CL', {style: 'currency', currency: this.cuenta.moneda.codigo})
|
||||||
|
const parent = $(this.id)
|
||||||
|
parent.html('')
|
||||||
|
$.each(this.transacciones, (i, el) => {
|
||||||
|
parent.append(el.draw({saldo: this.saldo, format: format}))
|
||||||
|
this.saldo = this.saldo + parseInt(el.valor.valor) * ((el.isIncrement()) ? 1 : -1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
add: function() {
|
add: function() {
|
||||||
return {
|
return {
|
||||||
@ -202,6 +228,27 @@ const transacciones = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
edit: function() {
|
||||||
|
const id = $("[name='id']").val()
|
||||||
|
const fecha = $("[name='fecha']").val()
|
||||||
|
const valor = $("[name='valor']").val()
|
||||||
|
const cuenta = $("[name='cuenta']").val()
|
||||||
|
const data = JSON.stringify({
|
||||||
|
debito_id: (valor < 0) ? this.cuenta_id : cuenta,
|
||||||
|
credito_id: (valor < 0) ? cuenta : this.cuenta_id,
|
||||||
|
fecha,
|
||||||
|
glosa,
|
||||||
|
detalle,
|
||||||
|
valor: (valor < 0) ? -valor : valor
|
||||||
|
})
|
||||||
|
return sendPut(_urls.api + '/transaccion/' + id + '/edit', data).then(() => {
|
||||||
|
this.modal.modal('hide')
|
||||||
|
this.get().transacciones()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
refresh: function () {
|
||||||
|
this.get().transacciones()
|
||||||
|
},
|
||||||
build: function() {
|
build: function() {
|
||||||
return {
|
return {
|
||||||
modal: () => {
|
modal: () => {
|
||||||
@ -212,7 +259,12 @@ const transacciones = {
|
|||||||
})
|
})
|
||||||
this.modal.find('form').submit((e) => {
|
this.modal.find('form').submit((e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
this.add().exec()
|
const add = $(e.currentTarget).find('.plus.icon')
|
||||||
|
if (add.length > 0) {
|
||||||
|
this.add().exec()
|
||||||
|
} else {
|
||||||
|
this.edit()
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
this.modal.find('.ui.calendar').calendar({
|
this.modal.find('.ui.calendar').calendar({
|
||||||
@ -234,7 +286,10 @@ const transacciones = {
|
|||||||
},
|
},
|
||||||
setup: function() {
|
setup: function() {
|
||||||
this.build().modal()
|
this.build().modal()
|
||||||
$(this.id).parent().find('.ui.button').click(() => {
|
$(this.id).parent().find('#refresh').click(() => {
|
||||||
|
this.refresh()
|
||||||
|
})
|
||||||
|
$(this.id).parent().find('#add').click(() => {
|
||||||
this.add().show()
|
this.add().show()
|
||||||
})
|
})
|
||||||
this.get().transacciones()
|
this.get().transacciones()
|
||||||
|
@ -27,23 +27,16 @@
|
|||||||
Saldo
|
Saldo
|
||||||
</th>
|
</th>
|
||||||
<th class="right aligned">
|
<th class="right aligned">
|
||||||
<button class="ui tiny green circular icon button">
|
<button class="ui tiny blue circular icon button" id="refresh">
|
||||||
|
<i class="refresh icon"></i>
|
||||||
|
</button>
|
||||||
|
<button class="ui tiny green circular icon button" id="add">
|
||||||
<i class="plus icon"></i>
|
<i class="plus icon"></i>
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="transacciones">
|
<tbody id="transacciones"></tbody>
|
||||||
<tr>
|
|
||||||
<td colspan="7">
|
|
||||||
<div class="ui active dimmer">
|
|
||||||
<div class="ui indeterminate elastic text loader">
|
|
||||||
Buscando los datos
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="ui modal">
|
<div class="ui modal">
|
||||||
|
Reference in New Issue
Block a user