src/Controller/InvoiceController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Invoice;
  4. use App\Service\CalendarEvent\CalendarEventService;
  5. use App\Service\Invoice\InvoiceService;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. class InvoiceController extends BaseAbstractController
  9. {
  10.     public function list(Request $requestInvoiceService $invoiceService,
  11.                          CalendarEventService $calendarEventService): Response
  12.     {
  13.         $userSettings $this->getLoggedInUser() ? $this->getLoggedInUser()->getSettings() : null;
  14.         $start $userSettings $userSettings->getStartCalendarEventsDate() : null;
  15.         $end $userSettings $userSettings->getEndCalendarEventsDate() : null;
  16.         /** @var Invoice[] $items */
  17.         $items $invoiceService->getList();
  18.         $items array_filter($items, function (Invoice $invoice) use ($start$end) {
  19.             $ce $invoice->getCandidate() ? $invoice->getCandidate()->getCalendarEvent() : null;
  20.             if (!$ce) {
  21.                 return true;
  22.             }
  23.             if ($start && $ce->getStartDate() < $start) {
  24.                 return false;
  25.             }
  26.             if ($end && $ce->getStartDate() > $end) {
  27.                 return false;
  28.             }
  29.             return true;
  30.         });
  31.         $calendarEvents $calendarEventService->getAll(["startDate""ASC"],
  32.             null$start$end);
  33.         return $this->render('admin/invoice/invoices.html.twig', [
  34.             'items' => $items,
  35.             'calendarEvents' => $calendarEvents,
  36.         ]);
  37.     }
  38. }