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 en .ctx |
---|
18 | function exec_export_compteresultats_ctx() { |
---|
19 | if (!autoriser('associer', 'export_compteresultats')) { |
---|
20 | include_spip('inc/minipres'); |
---|
21 | echo minipres(); |
---|
22 | } else { |
---|
23 | include_spip('inc/charsets'); |
---|
24 | include_spip('inc/association_plan_comptable'); |
---|
25 | $ctx = new CTX(_request('var')); |
---|
26 | $ctx->EnTete(); |
---|
27 | foreach (array('charges', 'produits', 'contributions_volontaires') as $key) { |
---|
28 | $ctx->LesEcritures($key); |
---|
29 | } |
---|
30 | $ctx->Enregistre(); |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | * Utilisation d'une classe tres tres tres simple !!! |
---|
36 | */ |
---|
37 | class CTX { |
---|
38 | |
---|
39 | var $exercice; |
---|
40 | var $join; |
---|
41 | var $sel; |
---|
42 | var $where; |
---|
43 | var $having; |
---|
44 | var $order; |
---|
45 | var $out; |
---|
46 | |
---|
47 | function __construct($var) { |
---|
48 | $tableau = unserialize(rawurldecode($var)); |
---|
49 | $this->exercice = $tableau[0]; |
---|
50 | $this->join = $tableau[1]; |
---|
51 | $this->sel = $tableau[2]; |
---|
52 | $this->where = $tableau[3]; |
---|
53 | $this->having = $tableau[4]; |
---|
54 | $this->order = $tableau[5]; |
---|
55 | $this->out = ''; |
---|
56 | } |
---|
57 | |
---|
58 | function EnTete() { |
---|
59 | $this->out .= str_replace(array("\r", "\n", "\\", '|'), array('\r', '\n', '\i', '\p'), html_entity_decode(_T('asso:entete_code'))) .'|'; |
---|
60 | $this->out .= '"'. str_replace(array("\r", "\n", "\\", '|'), array('\r', '\n', '\i', '\p'), html_entity_decode(_T('asso:entete_intitule'))) .'|'; |
---|
61 | $this->out .= str_replace(array("\r", "\n", "\\", '|'), array('\r', '\n', '\i', '\p'), html_entity_decode(_T('asso:entete_montant'))) ."\n"; |
---|
62 | } |
---|
63 | |
---|
64 | function LesEcritures($key) { |
---|
65 | switch ($key) { |
---|
66 | case 'charges' : |
---|
67 | $quoi = "SUM(depense) AS valeurs"; |
---|
68 | break; |
---|
69 | case 'produits' : |
---|
70 | $quoi = "SUM(recette) AS valeurs"; |
---|
71 | break; |
---|
72 | case 'contributions_volontaires' : |
---|
73 | $quoi = "SUM(depense) AS charge_evaluee, SUM(recette) AS produit_evalue"; |
---|
74 | break; |
---|
75 | } |
---|
76 | $query = sql_select( |
---|
77 | "imputation, $quoi, DATE_FORMAT(date, '%Y') AS annee".$this->sel, // select |
---|
78 | 'spip_asso_comptes '.$this->join, // from |
---|
79 | $this->where, // where |
---|
80 | $this->order, // group by |
---|
81 | $this->order, // order by |
---|
82 | '', // limit |
---|
83 | $this->having .$GLOBALS['association_metas']['classe_'.$key] // having |
---|
84 | ); |
---|
85 | $chapitre = ''; |
---|
86 | $i = 0; |
---|
87 | while ($data = sql_fetch($query)) { |
---|
88 | if ($key==='contributions_volontaires') { |
---|
89 | if ($data['charge_evaluee']>0) { |
---|
90 | $valeurs = $data['charge_evaluee']; |
---|
91 | } else { |
---|
92 | $valeurs = $data['produit_evalue']; |
---|
93 | } |
---|
94 | } else { |
---|
95 | $valeurs = $data['valeurs']; |
---|
96 | } |
---|
97 | $new_chapitre = substr($data['code'], 0, 2); |
---|
98 | if ($chapitre!=$new_chapitre) { |
---|
99 | $this->out .= str_replace(array("\r", "\n", "\\", '|'), array('\r', '\n', '\i', '\p'), $new_chapitre) .'|'; |
---|
100 | $this->out .= '"'. str_replace(array("\r", "\n", "\\", '|'), array('\r', '\n', '\i', '\p'), ($GLOBALS['association_metas']['plan_comptable_prerenseigne']?association_plan_comptable_complet($new_chapitre):sql_getfetsel('intitule','spip_asso_plan',"code='$new_chapitre'"))) .'|'; |
---|
101 | $this->out .= " | \n"; |
---|
102 | $chapitre = $new_chapitre; |
---|
103 | } |
---|
104 | $this->out .= str_replace(array("\r", "\n", "\\", '|'), array('\r', '\n', '\i', '\p'), $data['code']) .'|'; |
---|
105 | $this->out .= str_replace(array("\r", "\n", "\\", '|'), array('\r', '\n', '\i', '\p'), $data['intitule']) .'|'; |
---|
106 | $this->out .= $valeurs ."\n"; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | function Enregistre() { |
---|
111 | $fichier = _DIR_RACINE.'/'._NOM_TEMPORAIRES_ACCESSIBLES.'compte_resultats_'.$this->exercice.'.ctx'; |
---|
112 | $f = fopen($fichier, 'w'); |
---|
113 | fputs($f, $this->out); |
---|
114 | fclose($f); |
---|
115 | header('Content-type: application/ctx'); |
---|
116 | header('Content-Disposition: attachment; filename="'.$fichier.'"'); |
---|
117 | readfile($fichier); |
---|
118 | } |
---|
119 | |
---|
120 | } |
---|
121 | |
---|
122 | ?> |
---|