diff --git a/app/resources/routes/api/ventas/cierres.php b/app/resources/routes/api/ventas/cierres.php
index c242b05..414df64 100644
--- a/app/resources/routes/api/ventas/cierres.php
+++ b/app/resources/routes/api/ventas/cierres.php
@@ -1,6 +1,7 @@
group('/cierres', function($app) {
+ $app->get('/vigentes[/]', [Cierres::class, 'vigentes']);
$app->post('[/]', [Cierres::class, 'proyecto']);
});
diff --git a/app/resources/routes/api/ventas/cuotas.php b/app/resources/routes/api/ventas/cuotas.php
new file mode 100644
index 0000000..b895829
--- /dev/null
+++ b/app/resources/routes/api/ventas/cuotas.php
@@ -0,0 +1,8 @@
+group('/cuotas', function($app) {
+ $app->get('/hoy[/]', [Cuotas::class, 'hoy']);
+ $app->get('/pendiente[/]', [Cuotas::class, 'pendiente']);
+ $app->get('/vencer[/]', [Cuotas::class, 'porVencer']);
+});
diff --git a/app/resources/views/home.blade.php b/app/resources/views/home.blade.php
index 06597bf..9c25aaa 100644
--- a/app/resources/views/home.blade.php
+++ b/app/resources/views/home.blade.php
@@ -4,23 +4,83 @@
@include('home.cuotas_por_vencer')
+
+ Alertas
+
@include('home.cierres_vigentes')
@endsection
+
+@push('page_scripts')
+
+@endpush
diff --git a/app/resources/views/home/cierres_vigentes.blade.php b/app/resources/views/home/cierres_vigentes.blade.php
index fe974e0..06f6443 100644
--- a/app/resources/views/home/cierres_vigentes.blade.php
+++ b/app/resources/views/home/cierres_vigentes.blade.php
@@ -1,24 +1,59 @@
-
- @foreach($cierres_vigentes as $proyecto => $estados)
-
-
-
- {{$proyecto}} [{{$estados['total']}}]
-
-
-
Promesados
-
{{$estados['promesados']}}
-
-
-
Pendientes
-
{{$estados['pendientes']}}
-
-
-
Rechazados
-
{{$estados['rechazados']}}
-
-
-
- @endforeach
-
+
+
+@push('page_scripts')
+
+@endpush
diff --git a/app/resources/views/home/cuotas_por_vencer.blade.php b/app/resources/views/home/cuotas_por_vencer.blade.php
index a0df444..feb15c0 100644
--- a/app/resources/views/home/cuotas_por_vencer.blade.php
+++ b/app/resources/views/home/cuotas_por_vencer.blade.php
@@ -1,22 +1,52 @@
-
- @foreach ($cuotas_por_vencer as $date => $proyectos)
-
-
-
- {{$format->localDate($date, "EEE. dd 'de' MMMM 'de' yyyy", true)}}
-
- @foreach ($proyectos as $proyecto => $cuotas)
-
-
-
- {{$proyecto}}
-
-
-
{{$cuotas}}
-
- @endforeach
-
-
- @endforeach
-
+
+
+@push('page_scripts')
+
+@endpush
diff --git a/app/resources/views/search.blade.php b/app/resources/views/search.blade.php
index d81b1d1..6bcd790 100644
--- a/app/resources/views/search.blade.php
+++ b/app/resources/views/search.blade.php
@@ -71,6 +71,8 @@
)
).append(
$(' | ').append(unidad)
+ ).append(
+ $(' | ').append(this.unidad.descripcion.padStart(4, '0'))
).append(
$(' | ').append(propietario)
).append(
@@ -160,7 +162,23 @@
table.append(thead).append(tbody)
parent.append(table)
- this.table = new DataTable(table)
+ this.table = new DataTable(table, {
+ order: [
+ [0, 'asc'],
+ [2, 'asc']
+ ],
+ columnDefs: [
+ {
+ target: 2,
+ visible: false,
+ searchable: false
+ },
+ {
+ target: 1,
+ orderData: [2]
+ }
+ ]
+ })
},
head: () => {
return $('').append(
@@ -168,6 +186,8 @@
$(' | ').html('Proyecto')
).append(
$(' | ').html('Unidad')
+ ).append(
+ $(' | ').html('Unidad [Sort]')
).append(
$(' | ').html('Propietario')
).append(
diff --git a/app/src/Controller/API/Ventas/Cierres.php b/app/src/Controller/API/Ventas/Cierres.php
new file mode 100644
index 0000000..b07f15b
--- /dev/null
+++ b/app/src/Controller/API/Ventas/Cierres.php
@@ -0,0 +1,55 @@
+getBody();
+ $json = json_decode($body->getContents());
+ $proyecto_id = $json->proyecto_id;
+ $output = ['total' => 0];
+ try {
+ $cierres = $service->getByProyecto($proyecto_id);
+ $output['cierres'] = $cierres;
+ $output['total'] = count($cierres);
+ } catch (EmptyResult) {}
+ $response->getBody()->write(json_encode($output));
+ return $response->withHeader('Content-Type', 'application/json');
+ }
+ public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cierre $cierreRepository): ResponseInterface
+ {
+ $cierres = $cierreRepository->fetchDatosVigentes();
+ $output = [];
+ $estados = [
+ 'revisado' => 'pendientes',
+ 'rechazado' => 'rechazados',
+ 'aprobado' => 'pendientes',
+ 'vendido' => 'promesados',
+ 'abandonado' => 'rechazados',
+ 'promesado' => 'promesados',
+ 'resciliado' => 'rechazados'
+ ];
+ foreach ($cierres as $row) {
+ if (!isset($output[$row['Proyecto']])) {
+ $output[$row['Proyecto']] = [
+ 'promesados' => 0,
+ 'pendientes' => 0,
+ 'rechazados' => 0,
+ 'total' => 0
+ ];
+ }
+ $estado = $estados[$row['Estado']];
+ $output[$row['Proyecto']][$estado] += $row['Cantidad'];
+ $output[$row['Proyecto']]['total'] += $row['Cantidad'];
+ }
+ $response->getBody()->write(json_encode(['cierres' => $output]));
+ return $response->withHeader('Content-Type', 'application/json');
+ }
+}
diff --git a/app/src/Controller/API/Ventas/Cuotas.php b/app/src/Controller/API/Ventas/Cuotas.php
new file mode 100644
index 0000000..d81a016
--- /dev/null
+++ b/app/src/Controller/API/Ventas/Cuotas.php
@@ -0,0 +1,59 @@
+ count($cuotaRepository->fetchHoy()) ?? 0
+ ];
+ $response->getBody()->write(json_encode($output));
+ return $response->withHeader('Content-Type', 'application/json');
+ }
+ public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
+ {
+ $output = [
+ 'cuotas' => count($cuotaRepository->fetchPendientes()) ?? 0
+ ];
+ $response->getBody()->write(json_encode($output));
+ return $response->withHeader('Content-Type', 'application/json');
+ }
+ public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Format $formatService): ResponseInterface
+ {
+ $cuotas = $cuotaRepository->fetchDatosPorVencer();
+ $output = [];
+ foreach ($cuotas as $row) {
+ $fecha = $row['Fecha'];
+ $date = new DateTimeImmutable($fecha);
+ if (($weekday = $date->format('N')) > 5) {
+ $day_diff = 7 - $weekday + 1;
+ $date = $date->add(new DateInterval("P{$day_diff}D"));
+ $fecha = $date->format('Y-m-d');
+ }
+ $key = $formatService->localDate($fecha, "EEE. dd 'de' MMMM 'de' yyyy", true);
+ if (!isset($output[$key])) {
+ $output[$key] = [];
+ }
+ if (!isset($output[$key][$row['Proyecto']])) {
+ $output[$key][$row['Proyecto']] = 0;
+ }
+ $output[$key][$row['Proyecto']] += $row['Cantidad'];
+ }
+ foreach ($output as $key => $day) {
+ uksort($day, function($a, $b) {
+ return strcmp($a, $b);
+ });
+ $output[$key] = $day;
+ }
+ $response->getBody()->write(json_encode(['cuotas' => $output]));
+ return $response->withHeader('Content-Type', 'application/json');
+ }
+}
diff --git a/app/src/Controller/Base.php b/app/src/Controller/Base.php
index 99e56c1..15da3ec 100644
--- a/app/src/Controller/Base.php
+++ b/app/src/Controller/Base.php
@@ -11,10 +11,10 @@ use Incoviba\Repository;
class Base
{
- public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
+ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
{
if ($service->isIn()) {
- return $this->home($response, $view, $cuotaRepository, $cierreRepository);
+ return $this->home($response, $view);
}
return $this->login($response, $view);
}
@@ -22,72 +22,12 @@ class Base
{
return $view->render($response, 'construccion');
}
- protected function home(ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
+ protected function home(ResponseInterface $response, View $view): ResponseInterface
{
- $cuotas_hoy = count($cuotaRepository->fetchHoy()) ?? 0;
- $cuotas_pendientes = count($cuotaRepository->fetchPendientes()) ?? 0;
- $cuotas_por_vencer = $this->getCuotasPorVencer($cuotaRepository);
- $cierres_vigentes = $this->getCierresVigentes($cierreRepository);
- return $view->render($response, 'home', compact('cuotas_hoy', 'cuotas_pendientes', 'cuotas_por_vencer', 'cierres_vigentes'));
+ return $view->render($response, 'home');
}
protected function login(ResponseInterface $response, View $view): ResponseInterface
{
return $view->render($response, 'guest');
}
- protected function getCuotasPorVencer(Repository\Venta\Cuota $cuotaRepository): array
- {
- $cuotas = $cuotaRepository->fetchDatosPorVencer();
- $output = [];
- foreach ($cuotas as $row) {
- $fecha = $row['Fecha'];
- $date = new DateTimeImmutable($fecha);
- if (($weekday = $date->format('N')) > 5) {
- $day_diff = 7 - $weekday + 1;
- $date = $date->add(new DateInterval("P{$day_diff}D"));
- $fecha = $date->format('Y-m-d');
- }
- if (!isset($output[$fecha])) {
- $output[$fecha] = [];
- }
- if (!isset($output[$fecha][$row['Proyecto']])) {
- $output[$fecha][$row['Proyecto']] = 0;
- }
- $output[$fecha][$row['Proyecto']] += $row['Cantidad'];
- }
- foreach ($output as $fecha => $day) {
- uksort($day, function($a, $b) {
- return strcmp($a, $b);
- });
- $output[$fecha] = $day;
- }
- return $output;
- }
- protected function getCierresVigentes(Repository\Venta\Cierre $cierreRepository): array
- {
- $cierres = $cierreRepository->fetchDatosVigentes();
- $output = [];
- $estados = [
- 'revisado' => 'pendientes',
- 'rechazado' => 'rechazados',
- 'aprobado' => 'pendientes',
- 'vendido' => 'promesados',
- 'abandonado' => 'rechazados',
- 'promesado' => 'promesados',
- 'resciliado' => 'rechazados'
- ];
- foreach ($cierres as $row) {
- if (!isset($output[$row['Proyecto']])) {
- $output[$row['Proyecto']] = [
- 'promesados' => 0,
- 'pendientes' => 0,
- 'rechazados' => 0,
- 'total' => 0
- ];
- }
- $estado = $estados[$row['Estado']];
- $output[$row['Proyecto']][$estado] += $row['Cantidad'];
- $output[$row['Proyecto']]['total'] += $row['Cantidad'];
- }
- return $output;
- }
}