From ba5179da7e380d75e6bd0fd471092bb71612c472 Mon Sep 17 00:00:00 2001 From: vgreb Date: Tue, 30 Dec 2025 23:39:17 +0100 Subject: [PATCH] =?UTF-8?q?Refonte=20-=20Tr=C3=A9sorerie=20>=20Journal=20>?= =?UTF-8?q?=20T=C3=A9l=C3=A9charger=20un=20justificatif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routing/admin_accounting/journal.yml | 7 ++++ db/seeds/Compta.php | 21 ++++++++++ .../pages/administration/compta_journal.php | 37 ------------------ .../administration/compta_journal.html | 2 +- .../Journal/DownloadAttachmentAction.php | 39 +++++++++++++++++++ .../features/Admin/Tresorerie/Journal.feature | 18 +++++++++ 6 files changed, 86 insertions(+), 38 deletions(-) create mode 100644 sources/AppBundle/Controller/Admin/Accounting/Journal/DownloadAttachmentAction.php diff --git a/app/config/routing/admin_accounting/journal.yml b/app/config/routing/admin_accounting/journal.yml index e7f0f20b1..d9a8ab821 100644 --- a/app/config/routing/admin_accounting/journal.yml +++ b/app/config/routing/admin_accounting/journal.yml @@ -4,3 +4,10 @@ admin_accounting_journal_delete: _controller: AppBundle\Controller\Admin\Accounting\Journal\DeleteAction requirements: id: \d+ + +admin_accounting_journal_download: + path: /download/{id} + requirements: + id: '\d+' + defaults: + _controller: AppBundle\Controller\Admin\Accounting\Journal\DownloadAttachmentAction diff --git a/db/seeds/Compta.php b/db/seeds/Compta.php index fc8056e41..394bd83f6 100644 --- a/db/seeds/Compta.php +++ b/db/seeds/Compta.php @@ -92,6 +92,27 @@ public function run(): void 'date_regl' => null, 'idevenement' => 0, ], + [ + 'id' => '6', + 'date_ecriture' => '2024-03-10', + 'numero_operation' => 'BILL-XXX', + 'nom_frs' => '', + 'montant' => 42.5, + 'description' => 'une facture', + 'comment' => null, + 'attachment_required' => 1, + 'attachment_filename' => 'facture.pdf', + 'idcompte' => 1, + 'montant_ht_soumis_tva_20' => 34, + 'idclef' => 2, + 'numero' => '', + 'obs_regl' => '', + 'idoperation' => 0, + 'idcategorie' => 0, + 'idmode_regl' => 0, + 'date_regl' => null, + 'idevenement' => 0, + ], [ 'id' => '5', 'idoperation' => 1, diff --git a/htdocs/pages/administration/compta_journal.php b/htdocs/pages/administration/compta_journal.php index 79cf731a2..806a2f074 100755 --- a/htdocs/pages/administration/compta_journal.php +++ b/htdocs/pages/administration/compta_journal.php @@ -24,7 +24,6 @@ 'ventiler', 'modifier_colonne', 'export', - 'download_attachment', 'upload_attachment', ]); @@ -540,42 +539,6 @@ echo $e->getMessage(); } exit; -} - -/** - * Download a line attachment - */ elseif ($action === 'download_attachment') { - try { - // Bad request? - if (!isset($_GET['id']) || !($line = $compta->obtenir((int) $_GET['id']))) { - throw new Exception("Please verify parameters", 400); - } - - // Test line existence - if (!$line['id']) { - throw new Exception("Not found", 404); - } - - // Test file existence - $filename = AFUP_CHEMIN_RACINE . 'uploads' . DIRECTORY_SEPARATOR . $line['attachment_filename']; - if (!$line['attachment_filename'] || !is_file($filename)) { - throw new RuntimeException('File not found.'); - } - - // Download it - $finfo = new finfo(FILEINFO_MIME_TYPE); - $mime = $finfo->file($filename); - - header('Content-Type: ' . $mime); - header("Content-Transfer-Encoding: Binary"); - header("Content-disposition: attachment; filename=\"" . basename($filename) . "\""); - readfile($filename); - exit; - } catch (Exception $e) { - header('HTTP/1.1 400 Bad Request'); - header('X-Info: ' . $e->getMessage()); - } - exit; } elseif ($action == 'importer') { $formulaire = instancierFormulaire(); $formulaire->addElement('header', null , 'Import CSV'); diff --git a/htdocs/templates/administration/compta_journal.html b/htdocs/templates/administration/compta_journal.html index 5b34cfa16..f40a042c0 100644 --- a/htdocs/templates/administration/compta_journal.html +++ b/htdocs/templates/administration/compta_journal.html @@ -153,7 +153,7 @@

Journal

diff --git a/sources/AppBundle/Controller/Admin/Accounting/Journal/DownloadAttachmentAction.php b/sources/AppBundle/Controller/Admin/Accounting/Journal/DownloadAttachmentAction.php new file mode 100644 index 000000000..84bb6574a --- /dev/null +++ b/sources/AppBundle/Controller/Admin/Accounting/Journal/DownloadAttachmentAction.php @@ -0,0 +1,39 @@ +accountingRepository->get($id); + if (!$accounting instanceof Transaction) { + throw $this->createNotFoundException(); + } + + $path = $this->uploadDir . $accounting->getAttachmentFilename(); + if ($accounting->getAttachmentFilename() === null || !is_file($path)) { + throw $this->createNotFoundException('No attachment found'); + } + + return new BinaryFileResponse($path, Response::HTTP_OK, [ + 'Content-disposition' => 'attachment; filename="' . basename($path) . '"', + ], false); + } +} diff --git a/tests/behat/features/Admin/Tresorerie/Journal.feature b/tests/behat/features/Admin/Tresorerie/Journal.feature index a26236cc8..b1c650f47 100644 --- a/tests/behat/features/Admin/Tresorerie/Journal.feature +++ b/tests/behat/features/Admin/Tresorerie/Journal.feature @@ -97,3 +97,21 @@ Feature: Administration - Trésorerie - Journal When I am on "/pages/administration/index.php?page=compta_journal&id_periode=15" And I follow the button of tooltip "Supprimer la fiche de PRLV SEPA ONLINE SAS SCW SCALEWAY " Then I should see "L'écriture a été supprimée" + + @reloadDbWithTestData + Scenario: Compte journal Télécharger un justificatif + Given I am logged in as admin and on the Administration + When I follow "Journal" + And I follow "Afficher aussi les entrées pointées" + Then I should see "Une recette qui rapporte" + When I follow "Télécharger le justificatif" + Then the response header "Content-Disposition" should match '#^attachment; filename="test_file1.pdf"#' + + @reloadDbWithTestData + Scenario: Compte journal afficher les entrées déjà pointées + Given I am logged in as admin and on the Administration + When I follow "Journal" + And I follow "Afficher aussi les entrées pointées" + Then I should see "Une recette qui rapporte" + And I should see "Une dépense très utile" + And I should see "Une dépense moins utile"