@@ -203,18 +186,26 @@
movimiento: clickEvent => {
const id = $(clickEvent.currentTarget).data('id')
const index = $(clickEvent.currentTarget).data('index')
- const type = $(clickEvent.currentTarget).data('type')
const movimiento = this.props.movimientosHandler.find().id(id)
- clickEvent.data.handler.props.modalHandler.show({movimiento, type})
+ clickEvent.data.handler.props.modalHandler.show({movimiento, index})
+ },
+ modal: submitEvent => {
+ submitEvent.preventDefault()
+ const form = submitEvent.currentTarget
+ const data = new FormData(form)
+ app.handlers.movimientos.edit().movimiento(data).then(() => {
+ app.handlers.table.draw().table(app.handlers.results.props.parsed)
+ })
+ return false
}
}
}
}
class LoadingHandler {
props
- constructor({ids}) {
+ constructor(ids) {
this.props = {
- ids
+ ...ids
}
}
show() {
@@ -230,8 +221,6 @@
this.props = {
ids,
}
- }
- setup() {
$(this.props.ids.sociedades).dropdown()
const cdo = structuredClone(calendar_date_options)
@@ -242,12 +231,13 @@
$(this.props.ids.form).on('submit', {
sociedades_id: this.props.ids.sociedades,
mes_id: this.props.ids.mes,
- handler: app.handlers.event
- }, app.handlers.event.get().movimientos)
+ handler: app.handlers.events
+ }, app.handlers.events.get().movimientos)
}
}
class MovimientosTable {
props
+ columns
constructor({ids, eventHandler}) {
this.props = {
ids,
@@ -262,53 +252,75 @@
}),
},
}
- }
- draw() {
- return {
- table: (movimientos) => {
- this.props.table.clear().rows.add(this.draw().movimientos(movimientos)).draw()
- $(this.props.ids.buttons.edit).on('click', {handler: this.props.eventHandler}, this.props.eventHandler.edit().movimiento)
- },
- movimientos: (movimientos) => {
- const output = []
- movimientos.forEach(movimiento => {
- this.draw().movimiento({movimiento, output})
- })
- return output
- },
- movimiento: ({movimiento, output}) => {
- const valor = movimiento.abono - movimiento.cargo
- const fecha = movimiento.fecha
- output.push([
- movimiento.cuenta.inmobiliaria.sigla,//0
- movimiento.cuenta.banco.nombre,//1
- movimiento.cuenta.cuenta,//2
- this.props.formatters.date.format(fecha),//3
- [fecha.getFullYear(), fecha.getMonth() + 1, fecha.getDate()].join('-'),//4
- fecha.getMonth() + 1,//5
- fecha.getFullYear(),//6
- this.props.formatters.number.format(valor),//7
- valor,//8
- (movimiento.detalles) ? movimiento.detalles.centro_costo.id : '',//9
- movimiento.glosa,//10
- (movimiento.detalles) ? movimiento.detalles.detalle : '',//11
- '
',//12
- ])
+
+ this.columns = [
+ {title: 'Sigla', defs: {width: 'short', type: 'string'}, searchable: true, export: true}, //0
+ {title: 'Banco', defs: {width: 'long', type: 'string'}, searchable: true, export: true},
+ {title: 'Cuenta', defs: {width: 'short', type: 'string'}, searchable: true, export: true},
+ {title: 'Fecha', defs: {width: 'long', type: 'string'}, searchable: true, export: true},
+ {title: 'ISO Fecha', defs: {visible: false}},
+ {title: 'Mes', defs: {width: 'short', type: 'string'}, searchable: true}, //5
+ {title: 'Año', defs: {width: 'long', type: 'string'}, searchable: true},
+ {title: 'Valor', defs: {className: 'dt-right', width: 'long', type: 'num'}, export: true},
+ {title: 'ISO Valor', defs: {visible: false, type: 'num'}},
+ {title: 'Glosa', defs: {width: 'short', type: 'string'}, export: true},
+ {title: 'Centro de Costo', defs: {width: 'short', type: 'string'}, searchable: true, export: true}, //10
+ {title: 'Categoria', defs: {width: 'short', type: 'string'}},
+ {title: 'Detalle', defs: {width: 'long', type: 'string'}, export: true},
+ {title: 'RUT', defs: {width: 'short', type: 'string'}, export: true},
+ {title: 'Nombre', defs: {width: 'short', type: 'string'}, export: true},
+ {title: 'Identificador', defs: {width: 'short', type: 'string'}, export: true}, //15
+ {title: 'Editar', defs: {width: 'short', type: 'string'}},
+ ]
+ const N = this.columns.filter(column => typeof column.defs.visible === 'undefined' || column.defs.visible).length
+ const nShort = this.columns.filter(column => column.defs.width === 'short').length
+ const nLong = this.columns.filter(column => column.defs.width === 'long').length
+ const short = `${(nShort / N).toFixed(2)}%`
+ const long = `${(nLong / N).toFixed(2)}%`
+
+ this.columns = this.columns.map(column => {
+ if (typeof column.defs.width === 'undefined') {
+ return column
}
- }
- }
- setup() {
+ switch (column.defs.width) {
+ case 'short':
+ column.defs.width = short
+ break
+ case 'long':
+ column.defs.width = long
+ break
+ }
+ return column
+ })
+
+ const tr = $(this.props.ids.table).find('thead tr')
+ tr.empty()
+ this.columns.forEach(column => {
+ if (column.defs.className === 'dt-right') {
+ tr.append(`
${column.title} | `)
+ return
+ }
+ tr.append(`
${column.title} | `)
+ })
+
let dtD = structuredClone(datatables_defaults)
+ const groupedColumns = Object.groupBy(this.columns, ({defs}) => Object.entries(defs).map((field, value) => `${field}: ${value}`).join(' - '))
+ const columnDefs = Object.values(groupedColumns).map(group => {
+ return {
+ targets: group.map(({title}) => title).map(title => this.columns.map(column => column.title).indexOf(title)),
+ ...group[0].defs
+ }
+ })
+ const searchBuilderColumns = this.columns.filter(column => column.searchable)
+ .map(column => column.title).map(title => this.columns.map(column => column.title).indexOf(title))
+ const exportColumns = this.columns.filter(column => column.export)
+ .map(column => column.title).map(title => this.columns.map(column => column.title).indexOf(title))
+ const order = ['Sigla', 'Banco', 'ISO Fecha'].map(title => {
+ return [this.columns.map(column => column.title).indexOf(title), 'asc']
+ })
dtD = Object.assign(dtD, {
- columnDefs: [
- {targets: [0, 5, 9, 12], width: '5%', type: 'string'},
- {targets: [1, 2, 3, 6, 10], width: '10%', type: 'string'},
- {targets: [11], width: '20%', type: 'string'},
- {targets: 4, visible: false},
- {targets: 7, className: 'dt-right', width: '10%'},
- {targets: 8, visible: false, type: 'num'}
- ],
- order: [[4, 'asc']],
+ columnDefs,
+ order,
language: Object.assign(dtD.language, {
searchBuilder: {
add: 'Filtrar',
@@ -334,7 +346,7 @@
layout: {
top1: {
searchBuilder: {
- columns: [0, 1, 2, 4, 6, 7, 8]
+ columns: searchBuilderColumns,
}
},
top1End: {
@@ -346,15 +358,30 @@
title: 'Movimientos Contables',
download: 'open',
exportOptions: {
- columns: [0, 1, 2, 3, 5, 6, 8, 9, 10, 11],
+ columns: exportColumns,
format: {
body: (data, row, column, node) => {
- if (column === 3) {
+ if (column === this.columns.map(({title}) => title).indexOf('Fecha')) {
return data.split('-').reverse().join('-')
}
+ if (column === this.columns.map(({title}) => title).indexOf('Valor')) {
+ return data.replace(/\./g, '')
+ }
return data
}
}
+ },
+ customize: xlsx => {
+ const sheet = xlsx.xl.worksheets['sheet1.xml']
+ const columns = Object.values($('row[r="2"] t', sheet).map((idx, column) => column.textContent))
+ const columnStylesMap = {
+ Valor: '63',
+ Fecha: '15'
+ }
+ Object.entries(columnStylesMap).forEach((column, style) => {
+ const columnIndex = String.fromCharCode('A'.charCodeAt(0) + columns.indexOf(column))
+ $(`c[r^="${columnIndex}"]`, sheet).attr('s', style)
+ })
}
}
]
@@ -364,32 +391,117 @@
})
this.props.table = new DataTable(this.props.ids.table, dtD)
}
+ draw() {
+ return {
+ table: (movimientos) => {
+ this.props.table.clear().rows.add(this.draw().movimientos(movimientos)).draw()
+ $(this.props.ids.buttons.edit).on('click', {handler: this.props.eventHandler}, this.props.eventHandler.edit().movimiento)
+ },
+ movimientos: (movimientos) => {
+ const output = []
+ movimientos.forEach(movimiento => {
+ this.draw().movimiento({movimiento, output})
+ })
+ return output
+ },
+ movimiento: ({movimiento, output}) => {
+ const valor = movimiento.abono - movimiento.cargo
+ const fecha = movimiento.fecha
+
+ const data = {
+ Sigla: movimiento.cuenta.inmobiliaria.sigla,
+ Banco: movimiento.cuenta.banco.nombre,
+ Cuenta: movimiento.cuenta.cuenta,
+ Fecha: this.props.formatters.date.format(fecha),
+ 'ISO Fecha': [fecha.getFullYear(), fecha.getMonth() + 1, fecha.getDate()].join('-'),
+ Mes: fecha.getMonth() + 1,
+ 'Año': fecha.getFullYear(),
+ Valor: this.props.formatters.number.format(valor),
+ 'ISO Valor': valor,
+ Glosa: movimiento.glosa,
+ 'Centro de Costo': (movimiento.detalles) ? movimiento.detalles.centro_costo.id : '',
+ Categoria: (movimiento.detalles) ? movimiento.detalles.categoria : '',
+ Detalle: (movimiento.detalles) ? movimiento.detalles.detalle : '',
+ RUT: (movimiento.detalles && movimiento.detalles.digito) ? `${this.props.formatters.number.format(movimiento.detalles.rut)}-${movimiento.detalles.digito}` : '',
+ Nombre: (movimiento.detalles) ? movimiento.detalles.nombres : '',
+ Identificador: (movimiento.detalles) ? movimiento.detalles.identificador : '',
+ Editar: `
`,
+ }
+ const values = []
+ this.columns.forEach(column => {
+ values.push(data[column.title])
+ })
+ output.push(values)
+ }
+ }
+ }
}
class EditModal {
props
+ info
constructor({ids, editForm}) {
this.props = {
ids,
editForm,
movimientos: []
}
+ this.info = [
+ {
+ className: 'sociedad',
+ width: 'three wide',
+ value: movimiento => `
Sociedad: ${movimiento.cuenta.inmobiliaria.sigla}`
+ },
+ {
+ className: 'banco',
+ width: 'three wide',
+ value: movimiento => `
Banco: ${movimiento.cuenta.banco.nombre}`
+ },
+ {
+ className: 'cuenta',
+ width: 'three wide',
+ value: movimiento => `
Cuenta: ${movimiento.cuenta.cuenta}`
+ },
+ {
+ className: 'fecha',
+ width: 'three wide',
+ value: movimiento => `
Fecha: ${movimiento.fecha}`
+ },
+ {
+ className: 'valor',
+ width: 'three wide',
+ value: movimiento => `
Valor: ${movimiento.abono - movimiento.cargo}`
+ },
+ {
+ className: 'glosa',
+ width: 'ten wide',
+ value: movimiento => `
Glosa: ${movimiento.glosa}`
+ },
+ ]
+
+ const $info = $(this.props.ids.modal).find('#modal_info')
+ $info.empty()
+ this.info.forEach(field => {
+ $info.append(`
`)
+ })
+
+ $(this.props.ids.modal).modal({
+ onApprove: $element => {
+ $(this.props.editForm.props.ids.form).submit()
+ }
+ })
}
reset() {
- $(this.props.ids.modal).find('.sociedad').text('')
- $(this.props.ids.modal).find('.banco').text('')
- $(this.props.ids.modal).find('.cuenta').text('')
- $(this.props.ids.modal).find('.fecha').text('')
- $(this.props.ids.modal).find('.valor').text('')
+ this.info.forEach(info => {
+ $(this.props.ids.modal).find(`.${info.className}`).text('')
+ })
this.props.editForm.reset()
}
- show({movimiento, type}) {
+ show({movimiento, index}) {
$(this.props.ids.modal).modal('show')
- $(this.props.ids.modal).find('.sociedad').text('Sociedad: ' + movimiento.cuenta.inmobiliaria.sigla)
- $(this.props.ids.modal).find('.banco').text('Banco: ' + movimiento.cuenta.banco.nombre)
- $(this.props.ids.modal).find('.cuenta').text('Cuenta: ' + movimiento.cuenta.cuenta)
- $(this.props.ids.modal).find('.fecha').text('Fecha: ' + movimiento.fecha)
- $(this.props.ids.modal).find('.valor').text('Valor: ' + (movimiento.abono - movimiento.cargo))
- this.props.editForm.show({modal: $(this.props.ids.modal), movimiento, type})
+ this.info.forEach(info => {
+ $(this.props.ids.modal).find(`.${info.className}`).html(info.value(movimiento))
+ })
+ this.props.editForm.show({modal: $(this.props.ids.modal), movimiento, index})
}
hide() {
$(this.props.ids.modal).modal('hide')
@@ -398,57 +510,98 @@
}
class EditForm {
props
+ fields
constructor({ids}) {
this.props = {
ids,
movimientos: []
}
+ this.fields = [
+ {
+ name: 'index',
+ value: index => index
+ },
+ {
+ name: 'id',
+ value: movimiento => movimiento.id
+ },
+ {
+ id: 'centro_costo',
+ name: 'centro_id',
+ type: 'dropdown',
+ value: movimiento => movimiento.detalles.centro_costo.id ?? '',
+ values: CentrosCostos.get().map(centroCosto => {
+ return {
+ value: centroCosto.id,
+ name: `${centroCosto.id} - ${centroCosto.descripcion}`,
+ text: `${centroCosto.id} - ${centroCosto.descripcion}`,
+ }
+ })
+ },
+ {
+ name: 'rut',
+ type: 'text',
+ value: movimiento => movimiento.detalles.rut ?? ''
+ },
+ {
+ id: 'digito',
+ value: movimiento => movimiento.detalles.digito ?? ''
+ },
+ {
+ name: 'nombre',
+ type: 'text',
+ value: movimiento => movimiento.detalles.nombres ?? ''
+ },
+ {
+ name: 'categoria',
+ type: 'text',
+ value: movimiento => movimiento.detalles.categoria ?? ''
+ },
+ {
+ name: 'detalle',
+ type: 'text',
+ value: movimiento => movimiento.detalles.detalle ?? ''
+ },
+ {
+ name: 'identificador',
+ type: 'text',
+ value: movimiento => movimiento.detalles.identificador ?? ''
+ }
+ ]
+
+ this.fields.filter(field => typeof field.values !== 'undefined').forEach(field => {
+ $(this.props.ids.form).find(`#${field.id}`).dropdown('change values', field.values)
+ })
}
reset() {
$(this.props.ids.form).form('reset')
}
- show({modal, movimiento, type}) {
- if (movimiento.detalles) {
- modal.find('#movimiento_data').show()
- modal.find('#auxiliares').hide()
- modal.find("[name='centro_id']").dropdown('set selected', movimiento.detalles.centro_costo.id)
- modal.find("[name='rut']").val(movimiento.detalles.rut)
- modal.find("#digito").text(Rut.digitoVerificador(movimiento.detalles.rut))
- modal.find("[name='nombre']").val(movimiento.detalles.nombre)
- modal.find("[name='categoria']").val(movimiento.detalles.categoria)
- modal.find("[name='detalle']").val(movimiento.detalles.detalle)
- } else {
- modal.find('#movimiento_data').hide()
- modal.find('#auxiliares').show()
- const tbody = modal.find('#auxiliares tbody')
- tbody.empty()
- movimiento.auxiliares.forEach((auxiliar, i) => {
- tbody.append(`
- |
- |
-
-
-
-
- Centro de Costo
-
-
- |
-
-
- |
- |
- |
- |
- |
-
`)
- })
- }
+ show({modal, movimiento, index}) {
+ modal.find(this.props.ids.data).show()
+
+ this.fields.forEach(field => {
+ if (typeof field.name !== 'undefined') {
+ switch (field.type) {
+ case 'dropdown':
+ modal.find(`#${field.id}`).dropdown('set selected', field.value(movimiento))
+ break
+ default:
+ if (field.name === 'index') {
+ modal.find(`[name='${field.name}']`).val(index)
+ return
+ }
+ modal.find(`[name='${field.name}']`).val(field.value(movimiento))
+ break
+ }
+ return
+ }
+ modal.find(`#${field.id}`).text(field.value(movimiento))
+ })
+ }
+ setup() {
+ $(this.props.ids.form).on('submit', {
+ form_id: this.props.ids.form,
+ }, app.handlers.events.edit().modal)
}
}
class MovimientosHandler {
@@ -490,13 +643,17 @@
}
edit() {
return {
- movimiento: ({id, index, type, data}) => {
- /*this.props.resultsHandler.parse().movimientos()
- this.props.resultsHandler.props.movimientos.forEach((movimiento, i) => {
- if (movimiento.id === id && movimiento.index === index) {
- this.props.editModal.show({id, index, type})
+ movimiento: (data) => {
+ const method = 'post'
+ return APIClient.fetch(this.props.urls.edit, {method, body: data}).then(response => {
+ if (!response) {
+ throw new Error('No se pudo editar el movimiento')
}
- })*/
+ return response.json().then(json => {
+ const movimiento = this.find().id(json.movimiento.id)
+ movimiento.detalles = json.movimiento.detalles
+ })
+ })
}
}
}
@@ -528,22 +685,6 @@
},
movimiento: ({data, movimiento, index}) => {
const fecha = new Date(movimiento.fecha + 'Z' + this.props.timezone)
- if (movimiento.auxiliares.length > 0) {
- movimiento.auxiliares.forEach((auxiliar, indexAuxiliar) => {
- data.push({
- tipo: 'auxiliar',
- id: auxiliar.id,
- index: index * 100000 + indexAuxiliar,
- cuenta: movimiento.cuenta,
- fecha,
- cargo: auxiliar.cargo,
- abono: auxiliar.abono,
- detalles: auxiliar.detalles,
- glosa: movimiento.glosa,
- })
- })
- return
- }
data.push({
tipo: 'movimiento',
id: movimiento.id,
@@ -554,507 +695,35 @@
abono: movimiento.abono,
glosa: movimiento.glosa,
detalles: movimiento.detalles,
- auxiliares: movimiento.auxiliares,
})
}
}
}
}
- /*const editForm = {
- id: '',
- data: {
- index: 0,
- id: 0,
- sociedad: '',
- banco: '',
- fecha: '',
- valor: 0,
- glosa: '',
- },
- fields: {
- centro_costo: '',
- rut: '',
- nombre: '',
- categoria: '',
- detalle: '',
- },
- auxiliares: [],
- show({type, index, id, sociedad, banco, cuenta, fecha, valor, glosa, centro_costo = '', rut = '', nombre = '', categoria = '', detalle = '', auxiliares = []}) {
- this.data = {
- index,
- id,
- sociedad,
- banco,
- cuenta,
- fecha,
- valor,
- glosa,
- }
- this.auxiliares = auxiliares
- $(this.id).find('.sociedad').text('Sociedad: ' + sociedad)
- $(this.id).find('.banco').text('Banco: ' + banco)
- $(this.id).find('.cuenta').text('Cuenta: ' + cuenta)
- $(this.id).find('.fecha').text('Fecha: ' + fecha)
- $(this.id).find('.valor').text('Valor: ' + valor)
- $(this.id).find('.glosa').text('Glosa: ' + glosa)
- if (auxiliares.length > 0) {
- this.auxiliares = auxiliares
- $(this.id).find('#movimiento_data').hide()
- $(this.id).find('#auxiliares').show()
- const tbody = $(this.id).find('#auxiliares tbody')
- tbody.empty()
- auxiliares.forEach((auxiliar, i) => {
- this.draw().auxiliar({auxiliar, i})
- })
- } else {
- $(this.id).find('#movimiento_data').show()
- if (type === 'auxiliar') {
- $(this.id).find('#auxiliares').hide()
- }
- if (centro_costo !== '') {
- $(this.id).find("[name='centro_costo']").dropdown('set selected', centro_costo)
- }
- $(this.id).find("[name='rut']").val(rut)
- $(this.id).find("#digito").text(Rut.digitoVerificador(rut))
- $(this.id).find("[name='nombre']").val(nombre)
- $(this.id).find("[name='categoria']").val(categoria)
- $(this.id).find("[name='detalle']").val(detalle)
- }
- $(this.id).modal('show')
- },
- draw() {
- return {
- auxiliar: ({auxiliar, i}) => {
- const tbody = $(this.id).find('#auxiliares tbody')
- const menu = $('
').addClass('menu')
- CentrosCostos.get().forEach(centroCosto => {
- menu.append(`
${centroCosto.id} - ${centroCosto.descripcion}
`)
- })
- const tr = $('
')
- if (typeof auxiliar !== 'undefined' && auxiliar.includes('cargo')) {
- tr.append(` | `)
- } else {
- tr.append(` | `)
- }
- if (typeof auxiliar !== 'undefined' && auxiliar.includes('abono')) {
- tr.append(` | `)
- } else {
- tr.append(` | `)
- }
- tr.append(
- $('').append($('').addClass('ui selection search dropdown').attr('data-index', i).append(
- ` `
- ).append(
- ` Centro de Costo `
- ).append(menu)
- )
- )
- if (typeof auxiliar !== 'undefined' && auxiliar.includes('detalles') && auxiliar.detalles.includes('rut')) {
- tr.append(`
-
- | `)
- } else {
- tr.append(`
-
- | `)
- }
- if (typeof auxiliar !== 'undefined' && auxiliar.includes('nombre')) {
- tr.append(` | `)
- } else {
- tr.append(` | `)
- }
- if (typeof auxiliar !== 'undefined' && auxiliar.includes('categoria')) {
- tr.append(` | `)
- } else {
- tr.append(` | `)
- }
- if (typeof auxiliar !== 'undefined' && auxiliar.includes('detalle')) {
- tr.append(` | `)
- } else {
- tr.append(` | `)
- }
- tbody.append(tr)
- $(this.id).find(`.dropdown[data-index='${i}']`).dropdown()
- if (typeof auxiliar !== 'undefined' && auxiliar.detalles && auxiliar.detalles.centro_costo && auxiliar.detalles.centro_costo.id) {
- $(this.id).find(`[name='centro_costo${i}']`).val(auxiliar.detalles.centro_costo.id)
- }
- $(this.id).find(`[name='rut${i}']`).on('input', inputEvent => {
- inputEvent.currentTarget.value = Rut.format(inputEvent.currentTarget.value)
- const index = $(inputEvent.currentTarget).data('index')
- $(this.id).find(`.digito[data-index='${index}']`).text(Rut.digitoVerificador($(inputEvent.currentTarget).val()))
- })
- }
- }
- },
- submit() {
- const url = ''
- const method = 'post'
- const body = new FormData()
- const data = this.data
- data.centro_costo = $(this.id).find("[name='centro_costo']").dropdown('get value')
- data.rut = $(this.id).find("[name='rut']").val()
- data.nombre = $(this.id).find("[name='nombre']").val()
- data.categoria = $(this.id).find("[name='categoria']").val()
- data.detalle = $(this.id).find("[name='detalle']").val()
- console.debug(data)
- },
- setup(id) {
- this.id = id
- $(this.id).modal({
- onApprove: $element => {
- this.submit()
- }
- })
- $(this.id).find('#centro_costo').dropdown()
- $(this.id).find("[name='rut']").on('input', inputEvent => {
- $(this.id).find('#digito').text(Rut.digitoVerificador($(inputEvent.currentTarget).val()))
- })
- $(this.id).find('#digito').text(Rut.digitoVerificador($("[name='rut']").val()))
- $(this.id).find('#add_auxiliar').click(clickEvent => {
- const i = this.auxiliares.length + 1
- this.draw().auxiliar({i})
- })
- }
- }*/
- /*const movimientos = {
- ids: {
- form: {
- id: '',
- sociedades: '',
- mes: '',
- },
- table: '',
- },
- movimientos: [],
- table: null,
- amount: null,
- get() {
- return {
- movimientos: () => {
- const sociedades_ruts = $(this.ids.forms.search.sociedades).dropdown('get values')
- const mes = $(this.ids.forms.search.mes).calendar('get date')
-
- const url = '/contabilidad/movimientos/sociedad/mes'
- const method = 'post'
- const body = new FormData()
- sociedades_ruts.forEach(sociedad_rut => {
- body.append('sociedades_ruts[]', sociedad_rut)
- })
- body.set('mes', [mes.getFullYear(), mes.getMonth() + 1, mes.getDate()].join('-'))
- if (this.amount !== null) {
- body.set('amount', this.amount)
- }
- this.movimientos = []
- return fetchAPI(url, {method, body}).then(response => {
- $(this.ids.forms.search.id).removeClass('loading')
- if (!response) {
- return
- }
- response.json().then(json => {
- this.add().movimientos(json.movimientos)
- }).then(() => {
- this.draw().table()
- })
- })
- }
- }
- },
- add() {
- return {
- movimientos: data => {
- if (data.length === 0) {
- return
- }
- const tz = ((new Date()).getTimezoneOffset()) / -60
- data.forEach((movimiento, index) => {
- const fecha = new Date(movimiento.fecha + 'Z' + tz)
- if (movimiento.auxiliares.length > 0) {
- movimiento.auxiliares.forEach((auxiliar, indexAuxiliar) => {
- this.movimientos.push({
- tipo: 'auxiliar',
- id: auxiliar.id,
- index: index * 100 + indexAuxiliar,
- cuenta: movimiento.cuenta,
- fecha,
- cargo: auxiliar.cargo,
- abono: auxiliar.abono,
- detalles: auxiliar.detalles,
- glosa: movimiento.glosa,
- })
- })
- return
- }
- this.movimientos.push({
- tipo: 'movimiento',
- id: movimiento.id,
- index,
- cuenta: movimiento.cuenta,
- fecha,
- cargo: movimiento.cargo,
- abono: movimiento.abono,
- glosa: movimiento.glosa,
- detalles: movimiento.detalles,
- auxiliares: movimiento.auxiliares,
- })
- })
- }
- }
- },
- update() {
- return {
- movimiento: ({index, movimiento}) => {
- const formatter = new Intl.NumberFormat('es-CL')
- const dateFormatter = new Intl.DateTimeFormat('es-CL', {
- day: '2-digit',
- month: '2-digit',
- year: 'numeric'
- })
- const tz = ((new Date()).getTimezoneOffset()) / -60
- const fecha = new Date(movimiento.fecha + 'Z' + tz)
- const valor = movimiento.abono - movimiento.cargo
- this.movimientos[index] = [
- movimiento.cuenta.inmobiliaria.sigla,//0
- movimiento.cuenta.banco.nombre,//1
- movimiento.cuenta.cuenta,//2
- dateFormatter.format(fecha),//3
- [fecha.getFullYear(), fecha.getMonth() + 1, fecha.getDate()].join('-'),//4
- fecha.getMonth() + 1,//5
- fecha.getFullYear(),//6
- formatter.format(valor),//7
- valor,//8
- movimiento.detalles.centro_costo.id,//9
- movimiento.glosa,//10
- movimiento.detalles.detalle,//11
- ' ',//12
- ]
- this.draw().table()
- }
- }
- },
- draw() {
- return {
- table: () => {
- this.table.clear().rows.add(this.draw().movimientos()).draw()
- $(this.ids.buttons.edit).click(clickEvent => {
- const id = $(clickEvent.currentTarget).data('id')
- const index = $(clickEvent.currentTarget).data('index')
- this.draw().edit({id, index})
- })
- },
- movimientos: () => {
- const output = []
- this.movimientos.forEach(movimiento => {
- this.draw().movimiento({movimiento, output})
- })
- return output
- },
- movimiento: ({movimiento, output}) => {
- const formatter = new Intl.NumberFormat('es-CL')
- const dateFormatter = new Intl.DateTimeFormat('es-CL', {
- day: '2-digit',
- month: '2-digit',
- year: 'numeric'
- })
- const valor = movimiento.abono - movimiento.cargo
- const fecha = movimiento.fecha
- output.push([
- movimiento.cuenta.inmobiliaria.sigla,//0
- movimiento.cuenta.banco.nombre,//1
- movimiento.cuenta.cuenta,//2
- dateFormatter.format(fecha),//3
- [fecha.getFullYear(), fecha.getMonth() + 1, fecha.getDate()].join('-'),//4
- fecha.getMonth() + 1,//5
- fecha.getFullYear(),//6
- formatter.format(valor),//7
- valor,//8
- (movimiento.detalles) ? movimiento.detalles.centro_costo.id : '',//9
- movimiento.glosa,//10
- (movimiento.detalles) ? movimiento.detalles.detalle : '',//11
- ' ',//12
- ])
- },
- edit: ({id, index, type}) => {
- const idx = this.movimientos.findIndex(movimiento => movimiento.index === index)
- editForm.show({
- type,
- id,
- index,
- sociedad: this.movimientos[idx].cuenta.inmobiliaria.sigla,
- banco: this.movimientos[idx].cuenta.banco.nombre,
- cuenta: this.movimientos[idx].cuenta.cuenta,
- fecha: this.movimientos[idx].fecha,
- valor: this.movimientos[idx].abono - this.movimientos[idx].cargo,
- glosa: this.movimientos[idx].glosa,
- centro_costo: (this.movimientos[idx].detalles !== null && typeof this.movimientos[idx].detalles.centro_costo) ? this.movimientos[idx].detalles.centro_costo.id : '',
- rut: (this.movimientos[idx].detalles !== null) ? this.movimientos[idx].detalles.rut : '',
- nombre: (this.movimientos[idx].detalles !== null) ? this.movimientos[idx].detalles.nombre : '',
- categoria: (this.movimientos[idx].detalles !== null) ? this.movimientos[idx].detalles.categoria : '',
- detalle: (this.movimientos[idx].detalles !== null) ? this.movimientos[idx].detalles.detalle : '',
- auxiliares: this.movimientos[idx].auxiliares,
- })
- }
- }
- },
- submit(submitEvent) {
- submitEvent.preventDefault()
- $(submitEvent.currentTarget).addClass('loading')
- movimientos.get().movimientos()
- return false
- },
- edit() {
- const body = new FormData(document.getElementById('movimientos_edit'))
- const id = body.get('id')
- const index = body.get('index')
- body.delete('id')
- body.delete('index')
- const url = '/contabilidad/movimiento/' + id + '/detalles'
- const method = 'post'
- return fetchAPI(url, {method, body}).then(response => {
- if (!response) {
- return
- }
- return response.json().then(json => {
- this.update().movimiento({index, movimiento: json.movimiento})
- })
- })
- },
- setup(ids) {
- this.ids = ids
-
- $(this.ids.forms.search.sociedades).dropdown()
-
- const cdo = structuredClone(calendar_date_options)
- cdo['type'] = 'month'
- cdo['maxDate'] = new Date()
- $(this.ids.forms.search.mes).calendar(cdo)
-
- $(this.ids.forms.search.id).submit(this.submit)
-
- let dtD = structuredClone(datatables_defaults)
- dtD = Object.assign(dtD, {
- columnDefs: [
- {targets: [0, 5, 9, 12], width: '5%', type: 'string'},
- {targets: [1, 2, 3, 6, 10], width: '10%', type: 'string'},
- {targets: [11], width: '20%', type: 'string'},
- {targets: 4, visible: false},
- {targets: 7, className: 'dt-right', width: '10%'},
- {targets: 8, visible: false, type: 'num'}
- ],
- order: [[4, 'asc']],
- language: Object.assign(dtD.language, {
- searchBuilder: {
- add: 'Filtrar',
- condition: 'Comparador',
- clearAll: 'Resetear',
- delete: 'Eliminar',
- deleteTitle: 'Eliminar Titulo',
- data: 'Columna',
- left: 'Izquierda',
- leftTitle: 'Titulo Izquierdo',
- logicAnd: 'Y',
- logicOr: 'O',
- right: 'Derecha',
- rightTitle: 'Titulo Derecho',
- title: {
- 0: 'Filtros',
- _: 'Filtros (%d)'
- },
- value: 'Opciones',
- valueJoiner: 'y'
- }
- }),
- layout: {
- top1: {
- searchBuilder: {
- columns: [0, 1, 2, 4, 6, 7, 8]
- }
- },
- top1End: {
- buttons: [
- {
- extend: 'excelHtml5',
- className: 'green',
- text: 'Exportar a Excel ',
- title: 'Movimientos Contables',
- download: 'open',
- exportOptions: {
- columns: [0, 1, 2, 3, 5, 6, 8, 9, 10, 11],
- format: {
- body: (data, row, column, node) => {
- if (column === 3) {
- return data.split('-').reverse().join('-')
- }
- return data
- }
- }
- }
- }
- ]
- }
- },
- data: this.movimientos,
- })
- this.table = new DataTable(this.ids.table, dtD)
-
- /!*$(this.ids.modals.edit).modal({
- onApprove: $element => {
- this.edit()
- }
- })*!/
- editForm.setup(this.ids.modals.edit)
- //$('#' + this.ids.forms.edit.id).find('#centro_costo').dropdown()
- }
- }*/
-
const app = {
handlers: {},
setup() {
this.handlers.results = new ResultsHandler()
this.handlers.loading = new LoadingHandler({id: '#movimientos_form'})
- this.handlers.movimientos = new MovimientosHandler({urls: {get: '{{$urls->api}}/contabilidad/movimientos/sociedad/mes', edit: '{{$urls->api}}/contabilidad/movimientos/edit'}, loadingHandler: this.handlers.loading, resultsHandler: this.handlers.results})
- this.handlers.forms = {}
- this.handlers.forms.edit = new EditForm({ids: {modal: '#movimientos_modal', form: '#movimientos_edit',}})
- this.handlers.modals = {}
- this.handlers.modals.edit = new EditModal({ids: {modal: '#movimientos_modal'}, editForm: this.handlers.forms.edit})
+ this.handlers.movimientos = new MovimientosHandler({urls: {
+ get: '{{$urls->api}}/contabilidad/movimientos/sociedad/mes',
+ edit: '{{$urls->api}}/contabilidad/movimientos/edit'}, loadingHandler: this.handlers.loading, resultsHandler: this.handlers.results})
+ this.handlers.forms = {
+ edit: new EditForm({ids: {modal: '#movimientos_modal', data: '#movimientos_data', form: '#movimientos_edit',}})
+ }
+ this.handlers.modals = {
+ edit: new EditModal({ids: {modal: '#movimientos_modal'}, editForm: this.handlers.forms.edit})
+ }
this.handlers.events = new EventHandler({movimientosHandler: this.handlers.movimientos, modalHandler: this.handlers.modals.edit})
this.handlers.table = new MovimientosTable({ids: {table: '#tabla_movimientos', buttons: {edit: '.edit_button'}}, eventHandler: this.handlers.events})
- this.handlers.forms.control = new ControlForm({
- ids: {form: '#movimientos_form', sociedades: '#sociedades', mes: '#mes',},
- })
- this.handlers.table.setup()
- this.handlers.forms.control.setup()
+ this.handlers.forms.control = new ControlForm({ids: {form: '#movimientos_form', sociedades: '#sociedades', mes: '#mes',},})
+
+ this.handlers.forms.edit.setup()
}
}
$(document).ready(() => {
app.setup()
- /*movimientos.setup({
- forms: {
- search: {
- id: '#movimientos_form',
- sociedades: '#sociedades',
- mes: '#mes',
- },
- edit: {
- id: 'movimientos_edit',
- }
- },
- table: '#tabla_movimientos',
- modals: {
- edit: '#movimientos_modal'
- },
- buttons: {
- edit: '.edit_button'
- }
- })*/
})
@endpush
diff --git a/app/resources/views/layout/body/scripts.blade.php b/app/resources/views/layout/body/scripts.blade.php
index 2e721d9..949e6c7 100644
--- a/app/resources/views/layout/body/scripts.blade.php
+++ b/app/resources/views/layout/body/scripts.blade.php
@@ -3,11 +3,11 @@
|