From 34cb8bf0beaae9c6aa217adabc8d65bc3f67aa03 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 17 Dec 2024 00:06:00 -0300 Subject: [PATCH] Mostrar colores y posibilidad de eliminar movimientos obsoletos --- .../contabilidad/cartolas/import.blade.php | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/app/resources/views/contabilidad/cartolas/import.blade.php b/app/resources/views/contabilidad/cartolas/import.blade.php index 365f734..e840d50 100644 --- a/app/resources/views/contabilidad/cartolas/import.blade.php +++ b/app/resources/views/contabilidad/cartolas/import.blade.php @@ -42,6 +42,7 @@ RUT Nombres Identificador + @@ -179,9 +180,10 @@ } class Movimiento { props - constructor({sociedad, fecha, glosa, cargo, abono, saldo, categoria, detalle, centro_costo, rut, nombres, - identificador, relacionado, relacionadoType}) { + constructor({id, sociedad, fecha, glosa, cargo, abono, saldo, categoria, detalle, centro_costo, rut, nombres, + identificador, relacionado, relacionadoType, nuevo = false, obsoleto = false}) { this.props = { + id, sociedad, fecha, glosa, @@ -195,7 +197,9 @@ nombres, identificador, relacionado, - relacionadoType + relacionadoType, + nuevo, + obsoleto } } draw({formatters}) { @@ -210,8 +214,17 @@ nombre = this.props.nombres } } + let edit = '' + let color = '' + if (this.props.nuevo) { + color = ' class="green"' + } + if (this.props.obsoleto) { + color = ' class="red"' + edit = `` + } return [ - '', + ``, `${this.props.sociedad.sigla}`, `${formatters.date.format(fecha)}`, `${this.props.glosa}`, @@ -224,6 +237,7 @@ `${this.props.rut ?? ''}`, `${nombre}`, `${this.props.identificador ?? ''}`, + `${edit}`, '' ].join("\n") } @@ -250,6 +264,22 @@ } } }, + remove() { + return { + movimiento: id => { + const url = `{{$urls->api}}/contabilidad/movimiento/${id}` + const method = 'delete' + APIClient.fetch(url, {method}).then(response => { + if (!response.status) { + return + } + const index = this.data.movimientos.findIndex(movimiento => movimiento.id === response.movimiento.id) + this.data.movimientos.splice(index, 1) + this.draw().movimientos() + }) + } + } + }, draw() { return { form: () => { @@ -269,6 +299,12 @@ tbody.append(movimiento.draw({formatters: this.formatters})) }) table.show() + Object.values(document.getElementsByClassName('remove_movimiento')).forEach(element => { + element.addEventListener('click', clickEvent => { + const id = clickEvent.currentTarget.dataset['id'] + this.remove().movimiento(id) + }) + }) } } }, @@ -293,7 +329,7 @@ }) }) - fetchAPI(url, {method, body}).then(response => { + APIClient.fetch(url, {method, body}).then(response => { if (!response) { return }