Overview
Comment:Refactorisation export CSV/ODS fonctionnel
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 789d2ab164e8a0ef6088831217ec05e9f38506d2
User & Date: bohwaz on 2018-10-01 21:28:43
Other Links: branch diff | manifest | tags
Context
2018-10-02
15:55
Préparation à ajouter des actions pour les listes de membres check-in: a87b08c0b9 user: bohwaz tags: dev
2018-10-01
21:28
Refactorisation export CSV/ODS fonctionnel check-in: 789d2ab164 user: bohwaz tags: dev
18:00
Mise en commun export CSV/ODS (+ simplification) check-in: 72b8ff6c0f 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
<?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',




|
|
|
|
<







1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
<?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',
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	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);







|




|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	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].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

namespace Garradin\Membres;

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);










<
<







1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
<?php

namespace Garradin\Membres;

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].

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
<?php

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',








>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

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',
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
        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;
    }








|










|







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
        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].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$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', [












<
<





<
<







1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17


18
19
20
21
22
23
24
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$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', [