11 Commits

Author SHA1 Message Date
6ddc48ec60 Merge branch 'develop' 2024-03-13 16:31:34 -03:00
8caa80459e Accelerar listado ventas 2024-03-13 16:17:14 -03:00
98953cce42 FormaPago Service 2024-03-13 14:38:44 -03:00
c7dd309185 Movimiento + Detalles 2024-03-04 19:55:49 -03:00
48bfe5d8ab Mejora en velocidad de busqueda 2024-02-28 21:44:37 -03:00
d9b5bc6507 Procesar otras cartolas Santander 2024-02-28 17:02:04 -03:00
21d1ef653f FIX: Saldo actual informe tesoreria 2024-02-28 13:53:53 -03:00
331ee1e584 Merge branch 'develop' 2023-06-22 23:18:13 -04:00
24c17debf3 Merge branch 'develop' 2023-02-15 18:30:09 -03:00
552fd0aa06 Merge branch 'develop' 2023-02-14 20:50:42 -03:00
60faf293d4 Merge branch 'develop' 2023-02-13 17:18:41 -03:00
42 changed files with 1011 additions and 172 deletions

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\API\Contabilidad\Movimientos;
$app->group('/movimiento/{movimiento_id}', function($app) {
$app->post('/detalles', [Movimientos::class, 'detalles']);
});

View File

@ -1,4 +1,12 @@
<?php
use Incoviba\Controller\API\Search;
$app->post('/search', [Search::class, 'query']);
$app->group('/search', function($app) {
$app->group('/ventas', function($app) {
$app->post('/unidades', [Search::class, 'unidades']);
$app->get('/unidad/{unidad_id}', [Search::class, 'unidad']);
$app->post('[/]', [Search::class, 'ventas']);
});
$app->get('/venta/{venta_id}', [Search::class, 'venta']);
$app->post('[/]', [Search::class, 'query']);
});

View File

