1 | <?php |
---|
2 | |
---|
3 | /* * *************************************************************************\ |
---|
4 | * Associaspip, extension de SPIP pour gestion d'associations * |
---|
5 | * * |
---|
6 | * Copyright (c) 2007 Bernard Blazin & François de Montlivault (V1) * |
---|
7 | * Copyright (c) 2010-2011 Emmanuel Saint-James & Jeannot Lapin (V2) * |
---|
8 | * Ecrit par Marcel BOLLA en 01/2012 * |
---|
9 | * * |
---|
10 | * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
---|
11 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
---|
12 | \************************************************************************** */ |
---|
13 | |
---|
14 | if (!defined('_ECRIRE_INC_VERSION')) |
---|
15 | return; |
---|
16 | |
---|
17 | // Export du Compte de Resultat au format LaTeX |
---|
18 | function exec_export_compteresultats_tex() { |
---|
19 | if (!autoriser('associer', 'export_compteresultats_xml')) { |
---|
20 | include_spip('inc/minipres'); |
---|
21 | echo minipres(); |
---|
22 | } else { |
---|
23 | include_spip('inc/charsets'); |
---|
24 | include_spip('inc/association_plan_comptable'); |
---|
25 | $var = _request('var'); |
---|
26 | $latex = new LaTeX(_request('var')); |
---|
27 | $latex->EnTete(); |
---|
28 | foreach (array('charges', 'produits', 'contributions_volontaires') as $key) { |
---|
29 | $latex->LesEcritures($key); |
---|
30 | } |
---|
31 | $latex->Pied(); |
---|
32 | $latex->Enregistre(); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | /** |
---|
37 | * Utilisation d'une classe tres tres tres simple !!! |
---|
38 | */ |
---|
39 | class LaTeX { |
---|
40 | |
---|
41 | var $exercice; |
---|
42 | var $join; |
---|
43 | var $sel; |
---|
44 | var $where; |
---|
45 | var $having; |
---|
46 | var $order; |
---|
47 | var $out; |
---|
48 | |
---|
49 | function __construct($var) { |
---|
50 | $tableau = unserialize(rawurldecode($var)); |
---|
51 | $this->exercice = $tableau[0]; |
---|
52 | $this->join = $tableau[1]; |
---|
53 | $this->sel = $tableau[2]; |
---|
54 | $this->where = $tableau[3]; |
---|
55 | $this->having = $tableau[4]; |
---|
56 | $this->order = $tableau[5]; |
---|
57 | $this->out = ''; |
---|
58 | } |
---|
59 | |
---|
60 | function EnTete() { |
---|
61 | $this->out .= '\\documentclass[a4paper]{article}'."\n"; |
---|
62 | $this->out .= '\\usepackage['.$GLOBALS['meta']['charset'].']{inputenc}'."\n"; |
---|
63 | $this->out .= '\\usepackage[french]{babel}'."\n"; |
---|
64 | $this->out .= '\\usepackage[table]{xcolor}'."\n"; |
---|
65 | $this->out .= '%generator: Associaspip'."\n"; |
---|
66 | $this->out .= '\\title{'. html_entity_decode(_T('asso:cpte_resultat_titre_general')) .'\\\\ '. _T('Exercice') .' : '. sql_asso1champ('exercice', $this->exercice, 'intitule') .'}'."\n"; |
---|
67 | $this->out .= '\\author{'. $GLOBALS['association_metas']['nom'] .'}'."\n"; |
---|
68 | $this->out .= '\\date{\\today}'."\n"; |
---|
69 | $this->out .= '\\begin{document}'."\n"; |
---|
70 | $this->out .= '\\maketitle{}'."\n"; |
---|
71 | } |
---|
72 | |
---|
73 | function LesEcritures($key) { |
---|
74 | switch ($key) { |
---|
75 | case 'charges' : |
---|
76 | $quoi = "SUM(depense) AS valeurs"; |
---|
77 | break; |
---|
78 | case 'produits' : |
---|
79 | $quoi = "SUM(recette) AS valeurs"; |
---|
80 | break; |
---|
81 | case 'contributions_volontaires' : |
---|
82 | $quoi = "SUM(depense) AS charge_evaluee, SUM(recette) AS produit_evalue"; |
---|
83 | break; |
---|
84 | } |
---|
85 | $this->out .= '\\section*{'. ucfirst($key) .'}'."\n"; |
---|
86 | $this->out .= '\\begin{tabular}{|l p{.7562\\textwidth} r|}'."\n"; // 20/210=9.52381/100 30/210=14.8571/100 (210-20-30)/100=75.61909 |
---|
87 | $query = sql_select( |
---|
88 | "imputation, $quoi, DATE_FORMAT(date, '%Y') AS annee ".$this->sel, // select |
---|
89 | 'spip_asso_comptes'.$this->join, // from |
---|
90 | $this->where, // where |
---|
91 | $this->order, // group by |
---|
92 | $this->order, // order by |
---|
93 | '', // limit |
---|
94 | $this->having .$GLOBALS['association_metas']['classe_'.$key] // having |
---|
95 | ); |
---|
96 | $chapitre = ''; |
---|
97 | $i = 0; |
---|
98 | while ($data = sql_fetch($query)) { |
---|
99 | if ($key==='contributions_volontaires') { |
---|
100 | if ($data['charge_evaluee']>0) { |
---|
101 | $valeurs = $data['charge_evaluee']; |
---|
102 | } else { |
---|
103 | $valeurs = $data['produit_evalue']; |
---|
104 | } |
---|
105 | } else { |
---|
106 | $valeurs = $data['valeurs']; |
---|
107 | } |
---|
108 | $new_chapitre = substr($data['code'], 0, 2); |
---|
109 | if ($chapitre!=$new_chapitre) { |
---|
110 | $this->out .= str_replace(array('\\','&'), array('\\backslash{}','\\&'), $new_chapitre) .' & '; |
---|
111 | $this->out .= '\multicolumn{2}{l|}{'. str_replace(array('\\','&'), array('\\backslash{}','\\&'), ($GLOBALS['association_metas']['plan_comptable_prerenseigne']?association_plan_comptable_complet($new_chapitre):sql_getfetsel('intitule','spip_asso_plan',"code='$new_chapitre'"))) .'}\\\\'."\n"; |
---|
112 | $chapitre = $new_chapitre; |
---|
113 | } |
---|
114 | $this->out .= str_replace(array('\\','&'), array('\\backslash{}','\\&'), $data['code']) .' & '; |
---|
115 | $this->out .= str_replace(array('\\','&'), array('\\backslash{}','\\&'), $data['intitule']) .' & '; |
---|
116 | $this->out .= $valeurs.'\\\\'."\n"; |
---|
117 | } |
---|
118 | $this->out .= '\\end{tabular}'."\n"; |
---|
119 | } |
---|
120 | |
---|
121 | function Pied() { |
---|
122 | $this->out .= '\end{document}'."\n"; |
---|
123 | } |
---|
124 | |
---|
125 | function Enregistre() { |
---|
126 | $fichier =_DIR_RACINE.'/'._NOM_TEMPORAIRES_ACCESSIBLES.'compte_resultats_'.$this->exercice.'.tex'; |
---|
127 | $f = fopen($fichier, 'w'); |
---|
128 | fputs($f, $this->out); |
---|
129 | fclose($f); |
---|
130 | header('Content-Type: text/tex'); |
---|
131 | header('Content-Type: application/tex'); |
---|
132 | header('Content-Disposition: attachment; filename="'.$fichier.'"'); |
---|
133 | readfile($fichier); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | ?> |
---|