38 Commits

Author SHA1 Message Date
ad3285efd9 FIX: find ventas por proyecto y unidad 2024-01-30 12:07:43 -03:00
9d7857621e FIX: findPago sin numero 2024-01-22 12:10:16 -03:00
029cd095cb Base Log cli 2024-01-19 23:27:06 -03:00
c1792907c0 Basic Controller and Service 2024-01-19 23:12:13 -03:00
fa11f5b240 Cleanup logs, fixed add Venta, fixed search 2024-01-19 23:10:20 -03:00
f55e4dbd5f ventas.base 2024-01-18 17:15:32 -03:00
ca83472012 Informe escritura 2024-01-18 16:41:16 -03:00
01af47fba1 FIX: escriturar 2024-01-18 15:18:07 -03:00
e1462657fc Clave -> Contraseña 2024-01-18 13:20:02 -03:00
72f63c5e6c Cleanup 2024-01-18 13:17:23 -03:00
1f076bc2f1 FIX: IPC y factura 2024-01-18 13:15:26 -03:00
ad003c7dcf Cleanup 2024-01-18 13:05:36 -03:00
aef1ccd4a0 Santander 2024-01-17 18:27:29 -03:00
3684bc2e21 FIX: glosa 2024-01-17 16:21:40 -03:00
d1d3705a7b Cambio base Cartola/Banco e implementacion de Itau 2024-01-17 16:19:38 -03:00
ecdb67a9ab FIX: Security en htm 2024-01-17 14:31:49 -03:00
4c86ce2a8a TipoUnidad por Proyecto 2024-01-17 11:22:10 -03:00
5c6bd91425 Missing updates 2024-01-17 11:15:13 -03:00
18d7e449f7 Missing updates 2024-01-17 11:13:27 -03:00
bfdaf0e7f2 Missing updates 2024-01-17 11:10:56 -03:00
ce0510687a Menu Centros de Costos 2024-01-17 11:05:25 -03:00
3eb4ce4d21 Max log files 2024-01-17 10:49:14 -03:00
674aba801e Cartolas 2024-01-17 10:33:11 -03:00
c4f486d3fa Disable edit of Centros Costos 2024-01-10 20:47:39 -03:00
dc840a7bff Sort Centros Costos 2024-01-10 20:36:18 -03:00
316cc51387 FIX: Tipo Cuenta 2024-01-10 20:32:55 -03:00
68e59770fd Menu contabilidad 2024-01-10 19:34:41 -03:00
a66b549a8c Centros de Costos 2024-01-09 23:35:35 -03:00
74b3bb42ea Add sorting to fetchAll 2024-01-09 23:35:11 -03:00
72a2ffe924 Error code change 2024-01-08 21:25:02 -03:00
6393a1fced Implement movimientos cuotas 2024-01-08 21:24:34 -03:00
d225011ae9 Implement search pago 2024-01-08 17:33:42 -03:00
bc2333bc95 FIX: Pie cuotas valores uf 2024-01-08 13:16:12 -03:00
675b3843ea FIX: Pie cuotas vigentes 2023-12-22 14:15:09 -03:00
0829d338a9 FIX: null date 2023-12-22 14:14:02 -03:00
20b2bdc6c6 FIX: Cuotas vigentes 2023-12-22 13:17:03 -03:00
8492d1df2b Eliminar desistimiento y loading en editar desistimiento 2023-12-22 12:52:04 -03:00
afbadd520b FIX: when new value is null 2023-12-22 12:50:09 -03:00
112 changed files with 3845 additions and 758 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@
**/cache/ **/cache/
**/modules/ **/modules/
**/.idea/ **/.idea/
**/upload?/

View File

@ -0,0 +1,10 @@
<?php
namespace Incoviba\Common\Define\Cartola;
use Psr\Http\Message\UploadedFileInterface;
interface Banco
{
public function process(UploadedFileInterface $file): array;
}

View File

@ -0,0 +1,10 @@
<?php
namespace Incoviba\Common\Define\Contabilidad;
use DateTimeInterface;
use Incoviba\Model;
interface Exporter
{
public function export(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, array $movimientos): string;
}

View File

@ -0,0 +1,26 @@
<?php
namespace Incoviba\Common\Ideal\Cartola;
use Incoviba\Common\Define;
use Psr\Http\Message\UploadedFileInterface;
abstract class Banco implements Define\Cartola\Banco
{
public function process(UploadedFileInterface $file): array
{
$data = $this->parseFile($file);
$temp = [];
$columns = $this->columnMap();
foreach ($data as $row) {
$r = [];
foreach ($columns as $old => $new) {
$r[$new] = $row[$old];
}
$temp []= $r;
}
return $temp;
}
abstract protected function columnMap(): array;
abstract protected function parseFile(UploadedFileInterface $uploadedFile): array;
}

View File

@ -0,0 +1,9 @@
<?php
namespace Incoviba\Common\Ideal;
use Psr\Log\LoggerInterface;
abstract class Controller
{
public function __construct(protected LoggerInterface $logger) {}
}

View File

@ -45,11 +45,14 @@ abstract class Repository implements Define\Repository
->where("{$this->getKey()} = ?"); ->where("{$this->getKey()} = ?");
return $this->fetchOne($query, [$id]); return $this->fetchOne($query, [$id]);
} }
public function fetchAll(): array public function fetchAll(null|string|array $ordering = null): array
{ {
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()
->select() ->select()
->from($this->getTable()); ->from($this->getTable());
if ($ordering !== null) {
$query->order($ordering);
}
return $this->fetchMany($query); return $this->fetchMany($query);
} }
@ -116,7 +119,7 @@ abstract class Repository implements Define\Repository
$changes = []; $changes = [];
$values = []; $values = [];
foreach ($columns as $column) { foreach ($columns as $column) {
if (isset($data[$column])) { if (in_array($column, array_keys($data))) {
$changes []= $column; $changes []= $column;
$values []= $data[$column]; $values []= $data[$column];
} }

View File

@ -0,0 +1,9 @@
<?php
namespace Incoviba\Common\Ideal;
use Psr\Log\LoggerInterface;
abstract class Service
{
public function __construct(protected LoggerInterface $logger) {}
}

View File

@ -62,7 +62,11 @@ class Mapper implements Define\Repository\Mapper
} }
$value = $data[$column]; $value = $data[$column];
if ($this->hasFunction()) { if ($this->hasFunction()) {
$value = ($this->function)($data); if ($value !== null) {
$value = ($this->function)($data);
} elseif ($this->hasDefault()) {
$value = $this->default;
}
} }
$model->{$property} = $value; $model->{$property} = $value;
return true; return true;

View File

@ -9,7 +9,7 @@ class DateTime extends Mapper
public function __construct(string $column, ?string $property = null) public function __construct(string $column, ?string $property = null)
{ {
$this->setFunction(function($data) use ($column) { $this->setFunction(function($data) use ($column) {
return new DateTimeImmutable($data[$column]); return new DateTimeImmutable($data[$column] ?? '');
}); });
if ($property !== null) { if ($property !== null) {
$this->setProperty($property); $this->setProperty($property);

View File

@ -9,6 +9,7 @@
"nyholm/psr7-server": "^1.0", "nyholm/psr7-server": "^1.0",
"php-di/php-di": "^7.0", "php-di/php-di": "^7.0",
"php-di/slim-bridge": "^3.4", "php-di/slim-bridge": "^3.4",
"phpoffice/phpspreadsheet": "^1.29",
"predis/predis": "^2.2", "predis/predis": "^2.2",
"slim/slim": "^4.11" "slim/slim": "^4.11"
}, },

View File

@ -0,0 +1,10 @@
<?php
$app->group('/contabilidad', function($app) {
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
});

View File

@ -0,0 +1,10 @@
<?php
$app->group('/contabilidad', function($app) {
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
});

View File

@ -0,0 +1,9 @@
<?php
use Incoviba\Controller\API\Contabilidad;
$app->group('/cartolas', function($app) {
$app->post('/procesar[/]', [Contabilidad::class, 'procesarCartola']);
});
$app->group('/cartola', function($app) {
$app->post('/exportar[/]', [Contabilidad::class, 'exportarCartola']);
});

View File

@ -0,0 +1,10 @@
<?php
use Incoviba\Controller\API\CentrosCostos;
$app->group('/centros_costos', function($app) {
$app->post('/add[/]', [CentrosCostos::class, 'add']);
});
$app->group('/centro_costo/{centro_costo_id}', function($app) {
$app->post('/edit[/]', [CentrosCostos::class, 'edit']);
$app->delete('[/]', [CentrosCostos::class, 'remove']);
});

View File

@ -0,0 +1,11 @@
<?php
use Incoviba\Controller\API\Nubox;
$app->group('/nubox/{inmobiliaria_rut}', function($app) {
$app->get('/token[/]', [Nubox::class, 'token']);
$app->get('/sistemas[/]', [Nubox::class, 'sistemas']);
$app->group('/libro', function($app) {
$app->post('/mayor[/]', [Nubox::class, 'libroMayor']);
$app->post('/diario[/]', [Nubox::class, 'libroDiario']);
});
});

View File

@ -0,0 +1,10 @@
<?php
use Incoviba\Controller\API\Inmobiliarias;
$app->group('/inmobiliarias', function($app) {
$app->get('[/]', Inmobiliarias::class);
});
$app->group('/inmobiliaria/{inmobiliaria_rut}', function($app) {
$app->get('/cuentas[/]', [Inmobiliarias::class, 'cuentas']);
$app->get('/proyectos[/]', [Inmobiliarias::class, 'proyectos']);
});

View File

@ -1,4 +1,4 @@
<?php <?php
use Incoviba\Controller\Search; use Incoviba\Controller\API\Search;
$app->post('/search', [Search::class, 'query']); $app->post('/search', [Search::class, 'query']);

View File

@ -25,7 +25,10 @@ $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->post('/escriturar[/]', [Ventas::class, 'escriturar']); $app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
$app->post('/desistir[/]', [Ventas::class, 'desistir']); $app->group('/desistir', function($app) {
$app->get('/eliminar[/]', [Ventas::class, 'insistir']);
$app->post('[/]', [Ventas::class, 'desistir']);
});
$app->post('[/]', [Ventas::class, 'edit']); $app->post('[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'get']); $app->get('[/]', [Ventas::class, 'get']);
}); });

View File

@ -7,7 +7,9 @@ $app->group('/pagos', function($app) {
$app->get('/rebotes', [Pagos::class, 'rebotes']); $app->get('/rebotes', [Pagos::class, 'rebotes']);
}); });
$app->group('/pago/{pago_id:[0-9]+}', function($app) { $app->group('/pago/{pago_id:[0-9]+}', function($app) {
$app->put('/depositar[/]', [Pagos::class, 'depositar']); $app->post('/depositar[/]', [Pagos::class, 'depositar']);
$app->put('/abonar[/]', [Pagos::class, 'abonar']); $app->post('/abonar[/]', [Pagos::class, 'abonar']);
$app->post('/devolver[/]', [Pagos::class, 'devolver']);
$app->get('/anular[/]', [Pagos::class, 'anular']);
$app->post('[/]', [Pagos::class, 'edit']); $app->post('[/]', [Pagos::class, 'edit']);
}); });

View File

@ -8,4 +8,5 @@ $app->group('/unidad/{unidad_id}', function($app) {
$app->group('/prorrateo', function($app) { $app->group('/prorrateo', function($app) {
$app->post('[/]', [Unidades::class, 'prorrateo']); $app->post('[/]', [Unidades::class, 'prorrateo']);
}); });
$app->get('[/]', [Unidades::class, 'get']);
}); });

View File

@ -0,0 +1,7 @@
<?php
use Incoviba\Controller\CentrosCostos;
$app->group('/centros_costos', function($app) {
$app->get('/asignar[/]', [CentrosCostos::class, 'asignar']);
$app->get('[/]', CentrosCostos::class);
});

View File

@ -2,5 +2,6 @@
use Incoviba\Controller\Ventas\Escrituras; use Incoviba\Controller\Ventas\Escrituras;
$app->group('/escritura/{venta_id}', function($app) { $app->group('/escritura/{venta_id}', function($app) {
$app->get('/informe[/]', [Escrituras::class, 'informe']);
$app->get('[/]', [Escrituras::class, 'show']); $app->get('[/]', [Escrituras::class, 'show']);
}); });

View File

@ -0,0 +1,330 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">
Centros de Costos
</h1>
{{--<div class="ui top attached right aligned basic segment">
<button class="ui tiny green icon button" id="add_button">
Agregar
<i class="plus icon"></i>
</button>
</div>--}}
<table class="ui table" id="centros_costos">
<thead>
<tr>
<th>Tipo de Centro</th>
<th>Categoría</th>
<th>Tipo de Cuenta</th>
<th>Cuenta Contable</th>
<th>Centro de Costo</th>
<th>Descripción</th>
{{--<th>
</th>--}}
</tr>
</thead>
<tbody>
@foreach ($centrosCostos as $centroCosto)
<tr data-id="{{$centroCosto->id}}">
<td data-id="{{$centroCosto->tipoCentro->id}}">{{$centroCosto->tipoCentro->descripcion}}</td>
<td data-id="{{$centroCosto->categoria->id}}">{{$centroCosto->categoria->descripcion}}</td>
<td data-id="{{$centroCosto->tipoCuenta?->id}}">{{$centroCosto->tipoCuenta?->descripcion}}</td>
<td>{{$centroCosto->cuentaContable}}</td>
<td>{{$centroCosto->id}}</td>
<td>{{$centroCosto->descripcion}}</td>
{{--<td>
<div class="ui mini buttons">
<button class="ui icon button edit_button" data-id="{{$centroCosto->id}}">
<i class="edit icon"></i>
</button>
<button class="ui red icon button remove_button" data-id="{{$centroCosto->id}}">
<i class="remove icon"></i>
</button>
</div>
</td>--}}
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="ui modal" id="modal_add">
<div class="content">
<form class="ui form" id="add_form">
<div class="fields">
<div class="three wide field">
<label for="tipo_centro">Tipo de Centro</label>
<div class="ui selection search dropdown" id="tipo_centro">
<input type="hidden" name="tipo_centro_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo</div>
<div class="menu">
@foreach ($tiposCentros as $tipoCentro)
<div class="item" data-value="{{$tipoCentro->id}}">{{$tipoCentro->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="tipo_cuenta">Tipo de Cuenta</label>
<div class="ui selection search dropdown" id="tipo_cuenta">
<input type="hidden" name="tipo_cuenta_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo de Cuenta</div>
<div class="menu">
<div class="item" data-value="">---</div>
@foreach ($tiposCuentas as $tipoCuenta)
<div class="item" data-value="{{$tipoCuenta->id}}">{{$tipoCuenta->descripcion}}</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="five wide field">
<label for="categoria">Categoría</label>
<div class="ui selection search dropdown" id="categoria">
<input type="hidden" name="categoria_id" />
<i class="dropdown icon"></i>
<div class="default text">Categoría</div>
<div class="menu">
@foreach ($categorias as $categoria)
<div class="item" data-value="{{$categoria->id}}">{{$categoria->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="cuenta_contable">Cuenta Contable</label>
<input type="text" name="cuenta_contable" id="cuenta_contable" />
</div>
<div class="two wide field">
<label for="identificador">Centro de Costo</label>
<input type="number" name="id" id="identificador" maxlength="3" />
</div>
<div class="field">
<label for="descripcion">Descripción</label>
<textarea id="descripcion" name="descripcion" class="ui textarea" rows="1" cols="10"></textarea>
</div>
</form>
</div>
<div class="actions">
<button class="ui positive icon button">
<i class="plus icon"></i>
Agregar
</button>
</div>
</div>
<div class="ui modal" id="modal_edit">
<div class="header">
Centro de Costo <span id="id"></span>
</div>
<div class="content">
<form class="ui form" id="edit_form">
<input type="hidden" name="id" id="identificador" />
<div class="fields">
<div class="three wide field">
<label for="tipo_centro">Tipo de Centro</label>
<div class="ui selection search dropdown" id="tipo_centro">
<input type="hidden" name="tipo_centro_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo</div>
<div class="menu">
@foreach ($tiposCentros as $tipoCentro)
<div class="item" data-value="{{$tipoCentro->id}}">{{$tipoCentro->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="tipo_cuenta">Tipo de Cuenta</label>
<div class="ui selection search dropdown" id="tipo_cuenta">
<input type="hidden" name="tipo_cuenta_id" />
<i class="dropdown icon"></i>
<div class="default text">Tipo de Cuenta</div>
<div class="menu">
<div class="item" data-value="">---</div>
@foreach ($tiposCuentas as $tipoCuenta)
<div class="item" data-value="{{$tipoCuenta->id}}">{{$tipoCuenta->descripcion}}</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="five wide field">
<label for="categoria">Categoría</label>
<div class="ui selection search dropdown" id="categoria">
<input type="hidden" name="categoria_id" />
<i class="dropdown icon"></i>
<div class="default text">Categoría</div>
<div class="menu">
@foreach ($categorias as $categoria)
<div class="item" data-value="{{$categoria->id}}">{{$categoria->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="three wide field">
<label for="cuenta_contable">Cuenta Contable</label>
<input type="text" name="cuenta_contable" id="cuenta_contable" />
</div>
<div class="field">
<label for="descripcion">Descripción</label>
<textarea id="descripcion" name="descripcion" class="ui textarea" rows="1" cols="10"></textarea>
</div>
</form>
</div>
<div class="actions">
<button class="ui positive icon button">
<i class="plus icon"></i>
Editar
</button>
</div>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script>
const centros = {
ids: {
table: '',
modals: {
add: '',
edit: ''
},
buttons: {
add: '',
edit: '',
remove: ''
},
forms: {
add: '',
edit: ''
}
},
setup: function({ids}) {
this.ids = ids
Object.keys(this.ids.modals).forEach(name => {
$(this.ids.modals[name]).modal({
onApprove: ($element) => {
this.actions()[name]()
},
onHidden: (modal) => {
document.getElementById(this.ids.forms[name]).reset()
}
})
$(this.ids.modals[name]).find('.dropdown').each((idx, item) => {
$(item).dropdown()
})
})
Object.keys(this.ids.buttons).forEach(name => {
if (name === 'remove') {
return
}
$(this.ids.buttons[name]).click(event => {
if (name === 'edit') {
const id = $(event.currentTarget).data('id')
const row = $("tr[data-id='" + id + "']")
const data = {
id,
tipo_centro_id: row.find(':nth-child(1)').data('id'),
categoria_id: row.find(':nth-child(2)').data('id'),
tipo_cuenta_id: row.find(':nth-child(3)').data('id'),
cuenta_contable: row.find(':nth-child(4)').html(),
descripcion: row.find(':nth-child(6)').html()
}
$(this.ids.modals[name]).find('#id').html(id)
const form = $('#' + this.ids.forms[name])
form.find("[name='id']").val(data.id)
form.find('#tipo_centro').dropdown('set selected', data.tipo_centro_id)
form.find('#categoria').dropdown('set selected', data.categoria_id)
form.find('#tipo_cuenta').dropdown('set selected', data.tipo_cuenta_id)
form.find('#cuenta_contable').val(data.cuenta_contable)
form.find('#descripcion').val(data.descripcion)
}
$(this.ids.modals[name]).modal('show')
})
})
$(this.ids.buttons.remove).click(event => {
const id = $(event.currentTarget).data('id')
this.actions().remove(id)
})
$(this.ids.table).dataTable({
order: [
[0, 'desc'],
[2, 'asc'],
[1, 'asc'],
[4, 'asc']
]
})
},
actions: function() {
return {
add: () => {
const body = new FormData(document.getElementById(this.ids.forms.add))
const url = '{{$urls->api}}/contabilidad/centros_costos/add'
fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.added) {
window.location.reload()
}
})
})
},
edit: () => {
const body = new FormData(document.getElementById(this.ids.forms.edit))
const url = '{{$urls->api}}/contabilidad/centro_costo/' + body.get('id') + '/edit'
fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.edited) {
window.location.reload()
}
})
})
},
remove: id => {
const url = '{{$urls->api}}/contabilidad/centro_costo/' + id
fetchAPI(url, {method: 'delete'}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.removed) {
window.location.reload()
}
})
})
}
}
}
}
$(document).ready(() => {
centros.setup({ids: {
table: '#centros_costos',
modals: {
add: '#modal_add',
edit: '#modal_edit'
},
buttons: {
add: '#add_button',
edit: '.edit_button',
remove: '.remove_button'
},
forms: {
add: 'add_form',
edit: 'edit_form'
}
}
})
})
</script>
@endpush

