Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/config/packages/backoffice_menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ parameters:
- admin_event_prices
- admin_event_prices_add
- admin_event_prices_edit
forum_facturation:
admin_event_factures:
nom: "Factures d'évènement"
niveau: 'ROLE_ADMIN'
url: '/admin/event/invoices'
extra_routes:
- admin_event_factures
talks:
nom: 'Conférences'
niveau: 'ROLE_FORUM'
Expand Down
24 changes: 24 additions & 0 deletions app/config/routing/admin_event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ admin_event_prices_edit:
event: \d+
id: \d+

admin_event_factures:
path: /invoices
defaults: {_controller: AppBundle\Controller\Admin\Event\Facturation\ListFacturesAction }

admin_event_factures_download_facture:
path: /invoices/download/invoice
defaults: {_controller: AppBundle\Controller\Admin\Event\Facturation\DownloadFactureAction }

admin_event_factures_download_devis:
path: /invoices/download/quotation
defaults: {_controller: AppBundle\Controller\Admin\Event\Facturation\DownloadDevisAction }

admin_event_factures_issue_facture:
path: /invoices/issue/invoice
defaults: {_controller: AppBundle\Controller\Admin\Event\Facturation\IssueFactureAction }

admin_event_factures_send_facture:
path: /invoices/send/invoice
defaults: {_controller: AppBundle\Controller\Admin\Event\Facturation\SendFactureAction }

admin_event_factures_delete_facture:
path: /invoices/delete/invoice/{token}
defaults: {_controller: AppBundle\Controller\Admin\Event\Facturation\DeleteFactureAction }

admin_event_speaker_infos:
path: /speaker-infos
defaults: {_controller: AppBundle\Controller\Admin\Event\SpeakerInfosAction }
Expand Down
24 changes: 12 additions & 12 deletions htdocs/templates/administration/forum_facturation.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ <h2>Factures d'évènement</h2>

{literal}
<script type="text/javascript">
$(".regle").dblclick(function() {
ref=$(this).attr('title');
dateCourante=$(this).attr('alt');
if ((dateCourante=='')) {
today = new Date();
dateCourante = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();
}
nouvelleDate=prompt('Entrez la nouvelle date', dateCourante);
if (nouvelleDate) {
window.location='index.php?page=forum_facturation&action=changer_date_reglement&ref=' + ref + '&reglement=' + nouvelleDate;
}
});
$(".regle").dblclick(function() {
ref=$(this).attr('title');
dateCourante=$(this).attr('alt');
if ((dateCourante=='')) {
today = new Date();
dateCourante = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();
}
nouvelleDate=prompt('Entrez la nouvelle date', dateCourante);
if (nouvelleDate) {
window.location='index.php?page=forum_facturation&action=changer_date_reglement&ref=' + ref + '&reglement=' + nouvelleDate;
}
});
</script>
{/literal}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Event\Facturation;

use AppBundle\AuditLog\Audit;
use AppBundle\Event\Invoice\InvoiceService;
use AppBundle\Event\Model\Invoice;
use AppBundle\Event\Model\Repository\InvoiceRepository;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;

