<?php
namespace App\Controller;
use App\Entity\Invoice;
use App\Service\CalendarEvent\CalendarEventService;
use App\Service\Invoice\InvoiceService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class InvoiceController extends BaseAbstractController
{
public function list(Request $request, InvoiceService $invoiceService,
CalendarEventService $calendarEventService): Response
{
$userSettings = $this->getLoggedInUser() ? $this->getLoggedInUser()->getSettings() : null;
$start = $userSettings ? $userSettings->getStartCalendarEventsDate() : null;
$end = $userSettings ? $userSettings->getEndCalendarEventsDate() : null;
/** @var Invoice[] $items */
$items = $invoiceService->getList();
$items = array_filter($items, function (Invoice $invoice) use ($start, $end) {
$ce = $invoice->getCandidate() ? $invoice->getCandidate()->getCalendarEvent() : null;
if (!$ce) {
return true;
}
if ($start && $ce->getStartDate() < $start) {
return false;
}
if ($end && $ce->getStartDate() > $end) {
return false;
}
return true;
});
$calendarEvents = $calendarEventService->getAll(["startDate", "ASC"],
null, $start, $end);
return $this->render('admin/invoice/invoices.html.twig', [
'items' => $items,
'calendarEvents' => $calendarEvents,
]);
}
}