View File

@ -0,0 +1,399 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">Asignar Centros de Costos</h1>
<form class="ui form" id="asignar_form">
<div class="ui grid">
<div class="fourteen wide column">
<div class="fields">
<div class="five wide field">
<label>Inmobiliaria</label>
<div class="ui selection search dropdown" id="inmobiliaria">
<input type="hidden" name="inmobiliaria"/>
<i class="dropdown icon"></i>
<div class="default text">Inmobiliaria</div>
<div class="menu">
@foreach ($inmobiliarias as $inmobiliaria)
<div class="item" data-value="{{$inmobiliaria->rut}}">{{$inmobiliaria->razon}}</div>
@endforeach
</div>
</div>
</div>
<div class="two wide field">
<label>Banco</label>
<div class="ui selection search dropdown" id="banco">
<input type="hidden" name="banco"/>
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu"></div>
</div>
</div>
<div class="field">
<label>Mes</label>
<div class="ui calendar" id="mes">
<div class="ui icon input">
<i class="calendar icon"></i>
<input type="text" name="mes"/>
</div>
</div>
</div>
<div class="field">
<label for="file">Cartola</label>
<input type="file" name="file" id="file" class="ui invisible file input" />
<label for="file" class="ui icon button">
<i class="file icon"></i>
Cargar
</label>
</div>
</div>
</div>
<div class="two wide middle aligned column">
<button class="ui icon button">
Procesar
<i class="sync icon"></i>
</button>
</div>
</div>
</form>
<div class="ui two columns grid">
<div class="column">
<button class="ui icon button" id="export_button">
<i class="file excel icon"></i>
Exportar
</button>
</div>
<div class="right aligned column">
<div class="ui inline active loader" id="loader"></div>
</div>
</div>
</div>
<div class="ui fluid container">
<table class="ui table" id="tabla_movimientos">
<thead>
<tr>
<th>Fecha</th>
<th>Glosa</th>
<th>Documento</th>
<th class="right aligned">Cargo</th>
<th class="right aligned">Abono</th>
<th>Centro de Costo</th>
<th>Detalle</th>
<th>Orden</th>
</tr>
</thead>
<tbody id="movimientos"></tbody>
</table>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script>
const cartola = {
ids: {
table: {
base: '',
body: ''
},
form: {
base: '',
inmobiliaria: '',
banco: '',
mes: '',
},
button: '',
loader: '',
},
data: {
inmobiliaria: {
rut: 0,
razon: ''
},
banco: {
id: 0,
nombre: ''
},
mes: '',
movimientos: [],
centrosCostos: {
ingresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\CentroCosto $centroCosto) {
return [
'id' => $centroCosto->id,
'descripcion' => $centroCosto->descripcion
];
}, array_filter($centrosCostos, function(\Incoviba\Model\CentroCosto $centroCosto) {
return $centroCosto->tipoCentro->descripcion === 'Ingreso';
})))) !!}'),
egresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\CentroCosto $centroCosto) {
return [
'id' => $centroCosto->id,
'descripcion' => $centroCosto->descripcion
];
}, array_filter($centrosCostos, function(\Incoviba\Model\CentroCosto $centroCosto) {
return $centroCosto->tipoCentro->descripcion === 'Egreso';
})))) !!}'),
}
},
dataTableConfig: {
pageLength: 100,
order: [[7, 'asc']],
columnDefs: [
{
targets: [0, 2, 3, 4],
width: '10%'
},
{
targets: [1],
width: '20%'
},
{
targets: [7],
visible: false
}
],
},
get() {
return {
bancos: inmobiliaria_rut => {
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/cuentas'
$(this.ids.loader).show()
return fetchAPI(url).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
return response.json().then(json => {
if (json.cuentas.length === 0) {
return
}
$(this.ids.form.banco).dropdown('change values', json.cuentas.map(cuenta => {
return {value: cuenta.banco.id, text: cuenta.banco.nombre, name: cuenta.banco.nombre}
})).dropdown('refresh')
})
})
},
firstDate: inmobiliaria_rut => {
const url = '{{$urls->api}}/inmobiliaria/' + inmobiliaria_rut + '/proyectos'
$(this.ids.loader).show()
return fetchAPI(url).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
return response.json().then(json => {
if (json.proyectos.length === 0) {
return
}
const min = json.proyectos.reduce((min, proyecto) => {
const date = new Date(proyecto.current_estado.fecha.date)
if (min > date.getTime()) {
return date.getTime()
}
return min
}, (new Date()).getTime())
$(this.ids.form.mes).calendar('set minDate', new Date(min))
})
})
}
}
},
parse() {
return {
cartola: event => {
event.preventDefault()
const body = new FormData(document.getElementById('asignar_form'))
body.set('mes', $('#mes').calendar('get date').toISOString())
const url = '{{$urls->api}}/contabilidad/cartolas/procesar'
$(this.ids.loader).show()
fetchAPI(url, {method: 'post', body}).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
return response.json().then(json => {
if (json.movimientos.length === 0) {
return
}
this.data.movimientos = []
json.movimientos.forEach((row, idx) => {
const fecha = new Date(row.fecha)
fecha.setDate(fecha.getDate() + 1)
this.data.movimientos[idx] = {
fecha: fecha,
glosa: row.glosa,
documento: row.documento,
cargo: row.cargo,
abono: row.abono,
}
})
this.draw().cartola()
})
})
return false
}
}
},
export() {
return {
cartola: event => {
const url = '{{$urls->api}}/contabilidad/cartola/exportar'
const body = new FormData()
body.set('inmobiliaria', $(this.ids.form.inmobiliaria).dropdown('get value'))
body.set('banco', $(this.ids.form.banco).dropdown('get value'))
body.set('mes', $(this.ids.form.mes).calendar('get date').toISOString())
const movimientos = this.data.movimientos.map((movimiento, idx) => {
const temp = structuredClone(movimiento)
temp.fecha = movimiento.fecha.toISOString()
let centro = $(".centro[data-index='" + (idx+1) + "']").dropdown('get value')
if (centro.length === 0) {
centro = ''
}
temp.centro_costo = centro
let detalle = $("[name='detalle" + (idx+1) + "']").val()
if (typeof detalle === 'undefined') {
detalle = ''
}
temp.detalle = detalle
return temp
})
body.set('movimientos', JSON.stringify(movimientos))
$(this.ids.loader).show()
fetchAPI(url, {method: 'post', body}).then(response => {
$(this.ids.loader).hide()
if (!response) {
return
}
response.json().then(json => {
if (json.filename === '') {
return
}
const anchor = document.createElement('a')
anchor.href = ['/uploads/', json.filename].join('/')
anchor.download = 'Cartola ' + this.data.banco.nombre + ' - ' + this.data.inmobiliaria.razon + ' - ' + this.data.mes + '.xlsx'
document.body.appendChild(anchor)
anchor.click()
anchor.remove()
})
})
}
}
},
draw() {
return {
cartola: () => {
const table = $(this.ids.table.base)
table.DataTable().clear()
table.DataTable().destroy()
const tbody = $(this.ids.table.body)
tbody.html('')
const dateFormatter = new Intl.DateTimeFormat('es-CL', {
year: 'numeric',
month: 'numeric',
day: 'numeric'
})
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
this.data.movimientos.forEach((row, idx) => {
tbody.append(
$('<tr></tr>').append(
$('<td></td>').html(dateFormatter.format(row.fecha))
).append(
$('<td></td>').html(row.glosa)
).append(
$('<td></td>').html(row.documento)
).append(
$('<td></td>').addClass('right aligned').html(row.cargo === 0 ? '' : numberFormatter.format(row.cargo))
).append(
$('<td></td>').addClass('right aligned').html(row.abono === 0 ? '' : numberFormatter.format(row.abono))
).append(
$('<td></td>').append(this.draw().centrosDropdown(idx + 1, row.cargo === 0))
).append(
$('<td></td>').append(
$('<div></div>').addClass('ui fluid input').append(
$('<input />').attr('type', 'text').attr('name', 'detalle' + (idx + 1))
)
)
).append(
$('<td></td>').html(idx + 1)
)
)
})
table.DataTable(this.dataTableConfig)
},
centrosDropdown: (idx, ingreso=true) => {
const menu = $('<div></div>').addClass('menu')
let centros = this.data.centrosCostos.ingresos
if (!ingreso) {
centros = this.data.centrosCostos.egresos
}
centros.forEach(centro => {
menu.append(
$('<div></div>').addClass('item').attr('data-value', centro.id).html(centro.id + ' - ' + centro.descripcion)
)
})
return $('<div></div>').addClass('ui selection search dropdown centro').attr('data-index', idx).css('width', '80%').append(
$('<input />').attr('type', 'hidden').attr('name', 'centro' + idx)
).append(
$('<i></i>').addClass('dropdown icon')
).append(
$('<div></div>').addClass('default text').html('Centro de Costos')
).append(menu).dropdown()
}
}
},
setup({ids}) {
this.ids = ids
$(this.ids.form.inmobiliaria).dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.data.inmobiliaria.rut = value
this.data.inmobiliaria.razon = text
this.get().bancos(value)
this.get().firstDate(value)
},
})
$(this.ids.form.banco).dropdown({
fireOnInit: true,
onChange: (value, text, $choice) => {
this.data.banco.id = value
this.data.banco.nombre = text
}
})
$(this.ids.loader).hide()
calendar_date_options['type'] = 'month'
const lastMonth = new Date()
lastMonth.setDate(0)
calendar_date_options['maxDate'] = lastMonth
calendar_date_options['onChange'] = (date, text, mode) => {
this.data.mes = text
}
$(this.ids.form.mes).calendar(calendar_date_options)
$(this.ids.form.base).submit(this.parse().cartola)
$(this.ids.table.base).DataTable(this.dataTableConfig)
$(this.ids.button).click(this.export().cartola)
}
}
$(document).ready(() => {
cartola.setup({
ids: {
table: {
base: '#tabla_movimientos',
body: '#movimientos'
},
form: {
base: '#asignar_form',
inmobiliaria: '#inmobiliaria',
banco: '#banco',
mes: '#mes',
},
button: '#export_button',
loader: '#loader'
}
})
})
</script>
@endpush

View File

@ -4,7 +4,7 @@
@include('layout.body.header.menu.ventas') @include('layout.body.header.menu.ventas')
@include('layout.body.header.menu.proyectos') @include('layout.body.header.menu.proyectos')
@include('layout.body.header.menu.inmobiliarias') @include('layout.body.header.menu.inmobiliarias')
{{--@include('layout.body.header.menu.contabilidad')--}} @include('layout.body.header.menu.contabilidad')
{{--@include('layout.body.header.menu.operadores')--}} {{--@include('layout.body.header.menu.operadores')--}}
{{--@include('layout.body.header.menu.herramientas')--}} {{--@include('layout.body.header.menu.herramientas')--}}
<div class="right aligned menu"> <div class="right aligned menu">

View File

@ -2,7 +2,12 @@
Contabilidad Contabilidad
<i class="dropdown icon"></i> <i class="dropdown icon"></i>
<div class="menu"> <div class="menu">
<a class="item" href="{{$urls->base}}/contabilidad/pagos/mes">Pagos Mes</a> <div class="item">
<a class="item" href="{{$urls->base}}/contabilidad/resumen">Resumen</a> <i class="dropdown icon"></i>
<a class="text" href="{{$urls->base}}/contabilidad/centros_costos">Centros de Costos</a>
<div class="menu">
<a class="item" href="{{$urls->base}}/contabilidad/centros_costos/asignar">Asignar en Cartola</a>
</div>
</div>
</div> </div>
</div> </div>

View File

@ -8,7 +8,7 @@
<input type="text" id="name" name="name" /> <input type="text" id="name" name="name" />
</div> </div>
<div class="six wide field"> <div class="six wide field">
<label for="password">Clave</label> <label for="password">Contraseña</label>
<input type="password" id="password" name="password" /> <input type="password" id="password" name="password" />
</div> </div>
<button class="ui button" id="enter">Ingresar</button> <button class="ui button" id="enter">Ingresar</button>

View File

