-
Notifications
You must be signed in to change notification settings - Fork 71
Refonte - Trésorerie - Journal - Export #2077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vgreb
wants to merge
1
commit into
afup:master
Choose a base branch
from
vgreb:refacto/accounting-journal-export
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace AppBundle\Accounting; | ||
|
|
||
| enum TvaZone: string | ||
| { | ||
| case France = 'france'; | ||
| case EuropeanUnion = 'ue'; | ||
| case OutsideEuropeanUnion = 'hors_ue'; | ||
| case Undefined = ''; | ||
|
|
||
| public function getLabel(): string | ||
| { | ||
| return match ($this) { | ||
| self::France => 'France', | ||
| self::EuropeanUnion => 'Union Européenne hors France', | ||
| self::OutsideEuropeanUnion => 'Hors Union Européenne', | ||
| self::Undefined => 'Non définie', | ||
| }; | ||
| } | ||
| } |
111 changes: 111 additions & 0 deletions
111
sources/AppBundle/Controller/Admin/Accounting/Journal/ExportAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace AppBundle\Controller\Admin\Accounting\Journal; | ||
|
|
||
| use AppBundle\Accounting\Model\Repository\TransactionRepository; | ||
| use AppBundle\Accounting\Model\Repository\InvoicingPeriodRepository; | ||
| use AppBundle\Accounting\TvaZone; | ||
| use SplFileObject; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\HttpFoundation\ResponseHeaderBag; | ||
|
|
||
| class ExportAction extends AbstractController | ||
| { | ||
| public function __construct( | ||
| private readonly InvoicingPeriodRepository $invoicingPeriodRepository, | ||
| private readonly TransactionRepository $accountingRepository, | ||
| ) {} | ||
|
|
||
| public function __invoke(Request $request): Response | ||
| { | ||
| $periodId = $request->query->has('periodId') && !empty($request->query->get('periodId')) ? $request->query->getInt('periodId') : null; | ||
| $withReconciled = $request->query->getBoolean('with_reconciled'); | ||
| $period = $this->invoicingPeriodRepository->getCurrentPeriod($periodId); | ||
|
|
||
| $entries = $this->accountingRepository->getEntriesPerInvoicingPeriod($period, !$withReconciled); | ||
|
|
||
| // CSV | ||
| $csvFilename = sprintf( | ||
| 'AFUP_%s_journal_from-%s_to-%s.csv', | ||
| date('Y-M-d'), | ||
| $period->getStartDate()->format('Y-m-d'), | ||
| $period->getEndDate()->format('Y-m-d'), | ||
| ); | ||
| $tmpFile = tempnam(sys_get_temp_dir(), $csvFilename); | ||
| $file = new SplFileObject($tmpFile, 'w'); | ||
| $csvDelimiter = ';'; | ||
| $csvEnclosure = '"'; | ||
|
|
||
| $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", | ||
| ]; | ||
| $file->fputcsv($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 ($entries as $entry) { | ||
| $total = number_format((float) $entry['montant'], 2, $locale['decimal_point'], $locale['thousands_sep']); | ||
| $file->fputcsv( | ||
| [ | ||
| $entry['date_ecriture'], | ||
| $entry['nom_compte'], | ||
| $entry['evenement'], | ||
| $entry['categorie'], | ||
| $entry['description'], | ||
| $entry['idoperation'] == 1 ? '-' . $total : '', | ||
| $entry['idoperation'] != 1 ? $total : '', | ||
| $entry['reglement'], | ||
| $entry['comment'], | ||
| $entry['attachment_required'] ? 'Oui' : 'Non', | ||
| $entry['attachment_filename'], | ||
| number_format((float) $entry['montant_ht'], 2, $locale['decimal_point'], $locale['thousands_sep']), | ||
| number_format((float) $entry['montant_tva'], 3, $locale['decimal_point'], $locale['thousands_sep']), | ||
| $entry['montant_ht_0'], | ||
| $entry['montant_ht_5_5'], | ||
| $entry['montant_tva_5_5'], | ||
| $entry['montant_ht_10'], | ||
| $entry['montant_tva_10'], | ||
| $entry['montant_ht_20'], | ||
| $entry['montant_tva_20'], | ||
| TvaZone::from((string) $entry['tva_zone'])->getLabel(), | ||
| ], | ||
| $csvDelimiter, | ||
| $csvEnclosure, | ||
| ); | ||
| } | ||
| $file->eof(); | ||
|
|
||
| $response = new BinaryFileResponse($file); | ||
| $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $csvFilename); | ||
| $response->deleteFileAfterSend(true); | ||
|
|
||
| return $response; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 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" | ||
| 2026-01-01;"Compte courant";AG;"A déterminer";"Description dépense 001";-12001.00;;;;Non;;0.00;0.000;;;;;;;;"Non définie" | ||
| 2026-01-02;"Compte courant";AG;"A déterminer";"Description recette 001";;12003.00;;;Non;;0.00;0.000;;;;;;;;"Non définie" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.