881 lines
42 KiB
PHP
881 lines
42 KiB
PHP
@extends('layout.base')
|
|
|
|
@section('page_content')
|
|
<div class="ui container">
|
|
<h1 class="ui header">
|
|
Cartola Diaria
|
|
</h1>
|
|
<div class="ui grid">
|
|
<div class="right aligned sixteen wide column">
|
|
<button class="ui green icon button" id="add_button">
|
|
Agregar
|
|
<i class="plus icon"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<form class="ui form" id="cartola_form">
|
|
<input type="hidden" id="fields" name="fields" value="0" />
|
|
</form>
|
|
<div class="ui two columns grid">
|
|
<div class="column">
|
|
<button class="ui icon button" id="process_button">
|
|
<i class="file excel icon"></i>
|
|
Procesar
|
|
</button>
|
|
</div>
|
|
<div class="right aligned column">
|
|
<div class="ui inline active loader" id="loader"></div>
|
|
</div>
|
|
</div>
|
|
<table class="ui table" id="diferencia">
|
|
<thead>
|
|
<tr>
|
|
<th>Sociedad</th>
|
|
<th>Banco - Cuenta</th>
|
|
<th>Hoy</th>
|
|
<th>Último Saldo</th>
|
|
<th>Saldo Actual</th>
|
|
<th>Diferencia</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</div>
|
|
<div class="ui fluid container">
|
|
<table class="ui table" id="tabla_movimientos">
|
|
<thead>
|
|
<tr>
|
|
<th>Sociedad</th>
|
|
<th>Banco - Cuenta</th>
|
|
<th>Fecha</th>
|
|
<th>Glosa</th>
|
|
<th class="right aligned">Cargo</th>
|
|
<th class="right aligned">Abono</th>
|
|
<th class="right aligned">Saldo</th>
|
|
<th class="right aligned"></th>
|
|
<th>Orden</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="movimientos"></tbody>
|
|
</table>
|
|
</div>
|
|
<div class="ui modal" id="manual_modal">
|
|
<div class="content">
|
|
<div class="header">
|
|
Movimientos |
|
|
<span id="modal_inmobiliaria"></span> |
|
|
<span id="modal_cuenta"></span> |
|
|
<span id="modal_fecha"></span>
|
|
</div>
|
|
<div class="ui one column grid">
|
|
<div class="right aligned column">
|
|
<button class="ui green icon button" id="add_manual">
|
|
<i class="plus icon"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<form class="ui form" id="modal_form">
|
|
<input type="hidden" name="movimientos" value="[1]" />
|
|
<div id="modal_movimientos">
|
|
<div class="fields" data-movimiento="1">
|
|
<div class="field">
|
|
<label>Glosa</label>
|
|
<input type="text" name="glosa1" />
|
|
</div>
|
|
<div class="field">
|
|
<label>Cargo</label>
|
|
<div class="ui left labeled input">
|
|
<div class="ui basic label">$</div>
|
|
<input type="text" name="cargo1" />
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label>Abono</label>
|
|
<div class="ui left labeled input">
|
|
<div class="ui basic label">$</div>
|
|
<input type="text" name="abono1" />
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label>Saldo</label>
|
|
<div class="ui left labeled input">
|
|
<div class="ui basic label">$</div>
|
|
<input type="text" name="saldo1" />
|
|
</div>
|
|
</div>
|
|
<div class="field"></div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<div class="actions">
|
|
<button class="ui approve button">
|
|
Procesar
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="ui modal" id="edit_modal" data-cartola="">
|
|
<div class="header">
|
|
Movimiento
|
|
<div class="meta">
|
|
<span id="edit_inmobiliaria"></span> |
|
|
<span id="edit_cuenta"></span> |
|
|
<span id="edit_fecha"></span> |
|
|
<span id="edit_glosa"></span> |
|
|
<span id="edit_cargo"></span> |
|
|
<span id="edit_abono"></span> |
|
|
<span id="edit_saldo"></span>
|
|
</div>
|
|
</div>
|
|
<div class="content">
|
|
<form class="ui form" id="edit_form">
|
|
<input type="hidden" name="movimiento_id" value="" />
|
|
<div class="equal width fields">
|
|
<div class="field">
|
|
<label>Centro de Costo</label>
|
|
<div class="ui search selection dropdown">
|
|
<input type="hidden" name="centro_costo_id" />
|
|
<i class="dropdown icon"></i>
|
|
<div class="default text">Centro de Costo</div>
|
|
<div class="menu">
|
|
@foreach($centrosCostos as $centro)
|
|
<div class="item" data-value="{{$centro->id}}">
|
|
{{$centro->id}} - {{$centro->descripcion}}
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label>Categoría</label>
|
|
<div class="ui input">
|
|
<input type="text" name="categoria" />
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label>Detalle</label>
|
|
<div class="ui input">
|
|
<input type="text" name="detalle" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="equal width fields">
|
|
<div class="field">
|
|
<label>RUT</label>
|
|
<div class="ui right labeled input">
|
|
<input type="text" name="rut" />
|
|
<div class="ui basic label">-<span id="digito"></span></div>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label>Nombres</label>
|
|
<div class="ui input">
|
|
<input type="text" name="nombres" />
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label>Identificador</label>
|
|
<div class="ui input">
|
|
<input type="text" name="identificador" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="actions">
|
|
<button class="ui approve button">
|
|
Editar
|
|
</button>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@include('layout.head.styles.datatables')
|
|
@include('layout.body.scripts.datatables')
|
|
@include('layout.body.scripts.rut')
|
|
|
|
@push('page_scripts')
|
|
<script>
|
|
class Cartola {
|
|
idx
|
|
inmobiliaria = {
|
|
rut: 0,
|
|
razon: '',
|
|
sigla: ''
|
|
}
|
|
cuenta = {
|
|
id: 0,
|
|
descripcion: ''
|
|
}
|
|
fecha = ''
|
|
bancos = []
|
|
movimientos = []
|
|
saldo = 0
|
|
ayer = 0
|
|
|
|
constructor(idx) {
|
|
this.idx = idx
|
|
}
|
|
|
|
get() {
|
|
return {
|
|
bancos: () => {
|
|
const url = '{{$urls->api}}/inmobiliaria/' + this.inmobiliaria.rut + '/cuentas'
|
|
diaria.loader().show()
|
|
return fetchAPI(url).then(response => {
|
|
diaria.loader().hide()
|
|
if (!response) {
|
|
this.bancos = []
|
|
return
|
|
}
|
|
return response.json().then(json => {
|
|
if (json.cuentas.length === 0) {
|
|
this.bancos = []
|
|
return
|
|
}
|
|
this.bancos = json.cuentas.map(cuenta => {
|
|
return {
|
|
value: cuenta.id,
|
|
text: cuenta.banco.nombre + ' - ' + cuenta.cuenta,
|
|
name: cuenta.banco.nombre + ' - ' + cuenta.cuenta
|
|
}
|
|
})
|
|
})
|
|
})
|
|
},
|
|
ayer: (fecha) => {
|
|
const url = '{{$urls->api}}/contabilidad/cartola/diaria/ayer'
|
|
const body = new FormData()
|
|
body.set('cuenta_id', this.cuenta.id)
|
|
body.set('fecha', fecha.toISOString())
|
|
return fetchAPI(url, {method: 'post', body}).then(response => {
|
|
if (!response) {
|
|
return
|
|
}
|
|
return response.json().then(json => {
|
|
if (json.cartola.length === 0) {
|
|
return
|
|
}
|
|
this.ayer = json.cartola.saldo
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
draw() {
|
|
return {
|
|
form: ($form, inmobiliarias, first = false) => {
|
|
const $fields = $('<div></div>').addClass('fields cartola').attr('data-cartola', this.idx)
|
|
const $inmobiliarias_menu = $('<div></div>').addClass('menu')
|
|
inmobiliarias.forEach(inmobiliaria => {
|
|
$inmobiliarias_menu.append(
|
|
$('<div></div>').addClass('item').attr('data-value', inmobiliaria.rut).html(inmobiliaria.razon)
|
|
)
|
|
})
|
|
const $inmobiliarias_dropdown = $('<div></div>').addClass('ui search selection dropdown').attr('id', 'inmobiliaria' + this.idx).append(
|
|
$('<input />').attr('type', 'hidden')//.attr('name', 'inmobiliaria_rut' + this.idx)
|
|
).append(
|
|
$('<i></i>').addClass('dropdown icon')
|
|
).append(
|
|
$('<div></div>').addClass('default text').html('Inmobiliaria')
|
|
).append($inmobiliarias_menu)
|
|
$fields.append(
|
|
$('<div></div>').addClass('six wide field').append(
|
|
$('<label></label>').attr('for', 'inmobiliaria' + this.idx).html('Sociedad')
|
|
).append($inmobiliarias_dropdown)
|
|
)
|
|
const $cuentas_dropdown = $('<div></div>').addClass('ui search selection dropdown').attr('id', 'cuenta' + this.idx).append(
|
|
$('<input />').attr('type', 'hidden').attr('name', 'cuenta_id' + this.idx)
|
|
).append(
|
|
$('<i></i>').addClass('dropdown icon')
|
|
).append(
|
|
$('<div></div>').addClass('default text').html('Banco - Cuenta')
|
|
).append(
|
|
$('<div></div>').addClass('menu')
|
|
)
|
|
$fields.append(
|
|
$('<div></div>').addClass('four wide field').append(
|
|
$('<label></label>').html('Banco - Cuenta')
|
|
).append($cuentas_dropdown)
|
|
)
|
|
const $fecha_calendar = $('<div></div>').addClass('ui calendar').attr('id', 'fecha' + this.idx).append(
|
|
$('<div></div>').addClass('ui left icon input').append(
|
|
$('<i></i>').addClass('calendar icon')
|
|
).append(
|
|
$('<input />').attr('type', 'text')
|
|
)
|
|
)
|
|
$fields.append(
|
|
$('<div></div>').addClass('three wide field').append(
|
|
$('<label></label>').attr('for', 'fecha' + this.idx).html('Fecha')
|
|
).append($fecha_calendar)
|
|
)
|
|
$fields.append(
|
|
$('<div></div>').addClass('field').append(
|
|
$('<label></label>').html('Cartola')
|
|
).append(
|
|
$('<input />').addClass('ui invisible file input').attr('type', 'file').attr('name', 'file' + this.idx).attr('id', 'file' + this.idx)
|
|
).append(
|
|
$('<label></label>').addClass('ui icon button').attr('for', 'file' + this.idx).append(
|
|
$('<i></i>').addClass('file icon')
|
|
).append('Cargar')
|
|
)
|
|
)
|
|
const $manual_checkbox = $('<div></div>').addClass('ui invisible checkbox').append(
|
|
$('<input />').attr('type', 'checkbox').attr('name', 'manual' + this.idx).attr('id', 'manual' + this.idx)
|
|
).append(
|
|
$('<label></label>').addClass('image').attr('for', 'manual' + this.idx).append(
|
|
$('<i></i>').addClass('large orange keyboard icon')
|
|
)
|
|
)
|
|
|
|
$fields.append($('<div></div>').addClass('field').append(
|
|
$('<label></label>').html('Manual')
|
|
).append($manual_checkbox))
|
|
if (!first) {
|
|
$fields.append(
|
|
$('<div></div>').addClass('field').append(
|
|
$('<label></label>').html('Eliminar')
|
|
).append(
|
|
$('<button></button>').addClass('ui red icon button').attr('data-cartola', this.idx).append(
|
|
$('<i></i>').addClass('remove icon')
|
|
).click(event => {
|
|
const idx = $(event.currentTarget).data('cartola')
|
|
diaria.cartolas().remove(idx)
|
|
})
|
|
)
|
|
)
|
|
}
|
|
$form.append($fields)
|
|
|
|
const cdo = JSON.parse(JSON.stringify(calendar_date_options))
|
|
cdo['initialDate'] = new Date()
|
|
cdo['maxDate'] = cdo['initialDate']
|
|
cdo['onChange'] = (date, text, mode) => {
|
|
this.fecha = date
|
|
}
|
|
this.fecha = cdo['initialDate']
|
|
|
|
$inmobiliarias_dropdown.dropdown({
|
|
fireOnInit: true,
|
|
onChange: (value, text, $choice) => {
|
|
this.inmobiliaria.rut = value
|
|
this.inmobiliaria.razon = text
|
|
const inmobiliaria = diaria.data.inmobiliarias.find(inmobiliaria => inmobiliaria.rut === parseInt(value))
|
|
if (typeof inmobiliaria !== 'undefined') {
|
|
this.inmobiliaria.sigla = inmobiliaria.sigla
|
|
}
|
|
this.get().bancos(value).then(() => {
|
|
$cuentas_dropdown.dropdown('change values', this.bancos)
|
|
})
|
|
},
|
|
})
|
|
$cuentas_dropdown.dropdown({
|
|
fireOnInit: true,
|
|
onChange: (value, text, $choice) => {
|
|
this.cuenta.id = value
|
|
this.cuenta.descripcion = text
|
|
}
|
|
})
|
|
$fecha_calendar.calendar(cdo)
|
|
$manual_checkbox.change(event => {
|
|
const $element = $(event.currentTarget)
|
|
const status = $element.checkbox('is checked')
|
|
const $field = $element.parent().parent()
|
|
const $file = $field.find('#file' + this.idx).parent()
|
|
if (status) {
|
|
$file.find('input').attr('type', 'hidden')
|
|
$file.hide()
|
|
|
|
manual.data.inmobiliaria = $inmobiliarias_dropdown.dropdown('get text')
|
|
manual.data.cuenta = $cuentas_dropdown.dropdown('get text')
|
|
const fecha = $fecha_calendar.calendar('get date')
|
|
manual.data.fecha = [fecha.getDate(), (fecha.getMonth()+1).toString().padStart(2, '0'), fecha.getFullYear()].join('-')
|
|
manual.data.field = this.idx
|
|
manual.$modal.modal('show')
|
|
return
|
|
}
|
|
$file.find('input').attr('type', 'file')
|
|
$file.show()
|
|
})
|
|
},
|
|
diferencia: ($tbody, dateFormatter, numberFormatter) => {
|
|
$tbody.append(
|
|
$('<tr></tr>').append(
|
|
$('<td></td>').html(this.inmobiliaria.razon)
|
|
).append(
|
|
$('<td></td>').html(this.cuenta.descripcion)
|
|
).append(
|
|
$('<td></td>').html(dateFormatter.format(this.fecha))
|
|
).append(
|
|
$('<td></td>').html(numberFormatter.format(this.ayer))
|
|
).append(
|
|
$('<td></td>').html(numberFormatter.format(this.saldo))
|
|
).append(
|
|
$('<td></td>').html(numberFormatter.format(this.saldo - this.ayer))
|
|
)
|
|
)
|
|
},
|
|
cartola: ($tbody, dateFormatter, numberFormatter) => {
|
|
this.movimientos.forEach((row, idx) => {
|
|
$tbody.append(
|
|
[
|
|
'<tr>',
|
|
`<td>${this.inmobiliaria.sigla ?? this.inmobiliaria.razon}</td>`,
|
|
`<td>${this.cuenta.descripcion}</td>`,
|
|
`<td>${dateFormatter.format(row.fecha)}</td>`,
|
|
`<td>${row.glosa}</td>`,
|
|
`<td class="right aligned">${row.cargo === 0 ? '' : numberFormatter.format(row.cargo)}</td>`,
|
|
`<td class="right aligned">${row.abono === 0 ? '' : numberFormatter.format(row.abono)}</td>`,
|
|
`<td class="right aligned">${row.saldo === 0 ? '' : numberFormatter.format(row.saldo)}</td>`,
|
|
'<td class="center aligned">',
|
|
`<button class="ui icon button edit_movimiento" data-movimiento="${idx}">`,
|
|
'<i class="edit icon"></i>',
|
|
'</button>',
|
|
'</td>',
|
|
`<td>${(idx + 1).toString()}</td>`,
|
|
].join("\n")
|
|
)
|
|
})
|
|
Array.from(document.getElementsByClassName('edit_movimiento')).forEach(button => {
|
|
button.addEventListener('click', function(clickEvent) {
|
|
const idx = clickEvent.currentTarget.dataset['movimiento']
|
|
const movimiento = this.movimientos[idx]
|
|
const $modal = $('#edit_modal')
|
|
$modal.attr('data-cartola', this.idx)
|
|
$modal.find('#edit_inmobiliaria').html(this.inmobiliaria.razon)
|
|
$modal.find('#edit_cuenta').html(this.cuenta.descripcion)
|
|
$modal.find('#edit_fecha').html(dateFormatter.format(movimiento.fecha))
|
|
$modal.find('#edit_glosa').html(movimiento.glosa)
|
|
$modal.find('#edit_cargo').html(numberFormatter.format(movimiento.cargo))
|
|
$modal.find('#edit_abono').html(numberFormatter.format(movimiento.abono))
|
|
$modal.find('#edit_saldo').html(numberFormatter.format(movimiento.saldo))
|
|
$modal.find('input[name="movimiento_id"]').val(movimiento.id)
|
|
$modal.modal('show')
|
|
}.bind(this))
|
|
})
|
|
},
|
|
}
|
|
}
|
|
}
|
|
@php
|
|
$columns = [
|
|
'sociedad',
|
|
'cuenta',
|
|
'fecha',
|
|
'glosa',
|
|
'cargo',
|
|
'abono',
|
|
'saldo',
|
|
'edit',
|
|
'orden'
|
|
];
|
|
@endphp
|
|
const diaria = {
|
|
ids: {},
|
|
data: {
|
|
inmobiliarias: JSON.parse('{!! json_encode($inmobiliarias) !!}'),
|
|
cartolasIdx: [],
|
|
cartolas: [],
|
|
movimientos: [],
|
|
},
|
|
dataTableConfig: {
|
|
order: [[{{array_search('orden', $columns)}}, 'asc']],
|
|
columnDefs: [
|
|
{
|
|
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['fecha', 'cargo', 'abono', 'saldo', 'edit']);})))}}],
|
|
width: '{{round((1/(count($columns) + 2)) * 100, 2)}}%'
|
|
},
|
|
{
|
|
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['sociedad', 'cuenta', 'glosa']);})))}}],
|
|
width: '{{round((1/(count($columns) + 2)) * 2 * 100, 2)}}%'
|
|
},
|
|
{
|
|
targets: [{{array_search('orden', $columns)}}],
|
|
visible: false
|
|
}
|
|
],
|
|
},
|
|
loaderStatus: true,
|
|
loader() {
|
|
return {
|
|
show: () => {
|
|
if (!this.loaderStatus) {
|
|
$(this.ids.loader).show()
|
|
this.loaderStatus = true
|
|
}
|
|
},
|
|
hide: () => {
|
|
if (this.loaderStatus) {
|
|
$(this.ids.loader).hide()
|
|
this.loaderStatus = false
|
|
}
|
|
}
|
|
}
|
|
},
|
|
cartolas() {
|
|
return {
|
|
add: () => {
|
|
let first = false
|
|
if (this.data.cartolas.length === 0) {
|
|
first = true
|
|
}
|
|
const idx = this.data.cartolas.reduce((prev, cartola) => Math.max(prev, cartola.idx), 0) + 1
|
|
const cartola = new Cartola(idx)
|
|
this.data.cartolas.push(cartola)
|
|
this.data.cartolasIdx.push(idx)
|
|
const form = $(this.ids.form)
|
|
cartola.draw().form(form, this.data.inmobiliarias, first)
|
|
$(this.ids.fields).attr('value', JSON.stringify(this.data.cartolasIdx))
|
|
},
|
|
remove: idx => {
|
|
if (this.data.cartolas.length === 1) {
|
|
return
|
|
}
|
|
const i = this.data.cartolasIdx.findIndex(value => value === idx)
|
|
const cartolaIdx = this.data.cartolas.findIndex(cartola => cartola.idx === idx)
|
|
$("div.cartola[data-cartola='" + idx + "']").remove()
|
|
this.data.cartolasIdx.splice(i,1)
|
|
this.data.cartolas.splice(cartolaIdx,1)
|
|
$(this.ids.fields).attr('value', JSON.stringify(this.data.cartolasIdx))
|
|
}
|
|
}
|
|
},
|
|
draw() {
|
|
return {
|
|
empty: () => {
|
|
Object.values(this.ids.table).forEach(id => $(id).find('tbody').html(''))
|
|
},
|
|
diferencia: () => {
|
|
const $table = $(this.ids.table.diferencia)
|
|
const $tbody = $table.find('tbody')
|
|
$tbody.html('')
|
|
const dateFormatter = new Intl.DateTimeFormat('es-CL', {
|
|
year: 'numeric',
|
|
month: 'numeric',
|
|
day: 'numeric'
|
|
})
|
|
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
|
|
this.data.cartolas.forEach(cartola => {
|
|
cartola.draw().diferencia($tbody, dateFormatter, numberFormatter)
|
|
})
|
|
},
|
|
cartola: () => {
|
|
const $table = $(this.ids.table.base)
|
|
$table.DataTable().clear()
|
|
$table.DataTable().destroy()
|
|
const $tbody = $(this.ids.table.body)
|
|
$tbody.html('')
|
|
const dateFormatter = new Intl.DateTimeFormat('es-CL', {
|
|
year: 'numeric',
|
|
month: 'numeric',
|
|
day: 'numeric'
|
|
})
|
|
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
|
|
this.data.cartolas.forEach(cartola => {
|
|
cartola.draw().cartola($tbody, dateFormatter, numberFormatter)
|
|
})
|
|
$table.DataTable(this.dataTableConfig)
|
|
},
|
|
}
|
|
},
|
|
parse() {
|
|
return {
|
|
cartola: event => {
|
|
const body = new FormData($(this.ids.form)[0])
|
|
this.data.cartolas.forEach(cartola => {
|
|
body.set('fecha' + cartola.idx, [cartola.fecha.getFullYear(), cartola.fecha.getMonth()+1, cartola.fecha.getDate()].join('-'))
|
|
})
|
|
const url = '{{$urls->api}}/contabilidad/cartola/diaria/procesar'
|
|
diaria.loader().show()
|
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
|
diaria.loader().hide()
|
|
this.draw().empty()
|
|
if (!response) {
|
|
return
|
|
}
|
|
return response.json().then(json => {
|
|
if (json.cartolas.length === 0) {
|
|
return
|
|
}
|
|
Object.entries(json.cartolas).forEach(entry => {
|
|
const cartolaIdx = this.data.cartolas.findIndex(cartola => cartola.idx === parseInt(entry[0]))
|
|
this.data.cartolas[cartolaIdx].movimientos = []
|
|
entry[1].movimientos.forEach((row, idx) => {
|
|
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,
|
|
centro: row.detalles?.centro_costo?.id ?? '',
|
|
detalle: row.detalles?.detalle ?? '',
|
|
categoria: row.detalles?.categoria ?? '',
|
|
rut: row.detalles?.rut ?? '',
|
|
nombres: row.detalles?.nombres ?? '',
|
|
identificador: row.detalles?.identificador ?? ''
|
|
}
|
|
})
|
|
const ayer = new Date(this.data.cartolas[cartolaIdx].fecha.getTime())
|
|
ayer.setDate(this.data.cartolas[cartolaIdx].fecha.getDate() - 1)
|
|
this.data.cartolas[cartolaIdx].saldo = entry[1].cartola.saldo
|
|
this.data.cartolas[cartolaIdx].get().ayer(ayer)
|
|
})
|
|
this.draw().diferencia()
|
|
this.draw().cartola()
|
|
})
|
|
})
|
|
return false
|
|
}
|
|
}
|
|
},
|
|
setup(ids) {
|
|
this.ids = ids
|
|
|
|
this.loader().hide()
|
|
|
|
$(this.ids.form).submit(event => {
|
|
event.preventDefault()
|
|
return false
|
|
})
|
|
$(this.ids.buttons.add).click(event => {
|
|
this.cartolas().add()
|
|
})
|
|
$(this.ids.buttons.process).click(this.parse().cartola)
|
|
$(this.ids.table.base).DataTable(this.dataTableConfig)
|
|
|
|
this.cartolas().add()
|
|
|
|
$(this.ids.editModal).modal({
|
|
onApprove: $element => {
|
|
const idx = $(this.ids.editModal).data('cartola')
|
|
const id = $(this.ids.editModal).find('input[name="movimiento_id"]').val()
|
|
const body = new FormData($(this.ids.editModal).find('form')[0])
|
|
body.set('idx', idx)
|
|
if (body.has('rut')) {
|
|
body.set('rut', body.get('rut').replace(/\D/g, ''))
|
|
body.set('digito', Rut.digitoVerificador(body.get('rut')))
|
|
}
|
|
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
|
|
|
|
return fetchAPI(url, {method: 'post', body}).then(response => {
|
|
if (!response) {
|
|
return
|
|
}
|
|
response.json().then(json => {
|
|
if (!json.status || json.movimiento === null || json.movimiento.detalles === null) {
|
|
return
|
|
}
|
|
const idx = diaria.data.cartolas.findIndex(cartola => cartola.idx = json.input.idx)
|
|
const movimiento = diaria.data.cartolas[idx].movimientos.find(movimiento => movimiento.id === id)
|
|
movimiento.centro = json.movimiento.detalles.centro_costo.id
|
|
movimiento.categoria = json.movimiento.detalles.categoria
|
|
movimiento.detalle = json.movimiento.detalles.detalle
|
|
movimiento.rut = json.movimiento.detalles.rut
|
|
movimiento.digito = json.movimiento.detalles.digito
|
|
movimiento.nombres = json.movimiento.detalles.nombres
|
|
movimiento.identificador = json.movimiento.detalles.identificador
|
|
})
|
|
})
|
|
}
|
|
})
|
|
$(this.ids.editModal).find('.dropdown').dropdown()
|
|
$(this.ids.editModal).find('[name="rut"]').on('input', function(event) {
|
|
const rut = event.currentTarget.value
|
|
const rut_clean = rut.replace(/\D/g, '')
|
|
event.currentTarget.value = Rut.format(rut_clean)
|
|
document.getElementById('digito').innerHTML = Rut.digitoVerificador(rut_clean)
|
|
}.bind(this))
|
|
const rut = $(this.ids.editModal).find('[name="rut"]')
|
|
const rut_clean = rut.val().replace(/\D/g, '')
|
|
rut.val(Rut.format(rut_clean))
|
|
document.getElementById('digito').innerHTML = Rut.digitoVerificador(rut_clean)
|
|
}
|
|
}
|
|
const manual = {
|
|
ids: {},
|
|
$modal: null,
|
|
data: {
|
|
inmobiliaria: '',
|
|
cuenta: '',
|
|
fecha: '',
|
|
field: 0,
|
|
movimientos: [
|
|
{idx: 1}
|
|
]
|
|
},
|
|
get movimientosIdx() {
|
|
const $movimientosIdx = $(this.ids.form).find("[name='movimientos']")
|
|
return JSON.parse($movimientosIdx.val())
|
|
},
|
|
set movimientosIdx(list) {
|
|
const $movimientosIdx = $(this.ids.form).find("[name='movimientos']")
|
|
$movimientosIdx.val(JSON.stringify(list))
|
|
},
|
|
update() {
|
|
return {
|
|
file: movimientos => {
|
|
const $file = $("[name='file" + this.data.field + "']")
|
|
$file.val(JSON.stringify(movimientos))
|
|
}
|
|
}
|
|
},
|
|
parse() {
|
|
return {
|
|
movimientos: () => {
|
|
const $fields = $(this.ids.movimientos).find('.fields')
|
|
const movimientos = []
|
|
$fields.each((i, fields) => {
|
|
const idx = $(fields).data('movimiento')
|
|
const inputs = [
|
|
'glosa',
|
|
'cargo',
|
|
'abono',
|
|
'saldo'
|
|
]
|
|
const data = {}
|
|
inputs.forEach(name => {
|
|
data[name] = $(fields).find("[name='"+name+idx+"']").val()
|
|
if (name !== 'glosa') {
|
|
data[name] = parseInt(data[name]) || 0
|
|
}
|
|
})
|
|
|
|
movimientos.push(data)
|
|
})
|
|
this.update().file(movimientos)
|
|
}
|
|
}
|
|
},
|
|
movimiento() {
|
|
return {
|
|
add: () => {
|
|
const idx = this.data.movimientos.reduce((prev, movimiento) => Math.max(prev, movimiento.idx), 0) + 1
|
|
const movimiento = {
|
|
idx
|
|
}
|
|
this.data.movimientos.push(movimiento)
|
|
const movimientosidx = this.movimientosIdx
|
|
movimientosidx.push(idx)
|
|
this.movimientosIdx = movimientosidx
|
|
this.draw().movimiento(idx)
|
|
},
|
|
remove: idx => {
|
|
const movimientosIdx = this.movimientosIdx
|
|
const i = movimientosIdx.findIndex(n => n === idx)
|
|
movimientosIdx.splice(i, 1)
|
|
const movimientoIdx = this.data.movimientos.findIndex(movimiento => movimiento.idx === idx)
|
|
this.data.movimientos.splice(movimientoIdx, 1)
|
|
$(this.ids.movimientos).find("[data-idx='"+idx+"']").parent().parent().remove()
|
|
this.movimientosIdx = movimientosIdx
|
|
}
|
|
}
|
|
},
|
|
draw() {
|
|
return {
|
|
movimiento: idx => {
|
|
$(this.ids.movimientos).append(
|
|
$('<div></div>').addClass('fields').attr('data-movimiento', idx).append(
|
|
'<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')
|
|
).append(
|
|
$('<button></button>').addClass('ui red icon button').attr('type', 'button').attr('data-idx', idx).append(
|
|
$('<i></i>').addClass('remove icon')
|
|
).click(event => {
|
|
const idx = $(event.currentTarget).data('idx')
|
|
manual.movimiento().remove(idx)
|
|
})
|
|
)
|
|
)
|
|
)
|
|
}
|
|
}
|
|
},
|
|
setup(ids) {
|
|
this.ids = ids
|
|
|
|
$(this.ids.modal).modal({
|
|
onShow: () => {
|
|
$(this.ids.inmobiliaria).html(this.data.inmobiliaria)
|
|
$(this.ids.cuenta).html(this.data.cuenta)
|
|
$(this.ids.fecha).html(this.data.fecha)
|
|
this.movimientos = []
|
|
$(this.ids.form).trigger('reset')
|
|
},
|
|
onApprove: $element => {
|
|
this.parse().movimientos()
|
|
},
|
|
onHide: $element => {
|
|
this.parse().movimientos()
|
|
}
|
|
})
|
|
this.$modal = $(this.ids.modal)
|
|
$(this.ids.button).click(event => {
|
|
this.movimiento().add()
|
|
})
|
|
$(this.ids.form).submit(event => {
|
|
event.preventDefault()
|
|
this.$modal.modal('hide')
|
|
return false
|
|
})
|
|
}
|
|
}
|
|
$(document).ready(() => {
|
|
diaria.setup({
|
|
table: {
|
|
base: '#tabla_movimientos',
|
|
body: '#movimientos',
|
|
diferencia: '#diferencia'
|
|
},
|
|
form: '#cartola_form',
|
|
fields: '#fields',
|
|
buttons: {
|
|
add: '#add_button',
|
|
process: '#process_button'
|
|
},
|
|
loader: '#loader',
|
|
editModal: '#edit_modal'
|
|
})
|
|
manual.setup({
|
|
modal: '#manual_modal',
|
|
button: '#add_manual',
|
|
inmobiliaria: '#modal_inmobiliaria',
|
|
cuenta: '#modal_cuenta',
|
|
fecha: '#modal_fecha',
|
|
form: '#modal_form',
|
|
movimientos: '#modal_movimientos'
|
|
})
|
|
})
|
|
</script>
|
|
@endpush
|