@ -107,9 +107,10 @@
const uri = '{{$urls->api}}/search' const uri = '{{$urls->api}}/search'
this.data = [] this.data = []
return fetchAPI(uri, {method: 'post', body: data}).then(response => { return fetchAPI(uri, {method: 'post', body: data}).then(response => {
if (response.ok) { if (!response) {
return response.json() return
} }
return response.json()
}).catch(error => { }).catch(error => {
this.draw().clear() this.draw().clear()
this.draw().error(error) this.draw().error(error)
@ -123,7 +124,11 @@
const promises = [] const promises = []
data.results.forEach(row => { data.results.forEach(row => {
if (row.tipo === 'venta') { if (row.tipo === 'venta') {
promises.push(this.get().venta(row.id).then(json => { return promises.push(this.get().venta(row.id).then(json => {
if (json.venta === null) {
console.debug(json)
return
}
const venta = json.venta const venta = json.venta
progress.progress('increment') progress.progress('increment')
const r = new Row({unidad: venta.propiedad.unidades[0], proyecto: venta.proyecto}) const r = new Row({unidad: venta.propiedad.unidades[0], proyecto: venta.proyecto})
@ -134,7 +139,6 @@
console.error(row) console.error(row)
console.error(error) console.error(error)
})) }))
return
} }
promises.push(this.get().unidad(row.id).then(json => { promises.push(this.get().unidad(row.id).then(json => {
const unidad = json.unidad const unidad = json.unidad
@ -164,9 +168,10 @@
venta: id => { venta: id => {
const url = '{{$urls->api}}/venta/' + id const url = '{{$urls->api}}/venta/' + id
return fetchAPI(url).then(response => { return fetchAPI(url).then(response => {
if (response.ok) { if (!response) {
return response.json() return
} }
return response.json()
}) })
} }
} }

View File

@ -3,7 +3,7 @@
@section('page_content') @section('page_content')
<div class="ui container"> <div class="ui container">
<h2 class="ui header">Nueva Venta</h2> <h2 class="ui header">Nueva Venta</h2>
<form class="ui form" id="add_form" action="{{$urls->api}}/ventas/add" method="post"> <form class="ui form" id="add_form" method="post">
<label for="fecha_venta">Fecha de Venta</label> <label for="fecha_venta">Fecha de Venta</label>
<div class="inline field"> <div class="inline field">
<div class="ui calendar" id="fecha_venta_calendar"> <div class="ui calendar" id="fecha_venta_calendar">
@ -686,7 +686,7 @@
$('<div></div>').addClass('content').append(tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ').append( $('<div></div>').addClass('content').append(tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ').append(
unidad.draw(this.unidades[tipo]) unidad.draw(this.unidades[tipo])
).append( ).append(
$('<button></button>').addClass('ui icon button').attr('type', 'button').attr('data-number', number).append( $('<button></button>').addClass('ui basic red icon button').attr('type', 'button').attr('data-number', number).append(
$('<i></i>').addClass('remove icon') $('<i></i>').addClass('remove icon')
).click(event => { ).click(event => {
const number = $(event.currentTarget).attr('data-number') const number = $(event.currentTarget).attr('data-number')
@ -766,7 +766,7 @@
} }
function showErrors(errors) { function showErrors(errors) {
console.debug(errors) console.error(errors)
} }
$(document).ready(() => { $(document).ready(() => {
@ -789,20 +789,21 @@
$('#add_form').submit(event => { $('#add_form').submit(event => {
event.preventDefault() event.preventDefault()
const data = new FormData(event.currentTarget) const body = new FormData(event.currentTarget)
const uri = $(event.currentTarget).attr('action') const uri = '{{$urls->api}}/ventas/add'
fetch(uri, {method: 'post', body: data}).then(response => { return fetchAPI(uri, {method: 'post', body}).then(response => {
if (response.ok) { if (!response) {
return response.json() return false
} }
}).then(data => { return response.json().then(data => {
if (data.status) { if (data.status) {
window.location = '{{$urls->base}}' window.location = '{{$urls->base}}/venta/' + data.venta_id
return true return true
} }
showErrors(data.errors) showErrors(data.errors)
return false
})
}) })
return false
}) })
}) })
</script> </script>

View File

@ -0,0 +1,36 @@
@extends('layout.base')
@section('page_title')
Venta {{$venta->proyecto()->descripcion}} {{$venta->propiedad()->summary()}}
@endsection
@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<div class="row">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</div>
</h1>
@if (isset($showPropietario) and $showPropietario)
<div class="right floated column">
@include('ventas.show.propietario')
</div>
@endif
</div>
@hasSection('venta_subtitle')
<div class="row">
<h2 class="ui sub header column">
@yield('venta_subtitle')
</h2>
</div>
@endif
</div>
<br />
@yield('venta_content')
</div>
@endsection

View File

@ -1,14 +1,12 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Desistida
<h1 class="ui header"> @endsection
Desistida - {{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}"> @section('venta_content')
{{$venta->propiedad()->summary()}} <form class="ui form" id="desistida_form">
</a> <div class="fields">
</h1>
<form class="ui form" id="desistida_form">
<div class="three wide field"> <div class="three wide field">
<label for="fecha">Fecha</label> <label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha"> <div class="ui calendar" id="fecha">
@ -18,6 +16,11 @@
</div> </div>
</div> </div>
</div> </div>
<div class="one wide field">
<div id="loading-spinner-fecha" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
</div>
<div class="fields">
<div class="three wide field"> <div class="three wide field">
<label for="devolucion">Devolución</label> <label for="devolucion">Devolución</label>
<div class="ui left labeled input"> <div class="ui left labeled input">
@ -25,19 +28,27 @@
<input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" /> <input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" />
</div> </div>
</div> </div>
</form> <div class="one wide field">
</div> <div id="loading-spinner-devolucion" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
</div>
<button class="ui red icon button" type="button" id="eliminar_desistimiento">
<i class="ban icon"></i>
Elmininar desistimiento
</button>
<div id="loading-spinner-eliminar" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</form>
@endsection @endsection
@push('page_scripts') @push('page_scripts')
<script> <script>
function alertResponse(message, color = 'green') { function alertResponse(message, {color = 'green', icon = 'check circle'}={}) {
$.toast({ $.toast({
message, message,
showProgress: 'bottom', showProgress: 'bottom',
progressUp: true, progressUp: true,
class: color, class: color,
showIcon: 'check circle', showIcon: icon,
classProgress: 'blue' classProgress: 'blue'
}) })
} }
@ -52,7 +63,9 @@
} }
const body = new FormData() const body = new FormData()
body.set('fecha', date.toISOString()) body.set('fecha', date.toISOString())
$('#loading-spinner-fecha').show()
fetchAPI(url, {method: 'post', body}).then(response => { fetchAPI(url, {method: 'post', body}).then(response => {
$('#loading-spinner-fecha').hide()
if (!response) { if (!response) {
return return
} }
@ -62,17 +75,36 @@
} }
$('#fecha').calendar(calendar_date_options) $('#fecha').calendar(calendar_date_options)
$('#devolucion').change(event => { $('#devolucion').change(event => {
console.debug(event)
const val = $(event.currentTarget).val() const val = $(event.currentTarget).val()
const body = new FormData() const body = new FormData()
body.set('valor', val) body.set('valor', val)
$('#loading-spinner-devolucion').show()
fetchAPI(url, {method: 'post', body}).then(response => { fetchAPI(url, {method: 'post', body}).then(response => {
$('#loading-spinner-devolucion').hide()
if (!response) { if (!response) {
return return
} }
alertResponse('Devolución cambiada correctamente.') alertResponse('Devolución cambiada correctamente.')
}) })
}) })
$('#eliminar_desistimiento').click(event => {
const url = '{{$urls->api}}/venta/{{$venta->id}}/desistir/eliminar'
$('#loading-spinner-eliminar').show()
fetchAPI(url).then(response => {
$('#loading-spinner-eliminar').hide()
if (!response) {
alertResponse('No se pudo eliminar el desistimiento', {color: 'red', icon: 'triangle exclamation'})
return
}
response.json().then(json => {
if (!json.eliminado) {
alertResponse('No se pudo eliminar el disistimiento', {color: 'red', icon: 'triangle exclamation'})
return
}
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
})
})
})
}) })
</script> </script>
@endpush @endpush

View File

@ -1,51 +1,49 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Desistir
<h1 class="ui header"> @endsection
Desistir - {{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a> @section('venta_content')
</h1> <div class="ui list">
<div class="ui list"> <div class="item">
<div class="item"> <div class="header">Valor Pagado</div>
<div class="header">Valor Pagado</div> <div class="content">
<div class="content"> {{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}} <div class="ui left pointing small label">
<div class="ui left pointing small label"> {{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
</div>
</div>
<div class="item">
<div class="header">
Multa Estandar
<div class="ui left pointing small label">5%</div>
</div>
<div class="content">
{{$format->pesos($venta->valor * 0.05 * $UF->get())}}
</div> </div>
</div> </div>
</div> </div>
<form class="ui form" id="desistir_form"> <div class="item">
<div class="three wide field"> <div class="header">
<label for="fecha">Fecha</label> Multa Estandar
<div class="ui calendar" id="fecha"> <div class="ui left pointing small label">5%</div>
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
</div>
</div> </div>
<div class="three wide field"> <div class="content">
<label for="devolucion">Devolución [$]</label> {{$format->pesos($venta->valor * 0.05 * $UF->get())}}
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="devolucion" />
</div>
</div> </div>
<button class="ui button">Desistir</button> </div>
</form>
</div> </div>
<form class="ui form" id="desistir_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" />
</div>
</div>
</div>
<div class="three wide field">
<label for="devolucion">Devolución [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="devolucion" />
</div>
</div>
<button class="ui button">Desistir</button>
</form>
@endsection @endsection
@push('page_scripts') @push('page_scripts')

View File

@ -1,33 +1,31 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Editar Venta
<h2 class="ui header">Editar Venta - @endsection
{{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a> @section('venta_content')
</h2> <form class="ui form" id="edit_form">
<form class="ui form" id="edit_form"> <div class="inline field">
<div class="inline field"> <label for="valor">Valor</label>
<label for="valor">Valor</label> <div class="ui right labeled input">
<div class="ui right labeled input"> <input type="text" id="valor" name="valor" value="{{$venta->valor}}" />
<input type="text" id="valor" name="valor" value="{{$venta->valor}}" /> <div class="ui label">UF</div>
<div class="ui label">UF</div> </div>
</div>
<div class="inline field">
<label for="fecha">Fecha Promesa</label>
<div class="ui calendar" id="fecha_calendar">
<div class="ui icon input">
<input type="text" name="fecha" id="fecha" />
<i class="calendar icon"></i>
</div> </div>
</div> </div>
<div class="inline field"> </div>
<label for="fecha">Fecha Promesa</label> <button class="ui button">
<div class="ui calendar" id="fecha_calendar"> Guardar
<div class="ui icon input"> </button>
<input type="text" name="fecha" id="fecha" /> </form>
<i class="calendar icon"></i>
</div>
</div>
</div>
<button class="ui button">
Guardar
</button>
</form>
</div>
@endsection @endsection
@push('page_scripts') @push('page_scripts')

View File

@ -1,210 +1,206 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Escriturar
<h1 class="ui header"> @endsection
Escriturar - {{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}"> @section('venta_content')
{{$venta->propiedad()->summary()}} <div class="ui basic segment">
</a> <div class="ui four columns grid">
</h1> <div class="column">Faltante</div>
<div class="ui basic segment"> <div class="column">{{$format->pesos($venta->saldo('pesos'))}}</div>
<div class="ui four columns grid"> <div class="column">{{$format->ufs($venta->saldo())}}</div>
<div class="column">Faltante</div> </div>
<div class="column">{{$format->pesos($venta->saldo('pesos'))}}</div> </div>
<div class="column">{{$format->ufs($venta->saldo())}}</div> <div class="ui divider"></div>
<form class="ui form" id="escriturar_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> </div>
<div class="ui divider"></div> @if ($venta->formaPago()->pie->reajuste === null)
<form class="ui form" id="escriturar_form"> <h4 class="ui header optional" data-name="reajuste">Reajuste <i class="small plus icon"></i></h4>
<div class="three wide field"> <div class="fields optional" id="reajuste">
<label for="fecha">Fecha</label> <div class="field">
<div class="ui calendar" id="fecha"> <label for="valor_reajuste">Valor [$]</label>
<div class="ui left icon input"> <div class="ui left labeled input">
<i class="calendar icon"></i> <div class="ui basic label">$</div>
<input type="text" name="fecha" /> <input type="text" name="valor_reajuste" id="valor_reajuste" />
</div>
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui calendar" id="fecha_reajuste">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_reajuste" />
</div>
</div> </div>
</div> </div>
</div> </div>
@if ($venta->formaPago()->pie->reajuste === null) @else
<h4 class="ui header optional" data-name="reajuste">Reajuste <i class="small plus icon"></i></h4> <h4 class="ui header" data-name="reajuste">Reajuste</h4>
<div class="fields optional" id="reajuste"> <div class="fields" id="reajuste">
<div class="field"> <div class="field">
<label for="valor_reajuste">Valor [$]</label> <label for="valor_reajuste">Valor [$]</label>
<div class="ui left labeled input"> <div class="ui left labeled disabled input">
<div class="ui basic label">$</div> <div class="ui basic label">$</div>
<input type="text" name="valor_reajuste" id="valor_reajuste" /> <input type="text" value="{{$format->number($venta->formaPago()->pie->reajuste->valor)}}" />
</div>
</div> </div>
<div class="field"> </div>
<label for="fecha_reajuste">Fecha</label> <div class="field">
<div class="ui calendar" id="fecha_reajuste"> <label for="fecha_reajuste">Fecha</label>
<div class="ui left icon input"> <div class="ui disabled input">
<i class="calendar icon"></i> <input type="text" value="{{$venta->formaPago()->pie->reajuste->fecha->format('d-m-Y')}}" />
<input type="text" name="fecha_reajuste" /> </div>
</div> </div>
</div>
@endif
@if (!isset($venta->formaPago()->escritura))
<h4 class="ui header optional" data-name="pago">Pago en Escritura <i class="small plus icon"></i></h4>
<div class="fields optional" id="pago">
<div class="field">
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor_pago_pesos" id="valor_pago_pesos" />
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled input">
<input type="text" name="valor_pago_ufs" id="valor_pago_ufs" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui calendar" id="fecha_pago">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_pago" />
</div> </div>
</div> </div>
</div> </div>
@else </div>
<h4 class="ui header" data-name="reajuste">Reajuste</h4> @else
<div class="fields" id="reajuste"> <h4 class="ui header" data-name="pago">Pago en Escritura</h4>
<div class="field"> <div class="fields" id="pago">
<label for="valor_reajuste">Valor [$]</label> <div class="field">
<div class="ui left labeled disabled input"> <label for="valor_pago_pesos">Valor [$]</label>
<div class="ui basic label">$</div> <div class="ui left labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->pie->reajuste->valor)}}" /> <div class="ui basic label">$</div>
</div> <input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor)}}" />
</div> </div>
<div class="field"> </div>
<label for="fecha_reajuste">Fecha</label> <div class="field">
<div class="ui disabled input"> <label for="valor_pago_ufs">(Valor [UF])</label>
<input type="text" value="{{$venta->formaPago()->pie->reajuste->fecha->format('d-m-Y')}}" /> <div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor(),2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->escritura->pago->fecha->format('d-m-Y')}}">
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->subsidio))
<h4 class="ui header optional" data-name="subsidio">Subsidio <i class="small plus icon"></i></h4>
<div class="fields optional" id="subsidio">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_ahorro" id="valor_ahorro" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_subsidio" id="valor_subsidio" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="total_subsidio">Total</label>
<div class="ui right labeled disabled input">
<input type="text" id="total_subsidio" value="0,00" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="subsidio">Subsidio</h4>
<div class="fields">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subsidio->ahorro->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subidio->pago->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->credito) or $venta->formaPago()->credito->pago->banco === null)
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled input">
<input type="text" id="valor_credito" name="valor_credito" value="{{$venta->formaPago()->credito?->pago->valor() ?? ''}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui selection dropdown" id="banco_credito">
<input type="hidden" name="banco_credito" />
<div class="default text">Banco</div>
<i class="dropdown icon"></i>
<div class="menu">
@foreach ($bancos as $banco)
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div> </div>
</div> </div>
</div> </div>
@endif </div>
@if (!isset($venta->formaPago()->escritura)) @else
<h4 class="ui header optional" data-name="pago">Pago en Escritura <i class="small plus icon"></i></h4> <h4 class="ui header">Crédito</h4>
<div class="fields optional" id="pago"> <div class="fields">
<div class="field"> <div class="field">
<label for="valor_pago_pesos">Valor [$]</label> <label for="valor_credito">Valor [UF]</label>
<div class="ui left labeled input"> <div class="ui right labeled disabled input">
<div class="ui basic label">$</div> <input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
<input type="text" name="valor_pago_pesos" id="valor_pago_pesos" /> <div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled input">
<input type="text" name="valor_pago_ufs" id="valor_pago_ufs" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui calendar" id="fecha_pago">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" class="fecha_pago" />
</div>
</div>
</div> </div>
</div> </div>
@else <div class="four wide field">
<h4 class="ui header" data-name="pago">Pago en Escritura</h4> <label for="banco_credito">Banco</label>
<div class="fields" id="pago"> <div class="ui disabled input">
<div class="field"> <input type="text" value="{{$venta->formaPago()->credito->pago->banco->nombre}}" />
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled disabled input">
<div class="ui basic label">$</div>
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor)}}" />
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor(),2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->escritura->pago->fecha->format('d-m-Y')}}">
</div>
</div> </div>
</div> </div>
@endif </div>
@if (!isset($venta->formaPago()->subsidio)) @endif
<h4 class="ui header optional" data-name="subsidio">Subsidio <i class="small plus icon"></i></h4> <button class="ui button">Escriturar</button>
<div class="fields optional" id="subsidio"> </form>
<div class="field">
<label for="valor_ahorro">Valor Ahorrado [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_ahorro" id="valor_ahorro" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_subsidio" id="valor_subsidio" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="total_subsidio">Total</label>
<div class="ui right labeled disabled input">
<input type="text" id="total_subsidio" value="0,00" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="subsidio">Subsidio</h4>
<div class="fields">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subsidio->ahorro->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subidio->pago->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@endif
@if (isset($venta->formaPago()->credito) and $venta->formaPago()->credito->pago->banco === null)
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui selection dropdown" id="banco_credito">
<input type="hidden" name="banco_credito" />
<div class="default text">Banco</div>
<i class="dropdown icon"></i>
<div class="menu">
@foreach ($bancos as $banco)
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</div>
</div>
</div>
@else
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->credito->pago->banco->nombre}}" />
</div>
</div>
</div>
@endif
<button class="ui button">Escriturar</button>
</form>
</div>
@endsection @endsection
@push('page_scripts') @push('page_scripts')
@ -254,9 +250,15 @@
$('#escriturar_form').submit(event => { $('#escriturar_form').submit(event => {
event.preventDefault() event.preventDefault()
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar' const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
const data = new FormData(event.currentTarget) const body = new FormData(event.currentTarget)
data.set('fecha', $('#fecha').calendar('get date').toISOString()) body.set('fecha', $('#fecha').calendar('get date').toISOString())
fetchAPI(url, {method: 'post', body: data}).then(response => { if (body.get('fecha_pago') !== '') {
body.set('fecha_pago', $('#fecha_pago').calendar('get date').toISOString())
}
if (body.get('fecha_reajuste') !== '') {
body.set('fecha_reajuste', $('#fecha_reajuste').calendar('get date').toISOString())
}
fetchAPI(url, {method: 'post', body}).then(response => {
if (response.ok) { if (response.ok) {
return response.json() return response.json()
} }
@ -267,6 +269,8 @@
}) })
return false return false
}) })
$('#fecha_pago').calendar(calendar_date_options)
$('#fecha_reajuste').calendar(calendar_date_options)
}) })
</script> </script>
@endpush @endpush

View File

@ -0,0 +1,88 @@
@extends('ventas.base')
@section('venta_subtitle')
Resumen Escritura
@endsection
@section('venta_content')
<div class="ui segment">
El departamento {{$venta->propiedad()->departamentos()[0]->descripcion}}:<br />
@php
$estacionamientos = $venta->propiedad()->estacionamientos();
@endphp
@if (count($estacionamientos) === 0)
no tiene estacionamientos
@else
tiene
{{count($estacionamientos) === 1 ? 'el' : 'los'}}
estacionamiento{{count($estacionamientos) === 1 ? '': 's'}}
{{implode(', ', array_map(function(Incoviba\Model\Venta\Unidad $unidad) {
return $unidad->descripcion;
}, $estacionamientos))}}
@endif
y
@php
$bodegas = $venta->propiedad()->bodegas();
@endphp
@if (count($bodegas) === 0)
no tiene bodegas
@else
tiene
{{count($bodegas) === 1 ? 'la' : 'las'}}
bodega{{count($bodegas) === 1 ? '' : 's'}}
{{implode(', ', array_map(function(Incoviba\Model\Venta\Unidad $unidad) {
return $unidad->descripcion;
}, $bodegas))}}
@endif
<br />
<br />
<strong>PRECIO</strong>
{{$format->ufs($venta->valor)}}
<div class="ui fitted divider"></div>
<br />
@if (isset($venta->formaPago()->pie))
@php($pie = $venta->formaPago()->pie)
<strong>PIE</strong>
{{$pie->cuotas}} cuotas que suman
{{$format->pesos($pie->pagado('pesos'))}}
equivalente a
{{$format->ufs($pie->pagado())}}.
<br />
@endif
@if (isset($venta->formaPago()->escritura))
@php($escritura = $venta->formaPago()->escritura)
<strong>ESCRITURA</strong>
{{$format->pesos($escritura->pago->valor)}}
el
{{$escritura->fecha->format('d-m-Y')}}
equivalente a
{{$format->ufs($escritura->pago->valor())}}
<br />
@endif
<div class="ui fitted divider"></div>
<strong>TOTAL ANTICIPO</strong>
{{$format->ufs($venta->formaPago()->anticipo())}}
<br />
@if (isset($venta->formaPago()->bonoPie))
@php($bono = $venta->formaPago()->bonoPie)
<strong>BONO PIE</strong>
{{$format->ufs($bono->pago->valor())}}
<br />
@endif
@if (isset($venta->formaPago()->credito))
@php($credito = $venta->formaPago()->credito)
<strong>CRÉDITO</strong>
{{$format->ufs($credito->pago->valor())}}
en Banco {{$credito->pago->banco->nombre}}
<br />
@endif
<div class="ui fitted divider"></div>
<strong>TOTAL</strong>
{{$format->ufs($venta->formaPago()->total())}}
@if (($venta->formaPago()->total() - $venta->valor) !== 0)
<br />
<br />
Diferencia {{$format->ufs($venta->formaPago()->total() - $venta->valor)}}. ({{$format->percent(($venta->formaPago()->total() - $venta->valor) / $venta->valor * 100)}})
@endif
</div>
@endsection

View File

@ -1,27 +1,22 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Escritura
<h2 class="ui header"> @endsection
Escritura -
{{$venta->proyecto()->descripcion}} - @section('venta_content')
<a href="{{$urls->base}}/venta/{{$venta->id}}"> <form class="ui form" id="edit_form">
{{$venta->propiedad()->summary()}} <div class="three wide field">
</a> <label for="fecha">Fecha</label>
</h2> <div class="ui calendar" id="fecha">
<form class="ui form" id="edit_form"> <div class="ui left icon input">
<div class="three wide field"> <i class="calendar icon"></i>
<label for="fecha">Fecha</label> <input type="text" placeholder="Fecha" />
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" placeholder="Fecha" />
</div>
</div> </div>
</div> </div>
<button class="ui button">Guardar</button> </div>
</form> <button class="ui button">Guardar</button>
</div> </form>
@endsection @endsection
@push('page_scripts') @push('page_scripts')

View File

@ -62,7 +62,8 @@
</div> </div>
@endif @endif
</form> </form>
@if ($IPC->get($venta->proyecto()->terreno->fecha, $venta->currentEstado()->fecha) === 0.0) @if ($venta->currentEstado()->fecha->sub(new DateInterval('P1M')) > $venta->proyecto()->terreno->fecha
and $IPC->get($venta->proyecto()->terreno->fecha, $venta->currentEstado()->fecha->sub(new DateInterval('P1M'))) === 0.0)
<div class="ui compact icon error message"> <div class="ui compact icon error message">
<i class="exclamation triangle icon"></i> <i class="exclamation triangle icon"></i>
<div class="content"> <div class="content">
@ -314,7 +315,7 @@
return return
} }
const idx = this.unidades.findIndex(unidad => unidad.pid === json.propiedad_unidad_id) const idx = this.unidades.findIndex(unidad => unidad.pid === json.propiedad_unidad_id)
this.unidades[idx].precio = parseInt(json.input.valor) this.unidades[idx].precio = parseFloat(json.input.valor)
this.unidades[idx].base = parseFloat(json.input.valor * this.unidades[idx].base / old_value) this.unidades[idx].base = parseFloat(json.input.valor * this.unidades[idx].base / old_value)
this.build() this.build()
}) })

