diff --git a/app/config/routing/admin_accounting/journal.yml b/app/config/routing/admin_accounting/journal.yml
index 515b67675..d825c4268 100644
--- a/app/config/routing/admin_accounting/journal.yml
+++ b/app/config/routing/admin_accounting/journal.yml
@@ -23,3 +23,8 @@ admin_accounting_journal_allocate:
_controller: AppBundle\Controller\Admin\Accounting\Journal\AllocateAction
requirements:
id: \d+
+
+admin_accounting_journal_import:
+ path: /import
+ defaults:
+ _controller: AppBundle\Controller\Admin\Accounting\Journal\ImportAction
diff --git a/htdocs/pages/administration/compta_journal.php b/htdocs/pages/administration/compta_journal.php
index bd1eef1c3..264cdf1e2 100755
--- a/htdocs/pages/administration/compta_journal.php
+++ b/htdocs/pages/administration/compta_journal.php
@@ -5,9 +5,6 @@
// Impossible to access the file itself
use Afup\Site\Comptabilite\Comptabilite;
use Afup\Site\Utils\Logs;
-use AppBundle\Compta\Importer\CreditMutuel;
-use AppBundle\Compta\Importer\CreditMutuelLivret;
-use AppBundle\Compta\Importer\Factory;
if (!defined('PAGE_LOADED_USING_INDEX')) {
trigger_error("Direct access forbidden.", E_USER_ERROR);
@@ -20,7 +17,6 @@
'credit',
'ajouter',
'modifier',
- 'importer',
'modifier_colonne',
'export',
'upload_attachment',
@@ -538,38 +534,4 @@
echo $e->getMessage();
}
exit;
-} elseif ($action == 'importer') {
- $formulaire = instancierFormulaire();
- $formulaire->addElement('header', null , 'Import CSV');
- $formulaire->addElement('file', 'fichiercsv', 'Fichier banque');
- $formulaire->addElement('select', 'banque', 'Banque', [
- CreditMutuel::CODE => 'Crédit Mutuel - Compte Courant',
- CreditMutuelLivret::CODE => 'Crédit Mutuel - Livret',
- ]);
-
- $formulaire->addElement('header', 'boutons' , '');
- $formulaire->addElement('submit', 'soumettre', 'Soumettre');
-
- if ($formulaire->validate()) {
- $valeurs = $formulaire->exportValues();
- $file = & $formulaire->getElement('fichiercsv');
- $tmpDir = __DIR__ . '/../../../tmp';
- if ($file->isUploadedFile()) {
- $file->moveUploadedFile($tmpDir, 'banque.csv');
- $importerFactory = new Factory();
- $importer = $importerFactory->create(
- $tmpDir . '/banque.csv',
- $valeurs['banque'],
- );
- $importer->initialize($tmpDir . '/banque.csv');
- if ($compta->extraireComptaDepuisCSVBanque($importer)) {
- Logs::log('Chargement fichier banque');
- afficherMessage('Le fichier a été importé', 'index.php?page=compta_journal&action=lister');
- } else {
- afficherMessage("Le fichier n'a pas été importé. Le format est-il valide ?", 'index.php?page=compta_journal&action=lister', true);
- }
- unlink($tmpDir . '/banque.csv');
- }
- }
- $smarty->assign('formulaire', genererFormulaire($formulaire));
}
diff --git a/htdocs/templates/administration/compta_journal.html b/htdocs/templates/administration/compta_journal.html
index 67226a483..199e8aae5 100644
--- a/htdocs/templates/administration/compta_journal.html
+++ b/htdocs/templates/administration/compta_journal.html
@@ -9,7 +9,7 @@
Journal
Ajouter
-
+
Importer un fichier CSV
diff --git a/sources/Afup/Comptabilite/Comptabilite.php b/sources/Afup/Comptabilite/Comptabilite.php
index 5ce71979e..f26c06335 100755
--- a/sources/Afup/Comptabilite/Comptabilite.php
+++ b/sources/Afup/Comptabilite/Comptabilite.php
@@ -720,7 +720,6 @@ public function extraireComptaDepuisCSVBanque(Importer $importer): bool
$enregistrement = $this->obtenirParNumeroOperation($numero_operation);
$operationQualified = $qualifier->qualify($operation);
-
if (!is_array($enregistrement)) {
$this->ajouter(
$operationQualified['idoperation'],
@@ -736,7 +735,7 @@ public function extraireComptaDepuisCSVBanque(Importer $importer): bool
$operationQualified['date_ecriture'],
'',
$operationQualified['evenement'],
- $operationQualified['numero_operation'],
+ $operationQualified['numero_operation'] ?? null,
$operationQualified['attachmentRequired'],
$operationQualified['montant_ht_soumis_tva_0'],
$operationQualified['montant_ht_soumis_tva_5_5'],
diff --git a/sources/AppBundle/Accounting/Form/TransactionsImportType.php b/sources/AppBundle/Accounting/Form/TransactionsImportType.php
new file mode 100644
index 000000000..24924f1b3
--- /dev/null
+++ b/sources/AppBundle/Accounting/Form/TransactionsImportType.php
@@ -0,0 +1,34 @@
+add('file', FileType::class, [
+ 'label' => 'Fichier banque',
+ 'required' => true,
+ 'constraints' => [
+ new Assert\File(mimeTypes: ['text/csv', 'text/plain'], mimeTypesMessage: 'Veuillez uploader un fichier CSV valide.'),
+ ],
+ ])->add('bankAccount', ChoiceType::class, [
+ 'label' => 'Banque',
+ 'required' => true,
+ 'choices' => [
+ 'Crédit Mutuel - Compte Courant' => CreditMutuel::CODE,
+ 'Crédit Mutuel - Livret' => CreditMutuelLivret::CODE,
+ ],
+ ]);
+ }
+}
diff --git a/sources/AppBundle/Controller/Admin/Accounting/Journal/ImportAction.php b/sources/AppBundle/Controller/Admin/Accounting/Journal/ImportAction.php
new file mode 100644
index 000000000..c99983be5
--- /dev/null
+++ b/sources/AppBundle/Controller/Admin/Accounting/Journal/ImportAction.php
@@ -0,0 +1,56 @@
+createForm(TransactionsImportType::class);
+ $form->handleRequest($request);
+ if ($form->isSubmitted() && $form->isValid()) {
+ $uploadedFile = $form->get('file')->getData();
+ if ($uploadedFile instanceof UploadedFile) {
+
+ $uploadedFile->move($this->uploadDir, 'banque.csv');
+ $importer = $this->importerFactory->create($this->uploadDir . 'banque.csv', $form->get('bankAccount')->getData());
+ if ($this->compta->extraireComptaDepuisCSVBanque($importer)) {
+ $this->audit->log('Chargement fichier banque');
+ $_SESSION['flash'] = "Le fichier a été importé";
+ $_SESSION['erreur'] = false;
+ $this->addFlash('notice', "Le fichier a été importé");
+ } else {
+ $_SESSION['flash'] = "Le fichier n'a pas été importé. Le format est-il valide ?";
+ $_SESSION['erreur'] = true;
+ $this->addFlash('error', "Le fichier n'a pas été importé. Le format est-il valide ?");
+ }
+ unlink($this->uploadDir . 'banque.csv');
+ return $this->redirect('/pages/administration/index.php?page=compta_journal&&action=lister');
+ }
+ }
+
+ return $this->render('admin/accounting/journal/import.html.twig', [
+ 'form' => $form->createView(),
+ ]);
+ }
+}
diff --git a/templates/admin/accounting/journal/import.html.twig b/templates/admin/accounting/journal/import.html.twig
new file mode 100644
index 000000000..9780398ca
--- /dev/null
+++ b/templates/admin/accounting/journal/import.html.twig
@@ -0,0 +1,43 @@
+{% extends 'admin/base_with_header.html.twig' %}
+
+{% form_theme form 'form_theme_admin.html.twig' %}
+
+{% block content %}
+ Importer un fichier
+
+ {{ form_start(form) }}
+
+
+
+
+
+
+ {{ form_row(form.file) }}
+ {{ form_row(form.bankAccount) }}
+
+
+
+
+
+
+
+
+ * indique un champ obligatoire
+
+
+
+ {{ form_end(form) }}
+
+{% endblock %}
diff --git a/tests/behat/features/Admin/Tresorerie/JournalImport.feature b/tests/behat/features/Admin/Tresorerie/JournalImport.feature
index 3e2b73f01..0cd4ebe3b 100644
--- a/tests/behat/features/Admin/Tresorerie/JournalImport.feature
+++ b/tests/behat/features/Admin/Tresorerie/JournalImport.feature
@@ -17,8 +17,8 @@ Feature: Administration - Trésorerie - Journal import
# On importe le fichier sur le crédit mutuel
When I follow "Importer un fichier CSV"
Then I should see "Import CSV"
- When I select "CMUT" from "banque"
- And I attach the file "test_credit_mutuel.csv" to "fichiercsv"
+ When I select "CMUT" from "transactions_import[bankAccount]"
+ And I attach the file "test_credit_mutuel.csv" to "transactions_import[file]"
And I press "Soumettre"
Then I should see "Le fichier a été importé"
# On vérifie que l'import s'est bien passé