[55930] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /* * *************************************************************************\ |
---|
| 4 | * Associaspip, extension de SPIP pour gestion d'associations * |
---|
| 5 | * * |
---|
[56181] | 6 | * Copyright (c) 2007 Bernard Blazin & François de Montlivault (V1) * |
---|
[55930] | 7 | * Copyright (c) 2010-2011 Emmanuel Saint-James & Jeannot Lapin (V2) * |
---|
[56181] | 8 | * Ecrit par Marcel BOLLA en 01/2012 * |
---|
[55930] | 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 | |
---|
[57780] | 14 | if (!defined('_ECRIRE_INC_VERSION')) |
---|
[55930] | 15 | return; |
---|
| 16 | |
---|
[56181] | 17 | // Export du Compte de Resultat au format Xml |
---|
[59668] | 18 | function exec_export_compteresultats_xml() { |
---|
| 19 | if (!autoriser('associer', 'export_compteresultats_xml')) { |
---|
[55930] | 20 | include_spip('inc/minipres'); |
---|
| 21 | echo minipres(); |
---|
[59668] | 22 | } else { |
---|
[56181] | 23 | include_spip('inc/charsets'); |
---|
| 24 | include_spip('inc/association_plan_comptable'); |
---|
[55930] | 25 | $var = _request('var'); |
---|
[56181] | 26 | $xml = new XML($var); |
---|
| 27 | $xml->EnTete(); |
---|
| 28 | foreach (array('charges', 'produits', 'contributions_volontaires') as $key) { |
---|
| 29 | $xml->LesEcritures($key); |
---|
| 30 | } |
---|
| 31 | $xml->Pied(); |
---|
[59668] | 32 | $xml->Enregistre(); |
---|
[55930] | 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
[56181] | 36 | /** |
---|
| 37 | * Utilisation d'une classe tres tres tres simple !!! |
---|
| 38 | */ |
---|
| 39 | class XML { |
---|
| 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) { |
---|
[59668] | 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]; |
---|
[56181] | 57 | $this->out = ''; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | function EnTete() { |
---|
[59668] | 61 | $this->out .= '<?xml version="1.0" encoding="'.$GLOBALS['meta']['charset'].'"?>'."\n"; |
---|
| 62 | $this->out .= "<CompteDeResultat>\n"; |
---|
| 63 | $this->out .= "<Entete>\n"; |
---|
| 64 | $this->out .= '<Titre>'. utf8_decode(html_entity_decode(_T('asso:cpte_resultat_titre_general'))) ."</Titre>\n"; |
---|
| 65 | $this->out .= '<Nom>'. $GLOBALS['association_metas']['nom'] ."</Nom>\n"; |
---|
| 66 | $this->out .= '<Exercice>'. sql_asso1champ('exercice', $this->exercice, 'intitule') ."</Exercice>\n"; |
---|
| 67 | $this->out .= "</Entete>\n"; |
---|
[56181] | 68 | } |
---|
| 69 | |
---|
| 70 | function LesEcritures($key) { |
---|
| 71 | switch ($key) { |
---|
| 72 | case 'charges' : |
---|
[57780] | 73 | $quoi = "SUM(depense) AS valeurs"; |
---|
[56181] | 74 | break; |
---|
| 75 | case 'produits' : |
---|
[57780] | 76 | $quoi = "SUM(recette) AS valeurs"; |
---|
[56181] | 77 | break; |
---|
| 78 | case 'contributions_volontaires' : |
---|
[57780] | 79 | $quoi = "SUM(depense) AS charge_evaluee, SUM(recette) AS produit_evalue"; |
---|
[56181] | 80 | break; |
---|
| 81 | } |
---|
[59668] | 82 | $this->out .= '<'. ucfirst($key) .">\n"; |
---|
[56181] | 83 | $query = sql_select( |
---|
[59668] | 84 | "imputation, $quoi, DATE_FORMAT(date, '%Y') AS annee ".$this->sel, // select |
---|
| 85 | 'spip_asso_comptes'.$this->join, // from |
---|
| 86 | $this->where, // where |
---|
| 87 | $this->order, // group by |
---|
| 88 | $this->order, // order by |
---|
| 89 | '', // limit |
---|
| 90 | $this->having .$GLOBALS['association_metas']['classe_'.$key] // having |
---|
| 91 | ); |
---|
[56181] | 92 | $chapitre = ''; |
---|
| 93 | $i = 0; |
---|
| 94 | while ($data = sql_fetch($query)) { |
---|
[57780] | 95 | if ($key==='contributions_volontaires') { |
---|
[59668] | 96 | if ($data['charge_evaluee']>0) { |
---|
| 97 | $valeurs = $data['charge_evaluee']; |
---|
| 98 | } else { |
---|
| 99 | $valeurs = $data['produit_evalue']; |
---|
| 100 | } |
---|
| 101 | } else { |
---|
[56181] | 102 | $valeurs = $data['valeurs']; |
---|
| 103 | } |
---|
| 104 | $new_chapitre = substr($data['code'], 0, 2); |
---|
[57780] | 105 | if ($chapitre!=$new_chapitre) { |
---|
| 106 | if ($chapitre!='') { |
---|
[59668] | 107 | $this->out .= "</Chapitre>\n"; |
---|
[56181] | 108 | } |
---|
[59668] | 109 | $this->out .= "<Chapitre>\n"; |
---|
| 110 | $this->out .= '<Code>'. str_replace(array('<','>'), array('<','>'), $new_chapitre) ."</Code>\n"; |
---|
| 111 | $this->out .= '<Libelle>'. str_replace(array('<','>'), array('<','>'), ($GLOBALS['association_metas']['plan_comptable_prerenseigne']?association_plan_comptable_complet($new_chapitre):sql_getfetsel('intitule','spip_asso_plan',"code='$new_chapitre'"))) ."</Libelle>\n"; |
---|
[56181] | 112 | $chapitre = $new_chapitre; |
---|
| 113 | } |
---|
[59668] | 114 | $this->out .= "<Categorie>\n"; |
---|
| 115 | $this->out .= '<Code>'. str_replace(array('<','>'), array('<','>'), $data['code']) ."</Code>\n"; |
---|
| 116 | $this->out .= '<Intitule>'. str_replace(array('<','>'), array('<','>'), $data['intitule']) ."</Intitule>\n"; |
---|
| 117 | $this->out .= "<Montant>$valeurs</Montant>\n"; |
---|
| 118 | $this->out .= "</Categorie>\n"; |
---|
[56181] | 119 | } |
---|
[57780] | 120 | if ($chapitre!='') { |
---|
[59668] | 121 | $this->out .= "</Chapitre>\n"; |
---|
[56181] | 122 | } |
---|
[57780] | 123 | $this->out .= '</'. ucfirst($key) .'>'."\n"; |
---|
[56181] | 124 | } |
---|
| 125 | |
---|
| 126 | function Pied() { |
---|
[57780] | 127 | $this->out .= '</CompteDeResultat>'."\n"; |
---|
[56181] | 128 | } |
---|
| 129 | |
---|
[59668] | 130 | function Enregistre() { |
---|
| 131 | $fichier =_DIR_RACINE.'/'._NOM_TEMPORAIRES_ACCESSIBLES.'compte_resultats_'.$this->exercice.'.xml'; |
---|
[56181] | 132 | $f = fopen($fichier, 'w'); |
---|
| 133 | fputs($f, $this->out); |
---|
| 134 | fclose($f); |
---|
| 135 | header('Content-Type: text/xml'); |
---|
| 136 | header('Content-Type: application/xml'); |
---|
[59668] | 137 | header('Content-Disposition: attachment; filename="'.$fichier.'"'); |
---|
[56181] | 138 | readfile($fichier); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | ?> |
---|