View File

@ -234,6 +234,7 @@
this.table = new DataTable(table, { this.table = new DataTable(table, {
order: [[0, 'asc']], order: [[0, 'asc']],
pageLength: 50
}) })
}, },
table: () => { table: () => {

View File

@ -1,138 +1,139 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Cuotas - Pie
<div class="ui two column grid"> @endsection
<h1 class="four wide column header">
<div class="content"> @section('venta_content')
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div> <table class="ui table" id="cuotas">
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a> <thead>
</div> <tr>
</h1> <th>#</th>
</div> <th>Fecha</th>
<h2>Cuotas - Pie</h2> <th>Fecha ISO</th>
<table class="ui table" id="cuotas"> <th>Banco</th>
<thead> <th>Identificador</th>
<tr> <th class="right aligned">Valor</th>
<th>#</th> <th class="right aligned">Valor UF</th>
<th>Fecha</th> <th>Estado</th>
<th>Fecha ISO</th> <th>Fecha Estado</th>
<th>Banco</th> <th>Fecha Estado ISO</th>
<th>Identificador</th> <th></th>
<th class="right aligned">Valor</th> </tr>
<th class="right aligned">Valor UF</th> </thead>
<th>Estado</th> <tbody>@php
<th>Fecha Estado</th> $now = new DateTimeImmutable();
<th>Fecha Estado ISO</th> $uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf;
</tr> @endphp
</thead> @foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<tbody>@php $now = new DateTimeImmutable(); @endphp <tr data-pago="{{$cuota->pago->id}}"
@foreach ($venta->formaPago()->pie->cuotas() as $cuota) @if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
<tr> class="disabled"
<td>{{$cuota->numero}}</td> @endif >
<td>{{$cuota->pago->fecha->format('d-m-Y')}}</td> <td>{{$cuota->numero}}</td>
<td>{{$cuota->pago->fecha->format('Y-m-d')}}</td> <td>{{$cuota->pago->fecha->format('d-m-Y')}}</td>
<td>{{$cuota->pago->banco->nombre}}</td> <td>{{$cuota->pago->fecha->format('Y-m-d')}}</td>
<td>{{$cuota->pago->identificador}}</td> <td>{{$cuota->pago->banco->nombre}}</td>
<td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td> <td>{{$cuota->pago->identificador}}</td>
<td class="right aligned"> <td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now) <td class="right aligned">
{{$format->ufs($cuota->pago->valor())}} @if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now)
@endif {{$format->ufs($cuota->pago->valor())}}
</td> @endif
<td </td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado') <td
class="green" @if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado')
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado') class="green"
class="yellow" @elseif ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1) class="yellow"
class="red" @elseif ($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1)
@endif class="red"
>{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td> @endif
<td> >{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado') <td>
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}} @if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'anulado', 'reemplazado']))
@else {{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
<div class="ui action input"> @elseif (!in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
<div class="ui calendar fecha_estado" data-date="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}"> <div class="ui calendar fecha_estado" data-date="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}">
<div class="ui icon input"> <div class="ui action left icon input">
<i class="calendar icon"></i> <i class="calendar icon"></i>
<input type="text" name="fecha_estado" /> <input type="text" name="fecha_estado" />
</div> <button class="ui green basic icon button accept_estado" data-pago="{{$cuota->pago->id}}" data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion}}">
</div>
<button class="ui green basic icon button" id="accept_estado" data-pago="{{$cuota->pago->id}}">
<i class="check icon"></i> <i class="check icon"></i>
</button> </button>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado') @if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<button class="ui red basic icon button" id="reject_estado" data-pago="{{$cuota->pago->id}}"> <button class="ui red basic icon button reject_estado" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i> <i class="remove icon"></i>
</button> </button>
@endif @endif
</div> </div>
@endif </div>
</td> @endif
<td>{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}</td> </td>
</tr> <td>{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}</td>
@endforeach <td>
</tbody> @if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'anulado')
<tfoot> <button class="ui mini red icon basic button anular" data-pago="{{$cuota->pago->id}}">
<tr> <i class="remove icon"></i>
<th colspan="5">TOTAL</th> </button>
<th class="right aligned"> @endif
{{$format->pesos($total_pesos = array_reduce($venta->formaPago()->pie->cuotas(), </td>
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
@php
$now = new DateTimeImmutable();
@endphp
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $venta) {
if ($cuota->pago->fecha > $now) {
return $sum + $cuota->pago->valor / $venta->uf;
}
return $sum + $cuota->pago->valor();
}, 0))}}
</th>
<th colspan="3"></th>
</tr> </tr>
<tr> @endforeach
<th colspan="5">TOTAL PAGADO</th> </tbody>
<th class="right aligned"> <tfoot>
{{$format->pesos($pagado_pesos = array_reduce($venta->formaPago()->pie->cuotas(true), <tr>
function(int $sum, Incoviba\Model\Venta\Cuota $cuota) { <th colspan="5">TOTAL</th>
return $sum + $cuota->pago->valor; <th class="right aligned">
}, 0))}} {{$format->pesos($total_pesos = array_reduce($venta->formaPago()->pie->cuotas(),
</th> function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
<th class="right aligned"> return $sum + $cuota->pago->valor;
{{$format->ufs($pagado = array_reduce($venta->formaPago()->pie->cuotas(true), }, 0))}}
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) { </th>
return $sum + $cuota->pago->valor(); <th class="right aligned">
}, 0.0))}} {{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
</th> function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $uf_venta) {
<th class="right aligned"> return $sum + (($cuota->pago->fecha > $now or $cuota->pago->uf === null) ?
{{$format->number($pagado / $total * 100, 2)}}% $cuota->pago->valor / $uf_venta :
</th> $cuota->pago->valor());
<th colspan="2"></th> }, 0.0))}}
</tr> </th>
<tr> <th colspan="4"></th>
<th colspan="5">POR PAGAR</th> </tr>
<th class="right aligned"> <tr>
{{$format->pesos($total_pesos - $pagado_pesos)}} <th colspan="5">TOTAL PAGADO</th>
</th> <th class="right aligned">
<th class="right aligned"> {{$format->pesos($pagado_pesos = array_reduce($venta->formaPago()->pie->cuotas(true),
{{$format->ufs($total - $pagado)}} function(int $sum, Incoviba\Model\Venta\Cuota $cuota) {
</th> return $sum + $cuota->pago->valor;
<th class="right aligned"> }, 0))}}
{{$format->number(($total - $pagado) / $total * 100, 2)}}% </th>
</th> <th class="right aligned">
<th colspan="2"></th> {{$format->ufs($pagado = array_reduce($venta->formaPago()->pie->cuotas(true),
</tr> function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
</tfoot> return $sum + $cuota->pago->valor();
</table> }, 0.0))}}
</div> </th>
<th class="right aligned">
{{$format->number($pagado / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
<tr>
<th colspan="5">POR PAGAR</th>
<th class="right aligned">
{{$format->pesos($total_pesos - $pagado_pesos)}}
</th>
<th class="right aligned">
{{$format->ufs($total - $pagado)}}
</th>
<th class="right aligned">
{{$format->number(($total - $pagado) / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
</tfoot>
</table>
@endsection @endsection
@include('layout.body.scripts.datatables') @include('layout.body.scripts.datatables')
@ -140,12 +141,127 @@
@push('page_scripts') @push('page_scripts')
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(() => { $(document).ready(() => {
function updateRow({pago_id, fecha, color, estado, remove_fecha=false, add_reject=false, disable=false}) {
const tr = $("tr[data-pago='" + pago_id + "']")
tr.find(':nth-child(7)').attr('class', color).html(estado)
if (remove_fecha) {
tr.find(':nth-child(8)').html(fecha)
}
if (add_reject) {
tr.find(':nth-child(8)>.calendar>.input').append(
$('<button></button>').addClass('ui red basic icon button reject_estado').attr('data-pago', pago_id).append(
$('<i></i>').addClass('remove icon')
).click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
devolver(target, pago_id, fecha)
})
)
}
if (disable) {
tr.addClass('disabled')
tr.find(':nth-child(9)').html('')
}
return tr
}
function depositar(button, pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/depositar'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.depositado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Depositado', color: 'yellow', add_reject: true})
button.attr('data-estado', 'depositado')
})
})
}
function abonar(pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/abonar'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.abonado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Abonado', color: 'green', remove_fecha: true})
})
})
}
function anular(pago_id) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/anular'
return fetchAPI(url).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.anulado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.fecha, estado: 'Anulado', color: 'red', remove_fecha: true, disable: true})
/*const tr = $("button[data-id='" + json.pago_id + "']").parent().parent()
tr.addClass('disabled')
tr.find(':nth-child(7)').addClass('red').html('Anulado')
tr.find(':nth-child(8)').html(json.fecha)
tr.find(':nth-child(9)').html('')*/
})
})
}
function devolver(button, pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/devolver'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.devuelto) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Devuelto', color: 'red'})
button.parent().find('.accept_estado').attr('data-estado', 'devuelto')
button.remove()
})
})
}
$('.fecha_estado').calendar({ $('.fecha_estado').calendar({
type: 'date', type: 'date',
formatter: { formatter: {
date: 'DD-MM-YYYY' date: 'DD-MM-YYYY'
} }
}) })
$('.accept_estado').click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
if (target.attr('data-estado') === 'depositado') {
return abonar(pago_id, fecha)
}
return depositar(target, pago_id, fecha)
})
$('.reject_estado').click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
devolver(target, pago_id, fecha)
})
$('.anular').click(event => {
const pago_id = $(event.currentTarget).data('pago')
anular(pago_id)
})
new DataTable('#cuotas', { new DataTable('#cuotas', {
language: { language: {

View File

@ -1,93 +1,86 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Agregar Cuotas - Pie
<div class="ui two column grid"> @endsection
<h1 class="four wide column header">
<div class="content"> @section('venta_content')
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div> <form class="ui form" id="add_form" action="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add" method="post">
{{$venta->propiedad()->summary()}} <table class="ui table">
</div> <thead>
</h1> <tr>
</div> <th>#</th>
<h2>Agregar Cuotas - Pie</h2> <th>Fecha</th>
<form class="ui form" id="add_form" action="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add" method="post"> <th>Banco</th>
<table class="ui table"> <th>Identificador</th>
<thead> <th>Valor</th>
<tr> </tr>
<th>#</th> </thead>
<th>Fecha</th> <tbody id="cuotas">
<th>Banco</th> @for ($i = count($pie->cuotas(vigentes: true)); $i < $pie->cuotas; $i ++)
<th>Identificador</th> <tr>
<th>Valor</th> <td>{{$i + 1}}</td>
</tr> <td>
</thead> <div class="inline field">
<tbody id="cuotas"> <div class="ui calendar fecha" data-index="{{$i}}">
@for ($i = count($pie->cuotas()); $i < $pie->cuotas - count($pie->cuotas()); $i ++) <div class="ui icon input">
<tr> <input type="text" name="fecha{{$i}}" />
<td>{{$i + 1}}</td> <i class="calendar icon"></i>
<td>
<div class="inline field">
<div class="ui calendar fecha" data-index="{{$i}}">
<div class="ui icon input">
<input type="text" name="fecha{{$i}}" />
<i class="calendar icon"></i>
</div>
</div>
<button class="ui mini compact basic icon button copy fecha" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</div>
</td>
<td>
<div class="ui search selection dropdown banco" data-index="{{$i}}">
<input type="hidden" name="banco{{$i}}" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
@if ($banco->nombre === '')
@continue
@endif
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div> </div>
</div> </div>
<button class="ui mini compact basic icon button copy banco" type="button" data-index="{{$i}}"> <button class="ui mini compact basic icon button copy fecha" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i> <i class="down arrow icon"></i>
</button> </button>
</td> </div>
<td> </td>
<div class="ui input"> <td>
<input type="text" name="identificador{{$i}}" /> <div class="ui search selection dropdown banco" data-index="{{$i}}">
<input type="hidden" name="banco{{$i}}" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
@if ($banco->nombre === '')
@continue
@endif
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div> </div>
</td> </div>
<td> <button class="ui mini compact basic icon button copy banco" type="button" data-index="{{$i}}">
<div class="inline field"> <i class="down arrow icon"></i>
<div class="ui left labeled input"> </button>
<div class="ui label">$</div> </td>
<input type="text" name="valor{{$i}}" /> <td>
</div> <div class="ui input">
<button class="ui mini compact basic icon button copy valor" type="button" data-index="{{$i}}"> <input type="text" name="identificador{{$i}}" />
<i class="down arrow icon"></i> </div>
</button> </td>
<td>
<div class="inline field">
<div class="ui left labeled input">
<div class="ui label">$</div>
<input type="text" name="valor{{$i}}" />
</div> </div>
</td> <button class="ui mini compact basic icon button copy valor" type="button" data-index="{{$i}}">
</tr> <i class="down arrow icon"></i>
@endfor
</tbody>
<tfoot>
<tr>
<td colspan="5">
<button class="ui button" type="submit">
Agregar
</button> </button>
</td> </div>
</tr> </td>
</tfoot> </tr>
</table> @endfor
</form> </tbody>
</div> <tfoot>
<tr>
<td colspan="5">
<button class="ui button" type="submit">
Agregar
</button>
</td>
</tr>
</tfoot>
</table>
</form>
@endsection @endsection
@include('layout.body.scripts.dayjs') @include('layout.body.scripts.dayjs')
@ -112,7 +105,7 @@
const index = $(event.currentTarget).data('index') const index = $(event.currentTarget).data('index')
const calendar = $(".fecha.calendar[data-index='" + index + "']") const calendar = $(".fecha.calendar[data-index='" + index + "']")
const fecha = calendar.calendar('get date') const fecha = calendar.calendar('get date')
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) { for (let i = index + 1; i < {{$pie->cuotas}}; i ++) {
setDate(i - index, $(".fecha.calendar[data-index='" + i + "']"), fecha) setDate(i - index, $(".fecha.calendar[data-index='" + i + "']"), fecha)
} }
}) })
@ -120,7 +113,7 @@
$('.copy.banco').click(event => { $('.copy.banco').click(event => {
const index = $(event.currentTarget).data('index') const index = $(event.currentTarget).data('index')
const banco = $(".banco.dropdown[data-index='" + index + "']").dropdown('get value') const banco = $(".banco.dropdown[data-index='" + index + "']").dropdown('get value')
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) { for (let i = index + 1; i < {{$pie->cuotas}}; i ++) {
$(".banco.dropdown[data-index='" + i + "']").dropdown('set selected', banco) $(".banco.dropdown[data-index='" + i + "']").dropdown('set selected', banco)
} }
}) })
@ -133,7 +126,7 @@
$('.copy.valor').click(event => { $('.copy.valor').click(event => {
const index = $(event.currentTarget).data('index') const index = $(event.currentTarget).data('index')
const valor = $("[name='valor" + index + "']").val() const valor = $("[name='valor" + index + "']").val()
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) { for (let i = index + 1; i < {{$pie->cuotas}}; i ++) {
$("[name='valor" + i + "']").val(valor) $("[name='valor" + i + "']").val(valor)
} }
}) })

