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 | * ajouté en 08/2011 par Marcel BOLLA ... à partir de bilan.php * |
---|
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 | |
---|
15 | if (!defined('_ECRIRE_INC_VERSION')) |
---|
16 | return; |
---|
17 | |
---|
18 | include_spip('inc/navigation_modules'); |
---|
19 | |
---|
20 | function exec_compte_resultat() |
---|
21 | { |
---|
22 | if (!autoriser('associer', 'comptes')) { |
---|
23 | include_spip('inc/minipres'); |
---|
24 | echo minipres(); |
---|
25 | } else { |
---|
26 | $plan = sql_countsel('spip_asso_plan','active=1'); |
---|
27 | $id_exercice = intval(_request('exercice')); |
---|
28 | if(!$id_exercice){ |
---|
29 | /* on recupere l'id_exercice dont la date "fin" est "la plus grande" */ |
---|
30 | $id_exercice = sql_getfetsel('id_exercice', 'spip_asso_exercices', '', '', 'fin DESC'); |
---|
31 | if(!$id_exercice) |
---|
32 | $id_exercice = 0; |
---|
33 | } |
---|
34 | $exercice_data = sql_asso1ligne('exercice', $id_exercice); |
---|
35 | onglets_association('titre_onglet_comptes'); |
---|
36 | // INTRO : rappel de l'exercicee affichee |
---|
37 | $infos['exercice_entete_debut'] = association_datefr($exercice_data['debut'], 'dtstart'); |
---|
38 | $infos['exercice_entete_fin'] = association_datefr($exercice_data['fin'], 'dtend'); |
---|
39 | echo totauxinfos_intro($exercice_data['intitule'], 'exercice', $id_exercice, $infos); |
---|
40 | // pas de sommes de synthes puisque tous les totaux sont dans la zone centrale ;- |
---|
41 | // datation et raccourcis |
---|
42 | icones_association(array('comptes', "exercice=$exercice"), array( |
---|
43 | 'bilan' => array('finances-24.png', 'bilan', "exercice=$id_exercice"), |
---|
44 | 'annexe_titre_general' => array('finances-24.png', 'annexe', "exercice=$id_exercice"), |
---|
45 | )); |
---|
46 | // elements communs aux requetes |
---|
47 | if ($plan) { |
---|
48 | $join = ' RIGHT JOIN spip_asso_plan ON imputation=code'; |
---|
49 | $sel = ', code, intitule, classe'; |
---|
50 | $where = " date>='$exercice_data[debut]' AND date<='$exercice_data[fin]' "; |
---|
51 | $having = 'classe = '; |
---|
52 | $order = 'code'; |
---|
53 | } else { |
---|
54 | $join = $sel = $where = $having = $order = ''; |
---|
55 | } |
---|
56 | $var = serialize(array($id_exercice, $join, $sel, $where, $having, $order)); //!\ les cles numeriques peuvent poser probleme... <http://www.mail-archive.com/php-bugs@lists.php.net/msg100262.html> mais il semble qu'ici le souci vient de l'absence d'encodage lorsqu'on passe $var par URL... |
---|
57 | // $var = serialize(array('id'=>$id_exercice, '1'=>$join, '2'=>$sel, '3'=>$where, '4'=>$having, '5'=>$order)); |
---|
58 | if($plan){ // on peut exporter : pdf, csv, xml, ... |
---|
59 | echo debut_cadre_enfonce('',true); |
---|
60 | echo '<h3>'. _T('asso:cpte_resultat_mode_exportation') .'</h3>'; |
---|
61 | if (test_plugin_actif('FPDF')) { // impression en PDF : _T('asso:bouton_impression') |
---|
62 | echo icone1_association('PDF', generer_url_ecrire('export_compteresultats_pdf').'&var='.rawurlencode($var), 'print-24.png', 'print-24.png'); //!\ generer_url_ecrire() utilise url_enconde() or il est preferable avec les grosses variables serialisees d'utiliser rawurlencode() |
---|
63 | } |
---|
64 | foreach(array('csv','ctx','tex','tsv','xml','yaml') as $type) { // autres exports (donnees brutes) possibles |
---|
65 | echo icone1_association(strtoupper($type), generer_url_ecrire("export_compteresultats_$type").'&var='.rawurlencode($var), "export-$type.png", 'export-24.png'); //!\ generer_url_ecrire($exec, $param) equivaut a generer_url_ecrire($exec).'&'.urlencode($param) or il faut utiliser rawurlencode($param) ici... |
---|
66 | } |
---|
67 | fin_cadre_enfonce(); |
---|
68 | } |
---|
69 | debut_cadre_association('finances-32.jpg', 'cpte_resultat_titre_general', $exercice_data['intitule']); |
---|
70 | $depenses = compte_resultat_charges_produits($var, intval($GLOBALS['association_metas']['classe_charges'])); |
---|
71 | $recettes = compte_resultat_charges_produits($var, intval($GLOBALS['association_metas']['classe_produits'])); |
---|
72 | compte_resultat_benefice_perte($recettes, $depenses); |
---|
73 | compte_resultat_benevolat($var, intval($GLOBALS['association_metas']['classe_contributions_volontaires'])); |
---|
74 | /* |
---|
75 | if($plan){ // on peut exporter : pdf, csv, xml, ... |
---|
76 | echo "<br /><table width='100%' class='asso_tablo' cellspacing='6' id='asso_tablo_exports'>\n"; |
---|
77 | echo '<tbody><tr>'; |
---|
78 | echo '<td>'. _T('asso:cpte_resultat_mode_exportation') .'</td>'; |
---|
79 | if (test_plugin_actif('FPDF')) { // impression en PDF |
---|
80 | echo '<td class="action"><a href="'.generer_url_ecrire('export_compteresultats_pdf').'&var='.rawurlencode($var). '"><strong>PDF</strong></td>'; //!\ generer_url_ecrire() utilise url_enconde() or il est preferable avec les grosses variables serialisees d'utiliser rawurlencode() |
---|
81 | } |
---|
82 | foreach(array('csv','ctx','tex','tsv','xml','yaml') as $type) { // autres exports (donnees brutes) possibles |
---|
83 | echo '<td class="action"><a href="'. generer_url_ecrire('export_compteresultats_'.$type).'&var='.rawurlencode($var). '"><strong>'. strtoupper($type) .'</strong></td>'; //!\ generer_url_ecrire($exec, $param) equivaut a generer_url_ecrire($exec).'&'.urlencode($param) or il faut utiliser rawurlencode($param) ici... |
---|
84 | } |
---|
85 | echo '</tr></tbody></table>'; |
---|
86 | } |
---|
87 | */ |
---|
88 | fin_page_association(); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | function compte_resultat_charges_produits($var, $class) { |
---|
93 | include_spip('inc/association_plan_comptable'); |
---|
94 | $tableau = @unserialize($var); |
---|
95 | $id_tableau = (($class==$GLOBALS['association_metas']['classe_charges']) ? 'charges' : 'produits'); |
---|
96 | echo "<table width='100%' class='asso_tablo' id='asso_tablo_bilan_$id_tableau'>\n"; |
---|
97 | echo "<thead>\n<tr>"; |
---|
98 | echo '<th width="10"> </td>'; |
---|
99 | echo '<th width="30"> </td>'; |
---|
100 | echo '<th>'. (($class==$GLOBALS['association_metas']['classe_charges']) ? _T('asso:cpte_resultat_titre_charges') : _T('asso:cpte_resultat_titre_produits')) .'</th>'; |
---|
101 | echo '<th width="80"> </th>'; |
---|
102 | echo "</tr>\n</thead><tbody>"; |
---|
103 | $quoi = (($class==$GLOBALS['association_metas']['classe_charges']) ? 'SUM(depense) AS valeurs' : 'SUM(recette) AS valeurs'); |
---|
104 | $query = sql_select( |
---|
105 | "imputation, $quoi, DATE_FORMAT(date, '%Y') AS annee $tableau[2]", // select |
---|
106 | "spip_asso_comptes $tableau[1]", // from |
---|
107 | $tableau[3], // where |
---|
108 | $tableau[5], // group by |
---|
109 | $tableau[5], // order by |
---|
110 | '', // limit |
---|
111 | $tableau[4].$class // having |
---|
112 | ); |
---|
113 | $total = 0; |
---|
114 | $chapitre = ''; |
---|
115 | $i = 0; |
---|
116 | while ($data = sql_fetch($query)) { |
---|
117 | echo '<tr>'; |
---|
118 | $valeurs = $data['valeurs']; |
---|
119 | $new_chapitre = substr($data['code'], 0, 2); |
---|
120 | if ($chapitre!=$new_chapitre) { |
---|
121 | echo '<td class="text">'. $new_chapitre . '</td>'; |
---|
122 | echo '<td colspan="3" class="text">'. ($GLOBALS['association_metas']['plan_comptable_prerenseigne']?association_plan_comptable_complet($new_chapitre):sql_getfetsel('intitule','spip_asso_plan',"code='$new_chapitre'")) .'</td>'; |
---|
123 | $chapitre = $new_chapitre; |
---|
124 | echo "</tr>\n<tr>"; |
---|
125 | } |
---|
126 | echo "<td> </td>"; |
---|
127 | echo '<td class="text">'. $data['code'] .'</td>'; |
---|
128 | echo '<td class="text">'. $data['intitule'] .'</td>'; |
---|
129 | echo '<td class="decimal">'. association_nbrefr($valeurs) .'</td>'; |
---|
130 | echo "</tr>\n"; |
---|
131 | $total += $valeurs; |
---|
132 | } |
---|
133 | echo "</tbody><tfoot>\n<tr>"; |
---|
134 | echo '<th colspan="2"> </th>'; |
---|
135 | echo '<th class="text">'. (($class==$GLOBALS['association_metas']['classe_charges']) ? _T('asso:cpte_resultat_total_charges') : _T('asso:cpte_resultat_total_produits')) .'</th>'; |
---|
136 | echo '<th class="decimal">'. association_nbrefr($total) . '</th>'; |
---|
137 | echo "</tr>\n</tfoot>\n</table>\n"; |
---|
138 | return $total; |
---|
139 | } |
---|
140 | |
---|
141 | function compte_resultat_benefice_perte($recettes, $depenses) { |
---|
142 | echo "<table width='100%' class='asso_tablo' id='asso_tablo_bilan_solde'>\n"; |
---|
143 | echo "<thead>\n<tr>"; |
---|
144 | echo '<th width="10"> </td>'; |
---|
145 | echo '<th width="30"> </td>'; |
---|
146 | echo '<th>'. _T('asso:cpte_resultat_titre_resultat') .'</th>'; |
---|
147 | echo '<th width="80"> </th>'; |
---|
148 | echo "</tr>\n</thead>"; |
---|
149 | echo "<tfoot>\n<tr>"; |
---|
150 | echo '<th colspan="2"> </th>'; |
---|
151 | $res = $recettes-$depenses; |
---|
152 | echo '<th class="text">'. (($res<0) ? _T('asso:cpte_resultat_perte') : _T('asso:cpte_resultat_benefice')) .'</th>'; |
---|
153 | echo '<th class="decimal">'. association_nbrefr($res) .'</th>'; |
---|
154 | echo "</tr></tfoot></table>"; |
---|
155 | } |
---|
156 | |
---|
157 | function compte_resultat_benevolat($var, $class) { |
---|
158 | $tableau = @unserialize($var); |
---|
159 | echo "<table width='100%' class='asso_tablo' id='asso_tablo_bilan_benevolat'>\n"; |
---|
160 | echo "<thead>\n<tr>"; |
---|
161 | echo '<th width="10"> </th>'; |
---|
162 | echo '<th width="30"> </th>'; |
---|
163 | echo '<th>'. _T('asso:cpte_resultat_titre_benevolat') . '</th>'; |
---|
164 | echo '<th width="80">'. _T('asso:cpte_resultat_recette_evaluee') .'</th>'; |
---|
165 | echo '<th width="80">'. _T('asso:cpte_resultat_depense_evaluee') .'</th>'; |
---|
166 | $query = sql_select( |
---|
167 | "imputation, SUM(recette) AS recettes, SUM(depense) AS depenses, DATE_FORMAT(date, '%Y') AS annee $tableau[2]", // select |
---|
168 | "spip_asso_comptes $tableau[1]", // from |
---|
169 | $tableau[3], // where |
---|
170 | $tableau[5], // group by |
---|
171 | $tableau[5], // order by |
---|
172 | '', // limit |
---|
173 | $tableau[4].$class // having |
---|
174 | ); |
---|
175 | $chapitre = ''; |
---|
176 | $total_recettes = $total_depenses = 0; |
---|
177 | while ($data = sql_fetch($query)) { |
---|
178 | echo '<tr>'; |
---|
179 | $new_chapitre = substr($data['code'], 0, 2); |
---|
180 | if ($chapitre!=$new_chapitre) { |
---|
181 | echo '<td class="text">' . $new_chapitre . '</td>'; |
---|
182 | echo '<td colspan="4" class="text">'. ($GLOBALS['association_metas']['plan_comptable_prerenseigne']?association_plan_comptable_complet($new_chapitre):sql_getfetsel('intitule','spip_asso_plan',"code='$new_chapitre'")) . '</td>'; |
---|
183 | $chapitre = $new_chapitre; |
---|
184 | echo "</tr>\n"; |
---|
185 | } |
---|
186 | echo '<td> </td>'; |
---|
187 | echo '<td class="text">'. $data['code'] .'</td>'; |
---|
188 | echo '<td class="text">'. $data['intitule'] .'</td>'; |
---|
189 | echo '<td class="decimal">'. association_nbrefr($data['recettes']) .'</td>'; |
---|
190 | echo '<td class="decimal">'. association_nbrefr($data['depenses']) .'</td>'; |
---|
191 | echo '</tr>'; |
---|
192 | $total_recettes += $data['recettes']; |
---|
193 | $total_depenses += $data['depenses']; |
---|
194 | } |
---|
195 | echo "</tbody><tfoot>\n<tr>"; |
---|
196 | echo '<th width="10"> </td>'; |
---|
197 | echo '<th width="30"> </td>'; |
---|
198 | echo '<th class="decimal">'. _T('asso:resultat_courant') .'</th>'; |
---|
199 | echo '<th class="decimal">'. association_nbrefr($total_recettes) .'</th>'; |
---|
200 | echo '<th class="decimal">'. association_nbrefr($total_depenses) .'</th>'; |
---|
201 | echo "</tr>\n</tfoot>\n</table>\n"; |
---|
202 | } |
---|
203 | |
---|
204 | ?> |
---|