config
This commit is contained in:
85
app_old/app/Controller/Home.php
Normal file
85
app_old/app/Controller/Home.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Slim\Views\Blade as View;
|
||||
use Incoviba\old\Proyecto\Proyecto;
|
||||
|
||||
class Home
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
$dias = $this->getCantidadCuotasDias();
|
||||
$cierres = $this->getCierres();
|
||||
$pendientes = $this->getCantidadCuotasPendientes();
|
||||
$hoy = $this->getCantidadCuotasHoy();
|
||||
return $view->render($response, 'home', compact('pendientes', 'hoy', 'dias', 'cierres'));
|
||||
}
|
||||
|
||||
protected array $proyectos;
|
||||
protected function getProyectos(): array
|
||||
{
|
||||
if (!isset($this->proyectos)) {
|
||||
$this->proyectos = model(Proyecto::class)->findMany();
|
||||
}
|
||||
return $this->proyectos;
|
||||
}
|
||||
protected function getCantidadCuotasPendientes(): int
|
||||
{
|
||||
$pendientes = 0;
|
||||
$proyectos = $this->getProyectos();
|
||||
foreach ($proyectos as $proyecto) {
|
||||
$pendientes += $proyecto->cuotasPendientes();
|
||||
}
|
||||
return $pendientes;
|
||||
}
|
||||
protected function getCantidadCuotasDias(): array
|
||||
{
|
||||
$dias = [];
|
||||
$proyectos = $this->getProyectos();
|
||||
foreach ($proyectos as $proyecto) {
|
||||
foreach ($proyecto->cuotasMes() as $cuota) {
|
||||
$f = $cuota->pago()->fecha();
|
||||
if ($f->isoWeekday() == 6 or $f->isoWeekDay() == 7) {
|
||||
$f = $f->copy()->addDays(2)->startOfWeek();
|
||||
}
|
||||
$dia = $f->format('Y-m-d');
|
||||
if (!isset($dias[$dia])) {
|
||||
$dias[$dia] = [$proyecto->descripcion => 0];
|
||||
}
|
||||
if (!isset($dias[$dia][$proyecto->descripcion])) {
|
||||
$dias[$dia][$proyecto->descripcion] = 0;
|
||||
}
|
||||
$dias[$dia][$proyecto->descripcion] ++;
|
||||
}
|
||||
}
|
||||
uksort($dias, function($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
return $dias;
|
||||
}
|
||||
protected function getCantidadCuotasHoy(): int
|
||||
{
|
||||
$hoy = 0;
|
||||
$proyectos = $this->getProyectos();
|
||||
foreach ($proyectos as $proyecto) {
|
||||
$hoy += $proyecto->cuotasHoy();
|
||||
}
|
||||
return $hoy;
|
||||
}
|
||||
protected function getCierres(): array
|
||||
{
|
||||
$cierres = [];
|
||||
$proyectos = $this->getProyectos();
|
||||
foreach ($proyectos as $proyecto) {
|
||||
if (count($proyecto->cierres()) > 0) {
|
||||
$cierres[$proyecto->descripcion] = (object) ['total' => count($proyecto->cierres()),'vigentes' => $proyecto->cierres(3), 'rechazados' => $proyecto->cierres(-1), 'pendientes' => $proyecto->cierres(2)];
|
||||
}
|
||||
}
|
||||
uksort($cierres, function($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
return $cierres;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user