Ajout du support des écritures ventilées.
[garradin.git] / www / admin / compta / import.php
index 22a1137..b14fe02 100644 (file)
@@ -10,6 +10,7 @@ if ($user['droits']['compta'] < Membres::DROIT_ADMIN)
 
 $e = new Compta_Exercices;
 $import = new Compta_Import;
+$comptes = new Compta_Comptes;
 
 if (isset($_GET['export']))
 {
@@ -27,7 +28,7 @@ if (!empty($_POST['import']))
     {
         $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
     }
-    elseif (empty($_FILES['upload']['tmp_name']))
+    if (empty($_FILES['upload']['tmp_name']))
     {
         $error = 'Aucun fichier fourni.';
     }
@@ -35,13 +36,23 @@ if (!empty($_POST['import']))
     {
         try
         {
+            if (isset($_FILES['upload-plan-comptable']))
+            {
+              if (!$comptes->importPlan($_FILES['upload-plan-comptable']['tmp_name']))
+              {
+                  throw new UserException('Erreur lors de l’import du plan comptable');
+              }
+            }
             if (utils::post('type') == 'citizen')
             {
                 $import->fromCitizen($_FILES['upload']['tmp_name']);
             }
             elseif (utils::post('type') == 'garradin')
             {
-                $import->fromCSV($_FILES['upload']['tmp_name']);
+                if (!$import->fromCSV($_FILES['upload']['tmp_name']))
+                {
+                    throw new UserException('Erreur lors de l’import');
+                }
             }
             else
             {
@@ -62,4 +73,4 @@ $tpl->assign('ok', isset($_GET['ok']) ? true : false);
 
 $tpl->display('admin/compta/import.tpl');
 
-?>
\ No newline at end of file
+?>