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
5 changes: 5 additions & 0 deletions app/config/routing/admin_accounting/journal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ admin_accounting_journal_download:
id: '\d+'
defaults:
_controller: AppBundle\Controller\Admin\Accounting\Journal\DownloadAttachmentAction

admin_accounting_journal_download_attachments:
path: /download-attachments
defaults:
_controller: AppBundle\Controller\Admin\Accounting\Journal\DownloadAttachmentsAction
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ext-libxml": "*",
"ext-openssl": "*",
"ext-pdo": "*",
"ext-zip": "*",
"algolia/algoliasearch-client-php": "^3.4",
"beberlei/assert": "^2.9",
"captioning/captioning": "^2.6",
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 @@ -59,7 +59,7 @@ <h2>Journal</h2>
<i class="icon file"></i>
Exporter la période en CSV
</a>
<a href="index.php?page=compta_banque&amp;action=download_attachments&amp;id_periode={$smarty.get.id_periode|default:''}" class="item">
<a href="/admin/accounting/journal/download-attachments?periodId={$smarty.get.id_periode|default:''}" class="item">
<i class="icon file zip"></i>
Télécharger les justificatifs groupés par mois
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Accounting\Journal;

use AppBundle\Accounting\Model\Repository\InvoicingPeriodRepository;
use DateInterval;
use DatePeriod;
use RuntimeException;
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;
use ZipArchive;

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

public function __invoke(Request $request): Response
{
$periodId = $request->query->has('periodId') && $request->query->get('periodId') ? (int) $request->query->get('periodId') : null;
$period = $this->invoicingPeriodRepository->getCurrentPeriod($periodId);
$year = $period->getStartDate()->format('Y');

// Create the zip
$zipFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'afup_justificatifs-' . $year . '.zip';
$zip = new ZipArchive();
$state = $zip->open($zipFilename, ZipArchive::CREATE);
if ($state !== true) {
throw new RuntimeException("Impossible to open the Zip archive.");
}

$datePeriod = new DatePeriod($period->getStartDate(), new DateInterval('P1M'), $period->getEndDate());
/** @var \DateTime $month */
foreach ($datePeriod as $month) {
$directory = $year . $month->format('m');
$options = [
'add_path' => 'afup_justificatifs-' . $year . '/' . $directory . '/',
'remove_all_path' => true,
];
$zip->addGlob($this->uploadDir . $directory . '/*.*', 0, $options);
}
$zip->close();

$response = new BinaryFileResponse($zipFilename, Response::HTTP_OK, [
'Content-Type' => 'application/zip',
'Content-Transfer-Encoding' => 'Binary',
'Content-Disposition' => 'attachment; filename="' . basename($zipFilename) . '"',
'Cache-Control' => 'max-age=0',
], false);
$response->deleteFileAfterSend(true);

return $response;
}
}
2 changes: 1 addition & 1 deletion tests/behat/features/Admin/Tresorerie/Journal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Feature: Administration - Trésorerie - Journal
Given I am logged in as admin and on the Administration
When I follow "Journal"
And I follow "Télécharger les justificatifs groupés par mois"
Then the response header "Content-disposition" should match '#filename="afup_justificatifs-(.*).zip"#'
Then the response header "Content-Disposition" should match '#filename="afup_justificatifs-(.*).zip"#'

@reloadDbWithTestData
Scenario: Compte journal Suppression d'une transaction
Expand Down