Separar datos inicio

This commit is contained in:
2023-10-11 09:03:44 -03:00
parent e4328d8604
commit 0d558b7980
9 changed files with 327 additions and 119 deletions

View File

@ -1,6 +1,7 @@
<?php
use Incoviba\Controller\Ventas\Cierres;
use Incoviba\Controller\API\Ventas\Cierres;
$app->group('/cierres', function($app) {
$app->get('/vigentes[/]', [Cierres::class, 'vigentes']);
$app->post('[/]', [Cierres::class, 'proyecto']);
});

View File

@ -0,0 +1,8 @@
<?php
use Incoviba\Controller\API\Ventas\Cuotas;
$app->group('/cuotas', function($app) {
$app->get('/hoy[/]', [Cuotas::class, 'hoy']);
$app->get('/pendiente[/]', [Cuotas::class, 'pendiente']);
$app->get('/vencer[/]', [Cuotas::class, 'porVencer']);
});

View File

@ -4,23 +4,83 @@
<div class="ui container">
<h4 class="ui header">Bienvenid@ {{$user->name}}</h4>
<div class="ui basic fitted segment">
@if ($cuotas_hoy > 0)
Existe{{$cuotas_hoy > 1 ? 'n' : ''}} {{$cuotas_hoy}} deposito{{$cuotas_hoy > 1 ? 's' : ''}} para hoy.
<br />
@endif
@if ($cuotas_pendientes > 0)
<a href="{{$urls->base}}/ventas/cuotas/pendientes">
Existe{{$cuotas_pendientes > 1 ? 'n' : ''}} {{$cuotas_pendientes}} cuota{{$cuotas_pendientes > 1 ? 's' : ''}} pendiente{{$cuotas_pendientes > 1 ? 's' : ''}}. <i class="right arrow icon"></i>
</a>
@endif
<span id="cuotas_hoy"></span>
<span id="cuotas_pendientes"></span>
</div>
<div class="ui two column grid">
<div class="column">
@include('home.cuotas_por_vencer')
</div>
<div class="column">
Alertas
</div>
<div class="column">
@include('home.cierres_vigentes')
</div>
</div>
</div>
@endsection
@push('page_scripts')
<script type="text/javascript">
const cuotas = {
get: function() {
return {
hoy: () => {
const span = $('#cuotas_hoy')
return fetch('{{$urls->api}}/ventas/cuotas/hoy').then(response => {
span.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
let output = 'Existe'
if (data.cuotas > 1) {
output += 'n'
}
output += ' ' + data.cuotas + ' deposito'
if (data.cuotas > 1) {
output += 's'
}
output += ' para hoy.<br />'
span.html(output)
})
},
pendiente: () => {
const span = $('#cuotas_pendientes')
return fetch('{{$urls->api}}/ventas/cuotas/pendiente').then(response => {
span.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
const link = $('<a></a>').attr('href', '{{$urls->base}}/ventas/cuotas/pendientes')
let output = 'Existe'
if (data.cuotas > 1) {
output += 'n'
}
output += ' ' + data.cuotas + ' cuota'
if (data.cuotas > 1) {
output += 's'
}
output += ' pendiente'
if (data.cuotas > 1) {
output += 's'
}
output += ' por cobrar. <i class="right arrow icon"></i>'
link.html(output)
span.html(link)
})
}
}
},
run: function() {
this.get().hoy()
this.get().pendiente()
}
}
$(document).ready(() => {
cuotas.run()
})
</script>
@endpush

View File