View File

@ -1,27 +1,24 @@
@extends('layout.base') @extends('ventas.base')
@section('page_content') @section('venta_subtitle')
<div class="ui container"> Pie
<h2 class="ui header"> @endsection
Pie -
{{$venta->proyecto()->descripcion}} - @section('venta_content')
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a> <form class="ui form" id="edit_pie">
</h2> <div class="three wide field">
<form class="ui form" id="edit_pie"> <label for="valor">Valor</label>
<div class="three wide field"> <div class="ui right labeled input">
<label for="valor">Valor</label> <input type="text" name="valor" id="valor" value="{{$venta->formaPago()->pie->valor}}" />
<div class="ui right labeled input"> <div class="ui basic label">UF</div>
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->pie->valor}}" />
<div class="ui basic label">UF</div>
</div>
</div> </div>
<div class="three wide field"> </div>
<label for="cuotas"># Cuotas</label> <div class="three wide field">
<input type="number" name="cuotas" id="cuotas" value="{{$venta->formaPago()->pie->cuotas}}" /> <label for="cuotas"># Cuotas</label>
</div> <input type="number" name="cuotas" id="cuotas" value="{{$venta->formaPago()->pie->cuotas}}" />
<button class="ui button">Editar</button> </div>
</form> <button class="ui button">Editar</button>
</div> </form>
@endsection @endsection
@push('page_scripts') @push('page_scripts')

View File

@ -1,10 +1,39 @@
@extends('layout.base') @extends('ventas.base')
@section('page_title') @php
Venta {{$venta->proyecto()->descripcion}} {{$venta->propiedad()->summary()}} $showPropietario = true;
@endphp
@section('venta_content')
<div class="ui fitted basic mini segment">
@if ($venta->currentEstado()->tipoEstadoVenta->activa)
<a href="{{$urls->base}}/venta/{{$venta->id}}/desistir">
Desistir <i class="minus icon"></i>
</a>
<a href="{{$urls->base}}/venta/{{$venta->id}}/ceder">
Ceder <i clasS="right chevron icon"></i>
</a>
@else
<div class="ui red icon label">
<i class="ban icon"></i>
{{ucwords($venta->currentEstado()->tipoEstadoVenta->descripcion)}}
(<a href="{{$urls->base}}/venta/{{$venta->id}}/desistida">
{{$format->pesos($venta->resciliacion()->valor)}}
</a>)
</div>
@endif
</div>
<div class="ui segments">
@include('ventas.show.propiedad')
@include('ventas.show.detalle')
@include('ventas.show.forma_pago', ['formaPago' => $venta->formaPago()])
@include('ventas.show.escritura')
@include('ventas.show.entrega')
@include('ventas.show.comentarios')
</div>
@endsection @endsection
@section('page_content') {{--@section('page_content')
<div class="ui container"> <div class="ui container">
<div class="ui two column grid"> <div class="ui two column grid">
<h1 class="four wide column header"> <h1 class="four wide column header">
@ -45,4 +74,4 @@
@include('ventas.show.comentarios') @include('ventas.show.comentarios')
</div> </div>
</div> </div>
@endsection @endsection--}}

View File

@ -9,7 +9,7 @@
<i class="small edit icon"></i> <i class="small edit icon"></i>
</a> </a>
</sub> </sub>
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/informe"> <a href="{{$urls->base}}/ventas/escritura/{{$venta->id}}/informe">
Informe Informe
<i class="right chevron icon"></i> <i class="right chevron icon"></i>
</a> </a>

View File

@ -14,7 +14,7 @@
<td class="right aligned">Cuotas</td> <td class="right aligned">Cuotas</td>
<td> <td>
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas"> <a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas">
{{count($pie->cuotas(true))}}/{{$pie->cuotas}} <span data-tooltip="Pagadas">{{count($pie->cuotas(true))}}</span>/{{$pie->cuotas}}
</a> </a>
@if (count($pie->cuotas()) < $pie->cuotas) @if (count($pie->cuotas()) < $pie->cuotas)
<a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add"> <a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add">

View File

@ -6,7 +6,9 @@ return [
'resources' => DI\String('{base}/resources'), 'resources' => DI\String('{base}/resources'),
'routes' => DI\String('{resources}/routes'), 'routes' => DI\String('{resources}/routes'),
'cache' => DI\String('{base}/cache'), 'cache' => DI\String('{base}/cache'),
'templates' => DI\String('{resources}/views') 'templates' => DI\String('{resources}/views'),
'public' => DI\String('{base}/public'),
'uploads' => DI\String('{public}/uploads')
]); ]);
} }
]; ];

View File

@ -0,0 +1,8 @@
<?php
return [
'nubox' => function() {
return new DI\Container([
'url' => 'https://api.nubox.com/Nubox.API'
]);
}
];

View File

@ -5,19 +5,25 @@ return [
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) { Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
return new Monolog\Logger('incoviba', [ return new Monolog\Logger('incoviba', [
new Monolog\Handler\FilterHandler( new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/debug.log')) (new Monolog\Handler\RotatingFileHandler('/logs/debug.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)), ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Debug, Monolog\Level::Debug,
Monolog\Level::Notice Monolog\Level::Debug
), ),
new Monolog\Handler\FilterHandler( new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/error.log')) (new Monolog\Handler\RotatingFileHandler('/logs/info.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)), ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Info,
Monolog\Level::Warning, Monolog\Level::Warning,
),
new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/error.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Error,
Monolog\Level::Error Monolog\Level::Error
), ),
new Monolog\Handler\FilterHandler( new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/critical.log')) (new Monolog\Handler\RotatingFileHandler('/logs/critical.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)), ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Critical Monolog\Level::Critical
) )

View File

@ -2,7 +2,13 @@
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
return [ return [
Psr\Http\Message\StreamFactoryInterface::class => function(ContainerInterface $container) {
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
},
Psr\Http\Message\RequestFactoryInterface::class => function(ContainerInterface $container) {
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
},
Psr\Http\Message\ResponseFactoryInterface::class => function(ContainerInterface $container) { Psr\Http\Message\ResponseFactoryInterface::class => function(ContainerInterface $container) {
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class); return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
} },
]; ];

View File

@ -1,4 +1,5 @@
<?php <?php
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
return [ return [
@ -28,5 +29,29 @@ return [
'host' => $container->get('REDIS_HOST'), 'host' => $container->get('REDIS_HOST'),
'port' => $container->get('REDIS_PORT') 'port' => $container->get('REDIS_PORT')
]); ]);
},
Incoviba\Service\Cartola::class => function(ContainerInterface $container) {
return (new Incoviba\Service\Cartola(
$container->get(Psr\Http\Message\StreamFactoryInterface::class),
$container->get(Incoviba\Common\Define\Contabilidad\Exporter::class)
))
->register('security', $container->get(Incoviba\Service\Cartola\Security::class))
->register('itau', $container->get(Incoviba\Service\Cartola\Itau::class))
->register('santander', $container->get(Incoviba\Service\Cartola\Santander::class));
},
Incoviba\Common\Define\Contabilidad\Exporter::class => function(ContainerInterface $container) {
return $container->get(Incoviba\Service\Contabilidad\Exporter\Nubox::class);
},
Incoviba\Service\Contabilidad\Exporter\Nubox::class => function(ContainerInterface $container) {
return new Incoviba\Service\Contabilidad\Exporter\Nubox($container->get(Incoviba\Repository\CentroCosto::class),
$container->get('folders')->get('uploads'));
},
Incoviba\Service\Contabilidad\Nubox::class => function(ContainerInterface $container) {
return new Incoviba\Service\Contabilidad\Nubox(
$container->get(Incoviba\Repository\Nubox::class),
$container->get(Incoviba\Service\Redis::class),
new GuzzleHttp\Client(),
$container->get(Psr\Http\Message\RequestFactoryInterface::class),
$container->get('nubox')->get('url'));
} }
]; ];

View File

