Overview
SHA1:789d2ab164e8a0ef6088831217ec05e9f38506d2
Date: 2018-10-01 21:28:43
User: bohwaz
Comment:Refactorisation export CSV/ODS fonctionnel
Timelines: family | ancestors | descendants | both | dev
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2018-10-02
15:55
[a87b08c0b9] Préparation à ajouter des actions pour les listes de membres (user: bohwaz, tags: dev)
2018-10-01
21:28
[789d2ab164] Refactorisation export CSV/ODS fonctionnel (user: bohwaz, tags: dev)
18:00
[72b8ff6c0f] Mise en commun export CSV/ODS (+ simplification) (user: bohwaz, tags: dev)
Changes

Modified src/include/lib/Garradin/Compta/Import.php from [8af5b583d1] to [dbc9be8854].

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

namespace Garradin\Compta;

use \Garradin\DB;
use \Garradin\Utils;
use \Garradin\UserException;

use KD2\ODSWriter;


class Import
{
	protected $header = [
		'Numéro mouvement',
		'Date',
		'Type de mouvement',
................................................................................
	protected function exportName()
	{
		return sprintf('Export comptabilité - %s - %s', Config::getInstance()->get('nom_asso'), date('Y-m-d'));
	}

	public function toCSV($exercice)
	{
		return Utils::toCSV($this->exportName(), $this->export());
	}

	public function toODS($exercice)
	{
		return Utils::toODS($this->exportName(), $this->export());
	}

	public function fromCSV($path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);




|
|
|
<
<
>







 







|




|







1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

namespace Garradin\Compta;

use Garradin\DB;
use Garradin\Utils;
use Garradin\UserException;


use Garradin\Config;

class Import
{
	protected $header = [
		'Numéro mouvement',
		'Date',
		'Type de mouvement',
................................................................................
	protected function exportName()
	{
		return sprintf('Export comptabilité - %s - %s', Config::getInstance()->get('nom_asso'), date('Y-m-d'));
	}

	public function toCSV($exercice)
	{
		return Utils::toCSV($this->exportName(), $this->export($exercice));
	}

	public function toODS($exercice)
	{
		return Utils::toODS($this->exportName(), $this->export($exercice));
	}

	public function fromCSV($path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);

Modified src/include/lib/Garradin/Membres/Import.php from [b0e7e2ae10] to [5ce42c5c94].

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

use Garradin\Membres;
use Garradin\Config;
use Garradin\DB;
use Garradin\Utils;
use Garradin\UserException;

use KD2\ODSWriter;

class Import
{
	public function getCSVAsArray($path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);







<
<







4
5
6
7
8
9
10


11
12
13
14
15
16
17

use Garradin\Membres;
use Garradin\Config;
use Garradin\DB;
use Garradin\Utils;
use Garradin\UserException;



class Import
{
	public function getCSVAsArray($path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);

Modified src/include/lib/Garradin/Utils.php from [1b2b85687d] to [ced173fcb5].

2
3
4
5
6
7
8

9
10
11
12
13
14
15
...
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732

namespace Garradin;

use KD2\Security;
use KD2\Form;
use KD2\Translate;
use KD2\SMTP;


class Utils
{
    static protected $skriv = null;

    static private $french_date_names = [
        'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai',
................................................................................
        header(sprintf('Content-Disposition: attachment; filename="%s.ods"', $name));

        $ods = new ODSWriter;
        $ods->table_name = $name;

        if ($header)
        {
            $ods->add($header);
        }

        foreach ($iterator as $row)
        {
            if (!$header)
            {
                $ods->add(array_keys($row));
                $header = true;
            }

            $ods->add($row);
        }

        $ods->output();

        return true;
    }








>







 







|










|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733

namespace Garradin;

use KD2\Security;
use KD2\Form;
use KD2\Translate;
use KD2\SMTP;
use KD2\ODSWriter;

class Utils
{
    static protected $skriv = null;

    static private $french_date_names = [
        'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai',
................................................................................
        header(sprintf('Content-Disposition: attachment; filename="%s.ods"', $name));

        $ods = new ODSWriter;
        $ods->table_name = $name;

        if ($header)
        {
            $ods->add((array) $header);
        }

        foreach ($iterator as $row)
        {
            if (!$header)
            {
                $ods->add(array_keys($row));
                $header = true;
            }

            $ods->add((array) $row);
        }

        $ods->output();

        return true;
    }

Modified src/www/admin/compta/import.php from [7e73141123] to [d14bd1f9b9].

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$session->requireAccess('compta', Membres::DROIT_ADMIN);

$e = new Compta\Exercices;
$import = new Compta\Import;

if (qg('export') == 'csv')
{
    header('Content-type: application/csv');
    header('Content-Disposition: attachment; filename="Export comptabilité - ' . $config->get('nom_asso') . ' - ' . date('Y-m-d') . '.csv"');
    $import->toCSV($e->getCurrentId());
    exit;
}
elseif (qg('export') == 'ods')
{
    header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
    header('Content-Disposition: attachment; filename="Export comptabilité - ' . $config->get('nom_asso') . ' - ' . date('Y-m-d') . '.ods"');
    $import->toODS($e->getCurrentId());
    exit;
}

if (f('import'))
{
    $form->check('compta_import', [







<
<





<
<







6
7
8
9
10
11
12


13
14
15
16
17


18
19
20
21
22
23
24
$session->requireAccess('compta', Membres::DROIT_ADMIN);

$e = new Compta\Exercices;
$import = new Compta\Import;

if (qg('export') == 'csv')
{


    $import->toCSV($e->getCurrentId());
    exit;
}
elseif (qg('export') == 'ods')
{


    $import->toODS($e->getCurrentId());
    exit;
}

if (f('import'))
{
    $form->check('compta_import', [