Compare commits
44 Commits
2.1.21
...
c784d1bee9
Author | SHA1 | Date | |
---|---|---|---|
c784d1bee9 | |||
a1ade5c2c7 | |||
879b612493 | |||
b4cdd2d5f7 | |||
51cabee824 | |||
d2e51e76f8 | |||
1621d6fe30 | |||
0e32512adc | |||
338f290539 | |||
2aad7e1152 | |||
e542615128 | |||
1c7797b1b1 | |||
ba0d4073d7 | |||
faac3874a8 | |||
ade107ab3c | |||
c192cf1883 | |||
4fb75b11c4 | |||
ccbb71d875 | |||
7f25b4b5e1 | |||
f0b26a251b | |||
ea068d95d0 | |||
1ccc9ab3d4 | |||
5cd19bcdce | |||
712c70b34d | |||
35ab7e7e8b | |||
4b39f93f30 | |||
d3f188684a | |||
82647a171d | |||
e44ab30665 | |||
19333bc338 | |||
4738dae7c8 | |||
a370ffff43 | |||
88f9e539f7 | |||
671b26f038 | |||
e133bd36cf | |||
251dbbe0f0 | |||
e1eb2c4c56 | |||
1078f4c188 | |||
38962cb9cf | |||
3cd699d2e2 | |||
d8b8787be9 | |||
62edca5335 | |||
ac6c5b7d3d | |||
5b5a0ed1f5 |
@ -1,16 +1,19 @@
|
|||||||
FROM php:8.2-fpm
|
FROM php:8.2-cli
|
||||||
|
|
||||||
ENV TZ "America/Santiago"
|
ENV TZ "${TZ}"
|
||||||
|
ENV APP_NAME "${APP_NAME}"
|
||||||
|
ENV API_URL "${API_URL}"
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends cron && rm -r /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y --no-install-recommends cron rsyslog nano && rm -r /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN pecl install xdebug-3.2.2 \
|
RUN pecl install xdebug-3.2.2 \
|
||||||
&& docker-php-ext-enable xdebug
|
&& docker-php-ext-enable xdebug \
|
||||||
|
&& echo "#/bin/bash\nprintenv >> /etc/environment\ncron -f -L 11" > /root/entrypoint && chmod a+x /root/entrypoint
|
||||||
|
|
||||||
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
|
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
|
||||||
|
|
||||||
WORKDIR /code/bin
|
WORKDIR /code/bin
|
||||||
|
|
||||||
COPY ./cli/crontab /var/spool/cron/crontabs/root
|
COPY --chmod=644 ./cli/crontab /var/spool/cron/crontabs/root
|
||||||
|
|
||||||
CMD ["cron", "-f"]
|
CMD [ "/root/entrypoint" ]
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
namespace Incoviba\Common\Ideal\Cartola;
|
namespace Incoviba\Common\Ideal\Cartola;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
abstract class Banco implements Define\Cartola\Banco
|
abstract class Banco extends Service implements Define\Cartola\Banco
|
||||||
{
|
{
|
||||||
public function process(UploadedFileInterface $file): array
|
public function process(UploadedFileInterface $file): array
|
||||||
{
|
{
|
||||||
@ -14,12 +15,19 @@ abstract class Banco implements Define\Cartola\Banco
|
|||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
$r = [];
|
$r = [];
|
||||||
foreach ($columns as $old => $new) {
|
foreach ($columns as $old => $new) {
|
||||||
|
if (!isset($row[$old])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$r[$new] = $row[$old];
|
$r[$new] = $row[$old];
|
||||||
}
|
}
|
||||||
$temp []= $r;
|
$temp []= $r;
|
||||||
}
|
}
|
||||||
return $temp;
|
return $temp;
|
||||||
}
|
}
|
||||||
|
public function processMovimientosDiarios(array $movimientos): array
|
||||||
|
{
|
||||||
|
return $movimientos;
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected function columnMap(): array;
|
abstract protected function columnMap(): array;
|
||||||
abstract protected function parseFile(UploadedFileInterface $uploadedFile): array;
|
abstract protected function parseFile(UploadedFileInterface $uploadedFile): array;
|
||||||
|
@ -28,6 +28,12 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
|
|||||||
});
|
});
|
||||||
$app->get('[/]', [Ventas::class, 'pie']);
|
$app->get('[/]', [Ventas::class, 'pie']);
|
||||||
});
|
});
|
||||||
|
$app->group('/escritura', function($app) {
|
||||||
|
$app->get('/add[/]', [Ventas\Escrituras::class, 'add']);
|
||||||
|
});
|
||||||
|
$app->group('/credito', function($app) {
|
||||||
|
$app->get('[/]', [Ventas\Creditos::class, 'show']);
|
||||||
|
});
|
||||||
$app->get('/escriturar[/]', [Ventas::class, 'escriturar']);
|
$app->get('/escriturar[/]', [Ventas::class, 'escriturar']);
|
||||||
$app->get('/desistir[/]', [Ventas::class, 'desistir']);
|
$app->get('/desistir[/]', [Ventas::class, 'desistir']);
|
||||||
$app->get('/desistida[/]', [Ventas::class, 'desistida']);
|
$app->get('/desistida[/]', [Ventas::class, 'desistida']);
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\API\Contabilidad;
|
use Incoviba\Controller\API\Contabilidad\Cartolas;
|
||||||
|
|
||||||
$app->group('/cartolas', function($app) {
|
$app->group('/cartolas', function($app) {
|
||||||
$app->post('/procesar[/]', [Contabilidad::class, 'procesarCartola']);
|
$app->post('/procesar[/]', [Cartolas::class, 'procesar']);
|
||||||
});
|
});
|
||||||
$app->group('/cartola', function($app) {
|
$app->group('/cartola', function($app) {
|
||||||
$app->post('/exportar[/]', [Contabilidad::class, 'exportarCartola']);
|
$app->group('/diaria', function($app) {
|
||||||
|
$app->post('/ayer[/]', [Cartolas::class, 'ayer']);
|
||||||
|
$app->post('/procesar[/]', [Cartolas::class, 'diaria']);
|
||||||
|
});
|
||||||
|
$app->post('/exportar[/]', [Cartolas::class, 'exportar']);
|
||||||
});
|
});
|
||||||
|
7
app/resources/routes/api/contabilidad/daps.php
Normal file
7
app/resources/routes/api/contabilidad/daps.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
use Incoviba\Controller\API\Contabilidad\Depositos;
|
||||||
|
|
||||||
|
$app->group('/depositos', function($app) {
|
||||||
|
$app->post('/add[/]', [Depositos::class, 'add']);
|
||||||
|
$app->get('/inmobiliaria/{inmobiliaria_rut}[/]', [Depositos::class, 'inmobiliaria']);
|
||||||
|
});
|
@ -19,11 +19,20 @@ $app->group('/ventas', function($app) {
|
|||||||
$app->group('/escrituras', function($app) {
|
$app->group('/escrituras', function($app) {
|
||||||
$app->post('/estados[/]', [Ventas::class, 'escrituras']);
|
$app->post('/estados[/]', [Ventas::class, 'escrituras']);
|
||||||
});
|
});
|
||||||
|
$app->group('/by', function($app) {
|
||||||
|
$app->get('/unidad/{unidad_id}', [Ventas::class, 'unidad']);
|
||||||
|
});
|
||||||
$app->post('[/]', [Ventas::class, 'proyecto']);
|
$app->post('[/]', [Ventas::class, 'proyecto']);
|
||||||
});
|
});
|
||||||
$app->group('/venta/{venta_id}', function($app) {
|
$app->group('/venta/{venta_id}', function($app) {
|
||||||
$app->get('/unidades[/]', [Ventas::class, 'unidades']);
|
$app->get('/unidades[/]', [Ventas::class, 'unidades']);
|
||||||
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
|
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
|
||||||
|
$app->group('/escritura', function($app) {
|
||||||
|
$app->post('/add[/]', [Ventas\Escrituras::class, 'add']);
|
||||||
|
});
|
||||||
|
$app->group('/credito', function($app) {
|
||||||
|
$app->post('[/]', [Ventas\Creditos::class, 'edit']);
|
||||||
|
});
|
||||||
$app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
|
$app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
|
||||||
$app->group('/desistir', function($app) {
|
$app->group('/desistir', function($app) {
|
||||||
$app->get('/eliminar[/]', [Ventas::class, 'insistir']);
|
$app->get('/eliminar[/]', [Ventas::class, 'insistir']);
|
||||||
|
6
app/resources/routes/contabilidad/cartolas.php
Normal file
6
app/resources/routes/contabilidad/cartolas.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
use Incoviba\Controller\Contabilidad;
|
||||||
|
|
||||||
|
$app->group('/cartolas', function($app) {
|
||||||
|
$app->get('/diaria[/]', [Contabilidad::class, 'diaria']);
|
||||||
|
});
|
6
app/resources/routes/contabilidad/daps.php
Normal file
6
app/resources/routes/contabilidad/daps.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
use Incoviba\Controller\Contabilidad;
|
||||||
|
|
||||||
|
$app->group('/depositos', function($app) {
|
||||||
|
$app->get('[/]', [Contabilidad::class, 'depositos']);
|
||||||
|
});
|
10
app/resources/routes/contabilidad/informes.php
Normal file
10
app/resources/routes/contabilidad/informes.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
$app->group('/informes', function($app) {
|
||||||
|
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'informes']));
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if ($file->isDir()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
include_once $file->getRealPath();
|
||||||
|
}
|
||||||
|
});
|
6
app/resources/routes/contabilidad/informes/tesoreria.php
Normal file
6
app/resources/routes/contabilidad/informes/tesoreria.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
use Incoviba\Controller\Contabilidad;
|
||||||
|
|
||||||
|
$app->group('/tesoreria', function($app) {
|
||||||
|
$app->get('[/[{fecha}[/]]]', [Contabilidad::class, 'tesoreria']);
|
||||||
|
});
|
518
app/resources/views/contabilidad/cartolas/diaria.blade.php
Normal file
518
app/resources/views/contabilidad/cartolas/diaria.blade.php
Normal file
@ -0,0 +1,518 @@
|
|||||||
|
@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" />
|
||||||
|
{{--<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>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>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>
|
||||||
|
class Cartola {
|
||||||
|
idx
|
||||||
|
inmobiliaria = {
|
||||||
|
rut: 0,
|
||||||
|
razon: ''
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
const file_field = $('<div></div>').addClass('field').append(
|
||||||
|
$('<label></label>').attr('for', 'file' + this.idx).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')
|
||||||
|
)
|
||||||
|
fields.append(file_field)
|
||||||
|
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)
|
||||||
|
|
||||||
|
inmobiliarias_dropdown.dropdown({
|
||||||
|
fireOnInit: true,
|
||||||
|
onChange: (value, text, $choice) => {
|
||||||
|
this.inmobiliaria.rut = value
|
||||||
|
this.inmobiliaria.razon = text
|
||||||
|
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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
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']
|
||||||
|
fecha_calendar.calendar(cdo)
|
||||||
|
},
|
||||||
|
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></tr>').append(
|
||||||
|
$('<td></td>').html(this.inmobiliaria.razon)
|
||||||
|
).append(
|
||||||
|
$('<td></td>').html(this.cuenta.descripcion)
|
||||||
|
).append(
|
||||||
|
$('<td></td>').html(dateFormatter.format(row.fecha))
|
||||||
|
).append(
|
||||||
|
$('<td></td>').html(row.glosa)
|
||||||
|
).append(
|
||||||
|
$('<td></td>').addClass('right aligned').html(row.cargo === 0 ? '' : numberFormatter.format(row.cargo))
|
||||||
|
).append(
|
||||||
|
$('<td></td>').addClass('right aligned').html(row.abono === 0 ? '' : numberFormatter.format(row.abono))
|
||||||
|
).append(
|
||||||
|
$('<td></td>').addClass('right aligned').html(row.saldo === 0 ? '' : numberFormatter.format(row.saldo))
|
||||||
|
).append(
|
||||||
|
$('<td></td>').html(idx + 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@php
|
||||||
|
$columns = [
|
||||||
|
'sociedad',
|
||||||
|
'cuenta',
|
||||||
|
'fecha',
|
||||||
|
'glosa',
|
||||||
|
'cargo',
|
||||||
|
'abono',
|
||||||
|
'saldo',
|
||||||
|
'orden'
|
||||||
|
];
|
||||||
|
@endphp
|
||||||
|
const diaria = {
|
||||||
|
ids: {},
|
||||||
|
data: {
|
||||||
|
inmobiliarias: JSON.parse('{!! json_encode($inmobiliarias) !!}'),
|
||||||
|
cartolasIdx: [],
|
||||||
|
cartolas: [],
|
||||||
|
},
|
||||||
|
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']);})))}}],
|
||||||
|
width: '{{round((1/(count($columns) + 3 - 1)) * 100,2)}}%'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['sociedad', 'cuenta', 'glosa']);})))}}],
|
||||||
|
width: '{{round((1/(count($columns) + 3 - 1)) * 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]))
|
||||||
|
entry[1].movimientos.forEach((row, idx) => {
|
||||||
|
const fecha = new Date(row.fecha)
|
||||||
|
fecha.setDate(fecha.getDate() + 1)
|
||||||
|
this.data.cartolas[cartolaIdx].movimientos[idx] = {
|
||||||
|
fecha: fecha,
|
||||||
|
glosa: row.glosa,
|
||||||
|
documento: row.documento,
|
||||||
|
cargo: row.cargo,
|
||||||
|
abono: row.abono,
|
||||||
|
saldo: row.saldo
|
||||||
|
}
|
||||||
|
})
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(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'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
263
app/resources/views/contabilidad/depositos.blade.php
Normal file
263
app/resources/views/contabilidad/depositos.blade.php
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
@extends('layout.base')
|
||||||
|
|
||||||
|
@section('page_content')
|
||||||
|
<div class="ui container">
|
||||||
|
<h1 class="ui header">Depósitos a Plazo</h1>
|
||||||
|
</div>
|
||||||
|
<div class="ui stackable grid">
|
||||||
|
<div class="two wide column"></div>
|
||||||
|
<div class="twelve wide column">
|
||||||
|
<table class="ui table" id="depositos">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Inmobiliaria</th>
|
||||||
|
<th>Banco</th>
|
||||||
|
<th>N° Depósito</th>
|
||||||
|
<th>Capital</th>
|
||||||
|
<th>Inicio</th>
|
||||||
|
<th>Plazo</th>
|
||||||
|
<th>Vencimiento</th>
|
||||||
|
<th>Vencimiento ISO</th>
|
||||||
|
<th>Monto al Vencimiento</th>
|
||||||
|
<th>Tasa</th>
|
||||||
|
<th>
|
||||||
|
<button class="ui green icon button" id="add_button">
|
||||||
|
<i class="plus icon"></i>
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($activos as $deposito)
|
||||||
|
<tr>
|
||||||
|
<td>{{$deposito->cuenta->inmobiliaria->razon}}</td>
|
||||||
|
<td>{{$deposito->cuenta->banco->nombre}}</td>
|
||||||
|
<td>{{$deposito->id}}</td>
|
||||||
|
<td>{{$format->pesos($deposito->capital)}}</td>
|
||||||
|
<td>{{$deposito->inicio->format('d-m-Y')}}</td>
|
||||||
|
<td>{{$deposito->plazo()}}</td>
|
||||||
|
<td>{{$deposito->termino->format('d-m-Y')}}</td>
|
||||||
|
<td>{{$deposito->termino->format('Y-m-d')}}</td>
|
||||||
|
<td>{{$format->pesos($deposito->futuro)}}</td>
|
||||||
|
<td>{{$format->percent($deposito->tasa() * 100, 4)}}</td>
|
||||||
|
<td>
|
||||||
|
<button class="ui red icon button remove_button" data-deposito="{{$deposito->id}}">
|
||||||
|
<i class="remove icon"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
@foreach ($vencidos as $deposito)
|
||||||
|
<tr class="yellow">
|
||||||
|
<td>{{$deposito->cuenta->inmobiliaria->razon}}</td>
|
||||||
|
<td>{{$deposito->cuenta->banco->nombre}}</td>
|
||||||
|
<td>{{$deposito->id}}</td>
|
||||||
|
<td>{{$format->pesos($deposito->capital)}}</td>
|
||||||
|
<td>{{$deposito->inicio->format('d-m-Y')}}</td>
|
||||||
|
<td>{{$deposito->plazo()}}</td>
|
||||||
|
<td>{{$deposito->termino->format('d-m-Y')}}</td>
|
||||||
|
<td>{{$deposito->termino->format('Y-m-d')}}</td>
|
||||||
|
<td>{{$format->pesos($deposito->futuro)}}</td>
|
||||||
|
<td>{{$format->percent($deposito->tasa() * 100, 4)}}</td>
|
||||||
|
<td>
|
||||||
|
<button class="ui red icon button remove_button" data-deposito="{{$deposito->id}}">
|
||||||
|
<i class="remove icon"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ui modal" id="add_modal">
|
||||||
|
<div class="content">
|
||||||
|
<form class="ui form" id="add_form">
|
||||||
|
<div class="two fields">
|
||||||
|
<div class="field">
|
||||||
|
<label for="inmobiliaria">Inmobiliaria</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="field">
|
||||||
|
<label for="banco">Banco</label>
|
||||||
|
<div class="ui search selection 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>
|
||||||
|
<div class="three wide field">
|
||||||
|
<label for="identificador">N° Depósito</label>
|
||||||
|
<input type="text" id="identificador" name="id" />
|
||||||
|
</div>
|
||||||
|
<div class="three fields">
|
||||||
|
<div class="field">
|
||||||
|
<label for="capital">Capital</label>
|
||||||
|
<input type="number" id="capital" name="capital" />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="futuro">Monto al Vencimiento</label>
|
||||||
|
<input type="number" id="futuro" name="futuro" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="two fields">
|
||||||
|
<div class="field">
|
||||||
|
<label for="inicio">Inicio</label>
|
||||||
|
<div class="ui calendar" id="inicio">
|
||||||
|
<div class="ui left icon input">
|
||||||
|
<i class="calendar icon"></i>
|
||||||
|
<input type="text" name="inicio" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="termino">Vencimiento</label>
|
||||||
|
<div class="ui calendar" id="termino">
|
||||||
|
<div class="ui left icon input">
|
||||||
|
<i class="calendar icon"></i>
|
||||||
|
<input type="text" name="termino" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button class="ui approve button">Agregar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@include('layout.head.styles.datatables')
|
||||||
|
@include('layout.body.scripts.datatables')
|
||||||
|
|
||||||
|
@push('page_scripts')
|
||||||
|
<script>
|
||||||
|
const depositos = {
|
||||||
|
ids: {},
|
||||||
|
data: {
|
||||||
|
inmobiliaria: {
|
||||||
|
rut: 0,
|
||||||
|
razon: ''
|
||||||
|
},
|
||||||
|
banco: {
|
||||||
|
id: 0,
|
||||||
|
nombre: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return {
|
||||||
|
bancos: inmobiliaria_rut => {
|
||||||
|
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/cuentas'
|
||||||
|
return fetchAPI(url).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return response.json().then(json => {
|
||||||
|
if (json.cuentas.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$(this.ids.forms.add.bancos).dropdown('change values', json.cuentas.map(cuenta => {
|
||||||
|
return {value: cuenta.banco.id, text: cuenta.banco.nombre, name: cuenta.banco.nombre}
|
||||||
|
})).dropdown('refresh')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
add() {
|
||||||
|
return {
|
||||||
|
deposito: form => {
|
||||||
|
const url = '{{$urls->api}}/contabilidad/depositos/add'
|
||||||
|
const body = new FormData(form)
|
||||||
|
const inicio = $(this.ids.forms.add.inicio).calendar('get date')
|
||||||
|
const termino = $(this.ids.forms.add.termino).calendar('get date')
|
||||||
|
body.set('inicio', [inicio.getFullYear(), inicio.getMonth()+1, inicio.getDate()].join('-'))
|
||||||
|
body.set('termino', [termino.getFullYear(), termino.getMonth()+1, termino.getDate()].join('-'))
|
||||||
|
|
||||||
|
return fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return response.json().then(json => {
|
||||||
|
if (json.status) {
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setup(ids) {
|
||||||
|
this.ids = ids
|
||||||
|
|
||||||
|
$(this.ids.buttons.add).click(event => {
|
||||||
|
$(this.ids.modals.add).modal('show')
|
||||||
|
})
|
||||||
|
$(this.ids.modals.add).modal({
|
||||||
|
onApprove: $element => {
|
||||||
|
$(this.ids.forms.add.base).submit()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$(this.ids.forms.add.base).submit(event => {
|
||||||
|
event.preventDefault()
|
||||||
|
this.add().deposito(event.currentTarget)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
$(this.ids.forms.add.inmobiliarias).dropdown({
|
||||||
|
fireOnInit: true,
|
||||||
|
onChange: (value, text, $choice) => {
|
||||||
|
this.data.inmobiliaria.rut = value
|
||||||
|
this.data.inmobiliaria.razon = text
|
||||||
|
this.get().bancos(value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$(this.ids.forms.add.banco).dropdown({
|
||||||
|
fireOnInit: true,
|
||||||
|
onChange: (value, text, $choice) => {
|
||||||
|
this.data.banco.id = value
|
||||||
|
this.data.banco.nombre = text
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$(this.ids.forms.add.inicio).calendar(calendar_date_options)
|
||||||
|
$(this.ids.forms.add.termino).calendar(calendar_date_options)
|
||||||
|
|
||||||
|
$(this.ids.table).dataTable({
|
||||||
|
columnDefs: [{target: 7, visible: false, searchable: false}],
|
||||||
|
order: [[7, 'desc'], [0, 'asc']]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(document).ready(() => {
|
||||||
|
depositos.setup({
|
||||||
|
table: '#depositos',
|
||||||
|
buttons: {
|
||||||
|
add: '#add_button'
|
||||||
|
},
|
||||||
|
modals: {
|
||||||
|
add: '#add_modal'
|
||||||
|
},
|
||||||
|
forms: {
|
||||||
|
add: {
|
||||||
|
base: '#add_form',
|
||||||
|
inmobiliarias: '#inmobiliaria',
|
||||||
|
bancos: '#banco',
|
||||||
|
inicio: '#inicio',
|
||||||
|
termino: '#termino'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
147
app/resources/views/contabilidad/informes/tesoreria.blade.php
Normal file
147
app/resources/views/contabilidad/informes/tesoreria.blade.php
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
@extends('layout.base')
|
||||||
|
|
||||||
|
@section('page_content')
|
||||||
|
<div class="ui container">
|
||||||
|
<h1 class="ui centered header">Informe de Tesorería</h1>
|
||||||
|
<h4 class="ui centered sub header">{{$fecha->format('d M Y')}}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="four wide column">
|
||||||
|
<table class="ui collapsing simple table">
|
||||||
|
<tr>
|
||||||
|
<td>Informe anterior</td>
|
||||||
|
<td>{{$anterior->format('d/m/Y')}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Informe actual</td>
|
||||||
|
<td>{{$fecha->format('d/m/Y')}}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="column"></div>
|
||||||
|
<div class="four wide column">
|
||||||
|
<table class="ui collapsing simple table">
|
||||||
|
<tr>
|
||||||
|
<td>Valor UF</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($UF->get($fecha), 2)}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Valor Dólar</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($USD->get($fecha), 2)}}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<table class="ui striped table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>EMPRESA</th>
|
||||||
|
<th>Banco</th>
|
||||||
|
<th>Cuenta</th>
|
||||||
|
<th class="right aligned">Saldo Anterior</th>
|
||||||
|
<th class="right aligned">Saldo Actual</th>
|
||||||
|
<th class="right aligned">Diferencia</th>
|
||||||
|
<th class="right aligned">FFMM</th>
|
||||||
|
<th class="right aligned">DAP</th>
|
||||||
|
<th class="right aligned">Saldo Empresa</th>
|
||||||
|
<th class="right aligned">Total Cuentas</th>
|
||||||
|
<th class="right aligned">Total FFMM</th>
|
||||||
|
<th class="right aligned">Total DAP</th>
|
||||||
|
<th class="right aligned">Caja Total</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($informes['inmobiliarias'] as $inmobiliaria_rut => $informe)
|
||||||
|
@foreach ($informe->cuentas as $i => $cuenta)
|
||||||
|
<tr>
|
||||||
|
@if ($i === 0)
|
||||||
|
<td rowspan="{{count($informe->cuentas)}}">{{$informe->inmobiliaria->razon}}</td>
|
||||||
|
@endif
|
||||||
|
<td>{{$cuenta->banco}}</td>
|
||||||
|
<td>{{$cuenta->numero}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($cuenta->anterior)}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($cuenta->actual)}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($cuenta->diferencia())}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($cuenta->ffmm)}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($cuenta->deposito)}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($cuenta->saldo())}}</td>
|
||||||
|
@if ($i === 0)
|
||||||
|
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->total())}}</td>
|
||||||
|
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->ffmm())}}</td>
|
||||||
|
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->deposito())}}</td>
|
||||||
|
<td class="right aligned" rowspan="{{count($informe->cuentas)}}">{{$format->pesos($informe->caja())}}</td>
|
||||||
|
@endif
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr class="bold">
|
||||||
|
<th colspan="3">TOTAL</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->anterior)}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->actual)}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->diferencia())}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->ffmm)}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->deposito)}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->saldo())}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->cuentas())}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->ffmms())}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->depositos())}}</th>
|
||||||
|
<th class="right aligned">{{$format->pesos($informes['totales']->caja())}}</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
<table class="ui table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>EMPRESA</th>
|
||||||
|
<th class="right aligned">INGRESOS</th>
|
||||||
|
<th class="right aligned">EGRESOS</th>
|
||||||
|
<th>FECHA</th>
|
||||||
|
<th>BANCO</th>
|
||||||
|
<th>DESCRIPCIÓN</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($informes['movimientos'] as $tipo => $movimientos)
|
||||||
|
@if ($tipo === 'capital dap')
|
||||||
|
@if (count($movimientos['ingresos']) === 0 and count($movimientos['egresos']) === 0)
|
||||||
|
@continue
|
||||||
|
@endif
|
||||||
|
<tr class="grey">
|
||||||
|
<td colspan="6">{{strtoupper($tipo)}}</td>
|
||||||
|
</tr>
|
||||||
|
@foreach ($movimientos as $t => $ms)
|
||||||
|
@foreach ($ms as $movimiento)
|
||||||
|
<tr>
|
||||||
|
<td >{{$movimiento->cuenta->inmobiliaria->razon}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($movimiento->abono)}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($movimiento->cargo)}}</td>
|
||||||
|
<td>{{$movimiento->fecha->format('d/m/Y')}}</td>
|
||||||
|
<td>{{$movimiento->cuenta->banco->nombre}}</td>
|
||||||
|
<td>{{$movimiento->glosa}}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
@endforeach
|
||||||
|
@continue
|
||||||
|
@endif
|
||||||
|
@if (count($movimientos) === 0)
|
||||||
|
@continue
|
||||||
|
@endif
|
||||||
|
<tr class="grey">
|
||||||
|
<td colspan="6">{{strtoupper($tipo)}}</td>
|
||||||
|
</tr>
|
||||||
|
@foreach ($movimientos as $movimiento)
|
||||||
|
<tr>
|
||||||
|
<td >{{$movimiento->cuenta->inmobiliaria->razon}}</td>
|
||||||
|
<td class="right aligned">{{$format->pesos($movimiento->abono)}}</td>
|
||||||
|
<td class="red right aligned">{{$format->pesos($movimiento->cargo)}}</td>
|
||||||
|
<td>{{$movimiento->fecha->format('d/m/Y')}}</td>
|
||||||
|
<td>{{$movimiento->cuenta->banco->nombre}}</td>
|
||||||
|
<td>{{$movimiento->glosa}}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@endsection
|
@ -2,6 +2,13 @@
|
|||||||
Contabilidad
|
Contabilidad
|
||||||
<i class="dropdown icon"></i>
|
<i class="dropdown icon"></i>
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
|
<div class="item">
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
Informes
|
||||||
|
<div class="menu">
|
||||||
|
<a class="item" href="{{$urls->base}}/contabilidad/informes/tesoreria/{{$hoy->sub(new DateInterval('P1D'))->format('Y-m-d')}}">Tesorería</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<i class="dropdown icon"></i>
|
<i class="dropdown icon"></i>
|
||||||
<a class="text" href="{{$urls->base}}/contabilidad/centros_costos">Centros de Costos</a>
|
<a class="text" href="{{$urls->base}}/contabilidad/centros_costos">Centros de Costos</a>
|
||||||
@ -9,5 +16,7 @@
|
|||||||
<a class="item" href="{{$urls->base}}/contabilidad/centros_costos/asignar">Asignar en Cartola</a>
|
<a class="item" href="{{$urls->base}}/contabilidad/centros_costos/asignar">Asignar en Cartola</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<a class="item" href="{{$urls->base}}/contabilidad/cartolas/diaria">Cartola Diaria</a>
|
||||||
|
<a class="item" href="{{$urls->base}}/contabilidad/depositos">Depósitos a Plazo</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<form id="search_form" class="ui form" action="{{$urls->base}}/search" method="post">
|
<form id="search_form" class="ui form" action="{{$urls->base}}/search" method="post">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="ui fluid input" data-tooltip="Para buscar frases se deben encerrar entre comillas. ej, 'portal la viña' o "portal la viña"" data-position="bottom left">
|
<div class="ui fluid input" data-tooltip="Para buscar frases se deben encerrar entre comillas. ej, 'portal la viña' o "portal la viña"" data-position="top right">
|
||||||
<input type="text" name="query" />
|
<input type="text" name="query" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -56,7 +56,7 @@
|
|||||||
unidad.html(unidad.html() + ' (I)')
|
unidad.html(unidad.html() + ' (I)')
|
||||||
}
|
}
|
||||||
propietario = $('<a></a>')
|
propietario = $('<a></a>')
|
||||||
.attr('href','{{$urls->base}}/search/' + encodeURIComponent(this.venta.propietario.nombre_completo) + '/propietario')
|
.attr('href','{{$urls->base}}/search/"' + encodeURIComponent(this.venta.propietario.nombre_completo) + '"/propietario')
|
||||||
.html(this.venta.propietario.nombre_completo)
|
.html(this.venta.propietario.nombre_completo)
|
||||||
fecha = dateFormatter.format(new Date(this.venta.fecha))
|
fecha = dateFormatter.format(new Date(this.venta.fecha))
|
||||||
if (typeof this.venta.entrega !== 'undefined') {
|
if (typeof this.venta.entrega !== 'undefined') {
|
||||||
@ -309,15 +309,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
set: function() {
|
||||||
|
return {
|
||||||
|
query: value => {
|
||||||
|
$("[name='query']").val(value)
|
||||||
|
this.get().results()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
setup: function(id) {
|
setup: function(id) {
|
||||||
this.id = id
|
this.id = id
|
||||||
this.get().results()
|
this.get().results()
|
||||||
|
|
||||||
$('#tipo').dropdown().dropdown('set selected', '*')
|
$('#tipo').dropdown().dropdown('set selected', '*')
|
||||||
@if (trim($post) !== '')
|
@if (trim($post) !== '')
|
||||||
$("[name='query']").val('{{$post}}')
|
this.set().query('{!! $post !!}')
|
||||||
@elseif (trim($query) !== '')
|
@elseif (trim($query) !== '')
|
||||||
$("[name='query']").val('{{$query}}')
|
this.set().query('{!! $query !!}')
|
||||||
@endif
|
@endif
|
||||||
@if (trim($tipo) !== '')
|
@if (trim($tipo) !== '')
|
||||||
$('#tipo').dropdown('set selected', '{{$tipo}}')
|
$('#tipo').dropdown('set selected', '{{$tipo}}')
|
||||||
|
@ -349,7 +349,7 @@
|
|||||||
const lines = [
|
const lines = [
|
||||||
'<label for="rut">RUT</label>',
|
'<label for="rut">RUT</label>',
|
||||||
'<div class="inline field">',
|
'<div class="inline field">',
|
||||||
'<input type="text" id="rut" name="rut" />',
|
'<input type="text" id="rut" name="rut" placeholder="00000000-0" />',
|
||||||
'<span class="ui error message" id="alert_rut">',
|
'<span class="ui error message" id="alert_rut">',
|
||||||
'<i class="exclamation triangle icon"></i>',
|
'<i class="exclamation triangle icon"></i>',
|
||||||
'RUT Inválido',
|
'RUT Inválido',
|
||||||
@ -358,25 +358,25 @@
|
|||||||
'<label for="nombres">Nombre</label>',
|
'<label for="nombres">Nombre</label>',
|
||||||
'<div class="inline fields">',
|
'<div class="inline fields">',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="nombres" id="nombres" />',
|
'<input type="text" name="nombres" id="nombres" placeholder="Nombre(s)" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="apellido_paterno" />',
|
'<input type="text" name="apellido_paterno" placeholder="Apellido Paterno" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="apellido_materno" />',
|
'<input type="text" name="apellido_materno" placeholder="Apellido Materno" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<label for="calle">Dirección</label>',
|
'<label for="calle">Dirección</label>',
|
||||||
'<div class="inline fields">',
|
'<div class="inline fields">',
|
||||||
'<div class="eight wide field">',
|
'<div class="eight wide field">',
|
||||||
'<input type="text" name="calle" id="calle" size="16" />',
|
'<input type="text" name="calle" id="calle" size="16" placeholder="Calle" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="numero" size="5" />',
|
'<input type="text" name="numero" size="5" placeholder="Número" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="field">',
|
'<div class="field">',
|
||||||
'<input type="text" name="extra" />',
|
'<input type="text" name="extra" placeholder="Otros Detalles" />',
|
||||||
'</div>',
|
'</div>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="inline fields">',
|
'<div class="inline fields">',
|
||||||
|
294
app/resources/views/ventas/creditos.blade.php
Normal file
294
app/resources/views/ventas/creditos.blade.php
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
@extends('ventas.base')
|
||||||
|
|
||||||
|
@section('venta_subtitle')
|
||||||
|
Crédito
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('venta_content')
|
||||||
|
@php($credito = $venta->formaPago()->credito)
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="two wide column">Fecha</div>
|
||||||
|
<div class="six wide column" id="fecha" data-status="static">
|
||||||
|
<span id="fecha_data">
|
||||||
|
{{$credito->pago->fecha->format('d-m-Y')}}
|
||||||
|
</span>
|
||||||
|
<a href="#" id="fecha_edit">
|
||||||
|
<i class="edit icon"></i>
|
||||||
|
</a>
|
||||||
|
<div class="ui calendar hidden" id="fecha_input">
|
||||||
|
<div class="ui left icon input">
|
||||||
|
<i class="calendar icon"></i>
|
||||||
|
<input type="text" name="fecha" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="two wide column">Banco</div>
|
||||||
|
<div class="six wide column" id="banco" data-status="static">
|
||||||
|
<span id="banco_data">
|
||||||
|
@if (isset($credito->pago->banco))
|
||||||
|
{{$credito->pago->banco->nombre}}
|
||||||
|
@else
|
||||||
|
No definido
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
<a href="#" id="banco_edit">
|
||||||
|
<i class="edit icon"></i>
|
||||||
|
</a>
|
||||||
|
<div class="ui search selection dropdown hidden" id="banco_input">
|
||||||
|
<input type="hidden" name="banco" />
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
<div class="default text">Banco</div>
|
||||||
|
<div class="menu">
|
||||||
|
@foreach ($bancos as $banco)
|
||||||
|
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="two wide column">Valor</div>
|
||||||
|
<div class="six wide column" id="valor" data-status="static">
|
||||||
|
<span id="valor_data">
|
||||||
|
{{$format->ufs($credito->pago->valor())}}
|
||||||
|
</span>
|
||||||
|
<a href="#" id="valor_edit">
|
||||||
|
<i class="edit icon"></i>
|
||||||
|
</a>
|
||||||
|
<div class="ui right labeled input hidden" id="valor_input">
|
||||||
|
<input type="text" name="valor" />
|
||||||
|
<div class="ui basic label">UF</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('page_styles')
|
||||||
|
<style>
|
||||||
|
.hidden {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@endpush
|
||||||
|
@push('page_scripts')
|
||||||
|
<script>
|
||||||
|
const credito = {
|
||||||
|
ids: {},
|
||||||
|
data: {
|
||||||
|
venta: {{$venta->id}},
|
||||||
|
credito: {{$credito->id}},
|
||||||
|
fecha: new Date({{$credito->pago->fecha->format('Y')}},
|
||||||
|
{{$credito->pago->fecha->format('m')}}+1,
|
||||||
|
{{$credito->pago->fecha->format('d')}}),
|
||||||
|
banco: {
|
||||||
|
@if (isset($credito->pago->banco))
|
||||||
|
id: {{$credito->pago->banco->id}},
|
||||||
|
nombre: '{{$credito->pago->banco->nombre}}'
|
||||||
|
@else
|
||||||
|
id: 0,
|
||||||
|
nombre: ''
|
||||||
|
@endif
|
||||||
|
},
|
||||||
|
valor: {{$credito->pago->valor()}},
|
||||||
|
bancos: JSON.parse('{!! json_encode($bancos) !!}')
|
||||||
|
},
|
||||||
|
elements: {},
|
||||||
|
change() {
|
||||||
|
return {
|
||||||
|
status: (id, status) => {
|
||||||
|
this.elements[id].dataset.status = status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hide() {
|
||||||
|
return {
|
||||||
|
data: id => {
|
||||||
|
this.elements[id + '.data'].innerHTML = ''
|
||||||
|
this.elements[id + '.data'].classList.add('hidden')
|
||||||
|
this.elements[id + '.data'].hidden = true
|
||||||
|
},
|
||||||
|
input: id => {
|
||||||
|
this.elements[id + '.input'].classList.add('hidden')
|
||||||
|
this.elements[id + '.input'].hidden = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
show() {
|
||||||
|
return {
|
||||||
|
data: id => {
|
||||||
|
this.elements[id + '.data'].classList.remove('hidden')
|
||||||
|
this.elements[id + '.data'].hidden = false
|
||||||
|
},
|
||||||
|
input: id => {
|
||||||
|
this.elements[id + '.input'].classList.remove('hidden')
|
||||||
|
this.elements[id + '.input'].hidden = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
draw() {
|
||||||
|
return {
|
||||||
|
edit: (id) => {
|
||||||
|
this.change().status(id, 'edit')
|
||||||
|
this.show().input(id)
|
||||||
|
this.update()[id]()
|
||||||
|
},
|
||||||
|
static: (id, text) => {
|
||||||
|
this.change().status(id, 'static')
|
||||||
|
this.hide().input(id)
|
||||||
|
this.elements[this.ids.fields[id] + '.data'].innerHTML = this.format()[id](text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
send(id, value) {
|
||||||
|
const url = '{{$urls->api}}/venta/{{$venta->id}}/credito'
|
||||||
|
const body = new FormData()
|
||||||
|
body.set(id, value)
|
||||||
|
return fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return response.json().then(json => {
|
||||||
|
if (!json.status) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.data.fecha = new Date(json.credito.pago.fecha)
|
||||||
|
this.data.banco.id = json.credito.pago.banco.id
|
||||||
|
this.data.banco.nombre = json.credito.pago.banco.nombre
|
||||||
|
this.data.valor = json.credito.pago.valor / json.credito.pago.uf
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
edit() {
|
||||||
|
return {
|
||||||
|
fecha: fecha => {
|
||||||
|
this.send('fecha', fecha).then(() => {
|
||||||
|
this.draw().static('fecha', this.data.fecha)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
banco: banco_id => {
|
||||||
|
this.send('banco', banco_id).then(() => {
|
||||||
|
this.draw().static('banco', this.data.banco.nombre)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
valor: valor => {
|
||||||
|
this.send('valor', valor).then(() => {
|
||||||
|
this.draw().static('valor', this.data.valor)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
format() {
|
||||||
|
return {
|
||||||
|
fecha: value => {
|
||||||
|
const dateFormatter = new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: 'numeric', day: 'numeric'})
|
||||||
|
return dateFormatter.format(value)
|
||||||
|
},
|
||||||
|
banco: value => {
|
||||||
|
if (value === '') {
|
||||||
|
value = 'No definido'
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
},
|
||||||
|
valor: value => {
|
||||||
|
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||||
|
return numberFormatter.format(value) + ' UF'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update() {
|
||||||
|
return {
|
||||||
|
fecha: () => {
|
||||||
|
const $fecha = $(this.elements.fecha.querySelector('div.ui.calendar'))
|
||||||
|
$fecha.calendar('set date', this.data.fecha)
|
||||||
|
$fecha.calendar('focus')
|
||||||
|
},
|
||||||
|
banco: () => {
|
||||||
|
const $dropdown = $(this.elements.banco.querySelector('div.ui.dropdown'))
|
||||||
|
$dropdown.dropdown('clear')
|
||||||
|
if (this.data.banco.id !== 0) {
|
||||||
|
$dropdown.dropdown('set selected', this.data.banco.id)
|
||||||
|
}
|
||||||
|
$dropdown.dropdown('toggle')
|
||||||
|
},
|
||||||
|
valor: () => {
|
||||||
|
const input = this.elements.valor.querySelector('input')
|
||||||
|
input.value = this.data.valor ?? ''
|
||||||
|
input.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch(id) {
|
||||||
|
this.elements[id + '.edit'].addEventListener('click', event => {
|
||||||
|
const elem = event.currentTarget.parentNode
|
||||||
|
const id = elem.id
|
||||||
|
const status = elem.dataset.status
|
||||||
|
if (status !== 'static') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.draw().edit(id)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
register(name, elem_id) {
|
||||||
|
this.elements[name] = document.getElementById(elem_id)
|
||||||
|
},
|
||||||
|
setup(ids) {
|
||||||
|
this.ids = ids
|
||||||
|
|
||||||
|
Object.entries(this.ids.fields).forEach(entry => {
|
||||||
|
const name = entry[0]
|
||||||
|
const field = entry[1]
|
||||||
|
this.register(name, field)
|
||||||
|
this.register(name + '.data', field + '_data')
|
||||||
|
this.register(name + '.input', field + '_input')
|
||||||
|
this.register(name + '.edit', field + '_edit')
|
||||||
|
this.watch(field)
|
||||||
|
})
|
||||||
|
calendar_date_options['onChange'] = (date, text, mode) => {
|
||||||
|
if (date === this.data.fecha) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.edit().fecha([date.getFullYear(), date.getMonth()+1, date.getDate()].join('-'))
|
||||||
|
}
|
||||||
|
calendar_date_options['onHide'] = () => {
|
||||||
|
this.draw().static('fecha', this.data.fecha)
|
||||||
|
}
|
||||||
|
$(this.elements.fecha).find('div.ui.calendar').calendar(calendar_date_options)
|
||||||
|
$(this.elements.banco).find('div.ui.dropdown').dropdown({
|
||||||
|
onChange: (value, text, $element) => {
|
||||||
|
if (value === '' || value === this.data.banco.id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.edit().banco(value)
|
||||||
|
},
|
||||||
|
onHide: () => {
|
||||||
|
this.draw().static('banco', this.data.banco.nombre)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.elements.valor.querySelector('input').addEventListener('blur', event => {
|
||||||
|
let valor = event.currentTarget.value
|
||||||
|
if (valor.includes(',')) {
|
||||||
|
valor = valor.replaceAll('.', '').replace(',', '.')
|
||||||
|
}
|
||||||
|
if (parseFloat(valor) === this.data.valor) {
|
||||||
|
this.draw().static('valor', this.data.valor)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.edit().fecha(valor)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(document).ready(() => {
|
||||||
|
credito.setup({
|
||||||
|
fields: {
|
||||||
|
fecha: 'fecha',
|
||||||
|
banco: 'banco',
|
||||||
|
valor: 'valor'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
153
app/resources/views/ventas/escrituras/add.blade.php
Normal file
153
app/resources/views/ventas/escrituras/add.blade.php
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
@extends('ventas.base')
|
||||||
|
|
||||||
|
@section('venta_subtitle')
|
||||||
|
Agregar Abono en Escritura
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('venta_content')
|
||||||
|
<div class="ui basic segment">
|
||||||
|
<p>Valor Promesa {{$format->ufs($venta->valor)}}</p>
|
||||||
|
@if (isset($venta->formaPago()->pie))
|
||||||
|
<p>Valor Anticipo {{$format->ufs($venta->formaPago()->pie->valor)}}</p>
|
||||||
|
@endif
|
||||||
|
@if (isset($venta->formaPago()->credito))
|
||||||
|
<p>Crédito {{$format->ufs($venta->formaPago()->credito->pago->valor())}}</p>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
<form class="ui form" id="add_form">
|
||||||
|
<div class="three 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="fields">
|
||||||
|
<div class="field">
|
||||||
|
<label for="valor">Valor</label>
|
||||||
|
<div class="ui labeled input" id="valor">
|
||||||
|
<div class="ui basic label">$</div>
|
||||||
|
<input type="text" name="valor" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui checkbox" id="uf">
|
||||||
|
<input type="checkbox" name="uf" />
|
||||||
|
<label>Valor en UFs</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="fields">
|
||||||
|
<div class="three wide field">
|
||||||
|
<label for="bancos">Banco</label>
|
||||||
|
<div class="ui search selection dropdown" id="bancos">
|
||||||
|
<input type="hidden" name="banco" />
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
<div class="default text">Banco</div>
|
||||||
|
<div class="menu">
|
||||||
|
@foreach ($bancos as $banco)
|
||||||
|
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="fields">
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui radio checkbox">
|
||||||
|
<input type="radio" name="tipo" value="1" checked="checked" />
|
||||||
|
<label>Cheque</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui radio checkbox">
|
||||||
|
<input type="radio" name="tipo" value="3" />
|
||||||
|
<label>Vale Vista</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="ui button">Agregar</button>
|
||||||
|
</form>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('page_scripts')
|
||||||
|
<script>
|
||||||
|
const escritura = {
|
||||||
|
ids: {},
|
||||||
|
add() {
|
||||||
|
return {
|
||||||
|
escritura: event => {
|
||||||
|
event.preventDefault()
|
||||||
|
const body = new FormData(event.currentTarget)
|
||||||
|
const fecha = $(this.ids.fecha).calendar('get date')
|
||||||
|
body.set('fecha', [fecha.getFullYear(), fecha.getMonth()+1, fecha.getDate()].join('-'))
|
||||||
|
const status = $(this.ids.checkbox).checkbox('is checked')
|
||||||
|
body.set('uf', status)
|
||||||
|
|
||||||
|
const url = '{{$urls->api}}/venta/{{$venta->id}}/escritura/add'
|
||||||
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return response.json().then(json => {
|
||||||
|
if (json.status) {
|
||||||
|
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggle() {
|
||||||
|
return {
|
||||||
|
checkbox: () => {
|
||||||
|
const status = $(this.ids.checkbox).checkbox('is checked')
|
||||||
|
if (status) {
|
||||||
|
return this.toggle().uf()
|
||||||
|
}
|
||||||
|
return this.toggle().pesos()
|
||||||
|
},
|
||||||
|
uf: () => {
|
||||||
|
const valor = $(this.ids.valor)
|
||||||
|
valor.attr('class', 'ui right labeled input')
|
||||||
|
valor.find('.label').remove()
|
||||||
|
valor.append(
|
||||||
|
$('<div></div>').addClass('ui basic label').html('UF')
|
||||||
|
)
|
||||||
|
},
|
||||||
|
pesos: () => {
|
||||||
|
const valor = $(this.ids.valor)
|
||||||
|
valor.attr('class', 'ui labeled input')
|
||||||
|
valor.find('.label').remove()
|
||||||
|
valor.prepend(
|
||||||
|
$('<div></div>').addClass('ui basic label').html('$')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setup(ids) {
|
||||||
|
this.ids = ids
|
||||||
|
|
||||||
|
$(this.ids.fecha).calendar(calendar_date_options)
|
||||||
|
$(this.ids.checkbox).checkbox({
|
||||||
|
fireOnInit: true,
|
||||||
|
onChange: this.toggle().checkbox
|
||||||
|
})
|
||||||
|
$(this.ids.bancos).dropdown()
|
||||||
|
$(this.ids.form).submit(this.add().escritura)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(document).ready(() => {
|
||||||
|
escritura.setup({
|
||||||
|
form: '#add_form',
|
||||||
|
fecha: '#fecha',
|
||||||
|
checkbox: '#uf',
|
||||||
|
valor: '#valor',
|
||||||
|
bancos: '#bancos'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
@ -4,10 +4,10 @@ use Psr\Container\ContainerInterface;
|
|||||||
return [
|
return [
|
||||||
Incoviba\Common\Define\Database::class => function(ContainerInterface $container) {
|
Incoviba\Common\Define\Database::class => function(ContainerInterface $container) {
|
||||||
return new Incoviba\Common\Implement\Database\MySQL(
|
return new Incoviba\Common\Implement\Database\MySQL(
|
||||||
$container->has('MYSQL_HOST') ? $container->get('MYSQL_HOST') : 'db',
|
$container->has('DB_HOST') ? $container->get('DB_HOST') : 'db',
|
||||||
$container->get('MYSQL_DATABASE'),
|
$container->get('DB_DATABASE'),
|
||||||
$container->get('MYSQL_USER'),
|
$container->get('DB_USER'),
|
||||||
$container->get('MYSQL_PASSWORD')
|
$container->get('DB_PASSWORD')
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Incoviba\Common\Define\Connection::class => function(ContainerInterface $container) {
|
Incoviba\Common\Define\Connection::class => function(ContainerInterface $container) {
|
||||||
|
@ -20,7 +20,9 @@ return [
|
|||||||
$ine = new Incoviba\Service\Money\Ine(new GuzzleHttp\Client([
|
$ine = new Incoviba\Service\Money\Ine(new GuzzleHttp\Client([
|
||||||
'base_uri' => 'https://api-calculadora.ine.cl/ServiciosCalculadoraVariacion'
|
'base_uri' => 'https://api-calculadora.ine.cl/ServiciosCalculadoraVariacion'
|
||||||
]));
|
]));
|
||||||
return (new Incoviba\Service\Money())->register('uf', $mindicador)
|
return (new Incoviba\Service\Money($container->get(Psr\Log\LoggerInterface::class)))
|
||||||
|
->register('uf', $mindicador)
|
||||||
|
->register('usd', $mindicador)
|
||||||
->register('ipc', $ine);
|
->register('ipc', $ine);
|
||||||
},
|
},
|
||||||
Predis\Client::class => function(ContainerInterface $container) {
|
Predis\Client::class => function(ContainerInterface $container) {
|
||||||
@ -32,8 +34,13 @@ return [
|
|||||||
},
|
},
|
||||||
Incoviba\Service\Cartola::class => function(ContainerInterface $container) {
|
Incoviba\Service\Cartola::class => function(ContainerInterface $container) {
|
||||||
return (new Incoviba\Service\Cartola(
|
return (new Incoviba\Service\Cartola(
|
||||||
|
$container->get(Psr\Log\LoggerInterface::class),
|
||||||
$container->get(Psr\Http\Message\StreamFactoryInterface::class),
|
$container->get(Psr\Http\Message\StreamFactoryInterface::class),
|
||||||
$container->get(Incoviba\Common\Define\Contabilidad\Exporter::class)
|
$container->get(Incoviba\Common\Define\Contabilidad\Exporter::class),
|
||||||
|
$container->get(Incoviba\Repository\Inmobiliaria::class),
|
||||||
|
$container->get(Incoviba\Repository\Inmobiliaria\Cuenta::class),
|
||||||
|
$container->get(Incoviba\Repository\Movimiento::class),
|
||||||
|
$container->get(Incoviba\Repository\Cartola::class)
|
||||||
))
|
))
|
||||||
->register('security', $container->get(Incoviba\Service\Cartola\Security::class))
|
->register('security', $container->get(Incoviba\Service\Cartola\Security::class))
|
||||||
->register('itau', $container->get(Incoviba\Service\Cartola\Itau::class))
|
->register('itau', $container->get(Incoviba\Service\Cartola\Itau::class))
|
||||||
@ -48,6 +55,7 @@ return [
|
|||||||
},
|
},
|
||||||
Incoviba\Service\Contabilidad\Nubox::class => function(ContainerInterface $container) {
|
Incoviba\Service\Contabilidad\Nubox::class => function(ContainerInterface $container) {
|
||||||
return new Incoviba\Service\Contabilidad\Nubox(
|
return new Incoviba\Service\Contabilidad\Nubox(
|
||||||
|
$container->get(Psr\Log\LoggerInterface::class),
|
||||||
$container->get(Incoviba\Repository\Nubox::class),
|
$container->get(Incoviba\Repository\Nubox::class),
|
||||||
$container->get(Incoviba\Service\Redis::class),
|
$container->get(Incoviba\Service\Redis::class),
|
||||||
new GuzzleHttp\Client(),
|
new GuzzleHttp\Client(),
|
||||||
|
@ -11,7 +11,9 @@ return [
|
|||||||
'format' => $container->get(Incoviba\Service\Format::class),
|
'format' => $container->get(Incoviba\Service\Format::class),
|
||||||
'API_KEY' => $container->get('API_KEY'),
|
'API_KEY' => $container->get('API_KEY'),
|
||||||
'UF' => $container->get(Incoviba\Service\UF::class),
|
'UF' => $container->get(Incoviba\Service\UF::class),
|
||||||
'IPC' => $container->get(Incoviba\Service\IPC::class)
|
'USD' => $container->get(Incoviba\Service\USD::class),
|
||||||
|
'IPC' => $container->get(Incoviba\Service\IPC::class),
|
||||||
|
'hoy' => new DateTimeImmutable()
|
||||||
];
|
];
|
||||||
if ($global_variables['login']->isIn()) {
|
if ($global_variables['login']->isIn()) {
|
||||||
$global_variables['user'] = $global_variables['login']->getUser();
|
$global_variables['user'] = $global_variables['login']->getUser();
|
||||||
|
@ -2,51 +2,16 @@
|
|||||||
namespace Incoviba\Controller\API;
|
namespace Incoviba\Controller\API;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
|
||||||
class Contabilidad
|
class Contabilidad extends Controller
|
||||||
{
|
{
|
||||||
use withJson;
|
use withJson;
|
||||||
|
|
||||||
public function procesarCartola(ServerRequestInterface $request, ResponseInterface $response,
|
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
|
||||||
Repository\Banco $bancoRepository,
|
|
||||||
Service\Cartola $cartolaService): ResponseInterface
|
|
||||||
{
|
|
||||||
$body = $request->getParsedBody();
|
|
||||||
$output = [
|
|
||||||
'input' => $body,
|
|
||||||
'movimientos' => []
|
|
||||||
];
|
|
||||||
try {
|
|
||||||
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria']);
|
|
||||||
$banco = $bancoRepository->fetchById($body['banco']);
|
|
||||||
$mes = new DateTimeImmutable($body['mes']);
|
|
||||||
$file = $request->getUploadedFiles()['file'];
|
|
||||||
$output['movimientos'] = $cartolaService->process($inmobiliaria, $banco, $mes, $file);
|
|
||||||
} catch (EmptyResult) {}
|
|
||||||
return $this->withJson($response, $output);
|
|
||||||
}
|
|
||||||
public function exportarCartola(ServerRequestInterface $request, ResponseInterface $response,
|
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
|
||||||
Repository\Banco $bancoRepository,
|
|
||||||
Service\Cartola $cartolaService): ResponseInterface
|
|
||||||
{
|
|
||||||
$body = $request->getParsedBody();
|
|
||||||
$output = [
|
|
||||||
'input' => $body,
|
|
||||||
'filename' => ''
|
|
||||||
];
|
|
||||||
try {
|
|
||||||
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria']);
|
|
||||||
$banco = $bancoRepository->fetchById($body['banco']);
|
|
||||||
$mes = new DateTimeImmutable($body['mes']);
|
|
||||||
$output['filename'] = $cartolaService->export($inmobiliaria, $banco, $mes, json_decode($body['movimientos']));
|
|
||||||
} catch (EmptyResult) {}
|
|
||||||
return $this->withJson($response, $output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
94
app/src/Controller/API/Contabilidad/Cartolas.php
Normal file
94
app/src/Controller/API/Contabilidad/Cartolas.php
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
|
class Cartolas extends Controller
|
||||||
|
{
|
||||||
|
use withJson;
|
||||||
|
|
||||||
|
public function procesar(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
|
Repository\Banco $bancoRepository,
|
||||||
|
Service\Cartola $cartolaService): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $body,
|
||||||
|
'movimientos' => []
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria']);
|
||||||
|
$banco = $bancoRepository->fetchById($body['banco']);
|
||||||
|
$mes = new DateTimeImmutable($body['mes']);
|
||||||
|
$file = $request->getUploadedFiles()['file'];
|
||||||
|
$output['movimientos'] = $cartolaService->process($inmobiliaria, $banco, $mes, $file);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
public function exportar(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
|
Repository\Banco $bancoRepository,
|
||||||
|
Service\Cartola $cartolaService): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $body,
|
||||||
|
'filename' => ''
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria']);
|
||||||
|
$banco = $bancoRepository->fetchById($body['banco']);
|
||||||
|
$mes = new DateTimeImmutable($body['mes']);
|
||||||
|
$output['filename'] = $cartolaService->export($inmobiliaria, $banco, $mes, json_decode($body['movimientos']));
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
public function diaria(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
|
Service\Cartola $cartolaService): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $body,
|
||||||
|
'cartolas' => []
|
||||||
|
];
|
||||||
|
$fields = json_decode($body['fields']);
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
try {
|
||||||
|
$cuenta = $cuentaRepository->fetchById($body["cuenta_id{$field}"]);
|
||||||
|
$fecha = new DateTimeImmutable($body["fecha{$field}"]);
|
||||||
|
$file = $request->getUploadedFiles()["file{$field}"];
|
||||||
|
|
||||||
|
$output['cartolas'][$field] = $cartolaService->diaria($cuenta, $fecha, $file);
|
||||||
|
} catch (EmptyResult $exception) {
|
||||||
|
$this->logger->debug($exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
public function ayer(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
|
Repository\Cartola $cartolaRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $body,
|
||||||
|
'cartola' => []
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$cuenta = $cuentaRepository->fetchById($body['cuenta_id']);
|
||||||
|
$fecha = new DateTimeImmutable($body['fecha']);
|
||||||
|
$output['cartola'] = $cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
}
|
68
app/src/Controller/API/Contabilidad/Depositos.php
Normal file
68
app/src/Controller/API/Contabilidad/Depositos.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
|
class Depositos extends Ideal\Controller
|
||||||
|
{
|
||||||
|
use withJson;
|
||||||
|
|
||||||
|
public function inmobiliaria(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
|
Repository\Banco $bancoRepository,
|
||||||
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
|
Repository\Deposito $dapRepository,
|
||||||
|
int $inmobiliaria_rut): ResponseInterface
|
||||||
|
{
|
||||||
|
$output = [
|
||||||
|
'inmobiliaria_rut' => $inmobiliaria_rut,
|
||||||
|
'depositos' => []
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
|
||||||
|
$cuentas = $cuentaRepository->fetchByInmobiliaria($inmobiliaria->rut);
|
||||||
|
foreach ($cuentas as $cuenta) {
|
||||||
|
$output['depositos'] = $dapRepository->fetchByCuenta($cuenta->id);
|
||||||
|
}
|
||||||
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository, Repository\Banco $bancoRepository,
|
||||||
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
|
Repository\Deposito $dapRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $body,
|
||||||
|
'status' => false
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria_rut']);
|
||||||
|
$banco = $bancoRepository->fetchById($body['banco_id']);
|
||||||
|
$cuenta = $cuentaRepository->fetchByInmobiliariaAndBanco($inmobiliaria->rut, $banco->id);
|
||||||
|
$data = [
|
||||||
|
'id' => $body['id'],
|
||||||
|
'cuenta_id' => $cuenta->id,
|
||||||
|
'capital' => $body['capital'],
|
||||||
|
'futuro' => $body['futuro'],
|
||||||
|
'inicio' => (new DateTimeImmutable($body['inicio']))->format('Y-m-d'),
|
||||||
|
'termino' => (new DateTimeImmutable($body['termino']))->format('Y-m-d')
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$dapRepository->fetchById($body['id']);
|
||||||
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
|
$dap = $dapRepository->create($data);
|
||||||
|
$dapRepository->save($dap);
|
||||||
|
}
|
||||||
|
$output['status'] = true;
|
||||||
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
}
|
31
app/src/Controller/API/Ventas/Creditos.php
Normal file
31
app/src/Controller/API/Ventas/Creditos.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller\API\Ventas;
|
||||||
|
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
|
class Creditos extends Controller
|
||||||
|
{
|
||||||
|
use withJson;
|
||||||
|
|
||||||
|
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||||
|
Service\Venta\Credito $creditoService, int $venta_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $body,
|
||||||
|
'credito' => null,
|
||||||
|
'status' => false
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$venta = $ventaService->getById($venta_id);
|
||||||
|
$output['credito'] = $creditoService->edit($venta->formaPago()->credito, $body);
|
||||||
|
$output['status'] = true;
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,50 @@ class Escrituras
|
|||||||
{
|
{
|
||||||
use withJson;
|
use withJson;
|
||||||
|
|
||||||
|
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Repository\Venta $ventaRepository, Service\Venta $ventaService,
|
||||||
|
Repository\Venta\Escritura $escrituraRepository, Service\Venta\Pago $pagoService,
|
||||||
|
Service\UF $ufService, int $venta_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'venta_id' => $venta_id,
|
||||||
|
'input' => $body,
|
||||||
|
'status' => false
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$venta = $ventaService->getById($venta_id);
|
||||||
|
if (isset($venta->formaPago()->escritura)) {
|
||||||
|
throw new EmptyResult('');
|
||||||
|
}
|
||||||
|
$fecha = new DateTimeImmutable($body['fecha']);
|
||||||
|
$uf = $ufService->get($fecha);
|
||||||
|
$valor = $body['valor'];
|
||||||
|
if (str_contains($valor, ',')) {
|
||||||
|
$valor = str_replace(['.', ','], ['', '.'], $valor);
|
||||||
|
}
|
||||||
|
$valor = ((float) $valor) * (($body['uf']) ? $uf : 1);
|
||||||
|
$data = [
|
||||||
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
|
'valor' => $valor,
|
||||||
|
'banco' => $body['banco'],
|
||||||
|
'tipo' => $body['tipo'],
|
||||||
|
'uf' => $uf
|
||||||
|
];
|
||||||
|
$pago = $pagoService->add($data);
|
||||||
|
$data = [
|
||||||
|
'valor' => $valor,
|
||||||
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
|
'uf' => $uf,
|
||||||
|
'pago' => $pago->id
|
||||||
|
];
|
||||||
|
$escritura = $escrituraRepository->create($data);
|
||||||
|
$escrituraRepository->save($escritura);
|
||||||
|
$ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||||
|
$output['status'] = true;
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Service\Venta $ventaService, Repository\Venta\EstadoVenta $estadoVentaRepository,
|
Service\Venta $ventaService, Repository\Venta\EstadoVenta $estadoVentaRepository,
|
||||||
int $venta_id): ResponseInterface
|
int $venta_id): ResponseInterface
|
||||||
|
73
app/src/Controller/Contabilidad.php
Normal file
73
app/src/Controller/Contabilidad.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use DateInterval;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Common\Implement\Exception\{EmptyResult, EmptyRedis};
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
|
class Contabilidad extends Controller
|
||||||
|
{
|
||||||
|
use withRedis;
|
||||||
|
|
||||||
|
public function diaria(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Service\Redis $redisService,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$redisKey = 'inmobiliarias';
|
||||||
|
$inmobiliarias = [];
|
||||||
|
try {
|
||||||
|
$inmobiliarias = $this->fetchRedis($redisService, $redisKey);
|
||||||
|
} catch (EmptyRedis) {
|
||||||
|
try {
|
||||||
|
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
||||||
|
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
}
|
||||||
|
return $view->render($response, 'contabilidad.cartolas.diaria', compact('inmobiliarias'));
|
||||||
|
}
|
||||||
|
public function depositos(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Service\Redis $redisService,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
|
Repository\Deposito $dapRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$redisKey = 'inmobiliarias';
|
||||||
|
$inmobiliarias = [];
|
||||||
|
try {
|
||||||
|
$inmobiliarias = $this->fetchRedis($redisService, $redisKey);
|
||||||
|
} catch (EmptyRedis) {
|
||||||
|
try {
|
||||||
|
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
||||||
|
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
}
|
||||||
|
$depositos = [];
|
||||||
|
try {
|
||||||
|
$depositos = $dapRepository->fetchAll();
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
$fecha = new DateTimeImmutable('today');
|
||||||
|
$activos = array_filter($depositos, function(Model\Deposito $deposito) use ($fecha) {
|
||||||
|
return $deposito->termino >= $fecha;
|
||||||
|
});
|
||||||
|
$mes = $fecha->sub(new DateInterval('P1M'));
|
||||||
|
$vencidos = array_filter($depositos, function(Model\Deposito $deposito) use ($fecha, $mes) {
|
||||||
|
return $deposito->termino < $fecha and $deposito->termino >= $mes;
|
||||||
|
});
|
||||||
|
return $view->render($response, 'contabilidad.depositos', compact('inmobiliarias', 'activos', 'vencidos'));
|
||||||
|
}
|
||||||
|
public function tesoreria(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Service\Contabilidad\Informe\Tesoreria $contabilidadService,
|
||||||
|
string $fecha = 'today'): ResponseInterface
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable($fecha);
|
||||||
|
$anterior = $contabilidadService->getAnterior($fecha);
|
||||||
|
$informes = $contabilidadService->build($fecha);
|
||||||
|
return $view->render($response, 'contabilidad.informes.tesoreria', compact('fecha', 'anterior', 'informes'));
|
||||||
|
}
|
||||||
|
}
|
20
app/src/Controller/Ventas/Creditos.php
Normal file
20
app/src/Controller/Ventas/Creditos.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller\Ventas;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
|
class Creditos extends Controller
|
||||||
|
{
|
||||||
|
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Repository\Venta $ventaRepository, Repository\Banco $bancoRepository,
|
||||||
|
int $venta_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$venta = $ventaRepository->fetchById($venta_id);
|
||||||
|
$bancos = $bancoRepository->fetchAll('nombre');
|
||||||
|
return $view->render($response, 'ventas.creditos', compact('venta', 'bancos'));
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace Incoviba\Controller\Ventas;
|
|||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
|
||||||
class Escrituras
|
class Escrituras
|
||||||
@ -20,4 +21,12 @@ class Escrituras
|
|||||||
$venta = $ventaService->getById($venta_id);
|
$venta = $ventaService->getById($venta_id);
|
||||||
return $view->render($response, 'ventas.escrituras.informe', compact('venta'));
|
return $view->render($response, 'ventas.escrituras.informe', compact('venta'));
|
||||||
}
|
}
|
||||||
|
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Service\Venta $ventaService, Repository\Banco $bancoRepository,
|
||||||
|
int $venta_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$venta = $ventaService->getById($venta_id);
|
||||||
|
$bancos = $bancoRepository->fetchAll('nombre');
|
||||||
|
return $view->render($response, 'ventas.escrituras.add', compact('venta', 'bancos'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
26
app/src/Model/Cartola.php
Normal file
26
app/src/Model/Cartola.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Model;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
|
||||||
|
class Cartola extends Ideal\Model
|
||||||
|
{
|
||||||
|
public Inmobiliaria\Cuenta $cuenta;
|
||||||
|
public DateTimeInterface $fecha;
|
||||||
|
|
||||||
|
public int $cargos = 0;
|
||||||
|
public int $abonos = 0;
|
||||||
|
public int $saldo = 0;
|
||||||
|
|
||||||
|
public function jsonSerialize(): mixed
|
||||||
|
{
|
||||||
|
return array_merge(parent::jsonSerialize(), [
|
||||||
|
'cuenta_id' => $this->cuenta->id,
|
||||||
|
'fecha' => $this->fecha->format('Y-m-d'),
|
||||||
|
'cargos' => $this->cargos,
|
||||||
|
'abonos' => $this->abonos,
|
||||||
|
'saldo' => $this->saldo
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
36
app/src/Model/Deposito.php
Normal file
36
app/src/Model/Deposito.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Model;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
|
||||||
|
class Deposito extends Ideal\Model
|
||||||
|
{
|
||||||
|
public Inmobiliaria\Cuenta $cuenta;
|
||||||
|
public int $capital;
|
||||||
|
public int $futuro;
|
||||||
|
public DateTimeInterface $inicio;
|
||||||
|
public DateTimeInterface $termino;
|
||||||
|
|
||||||
|
public function plazo(): int
|
||||||
|
{
|
||||||
|
return $this->termino->diff($this->inicio)->days;
|
||||||
|
}
|
||||||
|
public function tasa(): float
|
||||||
|
{
|
||||||
|
return ($this->futuro - $this->capital) / $this->capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize(): mixed
|
||||||
|
{
|
||||||
|
return array_merge(parent::jsonSerialize(), [
|
||||||
|
'cuenta_id' => $this->cuenta->id,
|
||||||
|
'capital' => $this->capital,
|
||||||
|
'futuro' => $this->futuro,
|
||||||
|
'inicio' => $this->inicio->format('Y-m-d'),
|
||||||
|
'termino' => $this->termino->format('Y-m-d'),
|
||||||
|
'plazo' => $this->plazo(),
|
||||||
|
'tasa' => $this->tasa()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
29
app/src/Model/Movimiento.php
Normal file
29
app/src/Model/Movimiento.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Model;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
|
||||||
|
class Movimiento extends Ideal\Model
|
||||||
|
{
|
||||||
|
public Inmobiliaria\Cuenta $cuenta;
|
||||||
|
public DateTimeInterface $fecha;
|
||||||
|
public string $glosa;
|
||||||
|
public string $documento;
|
||||||
|
public int $cargo;
|
||||||
|
public int $abono;
|
||||||
|
public int $saldo;
|
||||||
|
|
||||||
|
public function jsonSerialize(): mixed
|
||||||
|
{
|
||||||
|
return array_merge(parent::jsonSerialize(), [
|
||||||
|
'cuenta_id' => $this->cuenta->id,
|
||||||
|
'fecha' => $this->fecha->format('Y-m-d'),
|
||||||
|
'glosa' => $this->glosa,
|
||||||
|
'documento' => $this->documento,
|
||||||
|
'cargo' => $this->cargo,
|
||||||
|
'abono' => $this->abono,
|
||||||
|
'saldo' => $this->saldo
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,17 @@ class FormaPago implements JsonSerializable
|
|||||||
}
|
}
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
public function prometido(string $moneda = Pago::UF): float
|
||||||
|
{
|
||||||
|
$sum = 0;
|
||||||
|
if (isset($this->pie)) {
|
||||||
|
$sum += $this->pie->valor($moneda);
|
||||||
|
}
|
||||||
|
if (isset($this->escritura)) {
|
||||||
|
$sum += $this->escritura->pago->valor($moneda);
|
||||||
|
}
|
||||||
|
return $sum;
|
||||||
|
}
|
||||||
public function total(string $moneda = Pago::UF): float
|
public function total(string $moneda = Pago::UF): float
|
||||||
{
|
{
|
||||||
$sum = $this->anticipo($moneda);
|
$sum = $this->anticipo($moneda);
|
||||||
|
@ -14,7 +14,7 @@ class Pie extends Model
|
|||||||
public ?Pie $asociado;
|
public ?Pie $asociado;
|
||||||
public ?Pago $reajuste;
|
public ?Pago $reajuste;
|
||||||
|
|
||||||
public array $cuotasArray;
|
public array $cuotasArray = [];
|
||||||
public function cuotas(bool $pagadas = false, bool $vigentes = false): array
|
public function cuotas(bool $pagadas = false, bool $vigentes = false): array
|
||||||
{
|
{
|
||||||
if ($this->asociado !== null) {
|
if ($this->asociado !== null) {
|
||||||
@ -33,14 +33,19 @@ class Pie extends Model
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function valor(string $moneda = Pago::UF): float
|
||||||
|
{
|
||||||
|
$proporcion = $this->proporcion();
|
||||||
|
if ($this->asociado !== null) {
|
||||||
|
return $this->asociado->valor($moneda) * $proporcion;
|
||||||
|
}
|
||||||
|
return array_reduce($this->cuotas(), function(float $sum, Cuota $cuota) use ($moneda) {
|
||||||
|
return $sum + $cuota->pago->valor($moneda);
|
||||||
|
}, 0) * $proporcion;
|
||||||
|
}
|
||||||
public function pagado(string $moneda = Pago::UF): float
|
public function pagado(string $moneda = Pago::UF): float
|
||||||
{
|
{
|
||||||
$proporcion = 1;
|
$proporcion = $this->proporcion();
|
||||||
if (count($this->asociados()) > 0) {
|
|
||||||
$proporcion = $this->valor / ((($this->asociado) ? $this->asociado->valor : $this->valor) + array_reduce($this->asociados(), function(float $sum, Pie $pie) {
|
|
||||||
return $sum + $pie->valor;
|
|
||||||
}, 0));
|
|
||||||
}
|
|
||||||
if ($this->asociado !== null) {
|
if ($this->asociado !== null) {
|
||||||
return $this->asociado->pagado($moneda) * $proporcion;
|
return $this->asociado->pagado($moneda) * $proporcion;
|
||||||
}
|
}
|
||||||
@ -49,6 +54,17 @@ class Pie extends Model
|
|||||||
return $sum + $cuota->pago->valor($moneda);
|
return $sum + $cuota->pago->valor($moneda);
|
||||||
}, 0) * $proporcion;
|
}, 0) * $proporcion;
|
||||||
}
|
}
|
||||||
|
protected function proporcion(): float
|
||||||
|
{
|
||||||
|
$proporcion = 1;
|
||||||
|
if (count($this->asociados()) > 0) {
|
||||||
|
$proporcion = $this->valor / ((($this->asociado) ? $this->asociado->valor : $this->valor) + array_reduce($this->asociados(), function(float $sum, Pie $pie) {
|
||||||
|
return $sum + $pie->valor;
|
||||||
|
}, 0));
|
||||||
|
}
|
||||||
|
return $proporcion;
|
||||||
|
}
|
||||||
|
|
||||||
public ?array $asociados;
|
public ?array $asociados;
|
||||||
public function asociados(): array
|
public function asociados(): array
|
||||||
{
|
{
|
||||||
|
68
app/src/Repository/Cartola.php
Normal file
68
app/src/Repository/Cartola.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Repository;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Common\Define;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
|
class Cartola extends Ideal\Repository
|
||||||
|
{
|
||||||
|
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria\Cuenta $cuentaRepository)
|
||||||
|
{
|
||||||
|
parent::__construct($connection);
|
||||||
|
$this->setTable('cartolas');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(?array $data = null): Model\Cartola
|
||||||
|
{
|
||||||
|
$map = (new Implement\Repository\MapperParser(['cargos', 'abonos', 'saldo']))
|
||||||
|
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||||
|
->register('cuenta_id', (new Implement\Repository\Mapper())
|
||||||
|
->setProperty('cuenta')
|
||||||
|
->setFunction(function($data) {
|
||||||
|
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
||||||
|
}));
|
||||||
|
return $this->parseData(new Model\Cartola(), $data, $map);
|
||||||
|
}
|
||||||
|
public function save(Define\Model $model): Model\Cartola
|
||||||
|
{
|
||||||
|
$model->id = $this->saveNew([
|
||||||
|
'cuenta_id',
|
||||||
|
'fecha',
|
||||||
|
'cargos',
|
||||||
|
'abonos',
|
||||||
|
'saldo'
|
||||||
|
], [
|
||||||
|
$model->cuenta->id,
|
||||||
|
$model->fecha->format('Y-m-d'),
|
||||||
|
$model->cargos,
|
||||||
|
$model->abonos,
|
||||||
|
$model->saldo
|
||||||
|
]);
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
public function edit(Define\Model $model, array $new_data): Model\Cartola
|
||||||
|
{
|
||||||
|
return $this->update($model, ['cuenta_id', 'fecha', 'cargos', 'abonos', 'saldo'], $new_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchByFecha(DateTimeInterface $fecha): array
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('fecha = ?');
|
||||||
|
return $this->fetchMany($query, [$fecha->format('Y-m-d')]);
|
||||||
|
}
|
||||||
|
public function fetchByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Cartola
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('cuenta_id = ? AND fecha = ?');
|
||||||
|
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||||
|
}
|
||||||
|
}
|
64
app/src/Repository/Deposito.php
Normal file
64
app/src/Repository/Deposito.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Repository;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Define;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Model;
|
||||||
|
|
||||||
|
class Deposito extends Ideal\Repository
|
||||||
|
{
|
||||||
|
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria\Cuenta $cuentaRepository)
|
||||||
|
{
|
||||||
|
parent::__construct($connection);
|
||||||
|
$this->setTable('depositos');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(?array $data = null): Model\Deposito
|
||||||
|
{
|
||||||
|
$map = (new Implement\Repository\MapperParser(['id', 'capital', 'futuro']))
|
||||||
|
->register('cuenta_id', (new Implement\Repository\Mapper())
|
||||||
|
->setProperty('cuenta')
|
||||||
|
->setFunction(function(array $data) {
|
||||||
|
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
||||||
|
}))
|
||||||
|
->register('inicio', new Implement\Repository\Mapper\DateTime('inicio'))
|
||||||
|
->register('termino', new Implement\Repository\Mapper\DateTime('termino'));
|
||||||
|
return $this->parseData(new Model\Deposito(), $data, $map);
|
||||||
|
}
|
||||||
|
public function save(Define\Model $model): Model\Deposito
|
||||||
|
{
|
||||||
|
$this->saveNew([
|
||||||
|
'id', 'cuenta_id', 'capital', 'futuro', 'inicio', 'termino'
|
||||||
|
], [
|
||||||
|
$model->id, $model->cuenta->id, $model->capital, $model->futuro,
|
||||||
|
$model->inicio->format('Y-m-d'), $model->termino->format('Y-m-d')
|
||||||
|
]);
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(Define\Model $model, array $new_data): Model\Deposito
|
||||||
|
{
|
||||||
|
return $this->update($model, ['cuenta_id', 'capital', 'futuro', 'inicio', 'termino'], $new_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchByCuenta(int $cuenta_id): array
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('cuenta_id = ?');
|
||||||
|
return $this->fetchMany($query, [$cuenta_id]);
|
||||||
|
}
|
||||||
|
public function fetchAllActive(): array
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable();
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('inicio <= ? AND termino >= ?');
|
||||||
|
return $this->fetchMany($query, [$fecha->format('Y-m-d'), $fecha->format('Y-m-d')]);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ use Incoviba\Common\Ideal;
|
|||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
|
use PhpParser\Node\Expr\BinaryOp\Mod;
|
||||||
|
|
||||||
class Cuenta extends Ideal\Repository
|
class Cuenta extends Ideal\Repository
|
||||||
{
|
{
|
||||||
@ -49,4 +50,12 @@ class Cuenta extends Ideal\Repository
|
|||||||
->where('inmobiliaria = ?');
|
->where('inmobiliaria = ?');
|
||||||
return $this->fetchMany($query, [$inmobiliaria_rut]);
|
return $this->fetchMany($query, [$inmobiliaria_rut]);
|
||||||
}
|
}
|
||||||
|
public function fetchByInmobiliariaAndBanco(int $inmobiliaria_rut, int $banco_id): Model\Inmobiliaria\Cuenta
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('inmobiliaria = ? AND banco = ?');
|
||||||
|
return $this->fetchOne($query, [$inmobiliaria_rut, $banco_id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
72
app/src/Repository/Movimiento.php
Normal file
72
app/src/Repository/Movimiento.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Repository;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Common\Define;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Model;
|
||||||
|
|
||||||
|
class Movimiento extends Ideal\Repository
|
||||||
|
{
|
||||||
|
public function __construct(Define\Connection $connection, protected Inmobiliaria\Cuenta $cuentaRepository)
|
||||||
|
{
|
||||||
|
parent::__construct($connection);
|
||||||
|
$this->setTable('movimientos');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(?array $data = null): Model\Movimiento
|
||||||
|
{
|
||||||
|
$map = (new Implement\Repository\MapperParser(['cargo', 'abono', 'saldo', 'glosa', 'documento']))
|
||||||
|
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||||
|
->register('cuenta_id', (new Implement\Repository\Mapper())
|
||||||
|
->setProperty('cuenta')
|
||||||
|
->setFunction(function($data) {
|
||||||
|
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return $this->parseData(new Model\Movimiento(), $data, $map);
|
||||||
|
}
|
||||||
|
public function save(Define\Model $model): Model\Movimiento
|
||||||
|
{
|
||||||
|
$model->id = $this->saveNew([
|
||||||
|
'cuenta_id',
|
||||||
|
'fecha',
|
||||||
|
'glosa',
|
||||||
|
'documento',
|
||||||
|
'cargo',
|
||||||
|
'abono',
|
||||||
|
'saldo'
|
||||||
|
], [
|
||||||
|
$model->cuenta->id,
|
||||||
|
$model->fecha->format('Y-m-d'),
|
||||||
|
$model->glosa,
|
||||||
|
$model->documento,
|
||||||
|
$model->cargo,
|
||||||
|
$model->abono,
|
||||||
|
$model->saldo
|
||||||
|
]);
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
public function edit(Define\Model $model, array $new_data): Model\Movimiento
|
||||||
|
{
|
||||||
|
return $this->update($model, ['cuenta_id', 'fecha', 'glosa', 'documento', 'cargo', 'abono', 'saldo'], $new_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): array
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('cuenta_id = ? AND fecha = ?');
|
||||||
|
return $this->fetchMany($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||||
|
}
|
||||||
|
public function fetchByCuentaAndFechaAndMonto(int $cuenta_id, DateTimeInterface $fecha, int $monto): Model\Movimiento
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('cuenta_id = ? AND fecha = ? AND (cargo = ? OR abono = ?)');
|
||||||
|
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d'), $monto, $monto]);
|
||||||
|
}
|
||||||
|
}
|
@ -159,15 +159,6 @@ class Venta extends Ideal\Repository
|
|||||||
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
|
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
|
||||||
->where('ptu.proyecto = ? AND tev.activa')
|
->where('ptu.proyecto = ? AND tev.activa')
|
||||||
->group('a.id');
|
->group('a.id');
|
||||||
/*$query = "SELECT a.*
|
|
||||||
FROM `{$this->getTable()}` a
|
|
||||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
|
||||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
|
||||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
|
||||||
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
|
|
||||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
|
||||||
WHERE ptu.`proyecto` = ? AND tev.`activa`
|
|
||||||
GROUP BY a.`id`";*/
|
|
||||||
return $this->fetchMany($query, [$proyecto_id]);
|
return $this->fetchMany($query, [$proyecto_id]);
|
||||||
}
|
}
|
||||||
public function fetchIdsByProyecto(int $proyecto_id): array
|
public function fetchIdsByProyecto(int $proyecto_id): array
|
||||||
@ -240,6 +231,15 @@ GROUP BY a.`id`";*/
|
|||||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||||
return $this->fetchMany($query, [$unidad, $tipo]);
|
return $this->fetchMany($query, [$unidad, $tipo]);
|
||||||
}
|
}
|
||||||
|
public function fetchByUnidadId(int $unidad_id): Model\Venta
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select('a.*')
|
||||||
|
->from("{$this->getTable()} a")
|
||||||
|
->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
|
||||||
|
->where('pu.unidad = ?');
|
||||||
|
return $this->fetchOne($query, [$unidad_id]);
|
||||||
|
}
|
||||||
public function fetchIdsByUnidad(string $unidad, string $tipo): array
|
public function fetchIdsByUnidad(string $unidad, string $tipo): array
|
||||||
{
|
{
|
||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
@ -17,7 +17,7 @@ class Credito extends Ideal\Repository
|
|||||||
|
|
||||||
public function create(?array $data = null): Model\Venta\Credito
|
public function create(?array $data = null): Model\Venta\Credito
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser())
|
$map = (new Implement\Repository\MapperParser(['valor']))
|
||||||
->register('pago', (new Implement\Repository\Mapper())
|
->register('pago', (new Implement\Repository\Mapper())
|
||||||
->setFunction(function($data) {
|
->setFunction(function($data) {
|
||||||
return $this->pagoService->getById($data['pago']);
|
return $this->pagoService->getById($data['pago']);
|
||||||
|
@ -47,15 +47,19 @@ class EstadoVenta extends Ideal\Repository
|
|||||||
|
|
||||||
public function fetchByVenta(int $venta_id): array
|
public function fetchByVenta(int $venta_id): array
|
||||||
{
|
{
|
||||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ?";
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('venta = ?');
|
||||||
return $this->fetchMany($query, [$venta_id]);
|
return $this->fetchMany($query, [$venta_id]);
|
||||||
}
|
}
|
||||||
public function fetchCurrentByVenta(int $venta_id): Model\Venta\EstadoVenta
|
public function fetchCurrentByVenta(int $venta_id): Model\Venta\EstadoVenta
|
||||||
{
|
{
|
||||||
$query = "SELECT a.*
|
$query = $this->connection->getQueryBuilder()
|
||||||
FROM `{$this->getTable()}` a
|
->select('a.*')
|
||||||
JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `{$this->getTable()}` GROUP BY `venta`) e0 ON e0.`id` = a.`id`
|
->from("{$this->getTable()} a")
|
||||||
WHERE a.`venta` = ?";
|
->joined("JOIN (SELECT MAX(id) AS id, venta FROM {$this->getTable()} GROUP BY venta) ev0 ON ev0.id = a.id")
|
||||||
|
->where('a.venta = ?');
|
||||||
return $this->fetchOne($query, [$venta_id]);
|
return $this->fetchOne($query, [$venta_id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class Propietario extends Ideal\Repository
|
|||||||
|
|
||||||
public function create(?array $data = null): Define\Model
|
public function create(?array $data = null): Define\Model
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser(['dv', 'nombres']))
|
$map = (new Implement\Repository\MapperParser(['rut', 'dv', 'nombres']))
|
||||||
->register('apellido_paterno', (new Implement\Repository\Mapper())
|
->register('apellido_paterno', (new Implement\Repository\Mapper())
|
||||||
->setProperty('apellidos')
|
->setProperty('apellidos')
|
||||||
->setFunction(function($data) {
|
->setFunction(function($data) {
|
||||||
@ -64,8 +64,8 @@ class Propietario extends Ideal\Repository
|
|||||||
public function save(Define\Model $model): Define\Model
|
public function save(Define\Model $model): Define\Model
|
||||||
{
|
{
|
||||||
$model->rut = $this->saveNew(
|
$model->rut = $this->saveNew(
|
||||||
['dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'otro', 'representante'],
|
['rut', 'dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'otro', 'representante'],
|
||||||
[$model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno'], $model->datos->direccion->id, $model->otro->rut ?? 0, $model->representante->rut ?? 0]
|
[$model->rut, $model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno'], $model->datos->direccion->id, $model->otro->rut ?? 0, $model->representante->rut ?? 0]
|
||||||
);
|
);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,28 @@
|
|||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use DateInterval;
|
||||||
use Psr\Http\Message\StreamFactoryInterface;
|
use Psr\Http\Message\StreamFactoryInterface;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Define\Cartola\Banco;
|
use Incoviba\Common\Define\Cartola\Banco;
|
||||||
use Incoviba\Common\Define\Contabilidad\Exporter;
|
use Incoviba\Common\Define\Contabilidad\Exporter;
|
||||||
|
use Incoviba\Common\Implement\Exception;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
class Cartola
|
class Cartola extends Service
|
||||||
{
|
{
|
||||||
public function __construct(protected StreamFactoryInterface $streamFactory, protected Exporter $exporter) {}
|
public function __construct(LoggerInterface $logger,
|
||||||
|
protected StreamFactoryInterface $streamFactory, protected Exporter $exporter,
|
||||||
|
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
|
protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
|
protected Repository\Movimiento $movimientoRepository,
|
||||||
|
protected Repository\Cartola $cartolaRepository) {
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
protected array $bancos;
|
protected array $bancos;
|
||||||
public function register(string $name, Banco $banco): Cartola
|
public function register(string $name, Banco $banco): Cartola
|
||||||
@ -26,4 +39,63 @@ class Cartola
|
|||||||
{
|
{
|
||||||
return $this->exporter->export($inmobiliaria, $banco, $mes, $movimientos);
|
return $this->exporter->export($inmobiliaria, $banco, $mes, $movimientos);
|
||||||
}
|
}
|
||||||
|
public function diaria(Model\Inmobiliaria\Cuenta $cuenta, DateTimeInterface $fecha, UploadedFileInterface $file): array
|
||||||
|
{
|
||||||
|
$ms = $this->getMovimientosDiarios($cuenta->banco, $file);
|
||||||
|
|
||||||
|
$cartolaData = [
|
||||||
|
'cargos' => 0,
|
||||||
|
'abonos' => 0,
|
||||||
|
'saldo' => 0
|
||||||
|
];
|
||||||
|
$movimientos = [];
|
||||||
|
foreach ($ms as $m) {
|
||||||
|
$movimiento = $this->buildMovimiento($cuenta, $m);
|
||||||
|
|
||||||
|
if ($movimiento->fecha->getTimestamp() === $fecha->getTimestamp()) {
|
||||||
|
$movimientos []= $movimiento;
|
||||||
|
$cartolaData['cargos'] += $movimiento->cargo;
|
||||||
|
$cartolaData['abonos'] += $movimiento->abono;
|
||||||
|
}
|
||||||
|
if ($movimiento->fecha->getTimestamp() > $fecha->getTimestamp()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$cartolaData['saldo'] = $movimiento->saldo;
|
||||||
|
}
|
||||||
|
$cartola = $this->buildCartola($cuenta, $fecha, $cartolaData);
|
||||||
|
return compact('cartola', 'movimientos');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getMovimientosDiarios(Model\Banco $banco, UploadedFileInterface $file): array
|
||||||
|
{
|
||||||
|
$movimientos = $this->bancos[strtolower($banco->nombre)]->process($file);
|
||||||
|
return $this->bancos[strtolower($banco->nombre)]->processMovimientosDiarios($movimientos);
|
||||||
|
}
|
||||||
|
protected function buildCartola(Model\Inmobiliaria\Cuenta $cuenta, DateTimeInterface $fecha, array $data): Model\Cartola
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
|
} catch (Exception\EmptyResult) {
|
||||||
|
$data['cuenta_id'] = $cuenta->id;
|
||||||
|
$data['fecha'] = $fecha->format('Y-m-d');
|
||||||
|
$cartola = $this->cartolaRepository->create($data);
|
||||||
|
return $this->cartolaRepository->save($cartola);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected function buildMovimiento(Model\Inmobiliaria\Cuenta $cuenta, array $data): Model\Movimiento
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$valor = ($data['cargo'] !== 0 and $data['cargo'] !== null) ? $data['cargo'] : $data['abono'];
|
||||||
|
return $this->movimientoRepository
|
||||||
|
->fetchByCuentaAndFechaAndMonto(
|
||||||
|
$cuenta->id,
|
||||||
|
new DateTimeImmutable($data['fecha']),
|
||||||
|
$valor
|
||||||
|
);
|
||||||
|
} catch (Exception\EmptyResult $exception) {
|
||||||
|
$data['cuenta_id'] = $cuenta->id;
|
||||||
|
$movimiento = $this->movimientoRepository->create($data);
|
||||||
|
return $this->movimientoRepository->save($movimiento);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,14 @@ use Incoviba\Common\Ideal\Cartola\Banco;
|
|||||||
|
|
||||||
class Itau extends Banco
|
class Itau extends Banco
|
||||||
{
|
{
|
||||||
|
const CUENTA_CORRIENTE = 0;
|
||||||
|
const ULTIMOS_MOVIMIENTOS = 1;
|
||||||
|
|
||||||
|
public function processMovimientosDiarios(array $movimientos): array
|
||||||
|
{
|
||||||
|
return array_reverse($movimientos);
|
||||||
|
}
|
||||||
|
|
||||||
protected function columnMap(): array
|
protected function columnMap(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -15,7 +23,10 @@ class Itau extends Banco
|
|||||||
'Número de operación' => 'documento',
|
'Número de operación' => 'documento',
|
||||||
'Descripción' => 'glosa',
|
'Descripción' => 'glosa',
|
||||||
'Depósitos o abonos' => 'abono',
|
'Depósitos o abonos' => 'abono',
|
||||||
'Giros o cargos' => 'cargo'
|
'Giros o cargos' => 'cargo',
|
||||||
|
'Documentos' => 'documento',
|
||||||
|
'Movimientos' => 'glosa',
|
||||||
|
'Saldos' => 'saldo'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,53 +39,130 @@ class Itau extends Banco
|
|||||||
$xlsx = $reader->load($filename);
|
$xlsx = $reader->load($filename);
|
||||||
$sheet = $xlsx->getActiveSheet();
|
$sheet = $xlsx->getActiveSheet();
|
||||||
|
|
||||||
$dates = explode(' - ', $sheet->getCell('C4')->getCalculatedValue());
|
|
||||||
$date = DateTimeImmutable::createFromFormat('d/m/Y', $dates[0]);
|
|
||||||
$year = $date->format('Y');
|
|
||||||
|
|
||||||
$rowIndex = 26;
|
|
||||||
$columns = [];
|
|
||||||
$row = $sheet->getRowIterator($rowIndex)->current();
|
|
||||||
$cols = $row->getColumnIterator('A','G');
|
|
||||||
foreach ($cols as $col) {
|
|
||||||
$columns []= trim($col->getCalculatedValue());
|
|
||||||
}
|
|
||||||
$rowIndex ++;
|
|
||||||
$row = $sheet->getRowIterator($rowIndex)->current();
|
|
||||||
$cols = $row->getColumnIterator('A', 'G');
|
|
||||||
$colIndex = 0;
|
|
||||||
foreach ($cols as $col) {
|
|
||||||
$value = $col->getCalculatedValue();
|
|
||||||
if ($value !== null) {
|
|
||||||
$columns[$colIndex] .= " {$value}";
|
|
||||||
}
|
|
||||||
$colIndex ++;
|
|
||||||
}
|
|
||||||
$rowIndex ++;
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$rows = $sheet->getRowIterator($rowIndex);
|
try {
|
||||||
foreach ($rows as $row) {
|
switch ($this->identifySheet($sheet)) {
|
||||||
if ($sheet->getCell("A{$rowIndex}")->getCalculatedValue() === null) {
|
case self::CUENTA_CORRIENTE:
|
||||||
|
$data = $this->parseCuentaCorriente($sheet);
|
||||||
|
break;
|
||||||
|
case self::ULTIMOS_MOVIMIENTOS:
|
||||||
|
$data = $this->parseUltimosMovimientos($sheet);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (PhpSpreadsheet\Exception $exception) {
|
||||||
|
$this->logger->critical($exception);
|
||||||
|
} finally {
|
||||||
|
unlink($filename);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
protected function parseCuentaCorriente(PhpSpreadsheet\Worksheet\Worksheet $sheet): array
|
||||||
|
{
|
||||||
|
$found = false;
|
||||||
|
$year = 0;
|
||||||
|
$columns = [];
|
||||||
|
$data = [];
|
||||||
|
foreach ($sheet->getRowIterator() as $row) {
|
||||||
|
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'Cartola Histórica') {
|
||||||
|
$columnIndex = 'A';
|
||||||
|
foreach ($row->getColumnIterator() as $column) {
|
||||||
|
if ($column->getValue() !== 'Periodo') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$columnIndex = $column->getColumn();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$dates = explode(' - ', $sheet->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue());
|
||||||
|
$date = DateTimeImmutable::createFromFormat('d/m/Y', $dates[0]);
|
||||||
|
$year = $date->format('Y');
|
||||||
|
}
|
||||||
|
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'Movimientos') {
|
||||||
|
$found = true;
|
||||||
|
foreach ($row->getColumnIterator() as $column) {
|
||||||
|
if ($column->getValue() === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$columns[$column->getColumn()] = trim($column->getValue());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($sheet->getCell("A{$row->getRowIndex()}")->getValue() === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$cols = $row->getColumnIterator('A', 'G');
|
|
||||||
$colIndex = 0;
|
|
||||||
$rowData = [];
|
$rowData = [];
|
||||||
foreach ($cols as $col) {
|
foreach ($columns as $columnIndex => $column) {
|
||||||
$value = $col->getCalculatedValue();
|
$value = $sheet->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue();
|
||||||
$col = $columns[$colIndex];
|
$mapped = $this->columnMap()[$column];
|
||||||
if ($col === 'Fecha') {
|
if ($mapped === 'fecha') {
|
||||||
list($d, $m) = explode('/', $value);
|
list($d, $m) = explode('/', $value);
|
||||||
$value = "{$year}-{$m}-{$d}";
|
$value = "{$year}-{$m}-{$d}";
|
||||||
}
|
}
|
||||||
$rowData[$col] = $value;
|
if (in_array($mapped, ['cargo', 'abono', 'saldo'])) {
|
||||||
$colIndex ++;
|
$value = (int) $value;
|
||||||
|
}
|
||||||
|
$rowData[$column] = $value;
|
||||||
}
|
}
|
||||||
$data []= $rowData;
|
$data []= $rowData;
|
||||||
$rowIndex ++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink($filename);
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
protected function parseUltimosMovimientos(PhpSpreadsheet\Worksheet\Worksheet $sheet): array
|
||||||
|
{
|
||||||
|
$found = false;
|
||||||
|
$data = [];
|
||||||
|
$columns = [];
|
||||||
|
foreach ($sheet->getRowIterator() as $row) {
|
||||||
|
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'Últimos Movimientos') {
|
||||||
|
$found = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (count($columns) === 0) {
|
||||||
|
foreach ($row->getColumnIterator() as $cell) {
|
||||||
|
if ($cell->getValue() === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$columns[$cell->getColumn()] = trim($cell->getValue());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($sheet->getCell("A{$row->getRowIndex()}")->getValue() === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$rowData = [];
|
||||||
|
foreach ($columns as $columnIndex => $column) {
|
||||||
|
$value = $sheet->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue();
|
||||||
|
$mapped = $this->columnMap()[$column] ?? $column;
|
||||||
|
if ($mapped === 'fecha') {
|
||||||
|
$value = PhpSpreadsheet\Shared\Date::excelToDateTimeObject($value, 'America/Santiago')->format('Y-m-d');
|
||||||
|
}
|
||||||
|
if (in_array($mapped, ['abono', 'cargo', 'saldo'])) {
|
||||||
|
$value = (int) $value;
|
||||||
|
}
|
||||||
|
$rowData[$column] = $value;
|
||||||
|
}
|
||||||
|
$data []= $rowData;
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function identifySheet(PhpSpreadsheet\Worksheet\Worksheet $sheet): int
|
||||||
|
{
|
||||||
|
foreach ($sheet->getRowIterator(1, 10) as $row) {
|
||||||
|
$value = $sheet->getCell("A{$row->getRowIndex()}")->getValue();
|
||||||
|
if ($value === 'Estado de Cuenta Corriente') {
|
||||||
|
return self::CUENTA_CORRIENTE;
|
||||||
|
}
|
||||||
|
if ($value === 'Consulta Saldos y Últimos movimientos') {
|
||||||
|
return self::ULTIMOS_MOVIMIENTOS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new PhpSpreadsheet\Exception();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ class Santander extends Banco
|
|||||||
'DESCRIPCIÓN MOVIMIENTO' => 'glosa',
|
'DESCRIPCIÓN MOVIMIENTO' => 'glosa',
|
||||||
'FECHA' => 'fecha',
|
'FECHA' => 'fecha',
|
||||||
'N° DOCUMENTO' => 'documento',
|
'N° DOCUMENTO' => 'documento',
|
||||||
|
'SALDO' => 'saldo'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
protected function parseFile(UploadedFileInterface $uploadedFile): array
|
protected function parseFile(UploadedFileInterface $uploadedFile): array
|
||||||
@ -28,42 +29,47 @@ class Santander extends Banco
|
|||||||
$xlsx = $reader->load($filename);
|
$xlsx = $reader->load($filename);
|
||||||
$sheet = $xlsx->getActiveSheet();
|
$sheet = $xlsx->getActiveSheet();
|
||||||
|
|
||||||
$rowIndex = 16;
|
$found = false;
|
||||||
$columns = [];
|
$columns = [];
|
||||||
$row = $sheet->getRowIterator($rowIndex)->current();
|
|
||||||
$cols = $row->getColumnIterator('A', 'H');
|
|
||||||
foreach ($cols as $col) {
|
|
||||||
$columns []= $col->getCalculatedValue();
|
|
||||||
}
|
|
||||||
$rowIndex ++;
|
|
||||||
$rows = $sheet->getRowIterator($rowIndex);
|
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($rows as $row) {
|
foreach ($sheet->getRowIterator() as $row) {
|
||||||
if ($sheet->getCell("A{$rowIndex}")->getCalculatedValue() === 'Resumen comisiones') {
|
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'MONTO') {
|
||||||
|
$found = true;
|
||||||
|
foreach ($row->getColumnIterator() as $column) {
|
||||||
|
if ($column->getValue() === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$columns[$column->getColumn()] = trim($column->getValue());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($sheet->getCell("A{$row->getRowIndex()}")->getValue() === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$cols = $row->getColumnIterator('A', 'H');
|
|
||||||
$colIndex = 0;
|
|
||||||
$rowData = [];
|
$rowData = [];
|
||||||
foreach ($cols as $col) {
|
foreach ($columns as $columnIndex => $column) {
|
||||||
$value = $col->getCalculatedValue();
|
$value = $sheet->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue();
|
||||||
$col = $columns[$colIndex];
|
$mapped = $this->columnMap()[$column] ?? $column;
|
||||||
if ($col === 'FECHA') {
|
if ($mapped === 'fecha') {
|
||||||
list($d,$m,$Y) = explode('/', $value);
|
$value = implode('-', array_reverse(explode('/', $value)));
|
||||||
$value = "{$Y}-{$m}-{$d}";
|
|
||||||
}
|
}
|
||||||
$rowData[$col] = $value;
|
if ($column === 'MONTO') {
|
||||||
$colIndex ++;
|
$value = (int) $value;
|
||||||
|
}
|
||||||
|
$rowData[$column] = $value;
|
||||||
}
|
}
|
||||||
if ($rowData['CARGO/ABONO'] === 'C') {
|
if ($rowData['CARGO/ABONO'] === 'C') {
|
||||||
$rowData['cargo'] = -$rowData['MONTO'];
|
$rowData['MONTO'] = -$rowData['MONTO'];
|
||||||
|
$rowData['cargo'] = $rowData['MONTO'];
|
||||||
$rowData['abono'] = 0;
|
$rowData['abono'] = 0;
|
||||||
} else {
|
} else {
|
||||||
$rowData['cargo'] = 0;
|
$rowData['cargo'] = 0;
|
||||||
$rowData['abono'] = $rowData['MONTO'];
|
$rowData['abono'] = $rowData['MONTO'];
|
||||||
}
|
}
|
||||||
$data []= $rowData;
|
$data []= $rowData;
|
||||||
$rowIndex ++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -9,6 +9,13 @@ use Incoviba\Common\Ideal\Cartola\Banco;
|
|||||||
|
|
||||||
class Security extends Banco
|
class Security extends Banco
|
||||||
{
|
{
|
||||||
|
public function processMovimientosDiarios(array $movimientos): array
|
||||||
|
{
|
||||||
|
$movimientos = array_reverse($movimientos);
|
||||||
|
array_shift($movimientos);
|
||||||
|
return $movimientos;
|
||||||
|
}
|
||||||
|
|
||||||
protected function parseFile(UploadedFileInterface $uploadedFile): array
|
protected function parseFile(UploadedFileInterface $uploadedFile): array
|
||||||
{
|
{
|
||||||
$stream = $uploadedFile->getStream();
|
$stream = $uploadedFile->getStream();
|
||||||
@ -24,8 +31,10 @@ class Security extends Banco
|
|||||||
'fecha' => 'fecha',
|
'fecha' => 'fecha',
|
||||||
'descripción' => 'glosa',
|
'descripción' => 'glosa',
|
||||||
'número de documentos' => 'documento',
|
'número de documentos' => 'documento',
|
||||||
|
'nº documento' => 'documento',
|
||||||
'cargos' => 'cargo',
|
'cargos' => 'cargo',
|
||||||
'abonos' => 'abono'
|
'abonos' => 'abono',
|
||||||
|
'saldos' => 'saldo'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,10 +42,9 @@ class Security extends Banco
|
|||||||
{
|
{
|
||||||
$filename = '/tmp/cartola.xls';
|
$filename = '/tmp/cartola.xls';
|
||||||
$file->moveTo($filename);
|
$file->moveTo($filename);
|
||||||
$reader = PhpSpreadsheet\IOFactory::createReader('Xls');
|
$xlsx = @PhpSpreadsheet\IOFactory::load($filename);
|
||||||
$xlsx = $reader->load($filename);
|
|
||||||
$worksheet = $xlsx->getActiveSheet();
|
$worksheet = $xlsx->getActiveSheet();
|
||||||
$rows = $worksheet->getRowIterator();
|
$rows = $worksheet->getRowIterator(3);
|
||||||
$dataFound = false;
|
$dataFound = false;
|
||||||
$columns = [];
|
$columns = [];
|
||||||
$data = [];
|
$data = [];
|
||||||
@ -44,10 +52,10 @@ class Security extends Banco
|
|||||||
$cells = $row->getCellIterator();
|
$cells = $row->getCellIterator();
|
||||||
$rowData = [];
|
$rowData = [];
|
||||||
foreach ($cells as $cell) {
|
foreach ($cells as $cell) {
|
||||||
if ($cell->getColumn() === 'A' and $cell->getCalculatedValue() === "fecha ") {
|
if ($cell->getColumn() === 'A' and $cell->getCalculatedValue() !== null and strtolower($cell->getCalculatedValue()) === "fecha ") {
|
||||||
$cols = $row->getColumnIterator();
|
$cols = $row->getColumnIterator();
|
||||||
foreach ($cols as $col) {
|
foreach ($cols as $col) {
|
||||||
$columns[$col->getColumn()] = trim($col->getCalculatedValue());
|
$columns[$col->getColumn()] = trim(strtolower($col->getCalculatedValue()), ' ');
|
||||||
}
|
}
|
||||||
$dataFound = true;
|
$dataFound = true;
|
||||||
break;
|
break;
|
||||||
@ -62,7 +70,11 @@ class Security extends Banco
|
|||||||
$col = $columns[$cell->getColumn()];
|
$col = $columns[$cell->getColumn()];
|
||||||
$value = $cell->getCalculatedValue();
|
$value = $cell->getCalculatedValue();
|
||||||
if ($col === 'fecha') {
|
if ($col === 'fecha') {
|
||||||
$value = PhpSpreadsheet\Shared\Date::excelToDateTimeObject($cell->getValue(), 'America/Santiago')->format('Y-m-d');
|
if ((int) $cell->getValue() !== $cell->getValue()) {
|
||||||
|
$value = implode('-', array_reverse(explode('-', $cell->getValue())));
|
||||||
|
} else {
|
||||||
|
$value = PhpSpreadsheet\Shared\Date::excelToDateTimeObject($cell->getValue(), 'America/Santiago')->format('Y-m-d');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$rowData[$col] = $value;
|
$rowData[$col] = $value;
|
||||||
}
|
}
|
||||||
|
20
app/src/Service/Contabilidad.php
Normal file
20
app/src/Service/Contabilidad.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
|
||||||
|
class Contabilidad extends Ideal\Controller
|
||||||
|
{
|
||||||
|
public function __construct(LoggerInterface $logger,
|
||||||
|
protected Contabilidad\Informe\Tesoreria $tesoreriaService)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tesoreria(DateTimeInterface $fecha): array
|
||||||
|
{
|
||||||
|
return $this->tesoreriaService->build($fecha);
|
||||||
|
}
|
||||||
|
}
|
280
app/src/Service/Contabilidad/Informe/Tesoreria.php
Normal file
280
app/src/Service/Contabilidad/Informe/Tesoreria.php
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Service\Contabilidad\Informe;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use DateInterval;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Model;
|
||||||
|
|
||||||
|
class Tesoreria extends Ideal\Service
|
||||||
|
{
|
||||||
|
public function __construct(LoggerInterface $logger,
|
||||||
|
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
|
protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
|
protected Repository\Deposito $depositoRepository,
|
||||||
|
protected Repository\Cartola $cartolaRepository,
|
||||||
|
protected Repository\Movimiento $movimientoRepository)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
|
||||||
|
$this->movimientos = new class() {
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->dap = new class()
|
||||||
|
{
|
||||||
|
public array $ingresos = [];
|
||||||
|
public array $egresos = [];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public object $dap;
|
||||||
|
public array $ingresos = [];
|
||||||
|
public array $egresos = [];
|
||||||
|
|
||||||
|
const INGRESOS = 'ingresos';
|
||||||
|
const EGRESOS = 'egresos';
|
||||||
|
public function addDap(string $tipo, array $movimientos)
|
||||||
|
{
|
||||||
|
foreach ($movimientos as $movimiento) {
|
||||||
|
$this->dap->{$tipo} []= $movimiento;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function build(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'capital dap' => [
|
||||||
|
'ingresos' => $this->dap->ingresos,
|
||||||
|
'egresos' => $this->dap->egresos
|
||||||
|
],
|
||||||
|
'ingresos' => $this->ingresos,
|
||||||
|
'egresos' => $this->egresos
|
||||||
|
];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$this->totales = new class() {
|
||||||
|
public int $anterior = 0;
|
||||||
|
public int $actual = 0;
|
||||||
|
public int $ffmm = 0;
|
||||||
|
public int $deposito = 0;
|
||||||
|
|
||||||
|
public function diferencia(): int
|
||||||
|
{
|
||||||
|
return $this->actual - $this->anterior;
|
||||||
|
}
|
||||||
|
public function saldo(): int
|
||||||
|
{
|
||||||
|
return $this->diferencia() + $this->ffmm + $this->deposito;
|
||||||
|
}
|
||||||
|
public function cuentas(): int
|
||||||
|
{
|
||||||
|
return $this->actual;
|
||||||
|
}
|
||||||
|
public function ffmms(): int
|
||||||
|
{
|
||||||
|
return $this->ffmm;
|
||||||
|
}
|
||||||
|
public function depositos(): int
|
||||||
|
{
|
||||||
|
return $this->deposito;
|
||||||
|
}
|
||||||
|
public function caja(): int
|
||||||
|
{
|
||||||
|
return $this->cuentas() + $this->ffmms() + $this->depositos();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const DAP_INGRESOS = 'dap->ingresos';
|
||||||
|
const DAP_EGRESOS = 'dap->egresos';
|
||||||
|
const INGRESOS = 'ingresos';
|
||||||
|
const EGRESOS = 'egresos';
|
||||||
|
const TOTAL_ANTERIOR = 'anterior';
|
||||||
|
const TOTAL_ACTUAL = 'actual';
|
||||||
|
const TOTAL_FFMM = 'ffmm';
|
||||||
|
const TOTAL_DAP = 'deposito';
|
||||||
|
|
||||||
|
protected DateTimeInterface $anterior;
|
||||||
|
protected object $totales;
|
||||||
|
protected object $movimientos;
|
||||||
|
|
||||||
|
public function getAnterior(DateTimeInterface $fecha): DateTimeInterface
|
||||||
|
{
|
||||||
|
if (!isset($this->anterior)) {
|
||||||
|
$this->anterior = $fecha->sub(new DateInterval('P1D'));
|
||||||
|
if ($this->anterior->format('N') === '7') {
|
||||||
|
$this->anterior = $fecha->sub(new DateInterval('P3D'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->anterior;
|
||||||
|
}
|
||||||
|
public function build(DateTimeInterface $fecha): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$inmobiliarias = $this->inmobiliariaRepository->fetchAll();
|
||||||
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$informe = ['inmobiliarias' => []];
|
||||||
|
foreach ($inmobiliarias as $inmobiliaria) {
|
||||||
|
$informe['inmobiliarias'][$inmobiliaria->rut] = $this->buildInmobiliaria($inmobiliaria, $fecha);
|
||||||
|
}
|
||||||
|
$informe['movimientos'] = $this->buildMovimientos();
|
||||||
|
$informe['totales'] = $this->buildTotales();
|
||||||
|
return $informe;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildInmobiliaria(Model\Inmobiliaria $inmobiliaria, DateTimeInterface $fecha): object
|
||||||
|
{
|
||||||
|
$dataInmobiliaria = new class() {
|
||||||
|
public Model\Inmobiliaria $inmobiliaria;
|
||||||
|
public array $cuentas = [];
|
||||||
|
public function total(): int
|
||||||
|
{
|
||||||
|
return array_reduce($this->cuentas, function(int $sum, $cuenta) {
|
||||||
|
return $sum + $cuenta->actual;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
public function ffmm(): int
|
||||||
|
{
|
||||||
|
return array_reduce($this->cuentas, function(int $sum, $cuenta) {
|
||||||
|
return $sum + $cuenta->ffmm;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
public function deposito(): int
|
||||||
|
{
|
||||||
|
return array_reduce($this->cuentas, function(int $sum, $cuenta) {
|
||||||
|
return $sum + $cuenta->deposito;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
public function caja(): int
|
||||||
|
{
|
||||||
|
return array_reduce($this->cuentas, function(int $sum, $cuenta) {
|
||||||
|
return $sum + $cuenta->saldo();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$dataInmobiliaria->inmobiliaria = $inmobiliaria;
|
||||||
|
try {
|
||||||
|
$cuentas = $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria->rut);
|
||||||
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
|
return $dataInmobiliaria;
|
||||||
|
}
|
||||||
|
foreach ($cuentas as $cuenta) {
|
||||||
|
$data = new class() {
|
||||||
|
public string $banco;
|
||||||
|
public string $numero;
|
||||||
|
public int $anterior = 0;
|
||||||
|
public int $actual = 0;
|
||||||
|
public int $ffmm = 0;
|
||||||
|
public int $deposito = 0;
|
||||||
|
|
||||||
|
public function diferencia(): int
|
||||||
|
{
|
||||||
|
return $this->actual - $this->anterior;
|
||||||
|
}
|
||||||
|
public function saldo(): int
|
||||||
|
{
|
||||||
|
return $this->diferencia() + $this->ffmm + $this->deposito;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$data->banco = $cuenta->banco->nombre;
|
||||||
|
$data->numero = $cuenta->cuenta;
|
||||||
|
try {
|
||||||
|
$depositos = $this->depositoRepository->fetchByCuenta($cuenta->id);
|
||||||
|
foreach ($depositos as $deposito) {
|
||||||
|
if ($deposito->termino < $fecha) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$data->deposito += $deposito->capital;
|
||||||
|
$this->addTotal(self::TOTAL_DAP, $deposito->capital);
|
||||||
|
|
||||||
|
if ($deposito->inicio === $fecha) {
|
||||||
|
$this->addMovimientos(self::DAP_EGRESOS, [(object) [
|
||||||
|
'cuenta' => $deposito->cuenta,
|
||||||
|
'fecha' => $deposito->inicio,
|
||||||
|
'cargo' => - $deposito->capital,
|
||||||
|
'abono' => 0,
|
||||||
|
'saldo' => - $deposito->capital,
|
||||||
|
'glosa' => 'INVERSION DAP'
|
||||||
|
]]);
|
||||||
|
}
|
||||||
|
if ($deposito->termino === $fecha) {
|
||||||
|
$data->deposito -= $deposito->capital;
|
||||||
|
$this->addTotal(self::TOTAL_DAP, -$deposito->capital);
|
||||||
|
|
||||||
|
$this->addMovimientos(self::DAP_INGRESOS, [(object) [
|
||||||
|
'cuenta' => $deposito->cuenta,
|
||||||
|
'fecha' => $deposito->termino,
|
||||||
|
'cargo' => 0,
|
||||||
|
'abono' => $deposito->capital,
|
||||||
|
'saldo' => $deposito->capital,
|
||||||
|
'glosa' => 'RESCATE DAP'
|
||||||
|
]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
|
try {
|
||||||
|
$cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
|
$data->actual = $cartola->saldo;
|
||||||
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
|
try {
|
||||||
|
$cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $this->getAnterior($fecha));
|
||||||
|
$data->anterior = $cartola->saldo;
|
||||||
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
|
if ($data->diferencia() !== 0) {
|
||||||
|
try {
|
||||||
|
$movimientos = $this->movimientoRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
|
$this->addMovimientos(self::INGRESOS,
|
||||||
|
array_filter($movimientos, function(Model\Movimiento $movimiento) {
|
||||||
|
return $movimiento->abono > 0;
|
||||||
|
}));
|
||||||
|
$this->addMovimientos(self::EGRESOS,
|
||||||
|
array_filter($movimientos, function(Model\Movimiento $movimiento) {
|
||||||
|
return $movimiento->cargo > 0;
|
||||||
|
}));
|
||||||
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
|
}
|
||||||
|
$dataInmobiliaria->cuentas []= $data;
|
||||||
|
|
||||||
|
$this->addTotal(
|
||||||
|
[self::TOTAL_ANTERIOR, self::TOTAL_ACTUAL],
|
||||||
|
[$data->anterior, $data->actual]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $dataInmobiliaria;
|
||||||
|
}
|
||||||
|
protected function buildMovimientos(): array
|
||||||
|
{
|
||||||
|
return $this->movimientos->build();
|
||||||
|
}
|
||||||
|
protected function buildTotales(): object
|
||||||
|
{
|
||||||
|
return $this->totales;
|
||||||
|
}
|
||||||
|
protected function addMovimientos(string $tipo, array $movimientos): Tesoreria
|
||||||
|
{
|
||||||
|
if (str_contains($tipo, 'dap')) {
|
||||||
|
list($d, $t) = explode('->', $tipo);
|
||||||
|
$this->movimientos->addDap($t, $movimientos);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
foreach ($movimientos as $movimiento) {
|
||||||
|
$this->movimientos->{$tipo} []= $movimiento;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
protected function addTotal(string|array $tipo, int|array $total): Tesoreria
|
||||||
|
{
|
||||||
|
if (is_array($tipo)) {
|
||||||
|
foreach ($tipo as $i => $t) {
|
||||||
|
$this->addTotal($t, $total[$i]);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
$this->totales->{$tipo} += $total;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -4,20 +4,25 @@ namespace Incoviba\Service\Contabilidad;
|
|||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
use Psr\Http\Message\RequestFactoryInterface;
|
use Psr\Http\Message\RequestFactoryInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Incoviba\Common\Implement\Exception;
|
use Incoviba\Common\Implement\Exception;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Incoviba\Common\Ideal;
|
||||||
use Psr\Http\Message\StreamInterface;
|
|
||||||
use function Symfony\Component\Translation\t;
|
|
||||||
|
|
||||||
class Nubox
|
class Nubox extends Ideal\Service
|
||||||
{
|
{
|
||||||
public function __construct(protected Repository\Nubox $nuboxRepository,
|
public function __construct(protected LoggerInterface $logger,
|
||||||
|
protected Repository\Nubox $nuboxRepository,
|
||||||
protected Service\Redis $redisService,
|
protected Service\Redis $redisService,
|
||||||
protected ClientInterface $client,
|
protected ClientInterface $client,
|
||||||
protected RequestFactoryInterface $requestFactory,
|
protected RequestFactoryInterface $requestFactory,
|
||||||
protected string $api_url) {}
|
protected string $api_url)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
protected array $tokens;
|
protected array $tokens;
|
||||||
public function getToken(int $inmobiliaria_rut): string
|
public function getToken(int $inmobiliaria_rut): string
|
||||||
@ -120,7 +125,7 @@ class Nubox
|
|||||||
$uri = 'contabilidad/libro-diario?' . http_build_query($query);
|
$uri = 'contabilidad/libro-diario?' . http_build_query($query);
|
||||||
$response = $this->send($uri, $inmobiliaria_rut);
|
$response = $this->send($uri, $inmobiliaria_rut);
|
||||||
if ($response->getStatusCode() !== 200) {
|
if ($response->getStatusCode() !== 200) {
|
||||||
error_log(var_export($uri,true).PHP_EOL,3,'/logs/debug');
|
$this->logger->debug($uri);
|
||||||
throw new Exception\HttpResponse($response->getReasonPhrase(), $response->getStatusCode());
|
throw new Exception\HttpResponse($response->getReasonPhrase(), $response->getStatusCode());
|
||||||
}
|
}
|
||||||
return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||||
|
@ -25,12 +25,12 @@ class Format
|
|||||||
{
|
{
|
||||||
return "{$this->number($number, $decimal_places)}%";
|
return "{$this->number($number, $decimal_places)}%";
|
||||||
}
|
}
|
||||||
public function pesos(string $valor): string
|
public function pesos(string $valor, int $decimal_places = 0): string
|
||||||
{
|
{
|
||||||
return "$ {$this->number($valor)}";
|
return "$ {$this->number($valor, $decimal_places)}";
|
||||||
}
|
}
|
||||||
public function ufs(string $valor): string
|
public function ufs(string $valor, int $decimal_places = 2): string
|
||||||
{
|
{
|
||||||
return "{$this->number($valor, 2)} UF";
|
return "{$this->number($valor, $decimal_places)} UF";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,12 @@ use DateInterval;
|
|||||||
use Incoviba\Common\Define\Money\Provider;
|
use Incoviba\Common\Define\Money\Provider;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||||
use Incoviba\Service\Money\MiIndicador;
|
use Incoviba\Service\Money\MiIndicador;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Money
|
class Money
|
||||||
{
|
{
|
||||||
|
public function __construct(protected LoggerInterface $logger) {}
|
||||||
|
|
||||||
protected array $providers;
|
protected array $providers;
|
||||||
public function register(string $name, Provider $provider): Money
|
public function register(string $name, Provider $provider): Money
|
||||||
{
|
{
|
||||||
@ -49,4 +52,13 @@ class Money
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function getUSD(DateTimeInterface $dateTime): float
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->getProvider('usd')->get(MiIndicador::USD, $dateTime);
|
||||||
|
} catch (EmptyResponse $exception) {
|
||||||
|
$this->logger->critical($exception);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class MiIndicador implements Provider
|
|||||||
{
|
{
|
||||||
const UF = 'uf';
|
const UF = 'uf';
|
||||||
const IPC = 'ipc';
|
const IPC = 'ipc';
|
||||||
const USD = 'dolar_intercambio';
|
const USD = 'dolar';
|
||||||
|
|
||||||
public function __construct(protected ClientInterface $client) {}
|
public function __construct(protected ClientInterface $client) {}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ class Search
|
|||||||
}
|
}
|
||||||
protected function findPago(string $query): array
|
protected function findPago(string $query): array
|
||||||
{
|
{
|
||||||
if ($query != 0) {
|
if ((int) $query === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$methods = [
|
$methods = [
|
||||||
|
34
app/src/Service/USD.php
Normal file
34
app/src/Service/USD.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
|
|
||||||
|
class USD
|
||||||
|
{
|
||||||
|
protected string $redisKey = 'usd';
|
||||||
|
|
||||||
|
public function __construct(protected Redis $redisService, protected Money $moneyService) {}
|
||||||
|
|
||||||
|
public function get(?DateTimeInterface $date = null): float
|
||||||
|
{
|
||||||
|
if ($date === null) {
|
||||||
|
$date = new DateTimeImmutable();
|
||||||
|
}
|
||||||
|
$usds = [];
|
||||||
|
try {
|
||||||
|
$usds = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
|
||||||
|
if (!isset($usds[$date->format('Y-m-d')])) {
|
||||||
|
throw new EmptyRedis($this->redisKey);
|
||||||
|
}
|
||||||
|
$usd = $usds[$date->format('Y-m-d')];
|
||||||
|
} catch (EmptyRedis) {
|
||||||
|
$usd = $this->moneyService->getUSD($date);
|
||||||
|
$usds[$date->format('Y-m-d')] = $usd;
|
||||||
|
ksort($usds);
|
||||||
|
$this->redisService->set($this->redisKey, json_encode($usds), 60 * 60 * 24 * 30);
|
||||||
|
}
|
||||||
|
return $usd;
|
||||||
|
}
|
||||||
|
}
|
@ -2,14 +2,17 @@
|
|||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use PhpParser\Node\Expr\AssignOp\Mod;
|
use PhpParser\Node\Expr\AssignOp\Mod;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Venta
|
class Venta extends Service
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
LoggerInterface $logger,
|
||||||
protected Repository\Venta $ventaRepository,
|
protected Repository\Venta $ventaRepository,
|
||||||
protected Repository\Venta\EstadoVenta $estadoVentaRepository,
|
protected Repository\Venta\EstadoVenta $estadoVentaRepository,
|
||||||
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
|
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
|
||||||
@ -25,7 +28,9 @@ class Venta
|
|||||||
protected Venta\BonoPie $bonoPieService,
|
protected Venta\BonoPie $bonoPieService,
|
||||||
protected Venta\Pago $pagoService,
|
protected Venta\Pago $pagoService,
|
||||||
protected Money $moneyService
|
protected Money $moneyService
|
||||||
) {}
|
) {
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
public function getById(int $venta_id): Model\Venta
|
public function getById(int $venta_id): Model\Venta
|
||||||
{
|
{
|
||||||
@ -51,6 +56,10 @@ class Venta
|
|||||||
$ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo);
|
$ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo);
|
||||||
return array_map([$this, 'process'], $ventas);
|
return array_map([$this, 'process'], $ventas);
|
||||||
}
|
}
|
||||||
|
public function getByUnidadId(int $unidad_id): Model\Venta
|
||||||
|
{
|
||||||
|
return $this->process($this->ventaRepository->fetchByUnidadId($unidad_id));
|
||||||
|
}
|
||||||
public function getByPropietario(string $propietario): array
|
public function getByPropietario(string $propietario): array
|
||||||
{
|
{
|
||||||
$ventas = $this->ventaRepository->fetchByPropietario($propietario);
|
$ventas = $this->ventaRepository->fetchByPropietario($propietario);
|
||||||
@ -89,7 +98,7 @@ class Venta
|
|||||||
'propietario' => $propietario->rut,
|
'propietario' => $propietario->rut,
|
||||||
'propiedad' => $propiedad->id,
|
'propiedad' => $propiedad->id,
|
||||||
'fecha' => $fecha->format('Y-m-d'),
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
'valor_uf' => $data['valor'],
|
'valor_uf' => $this->cleanValue($data['valor']),
|
||||||
'fecha_ingreso' => (new DateTimeImmutable())->format('Y-m-d'),
|
'fecha_ingreso' => (new DateTimeImmutable())->format('Y-m-d'),
|
||||||
'uf' => $data['uf']
|
'uf' => $data['uf']
|
||||||
];
|
];
|
||||||
@ -249,6 +258,7 @@ class Venta
|
|||||||
'cuotas',
|
'cuotas',
|
||||||
'uf'
|
'uf'
|
||||||
], $filtered_data);
|
], $filtered_data);
|
||||||
|
$mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
|
||||||
return $this->pieService->add($mapped_data);
|
return $this->pieService->add($mapped_data);
|
||||||
}
|
}
|
||||||
protected function addSubsidio(array $data): Model\Venta\Subsidio
|
protected function addSubsidio(array $data): Model\Venta\Subsidio
|
||||||
@ -307,6 +317,13 @@ class Venta
|
|||||||
$estado = $this->estadoVentaRepository->create($estadoData);
|
$estado = $this->estadoVentaRepository->create($estadoData);
|
||||||
$this->estadoVentaRepository->save($estado);
|
$this->estadoVentaRepository->save($estado);
|
||||||
}
|
}
|
||||||
|
protected function cleanValue($value): float
|
||||||
|
{
|
||||||
|
if ((float) $value == $value) {
|
||||||
|
return (float) $value;
|
||||||
|
}
|
||||||
|
return (float) str_replace(['.', ','], ['', '.'], $value);
|
||||||
|
}
|
||||||
|
|
||||||
public function escriturar(Model\Venta $venta, array $data): bool
|
public function escriturar(Model\Venta $venta, array $data): bool
|
||||||
{
|
{
|
||||||
|
@ -2,20 +2,25 @@
|
|||||||
namespace Incoviba\Service\Venta;
|
namespace Incoviba\Service\Venta;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Service\Money;
|
use Incoviba\Service\Money;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Credito
|
class Credito extends Service
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
LoggerInterface $logger,
|
||||||
protected Repository\Venta\Credito $creditoRepository,
|
protected Repository\Venta\Credito $creditoRepository,
|
||||||
protected Repository\Venta\Pago $pagoRepository,
|
protected Repository\Venta\Pago $pagoRepository,
|
||||||
protected Repository\Venta\TipoPago $tipoPagoRepository,
|
protected Repository\Venta\TipoPago $tipoPagoRepository,
|
||||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||||
protected Money $moneyService
|
protected Money $moneyService
|
||||||
) {}
|
) {
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
public function add(array $data): Model\Venta\Credito
|
public function add(array $data): Model\Venta\Credito
|
||||||
{
|
{
|
||||||
@ -30,6 +35,27 @@ class Credito
|
|||||||
]);
|
]);
|
||||||
return $this->creditoRepository->save($credito);
|
return $this->creditoRepository->save($credito);
|
||||||
}
|
}
|
||||||
|
public function edit(Model\Venta\Credito $credito, array $data): Model\Venta\Credito
|
||||||
|
{
|
||||||
|
$uf = $this->moneyService->getUF($credito->pago->fecha);
|
||||||
|
if (array_key_exists('fecha', $data)) {
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
$data['fecha'] = $fecha->format('Y-m-d');
|
||||||
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
|
$data['uf'] = $uf;
|
||||||
|
}
|
||||||
|
if (array_key_exists('valor', $data)) {
|
||||||
|
$data['valor'] = round(((float) $data['valor']) * $uf);
|
||||||
|
}
|
||||||
|
$filteredData = array_intersect_key($data, array_fill_keys([
|
||||||
|
'fecha',
|
||||||
|
'uf',
|
||||||
|
'valor',
|
||||||
|
'banco'
|
||||||
|
], 0));
|
||||||
|
$credito->pago = $this->pagoRepository->edit($credito->pago, $filteredData);
|
||||||
|
return $this->creditoRepository->edit($credito, $filteredData);
|
||||||
|
}
|
||||||
protected function addPago(array $data): Model\Venta\Pago
|
protected function addPago(array $data): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
$pago = $this->pagoRepository->create($data);
|
$pago = $this->pagoRepository->create($data);
|
||||||
|
@ -1,28 +1,37 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Venta;
|
namespace Incoviba\Service\Venta;
|
||||||
|
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Propietario
|
class Propietario extends Service
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
LoggerInterface $logger,
|
||||||
protected Repository\Venta\Propietario $propietarioRepository,
|
protected Repository\Venta\Propietario $propietarioRepository,
|
||||||
protected Repository\Direccion $direccionRepository
|
protected Repository\Direccion $direccionRepository
|
||||||
) {}
|
) {
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
public function addPropietario(array $data): Model\Venta\Propietario
|
public function addPropietario(array $data): Model\Venta\Propietario
|
||||||
{
|
{
|
||||||
$direccion = $this->addDireccion($data);
|
$direccion = $this->addDireccion($data);
|
||||||
$data['direccion'] = $direccion->id;
|
$data['direccion'] = $direccion->id;
|
||||||
|
$data['dv'] = 'i';
|
||||||
|
|
||||||
if (str_contains($data['rut'], '-')) {
|
if (str_contains($data['rut'], '-')) {
|
||||||
$data['rut'] = explode('-', $data['rut'])[0];
|
list($rut, $dv) = explode('-', $data['rut']);
|
||||||
|
$data['rut'] = $rut;
|
||||||
|
$data['dv'] = $dv;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = array_fill_keys([
|
$fields = array_fill_keys([
|
||||||
'rut',
|
'rut',
|
||||||
|
'dv',
|
||||||
'nombres',
|
'nombres',
|
||||||
'apellido_paterno',
|
'apellido_paterno',
|
||||||
'apellido_materno',
|
'apellido_materno',
|
||||||
|
5
cli/bin/incoviba
Executable file
5
cli/bin/incoviba
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
. /etc/profile
|
||||||
|
|
||||||
|
/usr/local/bin/php /code/bin/index.php "$@"
|
16
cli/crontab
16
cli/crontab
@ -1,8 +1,8 @@
|
|||||||
0 2 * * * php /code/bin/index.php ventas:cuotas:hoy 2>&1 >> /logs/commands
|
0 2 * * * /code/bin/incoviba ventas:cuotas:hoy >> /logs/commands 2>&1
|
||||||
0 2 * * * php /code/bin/index.php ventas:cuotas:pendientes 2>&1 >> /logs/commands
|
0 2 * * * /code/bin/incoviba ventas:cuotas:pendientes >> /logs/commands 2>&1
|
||||||
0 2 * * * php /code/bin/index.php ventas:cuotas:vencer 2>&1 >> /logs/commands
|
0 2 * * * /code/bin/incoviba ventas:cuotas:vencer >> /logs/commands 2>&1
|
||||||
0 2 * * * php /code/bin/index.php ventas:cierres:vigentes 2>&1 >> /logs/commands
|
0 2 * * * /code/bin/incoviba ventas:cierres:vigentes >> /logs/commands 2>&1
|
||||||
0 2 * * * php /code/bin/index.php proyectos:activos 2>&1 >> /logs/commands
|
* */3 * * * /code/bin/incoviba proyectos:activos >> /logs/commands 2>&1
|
||||||
0 2 * * * php /code/bin/index.php comunas 2>&1 >> /logs/commands
|
0 2 * * * /code/bin/incoviba comunas >> /logs/commands 2>&1
|
||||||
0 2 * * * php /code/bin/index.php money:uf 2>&1 >> /logs/commands
|
0 2 * * * /code/bin/incoviba money:uf >> /logs/commands 2>&1
|
||||||
0 2 1 * * php /code/bin/index.php money:ipc 2>&1 >> /logs/commands
|
0 2 1 * * /code/bin/incoviba money:ipc >> /logs/commands 2>&1
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
x-restart: &restart
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
proxy:
|
proxy:
|
||||||
profiles:
|
profiles:
|
||||||
- app
|
- app
|
||||||
image: nginx:alpine
|
image: nginx:alpine
|
||||||
container_name: incoviba_proxy
|
container_name: incoviba_proxy
|
||||||
<<: *restart
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "${APP_PORT}:80"
|
- "${APP_PORT}:80"
|
||||||
volumes:
|
volumes:
|
||||||
@ -22,12 +17,10 @@ services:
|
|||||||
- app
|
- app
|
||||||
build: .
|
build: .
|
||||||
container_name: incoviba_web
|
container_name: incoviba_web
|
||||||
<<: *restart
|
restart: unless-stopped
|
||||||
env_file:
|
env_file:
|
||||||
- ${APP_PATH:-.}/.env
|
- ${APP_PATH:-.}/.env
|
||||||
- ${APP_PATH:-.}/.db.env
|
|
||||||
- ./.key.env
|
- ./.key.env
|
||||||
#- ${APP_PATH:-.}/.remote.env
|
|
||||||
volumes:
|
volumes:
|
||||||
- ${APP_PATH:-.}/:/code
|
- ${APP_PATH:-.}/:/code
|
||||||
- ./logs/php:/logs
|
- ./logs/php:/logs
|
||||||
@ -37,7 +30,7 @@ services:
|
|||||||
- db
|
- db
|
||||||
image: mariadb:latest
|
image: mariadb:latest
|
||||||
container_name: incoviba_db
|
container_name: incoviba_db
|
||||||
<<: *restart
|
restart: unless-stopped
|
||||||
env_file: ${APP_PATH:-.}/.db.env
|
env_file: ${APP_PATH:-.}/.db.env
|
||||||
volumes:
|
volumes:
|
||||||
- dbdata:/var/lib/mysql
|
- dbdata:/var/lib/mysql
|
||||||
@ -53,22 +46,13 @@ services:
|
|||||||
- cache
|
- cache
|
||||||
image: redis
|
image: redis
|
||||||
container_name: incoviba_redis
|
container_name: incoviba_redis
|
||||||
<<: *restart
|
restart: unless-stopped
|
||||||
env_file: ${APP_PATH:-.}/.redis.env
|
env_file: ${APP_PATH:-.}/.redis.env
|
||||||
volumes:
|
volumes:
|
||||||
- incoviba_redis:/data
|
- incoviba_redis:/data
|
||||||
ports:
|
ports:
|
||||||
- "63790:6379"
|
- "63790:6379"
|
||||||
|
|
||||||
python:
|
|
||||||
profiles:
|
|
||||||
- python
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Python.Dockerfile
|
|
||||||
container_name: incoviba_python
|
|
||||||
<<: *restart
|
|
||||||
|
|
||||||
logview:
|
logview:
|
||||||
profiles:
|
profiles:
|
||||||
- log
|
- log
|
||||||
@ -81,7 +65,7 @@ services:
|
|||||||
WEB_URL: 'http://provm.cl:8084'
|
WEB_URL: 'http://provm.cl:8084'
|
||||||
WEB_PORT: '8084'
|
WEB_PORT: '8084'
|
||||||
volumes:
|
volumes:
|
||||||
- "./logs:/logs"
|
- ./logs:/logs
|
||||||
ports:
|
ports:
|
||||||
- "8084:80"
|
- "8084:80"
|
||||||
cli:
|
cli:
|
||||||
@ -91,7 +75,7 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: CLI.Dockerfile
|
dockerfile: CLI.Dockerfile
|
||||||
container_name: incoviba_cli
|
container_name: incoviba_cli
|
||||||
<<: *restart
|
restart: unless-stopped
|
||||||
env_file:
|
env_file:
|
||||||
- ${CLI_PATH:-.}/.env
|
- ${CLI_PATH:-.}/.env
|
||||||
- ./.key.env
|
- ./.key.env
|
||||||
|
Reference in New Issue
Block a user