class DeleteFactureAction extends AbstractController
{
public function __construct(
private readonly InvoiceRepository $invoiceRepository,
private readonly InvoiceService $invoiceService,
private readonly Audit $audit,
private readonly CsrfTokenManagerInterface $csrfTokenManager,
) {}

public function __invoke(Request $request, string $token): Response
{
if (!$this->csrfTokenManager->isTokenValid(new CsrfToken('event_invoice_delete', $token))) {
$this->addFlash('error', 'Token invalide');
return $this->redirectToRoute('admin_event_factures');
}

$reference = $request->query->get('ref');
$facture = $this->invoiceRepository->getByReference($reference);
if (!$facture instanceof Invoice) {
throw new NotFoundHttpException("Cette facture n'existe pas");
}

try {
$this->invoiceService->deleteInvoice($facture);
$this->audit->log('Supprimer => facture n°' . $reference);
$this->addFlash('notice', 'La facture est supprimée');
return $this->redirectToRoute('admin_event_factures');
} catch (Exception) {
}

$this->addFlash('error', "La facture n'a pas pu être supprimée");
return $this->redirectToRoute('admin_event_factures');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Event\Facturation;

use Afup\Site\Forum\Facturation;
use AppBundle\Event\Model\Invoice;
use AppBundle\Event\Model\Repository\InvoiceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class DownloadDevisAction extends AbstractController
{
public function __construct(
private readonly Facturation $facturation,
private readonly InvoiceRepository $invoiceRepository,
) {}

public function __invoke(Request $request): Response
{
$reference = $request->query->get('ref');
$devis = $this->invoiceRepository->getByReference($reference);
if (!$devis instanceof Invoice) {
throw new NotFoundHttpException("Ce devis n'existe pas");
}

ob_start();
$this->facturation->genererDevis($reference);
$pdf = ob_get_clean();

$response = new Response($pdf);
$response->headers->set('Content-Type', 'application/pdf');

return $response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Event\Facturation;

use Afup\Site\Forum\Facturation;
use AppBundle\Event\Model\Invoice;
use AppBundle\Event\Model\Repository\InvoiceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class DownloadFactureAction extends AbstractController
{
public function __construct(
private readonly Facturation $facturation,
private readonly InvoiceRepository $invoiceRepository,
) {}

public function __invoke(Request $request): Response
{
$reference = $request->query->get('ref');
$facture = $this->invoiceRepository->getByReference($reference);
if (!$facture instanceof Invoice) {
throw new NotFoundHttpException("Cette facture n'existe pas");
}

ob_start();
$this->facturation->genererFacture($reference);
$pdf = ob_get_clean();

$response = new Response($pdf);
$response->headers->set('Content-Type', 'application/pdf');

return $response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Event\Facturation;

use Afup\Site\Forum\Facturation;
use AppBundle\AuditLog\Audit;
use AppBundle\Event\Model\Invoice;
use AppBundle\Event\Model\Repository\InvoiceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class IssueFactureAction extends AbstractController
{
public function __construct(
private readonly InvoiceRepository $invoiceRepository,
private readonly Facturation $facturation,
private readonly Audit $audit,
) {}

public function __invoke(Request $request): Response
{
$reference = $request->query->get('ref');
$facture = $this->invoiceRepository->getByReference($reference);
if (!$facture instanceof Invoice) {
throw new NotFoundHttpException("Cette facture n'existe pas");
}

if ($this->facturation->estFacture($reference)) {
$this->audit->log('Facturation => facture n°' . $reference);
$this->addFlash('notice', 'La facture est prise en compte');
return $this->redirectToRoute('admin_event_factures');
}

$this->addFlash('error', "La facture n'a pas pu être prise en compte");
return $this->redirectToRoute('admin_event_factures');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Event\Facturation;

use AppBundle\Event\AdminEventSelection;
use AppBundle\Event\Model\Repository\InvoiceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Webmozart\Assert\Assert;

class ListFacturesAction extends AbstractController
{
public const VALID_SORTS = ['date_facture', 'reference', 'societe', 'montant', 'etat', 'facturation'];
public const VALID_DIRECTIONS = ['asc', 'desc'];

public function __construct(private readonly InvoiceRepository $invoiceRepository) {}

public function __invoke(AdminEventSelection $eventSelection, Request $request): Response
{
$event = $eventSelection->event;
$sort = $request->query->get('sort', 'date_facture');
$direction = $request->query->get('direction', 'desc');
Assert::inArray($sort, self::VALID_SORTS);
Assert::inArray($direction, self::VALID_DIRECTIONS);
$filter = $request->query->get('filter', '');
$invoices = $this->invoiceRepository->getByEventId($event->getId(), $sort, $direction, $filter);

return $this->render('admin/event/facturation/list.html.twig', [
'event' => $event,
'event_select_form' => $eventSelection->selectForm(),
'direction' => $direction,
'invoices' => $invoices,
'sort' => $sort,
'filter' => $filter,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Event\Facturation;

use Afup\Site\Forum\Facturation;
use AppBundle\AuditLog\Audit;
use AppBundle\Event\Model\Invoice;
use AppBundle\Event\Model\Repository\InvoiceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class SendFactureAction extends AbstractController
{
public function __construct(
private readonly Facturation $facturation,
private readonly InvoiceRepository $invoiceRepository,
private readonly Audit $audit,
) {}

public function __invoke(Request $request): Response
{
$reference = $request->query->get('ref');
$devis = $this->invoiceRepository->getByReference($reference);
if (!$devis instanceof Invoice) {
throw new NotFoundHttpException("Cette facture n'existe pas");
}

if ($this->facturation->envoyerFacture($reference)) {
$this->audit->log('Facturation => facture n°' . $reference);
$this->addFlash('notice', 'La facture a été envoyée');
return $this->redirectToRoute('admin_event_factures');
}

$this->addFlash('error', "La facture n'a pas pu être envoyée");
return $this->redirectToRoute('admin_event_factures');
}
}
16 changes: 16 additions & 0 deletions sources/AppBundle/Event/Model/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public function getLastEvent()
return $query->query($this->getCollection(new HydratorSingleObject()))->first();
}

public function getMostRecentEvent(): ?Event
{
$query = $this
->getQuery('SELECT id, path, titre, text, date_debut, date_fin, date_fin_appel_conferencier, date_fin_vente FROM afup_forum ORDER BY date_debut DESC')
;

return $query->query($this->getCollection(new HydratorSingleObject()))->first();
}

public function getNextEventForGithubUser(GithubUser $githubUser)
{
$events = $this
Expand Down Expand Up @@ -280,6 +289,13 @@ public function getAllActive(): CollectionInterface
return $query->query($this->getCollection(new HydratorSingleObject()));
}

public function getAllSortedByTitre(): CollectionInterface
{
$query = $this->getQuery('SELECT * FROM afup_forum ORDER BY titre ASC');

return $query->query($this->getCollection(new HydratorSingleObject()));
}

public static function initMetadata(SerializerFactoryInterface $serializerFactory, array $options = [])
{
$metadata = new Metadata($serializerFactory);
Expand Down
Loading
Loading