-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddTransactionAction.php
More file actions
40 lines (34 loc) · 1.41 KB
/
AddTransactionAction.php
File metadata and controls
40 lines (34 loc) · 1.41 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
<?php
declare(strict_types=1);
namespace AppBundle\Controller\Admin\Accounting\Journal;
use AppBundle\Accounting\Form\TransactionType;
use AppBundle\Accounting\Model\Repository\TransactionRepository;
use AppBundle\Accounting\Model\Transaction;
use AppBundle\AuditLog\Audit;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class AddTransactionAction extends AbstractController
{
public function __construct(
private readonly TransactionRepository $transactionRepository,
private readonly Audit $audit,
) {}
public function __invoke(Request $request): Response
{
$transaction = new Transaction();
$transaction->setAccountId(1); // Compte courant
$form = $this->createForm(TransactionType::class, $transaction);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->transactionRepository->save($transaction);
$this->audit->log("Ajout d'une écriture");
$this->addFlash('notice', "L'écriture a été ajoutée");
return $this->redirect('/admin/accounting/journal/list#L' . $transaction->getId());
}
return $this->render('admin/accounting/journal/add.html.twig', [
'form' => $form->createView(),
'operation' => 'add',
]);
}
}