Movimiento + Detalles

This commit is contained in:
Juan Pablo Vial
2024-03-04 19:55:49 -03:00
parent 48bfe5d8ab
commit c7dd309185
11 changed files with 334 additions and 52 deletions

View File

@ -52,6 +52,8 @@
<th class="right aligned">Cargo</th>
<th class="right aligned">Abono</th>
<th class="right aligned">Saldo</th>
<th>Centro de Costo</th>
<th>Detalle</th>
<th>Orden</th>
</tr>
</thead>
@ -185,6 +187,46 @@
}
}
}
update() {
return {
centro: (idx, centro_id) => {
const id = this.movimientos[idx].id
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
const body = new FormData()
body.set('centro_id', centro_id)
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (!json.status) {
return
}
const dropdown = $(".dropdown[data-idx='" + idx + "']")
dropdown.dropdown('set selected', json.centro.id, true)
})
})
},
detalle: (idx, detalle) => {
const id = this.movimientos[idx].id
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
const body = new FormData()
body.set('detalle', detalle)
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (!json.status) {
return
}
const input = $("input[data-idx='" + idx + "']")
input.val(json.detalle)
})
})
}
}
}
draw() {
return {
form: ($form, inmobiliarias, first = false) => {
@ -339,25 +381,73 @@
this.movimientos.forEach((row, idx) => {
$tbody.append(
$('<tr></tr>').append(
$('<td></td>').html(this.inmobiliaria.razon)
'<td>' + this.inmobiliaria.razon + '</td>' + "\n"
+ '<td>' + this.cuenta.descripcion + '</td>' + "\n"
+ '<td>' + dateFormatter.format(row.fecha) + '</td>' + "\n"
+ '<td>' + row.glosa + '</td>' + "\n"
+ '<td class="right aligned">' + (row.cargo === 0 ? '' : numberFormatter.format(row.cargo)) + '</td>' + "\n"
+ '<td class="right aligned">' + (row.abono === 0 ? '' : numberFormatter.format(row.abono)) + '</td>' + "\n"
+ '<td class="right aligned">' + (row.saldo === 0 ? '' : numberFormatter.format(row.saldo)) + '</td>' + "\n"
).append(
$('<td></td>').html(this.cuenta.descripcion)
$('<td></td>').append(
this.draw().centroCosto(idx)
)
).append(
$('<td></td>').html(dateFormatter.format(row.fecha))
).append(
$('<td></td>').html(row.glosa)
).append(
$('<td></td>').addClass('right aligned').html(row.cargo === 0 ? '' : numberFormatter.format(row.cargo))
).append(
$('<td></td>').addClass('right aligned').html(row.abono === 0 ? '' : numberFormatter.format(row.abono))
).append(
$('<td></td>').addClass('right aligned').html(row.saldo === 0 ? '' : numberFormatter.format(row.saldo))
$('<td></td>').append(
this.draw().detalle(idx)
)
).append(
$('<td></td>').html(idx + 1)
)
)
})
},
centroCosto: idx => {
const centros = JSON.parse('{!! json_encode($centrosCostos) !!}')
const menu = $('<div></div>').addClass('menu')
centros.forEach(centro => {
menu.append(
'<div class="item" data-value="' + centro.id + '">'
+ centro.id + ' - ' + centro.descripcion
+ '</div>'
)
})
const dropdown = $('<div></div>').addClass('ui search selection dropdown').attr('data-idx', idx).html(
'<input type="hidden" name="centro" />' + "\n" +
'<i class="dropdown icon"></i>' + "\n" +
'<div class="default text">Centro de Costo</div>' + "\n"
).append(menu)
dropdown.dropdown({
onChange: (value, text, $element) => {
const idx = $element.parent().parent().data('idx')
this.update().centro(idx, value)
}
})
if (this.movimientos[idx].centro !== '') {
const cid = centros.findIndex(centro => centro.descripcion === this.movimientos[idx].centro)
dropdown.dropdown('set selected', centros[cid].id, true)
}
return dropdown
},
detalle: idx => {
const detalle = document.createElement('input')
detalle.type = 'text'
detalle.name = 'detalle' + idx
detalle.placeholder = 'Detalle'
detalle.setAttribute('data-idx', idx)
const input = document.createElement('div')
input.className = 'ui input'
input.appendChild(detalle)
if (this.movimientos[idx].detalle !== '') {
detalle.value = this.movimientos[idx].detalle
}
detalle.addEventListener('blur', event => {
const idx = event.currentTarget.dataset['idx']
this.update().detalle(idx, event.currentTarget.value)
})
return $(input)
}
}
}
}
@ -370,6 +460,8 @@
'cargo',
'abono',
'saldo',
'centro',
'detalle',
'orden'
];
@endphp
@ -388,7 +480,7 @@
width: '{{round((1/(count($columns) + 3 - 1)) * 100,2)}}%'
},
{
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['sociedad', 'cuenta', 'glosa']);})))}}],
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['sociedad', 'cuenta', 'glosa', 'centro', 'detalle']);})))}}],
width: '{{round((1/(count($columns) + 3 - 1)) * 2 * 100, 2)}}%'
},
{
@ -506,12 +598,15 @@
const fecha = new Date(row.fecha)
fecha.setDate(fecha.getDate() + 1)
this.data.cartolas[cartolaIdx].movimientos[idx] = {
id: row.id,
fecha: fecha,
glosa: row.glosa,
documento: row.documento,
cargo: row.cargo,
abono: row.abono,
saldo: row.saldo
saldo: row.saldo,
centro: row.detalles?.centro_costo.descripcion ?? '',
detalle: row.detalles?.detalle ?? ''
}
})
const ayer = new Date(this.data.cartolas[cartolaIdx].fecha.getTime())
@ -629,41 +724,31 @@
movimiento: idx => {
$(this.ids.movimientos).append(
$('<div></div>').addClass('fields').attr('data-movimiento', idx).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Glosa')
).append(
$('<input />').attr('type', 'text').attr('name', 'glosa' + idx)
)
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Cargo')
).append(
$('<div></div>').addClass('ui left labeled input').append(
$('<div></div>').addClass('ui basic label').html('$')
).append(
$('<input />').attr('type', 'text').attr('name', 'cargo' + idx)
)
)
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Abono')
).append(
$('<div></div>').addClass('ui left labeled input').append(
$('<div></div>').addClass('ui basic label').html('$')
).append(
$('<input />').attr('type', 'text').attr('name', 'abono' + idx)
)
)
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Saldo')
).append(
$('<div></div>').addClass('ui left labeled input').append(
$('<div></div>').addClass('ui basic label').html('$')
).append(
$('<input />').attr('type', 'text').attr('name', 'saldo' + idx)
)
)
'<div class="field">' + "\n"
+ '<label>Glosa</label>' + "\n"
+ '<input type="text" name="glosa' + idx + '" />' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Cargo</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="cargo' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Abono</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="abono' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Saldo</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="saldo' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>'
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Eliminar')