-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathEditInvoiceAction.php
More file actions
47 lines (40 loc) · 1.67 KB
/
EditInvoiceAction.php
File metadata and controls
47 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace AppBundle\Controller\Admin\Accounting\Invoice;
use AppBundle\Accounting\Form\InvoiceType;
use AppBundle\Accounting\Model\Invoicing;
use AppBundle\Accounting\Model\Repository\InvoicingRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class EditInvoiceAction extends AbstractController
{
public function __construct(
private readonly InvoicingRepository $invoicingRepository,
) {}
public function __invoke(Request $request): Response
{
$invoiceId = $request->query->getInt('invoiceId');
$invoice = $this->invoicingRepository->getById($invoiceId);
if (!$invoice instanceof Invoicing) {
throw $this->createNotFoundException("Cette facture n'existe pas");
}
$form = $this->createForm(InvoiceType::class, $invoice);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$this->invoicingRepository->save($invoice);
$this->addFlash('success', 'L\'écriture a été modifiée');
return $this->redirectToRoute('admin_accounting_invoices_list');
} catch (\Exception $e) {
$this->invoicingRepository->rollback();
$this->addFlash('error', 'L\'écriture n\'a pas pu être enregistrée');
}
}
return $this->render('admin/accounting/invoice/edit.html.twig', [
'invoice' => $invoice,
'form' => $form->createView(),
'submitLabel' => 'Modifier',
]);
}
}