@ -22,6 +22,7 @@ $app->group('/ventas', function($app) {
$app->group('/by', function($app) {
$app->get('/unidad/{unidad_id}', [Ventas::class, 'unidad']);
});
$app->post('/get[/]', [Ventas::class, 'getMany']);
$app->post('[/]', [Ventas::class, 'proyecto']);
});
$app->group('/venta/{venta_id}', function($app) {

View File

@ -52,6 +52,8 @@
<th class="right aligned">Cargo</th>
<th class="right aligned">Abono</th>
<th class="right aligned">Saldo</th>
<th>Centro de Costo</th>
<th>Detalle</th>
<th>Orden</th>
</tr>
</thead>
@ -185,6 +187,46 @@
}
}
}
update() {
return {
centro: (idx, centro_id) => {
const id = this.movimientos[idx].id
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
const body = new FormData()
body.set('centro_id', centro_id)
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (!json.status) {
return
}
const dropdown = $(".dropdown[data-idx='" + idx + "']")
dropdown.dropdown('set selected', json.centro.id, true)
})
})
},
detalle: (idx, detalle) => {
const id = this.movimientos[idx].id
const url = '{{$urls->api}}/contabilidad/movimiento/' + id + '/detalles'
const body = new FormData()
body.set('detalle', detalle)
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (!json.status) {
return
}
const input = $("input[data-idx='" + idx + "']")
input.val(json.detalle)
})
})
}
}
}
draw() {
return {
form: ($form, inmobiliarias, first = false) => {
@ -339,25 +381,73 @@
this.movimientos.forEach((row, idx) => {
$tbody.append(
$('<tr></tr>').append(
$('<td></td>').html(this.inmobiliaria.razon)
'<td>' + this.inmobiliaria.razon + '</td>' + "\n"
+ '<td>' + this.cuenta.descripcion + '</td>' + "\n"
+ '<td>' + dateFormatter.format(row.fecha) + '</td>' + "\n"
+ '<td>' + row.glosa + '</td>' + "\n"
+ '<td class="right aligned">' + (row.cargo === 0 ? '' : numberFormatter.format(row.cargo)) + '</td>' + "\n"
+ '<td class="right aligned">' + (row.abono === 0 ? '' : numberFormatter.format(row.abono)) + '</td>' + "\n"
+ '<td class="right aligned">' + (row.saldo === 0 ? '' : numberFormatter.format(row.saldo)) + '</td>' + "\n"
).append(
$('<td></td>').html(this.cuenta.descripcion)
$('<td></td>').append(
this.draw().centroCosto(idx)
)
).append(
$('<td></td>').html(dateFormatter.format(row.fecha))
).append(
$('<td></td>').html(row.glosa)
).append(
$('<td></td>').addClass('right aligned').html(row.cargo === 0 ? '' : numberFormatter.format(row.cargo))
).append(
$('<td></td>').addClass('right aligned').html(row.abono === 0 ? '' : numberFormatter.format(row.abono))
).append(
$('<td></td>').addClass('right aligned').html(row.saldo === 0 ? '' : numberFormatter.format(row.saldo))
$('<td></td>').append(
this.draw().detalle(idx)
)
).append(
$('<td></td>').html(idx + 1)
)
)
})
},
centroCosto: idx => {
const centros = JSON.parse('{!! json_encode($centrosCostos) !!}')
const menu = $('<div></div>').addClass('menu')
centros.forEach(centro => {
menu.append(
'<div class="item" data-value="' + centro.id + '">'
+ centro.id + ' - ' + centro.descripcion
+ '</div>'
)
})
const dropdown = $('<div></div>').addClass('ui search selection dropdown').attr('data-idx', idx).html(
'<input type="hidden" name="centro" />' + "\n" +
'<i class="dropdown icon"></i>' + "\n" +
'<div class="default text">Centro de Costo</div>' + "\n"
).append(menu)
dropdown.dropdown({
onChange: (value, text, $element) => {
const idx = $element.parent().parent().data('idx')
this.update().centro(idx, value)
}
})
if (this.movimientos[idx].centro !== '') {
const cid = centros.findIndex(centro => centro.descripcion === this.movimientos[idx].centro)
dropdown.dropdown('set selected', centros[cid].id, true)
}
return dropdown
},
detalle: idx => {
const detalle = document.createElement('input')
detalle.type = 'text'
detalle.name = 'detalle' + idx
detalle.placeholder = 'Detalle'
detalle.setAttribute('data-idx', idx)
const input = document.createElement('div')
input.className = 'ui input'
input.appendChild(detalle)
if (this.movimientos[idx].detalle !== '') {
detalle.value = this.movimientos[idx].detalle
}
detalle.addEventListener('blur', event => {
const idx = event.currentTarget.dataset['idx']
this.update().detalle(idx, event.currentTarget.value)
})
return $(input)
}
}
}
}
@ -370,6 +460,8 @@
'cargo',
'abono',
'saldo',
'centro',
'detalle',
'orden'
];
@endphp
@ -388,7 +480,7 @@
width: '{{round((1/(count($columns) + 3 - 1)) * 100,2)}}%'
},
{
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['sociedad', 'cuenta', 'glosa']);})))}}],
targets: [{{implode(',', array_keys(array_filter($columns, function($column) {return in_array($column, ['sociedad', 'cuenta', 'glosa', 'centro', 'detalle']);})))}}],
width: '{{round((1/(count($columns) + 3 - 1)) * 2 * 100, 2)}}%'
},
{
@ -506,12 +598,15 @@
const fecha = new Date(row.fecha)
fecha.setDate(fecha.getDate() + 1)
this.data.cartolas[cartolaIdx].movimientos[idx] = {
id: row.id,
fecha: fecha,
glosa: row.glosa,
documento: row.documento,
cargo: row.cargo,
abono: row.abono,
saldo: row.saldo
saldo: row.saldo,
centro: row.detalles?.centro_costo.descripcion ?? '',
detalle: row.detalles?.detalle ?? ''
}
})
const ayer = new Date(this.data.cartolas[cartolaIdx].fecha.getTime())
@ -629,41 +724,31 @@
movimiento: idx => {
$(this.ids.movimientos).append(
$('<div></div>').addClass('fields').attr('data-movimiento', idx).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Glosa')
).append(
$('<input />').attr('type', 'text').attr('name', 'glosa' + idx)
)
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Cargo')
).append(
$('<div></div>').addClass('ui left labeled input').append(
$('<div></div>').addClass('ui basic label').html('$')
).append(
$('<input />').attr('type', 'text').attr('name', 'cargo' + idx)
)
)
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Abono')
).append(
$('<div></div>').addClass('ui left labeled input').append(
$('<div></div>').addClass('ui basic label').html('$')
).append(
$('<input />').attr('type', 'text').attr('name', 'abono' + idx)
)
)
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Saldo')
).append(
$('<div></div>').addClass('ui left labeled input').append(
$('<div></div>').addClass('ui basic label').html('$')
).append(
$('<input />').attr('type', 'text').attr('name', 'saldo' + idx)
)
)
'<div class="field">' + "\n"
+ '<label>Glosa</label>' + "\n"
+ '<input type="text" name="glosa' + idx + '" />' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Cargo</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="cargo' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Abono</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="abono' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>' + "\n" +
'<div class="field">' + "\n"
+ '<label>Saldo</label>' + "\n"
+ '<div class="ui left labeled input">' + "\n"
+ '<div class="ui basic label">$</div>' + "\n"
+ '<input type="text" name="saldo' + idx + '" />' + "\n"
+ '</div>' + "\n"
+ '</div>'
).append(
$('<div></div>').addClass('field').append(
$('<label></label>').html('Eliminar')

View File

@ -96,6 +96,10 @@
id: '',
data: [],
table: null,
queues: {
unidades: [],
ventas: []
},
get: function() {
return {
results: () => {
@ -122,34 +126,33 @@
}
const progress = this.draw().progress(data.results.length)
const promises = []
data.results.forEach(row => {
if (row.tipo === 'venta') {
return promises.push(this.get().venta(row.id).then(json => {
if (json.venta === null) {
console.debug(json)
return
}
const venta = json.venta
this.queues.ventas = data.results.filter(row => row.tipo === 'venta').map(row => row.id)
this.queues.unidades = data.results.filter(row => row.tipo !== 'venta').map(row => row.id)
promises.push(this.get().ventas().then(arrays => {
arrays.forEach(json => {
if (json.ventas.length === 0) {
console.debug(json)
return
}
json.ventas.forEach(venta => {
progress.progress('increment')
const r = new Row({unidad: venta.propiedad.unidades[0], proyecto: venta.proyecto})
r.venta = venta
this.data.push(r)
}).catch(error => {
})
})
}))
promises.push(this.get().unidades().then(arrays => {
arrays.forEach(json => {
if (json.unidades.length === 0) {
return
}
json.unidades.forEach(unidad => {
progress.progress('increment')
console.error(row)
console.error(error)
}))
}
promises.push(this.get().unidad(row.id).then(json => {
const unidad = json.unidad
progress.progress('increment')
this.data.push(new Row({unidad: unidad, proyecto: unidad.proyecto_tipo_unidad.proyecto}))
}).catch(error => {
progress.progress('increment')
console.error(row)
console.error(error)
}))
})
this.data.push(new Row({unidad: unidad, proyecto: unidad.proyecto_tipo_unidad.proyecto}))
})
})
}))
Promise.all(promises).then(() => {
this.sort()
this.draw().clear()
@ -157,22 +160,43 @@
})
})
},
unidad: id => {
const url = '{{$urls->api}}/ventas/unidad/' + id
return fetchAPI(url).then(response => {
if (response.ok) {
unidades: () => {
const url = '{{$urls->api}}/search/ventas/unidades'
const chunks = []
for (let i = 0; i < this.queues.unidades.length; i += 100) {
chunks.push(this.queues.unidades.slice(i, i + 100))
}
const promises = []
chunks.forEach(ids => {
const body = new FormData()
body.set('unidades', ids)
promises.push(fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json()
}
}))
})
return Promise.all(promises)
},
venta: id => {
const url = '{{$urls->api}}/venta/' + id
return fetchAPI(url).then(response => {
if (!response) {
return
}
return response.json()
ventas: () => {
const url = '{{$urls->api}}/search/ventas'
const chunks = []
for (let i = 0; i < this.queues.ventas.length; i += 100) {
chunks.push(this.queues.ventas.slice(i, i + 100))
}
const promises = []
chunks.forEach(ids => {
const body = new FormData()
body.set('ventas', ids)
promises.push(fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json()
}))
})
return Promise.all(promises)
}
}
},

View File

@ -116,10 +116,15 @@
this.data.id = data.proyecto.id
this.data.proyecto = data.proyecto.descripcion
this.data.venta_ids = data.ventas
const chunkSize = 50
const chunks = []
for (let i = 0; i < data.ventas.length; i += chunkSize) {
chunks.push(data.ventas.splice(i, i + chunkSize))
}
const promises = []
data.ventas.forEach(venta_id => {
const promise = this.get().venta(venta_id).then(() => {
progress.progress('increment')
chunks.forEach(chunk => {
const promise = this.get().venta(chunk).then(count => {
progress.progress('increment', count)
})
promises.push(promise)
})
@ -129,17 +134,22 @@
}
})
},
venta: venta_id => {
return fetchAPI('{{$urls->api}}/venta/' + venta_id).then(response => {
venta: chunk => {
const body = new FormData()
body.set('ventas', chunk.join(','))
return fetchAPI('{{$urls->api}}/ventas/get', {method: 'post', body}).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
if (typeof data.venta === 'undefined') {
console.error(venta_id, data.error)
if (data.ventas.length === 0) {
console.error(chunk, data.error)
return
}
this.add().venta(data.venta)
data.ventas.forEach(venta_id => {
this.add().venta(venta_id)
})
return data.ventas.length
})
}
}

View File

@ -32,46 +32,3 @@ $showPropietario = true;
@include('ventas.show.comentarios')
</div>
@endsection
{{--@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
{{$venta->propiedad()->summary()}}
</div>
</h1>
<div class="right floated column">
@include('ventas.show.propietario')
</div>
</div>
<br />
<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>
</div>
@endsection--}}

View File

@ -3,14 +3,14 @@
</div>
<div class="ui segment">
<table class="ui very basic fluid table">
@include('ventas.show.forma_pago.pie', ['pie' => $formaPago->pie])
@include('ventas.show.forma_pago.escritura', ['escritura' => $formaPago->escritura])
@include('ventas.show.forma_pago.anticipo', ['anticipo' => ['uf' => $formaPago->anticipo(), 'pesos' => $formaPago->anticipo('pesos')]])
@include('ventas.show.forma_pago.bono_pie', ['bonoPie' => $formaPago->bonoPie])
@include('ventas.show.forma_pago.subsidio', ['subsidio' => $formaPago->subsidio])
@include('ventas.show.forma_pago.credito', ['credito' => $formaPago->credito])
@include('ventas.show.forma_pago.pie', ['pie' => $formaPago?->pie])
@include('ventas.show.forma_pago.escritura', ['escritura' => $formaPago?->escritura])
@include('ventas.show.forma_pago.anticipo', ['anticipo' => ['uf' => $formaPago?->anticipo(), 'pesos' => $formaPago?->anticipo('pesos')]])
@include('ventas.show.forma_pago.bono_pie', ['bonoPie' => $formaPago?->bonoPie])
@include('ventas.show.forma_pago.subsidio', ['subsidio' => $formaPago?->subsidio])
@include('ventas.show.forma_pago.credito', ['credito' => $formaPago?->credito])
@include('ventas.show.forma_pago.total')
@include('ventas.show.forma_pago.devolucion', ['devolucion' => $formaPago->devolucion])
@include('ventas.show.forma_pago.devolucion', ['devolucion' => $formaPago?->devolucion])
</table>
</div>
<div id="pago_modal" class="ui modal">

View File

@ -40,6 +40,7 @@ return [
$container->get(Incoviba\Repository\Inmobiliaria::class),
$container->get(Incoviba\Repository\Inmobiliaria\Cuenta::class),
$container->get(Incoviba\Repository\Movimiento::class),
$container->get(Incoviba\Service\Movimiento::class),
$container->get(Incoviba\Repository\Cartola::class)
))
->register('security', $container->get(Incoviba\Service\Cartola\Security::class))

View File

@ -0,0 +1,50 @@
<?php
namespace Incoviba\Controller\API\Contabilidad;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\withJson;
use Incoviba\Common\Ideal;
use Incoviba\Repository;
use Incoviba\Service;
class Movimientos extends Ideal\Controller
{
use withJson;
public function detalles(ServerRequestInterface $request, ResponseInterface $response,
Service\Movimiento $movimientoService,
Repository\CentroCosto $centroCostoRepository, int $movimiento_id): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'movimiento_id' => $movimiento_id,
'input' => $body,
'status' => false,
'movimiento' => null,
'centro' => null,
'detalle' => ''
];
try {
$movimiento = $movimientoService->getById($movimiento_id);
$output['movimiento'] = $movimiento;
$data = [];
if (isset($body['centro_id'])) {
$centro = $centroCostoRepository->fetchById($body['centro_id']);
$data['centro_costo_id'] = $centro->id;
}
if (isset($body['detalle'])) {
$data['detalle'] = $body['detalle'];
}
$movimientoService->setDetalles($movimiento, $data);
if (isset($body['centro_id'])) {
$output['centro'] = $centro;
}
if (isset($body['detalle'])) {
$output['detalle'] = $body['detalle'];
}
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -3,11 +3,13 @@ namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Controller\withRedis;
use Incoviba\Common\Implement\Exception;
use Incoviba\Service;
class Search
{
use withJson;
use withJson, withRedis;
public function query(ServerRequestInterface $request, ResponseInterface $response,
Service\Search $service): ResponseInterface
@ -17,4 +19,155 @@ class Search
$output = compact('results');
return $this->withJson($response, $output);
}
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta\Unidad $unidadService, int $unidad_id): ResponseInterface
{
$output = [
'unidad_id' => $unidad_id,
'unidad' => null
];
$redisKey = "search:unidad:{$unidad_id}";
try {
$output['unidad'] = $this->fetchRedis($redisService, $redisKey);
} catch (Exception\EmptyRedis) {
try {
$unidad = $unidadService->getByIdForSearch($unidad_id);
$output['unidad'] = [
'id' => $unidad['id'],
'descripcion' => $unidad['descripcion'],
'proyecto_tipo_unidad' => [
'proyecto' => [
'id' => $unidad['proyecto_id'],
'descripcion' => $unidad['proyecto_descripcion']
],
'tipo_unidad' => [
'descripcion' => $unidad['tipo_unidad_descripcion']
],
'superficie' => $unidad['superficie']
],
'current_precio' => [
'valor' => $unidad['precio']
]
];
$this->saveRedis($redisService, $redisKey, $output['unidad']);
} catch (Exception\EmptyResult) {}
}
return $this->withJson($response, $output);
}
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta\Unidad $unidadService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'unidades' => []
];
$unidades = explode(',', $body['unidades']);
foreach ($unidades as $unidad_id) {
$redisKey = "search:unidad:{$unidad_id}";
try {
$output['unidades'] []= $this->fetchRedis($redisService, $redisKey);
} catch (Exception\EmptyRedis) {
try {
$unidad = $unidadService->getByIdForSearch($unidad_id);
$unidad = [
'id' => $unidad['id'],
'descripcion' => $unidad['descripcion'],
'proyecto_tipo_unidad' => [
'proyecto' => [
'id' => $unidad['proyecto_id'],
'descripcion' => $unidad['proyecto_descripcion']
],
'tipo_unidad' => [
'descripcion' => $unidad['tipo_unidad_descripcion']
],
'superficie' => $unidad['superficie']
],
'current_precio' => [
'valor' => $unidad['precio']
]
];
$output['unidades'] []= $unidad;
$this->saveRedis($redisService, $redisKey, $unidad);
} catch (Exception\EmptyResult) {}
}
}
return $this->withJson($response, $output);
}
public function venta(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta $ventaService, int $venta_id): ResponseInterface
{
$output = [
'venta_id' => $venta_id,
'venta' => null
];
$redisKey = "search:venta:{$venta_id}";
try {
$output['venta'] = $this->fetchRedis($redisService, $redisKey);
} catch (Exception\EmptyRedis) {
try {
$venta = $ventaService->getById($venta_id);
/*$output['venta'] = [
'id' => $venta->id,
''
];*/
$output['venta'] = $venta;
$this->saveRedis($redisService, $redisKey, $output['venta']);
} catch (Exception\EmptyResult) {}
}
return $this->withJson($response, $output);
}
public function ventas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta $ventaService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'ventas' => []
];
$ventas = explode(',', $body['ventas']);
foreach ($ventas as $venta_id) {
$redisKey = "search:venta:{$venta_id}";
try {
$output['ventas'] []= $this->fetchRedis($redisService, $redisKey);
} catch (Exception\EmptyRedis) {
try {
$venta = $ventaService->getByIdForSearch($venta_id);
$venta = [
'id' => $venta['id'],
'proyecto' => [
'id' => $venta['proyecto_id'],
'descripcion' => $venta['proyecto_descripcion']
],
'propietario' => [
'nombre_completo' => $venta['propietario']
],
'propiedad' => [
'unidades' => [
[
'descripcion' => $venta['unidad_descripcion'],
'proyecto_tipo_unidad' => [
'tipo_unidad' => [
'descripcion' => $venta['tipo_unidad_descripcion']
],
'superficie' => $venta['superficie']
]
]
]
],
'fecha' => $venta['fecha'],
'current_estado' => [
'tipo_estado_venta' => [
'activa' => $venta['activa']
]
],
'valor' => $venta['valor']
];
$output['ventas'] []= $venta;
$this->saveRedis($redisService, $redisKey, json_encode($venta));
} catch (Exception\EmptyResult) {}
}
}
return $this->withJson($response, $output);
}
}

