From b72b38d9046899b2e996e292b3e8a616275dbfd9 Mon Sep 17 00:00:00 2001 From: vgreb Date: Wed, 31 Dec 2025 03:11:42 +0100 Subject: [PATCH] =?UTF-8?q?Refonte=20-=20Tr=C3=A9sorerie=20-=20Journal=20-?= =?UTF-8?q?=20Export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routing/admin_accounting/journal.yml | 5 + db/seeds/Compta.php | 24 +++- .../pages/administration/compta_journal.php | 93 +-------------- .../administration/compta_journal.html | 2 +- sources/Afup/Comptabilite/Comptabilite.php | 9 -- sources/AppBundle/Accounting/TvaZone.php | 23 ++++ .../Admin/Accounting/Journal/ExportAction.php | 106 ++++++++++++++++++ tests/behat/bootstrap/FeatureContext.php | 10 +- .../features/Admin/Tresorerie/Journal.feature | 8 +- tests/behat/files/admin_journal_export.csv | 3 + .../files/admin_journal_export_reconciled.csv | 5 + 11 files changed, 181 insertions(+), 107 deletions(-) create mode 100644 sources/AppBundle/Accounting/TvaZone.php create mode 100644 sources/AppBundle/Controller/Admin/Accounting/Journal/ExportAction.php create mode 100644 tests/behat/files/admin_journal_export.csv create mode 100644 tests/behat/files/admin_journal_export_reconciled.csv diff --git a/app/config/routing/admin_accounting/journal.yml b/app/config/routing/admin_accounting/journal.yml index d825c4268..5ef2494ca 100644 --- a/app/config/routing/admin_accounting/journal.yml +++ b/app/config/routing/admin_accounting/journal.yml @@ -28,3 +28,8 @@ admin_accounting_journal_import: path: /import defaults: _controller: AppBundle\Controller\Admin\Accounting\Journal\ImportAction + +admin_accounting_journal_export: + path: /export + defaults: + _controller: AppBundle\Controller\Admin\Accounting\Journal\ExportAction diff --git a/db/seeds/Compta.php b/db/seeds/Compta.php index 394bd83f6..1df98cc0e 100644 --- a/db/seeds/Compta.php +++ b/db/seeds/Compta.php @@ -28,7 +28,7 @@ public function run(): void 'date_regl' => date('Y-10-16'), 'date_ecriture' => date('Y-10-17'), 'description' => 'Une recette qui rapporte', - 'attachment_filename' => $path . '/test_file1.pdf', + 'attachment_filename' => $path . 'test_file1.pdf', 'idevenement' => 5, 'idclef' => '', 'idcompte' => 1, @@ -130,6 +130,28 @@ public function run(): void 'numero' => '', 'obs_regl' => '', ], + [ + 'id' => '7', + 'idoperation' => 1, + 'idcategorie' => 34, + 'nom_frs' => 'Le fournisseur', + 'tva_intra' => 'FR9912345', + 'tva_zone' => 'france', + 'montant' => 12003.00, + 'idmode_regl' => 2, + 'date_regl' => date('Y-11-14'), + 'date_ecriture' => date('Y-12-14'), + 'description' => 'Description dépense', + 'idevenement' => 5, + 'idcompte' => 1, + 'idclef' => null, + 'numero' => '003', + 'obs_regl' => 'CB003', + 'montant_ht_soumis_tva_20' => 10002.50, + 'montant_ht_soumis_tva_10' => 10911.82, + 'montant_ht_soumis_tva_5_5' => 11377.25, + 'montant_ht_soumis_tva_0' => 12003.00, + ], ]; $table = $this->table('compta'); diff --git a/htdocs/pages/administration/compta_journal.php b/htdocs/pages/administration/compta_journal.php index 264cdf1e2..aca9b103b 100755 --- a/htdocs/pages/administration/compta_journal.php +++ b/htdocs/pages/administration/compta_journal.php @@ -18,7 +18,6 @@ 'ajouter', 'modifier', 'modifier_colonne', - 'export', 'upload_attachment', ]); @@ -39,7 +38,7 @@ $periode_debut = $listPeriode[$id_periode - 1]['date_debut']; $periode_fin = $listPeriode[$id_periode - 1]['date_fin']; -if (in_array($action, ['lister', 'debit', 'credit', 'export'])) { +if (in_array($action, ['lister', 'debit', 'credit'])) { $alsoDisplayClassifed = isset($_GET['also_display_classifed_entries']) && $_GET['also_display_classifed_entries']; $smarty->assign('also_display_classifed_entries', $alsoDisplayClassifed); @@ -251,96 +250,6 @@ $smarty->assign('formulaire', genererFormulaire($formulaire)); -} elseif ($action === 'export') { - /* - * This action allows the admin to export the full period in a CSV file. - * This is really useful when you need to filter by columns using Excel. - */ - $journal = $compta->obtenirJournal('', $periode_debut, $periode_fin, !$alsoDisplayClassifed); - - // Pointer to output - $fp = fopen('php://output', 'w'); - - // CSV - $csvDelimiter = ';'; - $csvEnclosure = '"'; - $csvFilename = sprintf( - 'AFUP_%s_journal_from-%s_to-%s.csv', - date('Y-M-d'), - $periode_debut, - $periode_fin, - ); - - // headers - header('Content-Type: text/csv'); - header("Content-Transfer-Encoding: Binary"); - header("Content-disposition: attachment; filename=\"$csvFilename\""); - - // First line - $columns = [ - 'Date', - 'Compte', - 'Événement', - 'Catégorie', - 'Description', - 'Débit', - 'Crédit', - 'Règlement', - 'Commentaire', - 'Justificatif', - 'Nom justificatif', - 'Montant HT', - 'TVA', - 'Montant HT non soumis à TVA', - 'Montant HT soumis à TVA 5,5', - 'TVA 5,5', - 'Montant HT soumis à TVA 10', - 'TVA 10', - 'Montant HT soumis à TVA 20', - 'TVA 20', - "Zone de TVA", - ]; - fputcsv($fp, $columns, $csvDelimiter, $csvEnclosure); - - // Set the current local and get variables to use in number_format - $l = setlocale(LC_ALL, 'fr_FR.utf8'); - $locale = localeconv(); - - foreach ($journal as $line) { - $total = number_format((float) $line['montant'], 2, $locale['decimal_point'], $locale['thousands_sep']); - fputcsv( - $fp, - [ - $line['date_ecriture'], - $line['nom_compte'], - $line['evenement'], - $line['categorie'], - $line['description'], - $line['idoperation'] == 1 ? "-$total" : '', - $line['idoperation'] != 1 ? $total : '', - $line['reglement'], - $line['comment'], - $line['attachment_required'] ? 'Oui' : 'Non', - $line['attachment_filename'], - $line['montant_ht'], - $line['montant_tva'], - $line['montant_ht_0'], - $line['montant_ht_5_5'], - $line['montant_tva_5_5'], - $line['montant_ht_10'], - $line['montant_tva_10'], - $line['montant_ht_20'], - $line['montant_tva_20'], - Comptabilite::getTvaZoneLabel($line['tva_zone'], 'Non définie'), - ], - $csvDelimiter, - $csvEnclosure, - ); - } - - fclose($fp); - - exit; } /* diff --git a/htdocs/templates/administration/compta_journal.html b/htdocs/templates/administration/compta_journal.html index 199e8aae5..0f4856ed2 100644 --- a/htdocs/templates/administration/compta_journal.html +++ b/htdocs/templates/administration/compta_journal.html @@ -55,7 +55,7 @@

Journal