diff --git a/app/common/Ideal/Repository.php b/app/common/Ideal/Repository.php index daf2139..56a2c10 100644 --- a/app/common/Ideal/Repository.php +++ b/app/common/Ideal/Repository.php @@ -102,7 +102,7 @@ abstract class Repository implements Define\Repository $this->connection->execute($query, $values); return $this->connection->getPDO()->lastInsertId(); } - protected function update(Model $model, array $columns, array $data): Define\Model + protected function update(Define\Model $model, array $columns, array $data): Define\Model { $changes = []; $values = []; @@ -119,10 +119,7 @@ abstract class Repository implements Define\Repository $query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?"; $values []= $model->id; $this->connection->execute($query, $values); - $id = $model->id; - $model = $this->create($data); - $model->id = $id; - return $model; + return $this->fetchById($model->id); } protected function fetchOne(string $query, ?array $data = null): Define\Model { diff --git a/app/public/index.php b/app/public/index.php index 9e47d85..a7bedad 100644 --- a/app/public/index.php +++ b/app/public/index.php @@ -8,6 +8,8 @@ try { $app->run(); } catch (Error $error) { $app->getContainer()->get(Psr\Log\LoggerInterface::class)->error($error); + header('Location: /construccion'); } catch (Exception $exception) { $app->getContainer()->get(Psr\Log\LoggerInterface::class)->notice($exception); + header('Location: /construccion'); } diff --git a/app/resources/routes/04_ventas.php b/app/resources/routes/04_ventas.php index 5e522cf..404feb1 100644 --- a/app/resources/routes/04_ventas.php +++ b/app/resources/routes/04_ventas.php @@ -9,6 +9,7 @@ $app->group('/ventas', function($app) { } include_once $file->getRealPath(); } + $app->get('/add', [Ventas::class, 'add']); $app->get('[/]', Ventas::class); }); $app->group('/venta/{proyecto_nombre:[A-za-zÑñ\+\ %0-9]+}/{unidad_descripcion:[0-9]+}', function($app) { diff --git a/app/resources/routes/99_base.php b/app/resources/routes/99_base.php index c8c764e..24b84c0 100644 --- a/app/resources/routes/99_base.php +++ b/app/resources/routes/99_base.php @@ -1,4 +1,5 @@ get('/construccion', [Base::class, 'construccion'])->setName('construccion'); $app->get('[/]', Base::class); diff --git a/app/resources/routes/api/provincias.php b/app/resources/routes/api/provincias.php new file mode 100644 index 0000000..188986c --- /dev/null +++ b/app/resources/routes/api/provincias.php @@ -0,0 +1,6 @@ +group('/provincia/{provincia_id}', function($app) { + $app->get('/comunas', [Provincias::class, 'comunas']); +}); diff --git a/app/resources/routes/api/proyectos.php b/app/resources/routes/api/proyectos.php index a0bf995..6128fd3 100644 --- a/app/resources/routes/api/proyectos.php +++ b/app/resources/routes/api/proyectos.php @@ -4,3 +4,6 @@ use Incoviba\Controller\Proyectos; $app->group('/proyectos', function($app) { $app->get('[/]', [Proyectos::class, 'list']); }); +$app->group('/proyecto/{proyecto_id}', function($app) { + $app->get('/unidades[/]', [Proyectos::class, 'unidades']); +}); diff --git a/app/resources/routes/api/regiones.php b/app/resources/routes/api/regiones.php new file mode 100644 index 0000000..14ccd9c --- /dev/null +++ b/app/resources/routes/api/regiones.php @@ -0,0 +1,7 @@ +group('/regiones', function($app) {}); +$app->group('/region/{region_id}', function($app) { + $app->get('/provincias[/]', [Regiones::class, 'provincias']); +}); diff --git a/app/resources/routes/api/ventas/pagos.php b/app/resources/routes/api/ventas/pagos.php index dd33bf3..6addcda 100644 --- a/app/resources/routes/api/ventas/pagos.php +++ b/app/resources/routes/api/ventas/pagos.php @@ -1,6 +1,11 @@ group('/pagos', function($app) { + $app->get('/pendientes', [Pagos::class, 'para_pendientes']); + $app->get('/abonar', [Pagos::class, 'para_abonar']); + $app->get('/rebotes', [Pagos::class, 'rebotes']); +}); $app->group('/pago/{pago_id:[0-9]+}', function($app) { $app->put('/depositar[/]', [Pagos::class, 'depositar']); $app->put('/abonar[/]', [Pagos::class, 'abonar']); diff --git a/app/resources/routes/api/ventas/propietarios.php b/app/resources/routes/api/ventas/propietarios.php new file mode 100644 index 0000000..d76be63 --- /dev/null +++ b/app/resources/routes/api/ventas/propietarios.php @@ -0,0 +1,6 @@ +group('/propietario/{propietario_rut}', function($app) { + $app->get('[/]', [Propietarios::class, 'get']); +}); diff --git a/app/resources/routes/ventas/cuotas.php b/app/resources/routes/ventas/cuotas.php index 981dccd..8960481 100644 --- a/app/resources/routes/ventas/cuotas.php +++ b/app/resources/routes/ventas/cuotas.php @@ -3,7 +3,10 @@ use Incoviba\Controller\Ventas\Cuotas; $app->group('/cuotas', function($app) { $app->get('/pendientes[/]', [Cuotas::class, 'pendientes']); + $app->get('/abonar[/]', [Cuotas::class, 'depositadas']); }); $app->group('/cuota', function($app) { $app->post('/depositar[/]', [Cuotas::class, 'depositar']); + $app->post('/abonar[/]', [Cuotas::class, 'abonar']); + $app->post('/devolver[/]', [Cuotas::class, 'devolver']); }); diff --git a/app/resources/routes/ventas/pagos.php b/app/resources/routes/ventas/pagos.php new file mode 100644 index 0000000..9fad5b0 --- /dev/null +++ b/app/resources/routes/ventas/pagos.php @@ -0,0 +1,6 @@ +group('/pagos', function($app) { + $app->get('/pendientes', [Pagos::class, 'pendientes']); +}); diff --git a/app/resources/views/construccion.blade.php b/app/resources/views/construccion.blade.php new file mode 100644 index 0000000..3b1d313 --- /dev/null +++ b/app/resources/views/construccion.blade.php @@ -0,0 +1,14 @@ +@extends('layout.base') + +@section('page_title') + Construcción +@endsection + +@section('page_content') +
+
+ + Esta parte del sitio está en construcción. +
+
+@endsection diff --git a/app/resources/views/layout/body/header/menu.blade.php b/app/resources/views/layout/body/header/menu.blade.php index 392dc36..872a747 100644 --- a/app/resources/views/layout/body/header/menu.blade.php +++ b/app/resources/views/layout/body/header/menu.blade.php @@ -4,9 +4,9 @@ @include('layout.body.header.menu.ventas') @include('layout.body.header.menu.proyectos') @include('layout.body.header.menu.inmobiliarias') - @include('layout.body.header.menu.contabilidad') - @include('layout.body.header.menu.operadores') - @include('layout.body.header.menu.herramientas') + {{--@include('layout.body.header.menu.contabilidad')--}} + {{--@include('layout.body.header.menu.operadores')--}} + {{--@include('layout.body.header.menu.herramientas')--}} diff --git a/app/resources/views/layout/body/header/menu/ventas.blade.php b/app/resources/views/layout/body/header/menu/ventas.blade.php index 7d669cc..b2a914a 100644 --- a/app/resources/views/layout/body/header/menu/ventas.blade.php +++ b/app/resources/views/layout/body/header/menu/ventas.blade.php @@ -17,11 +17,11 @@ Abonar - Pagos Pendientes - Consolidado Ventas + {{--Pagos Pendientes--}} + {{--Consolidado Ventas--}} -
+ {{--
Informes -
- Importar Precios - Evaluar Cierre +
--}} + {{--Importar Precios--}} + {{--Evaluar Cierre--}} Nueva Venta diff --git a/app/resources/views/layout/body/scripts/chartjs.blade.php b/app/resources/views/layout/body/scripts/chartjs.blade.php new file mode 100644 index 0000000..c11cb71 --- /dev/null +++ b/app/resources/views/layout/body/scripts/chartjs.blade.php @@ -0,0 +1,3 @@ +@push('page_scripts') + +@endpush diff --git a/app/resources/views/ventas/add.blade.php b/app/resources/views/ventas/add.blade.php new file mode 100644 index 0000000..3b88f25 --- /dev/null +++ b/app/resources/views/ventas/add.blade.php @@ -0,0 +1,799 @@ +@extends('layout.base') + +@section('page_content') +
+

Nueva Venta

+
+ +
+
+
+ + +
+
+
+

PROPIETARIO

+
+
+
+ + +
+
+
+
+ + +
+
+
+ +

PROPIEDAD

+ +
+ +
+ + + +
+

FORMA DE PAGO

+ +
+
+ +
UF
+
+
+ +
+
+ + +
+ +
+
+
+ +
UF
+
+
+
+ + +
+
+
+
+ +
+
+ + +
+ +
+
+
+ +
UF
+
+
+
+ +
+ +
UF
+
+
+
+
+
+ +
+
+ + +
+ +
+ +
UF
+
+
+
+

OTRAS CONDICIONES

+ +
+
+ + +
+ +
+ +
UF
+
+
+
+ + +
+
+@endsection + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/ventas/cuotas/abonar.blade.php b/app/resources/views/ventas/cuotas/abonar.blade.php new file mode 100644 index 0000000..f4e10bd --- /dev/null +++ b/app/resources/views/ventas/cuotas/abonar.blade.php @@ -0,0 +1,144 @@ +@extends('layout.base') + +@section('page_content') +
+

Abonar Cuotas

+
+
Total
+
{{count($cuotas_depositadas)}}
+
{{$format->pesos(array_reduce($cuotas_depositadas, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}
+
+ + + + + + + + + + + + + + + + + @foreach($cuotas_depositadas as $cuota) + + + + + + + + + + + + + @endforeach + +
ProyectoDepartamentoDepartamento SortPropietarioValor CuotaFecha CuotaFecha ISOFecha DepositadaFecha Abono / DevoluciónAcción
{{$cuota['Proyecto']}} + {{$cuota['Departamento']}} + {{str_pad($cuota['Departamento'], 4, 0, STR_PAD_LEFT)}}{{$cuota['Propietario']}}{{$format->pesos($cuota['Valor'])}}{{$cuota['Fecha Cheque']}}{{$cuota['Fecha ISO']}}{{$cuota['Fecha Depositada']}} +
+
+ + +
+
+
+
+ + +
+
+
+@endsection + +@include('layout.head.styles.datatables') +@include('layout.body.scripts.datatables') + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/ventas/cuotas/pendientes.blade.php b/app/resources/views/ventas/cuotas/pendientes.blade.php index 00a4ba1..ee0c4df 100644 --- a/app/resources/views/ventas/cuotas/pendientes.blade.php +++ b/app/resources/views/ventas/cuotas/pendientes.blade.php @@ -6,7 +6,7 @@
Total
{{count($cuotas_pendientes)}}
-
{{$format->pesos(array_reduce($cuotas_pendientes, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}
+
{{$format->pesos(array_reduce($cuotas_pendientes, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}
@@ -14,13 +14,14 @@ + + + - - - + @@ -34,16 +35,24 @@ + + + - - - + @@ -85,11 +94,19 @@ [2, 'asc'] ] }) + $('.ui.calendar').calendar({ + type: 'date', + formatter: { + date: 'DD-MM-YYYY' + } + }) $('.depositar.button').click(event => { const button = $(event.currentTarget) const cuota_id = button.data('cuota') - fetch('{{$urls->base}}/ventas/cuota/depositar', { - method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id}) + const calendar = $(".ui.calendar[data-cuota='" + cuota_id + "']").calendar('get date') + const fecha = [calendar.getFullYear(), calendar.getMonth()+1, calendar.getDate()].join('-') + fetch('{{$urls->api}}/ventas/cuota/depositar', { + method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id, fecha}) }).then(response => { if (response.ok) { return response.json() diff --git a/app/resources/views/ventas/list.blade.php b/app/resources/views/ventas/list.blade.php index 04261be..4f77afd 100644 --- a/app/resources/views/ventas/list.blade.php +++ b/app/resources/views/ventas/list.blade.php @@ -117,7 +117,11 @@ this.data.venta_ids = data.ventas const promises = [] data.ventas.forEach(venta_id => { - promises.push(this.get().venta(venta_id)) + const promise = this.get().venta(venta_id) + /*promise.then(() => { + this.draw().ventas(true) + })*/ + promises.push(promise) }) Promise.all(promises).then(() => { this.draw().ventas() @@ -181,7 +185,7 @@ parent.show() parent.find('.item.proyecto').click(this.actions().get) }, - ventas: () => { + ventas: (loading = false) => { const title = $(this.ids.title) const parent = $(this.ids.proyectos) const table = $(this.ids.table) @@ -195,6 +199,11 @@ } title.html('Ventas de ' + this.data.proyecto + ' [' + this.data.ventas.length + ']') + if (loading) { + title.append( + $('').addClass('ui active inline loader') + ) + } const tbody = $('') this.data.ventas.forEach(venta => { diff --git a/app/resources/views/ventas/pagos/pendientes.blade.php b/app/resources/views/ventas/pagos/pendientes.blade.php new file mode 100644 index 0000000..131c009 --- /dev/null +++ b/app/resources/views/ventas/pagos/pendientes.blade.php @@ -0,0 +1,257 @@ +@extends('layout.base') + +@section('page_title') + Pagos Pendientes +@endsection + +@section('page_content') +
+

Pagos Pendientes

+
+

Para Abonar

+
+

Pagos Devueltos

+
+
+@endsection + +@include('layout.body.scripts.chartjs') +@include('layout.head.styles.datatables') +@include('layout.body.scripts.datatables') + +@push('page_scripts') + +@endpush diff --git a/app/src/Controller/Base.php b/app/src/Controller/Base.php index 2cd225d..99e56c1 100644 --- a/app/src/Controller/Base.php +++ b/app/src/Controller/Base.php @@ -18,7 +18,10 @@ class Base } return $this->login($response, $view); } - + public function construccion(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface + { + return $view->render($response, 'construccion'); + } protected function home(ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface { $cuotas_hoy = count($cuotaRepository->fetchHoy()) ?? 0; diff --git a/app/src/Controller/Provincias.php b/app/src/Controller/Provincias.php new file mode 100644 index 0000000..36c3a11 --- /dev/null +++ b/app/src/Controller/Provincias.php @@ -0,0 +1,28 @@ + $provincia_id, + 'comunas' => [] + ]; + try { + $comunas = $comunaRepository->fetchByProvincia($provincia_id); + usort($comunas, function(Model\Comuna $a, Model\Comuna $b) { + return strcmp($a->descripcion, $b->descripcion); + }); + $output['comunas'] = $comunas; + } catch (EmptyResult) {} + $response->getBody()->write(json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); + } +} diff --git a/app/src/Controller/Proyectos.php b/app/src/Controller/Proyectos.php index b54dadb..d38d09f 100644 --- a/app/src/Controller/Proyectos.php +++ b/app/src/Controller/Proyectos.php @@ -1,11 +1,12 @@ getBody()->write(json_encode($output)); return $response->withHeader('Content-Type', 'application/json'); } + public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface + { + $output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0]; + try { + $unidades = $unidadRepository->fetchByProyecto($proyecto_id); + $tipos = []; + foreach ($unidades as $unidad) { + if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) { + $tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = []; + } + $tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad; + } + foreach ($tipos as &$subtipo) { + usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) { + return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT)); + }); + } + $output['unidades'] = $tipos; + $output['total'] = count($unidades); + } catch (EmptyResult) {} + $response->getBody()->write(json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); + } } diff --git a/app/src/Controller/Regiones.php b/app/src/Controller/Regiones.php new file mode 100644 index 0000000..8d43598 --- /dev/null +++ b/app/src/Controller/Regiones.php @@ -0,0 +1,28 @@ + $region_id, + 'provincias' => [] + ]; + try { + $provincias = $provinciaRepository->fetchByRegion($region_id); + usort($provincias, function(Model\Provincia $a, Model\Provincia $b) { + return strcmp($a->descripcion, $b->descripcion); + }); + $output['provincias'] = $provincias; + } catch (EmptyResult) {} + $response->getBody()->write(json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); + } +} diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index e74e222..215bbeb 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -102,4 +102,13 @@ class Ventas $response->getBody()->write(json_encode($output)); return $response->withHeader('Content-Type', 'application/json'); } + public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface + { + $regiones = $regionRepository->fetchAll(); + usort($regiones, function(Model\Region $a, Model\Region $b) { + return $a->numeracion - $b->numeracion; + }); + $proyectos = $proyectoRepository->fetchAllActive(); + return $view->render($response, 'ventas.add', compact('regiones', 'proyectos')); + } } diff --git a/app/src/Controller/Ventas/Cuotas.php b/app/src/Controller/Ventas/Cuotas.php index 313dff8..731c151 100644 --- a/app/src/Controller/Ventas/Cuotas.php +++ b/app/src/Controller/Ventas/Cuotas.php @@ -2,61 +2,72 @@ namespace Incoviba\Controller\Ventas; use DateTimeImmutable; -use DateInterval; -use Incoviba\Common\Implement\Exception\EmptyResult; -use IntlDateFormatter; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Alias\View; use Incoviba\Repository; use Incoviba\Service; class Cuotas { - public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository): ResponseInterface + public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): ResponseInterface { - $cuotas = $cuotaRepository->fetchPendientes(); - $cuotas_pendientes = []; - $today = new DateTimeImmutable(); - $formatter = new IntlDateFormatter('es_ES'); - $formatter->setPattern('EEEE dd'); - foreach ($cuotas as $cuota) { - $date = new DateTimeImmutable($cuota['fecha']); - $day = clone $date; - $weekday = $date->format('N'); - if ($weekday > 5) { - $diff = 7 - $weekday + 1; - $day = $day->add(new DateInterval("P{$diff}D")); - } - $cuotas_pendientes []= [ - 'id' => $cuota['cuota_id'], - 'venta_id' => $cuota['venta_id'], - 'Proyecto' => $cuota['Proyecto'], - 'Departamento' => $cuota['Departamento'], - 'Valor' => $cuota['Valor'], - 'Dia' => $formatter->format($day), - 'Numero' => $cuota['Numero'], - 'Propietario' => $cuota['Propietario'], - 'Banco' => $cuota['Banco'], - 'Fecha Cheque' => $date->format('d-m-Y'), - 'Vencida' => $today->diff($date)->days, - 'Fecha ISO' => $date->format('Y-m-d') - ]; - } + $cuotas_pendientes = $cuotaService->pendientes(); return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes')); } + public function depositadas(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): ResponseInterface + { + $cuotas_depositadas = $cuotaService->depositadas(); + return $view->render($response, 'ventas.cuotas.abonar', compact('cuotas_depositadas')); + } public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); $cuota_id = $json->cuota_id; + $fecha = new DateTimeImmutable($json->fecha); $output = [ 'cuota_id' => $cuota_id, 'depositada' => false ]; try{ $cuota = $cuotaRepository->fetchById($cuota_id); - $output['depositada'] = $pagoService->depositar($cuota->pago); + $output['depositada'] = $pagoService->depositar($cuota->pago, $fecha); + } catch (EmptyResult) {} + $response->getBody()->write(json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); + } + public function abonar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $cuota_id = $json->cuota_id; + $fecha = new DateTimeImmutable($json->fecha); + $output = [ + 'cuota_id' => $cuota_id, + 'abonada' => false + ]; + try{ + $cuota = $cuotaRepository->fetchById($cuota_id); + $output['abonada'] = $pagoService->abonar($cuota->pago, $fecha); + } catch (EmptyResult) {} + $response->getBody()->write(json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); + } + public function devolver(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $cuota_id = $json->cuota_id; + $fecha = new DateTimeImmutable($json->fecha); + $output = [ + 'cuota_id' => $cuota_id, + 'devuelta' => false + ]; + try{ + $cuota = $cuotaRepository->fetchById($cuota_id); + $output['devuelta'] = $pagoService->devolver($cuota->pago, $fecha); } catch (EmptyResult) {} $response->getBody()->write(json_encode($output)); return $response->withHeader('Content-Type', 'application/json'); diff --git a/app/src/Controller/Ventas/Pagos.php b/app/src/Controller/Ventas/Pagos.php index 6d93342..882c39e 100644 --- a/app/src/Controller/Ventas/Pagos.php +++ b/app/src/Controller/Ventas/Pagos.php @@ -4,10 +4,16 @@ namespace Incoviba\Controller\Ventas; use DateTimeImmutable; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Incoviba\Common\Alias\View; +use Incoviba\Service; class Pagos { - public function depositar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface + public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface + { + return $view->render($response, 'ventas.pagos.pendientes'); + } + public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); @@ -15,7 +21,7 @@ class Pagos $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); return $response->withHeader('Content-Type', 'application/json'); } - public function abonar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface + public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); @@ -23,4 +29,40 @@ class Pagos $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); return $response->withHeader('Content-Type', 'application/json'); } + public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $pagos = $pagoService->getPendientes(); + $pagos_pendientes = []; + foreach ($pagos as $pago) { + $pagos_pendientes []= [ + 'id' => $pago->id + ]; + } + $response->getBody()->write(json_encode(['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)])); + return $response->withHeader('Content-Type', 'application/json'); + } + public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $pagos = $pagoService->getDepositados(); + $pagos_depositados = []; + foreach ($pagos as $pago) { + $pagos_depositados []= [ + 'id' => $pago->id + ]; + } + $response->getBody()->write(json_encode(['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)])); + return $response->withHeader('Content-Type', 'application/json'); + } + public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $pagos = $pagoService->getRebotes(); + $rebotes = []; + foreach ($pagos as $pago) { + $rebotes []= [ + 'id' => $pago->id + ]; + } + $response->getBody()->write(json_encode(['pagos' => $rebotes, 'total' => count($rebotes)])); + return $response->withHeader('Content-Type', 'application/json'); + } } diff --git a/app/src/Controller/Ventas/Propietarios.php b/app/src/Controller/Ventas/Propietarios.php index 6d119fc..aee848c 100644 --- a/app/src/Controller/Ventas/Propietarios.php +++ b/app/src/Controller/Ventas/Propietarios.php @@ -1,5 +1,6 @@ fetchById($propietario_rut); return $view->render($response, 'ventas.propietarios.show', compact('propietario')); } -} \ No newline at end of file + public function get(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Propietario $propietarioRepository, int $propietario_rut): ResponseInterface + { + $output = [ + 'rut' => $propietario_rut, + 'propietario' => null + ]; + try { + $output['propietario'] = $propietarioRepository->fetchById($propietario_rut); + } catch (EmptyResult) {} + $response->getBody()->write(json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); + } +} diff --git a/app/src/Model/Menu.php b/app/src/Model/Menu.php new file mode 100644 index 0000000..7d45894 --- /dev/null +++ b/app/src/Model/Menu.php @@ -0,0 +1,7 @@ +register('banco', (new Implement\Repository\Mapper()) ->setFunction(function($data) { return $this->bancoRepository->fetchById($data['banco']); diff --git a/app/src/Repository/Menu.php b/app/src/Repository/Menu.php new file mode 100644 index 0000000..c709285 --- /dev/null +++ b/app/src/Repository/Menu.php @@ -0,0 +1,62 @@ +setTable('menus'); + } + + public function create(?array $data = null): Define\Model + { + $map = (new Implement\Repository\MapperParser(['title'])) + ->register('url', (new Implement\Repository\Mapper()) + ->setDefault('')); + $model = $this->parseData(new Model\Menu(), $data, $map); + $model->children = $this->fetchChildren($model->id); + return $model; + } + public function save(Define\Model $model): Define\Model + { + $model->id = $this->saveNew( + ['title', 'url'], + [$model->title, $model->url] + ); + return $model; + } + public function edit(Define\Model $model, array $new_data): Define\Model + { + return $this->update($model, ['title', 'url'], $new_data); + } + + public function fetchByUser(int $user_id): array + { + $query = "SELECT a.* +FROM `{$this->getTable()}` a + JOIN `menu_permissions` mp ON mp.`menu_id` = a.`id` + JOIN `permissions` ON `permissions`.`id` = mp.`permission_id` + LEFT JOIN `users` u1 ON u1.`id` = `permissions`.`'ext_id` AND `permissions`.`type` = 2 + LEFT JOIN (SELECT u2.* FROM `roles` ON `roles`.`id` = `permissions`.`ext_id` AND `permissions`.`type` = 1 + JOIN `user_roles` ur ON ur.`role` = `role`.`id` + JOIN `users` u2 ON u2.`id` = ur.`user`) us + LEFT JOIN `menu_relations` mr ON mr.`child_id` = a.`id` +WHERE u1.`id` = ? OR us.`id` = ? AND mr.`id` IS NULL"; + return $this->fetchMany($query, [$user_id, $user_id]); + } + public function fetchChildren(int $menu_id): array + { + $query = "SELECT sm.* FROM `menu_relations` mr WHERE mr.`parent_id` = ?"; + try { + return $this->fetchMany($query, [$menu_id]); + } catch (Implement\Exception\EmptyResult) { + return []; + } + } +} diff --git a/app/src/Repository/Permission.php b/app/src/Repository/Permission.php new file mode 100644 index 0000000..9fc501e --- /dev/null +++ b/app/src/Repository/Permission.php @@ -0,0 +1,15 @@ +setTable('permissions'); + } +} diff --git a/app/src/Repository/Proyecto.php b/app/src/Repository/Proyecto.php index b8e6dff..03efa2c 100644 --- a/app/src/Repository/Proyecto.php +++ b/app/src/Repository/Proyecto.php @@ -23,8 +23,8 @@ class Proyecto extends Ideal\Repository ->setArgs([$data['inmobiliaria']]))) ->register('direccion', (new Implement\Repository\Mapper()) ->setFactory((new Implement\Repository\Factory()) - ->setCallable([$this->inmobiliariaRepository, 'fetchById']) - ->setArgs([$data['inmobiliaria']]))) + ->setCallable([$this->direccionRepository, 'fetchById']) + ->setArgs([$data['direccion']]))) ->register('superficie_terreno', (new Implement\Repository\Mapper()) ->setProperty('terreno') ->setFunction(function($data) { diff --git a/app/src/Repository/Venta/Cuota.php b/app/src/Repository/Venta/Cuota.php index 8dc4c0c..43c1ef8 100644 --- a/app/src/Repository/Venta/Cuota.php +++ b/app/src/Repository/Venta/Cuota.php @@ -106,6 +106,30 @@ FROM `{$this->getTable()}` a JOIN `banco` ON `banco`.`id` = `pago`.`banco` WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` < CURDATE() AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria') +ORDER BY `pago`.`fecha` DESC"; + return $this->fetchAsArray($query); + } + public function fetchDepositadas(): array + { + $query = "SELECT a.`id` AS 'cuota_id', `venta`.`id` AS 'venta_id', `proyecto`.`descripcion` AS 'Proyecto', `unidad`.`descripcion` AS 'Departamento', + `pago`.`valor` AS 'Valor', `pago`.`fecha`, CONCAT_WS(' - ', a.`numero`, `pie`.`cuotas`) AS 'Numero', `banco`.`nombre` AS 'Banco', ep.`fecha` AS 'Fecha Depositada', + CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) AS 'Propietario' +FROM `{$this->getTable()}` a + 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 `tipo_estado_pago` tep ON tep.`id` = ep.`estado` + JOIN `pie` ON `pie`.`id` = a.`pie` + JOIN `venta` ON `venta`.`pie` = a.`pie` + 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` + JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado` + JOIN `propietario` ON `propietario`.`rut` = `venta`.`propietario` + JOIN `propiedad_unidad` pu ON pu.`propiedad` = `venta`.`propiedad` + JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1 + JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt` + JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto` + JOIN `banco` ON `banco`.`id` = `pago`.`banco` +WHERE tep.`descripcion` = 'depositado' AND `pago`.`fecha` < CURDATE() + AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria') ORDER BY `pago`.`fecha` DESC"; return $this->fetchAsArray($query); } diff --git a/app/src/Service/Menu.php b/app/src/Service/Menu.php new file mode 100644 index 0000000..c2a6140 --- /dev/null +++ b/app/src/Service/Menu.php @@ -0,0 +1,44 @@ +getValid($user_id); + $output = []; + foreach ($menus as $menu) { + $output []= $this->buildItem($menu); + } + return implode(PHP_EOL, $output); + } + protected function buildItem(mixed $item): string + { + if (isset($item->submenus)) { + return $this->buildDropdown($item); + } + return "urls->base}}/{{$item->url}}\">{{$item->title}}"; + } + protected function buildDropdown(mixed $item): string + { + $output []= ''; + return implode(PHP_EOL, $output); + } + + public function getValid(int $user_id): array + { + return $this->menuRepository->fetchByUser($user_id); + } +} diff --git a/app/src/Service/Permission.php b/app/src/Service/Permission.php new file mode 100644 index 0000000..f729201 --- /dev/null +++ b/app/src/Service/Permission.php @@ -0,0 +1,9 @@ +cuotaRepository->fetchPendientes(); + $cuotas_pendientes = []; + $today = new DateTimeImmutable(); + $formatter = new IntlDateFormatter('es_ES'); + $formatter->setPattern('EEEE dd'); + foreach ($cuotas as $cuota) { + $date = new DateTimeImmutable($cuota['fecha']); + $day = clone $date; + $weekday = $date->format('N'); + if ($weekday > 5) { + $diff = 7 - $weekday + 1; + $day = $day->add(new DateInterval("P{$diff}D")); + } + $cuotas_pendientes []= [ + 'id' => $cuota['cuota_id'], + 'venta_id' => $cuota['venta_id'], + 'Proyecto' => $cuota['Proyecto'], + 'Departamento' => $cuota['Departamento'], + 'Valor' => $cuota['Valor'], + 'Dia' => $formatter->format($day), + 'Numero' => $cuota['Numero'], + 'Propietario' => $cuota['Propietario'], + 'Banco' => $cuota['Banco'], + 'Fecha Cheque' => $date->format('d-m-Y'), + 'Vencida' => $today->diff($date)->days, + 'Fecha ISO' => $date->format('Y-m-d') + ]; + } + return $cuotas_pendientes; + } + public function depositadas(): array + { + $cuotas = $this->cuotaRepository->fetchDepositadas(); + $cuotas_depositadas = []; + $today = new DateTimeImmutable(); + $formatter = new IntlDateFormatter('es_ES'); + $formatter->setPattern('EEEE dd'); + foreach ($cuotas as $cuota) { + $date = new DateTimeImmutable($cuota['fecha']); + $deposito = new DateTimeImmutable($cuota['Fecha Depositada']); + $cuotas_depositadas []= [ + 'id' => $cuota['cuota_id'], + 'venta_id' => $cuota['venta_id'], + 'Proyecto' => $cuota['Proyecto'], + 'Departamento' => $cuota['Departamento'], + 'Valor' => $cuota['Valor'], + 'Numero' => $cuota['Numero'], + 'Propietario' => $cuota['Propietario'], + 'Banco' => $cuota['Banco'], + 'Fecha Cheque' => $date->format('d-m-Y'), + 'Fecha ISO' => $date->format('Y-m-d'), + 'Fecha Depositada' => $deposito->format('d-m-Y') + ]; + } + return $cuotas_depositadas; + } +} diff --git a/app/src/Service/Venta/Pago.php b/app/src/Service/Venta/Pago.php index c11f8bb..0bd7041 100644 --- a/app/src/Service/Venta/Pago.php +++ b/app/src/Service/Venta/Pago.php @@ -1,6 +1,7 @@ tipoEstadoPagoRepository->fetchByDescripcion('depositado'); $data = [ 'pago' => $pago->id, 'estado' => $tipo_estado->id, - 'fecha' => (new DateTimeImmutable())->format('Y-m-d') + 'fecha' => $fecha->format('Y-m-d') + ]; + try { + $estado = $this->estadoPagoRepository->create($data); + $this->estadoPagoRepository->save($estado); + return true; + } catch (PDOException) { + return false; + } + } + public function abonar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool + { + $tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('abonado'); + $data = [ + 'pago' => $pago->id, + 'estado' => $tipo_estado->id, + 'fecha' => $fecha->format('Y-m-d') + ]; + try { + $estado = $this->estadoPagoRepository->create($data); + $this->estadoPagoRepository->save($estado); + return true; + } catch (PDOException) { + return false; + } + } + public function devolver(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool + { + $tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('devuelto'); + $data = [ + 'pago' => $pago->id, + 'estado' => $tipo_estado->id, + 'fecha' => $fecha->format('Y-m-d') ]; try { $estado = $this->estadoPagoRepository->create($data); @@ -35,4 +68,17 @@ class Pago $pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id); return $pago; } + + public function getPendientes(): array + { + return []; + } + public function getDepositados(): array + { + return []; + } + public function getRebotes(): array + { + return []; + } } diff --git a/incoviba.sql.gz b/incoviba.sql.gz new file mode 100644 index 0000000..3839f9c Binary files /dev/null and b/incoviba.sql.gz differ
Proyecto Departamento Departamento SortPropietarioCuotaBanco Valor DíaCuotaPropietarioBanco Fecha Cheque (Días) Fecha ISOFecha Deposito Depositar
{{str_pad($cuota['Departamento'], 4, '0', STR_PAD_LEFT)}}{{$cuota['Propietario']}}{{$cuota['Numero']}}{{$cuota['Banco']}} {{$format->pesos($cuota['Valor'])}} {{$cuota['Dia']}}{{$cuota['Numero']}}{{$cuota['Propietario']}}{{$cuota['Banco']}} {{$cuota['Fecha Cheque']}} ({{$cuota['Vencida']}}) {{$cuota['Fecha ISO']}} +
+
+ + +
+
+