2024-06-18
This commit is contained in:
@ -2,5 +2,15 @@
|
||||
use Incoviba\Controller\Inmobiliarias;
|
||||
|
||||
$app->group('/inmobiliarias', function($app) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'inmobiliarias']);
|
||||
if (file_exists($folder)) {
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
$app->get('[/]', Inmobiliarias::class);
|
||||
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
use Incoviba\Controller\API\Contabilidad\Nubox;
|
||||
|
||||
$app->group('/nubox/{inmobiliaria_rut}', function($app) {
|
||||
@ -10,5 +9,6 @@ $app->group('/nubox/{inmobiliaria_rut}', function($app) {
|
||||
$app->post('/mayor[/]', [Nubox::class, 'libroMayor']);
|
||||
$app->post('/diario[/]', [Nubox::class, 'libroDiario']);
|
||||
});
|
||||
$app->get('/facturas/{dia}[/]', [Nubox::class, 'facturas']);
|
||||
$app->post('/cuenta', [Nubox::class, 'cuenta']);
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ $app->group('/inmobiliarias', function($app) {
|
||||
$app->get('[/]', Inmobiliarias::class);
|
||||
});
|
||||
$app->group('/inmobiliaria/{inmobiliaria_rut}', function($app) {
|
||||
$app->post('/agentes', [Inmobiliarias::class, 'agentes']);
|
||||
$app->post('/proveedores', [Inmobiliarias::class, 'proveedores']);
|
||||
$app->get('/cuentas[/]', [Inmobiliarias::class, 'cuentas']);
|
||||
$app->get('/proyectos[/]', [Inmobiliarias::class, 'proyectos']);
|
||||
});
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Inmobiliarias\Agentes;
|
||||
|
||||
$app->group('/agentes', function($app) {
|
||||
$app->group('/proveedores', function($app) {
|
||||
$app->post('/add[/]', [Agentes::class, 'add']);
|
||||
$app->post('/register[/]', [Agentes::class, 'register']);
|
||||
$app->get('[/]', Agentes::class);
|
||||
});
|
||||
$app->group('/agente/{agente_id}', function($app) {
|
||||
$app->group('/proveedor/{agente_id}', function($app) {
|
||||
$app->post('/edit[/]', [Agentes::class, 'edit']);
|
||||
});
|
||||
|
7
app/resources/routes/api/inmobiliarias/sociedades.php
Normal file
7
app/resources/routes/api/inmobiliarias/sociedades.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Inmobiliarias\Sociedades;
|
||||
|
||||
$app->group('/sociedades', function($app) {
|
||||
$app->post('/add[/]', [Sociedades::class, 'add']);
|
||||
$app->get('[/]', Sociedades::class);
|
||||
});
|
17
app/resources/routes/api/sociedades.php
Normal file
17
app/resources/routes/api/sociedades.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Sociedades;
|
||||
|
||||
$app->group('/sociedades', function($app) {
|
||||
$app->group('/add', function($app) {
|
||||
$app->post('/one[/]', Sociedades::class . ':add');
|
||||
$app->post('[/]', Sociedades::class . ':addMany');
|
||||
});
|
||||
$app->post('/get[/]', [Sociedades::class, 'getMany']);
|
||||
$app->post('/edit[/]', [Sociedades::class, 'edit']);
|
||||
$app->post('/delete[/]', [Sociedades::class, 'delete']);
|
||||
$app->post('/asisgnar[/]', [Sociedades::class, 'asignar']);
|
||||
$app->get('[/]', Sociedades::class);
|
||||
});
|
||||
$app->group('/sociedad/{sociedad_rut}', function($app) {
|
||||
$app->get('[/]', Sociedades::class . ':get');
|
||||
});
|
6
app/resources/routes/api/ventas/facturas.php
Normal file
6
app/resources/routes/api/ventas/facturas.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Ventas\Facturas;
|
||||
|
||||
$app->group('/facturas', function($app) {
|
||||
$app->post('/add[/]', [Facturas::class, 'add']);
|
||||
});
|
4
app/resources/routes/contabilidad/cuadratura.php
Normal file
4
app/resources/routes/contabilidad/cuadratura.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Contabilidad;
|
||||
|
||||
$app->get('/cuadratura[/]', [Contabilidad::class, 'cuadratura']);
|
6
app/resources/routes/inmobiliarias/proveedores.php
Normal file
6
app/resources/routes/inmobiliarias/proveedores.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Inmobiliarias\Proveedores;
|
||||
|
||||
$app->group('/proveedores', function($app) {
|
||||
$app->get('[/]', Proveedores::class);
|
||||
});
|
225
app/resources/views/contabilidad/cuadratura.blade.php
Normal file
225
app/resources/views/contabilidad/cuadratura.blade.php
Normal file
@ -0,0 +1,225 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h1 class="ui header">
|
||||
Cuadratura de Cartola Mensual
|
||||
</h1>
|
||||
<form class="ui form" id="cuadratura_form">
|
||||
<div class="ui grid">
|
||||
<div class="fourteen wide column">
|
||||
<div class="fields">
|
||||
<div class="five wide field">
|
||||
<label>Inmobiliaria</label>
|
||||
<div class="ui selection search dropdown" id="inmobiliaria">
|
||||
<input type="hidden" name="inmobiliaria"/>
|
||||
<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"/>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Banco</div>
|
||||
<div class="menu"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Mes</label>
|
||||
<div class="ui calendar" id="mes">
|
||||
<div class="ui icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="mes"/>
|
||||
</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>
|
||||
</div>
|
||||
<div class="two wide middle aligned column">
|
||||
<button class="ui icon button">
|
||||
Procesar
|
||||
<i class="sync icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="ui two columns grid">
|
||||
<div class="column"></div>
|
||||
<div class="right aligned column">
|
||||
<div class="ui inline active loader" id="loader"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui fluid container" id="movimientos"></div>
|
||||
@endsection
|
||||
|
||||
@include('layout.head.styles.datatables')
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class LibroMayor {
|
||||
props
|
||||
constructor(props) {
|
||||
this.props = props
|
||||
}
|
||||
}
|
||||
class Cartola {
|
||||
|
||||
}
|
||||
const movimientos = {
|
||||
ids: {},
|
||||
data: {
|
||||
inmobiliaria: {
|
||||
rut: '',
|
||||
razon: ''
|
||||
},
|
||||
banco: {
|
||||
id: '',
|
||||
nombre: ''
|
||||
}
|
||||
},
|
||||
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.inputs.banco).dropdown('change values', json.cuentas.map(cuenta => {
|
||||
return {value: cuenta.banco.id, text: cuenta.banco.nombre, name: cuenta.banco.nombre}
|
||||
})).dropdown('refresh')
|
||||
})
|
||||
})
|
||||
},
|
||||
firstDate: inmobiliaria_rut => {
|
||||
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/proyectos'
|
||||
$(this.ids.loader).show()
|
||||
return fetchAPI(url).then(response => {
|
||||
$(this.ids.loader).hide()
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (json.proyectos.length === 0) {
|
||||
return
|
||||
}
|
||||
const min = json.proyectos.reduce((min, proyecto) => {
|
||||
const date = new Date(proyecto.current_estado.fecha.date)
|
||||
if (min > date.getTime()) {
|
||||
return date.getTime()
|
||||
}
|
||||
return min
|
||||
}, (new Date()).getTime())
|
||||
$(this.ids.inputs.mes).calendar('set minDate', new Date(min))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
parse() {
|
||||
return {
|
||||
cartola: submitEvent => {
|
||||
submitEvent.preventDefault()
|
||||
const body = new FormData(document.getElementById('asignar_form'))
|
||||
body.set('mes', $(this.ids.inputs.mes).calendar('get date').toISOString())
|
||||
const url = '{{$urls->api}}/contabilidad/cartolas/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.movimientos.length === 0) {
|
||||
return
|
||||
}
|
||||
this.data.movimientos = []
|
||||
json.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,
|
||||
}
|
||||
})
|
||||
this.draw().cartola()
|
||||
})
|
||||
})
|
||||
return false
|
||||
}
|
||||
}
|
||||
},
|
||||
setup(ids) {
|
||||
this.ids = ids
|
||||
|
||||
$(this.ids.inputs.inmobiliaria).dropdown({
|
||||
fireOnInit: true,
|
||||
onChange: (value, text, $choice) => {
|
||||
this.data.inmobiliaria.rut = value
|
||||
this.data.inmobiliaria.razon = text
|
||||
this.get().bancos(value)
|
||||
this.get().firstDate(value)
|
||||
},
|
||||
})
|
||||
$(this.ids.inputs.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['type'] = 'month'
|
||||
const lastMonth = new Date()
|
||||
lastMonth.setDate(0)
|
||||
calendar_date_options['maxDate'] = lastMonth
|
||||
calendar_date_options['onChange'] = (date, text, mode) => {
|
||||
this.data.mes = text
|
||||
}
|
||||
$(this.ids.inputs.mes).calendar(calendar_date_options)
|
||||
$(this.ids.form).submit(this.parse().cartola)
|
||||
//$(this.ids.button).click(this.export().cartola)
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
movimientos.setup({
|
||||
movimientos: '#movimientos',
|
||||
form: '#cuadratura_form',
|
||||
loader: '#loader',
|
||||
inputs: {
|
||||
inmobiliaria: '#inmobiliaria',
|
||||
banco: '#banco',
|
||||
mes: '#mes',
|
||||
cartola: '#file'
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -71,7 +71,7 @@
|
||||
<tbody id="movimientos"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="ui modal" id="movimientos_modal">
|
||||
<div class="ui fluid modal" id="movimientos_modal">
|
||||
<div class="content">
|
||||
<h3 class="header">
|
||||
Editar Movimiento
|
||||
@ -92,30 +92,66 @@
|
||||
<form class="ui form" id="movimientos_edit">
|
||||
<input type="hidden" name="index"/>
|
||||
<input type="hidden" name="id"/>
|
||||
<div class="field">
|
||||
<label for="centro_costo">Centro de Costo</label>
|
||||
<div class="ui selection search dropdown" id="centro_costo">
|
||||
<input type="hidden" name="centro_id"/>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Centro de Costo</div>
|
||||
<div class="menu">
|
||||
@foreach($centros as $centroCosto)
|
||||
<div class="item" data-value="{{$centroCosto->id}}">{{$centroCosto->id}} - {{$centroCosto->descripcion}}</div>
|
||||
@endforeach
|
||||
<div class="fields" id="movimiento_data">
|
||||
<div class="field">
|
||||
<label for="centro_costo">Centro de Costo</label>
|
||||
<div class="ui selection search dropdown" id="centro_costo">
|
||||
<input type="hidden" name="centro_id"/>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Centro de Costo</div>
|
||||
<div class="menu">
|
||||
@foreach($centros as $centroCosto)
|
||||
<div class="item" data-value="{{$centroCosto->id}}">{{$centroCosto->id}} - {{$centroCosto->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>RUT</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="rut" placeholder="RUT" />
|
||||
<div class="ui basic label">-<span id="digito"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="nombre" placeholder="Nombre" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Categoría</label>
|
||||
<input type="text" name="categoria" placeholder="Categoría" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="detalle">Detalle</label>
|
||||
<div class="ui input">
|
||||
<textarea id="detalle" name="detalle"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="detalle">Detalle</label>
|
||||
<div class="ui input">
|
||||
<textarea id="detalle" name="detalle"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<table class="ui table" id="auxiliares">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Cargo</th>
|
||||
<th>Abono</th>
|
||||
<th>Centro Costo</th>
|
||||
<th>RUT</th>
|
||||
<th>Nombre</th>
|
||||
<th>Categoría</th>
|
||||
<th>Detalle</th>
|
||||
<th class="right aligned">
|
||||
<button class="ui green icon button" type="button" id="add_auxiliar">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui cancel button">Cancelar</div>
|
||||
<div class="ui approve success button">Guardar</div>
|
||||
<div class="ui red cancel button">Cancelar</div>
|
||||
<div class="ui green approve success button">Guardar</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@ -123,10 +159,573 @@
|
||||
@include('layout.body.scripts.datatables')
|
||||
@include('layout.body.scripts.datatables.searchbuilder')
|
||||
@include('layout.body.scripts.datatables.buttons')
|
||||
@include('layout.body.scripts.rut')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
const movimientos = {
|
||||
class CentrosCostos {
|
||||
static data = []
|
||||
static get() {
|
||||
if (this.data.length === 0) {
|
||||
this.data = JSON.parse('{!! json_encode($centros) !!}')
|
||||
}
|
||||
return this.data
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class EventHandler {
|
||||
props
|
||||
constructor({movimientosHandler, modalHandler}) {
|
||||
this.props = {
|
||||
movimientosHandler,
|
||||
modalHandler
|
||||
}
|
||||
}
|
||||
get() {
|
||||
return {
|
||||
movimientos: submitEvent => {
|
||||
submitEvent.preventDefault()
|
||||
submitEvent.data.handler.props.movimientosHandler.get().movimientos({
|
||||
sociedades_ruts: $(submitEvent.data.sociedades_id).dropdown('get values'),
|
||||
mes: $(submitEvent.data.mes_id).calendar('get date')
|
||||
}).then(() => {
|
||||
app.handlers.table.draw().table(app.handlers.results.props.parsed)
|
||||
})
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
edit() {
|
||||
return {
|
||||
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})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class LoadingHandler {
|
||||
props
|
||||
constructor({ids}) {
|
||||
this.props = {
|
||||
ids
|
||||
}
|
||||
}
|
||||
show() {
|
||||
$(this.props.id).addClass('loading')
|
||||
}
|
||||
hide() {
|
||||
$(this.props.id).removeClass('loading')
|
||||
}
|
||||
}
|
||||
class ControlForm {
|
||||
props
|
||||
constructor({ids,}) {
|
||||
this.props = {
|
||||
ids,
|
||||
}
|
||||
}
|
||||
setup() {
|
||||
$(this.props.ids.sociedades).dropdown()
|
||||
|
||||
const cdo = structuredClone(calendar_date_options)
|
||||
cdo['type'] = 'month'
|
||||
cdo['maxDate'] = new Date()
|
||||
$(this.props.ids.mes).calendar(cdo)
|
||||
|
||||
$(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)
|
||||
}
|
||||
}
|
||||
class MovimientosTable {
|
||||
props
|
||||
constructor({ids, eventHandler}) {
|
||||
this.props = {
|
||||
ids,
|
||||
eventHandler,
|
||||
movimientos: [],
|
||||
formatters: {
|
||||
number: new Intl.NumberFormat('es-CL'),
|
||||
date: new Intl.DateTimeFormat('es-CL', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
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
|
||||
'<button class="ui icon button edit_button" data-id="' + movimiento.id + '" data-index="' + movimiento.index + '" data-type="movimiento"><i class="edit icon"></i></button>',//12
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
setup() {
|
||||
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 <i class="file excel icon"></i>',
|
||||
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.props.movimientos,
|
||||
})
|
||||
this.props.table = new DataTable(this.props.ids.table, dtD)
|
||||
}
|
||||
}
|
||||
class EditModal {
|
||||
props
|
||||
constructor({ids, editForm}) {
|
||||
this.props = {
|
||||
ids,
|
||||
editForm,
|
||||
movimientos: []
|
||||
}
|
||||
}
|
||||
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.props.editForm.reset()
|
||||
}
|
||||
show({movimiento, type}) {
|
||||
$(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})
|
||||
}
|
||||
hide() {
|
||||
$(this.props.ids.modal).modal('hide')
|
||||
this.reset()
|
||||
}
|
||||
}
|
||||
class EditForm {
|
||||
props
|
||||
constructor({ids}) {
|
||||
this.props = {
|
||||
ids,
|
||||
movimientos: []
|
||||
}
|
||||
}
|
||||
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(`<tr>
|
||||
<td><input type="text" name="cargo${i}" value="${auxiliar.cargo}" /></td>
|
||||
<td><input type="text" name="abono${i}" value="${auxiliar.abono}" /></td>
|
||||
<td>
|
||||
<div class="ui selection search dropdown">
|
||||
<input type="hidden" name="centro_costo${i}" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Centro de Costo</div>
|
||||
<div class="menu">
|
||||
${CentrosCostos.get().map(centroCosto => `<div class="item" data-value="${centroCosto.id}">${centroCosto.id} - ${centroCosto.descripcion}</div>`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="rut${i}" value="${auxiliar.detalles.rut}" />
|
||||
<div class="ui basic label">-<span class="digito" data-index="${i}">${Rut.digitoVerificador(auxiliar.detalles.rut)}</span></div>
|
||||
</div>
|
||||
</td>
|
||||
<td><input type="text" name="nombre${i}" value="${auxiliar.detalles.nombre}" /></td>
|
||||
<td><input type="text" name="categoria${i}" value="${auxiliar.detalles.categoria}" /></td>
|
||||
<td><input type="text" name="detalle${i}" value="${auxiliar.detalles.detalle}" /></td>
|
||||
<td><button class="ui red icon button" type="button"><i class="trash icon"></i></button></td>
|
||||
</tr>`)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
class MovimientosHandler {
|
||||
props
|
||||
constructor({urls, loadingHandler, resultsHandler}) {
|
||||
this.props = {
|
||||
urls,
|
||||
loadingHandler,
|
||||
resultsHandler
|
||||
}
|
||||
}
|
||||
get() {
|
||||
return {
|
||||
movimientos: ({sociedades_ruts, mes}) => {
|
||||
this.props.loadingHandler.show()
|
||||
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('-'))
|
||||
return APIClient.fetch(this.props.urls.get, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
throw new Error('No se pudo obtener los movimientos')
|
||||
}
|
||||
return response.json().then(json => {
|
||||
this.movimientos = json.movimientos
|
||||
this.props.resultsHandler.props.movimientos = json.movimientos
|
||||
this.props.resultsHandler.parse().movimientos()
|
||||
return json.movimientos
|
||||
})
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
}).finally(() => {
|
||||
this.props.loadingHandler.hide()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
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})
|
||||
}
|
||||
})*/
|
||||
}
|
||||
}
|
||||
}
|
||||
find() {
|
||||
return {
|
||||
id: id => {
|
||||
return this.props.resultsHandler.props.movimientos.find(movimiento => movimiento.id === id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class ResultsHandler {
|
||||
props
|
||||
constructor() {
|
||||
this.props = {
|
||||
movimientos: [],
|
||||
timezone: ((new Date()).getTimezoneOffset()) / -60
|
||||
}
|
||||
}
|
||||
parse() {
|
||||
return {
|
||||
movimientos: () => {
|
||||
const movimientos = this.props.movimientos
|
||||
const data = []
|
||||
movimientos.forEach((movimiento, index) => {
|
||||
this.parse().movimiento({data, movimiento, index})
|
||||
})
|
||||
this.props.parsed = data
|
||||
},
|
||||
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,
|
||||
index,
|
||||
cuenta: movimiento.cuenta,
|
||||
fecha,
|
||||
cargo: movimiento.cargo,
|
||||
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 = $('<div></div>').addClass('menu')
|
||||
CentrosCostos.get().forEach(centroCosto => {
|
||||
menu.append(`<div class="item" data-value="${centroCosto.id}">${centroCosto.id} - ${centroCosto.descripcion}</div>`)
|
||||
})
|
||||
const tr = $('<tr>')
|
||||
if (typeof auxiliar !== 'undefined' && auxiliar.includes('cargo')) {
|
||||
tr.append(`<td><input type="text" name="cargo${i}" value="${auxiliar.cargo}" /></td>`)
|
||||
} else {
|
||||
tr.append(`<td><input type="text" name="cargo${i}" /></td>`)
|
||||
}
|
||||
if (typeof auxiliar !== 'undefined' && auxiliar.includes('abono')) {
|
||||
tr.append(`<td><input type="text" name="abono${i}" value="${auxiliar.abono}" /></td>`)
|
||||
} else {
|
||||
tr.append(`<td><input type="text" name="abono${i}" /></td>`)
|
||||
}
|
||||
tr.append(
|
||||
$('<td>').append($('<div>').addClass('ui selection search dropdown').attr('data-index', i).append(
|
||||
`<input type="hidden" name="centro_costo${i} />`
|
||||
).append(
|
||||
`<i class="dropdown icon"></i>`
|
||||
).append(
|
||||
`<div class="default text">Centro de Costo</div>`
|
||||
).append(menu)
|
||||
)
|
||||
)
|
||||
if (typeof auxiliar !== 'undefined' && auxiliar.includes('detalles') && auxiliar.detalles.includes('rut')) {
|
||||
tr.append(`<td>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="rut${i}" value="${auxiliar.detalles.rut}" />
|
||||
<div class="ui basic label">-<span class="digito" data-index="${i}">${Rut.digitoVerificador(auxiliar.detalles.rut)}</span></div>
|
||||
</div>
|
||||
</td>`)
|
||||
} else {
|
||||
tr.append(`<td>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="rut${i}" />
|
||||
<div class="ui basic label">-<span class="digito" data-index="${i}"></span></div>
|
||||
</div>
|
||||
</td>`)
|
||||
}
|
||||
if (typeof auxiliar !== 'undefined' && auxiliar.includes('nombre')) {
|
||||
tr.append(`<td><input type="text" name="nombre${i}" value="${auxiliar.nombre}" /></td>`)
|
||||
} else {
|
||||
tr.append(`<td><input type="text" name="nombre${i}" /></td>`)
|
||||
}
|
||||
if (typeof auxiliar !== 'undefined' && auxiliar.includes('categoria')) {
|
||||
tr.append(`<td><input type="text" name="categoria${i}" value="${auxiliar.categoria}" /></td>`)
|
||||
} else {
|
||||
tr.append(`<td><input type="text" name="categoria${i}" /></td>`)
|
||||
}
|
||||
if (typeof auxiliar !== 'undefined' && auxiliar.includes('detalle')) {
|
||||
tr.append(`<td><input type="text" name="detalle${i}" value="${auxiliar.detalle}" /></td>`)
|
||||
} else {
|
||||
tr.append(`<td><input type="text" name="detalle${i}" /></td>`)
|
||||
}
|
||||
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: '',
|
||||
@ -144,7 +743,7 @@
|
||||
const sociedades_ruts = $(this.ids.forms.search.sociedades).dropdown('get values')
|
||||
const mes = $(this.ids.forms.search.mes).calendar('get date')
|
||||
|
||||
const url = '{{$urls->api}}/contabilidad/movimientos/sociedad/mes'
|
||||
const url = '/contabilidad/movimientos/sociedad/mes'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
sociedades_ruts.forEach(sociedad_rut => {
|
||||
@ -175,31 +774,37 @@
|
||||
if (data.length === 0) {
|
||||
return
|
||||
}
|
||||
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
|
||||
data.forEach((movimiento, index) => {
|
||||
const fecha = new Date(movimiento.fecha + 'Z' + tz)
|
||||
const valor = movimiento.abono - movimiento.cargo
|
||||
this.movimientos.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
|
||||
'<button class="ui icon button edit_button" data-id="' + movimiento.id + '" data-index="' + index + '"><i class="edit icon"></i></button>',//12
|
||||
])
|
||||
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,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -238,27 +843,64 @@
|
||||
draw() {
|
||||
return {
|
||||
table: () => {
|
||||
this.table.clear().rows.add(this.movimientos).draw()
|
||||
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})
|
||||
})
|
||||
},
|
||||
edit: ({id, index}) => {
|
||||
const form = $('#' + this.ids.forms.edit.id)
|
||||
form.find("[name='id']").val(id)
|
||||
form.find("[name='index']").val(index)
|
||||
$(this.ids.modals.edit).find('.sociedad').text('Sociedad: ' + this.movimientos[index][0])
|
||||
$(this.ids.modals.edit).find('.banco').text('Banco: ' + this.movimientos[index][1])
|
||||
$(this.ids.modals.edit).find('.cuenta').text('Cuenta: ' + this.movimientos[index][2])
|
||||
$(this.ids.modals.edit).find('.fecha').text('Fecha: ' + this.movimientos[index][3])
|
||||
$(this.ids.modals.edit).find('.valor').text('Valor: ' + this.movimientos[index][7])
|
||||
$(this.ids.modals.edit).find('.glosa').text('Glosa: ' + this.movimientos[index][10])
|
||||
form.find("[name='centro_costo']").dropdown('set selected', this.movimientos[index][9])
|
||||
form.find("[name='detalle']").val(this.movimientos[index][11])
|
||||
|
||||
$(this.ids.modals.edit).modal('show')
|
||||
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
|
||||
'<button class="ui icon button edit_button" data-id="' + movimiento.id + '" data-index="' + movimiento.index + '" data-type="movimiento"><i class="edit icon"></i></button>',//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,
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -274,7 +916,7 @@
|
||||
const index = body.get('index')
|
||||
body.delete('id')
|
||||
body.delete('index')
|
||||
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
|
||||
const url = '/contabilidad/movimiento/' + id + '/detalles'
|
||||
const method = 'post'
|
||||
return fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
@ -363,17 +1005,38 @@
|
||||
})
|
||||
this.table = new DataTable(this.ids.table, dtD)
|
||||
|
||||
$(this.ids.modals.edit).modal({
|
||||
/!*$(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.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.ids.forms.edit.id).find('#centro_costo').dropdown()
|
||||
this.handlers.table.setup()
|
||||
this.handlers.forms.control.setup()
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
movimientos.setup({
|
||||
app.setup()
|
||||
/*movimientos.setup({
|
||||
forms: {
|
||||
search: {
|
||||
id: '#movimientos_form',
|
||||
@ -391,7 +1054,7 @@
|
||||
buttons: {
|
||||
edit: '.edit_button'
|
||||
}
|
||||
})
|
||||
})*/
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
330
app/resources/views/inmobiliarias/proveedores.blade.php
Normal file
330
app/resources/views/inmobiliarias/proveedores.blade.php
Normal file
@ -0,0 +1,330 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<table class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nombre</th>
|
||||
<th>Contacto</th>
|
||||
<th class="right aligned">
|
||||
<button class="ui green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="proveedores">
|
||||
@foreach ($sociedades as $sociedad)
|
||||
<tr>
|
||||
<td>{{$sociedad->nombre}}</td>
|
||||
<td>{{$sociedad->contacto->nombreCompleto()}}</td>
|
||||
<td class="right aligned">
|
||||
<button class="ui icon button" data-sociedad="{{$sociedad->rut}}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui red icon button" data-sociedad="{{$sociedad->rut}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="ui modal" id="add_modal">
|
||||
<div class="content">
|
||||
<form class="ui form">
|
||||
<div class="three wide field">
|
||||
<label for="rut">RUT</label>
|
||||
<div class="ui right labeled input">
|
||||
<input class="right aligned" type="text" id="rut" name="rut" placeholder="RUT" maxlength="10" required />
|
||||
<div class="ui basic label">-<span id="dv"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="five wide field">
|
||||
<label for="nombre">Nombre</label>
|
||||
<input type="text" id="nombre" name="nombre" placeholder="Nombre" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="razon">Razón Social</label>
|
||||
<input type="text" id="razon" name="razon" placeholder="Razón Social" required />
|
||||
</div>
|
||||
<div class="four wide field">
|
||||
<label for="tipo">Tipo</label>
|
||||
<div class="ui selection dropdown" id="tipo">
|
||||
<input type="hidden" name="tipo" required />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Tipo</div>
|
||||
<div class="menu">
|
||||
@foreach ($tiposSociedades as $tipo)
|
||||
<div class="item" data-value="{{$tipo->id}}">{{$tipo->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui divider">Contacto</div>
|
||||
<div class="three wide field">
|
||||
<label for="rut_contacto">RUT</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" id="rut_contacto" name="rut_contacto" placeholder="RUT" maxlength="10" required />
|
||||
<div class="ui basic label">-<span id="dv_contacto"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="five wide field">
|
||||
<label for="nombre_contacto">Nombre</label>
|
||||
<input type="text" id="nombre_contacto" name="nombre_contacto" placeholder="Nombre" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="apellido_paterno_contacto">Apellido Paterno</label>
|
||||
<input type="text" id="apellido_paterno_contacto" name="apellido_paterno_contacto" placeholder="Apellido Paterno" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="apellido_materno_contacto">Apellido Materno</label>
|
||||
<input type="text" id="apellido_materno_contacto" name="apellido_materno_contacto" placeholder="Apellido Materno" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="email_contacto">Email</label>
|
||||
<input type="email" id="email_contacto" name="email_contacto" placeholder="Email" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="telefono_contacto">Teléfono</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">+56</div>
|
||||
<input type="text" id="telefono_contacto" name="telefono_contacto" placeholder="Teléfono" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui green approve button">Guardar</button>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
const proveedores = {
|
||||
ids: {
|
||||
modal: '',
|
||||
buttons: {
|
||||
add: '',
|
||||
edit: '',
|
||||
remove: ''
|
||||
},
|
||||
add: {
|
||||
form: '',
|
||||
rut: '',
|
||||
dv: '',
|
||||
nombre: '',
|
||||
razon: '',
|
||||
tipo: '',
|
||||
contacto: {
|
||||
rut: '',
|
||||
dv: '',
|
||||
nombre: '',
|
||||
apellido_paterno: '',
|
||||
apellido_materno: '',
|
||||
email: '',
|
||||
telefono: ''
|
||||
}
|
||||
},
|
||||
proveedores: ''
|
||||
},
|
||||
data: JSON.parse('{!! json_encode($sociedades) !!}'),
|
||||
add() {
|
||||
return {
|
||||
sociedad: () => {
|
||||
const data = {
|
||||
rut: $(this.ids.add.rut).val().replace(/\D/g, ''),
|
||||
digito: $(this.ids.add.dv).text(),
|
||||
nombre: $(this.ids.add.nombre).val(),
|
||||
razon: $(this.ids.add.razon).val(),
|
||||
tipo_sociedad_id: $(this.ids.add.tipo).dropdown('get value'),
|
||||
contacto: {
|
||||
rut: $(this.ids.add.contacto.rut).val().replace(/\D/g, ''),
|
||||
digito: $(this.ids.add.contacto.dv).text(),
|
||||
nombres: $(this.ids.add.contacto.nombre).val(),
|
||||
apellido_paterno: $(this.ids.add.contacto.apellido_paterno).val(),
|
||||
apellido_materno: $(this.ids.add.contacto.apellido_materno).val(),
|
||||
email: $(this.ids.add.contacto.email).val(),
|
||||
telefono: $(this.ids.add.contacto.telefono).val().replace(/\D/g, ''),
|
||||
}
|
||||
}
|
||||
const body = new FormData()
|
||||
body.append('sociedades[]', JSON.stringify(data))
|
||||
const url = '{{$urls->api}}/sociedades/add'
|
||||
const method = 'post'
|
||||
fetchAPI(url, {method, body})
|
||||
.then(response => (response) ? response.json() : null)
|
||||
.then(data => {
|
||||
if (data.sociedades !== null) {
|
||||
data.sociedades.forEach(sociedad => {
|
||||
const exists = this.data.find(s => s.rut === sociedad.rut)
|
||||
if (typeof exists !== 'undefined') {
|
||||
return
|
||||
}
|
||||
this.data.push(sociedad)
|
||||
})
|
||||
this.draw().sociedades()
|
||||
$(this.ids.modal).find('form.form').trigger('reset')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
edit() {},
|
||||
remove() {
|
||||
return {
|
||||
sociedad: rut => {
|
||||
const body = new FormData()
|
||||
body.append('sociedades_ruts[]', rut)
|
||||
const url = '{{$urls->api}}/sociedades/delete'
|
||||
const method = 'post'
|
||||
fetchAPI(url, {method, body})
|
||||
.then(response => (response) ? response.json() : null)
|
||||
.then(data => {
|
||||
if (data.sociedades !== null) {
|
||||
data.sociedades.forEach(sociedad => {
|
||||
if (sociedad.sociedad.rut !== rut) {
|
||||
return
|
||||
}
|
||||
if (!sociedad.deleted) {
|
||||
return
|
||||
}
|
||||
$(this.ids.proveedores).find(`button[data-sociedad="${rut}"]`).closest('tr').remove()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
draw() {
|
||||
return {
|
||||
sociedades: () => {
|
||||
$(this.ids.proveedores).empty()
|
||||
this.data.forEach(sociedad => {
|
||||
$(this.ids.proveedores).append(`
|
||||
<tr>
|
||||
<td>${sociedad.nombre}</td>
|
||||
<td>${sociedad.contacto.nombreCompleto}</td>
|
||||
<td class="right aligned">
|
||||
<button class="ui icon button" data-sociedad="${sociedad.rut}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui red icon button" data-sociedad="${sociedad.rut}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`)
|
||||
})
|
||||
$(this.ids.buttons.remove).click((e) => {
|
||||
this.remove().sociedad($(e.target).data('sociedad'))
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
formatters() {
|
||||
return {
|
||||
rut: value => {
|
||||
const rut = value.replace(/[^0-9]/g, '')
|
||||
if (rut.length <= 1) {
|
||||
return rut
|
||||
}
|
||||
return rut.replace(/\B(?=(\d{3})+(?!\d))/g, '.')
|
||||
},
|
||||
telefono: value => {
|
||||
const phone = value.replace(/[^0-9]/g, '')
|
||||
if (phone.length <= 1) {
|
||||
return phone
|
||||
}
|
||||
return phone.replace(/(\d{2})(\d{3})(\d{4})/, '$1 $2 $3')
|
||||
}
|
||||
}
|
||||
},
|
||||
digitoVerificador(value) {
|
||||
let rut = value.replace(/[^0-9kK]/g, '')
|
||||
if (rut.length < 1) {
|
||||
return ''
|
||||
}
|
||||
let suma = 0
|
||||
let mul = 2
|
||||
for (let i = rut.length-1; i >= 0; i--) {
|
||||
suma += parseInt(rut[i]) * mul
|
||||
mul = (mul + 1) % 8 || 2
|
||||
}
|
||||
const dv = 11 - suma % 11
|
||||
return dv === 10 ? 'K' : (dv === 11 ? '0' : dv.toString())
|
||||
},
|
||||
setup(ids) {
|
||||
this.ids = ids
|
||||
$(this.ids.buttons.add).click(() => {
|
||||
$(this.ids.modal).modal('show')
|
||||
})
|
||||
$(this.ids.add.rut).on('input', (e) => {
|
||||
e.target.value = this.formatters().rut(e.target.value)
|
||||
$(this.ids.add.dv).text(this.digitoVerificador(e.target.value))
|
||||
})
|
||||
if ($(this.ids.add.rut).val().length > 0) {
|
||||
$(this.ids.add.rut).val(this.formatters().rut($(this.ids.add.rut).val()))
|
||||
$(this.ids.add.dv).text(this.digitoVerificador($(this.ids.add.rut).val()))
|
||||
}
|
||||
$(this.ids.tipo).dropdown()
|
||||
$(this.ids.add.contacto.rut).on('input', (e) => {
|
||||
e.target.value = this.formatters().rut(e.target.value)
|
||||
$(this.ids.add.contacto.dv).text(this.digitoVerificador(e.target.value))
|
||||
})
|
||||
if ($(this.ids.add.contacto.rut).val().length > 0) {
|
||||
$(this.ids.add.contacto.rut).val(this.formatters().rut($(this.ids.add.contacto.rut).val()))
|
||||
$(this.ids.add.contacto.dv).text(this.digitoVerificador($(this.ids.add.contacto.rut).val()))
|
||||
}
|
||||
$(this.ids.add.contacto.telefono).on('input', (e) => {
|
||||
e.target.value = this.formatters().telefono(e.target.value)
|
||||
})
|
||||
if ($(this.ids.add.contacto.telefono).val().length > 0) {
|
||||
$(this.ids.add.contacto.telefono).val(this.formatters().telefono($(this.ids.add.contacto.telefono).val()))
|
||||
}
|
||||
$(this.ids.modal).modal({
|
||||
onApprove: () => {
|
||||
this.add().sociedad()
|
||||
}
|
||||
})
|
||||
$(this.ids.buttons.remove).click((e) => {
|
||||
this.remove().sociedad($(e.target).data('sociedad'))
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
proveedores.setup({
|
||||
modal: '#add_modal',
|
||||
buttons: {
|
||||
add: '#add_button',
|
||||
edit: '.edit',
|
||||
remove: '.remove'
|
||||
},
|
||||
add: {
|
||||
form: '#add_modal form.form',
|
||||
rut: '#rut',
|
||||
dv: '#dv',
|
||||
nombre: '#nombre',
|
||||
razon: '#razon',
|
||||
tipo: '#tipo',
|
||||
contacto: {
|
||||
rut: '#rut_contacto',
|
||||
dv: '#dv_contacto',
|
||||
nombre: '#nombre_contacto',
|
||||
apellido_paterno: '#apellido_paterno_contacto',
|
||||
apellido_materno: '#apellido_materno_contacto',
|
||||
email: '#email_contacto',
|
||||
telefono: '#telefono_contacto'
|
||||
}
|
||||
},
|
||||
proveedores: '#proveedores'
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -2,6 +2,11 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
class APIClient {
|
||||
static fetch(url, options=null) {
|
||||
return fetchAPI(url, options)
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null) {
|
||||
if (options === null) {
|
||||
options = {}
|
||||
|
26
app/resources/views/layout/body/scripts/rut.blade.php
Normal file
26
app/resources/views/layout/body/scripts/rut.blade.php
Normal file
@ -0,0 +1,26 @@
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class Rut {
|
||||
static digitoVerificador(rut) {
|
||||
if (rut.length === 0) {
|
||||
return ''
|
||||
}
|
||||
let M = 0, S = 1
|
||||
for (; rut; rut = Math.floor(rut / 10)) {
|
||||
S = (S + rut % 10 * (9 - M++ % 6)) % 11
|
||||
}
|
||||
return S ? S - 1 : 'K'
|
||||
}
|
||||
static format(rut) {
|
||||
if (rut.length === 0) {
|
||||
return ''
|
||||
}
|
||||
rut.replace(/\./g, '')
|
||||
return rut.replace(/^(\d{1,2})(\d{3})(\d{3})$/, '$1.$2.$3')
|
||||
}
|
||||
static validar(rut, digito) {
|
||||
return Rut.digitoVerificador(rut) === digito
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -656,9 +656,9 @@
|
||||
}
|
||||
add() {
|
||||
return {
|
||||
propietario: ({rut, nombre, proporcion, direccion, comuna, fecha, uf}) => {
|
||||
propietario: ({rut, nombre, proporcion, direccion, comuna, fecha}) => {
|
||||
const index = this.props.propietarios.length + 1
|
||||
const propietario = new Propietario({index, rut, nombre, proporcion, direccion, comuna, fecha, uf})
|
||||
const propietario = new Propietario({index, proporcion, rut, nombre, direccion, comuna, fecha})
|
||||
this.props.propietarios.push(propietario)
|
||||
this.add().factura(propietario)
|
||||
return propietario
|
||||
@ -691,6 +691,47 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
save() {
|
||||
return {
|
||||
factura: ({index}) => {
|
||||
const factura = this.props.facturas[index]
|
||||
if (factura.props.saved) {
|
||||
return
|
||||
}
|
||||
const url = '{{$urls->api}}/ventas/facturas/add'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('venta_id', this.props.id)
|
||||
body.set('index', (index+1).toString())
|
||||
const data = structuredClone(factura.props)
|
||||
delete data.index
|
||||
data.detalle.base = data.detalle.base.toFixed(0)
|
||||
data.detalle.terreno = data.detalle.terreno.toFixed(0)
|
||||
data.detalle.neto = data.detalle.neto.toFixed(0)
|
||||
data.detalle.iva = data.detalle.iva.toFixed(0)
|
||||
data.detalle.bruto = data.detalle.bruto.toFixed(0)
|
||||
data.detalle.total = data.detalle.total.toFixed(0)
|
||||
data.total.neto = data.total.neto.toFixed(0)
|
||||
data.total.exento = data.total.exento.toFixed(0)
|
||||
data.total.iva = data.total.iva.toFixed(0)
|
||||
data.total.total = data.total.total.toFixed(0)
|
||||
data.fecha = [data.fecha.getFullYear(), data.fecha.getMonth()+1, data.fecha.getDate()].join('-')
|
||||
data.uf.fecha = [data.uf.fecha.getFullYear(), data.uf.fecha.getMonth()+1, data.uf.fecha.getDate()].join('-')
|
||||
body.set('data', JSON.stringify(data))
|
||||
return fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.saved) {
|
||||
return
|
||||
}
|
||||
this.props.facturas[json.factura.index-1].props.saved = true
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Factura extends BaseObject {
|
||||
draw() {
|
||||
@ -699,6 +740,45 @@
|
||||
return '<div class="ui divider" data-index="'+index+'"></div>'
|
||||
},
|
||||
factura: ({proyecto, propietario, unidades, terreno, venta, uf, formatters = {date, pesos, ufs, percent}}) => {
|
||||
this.props.proporcion = propietario.props.proporcion
|
||||
this.props.emisor = {
|
||||
nombre: proyecto.inmobiliaria.nombre,
|
||||
rut: proyecto.inmobiliaria.rut,
|
||||
direccion: proyecto.direccion
|
||||
}
|
||||
this.props.receptor = {
|
||||
nombre: propietario.props.nombre,
|
||||
rut: propietario.props.rut,
|
||||
direccion: propietario.props.direccion,
|
||||
comuna: propietario.props.comuna
|
||||
}
|
||||
this.props.fecha = propietario.props.fecha
|
||||
this.props.unidades = []
|
||||
this.props.detalle = {
|
||||
base: venta.base * propietario.props.proporcion,
|
||||
terreno: venta.exento * propietario.props.proporcion,
|
||||
neto: venta.neto * propietario.props.proporcion,
|
||||
iva: venta.iva * propietario.props.proporcion,
|
||||
bruto: venta.bruto * propietario.props.proporcion,
|
||||
descuento: venta.descuento * propietario.props.proporcion,
|
||||
total: venta.total * propietario.props.proporcion
|
||||
}
|
||||
this.props.total = {
|
||||
neto: venta.neto * propietario.props.proporcion,
|
||||
exento: venta.exento * propietario.props.proporcion,
|
||||
iva: venta.iva * propietario.props.proporcion,
|
||||
total: venta.total * propietario.props.proporcion,
|
||||
}
|
||||
this.props.uf = uf
|
||||
unidades.forEach(unidad => {
|
||||
const descuento = terreno.reajustado * unidad.props.prorrateo
|
||||
const bruto = unidad.props.valor * uf.valor - descuento
|
||||
const neto = bruto / 1.19
|
||||
this.props.unidades.push({
|
||||
descripcion: unidad.props.tipo + ' ' + unidad.props.descripcion + ' (UF ' + formatters.ufs.format(unidad.props.valor * propietario.props.proporcion) + ')',
|
||||
precio: (neto * propietario.props.proporcion).toFixed(0)
|
||||
})
|
||||
})
|
||||
return [
|
||||
this.draw().divider(propietario.props.index),
|
||||
'<div class="factura" data-index="'+propietario.props.index+'">',
|
||||
@ -707,6 +787,7 @@
|
||||
this.draw().propietario({propietario, formatters}),
|
||||
this.draw().table({venta, unidades, propietario, terreno, uf, formatters}),
|
||||
this.draw().totales({propietario, venta, uf, formatters}),
|
||||
this.draw().guardar({index: propietario.props.index}),
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
@ -868,7 +949,7 @@
|
||||
'SUBTOTAL (Bruto): $' + formatters.pesos.format((venta.neto + venta.iva) * propietario.props.proporcion) + '<br />' +
|
||||
'Mas valor terreno: $' + ((venta.exento > 0) ? formatters.pesos.format(venta.exento * propietario.props.proporcion) : emptyTerreno) + '<br />' +
|
||||
'TOTAL (Escritura): $' + formatters.pesos.format(venta.total * propietario.props.proporcion) + '; ' + formatters.ufs.format(venta.totalUF * propietario.props.proporcion) + ' UF<br /><br />' +
|
||||
'Descuento Terreno: ' + ((venta.exento > 0) ? formatters.percent.format(venta.descuento * 100) : emptyTerreno) + '%<br /><br />' +
|
||||
'Descuento Terreno: ' + ((venta.exento > 0) ? formatters.percent.format(venta.descuento * propietario.props.proporcion * 100) : emptyTerreno) + '%<br /><br />' +
|
||||
'UF (' + formatters.date.format(uf.fecha) + '): $' + formatters.ufs.format(uf.valor),
|
||||
'1 UNID',
|
||||
formatters.pesos.format(venta.exento * propietario.props.proporcion),
|
||||
@ -920,6 +1001,28 @@
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
},
|
||||
guardar: ({index}) => {
|
||||
if (this.props.saved) {
|
||||
return [
|
||||
'<div class="row">',
|
||||
'<div class="fourteen wide column"></div>',
|
||||
'<div class="two wide center aligned column">',
|
||||
'<div class="ui green message">',
|
||||
'<i class="check icon"></i>',
|
||||
'Guardada',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
}
|
||||
return [
|
||||
'<div class="row">',
|
||||
'<div class="right aligned sixteen wide column">',
|
||||
`<button class="ui primary button guardar" data-index="${index}">Guardar</button>`,
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -942,6 +1045,10 @@
|
||||
},
|
||||
facturas: () => {
|
||||
document.getElementById(this.ids.facturas).innerHTML = this.venta.draw().facturas(this.formatters)
|
||||
$('button.guardar').click(clickEvent => {
|
||||
const index = clickEvent.currentTarget.getAttribute('data-index')
|
||||
facturas.venta.save().factura({index: index-1})
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -955,7 +1062,7 @@
|
||||
rut: '{{$venta->proyecto()->inmobiliaria()->rut()}}',
|
||||
nombre: '{{$venta->proyecto()->inmobiliaria()->nombreCompleto()}}'
|
||||
},
|
||||
direccion: '{{$venta->proyecto()->direccion()->simple()}}'
|
||||
direccion: '{{$venta->proyecto()->direccion()->simple()}}, {{$venta->proyecto()->direccion()->comuna->descripcion}}'
|
||||
},
|
||||
valor: {{$venta->valor}},
|
||||
uf: {
|
||||
@ -990,15 +1097,35 @@
|
||||
propietarios: [],
|
||||
facturas: []
|
||||
})
|
||||
this.venta.add().propietario({
|
||||
rut: '{{$venta->propietario()->rut()}}',
|
||||
nombre: '{{$venta->propietario()->nombreCompleto()}}',
|
||||
proporcion: 1,
|
||||
direccion: '{{$venta->propietario()->datos->direccion->simple()}}',
|
||||
comuna: '{{$venta->propietario()->datos->direccion->comuna->descripcion}}',
|
||||
fecha: new Date('{{$venta->currentEstado()->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
||||
uf: {{$uf}}
|
||||
})
|
||||
@if (count($facturas) > 0)
|
||||
this.venta.props.uf = {
|
||||
fecha: new Date('{{$facturas[0]->fechaUF->format('Y-m-d')}}'),
|
||||
valor: {{$facturas[0]->valorUF}}
|
||||
}
|
||||
@foreach ($facturas as $factura)
|
||||
this.venta.props.facturas[{{$factura->index-1}}] = new Factura(JSON.parse('{!! json_encode($factura) !!}'))
|
||||
this.venta.props.facturas[{{$factura->index-1}}].props.saved = true
|
||||
this.venta.props.propietarios[{{$factura->index-1}}] = new Propietario({
|
||||
index: {{$factura->index}},
|
||||
proporcion: {{$factura->proporcion}},
|
||||
rut: '{{$factura->receptorRut}}',
|
||||
nombre: '{{$factura->receptorNombre}}',
|
||||
direccion: '{{$factura->receptorDireccion}}',
|
||||
comuna: '{{$factura->receptorComuna}}',
|
||||
fecha: new Date('{{$factura->fecha->format('Y-m-d')}}'),
|
||||
})
|
||||
@endforeach
|
||||
@else
|
||||
this.venta.add().propietario({
|
||||
rut: '{{$venta->propietario()->rut()}}',
|
||||
nombre: '{{$venta->propietario()->nombreCompleto()}}',
|
||||
proporcion: 1,
|
||||
direccion: '{{$venta->propietario()->datos->direccion->simple()}}',
|
||||
comuna: '{{$venta->propietario()->datos->direccion->comuna->descripcion}}',
|
||||
fecha: new Date('{{$venta->currentEstado()->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
||||
uf: {{$uf}}
|
||||
})
|
||||
@endif
|
||||
this.draw().venta()
|
||||
this.draw().facturas()
|
||||
}
|
||||
|
Reference in New Issue
Block a user