Overview
Comment:Faire en sorte que le graph corresponde à quelque chose de correct
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ded6bb9c5b47c86d344fd1f5f2d6f4b3a5c4b96e
User & Date: bohwaz on 2012-10-16 04:27:52
Other Links: manifest | tags
Context
2012-10-16
04:37
Si pas de données, ne pas les traiter check-in: d3ff32844b user: bohwaz tags: trunk
04:27
Faire en sorte que le graph corresponde à quelque chose de correct check-in: ded6bb9c5b user: bohwaz tags: trunk
2012-10-15
22:57
Fix _SESSION not set check-in: 8d4cd100b9 user: bohwaz tags: trunk
Changes

Modified include/class.compta_stats.php from [09edc60f74] to [973311ee4b].

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

48
49
50

51
52
53


54
55
56

57
58

59

60

61
62



63
64
65
66
67
68
<?php

require_once __DIR__ . '/class.compta_comptes.php';

class Garradin_Compta_Stats
{
	public function recettes()
	{

		return $this->getStats('SELECT date, SUM(montant) FROM compta_journal
			WHERE id_categorie IN (SELECT id FROM compta_categories WHERE type = -1)

			AND date > ?

			GROUP BY date ORDER BY date;');



	}

	public function depenses()
	{
		return $this->getStats('SELECT date, SUM(montant) FROM compta_journal
			WHERE id_categorie IN (SELECT id FROM compta_categories WHERE type = 1)
			AND date > ?
			GROUP BY date ORDER BY date;');
	}

	public function actif()
	{
		return $this->getStats('SELECT date, (SELECT SUM(sub.montant) FROM compta_journal AS sub WHERE sub.date <= date)
			FROM compta_journal WHERE compte_credit IN (SELECT id FROM compta_comptes
				WHERE position = '.(int)Garradin_Compta_Comptes::ACTIF.')
			AND date > ?
			GROUP BY date ORDER BY date;');
	}

	public function passif()
	{
		return $this->getStats('SELECT date, (SELECT SUM(sub.compte_debit) FROM compta_journal AS sub WHERE sub.date <= date)
			FROM compta_journal WHERE compte_debit IN (SELECT id FROM compta_comptes
				WHERE position = '.(int)Garradin_Compta_Comptes::PASSIF.')
			AND date > ?
			GROUP BY date ORDER BY date;');
	}

	public function getStats($query)
	{
		$db = Garradin_DB::getInstance();

		$start = strtotime('1 month ago');

		$data = $db->simpleStatementFetchAssoc($query, date('Y-m-d', $start));


		$now = $start;
		$today = time();


		while ($now < $today)
		{


			$day = date('Y-m-d', $now);

			if (!array_key_exists($day, $data))

			{
				$data[$day] = 0;

			}



			$now = strtotime('+1 day', $now);
		}




		return $data;
	}
}

?>






|

>
|
|
>
|
>
|
>
>
>




|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






|

|
>

|
|
>

|

>
>
|
|
|
>

|
>

>
|
>
|
|
>
>
>






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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

require_once __DIR__ . '/class.compta_comptes.php';

class Garradin_Compta_Stats
{
	protected function _byType($type)
	{
		return $this->getStats('SELECT strftime(\'%Y%m\', date) AS date,
			SUM(montant) FROM compta_journal
			WHERE id_categorie IN (SELECT id FROM compta_categories WHERE type = '.$type.')
			AND id_exercice = (SELECT id FROM compta_exercices WHERE cloture = 0)
			GROUP BY strftime(\'%Y-%m\', date) ORDER BY date;');
	}

	public function recettes()
	{
		return $this->_byType(-1);
	}

	public function depenses()
	{
		return $this->_byType(1);





















	}

	public function getStats($query)
	{
		$db = Garradin_DB::getInstance();

		$data = $db->simpleStatementFetchAssoc($query);

		$e = $db->querySingle('SELECT *, strftime(\'%s\', debut) AS debut,
			strftime(\'%s\', fin) AS fin FROM compta_exercices WHERE cloture = 0;', true);

		$y = date('Y', $e['debut']);
		$m = date('m', $e['debut']);
		$max = date('Ym', $e['fin']);

		while ($y . $m <= $max)
		{
			if (!isset($data[$y . $m]))
			{
				$data[$y . $m] = 0;
			}

			if ($m == 12)
			{
				$m = '01';
				$y++;
			}
			else
			{
				$m++;
				$m = str_pad((int)$m, 2, '0', STR_PAD_LEFT);
			}
		}

		ksort($data);

		return $data;
	}
}

?>

Modified templates/admin/compta/index.tpl from [24a5537e1b] to [531faae92a].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{include file="admin/_head.tpl" title="Comptabilité" current="compta"}

<p class="alert">
    <strong>Attention !</strong>
    La comptabilité est une fonctionnalité en beta,
    il est déconseillé pour le moment de l'utiliser pour la
    comptabilité réelle de votre association.<br />
    Vous êtes cependant encouragé à la tester et à faire part
    de votre retour sur le site de <a href="http://dev.kd2.org/garradin/">Garradin</a>.
</p>

<h3>Évolution des recettes et dépenses sur les 30 derniers jours</h3>
<p>
    <img src="{$www_url}admin/compta/graph.php?g=recettes_depenses" />
</p>

<h3>Évolution actif/passif sur les 30 derniers jours</h3>
<p>
    <img src="{$www_url}admin/compta/graph.php?g=actif_passif" />
</p>

{include file="admin/_foot.tpl"}











<




<
<
<
<
<

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15





16
{include file="admin/_head.tpl" title="Comptabilité" current="compta"}

<p class="alert">
    <strong>Attention !</strong>
    La comptabilité est une fonctionnalité en beta,
    il est déconseillé pour le moment de l'utiliser pour la
    comptabilité réelle de votre association.<br />
    Vous êtes cependant encouragé à la tester et à faire part
    de votre retour sur le site de <a href="http://dev.kd2.org/garradin/">Garradin</a>.
</p>


<p>
    <img src="{$www_url}admin/compta/graph.php?g=recettes_depenses" />
</p>






{include file="admin/_foot.tpl"}

Modified www/admin/compta/graph.php from [4c1b6f9088] to [40cd88fa18].

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
29
30
31
32
33
34
35
36
37
38
39
<?php

require_once __DIR__ . '/_inc.php';

require_once GARRADIN_ROOT . '/include/class.compta_stats.php';
$stats = new Garradin_Compta_Stats;

require_once GARRADIN_ROOT . '/include/libs/svgplot/lib.svgplot.php';

$plot = new SVGPlot(400, 300);

if (utils::get('g') == 'recettes_depenses')
{
	$data = array(
		$stats->recettes(),


		$stats->depenses(),

	);

}
elseif (utils::get('g') == 'actif_passif')

{
	$data = array(
		$stats->actif(),




		$stats->passif()
	);
}

$i = 0;

foreach ($data as $line)
{
	$line = new SVGPlot_Data($line);
	$line->color = ($i++ % 2) ? '#d98628' : '#9c4f15';
	$line->width = 5;
	$plot->add($line);
}

$plot->display();

?>













<
|
>
>
|
>
|
>
|
<
>
|
|
|
>
>
>
>
|
|






<
|
|






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
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
<?php

require_once __DIR__ . '/_inc.php';

require_once GARRADIN_ROOT . '/include/class.compta_stats.php';
$stats = new Garradin_Compta_Stats;

require_once GARRADIN_ROOT . '/include/libs/svgplot/lib.svgplot.php';

$plot = new SVGPlot(400, 300);

if (utils::get('g') == 'recettes_depenses')
{

	$r = new SVGPlot_Data($stats->recettes());
	$r->title = 'Recettes';

	$d = new SVGPlot_Data($stats->depenses());
	$d->title = 'Dépenses';

	$data = array($r, $d);


	$plot->setTitle('Recettes et dépenses de l\'exercice courant');

	$labels = array();

	foreach ($r->get() as $k=>$v)
	{
		$labels[] = utils::date_fr('M y', strtotime(substr($k, 0, 4) . '-' . substr($k, 4, 2) .'-01'));
	}

	$plot->setLabels($labels);
}

$i = 0;

foreach ($data as $line)
{

	$line->color = ($i++ % 2) ? '#fa4' : '#9c4f15';
	$line->width = 2;
	$plot->add($line);
}

$plot->display();

?>