324 lines
14 KiB
PHP
324 lines
14 KiB
PHP
@extends('layout.base')
|
|
|
|
@section('page_content')
|
|
<div class="ui container">
|
|
<h1 class="ui header">
|
|
Cartola Diaria
|
|
</h1>
|
|
<form class="ui form" id="cartola_form">
|
|
<div class="fields">
|
|
<div class="six wide field">
|
|
<label for="inmobiliaria">Sociedad</label>
|
|
<div class="ui search selection dropdown" id="inmobiliaria">
|
|
<input type="hidden" name="inmobiliaria_rut" />
|
|
<i class="dropdown icon"></i>
|
|
<div class="default text">Inmobiliaria</div>
|
|
<div class="menu">
|
|
@foreach($inmobiliarias as $inmobiliaria)
|
|
<div class="item" data-value="{{$inmobiliaria->rut}}">{{$inmobiliaria->razon}}</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="two wide field">
|
|
<label>Banco</label>
|
|
<div class="ui selection search dropdown" id="banco">
|
|
<input type="hidden" name="banco_id"/>
|
|
<i class="dropdown icon"></i>
|
|
<div class="default text">Banco</div>
|
|
<div class="menu"></div>
|
|
</div>
|
|
</div>
|
|
<div class="four wide field">
|
|
<label for="fecha">Fecha</label>
|
|
<div class="ui calendar" id="fecha">
|
|
<div class="ui left icon input">
|
|
<i class="calendar icon"></i>
|
|
<input type="text" name="fecha" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="file">Cartola</label>
|
|
<input type="file" name="file" id="file" class="ui invisible file input" />
|
|
<label for="file" class="ui icon button">
|
|
<i class="file icon"></i>
|
|
Cargar
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</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>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>Fecha</th>
|
|
<th>Glosa</th>
|
|
<th>Documento</th>
|
|
<th class="right aligned">Cargo</th>
|
|
<th class="right aligned">Abono</th>
|
|
<th class="right aligned">Saldo</th>
|
|
<th>Orden</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="movimientos"></tbody>
|
|
</table>
|
|
</div>
|
|
@endsection
|
|
|
|
@include('layout.head.styles.datatables')
|
|
@include('layout.body.scripts.datatables')
|
|
|
|
@push('page_scripts')
|
|
<script>
|
|
const diaria = {
|
|
ids: {},
|
|
data: {
|
|
inmobiliaria: {
|
|
rut: 0,
|
|
razon: ''
|
|
},
|
|
banco: {
|
|
id: 0,
|
|
nombre: ''
|
|
},
|
|
fecha: '',
|
|
movimientos: [],
|
|
saldo: 0,
|
|
ayer: 0
|
|
},
|
|
dataTableConfig: {
|
|
order: [[6, 'asc']],
|
|
columnDefs: [
|
|
{
|
|
targets: [0, 2, 3, 4, 5],
|
|
width: '10%'
|
|
},
|
|
{
|
|
targets: [1],
|
|
width: '20%'
|
|
},
|
|
{
|
|
targets: [6],
|
|
visible: false
|
|
}
|
|
],
|
|
},
|
|
get() {
|
|
return {
|
|
bancos: inmobiliaria_rut => {
|
|
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/cuentas'
|
|
$(this.ids.loader).show()
|
|
return fetchAPI(url).then(response => {
|
|
$(this.ids.loader).hide()
|
|
if (!response) {
|
|
return
|
|
}
|
|
return response.json().then(json => {
|
|
if (json.cuentas.length === 0) {
|
|
return
|
|
}
|
|
$(this.ids.form.banco).dropdown('change values', json.cuentas.map(cuenta => {
|
|
return {
|
|
value: cuenta.banco.id,
|
|
text: cuenta.banco.nombre,
|
|
name: cuenta.banco.nombre
|
|
}
|
|
})).dropdown('refresh')
|
|
})
|
|
})
|
|
},
|
|
ayer: (inmobiliaria_rut, banco_id, fecha) => {
|
|
const url = '{{$urls->api}}/contabilidad/cartola/diaria/ayer'
|
|
const body = new FormData()
|
|
body.set('inmobiliaria_rut', inmobiliaria_rut)
|
|
body.set('banco_id', banco_id)
|
|
body.set('fecha', fecha.toISOString())
|
|
return fetchAPI(url, {method: 'post', body}).then(response => {
|
|
if (!response) {
|
|
return
|
|
}
|
|
return response.json().then(json => {
|
|
this.data.ayer = json.cartola.saldo
|
|
})
|
|
})
|
|
}
|
|
}
|
|
},
|
|
parse() {
|
|
return {
|
|
cartola: event => {
|
|
event.preventDefault()
|
|
const body = new FormData(document.getElementById('cartola_form'))
|
|
const fecha = $('#fecha').calendar('get date')
|
|
body.set('fecha', [fecha.getFullYear(), fecha.getMonth()+1, fecha.getDate()].join('-'))
|
|
const url = '{{$urls->api}}/contabilidad/cartola/diaria/procesar'
|
|
$(this.ids.loader).show()
|
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
|
$(this.ids.loader).hide()
|
|
if (!response) {
|
|
return
|
|
}
|
|
return response.json().then(json => {
|
|
if (json.cartola.movimientos.length === 0) {
|
|
return
|
|
}
|
|
this.data.movimientos = []
|
|
json.cartola.movimientos.forEach((row, idx) => {
|
|
const fecha = new Date(row.fecha)
|
|
fecha.setDate(fecha.getDate() + 1)
|
|
this.data.movimientos[idx] = {
|
|
fecha: fecha,
|
|
glosa: row.glosa,
|
|
documento: row.documento,
|
|
cargo: row.cargo,
|
|
abono: row.abono,
|
|
saldo: row.saldo
|
|
}
|
|
})
|
|
this.data.saldo = json.cartola.cartola.saldo
|
|
const ayer = new Date()
|
|
ayer.setDate(fecha.getDate() - 1)
|
|
this.get().ayer(body.get('inmobiliaria_rut'), body.get('banco_id'), ayer)
|
|
.then(() => {
|
|
this.draw().diferencia()
|
|
this.draw().cartola()
|
|
})
|
|
})
|
|
})
|
|
return false
|
|
}
|
|
}
|
|
},
|
|
draw() {
|
|
return {
|
|
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})
|
|
tbody.append(
|
|
$('<tr></tr>').append(
|
|
$('<td></td>').html(dateFormatter.format(this.data.fecha))
|
|
).append(
|
|
$('<td></td>').html(numberFormatter.format(this.data.ayer))
|
|
).append(
|
|
$('<td></td>').html(numberFormatter.format(this.data.saldo))
|
|
).append(
|
|
$('<td></td>').html(numberFormatter.format(this.data.saldo - this.data.ayer))
|
|
)
|
|
)
|
|
},
|
|
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.movimientos.forEach((row, idx) => {
|
|
tbody.append(
|
|
$('<tr></tr>').append(
|
|
$('<td></td>').html(dateFormatter.format(row.fecha))
|
|
).append(
|
|
$('<td></td>').html(row.glosa)
|
|
).append(
|
|
$('<td></td>').html(row.documento)
|
|
).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))
|
|
).append(
|
|
$('<td></td>').html(idx + 1)
|
|
)
|
|
)
|
|
})
|
|
table.DataTable(this.dataTableConfig)
|
|
},
|
|
}
|
|
},
|
|
setup(ids) {
|
|
this.ids = ids
|
|
$(this.ids.form.inmobiliaria).dropdown({
|
|
fireOnInit: true,
|
|
onChange: (value, text, $choice) => {
|
|
this.data.inmobiliaria.rut = value
|
|
this.data.inmobiliaria.razon = text
|
|
this.get().bancos(value)
|
|
},
|
|
})
|
|
$(this.ids.form.banco).dropdown({
|
|
fireOnInit: true,
|
|
onChange: (value, text, $choice) => {
|
|
this.data.banco.id = value
|
|
this.data.banco.nombre = text
|
|
}
|
|
})
|
|
$(this.ids.loader).hide()
|
|
|
|
calendar_date_options['initialDate'] = new Date()
|
|
calendar_date_options['maxDate'] = calendar_date_options['initialDate']
|
|
calendar_date_options['onChange'] = (date, text, mode) => {
|
|
this.data.fecha = date
|
|
}
|
|
$(this.ids.form.fecha).calendar(calendar_date_options)
|
|
$(this.ids.form.base).submit(this.parse().cartola)
|
|
$(this.ids.button).click(this.parse().cartola)
|
|
$(this.ids.table.base).DataTable(this.dataTableConfig)
|
|
}
|
|
}
|
|
$(document).ready(() => {
|
|
diaria.setup({
|
|
table: {
|
|
base: '#tabla_movimientos',
|
|
body: '#movimientos',
|
|
diferencia: '#diferencia'
|
|
},
|
|
form: {
|
|
base: '#cartola_form',
|
|
inmobiliaria: '#inmobiliaria',
|
|
banco: '#banco',
|
|
fecha: '#fecha'
|
|
},
|
|
button: '#process_button',
|
|
loader: '#loader'
|
|
})
|
|
})
|
|
</script>
|
|
@endpush
|