1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
<?php
/**
* $Id: chart.php,v 1.8 2003/03/26 08:31:28 courou Exp $
*
* Gnration d'un fichier SYLK partir de donnes MySQL en vue d'une rcupration sous Excel.
* L'avantange du format SYLK par rapport au format CSV est qu'il permet de dfinir des attributs
* de mise en forme pour les donnes : alignement,gras, itallique, formats de donnes, ..
* Auteur: J-Pierre DEZELUS
* Email: jpdezelus@phpinfo.net
* Web: http://www.phpinfo.net/
*
* Date: 02/12/2001
* Adaptation: Courou -- MyPhpMoney
* Web: http://allreponse.ath.cx
* Email: courou@users.sourceforge.net
*
* Support : http://sourceforge.net/projects/myphpmoney/
* CVS : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/myphpmoney/
*/
/**
* INCLUDE FILE
*/
require_once 'config/settings.inc.php';
/**
* ENTER IN THE SESSION OR BUILD THE LOGIN FORM
*/
if (SQL_VerifSession()) {
/**
* DEFINES VARIABLES FOR THE EXCEL FILE
*/
define('__ALIGN_RIGHT__', 'R'); ## ALIGN RIGHT
define('__ALIGN_LEFT__', 'L'); ## ALIGN LEFT
define('__ALIGN_CENTER__', 'C'); ## ALIGN CENTER
define('__FORMAT_REEL__', 1); ## #,##0.00
define('__FORMAT_ENTIER__', 2); ## #,##0
define('__FORMAT_TEXTE__', 3); ## @
$DEFINE_SYLK_FORMATS[__FORMAT_REEL__] = 'FF2'; ## FORMAT_REEL
$DEFINE_SYLK_FORMATS[__FORMAT_ENTIER__] = 'FF0'; ## FORMAT_ENTIER
$DEFINE_SYLK_FORMATS[__FORMAT_TEXTE__] = 'FG0'; ## FORMAT_TEXTE
if (isset($_POST['choix_duree']) && $_POST['choix_duree'] != '') $choix_duree = $_POST['choix_duree'];
if (isset($_POST['MT']) && $_POST['MT'] != '') $MT = $_POST['MT'];
if (isset($_POST['REMB']) && $_POST['REMB'] != '') $REMB = $_POST['REMB'];
if (isset($_POST['duree']) && $_POST['duree'] != '') $duree = $_POST['duree'];
if (isset($_POST['taux']) && $_POST['taux'] != '') $taux = $_POST['taux'];
if ($choix_duree == 1) $nbr_page = $duree * 12;
if ($choix_duree == 2) $nbr_page = $duree;
$taux_mensuelle = $taux / 12;
$MT = str_replace(' ','',$MT);
$REMB = str_replace(' ','',$REMB);
/**
* CHAMPS EN-TETE FORMAT ALIGN WIDTH
*/
$champs =
array
(
array('i', $_VAR['LANG_ACCOUNT_2'], __FORMAT_ENTIER__, __ALIGN_CENTER__, 5),
array('time', $_VAR['SIMUL_FORM_2'], __FORMAT_TEXTE__, __ALIGN_CENTER__, 10),
array('DETTE', $_VAR['SIMUL_FORM_3'], __FORMAT_TEXTE__, __ALIGN_CENTER__, 15),
array('REMB', $_VAR['SIMUL_FORM_4'], __FORMAT_TEXTE__, __ALIGN_CENTER__, 15),
array('INTERET', $_VAR['SIMUL_FORM_5'], __FORMAT_TEXTE__, __ALIGN_CENTER__, 15),
array('CAPITAL', $_VAR['SIMUL_FORM_6'], __FORMAT_TEXTE__, __ALIGN_CENTER__, 15),
array('INTERETPLUS', $_VAR['SIMUL_FORM_7'], __FORMAT_TEXTE__, __ALIGN_CENTER__, 20),
array('MONTANT', $_VAR['SIMUL_FORM_8'], __FORMAT_TEXTE__, __ALIGN_CENTER__, 15)
);
/**
* EN-TETE HTTP
*/
$tools->Construc_header('tableau.slk');
/**
* EN-TETE FILE
*/
$excel_file = "ID;MYPHPMONEY\n";
$excel_file .= "\n";
/**
* FORMATS
*/
$excel_file .= "P;PGeneral\n";
$excel_file .= "P;P#,##0.00\n"; ## P;Pformat_1 (reels)
$excel_file .= "P;P#,##0\n"; ## P;Pformat_2 (entiers)
$excel_file .= "P;P@\n"; ## P;Pformat_3 (textes)
$excel_file .= "\n";
/**
* POLICE
*/
$excel_file .= "P;EArial;M200\n";
$excel_file .= "P;EArial;M200\n";
$excel_file .= "P;EArial;M200\n";
$excel_file .= "P;FArial;M200;SB\n";
$excel_file .= "\n";
/**
* NUMBER OF LIGNES * NUMBERS OF COLUMN
*/
$excel_file .= "B;Y".($nbr_page-1);
$excel_file .= ";X".($nbcol = count($champs))."\n";
$excel_file .= "\n";
/**
* RECOVERY OF THE INFORMATION OF FORMATTING
*/
for ($cpt = 0; $cpt < $nbcol; $cpt++) {
$num_format[$cpt] = $champs[$cpt][2];
$format[$cpt] = $DEFINE_SYLK_FORMATS[ $num_format[$cpt] ] . $champs[$cpt][3];
}
/**
* WIDTH OF THE COLUMNS
*/
for ($cpt = 1; $cpt <= $nbcol; $cpt++) {
$excel_file .= "F;W".$cpt." ".$cpt." ".$champs[$cpt-1][4]."\n";
}
$excel_file .= "F;W".$cpt." 256 8\n";
$excel_file .= "\n";
/**
* EN-TETE OF THE COLUMNS (BOLD --> SDM4)
*/
for ($cpt = 1; $cpt <= $nbcol; $cpt++) {
$excel_file .= "F;SDM4;FG0C;".($cpt == 1 ? "Y1;" : "")."X".$cpt."\n";
$excel_file .= "C;N;K\"".$champs[$cpt-1][1]."\"\n";
}
$excel_file .= "\n";
/**
* THE DATAS
*/
$ligne = 2;
$incomeplus = '';
## FOR FIX BUG THE MONTH (29,30,31)
for ($i=1; $i <= $nbr_page; $i++) {
$income = round(((($i == 1 ? $MT : $MONTANT) * $taux_mensuelle) / 100),2);
$CAPITAL = $REMB - $income;
$MONTANT = ($i == 1 ? $MT : $MONTANT) - $CAPITAL;
$incomeplus += $income;
$_month = (($_MPM['date_gettime']['mon']) + ($i - 1));
$month = date('m',mktime(0,0,0,$_month));
if ($_MPM['date_gettime']['mday'] <= 28) {
$time = date('d-m-Y',mktime(0,0,0,$_month,$_MPM['date_gettime']['mday'],$_MPM['date_gettime']['year']));
} else if (($_MPM['date_gettime']['mday'] > 28) && ($_MPM['date_gettime']['mday'] < 32)) {
$der_j = $shuffle->getDaysInMonth($month,$_MPM['date_gettime']['year']);
if ($der_j >= $_MPM['date_gettime']['mday']) {
$der_j = $_MPM['date_gettime']['mday'];
} else {
$der_j = $der_j;
}
$time = date('d-m-Y',mktime(0,0,0,$_month,$der_j,$_MPM['date_gettime']['year']));
}
$enr[0] = $i;
$enr[1] = $time;
$enr[2] = $tools->formatage(($i == 1 ? $MT : $MONTANT));
$enr[3] = $tools->formatage($REMB);
$enr[4] = $tools->formatage($income);
$enr[5] = $tools->formatage($CAPITAL);
$enr[6] = $tools->formatage($incomeplus);
$enr[7] = $tools->formatage($MONTANT);
$j = $nbr_page - 1;
if ($i == $nbr_page) $enr[7]= 0;
if ($i == $j) $MONTANTs = $enr[7];
if ($i== $nbr_page) { $enr[5]= $MONTANTs; $enr[3]= $MONTANTs + $enr[4];}
/**
* THE FIELDS
*/
for ($cpt = 0; $cpt < $nbcol; $cpt++) {
/**
* FORMAT
*/
$excel_file .= "F;P".$num_format[$cpt].";".$format[$cpt];
$excel_file .= ($cpt == 0 ? ";Y".$ligne : "").";X".($cpt+1)."\n";
/**
* VALUE
*/
if ($num_format[$cpt] == __FORMAT_TEXTE__)
$excel_file .= "C;N;K\"".str_replace(';', ';;', $enr[$cpt])."\"\n"; ## ajout des ""
else
$excel_file .= "C;N;K".$enr[$cpt]."\n";
}
$excel_file .= "\n";
$ligne++;
} ## end of for $i <= $nbr_page
/**
* END OF THE FILE
*/
$excel_file .= "E\n";
echo $excel_file;
page_close();
} else {
XHTML_DisplayLogin();
XHTML_footer();
} ## end if (SQL_VerifSession())
|