View File

@ -74,6 +74,32 @@ class Ventas extends Controller
}
return $this->withJson($response, $output);
}
public function getMany(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta $service): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'ventas' => []
];
$ventas = explode(',', $body['ventas']);
foreach ($ventas as $venta_id) {
$redisKey = "venta:{$venta_id}";
try {
$venta = $this->fetchRedis($redisService, $redisKey);
$output['ventas'] []= $venta;
} catch (EmptyRedis) {
try {
$venta = $service->getById($venta_id);
$output['ventas'] []= $venta;
$this->saveRedis($redisService, $redisKey, $venta);
} catch (EmptyResult $exception) {
$this->logger->notice($exception);
}
}
}
return $this->withJson($response, $output);
}
public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Redis $redisService): ResponseInterface
{
$body = $request->getBody();

View File

@ -18,7 +18,8 @@ class Contabilidad extends Controller
public function diaria(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Redis $redisService,
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\CentroCosto $centroCostoRepository): ResponseInterface
{
$redisKey = 'inmobiliarias';
$inmobiliarias = [];
@ -30,7 +31,8 @@ class Contabilidad extends Controller
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
} catch (EmptyResult) {}
}
return $view->render($response, 'contabilidad.cartolas.diaria', compact('inmobiliarias'));
$centrosCostos = $centroCostoRepository->fetchAll();
return $view->render($response, 'contabilidad.cartolas.diaria', compact('inmobiliarias', 'centrosCostos'));
}
public function depositos(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Redis $redisService,

View File

@ -13,7 +13,7 @@ class Login
public function form(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
{
if ($service->isIn()) {
return $response->withStatus(301)->withHeader('Location', $view->get('urls')->base);
return $response->withStatus(302)->withHeader('Location', $view->get('urls')->base);
}
return $view->render($response, 'login.form');
}

View File

@ -32,8 +32,13 @@ class Ventas
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $service, int $venta_id): ResponseInterface
{
$venta = $service->getById($venta_id);
return $view->render($response, 'ventas.show', compact('venta'));
try {
$venta = $service->getById($venta_id);
return $view->render($response, 'ventas.show', compact('venta'));
} catch (EmptyResult) {
$response = $response->withStatus(404);
return $view->render($response, 'not_found');
}
}
public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface

View File

@ -6,8 +6,8 @@ use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Incoviba\Service;
use Psr\Log\LoggerInterface;
use Incoviba\Service;
class Authentication
{
@ -27,7 +27,11 @@ class Authentication
$response = $this->responseFactory->createResponse(301, 'Not logged in')
->withHeader('Referer', (string) $request->getUri())
->withHeader('X-Redirected-URI', (string) $request->getUri());
return $this->view->render($response, 'login.form', ['redirect_uri' => (string) $request->getUri()]);
$url = "{$request->getUri()}";
if (str_ends_with($url, '/login')) {
$url = str_replace('/login', '', $url);
}
return $this->view->render($response, 'login.form', ['redirect_uri' => $url]);
}
protected function isValid(ServerRequestInterface $request): bool

View File

@ -13,7 +13,7 @@ class CentroCosto extends Ideal\Model
public function jsonSerialize(): mixed
{
return array_map(parent::jsonSerialize(), [
return array_merge(parent::jsonSerialize(), [
'tipo_centro' => $this->tipoCentro,
'categoria' => $this->categoria,
'tipo_cuenta' => $this->tipoCuenta,

View File

@ -3,6 +3,7 @@ namespace Incoviba\Model;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Model\Movimiento\Detalle;
class Movimiento extends Ideal\Model
{
@ -14,6 +15,15 @@ class Movimiento extends Ideal\Model
public int $abono;
public int $saldo;
protected ?Detalle $detalles;
public function getDetalles(): ?Detalle
{
if (!isset($this->detalles)) {
$this->detalles = $this->runFactory('detalles');
}
return $this->detalles;
}
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
@ -23,7 +33,8 @@ class Movimiento extends Ideal\Model
'documento' => $this->documento,
'cargo' => $this->cargo,
'abono' => $this->abono,
'saldo' => $this->saldo
'saldo' => $this->saldo,
'detalles' => $this->getDetalles() ?? null
]);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Incoviba\Model\Movimiento;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Detalle extends Ideal\Model
{
public Model\Movimiento $movimiento;
public ?Model\CentroCosto $centroCosto;
public ?string $detalle;
public function jsonSerialize(): mixed
{
return [
'movimiento_id' => $this->movimiento->id,
'centro_costo' => $this->centroCosto,
'detalle' => $this->detalle
];
}
}

View File

@ -4,13 +4,14 @@ namespace Incoviba\Model;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Controller\Ventas;
use Incoviba\Model\Venta\FormaPago;
use Incoviba\Model\Venta\Pago;
class Venta extends Ideal\Model
{
protected Venta\Propietario $propietario;
protected Venta\Propiedad $propiedad;
protected Venta\FormaPago $formaPago;
protected ?Venta\FormaPago $formaPago;
public DateTimeInterface $fecha;
public DateTimeInterface $fechaIngreso;
public float $valor;
@ -36,7 +37,7 @@ class Venta extends Ideal\Model
}
return $this->propiedad;
}
public function formaPago(): Venta\FormaPago
public function formaPago(): ?Venta\FormaPago
{
if (!isset($this->formaPago)) {
$this->formaPago = $this->runFactory('formaPago');
@ -104,7 +105,7 @@ class Venta extends Ideal\Model
return array_merge(parent::jsonSerialize(), [
'propietario' => $this->propietario(),
'propiedad' => $this->propiedad(),
'forma_pago' => $this->formaPago()->ids(),
'forma_pago' => $this->formaPago()?->ids(),
'fecha' => $this->fecha->format('Y-m-d'),
'fecha_ingreso' => $this->fechaIngreso->format('Y-m-d'),
'valor' => $this->valor,

View File

@ -5,12 +5,12 @@ use JsonSerializable;
class FormaPago implements JsonSerializable
{
public ?Pie $pie;
public ?Escritura $escritura;
public ?BonoPie $bonoPie;
public ?Subsidio $subsidio;
public ?Credito $credito;
public ?Pago $devolucion;
public ?Pie $pie = null;
public ?Escritura $escritura = null;
public ?BonoPie $bonoPie = null;
public ?Subsidio $subsidio = null;
public ?Credito $credito = null;
public ?Pago $devolucion = null;
public function anticipo(string $moneda = Pago::UF): float
{

View File

@ -0,0 +1,60 @@
<?php
namespace Incoviba\Repository\Movimiento;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class Detalle extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Movimiento $movimientoRepository,
protected Repository\CentroCosto $centroCostoRepository)
{
parent::__construct($connection);
$this->setTable('movimientos_detalles');
}
public function create(?array $data = null): Model\Movimiento\Detalle
{
$map = (new Implement\Repository\MapperParser(['detalle']))
->register('movimiento_id', (new Implement\Repository\Mapper())
->setProperty('movimiento')
->setFunction(function(array $data) {
return $this->movimientoRepository->fetchById($data['movimiento_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\Movimiento\Detalle(), $data, $map);
}
public function save(Define\Model $model): Model\Movimiento\Detalle
{
$this->saveNew(
['movimiento_id', 'centro_costo_id', 'detalle'],
[$model->movimiento->id, $model->centroCosto->id, $model->detalle]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Movimiento\Detalle
{
return $this->update($model, ['movimiento_id', 'centro_costo_id', 'detalle'], $new_data);
}
public function fetchByMovimiento(int $movimiento_id): Model\Movimiento\Detalle
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('movimiento_id = ?');
return $this->fetchOne($query, [$movimiento_id]);
}
protected function getKey(): string
{
return 'movimiento_id';
}
}

View File

@ -38,7 +38,7 @@ class Venta extends Ideal\Repository
->setFactory((new Implement\Repository\Factory())
->setCallable([$this->propiedadRepository, 'fetchById'])
->setArgs([$data['propiedad']])))
->register('pie', (new Implement\Repository\Mapper())
/*->register('pie', (new Implement\Repository\Mapper())
->setProperty('formaPago')
->setFactory((new Implement\Repository\Factory())
->setCallable(function($repositories, $data) {
@ -84,7 +84,7 @@ class Venta extends Ideal\Repository
'escrituraRepository' => $this->escrituraRepository,
'subsidioRepository' => $this->subsidioRepository,
'pagoService' => $this->pagoService
], $data])))
], $data])))*/
/*->register('escriturado', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $data['escritura'] !== null;
@ -298,7 +298,6 @@ class Venta extends Ideal\Repository
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario
OR rut = :rut
OR CONCAT_WS('-', rut, dv) = :rut");
error_log($query.PHP_EOL,3,'/logs/debug');
return $this->fetchIds($query, [':propietario' => "%{$propietario}%", ':rut' => $propietario]);
}
public function fetchByPropietarioNombreCompleto(string $propietario): array
@ -356,6 +355,48 @@ class Venta extends Ideal\Repository
->where('bono_pie = ?');
return $this->fetchId($query, [$bono_id]);
}
public function fetchByIdForSearch(int $venta_id): array
{
$query = $this->connection->getQueryBuilder()
->select('venta.id AS id, venta.fecha AS fecha, venta.valor_uf AS valor')
->columns('proyecto.id AS proyecto_id, proyecto.descripcion AS proyecto_descripcion')
->columns('CONCAT_WS(" ", propietario.nombres, propietario.apellido_paterno, propietario.apellido_materno) AS propietario')
->columns('unidad.descripcion AS unidad_descripcion, tu.descripcion AS tipo_unidad_descripcion, ptu.m2 + ptu.logia + ptu.terraza AS superficie')
->columns('tev.activa')
->from($this->getTable())
->joined('JOIN propietario ON propietario.rut = venta.propietario')
->joined('JOIN propiedad_unidad pu ON pu.propiedad = venta.propiedad')
->joined('JOIN unidad ON unidad.id = pu.unidad')
->joined('JOIN proyecto_tipo_unidad ptu ON unidad.pt = ptu.id')
->joined('JOIN proyecto ON proyecto.id = ptu.proyecto')
->joined('JOIN tipo_unidad tu ON tu.id = ptu.tipo')
->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 = venta.id')
->joined('JOIN tipo_estado_venta tev ON ev.estado = tev.id')
->where('venta.id = ? AND tu.descripcion = "departamento"')
->group('venta.id');
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
}
public function fetchByIdForList(int $venta_id): array
{
$query = $this->connection->getQueryBuilder()
->select('venta.id AS id, venta.fecha AS fecha, venta.valor_uf AS valor')
->columns('proyecto.id AS proyecto_id, proyecto.descripcion AS proyecto_descripcion')
->columns('CONCAT_WS(" ", propietario.nombres, propietario.apellido_paterno, propietario.apellido_materno) AS propietario')
->columns("GROUP_CONCAT(unidad.descripcion SEPARATOR ' - ') AS unidad_descripcion, tu.descripcion AS tipo_unidad_descripcion, ptu.m2 + ptu.logia + ptu.terraza AS superficie")
->columns('tev.activa')
->from($this->getTable())
->joined('JOIN propietario ON propietario.rut = venta.propietario')
->joined('JOIN propiedad_unidad pu ON pu.propiedad = venta.propiedad')
->joined('JOIN unidad ON unidad.id = pu.unidad')
->joined('JOIN proyecto_tipo_unidad ptu ON unidad.pt = ptu.id')
->joined('JOIN proyecto ON proyecto.id = ptu.proyecto')
->joined('JOIN tipo_unidad tu ON tu.id = ptu.tipo')
->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 = venta.id')
->joined('JOIN tipo_estado_venta tev ON ev.estado = tev.id')
->where('venta.id = ?')
->group('venta.id');
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
}
protected function fetchIds(string $query, ?array $data = null): array
{

View File

@ -52,4 +52,13 @@ class BonoPie extends Ideal\Repository
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
public function fetchByVenta(int $venta_id): Model\Venta\BonoPie
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN venta ON venta.bono_pie = a.id')
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
}

View File

@ -53,4 +53,13 @@ class Credito extends Ideal\Repository
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
public function fetchByVenta(int $venta_id): Model\Venta\Credito
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN venta ON venta.credito = a.id')
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
}

View File

@ -55,4 +55,13 @@ class Escritura extends Ideal\Repository
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
public function fetchByVenta(int $venta_id): Model\Venta\Escritura
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN venta ON venta.escritura = a.id')
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
}

View File

@ -108,4 +108,13 @@ WHERE venta_id = ?";
->where('valor = ? OR ROUND(valor/uf, 3) = ?');
return $this->fetchMany($query, [$value, $value]);
}
public function fetchDevolucionByVenta(int $venta_id): Model\Venta\Pago
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN venta ON venta.devolucion = a.id')
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
}

View File

@ -72,4 +72,13 @@ class Pie extends Ideal\Repository
->where('reajuste = ?');
return $this->fetchOne($query, [$reajuste_id]);
}
public function fetchByVenta(int $venta_id): Model\Venta\Pie
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN venta ON venta.pie = a.id')
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
}

View File

@ -49,4 +49,13 @@ class Subsidio extends Ideal\Repository
->where('subsidio = ? OR pago = ?');
return $this->fetchOne($query, [$pago_id, $pago_id]);
}
public function fetchByVenta(int $venta_id): Model\Venta\Subsidio
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN venta ON venta.subsidio = a.id')
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
}

View File

@ -177,6 +177,24 @@ class Unidad extends Ideal\Repository
->where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)");
return $this->connection->execute($query, [$descripcion, $tipo])->fetchAll(PDO::FETCH_ASSOC);
}
public function fetchByIdForSearch(int $unidad_id): array
{
$query = $this->connection->getQueryBuilder()
->select('unidad.id AS id, unidad.descripcion AS descripcion')
->columns('proyecto.id AS proyecto_id, proyecto.descripcion AS proyecto_descripcion')
->columns('tu.descripcion AS tipo_unidad_descripcion')
->columns('ptu.m2 + ptu.logia + ptu.terraza AS superficie')
->columns('precio.valor AS precio')
->from($this->getTable())
->joined('JOIN proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
->joined('JOIN proyecto ON proyecto.id = ptu.proyecto')
->joined('JOIN tipo_unidad tu ON tu.id = ptu.tipo')
->joined('JOIN precio ON precio.unidad = unidad.id')
->joined('JOIN (SELECT ep1.* FROM estado_precio ep1 JOIN (SELECT MAX(id) AS id, precio FROM estado_precio GROUP BY precio) ep0 ON ep0.id = ep1.id) ep ON ep.precio = precio.id')
->where('unidad.id = ?')
->group('unidad.id');
return $this->connection->execute($query, [$unidad_id])->fetch(PDO::FETCH_ASSOC);
}
protected function joinProrrateo(): string
{

View File

@ -21,6 +21,7 @@ class Cartola extends Service
protected Repository\Inmobiliaria $inmobiliariaRepository,
protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
protected Repository\Movimiento $movimientoRepository,
protected Movimiento $movimientoService,
protected Repository\Cartola $cartolaRepository) {
parent::__construct($logger);
}
@ -51,6 +52,7 @@ class Cartola extends Service
$movimientos = [];
foreach ($ms as $m) {
$movimiento = $this->buildMovimiento($cuenta, $m);
$movimiento = $this->movimientoService->process($movimiento);
if ($movimiento->fecha->getTimestamp() === $fecha->getTimestamp()) {
$movimientos []= $movimiento;
@ -78,6 +80,7 @@ class Cartola extends Service
$dataMovimiento['fecha'] = $fecha->format('Y-m-d');
$dataMovimiento['documento'] = '';
$movimiento = $this->buildMovimiento($cuenta, $dataMovimiento);
$movimiento = $this->movimientoService->process($movimiento);
$movimientos []= $movimiento;
$cartolaData['cargos'] += $movimiento->cargo;

View File

@ -17,7 +17,12 @@ class Santander extends Banco
'DESCRIPCIÓN MOVIMIENTO' => 'glosa',
'FECHA' => 'fecha',
'N° DOCUMENTO' => 'documento',
'SALDO' => 'saldo'
'SALDO' => 'saldo',
'Fecha' => 'fecha',
'Cargo ($)' => 'cargo',
'Abono ($)' => 'abono',
'Descripcin' => 'glosa',
'Saldo Diario' => 'saldo'
];
}
protected function parseFile(UploadedFileInterface $uploadedFile): array
@ -26,7 +31,11 @@ class Santander extends Banco
$uploadedFile->moveTo($filename);
$reader = PhpSpreadsheet\IOFactory::createReader('Xlsx');
$xlsx = $reader->load($filename);
try {
$xlsx = $reader->load($filename);
} catch (PhpSpreadsheet\Reader\Exception) {
return $this->parseHtml($filename);
}
$sheet = $xlsx->getActiveSheet();
$found = false;
@ -74,4 +83,59 @@ class Santander extends Banco
return $data;
}
protected function parseHtml(string $filename): array
{
$data = [];
$lines = explode("\r\n", file_get_contents($filename));
$columns = [];
$found = false;
for ($rowIndex = 0; $rowIndex < count($lines); $rowIndex ++) {
if (!$found and str_contains($lines[$rowIndex], 'Cuenta Corriente: ')) {
$found = true;
$rowIndex += 2;
$columns = $this->parseHtmlRow($lines, $rowIndex);
continue;
}
if (!$found) {
continue;
}
$row = $this->parseHtmlRow($lines, $rowIndex);
if (str_contains($row[0], 'Saldo Contable')) {
break;
}
$row = array_combine($columns, $row);
$row['Fecha'] = implode('-', array_reverse(explode('-', $row['Fecha'])));
foreach (['Cargo ($)', 'Abono ($)', 'Saldo Diario'] as $column) {
$row[$column] = (int) str_replace('.', '', $row[$column]);
}
$row['Saldo Diario'] -= ($row['Abono ($)'] - $row['Cargo ($)']);
$row['N° DOCUMENTO'] = '';
$data []= $row;
}
return $data;
}
protected function parseHtmlRow(array $lines, int &$rowIndex): array
{
if (!str_contains($lines[$rowIndex ++], '<tr>')) {
return [];
}
$data = [];
while (!str_contains($lines[$rowIndex], '</tr>')) {
$tags = substr_count($lines[$rowIndex], '<') - substr_count($lines[$rowIndex], '</');
$ini = 0;
for ($t = 0; $t < $tags; $t ++) {
$ini = strpos($lines[$rowIndex], '>', $ini) + 1;
}
$end = strpos($lines[$rowIndex], '<', $ini + 1);
$cell = str_replace(' ', '', substr($lines[$rowIndex], $ini, $end - $ini));
$encoding = mb_detect_encoding($cell, ['Windows-1252', 'UTF-8']);
if ($encoding !== 'UTF-8') {
$cell = mb_convert_encoding($cell, $encoding, 'UTF-8');
$cell = str_replace('?', '', $cell);
}
$data []= $cell;
$rowIndex ++;
}
return $data;
}
}

View File

@ -271,6 +271,7 @@ class Excel extends Ideal\Service
'formatCode' => self::CURRENCY_CODE
]
]);
$rowSaldoAnterior = $rowIndex;
$rowIndex ++;
$styles = [
@ -284,6 +285,9 @@ class Excel extends Ideal\Service
'bold' => true
]
];
$rowDap = null;
$rowIngreso = null;
$rowEgreso = null;
foreach ($data['movimientos'] as $tipo => $movimientos) {
if ($tipo === 'capital dap') {
$sheet->getCell("B{$rowIndex}")->setValue('CAPITAL DAP');
@ -291,6 +295,7 @@ class Excel extends Ideal\Service
$sheet->getStyle("B{$rowIndex}:V{$rowIndex}")->applyFromArray($styles);
$sheet->getCell("V{$rowIndex}")->getStyle()->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
$totalRow = $rowIndex;
$rowDap = $rowIndex;
$rowIndex ++;
if (count($movimientos['ingresos']) === 0 and count($movimientos['egresos']) === 0) {
$sheet->getCell("V{$totalRow}")->setValue(0);
@ -319,6 +324,11 @@ class Excel extends Ideal\Service
$sheet->getCell("V{$rowIndex}")->getStyle()->getNumberFormat()
->setFormatCode(self::CURRENCY_CODE);
$totalRow = $rowIndex;
if (!isset($rowIngreso) or $rowIngreso === null) {
$rowIngreso = $rowIndex;
} else {
$rowEgreso = $rowIndex;
}
$rowIndex ++;
if (count($movimientos) === 0) {
$sheet->getCell("V{$totalRow}")->setValue(0);
@ -363,7 +373,7 @@ class Excel extends Ideal\Service
'formatCode' => PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY
]
]);
$sheet->getCell("V{$rowIndex}")->setValue(0)->getStyle()->applyFromArray([
$sheet->getCell("V{$rowIndex}")->setValue("=V{$rowSaldoAnterior}+V{$rowDap}+V{$rowIngreso}+V{$rowEgreso}")->getStyle()->applyFromArray([
'font' => [
'bold' => true
],

View File

@ -0,0 +1,43 @@
<?php
namespace Incoviba\Service;
use DateTimeInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal\Service;
use Incoviba\Common\Implement;
use Incoviba\Repository;
use Incoviba\Model;
class Movimiento extends Service
{
public function __construct(LoggerInterface $logger, protected Repository\Movimiento $movimientoRepository,
protected Repository\Movimiento\Detalle $detalleRepository)
{
parent::__construct($logger);
}
public function getById(int $movimiento_id): Model\Movimiento
{
return $this->process($this->movimientoRepository->fetchById($movimiento_id));
}
public function setDetalles(Model\Movimiento $movimiento, array $data): Model\Movimiento
{
try {
$detalles = $this->detalleRepository->fetchByMovimiento($movimiento->id);
$this->detalleRepository->edit($detalles, $data);
} catch (Implement\Exception\EmptyResult) {
$data['movimiento_id'] = $movimiento->id;
$detalles = $this->detalleRepository->create($data);
$this->detalleRepository->save($detalles);
}
return $movimiento;
}
public function process(Model\Movimiento $movimiento): Model\Movimiento
{
$movimiento->addFactory('detalles', (new Implement\Repository\Factory())->setCallable(function(int $movimiento_id) {
return $this->detalleRepository->fetchByMovimiento($movimiento_id);
})->setArgs(['movimiento_id' => $movimiento->id]));
return $movimiento;
}
}

View File

@ -6,7 +6,6 @@ use Incoviba\Common\Ideal\Service;
use Incoviba\Common\Implement;
use Incoviba\Repository;
use Incoviba\Model;
use PhpParser\Node\Expr\AssignOp\Mod;
use Psr\Log\LoggerInterface;
class Venta extends Service
@ -20,6 +19,7 @@ class Venta extends Service
protected Repository\Venta\Escritura $escrituraRepository,
protected Repository\Venta\Pago $pagoRepository,
protected Repository\Venta\EstadoPago $estadoPagoRepository,
protected Venta\FormaPago $formaPagoService,
protected Venta\Propietario $propietarioService,
protected Venta\Propiedad $propiedadService,
protected Venta\Pie $pieService,
@ -75,9 +75,20 @@ class Venta extends Service
$ventas = $this->ventaRepository->fetchEscriturasByProyecto($proyecto_id);
return array_map([$this, 'process'], $ventas);
}
public function getByIdForSearch(int $venta_id): array
{
return $this->ventaRepository->fetchByIdForSearch($venta_id);
}
public function getByIdForList(int $venta_id): array
{
return $this->ventaRepository->fetchByIdForList($venta_id);
}
protected function process(Model\Venta $venta): Model\Venta
{
$venta->addFactory('formaPago', (new Implement\Repository\Factory())
->setCallable([$this->formaPagoService, 'getByVenta'])
->setArgs(['venta_id' => $venta->id]));
$venta->addFactory('estados', (new Implement\Repository\Factory())
->setCallable([$this->estadoVentaRepository, 'fetchByVenta'])
->setArgs([$venta->id]));
@ -227,7 +238,8 @@ class Venta extends Service
}
protected function addFormaPago(array $data): Model\Venta\FormaPago
{
$fields = [
return $this->formaPagoService->add($data);
/*$fields = [
'pie',
'subsidio',
'credito',
@ -241,9 +253,9 @@ class Venta extends Service
$forma_pago->{$name} = $obj;
}
}
return $forma_pago;
return $forma_pago;*/
}
protected function addPie(array $data): Model\Venta\Pie
/*protected function addPie(array $data): Model\Venta\Pie
{
$fields = array_fill_keys([
'fecha_venta',
@ -305,7 +317,7 @@ class Venta extends Service
'valor'
], $filtered_data);
return $this->bonoPieService->add($mapped_data);
}
}*/
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
{
$fecha = new DateTimeImmutable($data['fecha']);

View File

@ -12,4 +12,8 @@ class BonoPie
{
return new Model\Venta\BonoPie();
}
public function getByVenta(int $venta_id): Model\Venta\BonoPie
{
return $this->bonoPieRepository->fetchByVenta($venta_id);
}
}

View File

@ -22,6 +22,11 @@ class Credito extends Service
parent::__construct($logger);
}
public function getByVenta(int $venta_id): Model\Venta\Credito
{
return $this->creditoRepository->fetchByVenta($venta_id);
}
public function add(array $data): Model\Venta\Credito
{
$fecha = new DateTimeImmutable($data['fecha']);

View File

@ -0,0 +1,143 @@
<?php
namespace Incoviba\Service\Venta;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Implement;
use Incoviba\Common\Ideal;
use Incoviba\Model;
use Incoviba\Repository;
class FormaPago extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Pie $pieService,
protected BonoPie $bonoPieService,
protected Credito $creditoService,
protected Repository\Venta\Escritura $escrituraRepository,
protected Subsidio $subsidioService,
protected Pago $pagoService)
{
parent::__construct($logger);
}
public function getByVenta(int $venta_id): Model\Venta\FormaPago
{
$formaPago = new Model\Venta\FormaPago();
try {
$formaPago->pie = $this->pieService->getByVenta($venta_id);
} catch (Implement\Exception\EmptyResult) {}
try {
$formaPago->bonoPie = $this->bonoPieService->getByVenta($venta_id);
} catch (Implement\Exception\EmptyResult) {}
try {
$formaPago->credito = $this->creditoService->getByVenta($venta_id);
} catch (Implement\Exception\EmptyResult) {}
try {
$formaPago->escritura = $this->escrituraRepository->fetchByVenta($venta_id);
} catch (Implement\Exception\EmptyResult) {}
try {
$formaPago->subsidio = $this->subsidioService->getByVenta($venta_id);
} catch (Implement\Exception\EmptyResult) {}
try {
$formaPago->devolucion = $this->pagoService->getDevolucionByVenta($venta_id);
} catch (Implement\Exception\EmptyResult) {}
return $formaPago;
}
public function add(array $data): Model\Venta\FormaPago
{
$fields = [
'pie',
'subsidio',
'credito',
'bono_pie'
];
$forma_pago = new Model\Venta\FormaPago();
foreach ($fields as $name) {
if (isset($data["has_{$name}"])) {
try {
$method = 'add' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
$obj = $this->{$method}($data);
$forma_pago->{$name} = $obj;
} catch (\Error $error) {
$this->logger->critical($error);
}
}
}
return $forma_pago;
}
protected function addPie(array $data): Model\Venta\Pie
{
$fields = array_fill_keys([
'fecha_venta',
'pie',
'cuotas',
'uf'
], 0);
$filtered_data = array_intersect_key($data, $fields);
$this->logger->critical(var_export($filtered_data,true));
$mapped_data = array_combine([
'fecha',
'valor',
'cuotas',
'uf'
], $filtered_data);
$mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
return $this->pieService->add($mapped_data);
}
protected function addSubsidio(array $data): Model\Venta\Subsidio
{
$fields = array_fill_keys([
'fecha_venta',
'ahorro',
'subsidio',
'uf'
], 0);
$filtered_data = array_intersect_key($data, $fields);
$mapped_data = array_combine([
'fecha',
'ahorro',
'subsidio',
'uf'
], $filtered_data);
return $this->subsidioService->add($mapped_data);
}
protected function addCredito(array $data): Model\Venta\Credito
{
$fields = array_fill_keys([
'fecha_venta',
'credito',
'uf'
], 0);
$filtered_data = array_intersect_key($data, $fields);
$mapped_data = array_combine([
'fecha',
'valor',
'uf'
], $filtered_data);
return $this->creditoService->add($mapped_data);
}
protected function addBonoPie(array $data): Model\Venta\BonoPie
{
$fields = array_fill_keys([
'fecha_venta',
'bono_pie'
], 0);
$filtered_data = array_intersect_key($data, $fields);
$mapped_data = array_combine([
'fecha',
'valor'
], $filtered_data);
return $this->bonoPieService->add($mapped_data);
}
protected function cleanValue($value): float
{
if ((float) $value == $value) {
return (float) $value;
}
return (float) str_replace(['.', ','], ['', '.'], $value);
}
}

View File

@ -109,6 +109,10 @@ class Pago
{
return [];
}
public function getDevolucionByVenta(int $venta_id): Model\Venta\Pago
{
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
}
public function add(array $data): Model\Venta\Pago
{

View File

@ -17,6 +17,10 @@ class Pie
{
return $this->process($this->pieRepository->fetchById($pie_id));
}
public function getByVenta(int $venta_id): Model\Venta\Pie
{
return $this->process($this->pieRepository->fetchByVenta($venta_id));
}
public function add(array $data): Model\Venta\Pie
{

View File

@ -17,6 +17,11 @@ class Subsidio
protected Service\Money $moneyService
) {}
public function getByVenta(int $venta_id): Model\Venta\Subsidio
{
return $this->subsidioRepository->fetchByVenta($venta_id);
}
public function add(array $data): Model\Venta\Subsidio
{
$fecha = new DateTimeImmutable($data['fecha']);

View File

@ -33,6 +33,10 @@ class Unidad
{
return $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
}
public function getByIdForSearch(int $unidad_id): array
{
return $this->unidadRepository->fetchByIdForSearch($unidad_id);
}
protected function process($unidad): Model\Venta\Unidad
{