Index: src/include/lib/Garradin/Compta/Import.php ================================================================== --- src/include/lib/Garradin/Compta/Import.php +++ src/include/lib/Garradin/Compta/Import.php @@ -237,186 +237,11 @@ { throw new UserException(sprintf('Ligne %s: %s', $line, $e->getMessage())); } } - $db->commit(); - - fclose($fp); - return true; - } - - public function fromCitizen($path) - { - if (!file_exists($path) || !is_readable($path)) - { - throw new \RuntimeException('Fichier inconnu : '.$path); - } - - $fp = fopen($path, 'r'); - - if (!$fp) - { - return false; - } - - $db = DB::getInstance(); - $db->begin(); - $comptes = new Comptes; - $banques = new Comptes_Bancaires; - $cats = new Categories; - $journal = new Journal; - - $columns = []; - $liste_comptes = $db->getAssoc('SELECT id, id FROM compta_comptes;'); - $liste_cats = $db->getAssoc('SELECT intitule, id FROM compta_categories;'); - $liste_moyens = $cats->listMoyensPaiement(); - - $get_compte = function ($compte, $intitule) use (&$liste_comptes, &$comptes, &$banques) - { - if (substr($compte, 0, 2) == '51') - { - $compte = '512' . substr($compte, -1); - } - - // Création comptes - if (!array_key_exists($compte, $liste_comptes)) - { - if (substr($compte, 0, 3) == '512') - { - $liste_comptes[$compte] = $banques->add([ - 'libelle' => $intitule, - 'banque' => 'Inconnue', - ]); - } - else - { - $liste_comptes[$compte] = $comptes->add([ - 'id' => $compte, - 'libelle' => $intitule, - 'parent' => substr($compte, 0, -1) - ]); - } - } - - return $compte; - }; - - $col = function($column) use (&$row, &$columns) - { - if (!isset($columns[$column])) - return null; - - if (!isset($row[$columns[$column]])) - return null; - - return $row[$columns[$column]]; - }; - - $line = 0; - $delim = Utils::find_csv_delim($fp); - Utils::skip_bom($fp); - - while (!feof($fp)) - { - $row = fgetcsv($fp, 4096, $delim); - $line++; - - if (empty($row)) - { - continue; - } - - if (empty($columns)) - { - if (empty($row[0])) - { - throw new UserException(sprintf('Erreur sur la ligne %d : la ligne est vide ?', $line)); - } - - $columns = $row; - $columns = array_flip($columns); - continue; - } - - $date = $col('Date'); - $date = \DateTime::createFromFormat('d/m/Y', $date); - - if (!$date) - { - $db->rollback(); - throw new UserException(sprintf('Erreur sur la ligne %d : la date "%s" n\'est pas au format jj/mm/aaaa.', $line, $col('Date'))); - } - - $date = $date->format('Y-m-d'); - - if ($db->test('compta_exercices', '(? < debut OR ? > fin) AND cloture = 0', $date, $date)) - { - continue; - } - - $debit = $get_compte($col('Compte débité - Numéro'), $col('Compte débité - Intitulé')); - $credit = $get_compte($col('Compte crédité - Numéro'), $col('Compte crédité - Intitulé')); - - $cat = $col('Rubrique'); - $moyen = strtoupper(substr($col('Moyen de paiement'), 0, 2)); - - if (!$moyen || !array_key_exists($moyen, $liste_moyens)) - { - $moyen = false; - $cat = false; - } - - if ($cat && !array_key_exists($cat, $liste_cats)) - { - if ($col('Nature') == 'Recette') - { - $type = $cats::RECETTES; - $compte = $credit; - } - elseif ($col('Nature') == 'Dépense') - { - $type = $cats::DEPENSES; - $compte = $debit; - } - else - { - $type = $cats::AUTRES; - $cat = false; - } - - if ($type != $cats::AUTRES) - { - $liste_cats[$cat] = $cats->add([ - 'intitule' => $cat, - 'type' => $type, - 'compte' => $compte - ]); - } - } - - $data = [ - 'libelle' => $col('Libellé'), - 'montant' => $col('Montant'), - 'date' => $date, - 'compte_credit' => $credit, - 'compte_debit' => $debit, - 'numero_piece' => $col('Numéro de pièce'), - 'remarques' => $col('Remarques'), - ]; - - if ($cat) - { - $data['moyen_paiement'] = $moyen; - $data['numero_cheque'] = $col('Numéro de chèque'); - $data['id_categorie'] = $liste_cats[$cat]; - } - - $journal->add($data); - } - $db->commit(); fclose($fp); return true; } } Index: src/templates/admin/compta/import.tpl ================================================================== --- src/templates/admin/compta/import.tpl +++ src/templates/admin/compta/import.tpl @@ -29,21 +29,10 @@
Si le fichier comporte des opérations dont la date est en dehors de l'exercice courant, Index: src/www/admin/compta/import.php ================================================================== --- src/www/admin/compta/import.php +++ src/www/admin/compta/import.php @@ -21,22 +21,18 @@ if (f('import')) { $form->check('compta_import', [ 'upload' => 'file|required', - 'type' => 'required|in:citizen,garradin', + 'type' => 'required|in:garradin', ]); if (!$form->hasErrors()) { try { - if (f('type') == 'citizen') - { - $import->fromCitizen($_FILES['upload']['tmp_name']); - } - elseif (f('type') == 'garradin') + if (f('type') == 'garradin') { $import->fromCSV($_FILES['upload']['tmp_name']); } else {