1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * Associaspip, extension de SPIP pour gestion d'associations * |
---|
4 | * * |
---|
5 | * Copyright (c) 2007 Bernard Blazin & Fran�ois de Montlivault (V1) * |
---|
6 | * Copyright (c) 2010-2011 Emmanuel Saint-James & Jeannot Lapin (V2) * |
---|
7 | * * |
---|
8 | * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
---|
9 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
---|
10 | \***************************************************************************/ |
---|
11 | |
---|
12 | if (!defined('_ECRIRE_INC_VERSION')) |
---|
13 | return; |
---|
14 | |
---|
15 | include_spip ('inc/navigation_modules'); |
---|
16 | |
---|
17 | function exec_comptes() |
---|
18 | { |
---|
19 | if (!autoriser('associer', 'comptes')) { |
---|
20 | include_spip('inc/minipres'); |
---|
21 | echo minipres(); |
---|
22 | } else { |
---|
23 | // initialisations |
---|
24 | $exercice = intval(_request('exercice')); |
---|
25 | if(!$exercice){ |
---|
26 | /* on recupere l'id du dernier exercice */ |
---|
27 | $exercice = sql_getfetsel('id_exercice','spip_asso_exercices','','','debut DESC'); |
---|
28 | if(!$exercice) |
---|
29 | $exercice = 0; |
---|
30 | } |
---|
31 | $vu = _request('vu'); |
---|
32 | if (!is_numeric($vu)) |
---|
33 | $vu = ''; |
---|
34 | $imputation = _request('imputation'); |
---|
35 | if (!$imputation) |
---|
36 | $imputation= '%'; |
---|
37 | $max_par_page = intval(_request('max')); |
---|
38 | if (!$max_par_page) |
---|
39 | $max_par_page = 30; |
---|
40 | $id_compte = intval(_request('id_compte', $_GET)); |
---|
41 | if (!$id_compte) |
---|
42 | $id_compte = ''; |
---|
43 | $debut = intval(_request('debut')); |
---|
44 | $exercice_data = sql_asso1ligne('exercice', $exercice); |
---|
45 | // traitements |
---|
46 | $where = 'imputation LIKE '. sql_quote($imputation); |
---|
47 | $where .= (!is_numeric($vu) ? '' : " AND vu=$vu"); |
---|
48 | $where .= " AND date>='$exercice_data[debut]' AND date<='$exercice_data[fin]'"; |
---|
49 | onglets_association('titre_onglet_comptes'); |
---|
50 | // INTRO : rappel de l'exercicee affichee |
---|
51 | echo totauxinfos_intro($exercice_data['intitule'],'exercice',$exercice); |
---|
52 | $journaux = sql_allfetsel('journal, intitule', 'spip_asso_comptes RIGHT JOIN spip_asso_plan ON journal=code',"classe='".$GLOBALS['association_metas']['classe_banques']."' AND date>='$exercice_data[debut]' AND date<='$exercice_data[fin]'", "intitule DESC"); // on se permet sql_allfetsel car il s'agit d'une association (mois d'une demie dizaine de comptes) et non d'un etablissement financier (des milliers de comptes clients) |
---|
53 | /* bof * |
---|
54 | // STATS recettes et depenses par comptes financiers (indique rapidement les comptes financiers avec les mouvements les plus importants --en montant !) |
---|
55 | foreach ($journaux as $financier) { |
---|
56 | echo totauxinfos_stats($financier['intitule'], 'comptes', array('bilan_recettes'=>'recette','bilan_depenses'=>'depense',), "journal='".$financier['journal']."' AND date>='$exercice_data[debut]' AND date<='$exercice_data[fin]'"); |
---|
57 | } |
---|
58 | * fob */ |
---|
59 | // TOTAUX : operations de l'exercice par compte financier (indique rapidement les comptes financiers les plus utilises ou les modes de paiement preferes...) |
---|
60 | foreach (array('recette','depense') as $direction) { |
---|
61 | foreach ($journaux as $financier) { |
---|
62 | $nombre_direction = sql_countsel('spip_asso_comptes', "journal='".$financier['journal']."' AND date>='$exercice_data[debut]' AND date<='$exercice_data[fin]' AND $direction<>0 "); |
---|
63 | if ($nombre_direction) { // on ne s'embarasse pas avec ceux a zero |
---|
64 | $direction_libelles[$financier['journal']] = $financier['intitule']; |
---|
65 | $direction_effectifs[$financier['journal']] = $nombre_direction; |
---|
66 | } |
---|
67 | } |
---|
68 | if (count($direction_libelles)) |
---|
69 | echo totauxinfos_effectifs(_T('asso:compte_entete_financier') .': '. _T('asso:'.$direction.'s'), $direction_libelles, $direction_effectifs); // ToDo: tri par ordre decroissant (sorte de "top") |
---|
70 | } |
---|
71 | // TOTAUX : operations de l'exercice par type d'operation |
---|
72 | $classes = array('pair'=>'produits', 'impair'=>'charges', 'cv'=>'contributions_volontaires', 'vi'=>'banques'); |
---|
73 | $liste_libelles = $liste_effectifs = array(); |
---|
74 | foreach ($classes as $classe_css=>$classe_cpt) { |
---|
75 | $liste_effectifs[$classe_css] = sql_countsel('spip_asso_comptes', "LEFT(imputation,1)='".$GLOBALS['association_metas']["classe_$classe_cpt"]."' AND date>='$exercice_data[debut]' AND date<='$exercice_data[fin]' "); |
---|
76 | $liste_libelles[$classe_css] = 'compte_liste_nombre_'.$classe_css; |
---|
77 | } |
---|
78 | echo totauxinfos_effectifs('comptes', $liste_libelles, $liste_effectifs); |
---|
79 | // STATS : montants de l'exercice pour l'imputation choisie (toutes si aucune) |
---|
80 | echo totauxinfos_stats('mouvements', 'comptes', array('bilan_recettes'=>'recette','bilan_depenses'=>'depense',), $where, 2); |
---|
81 | // TOTAUX : montants de l'exercice pour l'imputation choisie (toutes si aucune) |
---|
82 | $data = sql_fetsel( 'SUM(recette) AS somme_recettes, SUM(depense) AS somme_depenses, code, classe', 'spip_asso_comptes RIGHT JOIN spip_asso_plan ON imputation=code', "$where AND classe<>".sql_quote($GLOBALS['association_metas']['classe_banques']). " AND classe<>".sql_quote($GLOBALS['association_metas']['classe_contributions_volontaires']), 'code'); // une contribution benevole ne doit pas etre comptabilisee en charge/produit |
---|
83 | echo totauxinfos_montants(($imputation=='%' ? _T('asso:tous') : $imputation), $data['somme_recettes'], $data['somme_depenses']); |
---|
84 | // datation et raccourcis |
---|
85 | icones_association(array(), array( |
---|
86 | 'cpte_resultat_titre_general' => array('finances-24.png', 'compte_resultat', "exercice=$exercice"), |
---|
87 | 'bilan' => array('finances-24.png', 'bilan', "exercice=$exercice"), |
---|
88 | 'annexe_titre_general' => array('finances-24.png', 'annexe', "exercice=$exercice"), |
---|
89 | 'ajouter_une_operation' => array('ajout-24.png', 'edit_compte'), |
---|
90 | ) ); |
---|
91 | debut_cadre_association('finances-32.jpg', 'informations_comptables'); |
---|
92 | echo "\n<table width='100%'>"; |
---|
93 | echo '<tr><td>'; |
---|
94 | echo '<form method="post" action="'.generer_url_ecrire('comptes',"imputation=$imputation").'"><div>'; |
---|
95 | echo '<select name ="exercice" onchange="form.submit()">'; |
---|
96 | echo '<option value="0" '; |
---|
97 | if (!$exercice) { |
---|
98 | echo ' selected="selected"'; |
---|
99 | } |
---|
100 | echo '>Choix Exercice ?</option>'; |
---|
101 | $sql = sql_select('id_exercice, intitule', 'spip_asso_exercices','', "intitule DESC"); |
---|
102 | while ($val = sql_fetch($sql)) { |
---|
103 | echo '<option value="'.$val['id_exercice'].'" '; |
---|
104 | if ($exercice==$val['id_exercice']) { echo ' selected="selected"'; } |
---|
105 | echo '>'.$val['intitule'].'</option>'; |
---|
106 | } |
---|
107 | echo '</select><noscript><input type="submit" value="'._T('lister').'" /></noscript></div></form></td>'; |
---|
108 | echo '<td>'; |
---|
109 | echo '<form method="post" action="'.generer_url_ecrire('comptes', "exercice=$exercice").'"><div>'; |
---|
110 | echo '<select name ="imputation" class="fondl" onchange="form.submit()">'; |
---|
111 | echo '<option value="%" '; |
---|
112 | if ($imputation=="%") { echo ' selected="selected"'; } |
---|
113 | echo '>Tous</option>'; |
---|
114 | /* Remplir le select uniquement avec les comptes utilises */ |
---|
115 | $sql = sql_select( |
---|
116 | 'imputation , code, intitule, classe', |
---|
117 | 'spip_asso_comptes RIGHT JOIN spip_asso_plan ON imputation=code', |
---|
118 | /* n'afficher ni les comptes de la classe financiere --ce ne sont pas des imputations-- ni les inactifs */ |
---|
119 | "classe<>'".$GLOBALS['association_metas']['classe_banques']."' AND active AND date>='$exercice_data[debut]' AND date<='$exercice_data[fin]' ", |
---|
120 | 'code', 'code ASC'); |
---|
121 | while ($plan = sql_fetch($sql)) { |
---|
122 | echo '<option value="'.$plan['code'].'" '; |
---|
123 | if ($imputation==$plan['code']) { echo ' selected="selected"'; } |
---|
124 | echo '>'.$plan['code'].' - '.$plan['intitule'].'</option>'; |
---|
125 | } |
---|
126 | echo '</select><noscript><input type="submit" value="'._T('filtrer').'" /></noscript></div></form></td>'; |
---|
127 | echo '</tr></table>'; |
---|
128 | /* (re)calculer la pagination en fonction de id_compte */ |
---|
129 | if ($id_compte) { |
---|
130 | /* on recupere les id_comptes de la requete sans le critere de limite et on en tire l'index de l'id_compte recherche parmis tous ceux disponible */ |
---|
131 | $all_id_compte = sql_allfetsel('id_compte', 'spip_asso_comptes', $where, '', 'date DESC,id_compte DESC'); |
---|
132 | $index_id_compte = -1; |
---|
133 | reset($all_id_compte); |
---|
134 | while (($index_id_compte<0) && (list($k,$v) = each($all_id_compte))) { |
---|
135 | if ($v['id_compte']==$id_compte) $index_id_compte = $k; |
---|
136 | } |
---|
137 | /* on recalcule le parametre de limite de la requete */ |
---|
138 | if ($index_id_compte>=0) { |
---|
139 | $debut = intval($index_id_compte/$max_par_page)*$max_par_page; |
---|
140 | } |
---|
141 | } |
---|
142 | // TABLEAU |
---|
143 | $table = comptes_while($where, "$debut,$max_par_page", $id_compte); |
---|
144 | if ($table) { |
---|
145 | //SOUS-PAGINATION |
---|
146 | $nombre_selection = sql_countsel('spip_asso_comptes', $where); |
---|
147 | $pages = intval($nombre_selection/$max_par_page)+1; |
---|
148 | $args = 'exercice='.$exercice.'&imputation='.$imputation. (is_numeric($vu) ? "&vu=$vu" : ''); |
---|
149 | $nav = ''; |
---|
150 | if ($pages!=1) |
---|
151 | for ($i=0; $i<$pages; $i++) { |
---|
152 | $position = $i*$max_par_page; |
---|
153 | if ($position==$debut) { |
---|
154 | $nav .= '<strong>'.$position.' </strong>'; |
---|
155 | } else { |
---|
156 | $h = generer_url_ecrire('comptes',$args.'&debut='.$position); |
---|
157 | $nav .= "<a href='$h'>$position</a>\n"; |
---|
158 | } |
---|
159 | } |
---|
160 | // |
---|
161 | $table = "<table width='100%' class='asso_tablo' id='asso_tablo_comptes'>\n" |
---|
162 | . "<thead>\n<tr>" |
---|
163 | . '<th>'. _T('asso:entete_id') .'</th>' |
---|
164 | . '<th>'. _T('asso:entete_date') .'</th>' |
---|
165 | . '<th>'. _T('asso:compte_entete_imputation') .'</th>' |
---|
166 | . '<th>'. _T('asso:compte_entete_justification') .'</th>' |
---|
167 | . '<th>'. _T('asso:entete_montant') .'</th>' |
---|
168 | . '<th>'. _T('asso:compte_entete_financier') .'</th>' |
---|
169 | . '<th colspan="3" class="actions">'. _T('asso:entete_action') .'</th>' |
---|
170 | . "</tr>\n</thead><tbody>" |
---|
171 | . $table |
---|
172 | . "</tbody>\n</table>\n" |
---|
173 | . "<table width='100%'><tr>\n<td>" . $nav . '</td><td style="text-align:right;"><input type="submit" value="'. _T('asso:valider') . '" class="fondo" /></td></tr></table>'; |
---|
174 | echo generer_form_ecrire('action_comptes', $table); |
---|
175 | } else { |
---|
176 | echo '<table width="100%"><tbody><tr><td class="actions erreur">' .( $exercice ? _T('asso:aucune_operation') : '<a href="'.generer_url_ecrire('exercices').'">'._T('asso:definir_exercice').'</a>' ). '</td></tr></tbody></table>'; |
---|
177 | } |
---|
178 | fin_page_association(); |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | function comptes_while($where, $limit, $id_compte) |
---|
183 | { |
---|
184 | $query = sql_select('*', 'spip_asso_comptes', $where,'', 'date DESC,id_compte DESC', $limit); |
---|
185 | $comptes = ''; |
---|
186 | while ($data = sql_fetch($query)) { |
---|
187 | if ($data['depense']>0) { |
---|
188 | $class = 'impair'; |
---|
189 | } else { |
---|
190 | $class = 'pair'; |
---|
191 | } |
---|
192 | if ($data['imputation']==$GLOBALS['association_metas']['pc_intravirements']) { |
---|
193 | $class = 'vi'; |
---|
194 | } // virement interne |
---|
195 | if (substr($data['imputation'],0,1)==$GLOBALS['association_metas']['classe_contributions_volontaires']) { |
---|
196 | $class = 'cv'; |
---|
197 | } |
---|
198 | if($id_compte==$data['id_compte']) { /* pour voir au chargement l'id_compte recherche */ |
---|
199 | $onload_option .= 'onLoad="document.getElementById(\'id_compte'.$id_compte.'\').scrollIntoView(true);"'; |
---|
200 | } else { |
---|
201 | $onload_option = ''; |
---|
202 | } |
---|
203 | $comptes .= "\n<tr id='id_compte$id' class='$class'>" |
---|
204 | . '<td class="integer">'.$data['id_compte'].'</td>' |
---|
205 | . '<td class="date">'. association_datefr($data['date']) .'</td>' |
---|
206 | . '<td class="text">'. $data['imputation'].'</td>' |
---|
207 | . '<td class="text"> '. propre($data['justification']) .'</td>' |
---|
208 | . '<td class="decimal">'. association_prixfr($data['recette']-$data['depense']) .'</td>' |
---|
209 | . '<td class="text"> '.$data['journal'].'</td>' |
---|
210 | . ( $data['vu'] |
---|
211 | /* pas d'action sur les operations validees */ |
---|
212 | ? ('<td class="action" colspan="2"><img src="'._DIR_PLUGIN_ASSOCIATION_ICONES.'puce-verte.gif" '.$onload_option.' /></td>'.'<td class="action"><input disabled="disabled" type="checkbox" /></td>') |
---|
213 | : ( $data['id_journal'] |
---|
214 | /* pas d'edition/suppression des operations gerees par un module externe (souci de coherence avec des donnees d'autres tables) */ |
---|
215 | ? ('<td class="action" colspan="2"><img src="'._DIR_PLUGIN_ASSOCIATION_ICONES.'puce-rouge.gif" '.$onload_option.' /></td>') |
---|
216 | : ( (substr($data['imputation'],0,1)==$GLOBALS['association_metas']['classe_banques']) |
---|
217 | /* pas d'edition des virements internes (souci de coherence car il faut modifier deux operations concordament : ToDo...) */ |
---|
218 | ? '<td class="action"> </td>' |
---|
219 | /* le reste est editable */ |
---|
220 | : '<td class="action">'. association_bouton('mettre_a_jour', 'edit-12.gif', 'edit_compte', 'id='.$data['id_compte'], $onload_option) . '</td>' |
---|
221 | ) |
---|
222 | /* operation supprimable */ |
---|
223 | . association_bouton_supprimer('compte', 'id='.$data['id_compte'], 'td') |
---|
224 | ) |
---|
225 | /* operation non validee (donc validable et editable ...ici ou via le module dedie...) */ |
---|
226 | . '<td class="action"><input name="valide[]" type="checkbox" value="'.$data['id_compte']. '" /></td>' |
---|
227 | ) |
---|
228 | . '</tr>'; |
---|
229 | } |
---|
230 | return $comptes; |
---|
231 | } |
---|
232 | |
---|
233 | ?> |
---|