Cuando no tiene resultados en cuotas, entregar vacio
This commit is contained in:
@ -3,6 +3,7 @@ namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@ -15,44 +16,52 @@ class Cuotas
|
||||
public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'cuotas' => count($cuotaRepository->fetchHoy()) ?? 0
|
||||
'cuotas' => 0
|
||||
];
|
||||
try {
|
||||
$output['cuotas'] = count($cuotaRepository->fetchHoy());
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'cuotas' => count($cuotaRepository->fetchPendientes()) ?? 0
|
||||
'cuotas' => 0
|
||||
];
|
||||
try {
|
||||
$output['cuotas'] = count($cuotaRepository->fetchPendientes());
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
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');
|
||||
try {
|
||||
$cuotas = $cuotaRepository->fetchDatosPorVencer();
|
||||
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'];
|
||||
}
|
||||
$key = $formatService->localDate($fecha, "EEE. dd 'de' MMMM 'de' yyyy", true);
|
||||
if (!isset($output[$key])) {
|
||||
$output[$key] = [];
|
||||
foreach ($output as $key => $day) {
|
||||
uksort($day, function($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
$output[$key] = $day;
|
||||
}
|
||||
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;
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, ['cuotas' => $output]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user