Skip to content
Merged
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
7 changes: 7 additions & 0 deletions app/config/routing/admin_accounting/journal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions db/seeds/Compta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 0 additions & 37 deletions htdocs/pages/administration/compta_journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
'ventiler',
'modifier_colonne',
'export',
'download_attachment',
'upload_attachment',
]);

Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion htdocs/templates/administration/compta_journal.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ <h2>Journal</h2>
<a
{if !$ecriture.attachment_filename}style="display:none;"{/if}
class="js-has-attachment"
href="index.php?page=compta_journal&amp;action=download_attachment&amp;id={$ecriture.idtmp}"
href="/admin/accounting/journal/download/{$ecriture.idtmp}"
title="Télécharger le justificatif"
>
<i class="paperclip icon"></i>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Accounting\Journal;

use AppBundle\Accounting\Model\Transaction;
use AppBundle\Accounting\Model\Repository\TransactionRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class DownloadAttachmentAction extends AbstractController
{
public function __construct(
private readonly TransactionRepository $accountingRepository,
#[Autowire('%kernel.project_dir%/../htdocs/uploads/')]
private readonly string $uploadDir,
) {}

public function __invoke(Request $request, int $id): Response
{
$accounting = $this->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);
}
}
18 changes: 18 additions & 0 deletions tests/behat/features/Admin/Tresorerie/Journal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"