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

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