[59668] | 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 | |
---|
[59760] | 17 | include_spip('exec/compte_resultat'); // c'est pour la definition de classe ExportCompteResultats |
---|
| 18 | |
---|
| 19 | // Export du Compte de Resultat au format TSV |
---|
| 20 | // http://fr.wikipedia.org/wiki/Format_TSV |
---|
[59668] | 21 | function exec_export_compteresultats_tsv() { |
---|
| 22 | if (!autoriser('associer', 'export_compteresultats')) { |
---|
| 23 | include_spip('inc/minipres'); |
---|
| 24 | echo minipres(); |
---|
| 25 | } else { |
---|
[59760] | 26 | $tsv = new ExportCompteResultats(_request('var')); |
---|
| 27 | $tsv->LignesSimplesEntete("\t", "\n", array("\t"=>'\t',"\n"=>'\n'), '"', '"'); |
---|
[59668] | 28 | foreach (array('charges', 'produits', 'contributions_volontaires') as $key) { |
---|
[59760] | 29 | $tsv->LignesSimplesCorps($key, ',', "\n", array("\t"=>'\t',"\n"=>'\n'), '"', '"'); |
---|
[59668] | 30 | } |
---|
[59760] | 31 | $tsv->leFichier('tab'); |
---|
[59668] | 32 | } |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * Utilisation d'une classe tres tres tres simple !!! |
---|
| 37 | */ |
---|
[59760] | 38 | class TSV extends ExportCompteResultats { |
---|
[59668] | 39 | |
---|
| 40 | function EnTete() { |
---|
| 41 | $this->out .= str_replace(array("\t","\n"), array('\t','\n'), utf8_decode(html_entity_decode(_T('asso:entete_code')))) ."\t"; |
---|
| 42 | $this->out .= str_replace(array("\t","\n"), array('\t','\n'), utf8_decode(html_entity_decode(_T('asso:entete_intitule')))) ."\t"; |
---|
| 43 | $this->out .= str_replace(array("\t","\n"), array('\t','\n'), utf8_decode(html_entity_decode(_T('asso:entete_montant')))) ."\n"; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function LesEcritures($key) { |
---|
| 47 | switch ($key) { |
---|
| 48 | case 'charges' : |
---|
| 49 | $quoi = "SUM(depense) AS valeurs"; |
---|
| 50 | break; |
---|
| 51 | case 'produits' : |
---|
| 52 | $quoi = "SUM(recette) AS valeurs"; |
---|
| 53 | break; |
---|
| 54 | case 'contributions_volontaires' : |
---|
| 55 | $quoi = "SUM(depense) AS charge_evaluee, SUM(recette) AS produit_evalue"; |
---|
| 56 | break; |
---|
| 57 | } |
---|
| 58 | $query = sql_select( |
---|
| 59 | "imputation, $quoi, DATE_FORMAT(date, '%Y') AS annee".$this->sel, // select |
---|
| 60 | 'spip_asso_comptes '.$this->join, // from |
---|
| 61 | $this->where, // where |
---|
| 62 | $this->order, // group by |
---|
| 63 | $this->order, // order by |
---|
| 64 | '', // limit |
---|
| 65 | $this->having .$GLOBALS['association_metas']['classe_'.$key] // having |
---|
| 66 | ); |
---|
| 67 | $chapitre = ''; |
---|
| 68 | $i = 0; |
---|
| 69 | while ($data = sql_fetch($query)) { |
---|
| 70 | if ($key==='contributions_volontaires') { |
---|
| 71 | if ($data['charge_evaluee']>0) { |
---|
| 72 | $valeurs = $data['charge_evaluee']; |
---|
| 73 | } else { |
---|
| 74 | $valeurs = $data['produit_evalue']; |
---|
| 75 | } |
---|
| 76 | } else { |
---|
| 77 | $valeurs = $data['valeurs']; |
---|
| 78 | } |
---|
| 79 | $new_chapitre = substr($data['code'], 0, 2); |
---|
| 80 | if ($chapitre!=$new_chapitre) { |
---|
| 81 | $this->out .= str_replace(array("\t","\n"), array('\t','\n'), $new_chapitre) .'",'; |
---|
| 82 | $this->out .= str_replace(array("\t","\n"), array('\t','\n'), ($GLOBALS['association_metas']['plan_comptable_prerenseigne']?association_plan_comptable_complet($new_chapitre):sql_getfetsel('intitule','spip_asso_plan',"code='$new_chapitre'"))) ."\t\n"; |
---|
| 83 | $chapitre = $new_chapitre; |
---|
| 84 | } |
---|
| 85 | $this->out .= str_replace(array("\t","\n"), array('\t','\n'), $data['code']) ."\t"; |
---|
| 86 | $this->out .= str_replace(array("\t","\n"), array('\t','\n'), $data['intitule']) ."\t"; |
---|
| 87 | $this->out .= $valeurs."\n"; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | ?> |
---|