@ -1,24 +1,59 @@
<h4 class="ui dividing header">Cierres Vigentes</h4>
<div class="ui divided list">
@foreach($cierres_vigentes as $proyecto => $estados)
<div class="item">
<div class="ui feed">
<div class="date">
<strong>{{$proyecto}}</strong> [{{$estados['total']}}]
</div>
<div class="event">
<div class="content">Promesados</div>
<div class="meta">{{$estados['promesados']}}</div>
</div>
<div class="event">
<div class="content">Pendientes</div>
<div class="meta">{{$estados['pendientes']}}</div>
</div>
<div class="event">
<div class="content">Rechazados</div>
<div class="meta">{{$estados['rechazados']}}</div>
</div>
</div>
</div>
@endforeach
</div>
<div class="ui divided list" id="cierres_vigentes"></div>
@push('page_scripts')
<script type="text/javascript">
const cierres_vigentes = {
get: function() {
const list = $('#cierres_vigentes')
list.html('')
list.append(
$('<div><div>').addClass('ui inline active loader')
)
fetch('{{$urls->api}}/ventas/cierres/vigentes').then(response => {
list.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
this.draw(data.cierres)
})
},
draw: function(cierres) {
const list = $('#cierres_vigentes')
Object.entries(cierres).forEach(([proyecto, estados]) => {
const item = $('<div></div>').addClass('item')
const feed = $('<div></div>').addClass('ui feed')
feed.append(
$('<div></div>').addClass('date').append(
$('<strong></strong>').html(proyecto).append('[' + estados['total'] + ']')
)
).append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html('Promesados')
).append(
$('<div></div>').addClass('meta').html(estados['promesados'])
)
).append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html('Pendientes')
).append(
$('<div></div>').addClass('meta').html(estados['pendientes'])
)
).append(
$('<div></div>').addClass('event').append(
$('<div></div>').addClass('content').html('Rechazados')
).append(
$('<div></div>').addClass('meta').html(estados['rechazados'])
)
)
item.append(feed)
list.append(item)
})
}
}
$(document).ready(() => {
cierres_vigentes.get()
})
</script>
@endpush

View File

@ -1,22 +1,52 @@
<h4 class="ui dividing header">Cuotas Por Vencer</h4>
<div class="ui divided list">
@foreach ($cuotas_por_vencer as $date => $proyectos)
<div class="item">
<div class="ui feed">
<div class="date">
<strong>{{$format->localDate($date, "EEE. dd 'de' MMMM 'de' yyyy", true)}}</strong>
</div>
@foreach ($proyectos as $proyecto => $cuotas)
<div class="event">
<div class="content">
<span class="ui small text">
{{$proyecto}}
</span>
</div>
<div class="meta">{{$cuotas}}</div>
</div>
@endforeach
</div>
</div>
@endforeach
</div>
<div class="ui divided list" id="cuotas_por_vencer"></div>
@push('page_scripts')
<script type="text/javascript">
const cuotas_por_vencer = {
get: function() {
const list = $('#cuotas_por_vencer')
list.html('')
list.append(
$('<div><div>').addClass('ui inline active loader')
)
return fetch('{{$urls->api}}/ventas/cuotas/vencer').then(response => {
list.html('')
if (response.ok) {
return response.json()
}
}).then(data => {
this.draw(data.cuotas)
})
},
draw: function(cuotas) {
const list = $('#cuotas_por_vencer')
Object.entries(cuotas).forEach(([fecha, proyectos]) => {
const item = $('<div></div>').addClass('item')
const feed = $('<div></div>').addClass('ui feed')
feed.append(
$('<div></div>').addClass('date').append(
$('<strong></strong>').html(fecha)
)
)
Object.entries(proyectos).forEach(([proyecto, cuotas]) => {
const event = $('<div></div>').addClass('event')
event.append(
$('<div></div>').addClass('content').append(
$('<span></span>').addClass('ui small text').html(proyecto)
)
).append(
$('<div></div>').addClass('meta').html(cuotas)
)
feed.append(event)
})
item.append(feed)
list.append(item)
})
}
}
$(document).ready(() => {
cuotas_por_vencer.get()
})
</script>
@endpush

View File

@ -71,6 +71,8 @@
)
).append(
$('<td></td>').append(unidad)
).append(
$('<td></td>').append(this.unidad.descripcion.padStart(4, '0'))
).append(
$('<td></td>').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 $('<thead></thead>').append(
@ -168,6 +186,8 @@
$('<th></th>').html('Proyecto')
).append(
$('<th></th>').html('Unidad')
).append(
$('<th></th>').html('Unidad [Sort]')
).append(
$('<th></th>').html('Propietario')
).append(

View File

@ -0,0 +1,55 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository;
use Incoviba\Service;
class Cierres
{
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
{
$body = $request->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');
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use DateTimeImmutable;
use DateInterval;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Repository;
use Incoviba\Service;
class Cuotas
{
public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
{
$output = [
'cuotas' => 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');
}
}

View File

@ -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;
}
}