@ -0,0 +1,62 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository;
class CentrosCostos
{
use withJson;
public function add(ServerRequestInterface $request, ResponseInterface $response,
Repository\CentroCosto $centroCostoRepository): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'added' => false
];
try {
$centroCosto = $centroCostoRepository->create($body);
$centroCosto->id = $body['id'];
$centroCostoRepository->save($centroCosto);
$output['added'] = true;
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function edit(ServerRequestInterface $request, ResponseInterface $response,
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'centro_costo_id' => $centro_costo_id,
'input' => $body,
'edited' => false
];
try {
$centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
if ($body['tipo_cuenta_id'] === '') {
$body['tipo_cuenta_id'] = null;
}
$centroCostoRepository->edit($centroCosto, $body);
$output['edited'] = true;
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function remove(ServerRequestInterface $request, ResponseInterface $response,
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
{
$output = [
'centro_costo_id' => $centro_costo_id,
'removed' => false
];
try {
$centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
$centroCostoRepository->remove($centroCosto);
$output['removed'] = true;
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Incoviba\Controller\API;
use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository;
use Incoviba\Service;
class Contabilidad
{
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);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Service;
class Informes
{
use withJson;
public function diario(ServerRequestInterface $request, ResponseInterface $response, Service\Informes\Diario $diarioService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'data' => []
];
try {
$file = $request->getUploadedFiles()['file'];
$output['data'] = $diarioService->process($file);
} catch (\Error) {}
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class Inmobiliarias
{
use withJson;
public function cuentas(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Inmobiliaria\Cuenta $cuentaRepository, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'cuentas' => []
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
$output['cuentas'] = $cuentaRepository->fetchByInmobiliaria($inmobiliaria->rut);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function proyectos(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Service\Proyecto $proyectoService, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'proyectos' => []
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
$output['proyectos'] = array_map(function(Model\Proyecto $proyecto) {
$p = json_decode(json_encode($proyecto));
$p->current_estado = $proyecto->currentEstado();
$p->estados = $proyecto->estados();
return $p;
},$proyectoService->getByInmobiliaria($inmobiliaria->rut));
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,90 @@
<?php
namespace Incoviba\Controller\API;
use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\HttpResponse;
use Incoviba\Service;
class Nubox
{
use withJson;
public function token(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'token' => ''
];
try {
$output['token'] = $nuboxService->getToken($inmobiliaria_rut);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
public function sistemas(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'sistemas' => []
];
try {
$output['sistemas'] = $nuboxService->getSistemas($inmobiliaria_rut);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
public function libroMayor(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'input' => $body,
'libro_mayor' => []
];
try {
$from = new DateTimeImmutable($body['inicio']);
$to = new DateTimeImmutable($body['termino']);
$output['libro_mayor'] = $nuboxService->getLibroMayor($inmobiliaria_rut, $from, $to);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
public function libroDiario(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'input' => $body,
'libro_diario' => []
];
try {
$from = new DateTimeImmutable($body['inicio']);
$to = new DateTimeImmutable($body['termino']);
$output['libro_diario'] = $nuboxService->getLibroDiario($inmobiliaria_rut, $from, $to);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
}

View File

@ -155,4 +155,19 @@ class Proyectos
} catch (EmptyResult) {} } catch (EmptyResult) {}
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function tiposUnidades(ServerRequestInterface $request, ResponseInterface $response,
Repository\Proyecto $proyectoRepository,
Repository\Proyecto\TipoUnidad $tipoUnidadRepository,
int $proyecto_id): ResponseInterface
{
$output = [
'proyecto_id' => $proyecto_id,
'tipos' => []
];
try {
$proyecto = $proyectoRepository->fetchById($proyecto_id);
$output['tipos'] = $tipoUnidadRepository->fetchByProyecto($proyecto->id);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
} }

View File

@ -0,0 +1,20 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Service;
class Search
{
use withJson;
public function query(ServerRequestInterface $request, ResponseInterface $response,
Service\Search $service): ResponseInterface
{
$data = $request->getParsedBody();
$results = $service->query($data['query'], $data['tipo']);
$output = compact('results');
return $this->withJson($response, $output);
}
}

View File

@ -1,17 +1,19 @@
<?php <?php
namespace Incoviba\Controller\API; namespace Incoviba\Controller\API;
use PDOException;
use DateTimeImmutable; use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Ideal\Controller;
use Incoviba\Common\Implement\Exception\EmptyRedis; use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\withRedis; use Incoviba\Controller\withRedis;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Service; use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class Ventas class Ventas extends Controller
{ {
use withJson, withRedis; use withJson, withRedis;
@ -55,6 +57,9 @@ class Ventas
Service\Venta $service, int $venta_id): ResponseInterface Service\Venta $service, int $venta_id): ResponseInterface
{ {
$redisKey = "venta:{$venta_id}"; $redisKey = "venta:{$venta_id}";
$output = [
'venta' => null
];
try { try {
$venta = $this->fetchRedis($redisService, $redisKey); $venta = $this->fetchRedis($redisService, $redisKey);
$output = compact('venta'); $output = compact('venta');
@ -64,12 +69,7 @@ class Ventas
$output = compact('venta'); $output = compact('venta');
$this->saveRedis($redisService, $redisKey, $venta); $this->saveRedis($redisService, $redisKey, $venta);
} catch (EmptyResult $exception) { } catch (EmptyResult $exception) {
$output = [ $this->logger->notice($exception);
'error' => [
'code' => $exception->getCode(),
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
]
];
} }
} }
return $this->withJson($response, $output); return $this->withJson($response, $output);
@ -178,14 +178,20 @@ class Ventas
$data = $request->getParsedBody(); $data = $request->getParsedBody();
$output = [ $output = [
'status' => false, 'status' => false,
'venta_id' => null,
'errors' => [] 'errors' => []
]; ];
try { try {
$venta = $ventaService->add($data); $venta = $ventaService->add($data);
$this->saveRedis($redisService, "venta:{$venta->id}", $venta); $this->saveRedis($redisService, "venta:{$venta->id}", $venta);
$output['venta_id'] = $venta->id;
$output['status'] = true; $output['status'] = true;
} catch (\Exception $exception) { } catch (EmptyResult | PDOException $exception) {
$output['errors'] = $exception; $output['errors'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'stack' => $exception->getTraceAsString()
];
} }
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
@ -258,4 +264,16 @@ class Ventas
} catch (EmptyResult) {} } catch (EmptyResult) {}
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function insistir(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, int $venta_id): ResponseInterface
{
$output = [
'venta_id' => $venta_id,
'eliminado' => false
];
try {
$venta = $ventaService->getById($venta_id);
$output['eliminado'] = $ventaService->insistir($venta);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
} }

View File

@ -31,23 +31,52 @@ class Pagos
} catch (EmptyResult) {} } catch (EmptyResult) {}
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
// NOT IMPLEMENTED public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
{ {
$body = $request->getBody(); $body = $request->getParsedBody();
$json = json_decode($body->getContents()); $output = [
$date = new DateTimeImmutable($json->fecha); 'pago_id' => $pago_id,
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); 'input' => $body,
return $response->withHeader('Content-Type', 'application/json'); 'depositado' => false
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body->fecha);
$output['depositado'] = $pagoService->depositar($pago, $fecha);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
} }
// NOT IMPLEMENTED public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
{ {
$body = $request->getBody(); $body = $request->getParsedBody();
$json = json_decode($body->getContents()); $output = [
$date = new DateTimeImmutable($json->fecha); 'pago_id' => $pago_id,
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); 'input' => $body,
return $response->withHeader('Content-Type', 'application/json'); 'abonado' => false
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body->fecha);
$output['abonado'] = $pagoService->abonar($pago, $fecha);
$output['input']['fecha'] = $fecha->format('d-m-Y');
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function devolver(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'pago_id' => $pago_id,
'input' => $body,
'devuelto' => false
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body->fecha);
$output['devuelto'] = $pagoService->devolver($pago, $fecha);
$output['input']['fecha'] = $fecha->format('d-m-Y');
} catch (EmptyResult) {}
return $this->withJson($response, $output);
} }
public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
{ {
@ -82,4 +111,19 @@ class Pagos
} }
return $this->withJson($response, ['pagos' => $rebotes, 'total' => count($rebotes)]); return $this->withJson($response, ['pagos' => $rebotes, 'total' => count($rebotes)]);
} }
public function anular(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
{
$fecha = new DateTimeImmutable();
$output = [
'pago_id' => $pago_id,
'fecha' => $fecha->format('d-m-Y'),
'anulado' => false
];
try {
$pago = $pagoService->getById($pago_id);
$output['anulado'] = $pagoService->anular($pago, $fecha);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
} }

View File

@ -20,7 +20,6 @@ class Pies
'input' => $body, 'input' => $body,
'edited' => false 'edited' => false
]; ];
error_log(var_export($output,true).PHP_EOL,3,'/logs/pies');
try { try {
$pie = $pieService->getById($pie_id); $pie = $pieService->getById($pie_id);
$pieService->edit($pie, (array) $body); $pieService->edit($pie, (array) $body);

View File

@ -0,0 +1,32 @@
<?php
namespace Incoviba\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Repository;
use Incoviba\Common\Alias\View;
class CentrosCostos
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
Repository\CentroCosto $centroCostoRepository,
Repository\TipoCentro $tipoCentroRepository,
Repository\CategoriaCentro $categoriaCentroRepository,
Repository\TipoCuenta $tipoCuentaRepository): ResponseInterface
{
$centrosCostos = $centroCostoRepository->fetchAll();
$tiposCentros = $tipoCentroRepository->fetchAll();
$categorias = $categoriaCentroRepository->fetchAll('descripcion');
$tiposCuentas = $tipoCuentaRepository->fetchAll();
return $view->render($response, 'contabilidad.centros_costos', compact('centrosCostos',
'tiposCentros', 'categorias', 'tiposCuentas'));
}
public function asignar(ServerRequestInterface $request, ResponseInterface $response, View $view,
Repository\CentroCosto $centroCostoRepository,
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
{
$centrosCostos = $centroCostoRepository->fetchAll();
$inmobiliarias = $inmobiliariaRepository->fetchAllActive('razon');
return $view->render($response, 'contabilidad.centros_costos.asignar', compact('centrosCostos', 'inmobiliarias'));
}
}

View File

@ -13,11 +13,4 @@ class Search
$post = $request->getParsedBody() ?? ''; $post = $request->getParsedBody() ?? '';
return $view->render($response, 'search', compact('post', 'query', 'tipo')); return $view->render($response, 'search', compact('post', 'query', 'tipo'));
} }
public function query(ServerRequestInterface $request, ResponseInterface $response, Service\Search $service): ResponseInterface
{
$data = $request->getParsedBody();
$results = $service->query($data['query'], $data['tipo']);
$response->getBody()->write(json_encode(compact('results')));
return $response->withHeader('Content-Type', 'application/json');
}
} }

View File

@ -83,13 +83,14 @@ class Cuotas
}); });
return $view->render($response, 'ventas.pies.cuotas.add', compact('pie', 'venta', 'bancos')); return $view->render($response, 'ventas.pies.cuotas.add', compact('pie', 'venta', 'bancos'));
} }
public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, Repository\Venta $ventaRepository, int $pie_id): ResponseInterface public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService,
Repository\Venta $ventaRepository, int $pie_id): ResponseInterface
{ {
$body = $request->getParsedBody(); $body = $request->getParsedBody();
$pie = $pieService->getById($pie_id); $pie = $pieService->getById($pie_id);
$venta = $ventaRepository->fetchByPie($pie_id); $venta = $ventaRepository->fetchByPie($pie_id);
$total = $pie->cuotas - count($pie->cuotas()); $start = count($pie->cuotas(vigentes: true));
$start = count($pie->cuotas()); $total = $pie->cuotas;
for ($i = $start; $i < $total; $i ++) { for ($i = $start; $i < $total; $i ++) {
$data = [ $data = [
'pie' => $pie->id, 'pie' => $pie->id,

View File

@ -8,9 +8,16 @@ use Incoviba\Service;
class Escrituras class Escrituras
{ {
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $ventaService, int $venta_id): ResponseInterface public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $ventaService, int $venta_id): ResponseInterface
{ {
$venta = $ventaService->getById($venta_id); $venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.escrituras.show', compact('venta')); return $view->render($response, 'ventas.escrituras.show', compact('venta'));
} }
public function informe(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $ventaService, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.escrituras.informe', compact('venta'));
}
} }

View File

@ -22,7 +22,7 @@ class Errors
} catch (Error $error) { } catch (Error $error) {
$this->logger->error($error); $this->logger->error($error);
} }
$response = $this->responseFactory->createResponse(404); $response = $this->responseFactory->createResponse(600, 'Internal Server Error');
if (str_contains($request->getUri()->getPath(), '/api')) { if (str_contains($request->getUri()->getPath(), '/api')) {
return $response; return $response;
} }

View File

@ -17,7 +17,7 @@ class NotFound
try { try {
return $handler->handle($request); return $handler->handle($request);
} catch (HttpNotFoundException $exception) { } catch (HttpNotFoundException $exception) {
$this->logger->warning($exception); $this->logger->notice($exception);
$response = $this->responseFactory->createResponse(404); $response = $this->responseFactory->createResponse(404);
if (str_contains($request->getUri()->getPath(), '/api')) { if (str_contains($request->getUri()->getPath(), '/api')) {
return $response; return $response;

View File

@ -0,0 +1,5 @@
<?php
namespace Incoviba\Model;
class CategoriaCentro extends Tipo
{}

View File

@ -0,0 +1,24 @@
<?php
namespace Incoviba\Model;
use Incoviba\Common\Ideal;
class CentroCosto extends Ideal\Model
{
public TipoCentro $tipoCentro;
public CategoriaCentro $categoria;
public ?TipoCuenta $tipoCuenta;
public string $cuentaContable;
public string $descripcion;
public function jsonSerialize(): mixed
{
return array_map(parent::jsonSerialize(), [
'tipo_centro' => $this->tipoCentro,
'categoria' => $this->categoria,
'tipo_cuenta' => $this->tipoCuenta,
'cuenta_contable' => $this->cuentaContable,
'descripcion' => $this->descripcion
]);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Incoviba\Model\Inmobiliaria;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Cuenta extends Ideal\Model
{
public Model\Inmobiliaria $inmobiliaria;
public Model\Banco $banco;
public string $cuenta;
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
'inmobiliaria_rut' => $this->inmobiliaria->rut,
'banco' => $this->banco,
'cuenta' => $this->cuenta
]);
}
}

18
app/src/Model/Nubox.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace Incoviba\Model;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
class Nubox extends Ideal\Model
{
public Inmobiliaria $inmobiliaria;
public string $alias;
public string $usuario;
public string $password;
public function getLogin(): string
{
return base64_encode(implode(':', [$this->usuario, $this->password]));
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Incoviba\Model;
use Incoviba\Common\Ideal;
class PagoCentroCosto extends Ideal\Model
{
public Venta\Pago $pago;
public CentroCosto $centroCosto;
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
'pago' => $this->pago,
'centro_costo' => $this->centroCosto
]);
}
}

View File

@ -0,0 +1,5 @@
<?php
namespace Incoviba\Model;
class TipoCentro extends Tipo
{}

View File

@ -0,0 +1,5 @@
<?php
namespace Incoviba\Model;
class TipoCuenta extends Tipo
{}

View File

@ -19,8 +19,8 @@ class Venta extends Ideal\Model
public float $uf; public float $uf;
protected ?Pago $resciliacion; protected ?Pago $resciliacion;
public array $estados; public ?array $estados;
public Venta\EstadoVenta $currentEstado; public ?Venta\EstadoVenta $currentEstado;
public function propietario(): Venta\Propietario public function propietario(): Venta\Propietario
{ {
@ -63,7 +63,7 @@ class Venta extends Ideal\Model
if (!isset($this->estados)) { if (!isset($this->estados)) {
$this->estados = $this->runFactory('estados'); $this->estados = $this->runFactory('estados');
} }
return $this->estados; return $this->estados ?? [];
} }
public function currentEstado(): ?Venta\EstadoVenta public function currentEstado(): ?Venta\EstadoVenta
{ {

View File

@ -27,9 +27,9 @@ class Cuota extends Model
'valor' => $this->valor, 'valor' => $this->valor,
'estado' => $this->estado ?? false, 'estado' => $this->estado ?? false,
'banco' => $this->banco, 'banco' => $this->banco,
'fecha_pago' => $this->fechaPago->format('Y-m-d H:i:s') ?? '', 'fecha_pago' => $this->fechaPago?->format('Y-m-d H:i:s') ?? '',
'abonado' => $this->abonado ?? false, 'abonado' => $this->abonado ?? false,
'fecha_abonado' => $this->fechaAbonado->format('Y-m-d H:i:s') ?? '', 'fecha_abonado' => $this->fechaAbonado?->format('Y-m-d H:i:s') ?? '',
'uf' => $this->uf ?? 1, 'uf' => $this->uf ?? 1,
'pago' => $this->pago ?? '', 'pago' => $this->pago ?? '',
'numero' => $this->numero ?? '' 'numero' => $this->numero ?? ''

View File

@ -24,7 +24,8 @@ class Pago extends Model
public function valor(string $moneda = Pago::UF): float public function valor(string $moneda = Pago::UF): float
{ {
return $this->valor / (($moneda === Pago::UF) ? ($this->uf > 0 ? $this->uf : 1) : 1); $uf = $this->uf ?? ($this->uf > 0.0 ? $this->uf : 1);
return $this->valor / (($moneda === Pago::UF) ? $uf : 1);
} }
public function jsonSerialize(): mixed public function jsonSerialize(): mixed

View File

@ -15,16 +15,21 @@ class Pie extends Model
public ?Pago $reajuste; public ?Pago $reajuste;
public array $cuotasArray; public array $cuotasArray;
public function cuotas(bool $pagadas = false): array public function cuotas(bool $pagadas = false, bool $vigentes = false): array
{ {
if ($this->asociado !== null) { if ($this->asociado !== null) {
return $this->asociado->cuotas($pagadas); return $this->asociado->cuotas($pagadas);
} }
if (!$pagadas) { if (!$pagadas and !$vigentes) {
return $this->cuotasArray; return $this->cuotasArray;
} }
if ($pagadas) {
return array_filter($this->cuotasArray, function(Cuota $cuota) {
return in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado']);
});
}
return array_filter($this->cuotasArray, function(Cuota $cuota) { return array_filter($this->cuotasArray, function(Cuota $cuota) {
return $cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'no pagado'; return $cuota->pago->currentEstado->tipoEstadoPago->activo or $cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'devuelto';
}); });
} }

View File

@ -0,0 +1,19 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Model;
class CategoriaCentro extends Tipo
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('categorias_centros_costos');
}
protected function getBlank(): Define\Model
{
return new Model\CategoriaCentro();
}
}

View File

@ -0,0 +1,81 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Repository\Mapper;
use Incoviba\Common\Implement\Repository\MapperParser;
use Incoviba\Repository;
use Incoviba\Model;
class CentroCosto extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected TipoCentro $tipoCentroRepository,
protected CategoriaCentro $categoriaCentroRepository,
protected TipoCuenta $tipoCuentaRepository)
{
parent::__construct($connection);
$this->setTable('centros_costos');
}
public function create(?array $data = null): Model\CentroCosto
{
$map = (new MapperParser(['descripcion']))
->register('tipo_centro_id', (new Mapper())
->setProperty('tipoCentro')
->setFunction(function(array $data) {
return $this->tipoCentroRepository->fetchById($data['tipo_centro_id']);
}))
->register('categoria_id', (new Mapper())
->setProperty('categoria')
->setFunction(function(array $data) {
return $this->categoriaCentroRepository->fetchById($data['categoria_id']);
}))
->register('tipo_cuenta_id', (new Mapper())
->setProperty('tipoCuenta')
->setFunction(function(array $data) {
return $this->tipoCuentaRepository->fetchById($data['tipo_cuenta_id']);
})
->setDefault(null))
->register('cuenta_contable', (new Mapper())
->setProperty('cuentaContable'));
return $this->parseData(new Model\CentroCosto(), $data, $map);
}
public function save(Define\Model $model): Model\CentroCosto
{
$this->saveNew(
['id', 'tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'],
[$model->id, $model->tipoCentro->id, $model->categoria->id, $model->tipoCuenta?->id, $model->cuentaContable, $model->descripcion]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\CentroCosto
{
return $this->update($model, ['tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'], $new_data);
}
public function fetchByDescripcion(string $descripcion): Model\CentroCosto
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('descripcion LIKE ?');
return $this->fetchOne($query, [$descripcion]);
}
public function fetchByTipoCuenta(string $tipo_cuenta): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('tipo_cuenta_id LIKE ?');
return $this->fetchMany($query, [$tipo_cuenta]);
}
public function fetchByCategoria(string $categoria): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('categoria_id LIKE ?');
return $this->fetchMany($query, [$categoria]);
}
}

View File

@ -46,4 +46,20 @@ class Inmobiliaria extends Ideal\Repository
{ {
return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data); return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data);
} }
public function fetchAllActive(null|string|array $sorting = null): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN proyecto ON a.rut = proyecto.inmobiliaria')
->joined('JOIN (SELECT ep1.* FROM estado_proyecto ep1 JOIN (SELECT MAX(id) AS id, proyecto FROM estado_proyecto GROUP BY proyecto) ep0 ON ep0.id = ep1.id) ep ON ep.proyecto = proyecto.id')
->joined('JOIN tipo_estado_proyecto tep ON tep.id = ep.estado')
->joined('JOIN etapa_proyecto ON etapa_proyecto.id = tep.etapa')
->where('etapa_proyecto.orden BETWEEN ? AND ?');
if ($sorting !== null) {
$query->order($sorting);
}
return $this->fetchMany($query, [1, 8]);
}
} }

View File

@ -0,0 +1,52 @@
<?php
namespace Incoviba\Repository\Inmobiliaria;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Repository;
use Incoviba\Model;
use Incoviba\Common\Implement;
class Cuenta extends Ideal\Repository
{
public function __construct(Define\Connection $connection,
protected Repository\Inmobiliaria $inmobiliariaRepository,
protected Repository\Banco $bancoRepository)
{
parent::__construct($connection);
$this->setTable('cuenta');
}
public function create(?array $data = null): Model\Inmobiliaria\Cuenta
{
$map = (new Implement\Repository\MapperParser(['cuenta']))
->register('inmobiliaria', (new Implement\Repository\Mapper())
->setFunction(function(array $data) {
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria']);
}))
->register('banco', (new Implement\Repository\Mapper())
->setFunction(function(array $data) {
return $this->bancoRepository->fetchById($data['banco']);
}));
return $this->parseData(new Model\Inmobiliaria\Cuenta(), $data, $map);
}
public function save(Define\Model $model): Model\Inmobiliaria\Cuenta
{
$model->id = $this->saveNew(['inmobiliaria', 'banco', 'cuenta'],
[$model->inmobiliaria->rut, $model->banco->id, $model->cuenta]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Cuenta
{
return $this->update($model, ['inmobiliaria', 'banco', 'cuenta'], $new_data);
}
public function fetchByInmobiliaria(int $inmobiliaria_rut): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('inmobiliaria = ?');
return $this->fetchMany($query, [$inmobiliaria_rut]);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Nubox extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Inmobiliaria $inmobiliariaRepository)
{
parent::__construct($connection);
$this->setTable('inmobiliarias_nubox');
}
public function create(?array $data = null): Model\Nubox
{
$map = (new Implement\Repository\MapperParser(['usuario', 'alias']))
->register('inmobiliaria_rut', (new Implement\Repository\Mapper())
->setProperty('inmobiliaria')
->setFunction(function(array $data) {
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria_rut']);
}))
->register('contraseña', (new Implement\Repository\Mapper())
->setProperty('password'));
return $this->parseData(new Model\Nubox(), $data, $map);
}
public function save(Define\Model $model): Model\Nubox
{
$this->saveNew(
['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'],
[$model->inmobiliaria->rut, $model->alias, $model->usuario, $model->password]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Nubox
{
return $this->update($model, ['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'], $new_data);
}
public function fetchByInmobiliaria(int $inmobiliaria_rut): Model\Nubox
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('inmobiliaria_rut = ?');
return $this->fetchOne($query, [$inmobiliaria_rut]);
}
protected function getKey(): string
{
return 'inmobiliaria_rut';
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class PagoCentroCosto extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Venta\Pago $pagoRepository, protected CentroCosto $centroCostoRepository)
{
parent::__construct($connection);
$this->setTable('pagos_centros_costos');
}
public function create(?array $data = null): Model\PagoCentroCosto
{
$map = (new Implement\Repository\MapperParser())
->register('pago_id', (new Implement\Repository\Mapper())
->setProperty('pago')
->setFunction(function(array $data) {
return $this->pagoRepository->fetchById($data['pago_id']);
}))
->register('centro_costo_id', (new Implement\Repository\Mapper())
->setProperty('centroCosto')
->setFunction(function(array $data) {
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
}));
return $this->parseData(new Model\PagoCentroCosto(), $data, $map);
}
public function save(Define\Model $model): Model\PagoCentroCosto
{
$model->id = $this->saveNew(['pago_id', 'centro_costo_id'], [$model->pago->id, $model->centroCosto->id]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\PagoCentroCosto
{
return $this->update($model, ['pago_id', 'centro_costo_id'], $new_data);
}
}

View File

@ -156,6 +156,14 @@ class Proyecto extends Ideal\Repository
} }
return $proyecto; return $proyecto;
} }
public function fetchByInmobiliaria(int $inmobiliaria_rut): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('inmobiliaria = ?');
return $this->fetchMany($query, [$inmobiliaria_rut]);
}
/*public function fetchSuperficieVendido(int $proyecto_id): float /*public function fetchSuperficieVendido(int $proyecto_id): float
{ {

View File

@ -31,6 +31,18 @@ class TipoUnidad extends Ideal\Repository
{ {
return $this->update($model, ['descripcion', 'orden'], $new_data); return $this->update($model, ['descripcion', 'orden'], $new_data);
} }
public function fetchByProyecto(int $proyecto_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN proyecto_tipo_unidad b ON b.tipo = a.id')
->where('b.proyecto = ?')
->group('a.id')
->order('a.orden');
return $this->fetchMany($query, [$proyecto_id]);
}
} }

View File

@ -0,0 +1,37 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
abstract class Tipo extends Ideal\Repository
{
abstract protected function getBlank(): Define\Model;
public function create(?array $data = null): Define\Model
{
$map = new Implement\Repository\MapperParser(['descripcion']);
return $this->parseData($this->getBlank(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['descripcion'],
[$model->descripcion]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['descripcion'], $new_data);
}
public function fetchByDescripcion(string $descripcion): Define\Model
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('descripcion LIKE ?');
return $this->fetchOne($query, [$descripcion]);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Model;
class TipoCentro extends Tipo
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('tipos_centros_costos');
}
protected function getBlank(): Define\Model
{
return new Model\TipoCentro();
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Model;
class TipoCuenta extends Tipo
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('tipos_cuentas_costos');
}
protected function getBlank(): Define\Model
{
return new Model\TipoCuenta();
}
}

View File

@ -115,13 +115,15 @@ class Venta extends Ideal\Repository
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso')) ->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
//->register('avalchile') //->register('avalchile')
//->register('agente') //->register('agente')
->register('resciliacion', (new Implement\Repository\Mapper())
->setFactory((new Implement\Repository\Factory())
->setCallable([$this->pagoService, 'getById'])
->setArgs(['pago_id' => $data['resciliacion']])))
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado')); ->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
//->register('promocion') //->register('promocion')
//->register('devolucion'); //->register('devolucion');
if (array_key_exists('resciliacion', $data)) {
$map = $map->register('resciliacion', (new Implement\Repository\Mapper())
->setFactory((new Implement\Repository\Factory())
->setCallable([$this->pagoService, 'getById'])
->setArgs(['pago_id' => $data['resciliacion']])));
}
return $this->parseData(new Model\Venta(), $data, $map); return $this->parseData(new Model\Venta(), $data, $map);
} }
public function save(Define\Model $model): Model\Venta public function save(Define\Model $model): Model\Venta
@ -147,7 +149,17 @@ class Venta extends Ideal\Repository
public function fetchByProyecto(int $proyecto_id): array public function fetchByProyecto(int $proyecto_id): array
{ {
$query = "SELECT a.* $query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
->joined('JOIN unidad ON unidad.id = pu.unidad AND pu.principal = 1')
->joined('JOIN proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
->joined('JOIN (SELECT ev1.* FROM estado_venta ev1 JOIN (SELECT MAX(id) AS id, venta FROM estado_venta GROUP BY venta) ev0 ON ev0.id = ev1.id) ev ON ev.venta = a.id')
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
->where('ptu.proyecto = ? AND tev.activa')
->group('a.id');
/*$query = "SELECT a.*
FROM `{$this->getTable()}` a FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1 JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
@ -155,124 +167,207 @@ FROM `{$this->getTable()}` a
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 (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` JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
WHERE ptu.`proyecto` = ? AND tev.`activa` WHERE ptu.`proyecto` = ? AND tev.`activa`
GROUP BY a.`id`"; 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
{ {
$query = "SELECT a.`id` $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('a.id')
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` ->from("{$this->getTable()} a")
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1 ->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` ->joined('JOIN unidad ON unidad.id = pu.unidad AND 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` ->joined('JOIN proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` ->joined('JOIN (SELECT ev1.* FROM estado_venta ev1 JOIN (SELECT MAX(id) AS id, venta FROM estado_venta GROUP BY venta) ev0 ON ev0.id = ev1.id) ev ON ev.venta = a.id')
WHERE ptu.`proyecto` = ? AND tev.`activa` ->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
GROUP BY a.`id`"; ->where('ptu.proyecto = ? AND tev.activa')
return $this->connection->execute($query, [$proyecto_id])->fetchAll(PDO::FETCH_ASSOC); ->group('a.id');
return $this->fetchIds($query, [$proyecto_id]);
} }
public function fetchActivaByProyecto(int $proyecto_id): array public function fetchActivaByProyecto(int $proyecto_id): array
{ {
$query = "SELECT a.* $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('a.*')
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` ->from("{$this->getTable()} a")
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1 ->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` ->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1')
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` ->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` ->joined("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`")
WHERE ptu.`proyecto` = ? AND tev.`activa` ->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
GROUP BY a.`id`"; ->where('ptu.`proyecto` = ? AND tev.`activa`')
->group('a.id');
return $this->fetchMany($query, [$proyecto_id]); return $this->fetchMany($query, [$proyecto_id]);
} }
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
{ {
$query = "SELECT a.* $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select("a.*")
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` ->from("`{$this->getTable()}` a")
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1 ->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` ->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1')
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto` ->joined('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` ->joined('JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`')
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` ->joined("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`")
WHERE `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`"; ->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
->where('`proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`');
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]); return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
} }
public function fetchByPie(int $pie_id): Model\Venta public function fetchByPie(int $pie_id): Model\Venta
{ {
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pie` = ?"; $query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('pie = ?');
return $this->fetchOne($query, [$pie_id]); return $this->fetchOne($query, [$pie_id]);
} }
public function fetchIdByPie(int $pie_id): array
{
$query = $this->connection->getQueryBuilder()
->select('id')
->from($this->getTable())
->where('pie = ?');
return $this->fetchId($query, [$pie_id]);
}
public function fetchByUnidad(string $unidad, string $tipo): array public function fetchByUnidad(string $unidad, string $tipo): array
{ {
$query = "SELECT a.* $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('a.*')
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` ->from("{$this->getTable()} a")
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` ->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` ->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` ->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?"; ->joined('JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`')
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
return $this->fetchMany($query, [$unidad, $tipo]); return $this->fetchMany($query, [$unidad, $tipo]);
} }
public function fetchIdsByUnidad(string $unidad, string $tipo): array public function fetchIdsByUnidad(string $unidad, string $tipo): array
{ {
$query = "SELECT a.id $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('a.id')
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` ->from("{$this->getTable()} a")
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` ->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` ->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo` ->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?"; ->joined('JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`')
return $this->connection->execute($query, [$unidad, $tipo])->fetchAll(PDO::FETCH_ASSOC); ->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
return $this->fetchIds($query, [$unidad, $tipo]);
} }
public function fetchByPrecio(string $precio): array public function fetchByPrecio(string $precio): array
{ {
$query = "SELECT * FROM `{$this->getTable()}` WHERE `valor_uf` = ?"; $query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor_uf = ?');
return $this->fetchMany($query, [$precio]); return $this->fetchMany($query, [$precio]);
} }
public function fetchIdsByPrecio(string $precio): array public function fetchIdsByPrecio(string $precio): array
{ {
$query = "SELECT `id` FROM `{$this->getTable()}` WHERE `valor_uf` = ?"; $query = $this->connection->getQueryBuilder()
return $this->connection->execute($query, [$precio])->fetchAll(PDO::FETCH_ASSOC); ->select('id')
->from($this->getTable())
->where('valor_uf = ?');
return $this->fetchIds($query, [$precio]);
}
public function fetchByPropietarioAndPropiedad(int $propietario_rut, int $propiedad_id): Model\Venta
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('propietario = ? AND propiedad = ?');
return $this->fetchOne($query, [$propietario_rut, $propiedad_id]);
} }
public function fetchByPropietario(string $propietario): array public function fetchByPropietario(string $propietario): array
{ {
$query = "SELECT a.* $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('a.*')
JOIN `propietario` ON `propietario`.`rut` = a.`propietario` ->from("{$this->getTable()} a")
WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario ->joined('JOIN `propietario` ON `propietario`.`rut` = a.`propietario`')
->where("CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario
OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario"; OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario");
return $this->fetchMany($query, [':propietario' => "%{$propietario}%"]); return $this->fetchMany($query, [':propietario' => "%{$propietario}%"]);
} }
public function fetchIdsByPropietario(string $propietario): array public function fetchIdsByPropietario(string $propietario): array
{ {
$query = "SELECT a.id $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('a.id')
JOIN `propietario` ON `propietario`.`rut` = a.`propietario` ->from("{$this->getTable()} a")
WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario ->joined('JOIN `propietario` ON `propietario`.`rut` = a.`propietario`')
->where("CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario
OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario"; OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario");
return $this->connection->execute($query, [':propietario' => "%{$propietario}%"])->fetchAll(PDO::FETCH_ASSOC); return $this->fetchIds($query, [':propietario' => "%{$propietario}%"]);
} }
public function fetchByPropietarioNombreCompleto(string $propietario): array public function fetchByPropietarioNombreCompleto(string $propietario): array
{ {
$query = "SELECT a.* $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('a.*')
JOIN `propietario` ON `propietario`.`rut` = a.`propietario` ->from("{$this->getTable()} a")
WHERE CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?"; ->joined('JOIN `propietario` ON `propietario`.`rut` = a.`propietario`')
->where("CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?");
return $this->fetchMany($query, [$propietario]); return $this->fetchMany($query, [$propietario]);
} }
public function fetchEscriturasByProyecto(int $proyecto_id): array public function fetchEscriturasByProyecto(int $proyecto_id): array
{ {
$query = "SELECT DISTINCT a.* $query = $this->connection->getQueryBuilder()
FROM `{$this->getTable()}` a ->select('DISTINCT a.*')
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad` ->from("{$this->getTable()} a")
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` ->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id` ->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
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` ->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id`')
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` ->joined("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`")
WHERE ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando') ->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
GROUP BY a.`id`"; ->where("ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando')")
->group('a.id');
return $this->fetchMany($query, [$proyecto_id]); return $this->fetchMany($query, [$proyecto_id]);
} }
public function fetchIdByEscritura(int $escritura_id): array
{
$query = $this->connection->getQueryBuilder()
->select('id')
->from($this->getTable())
->where('escritura = ?');
return $this->fetchId($query, [$escritura_id]);
}
public function fetchIdBySubsidio(int $subsidio_id): array
{
$query = $this->connection->getQueryBuilder()
->select('id')
->from($this->getTable())
->where('subsidio = ?');
return $this->fetchId($query, [$subsidio_id]);
}
public function fetchIdByCredito(int $credito_id): array
{
$query = $this->connection->getQueryBuilder()
->select('id')
->from($this->getTable())
->where('credito = ?');
return $this->fetchId($query, [$credito_id]);
}
public function fetchIdByBono(int $bono_id): array
{
$query = $this->connection->getQueryBuilder()
->select('id')
->from($this->getTable())
->where('bono_pie = ?');
return $this->fetchId($query, [$bono_id]);
}
protected function fetchIds(string $query, ?array $data = null): array
{
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
if ($results === false) {
throw new Implement\Exception\EmptyResult($query);
}
return $results;
}
protected function fetchId(string $query, ?array $data = null): array
{
$results = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
if ($results === false) {
throw new Implement\Exception\EmptyResult($query);
}
return $results;
}
} }

View File

@ -35,4 +35,21 @@ class BonoPie extends Ideal\Repository
{ {
return $this->update($model, ['valor', 'pago'], $new_data); return $this->update($model, ['valor', 'pago'], $new_data);
} }
public function fetchByValue(float $value): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor = ?');
return $this->fetchMany($query, [$value]);
}
public function fetchByPago(int $pago_id): Model\Venta\BonoPie
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
} }

View File

@ -36,4 +36,21 @@ class Credito extends Ideal\Repository
{ {
return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data); return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
} }
public function fetchByValue(int $value): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor = ?');
return $this->fetchMany($query, [$value]);
}
public function fetchByPago(int $pago_id): Model\Venta\Credito
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
} }

View File

@ -182,7 +182,8 @@ ORDER BY p1.`fecha`, v1.`descripcion`";
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()
->select() ->select()
->from($this->getTable()) ->from($this->getTable())
->where('pie = ?'); ->where('pie = ?')
->group('id');
return $this->fetchMany($query, [$pie_id]); return $this->fetchMany($query, [$pie_id]);
} }
public function fetchVigenteByPie(int $pie_id): array public function fetchVigenteByPie(int $pie_id): array
@ -192,7 +193,16 @@ FROM `{$this->getTable()}` a
JOIN `pago` ON `pago`.`id` = a.`pago` JOIN `pago` ON `pago`.`id` = a.`pago`
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id` JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado` JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
WHERE a.`pie` = ? AND tep.`active` = 1"; WHERE a.`pie` = ? AND tep.`active` = 1
GROUP BY a.`id`";
return $this->fetchMany($query, [$pie_id]); return $this->fetchMany($query, [$pie_id]);
} }
public function fetchByPago(int $pago_id): Model\Venta\Cuota
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
} }

View File

@ -38,4 +38,21 @@ class Escritura extends Ideal\Repository
{ {
return $this->update($model, ['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data); return $this->update($model, ['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
} }
public function fetchByValue(int $value): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor = ?');
return $this->fetchMany($query, [$value]);
}
public function fetchByPago(int $pago_id): Model\Venta\Escritura
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
} }

View File

@ -100,4 +100,12 @@ FROM (
WHERE venta_id = ?"; WHERE venta_id = ?";
return $this->fetchMany($query, [$venta_id]); return $this->fetchMany($query, [$venta_id]);
} }
public function fetchByValue(int $value): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor = ? OR ROUND(valor/uf, 3) = ?');
return $this->fetchMany($query, [$value, $value]);
}
} }

View File

@ -56,4 +56,20 @@ class Pie extends Ideal\Repository
->where('asociado = ?'); ->where('asociado = ?');
return $this->fetchMany($query, [$pie_id]); return $this->fetchMany($query, [$pie_id]);
} }
public function fetchByValue(float $value): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor = ?');
return $this->fetchMany($query, [$value]);
}
public function fetchByReajuste(int $reajuste_id): Model\Venta\Pie
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('reajuste = ?');
return $this->fetchOne($query, [$reajuste_id]);
}
} }

View File

@ -40,4 +40,13 @@ class Subsidio extends Ideal\Repository
{ {
return $this->update($model, ['pago', 'subsidio'], $new_data); return $this->update($model, ['pago', 'subsidio'], $new_data);
} }
public function fetchByPago(int $pago_id): Model\Venta\Subsidio
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('subsidio = ? OR pago = ?');
return $this->fetchOne($query, [$pago_id, $pago_id]);
}
} }

View File

@ -0,0 +1,29 @@
<?php
namespace Incoviba\Service;
use DateTimeInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileInterface;
use Incoviba\Common\Define\Cartola\Banco;
use Incoviba\Common\Define\Contabilidad\Exporter;
use Incoviba\Model;
class Cartola
{
public function __construct(protected StreamFactoryInterface $streamFactory, protected Exporter $exporter) {}
protected array $bancos;
public function register(string $name, Banco $banco): Cartola
{
$this->bancos[$name] = $banco;
return $this;
}
public function process(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, UploadedFileInterface $file): array
{
return $this->bancos[strtolower($banco->nombre)]->process($file);
}
public function export(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, array $movimientos): string
{
return $this->exporter->export($inmobiliaria, $banco, $mes, $movimientos);
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace Incoviba\Service\Cartola;
use DateTimeImmutable;
use Psr\Http\Message\UploadedFileInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Ideal\Cartola\Banco;
class Itau extends Banco
{
protected function columnMap(): array
{
return [
'Fecha' => 'fecha',
'Número de operación' => 'documento',
'Descripción' => 'glosa',
'Depósitos o abonos' => 'abono',
'Giros o cargos' => 'cargo'
];
}
protected function parseFile(UploadedFileInterface $uploadedFile): array
{
$filename = '/tmp/cartola.xls';
$uploadedFile->moveTo($filename);
$reader = PhpSpreadsheet\IOFactory::createReader('Xls');
$xlsx = $reader->load($filename);
$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 = [];
$rows = $sheet->getRowIterator($rowIndex);
foreach ($rows as $row) {
if ($sheet->getCell("A{$rowIndex}")->getCalculatedValue() === null) {
break;
}
$cols = $row->getColumnIterator('A', 'G');
$colIndex = 0;
$rowData = [];
foreach ($cols as $col) {
$value = $col->getCalculatedValue();
$col = $columns[$colIndex];
if ($col === 'Fecha') {
list($d, $m) = explode('/', $value);
$value = "{$year}-{$m}-{$d}";
}
$rowData[$col] = $value;
$colIndex ++;
}
$data []= $rowData;
$rowIndex ++;
}
unlink($filename);
return $data;
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace Incoviba\Service\Cartola;
use DateTimeImmutable;
use Psr\Http\Message\UploadedFileInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Ideal\Cartola\Banco;
class Santander extends Banco
{
protected function columnMap(): array
{
// MONTO DESCRIPCIÓN MOVIMIENTO FECHA N° DOCUMENTO SUCURSAL CARGO/ABONO
return [
'cargo' => 'cargo',
'abono' => 'abono',
'DESCRIPCIÓN MOVIMIENTO' => 'glosa',
'FECHA' => 'fecha',
'N° DOCUMENTO' => 'documento',
];
}
protected function parseFile(UploadedFileInterface $uploadedFile): array
{
$filename = '/tmp/cartola.xlsx';
$uploadedFile->moveTo($filename);
$reader = PhpSpreadsheet\IOFactory::createReader('Xlsx');
$xlsx = $reader->load($filename);
$sheet = $xlsx->getActiveSheet();
$rowIndex = 16;
$columns = [];
$row = $sheet->getRowIterator($rowIndex)->current();
$cols = $row->getColumnIterator('A', 'H');
foreach ($cols as $col) {
$columns []= $col->getCalculatedValue();
}
$rowIndex ++;
$rows = $sheet->getRowIterator($rowIndex);
$data = [];
foreach ($rows as $row) {
if ($sheet->getCell("A{$rowIndex}")->getCalculatedValue() === 'Resumen comisiones') {
break;
}
$cols = $row->getColumnIterator('A', 'H');
$colIndex = 0;
$rowData = [];
foreach ($cols as $col) {
$value = $col->getCalculatedValue();
$col = $columns[$colIndex];
if ($col === 'FECHA') {
list($d,$m,$Y) = explode('/', $value);
$value = "{$Y}-{$m}-{$d}";
}
$rowData[$col] = $value;
$colIndex ++;
}
if ($rowData['CARGO/ABONO'] === 'C') {
$rowData['cargo'] = -$rowData['MONTO'];
$rowData['abono'] = 0;
} else {
$rowData['cargo'] = 0;
$rowData['abono'] = $rowData['MONTO'];
}
$data []= $rowData;
$rowIndex ++;
}
return $data;
}
}

View File

@ -0,0 +1,116 @@
<?php
namespace Incoviba\Service\Cartola;
use DOMDocument;
use DateTimeImmutable;
use Psr\Http\Message\UploadedFileInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Ideal\Cartola\Banco;
class Security extends Banco
{
protected function parseFile(UploadedFileInterface $uploadedFile): array
{
$stream = $uploadedFile->getStream();
$stream->seek(3);
if ($stream->read(strlen('table')) === 'table') {
return $this->processHtm($uploadedFile);
}
return $this->processXls($uploadedFile);
}
protected function columnMap(): array
{
return [
'fecha' => 'fecha',
'descripción' => 'glosa',
'número de documentos' => 'documento',
'cargos' => 'cargo',
'abonos' => 'abono'
];
}
private function processXls(UploadedFileInterface $file): array
{
$filename = '/tmp/cartola.xls';
$file->moveTo($filename);
$reader = PhpSpreadsheet\IOFactory::createReader('Xls');
$xlsx = $reader->load($filename);
$worksheet = $xlsx->getActiveSheet();
$rows = $worksheet->getRowIterator();
$dataFound = false;
$columns = [];
$data = [];
foreach ($rows as $row) {
$cells = $row->getCellIterator();
$rowData = [];
foreach ($cells as $cell) {
if ($cell->getColumn() === 'A' and $cell->getCalculatedValue() === "fecha ") {
$cols = $row->getColumnIterator();
foreach ($cols as $col) {
$columns[$col->getColumn()] = trim($col->getCalculatedValue());
}
$dataFound = true;
break;
}
if ($cell->getColumn() === 'A' and $cell->getCalculatedValue() === null) {
$dataFound = false;
break;
}
if (!$dataFound) {
break;
}
$col = $columns[$cell->getColumn()];
$value = $cell->getCalculatedValue();
if ($col === 'fecha') {
$value = PhpSpreadsheet\Shared\Date::excelToDateTimeObject($cell->getValue(), 'America/Santiago')->format('Y-m-d');
}
$rowData[$col] = $value;
}
if (count($rowData) > 0) {
$data []= $rowData;
}
}
unlink($filename);
return $data;
}
private function processHtm(UploadedFileInterface $file): array
{
$filename = '/tmp/cartola.htm';
$file->moveTo($filename);
$domDocument = new DOMDocument();
$domDocument->loadHTML('<body>' . file_get_contents($filename) . '</body>');
$tables = $domDocument->getElementsByTagName('table');
$table = $tables->item(4);
$columns = [];
$data = [];
foreach ($table->getElementsByTagName('tr')->getIterator() as $rowIndex => $row) {
if ($rowIndex === 0) {
continue;
}
if (str_contains($row->textContent, 'cargos')) {
foreach ($row->getElementsByTagName('td')->getIterator() as $cell) {
$columns []= trim($cell->textContent);
}
continue;
}
$rowData = [];
foreach ($row->getElementsByTagName('td')->getIterator() as $colIndex => $cell) {
$col = $columns[$colIndex];
$value = trim($cell->textContent);
if ($col === 'fecha') {
$value = DateTimeImmutable::createFromFormat('d/m/Y', $value)->format('Y-m-d');
}
if (in_array($col, ['cargos', 'abonos', 'saldos'])) {
$value = (float) str_replace(',', '.', $value);
}
$rowData[$col] = $value;
}
$data []= $rowData;
}
return $data;
}
}

View File

@ -0,0 +1,115 @@
<?php
namespace Incoviba\Service\Contabilidad\Exporter;
use DateTimeImmutable;
use DateTimeInterface;
use Incoviba\Common\Define\Contabilidad\Exporter;
use Incoviba\Model;
use Incoviba\Repository;
use PhpOffice\PhpSpreadsheet;
class Nubox implements Exporter
{
public function __construct(protected Repository\CentroCosto $centroCostoRepository, protected string $uploadFolder) {}
public function export(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, array $movimientos): string
{
PhpSpreadsheet\Settings::setLocale('es-CL');
$workbook = new PhpSpreadsheet\Spreadsheet();
$sheet = $workbook->getActiveSheet();
$rowIndex = $this->buildHeaders($sheet);
foreach ($movimientos as $movimiento) {
$tipoCentro = '';
$cuenta = '';
$centro = '';
if ($movimiento->centro_costo !== '') {
$centroCosto = $this->centroCostoRepository->fetchById($movimiento->centro_costo);
$tipoCentro = substr($centroCosto->tipoCentro->descripcion, 0, 1);
$cuenta = $centroCosto->cuentaContable;
$centro = $centroCosto->id;
}
$fecha = (new DateTimeImmutable($movimiento->fecha))->format('d/m/Y');
$rowIndex = $this->add($sheet, [
'Número' => '0',
'Tipo' => $tipoCentro,
'Fecha' => $fecha,
'Glosa' => $movimiento->detalle,
'Cuenta Detalle' => $cuenta,
'Glosa Detalle' => '',
'Centro Costo' => $centro,
'Sucursal' => '',
'Debe' => $movimiento->abono === 0 ? '' : $movimiento->abono,
'Haber' => $movimiento->cargo === 0 ? '' : $movimiento->cargo,
'Tipo Auxiliar' => 'B',
'A: Rut Cliente-Proveedor/H: Rut Prestador' => '',
'A: Razon Social/B: Descripción Movimiento Bancario/ H: Nombre Prestador' => $movimiento->glosa,
'A: Tipo De Documento/H: Tipo De Boleta Honorario' => '',
'A: Folio /B: Numero Documento/H: Folio Boleta' => $movimiento->documento,
'A/B/H: Monto' => ($movimiento->abono === 0) ? $movimiento->cargo : $movimiento->abono,
'A: Fecha Vencimiento /B: Fecha /H: Fecha Emisión (DD/MM/AAAA)' => $fecha
], $rowIndex);
}
$sheet->getStyle("I1:J{$rowIndex}")->getNumberFormat()
->setFormatCode('#,##0');
$sheet->getStyle("O1:O{$rowIndex}")->getNumberFormat()
->setFormatCode('##0');
$sheet->getStyle("P1:P{$rowIndex}")->getNumberFormat()
->setFormatCode('#,##0');
foreach (range('A', 'Q') as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
$sheet->getSheetView()->setZoomScale(90);
$writer = PhpSpreadsheet\IOFactory::createWriter($workbook, 'Xlsx');
$filename = "Cartola {$banco->nombre} - {$inmobiliaria->abreviacion} - {$mes->format('M Y')}.xlsx";
$writer->save(implode(DIRECTORY_SEPARATOR, [
$this->uploadFolder,
$filename
]));
return $filename;
}
protected function getHeaders(): array
{
return [
'Número',
'Tipo',
'Fecha',
'Glosa',
'Cuenta Detalle',
'Glosa Detalle',
'Centro Costo',
'Sucursal',
'Debe',
'Haber',
'Tipo Auxiliar',
'A: Rut Cliente-Proveedor/H: Rut Prestador',
'A: Razon Social/B: Descripción Movimiento Bancario/ H: Nombre Prestador',
'A: Tipo De Documento/H: Tipo De Boleta Honorario',
'A: Folio /B: Numero Documento/H: Folio Boleta',
'A/B/H: Monto',
'A: Fecha Vencimiento /B: Fecha /H: Fecha Emisión (DD/MM/AAAA)'
];
}
protected function buildHeaders(PhpSpreadsheet\Worksheet\Worksheet &$sheet, int $rowIndex = 1): int
{
$map = $this->getHeaders();
foreach ($map as $index => $header) {
$columnIndex = $index + 1;
$sheet->getCell([$columnIndex, $rowIndex])->setValue($header);
}
return $rowIndex + 1;
}
protected function add(PhpSpreadsheet\Worksheet\Worksheet &$sheet, array $row, int $rowIndex): int
{
$headers = $this->getHeaders();
foreach ($headers as $index => $header) {
$columnIndex = $index + 1;
$sheet->getCell([$columnIndex, $rowIndex])->setValue($row[$header]);
$sheet->getCell([$columnIndex, $rowIndex + 1])->setValue(($header === 'Tipo Auxiliar') ? 'A' : '');
}
return $rowIndex + 2;
}
}

Some files were not shown because too many files have changed in this diff Show More