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
|
<?php
/**
* $Id: simulate.php,v 1.12 2003/04/02 12:16:54 courou Exp $
*
* Author : courou@users.sourceforge.net
* Website : http://allreponse.ath.cx
*
* 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()) {
/**
* BUILD THE HEADER
*/
XHTML_header(1,0,1,1,1,1,1,1);
/**
* DEFINE VARIABLE GLOBALS
*/
$Formule = '';
$Val = '';
/**
* THE SWITCH POST
*/
if (!isset($_POST['opt'])) $_POST['opt'] = '';
switch($_POST['opt']) {
## THE TEMPLATES -- BUILD THE DEFAULT SIMULATION PAGE
default :
$_MPM['BeginMixed'] = array
(
'SIMUL_S_TITRE' => $_VAR['SIMUL_S_TITRE'],
'SIMUL_BODY' => $_VAR['SIMUL_BODY'],
'SIMULATION' => $_VAR['SIMULATION']
);
XHTML_SetFile('header_simulation.tpl',$_MPM['BeginMixed'],2);
break;
## AFFICHE LE TABLEAU POUR FAIRE LA SIMULATION
case $_VAR['SIMULATION'] :
case $_VAR['CALCULE'] :
if ($_POST['opt'] == $_VAR['CALCULE']) {
if ($_POST['MT'] == '') $Formule = 1;
if ($_POST['taux'] == '') $Formule = 2;
if ($_POST['duree'] == '') $Formule = 3;
if ($_POST['REMB'] == '') $Formule = 4;
if ($_POST['choix_duree'] == 1) $Val = 12;
if ($_POST['choix_duree'] == 2) $Val = 1;
$_POST['MT'] = str_replace(' ', '', $_POST['MT']);
$_POST['REMB'] = str_replace(' ', '', $_POST['REMB']);
switch($Formule) {
## Recherche du Montant de l'emprunt ==> MT = REMB * (1 - (1 + i )^-n) / i
case '1' :
$i = ($_POST['taux'] / 100) / 12;
$n = $_POST['duree'] * $Val;
if ($i != 0 && $n != 0 && $_POST['REMB'] != 0) $_POST['MT'] = $tools->formatage(round($_POST['REMB'] * (1-pow((1+$i),-$n)) / $i)); else $_POST['MT'] = $_VAR['AMORTISS_REPONSE'];
break;
## Recherche du Taux d'intret
case '2' :
$n = $_POST['duree'] * $Val;
$b2 = 1; ## au lieu de prendre 25% (0.25) comme valeur maxi , je prend 100% (1.00)
if ($_POST['REMB'] != 0 && $_POST['MT'] != 0 && $n != 0) {
if ((($n * $_POST['REMB']) < $_POST['MT'])) $trier = 1;
for ($t=0; $t < 10000000; $t++) {
if ($t == 0) $b1 = 0.005; else $b1 = $c;
$a1 = ((pow((1 + ($b1 / 12)),$n)) * (((($b1 * $_POST['MT']) / 12) - $_POST['REMB']) / $_POST['REMB']) + 1);
$a2 = ((pow((1 + ($b2 / 12)),$n)) * (((($b2 * $_POST['MT']) / 12) - $_POST['REMB']) / $_POST['REMB']) + 1);
if ($a2 <= 0) $trier = 1;
if ($a1 != 0 && $a2 != 0) {
$c = (($a2 * $b1) - ($a1 * $b2)) / ($a2 - $a1);
} else {
$trier = 1;
break;
}
if ((($c - $b1) < 0.00000001) && ($t > 9)) break;
}
$i = ((100000 * $c) + 15) / 1000;
$_POST['taux'] = $i;
$cherche = explode('.',$i);
$reste = substr($cherche[1], 0, 2);
if (isset($trier) && $trier == 1) {
$_POST['taux'] = $_VAR['AMORTISS_REPONSE'];
} else {
$_POST['taux'] = "$cherche[0].$reste";
}
} else {
$_POST['taux'] = $_VAR['AMORTISS_REPONSE'];
}
break;
## Recherche de la duree ==> n = - log((REMB - (MT * i)) / REMB) / log(1+i)
case '3' :
$i = ($_POST['taux'] / 100) / 12;
if ($i != 0 && $_POST['REMB'] != 0 && $_POST['MT'] != 0) {
$_POST['duree'] = round(- log(($_POST['REMB'] - ($_POST['MT'] * $i)) / $_POST['REMB']) / log(1+$i));
if ($_POST['duree'] % 12 == 0) {
$_POST['duree'] = $_POST['duree'] / 12;
$_POST['choix_duree'] = 1;
} else {
$_POST['choix_duree'] = 2;
}
} else {
$_POST['duree'] = $_VAR['AMORTISS_REPONSE'];
}
break;
## Recherche du Montant de l'emprunt ==> REMB = MT * i / 1 - (i+1)^-n
case '4' :
$i = ($_POST['taux'] / 100) / 12;
$n = $_POST['duree'] * $Val;
if ($i != 0 && $n != 0)
$_POST['REMB'] = $tools->formatage(($_POST['MT'] * $i)/(1-pow(($i+1),-$n)));
else
$_POST['REMB'] = $_VAR['AMORTISS_REPONSE'];
break;
} ## end of switch $Formule
$_MPM['BeginMixed'] = array
(
'AMORTISSEMENT' => $_VAR['AMORTISSEMENT'],
'AMORTISSEMENT_URL' => urlencode($_VAR['AMORTISSEMENT']),
'L_LISTING' => $_MPM['file_listing'],
'MT_STR' => str_replace(' ','',$_POST['MT']),
'TAUX_STR' => str_replace(' ','',$_POST['taux']),
'DUREE_STR' => str_replace(' ','',$_POST['duree']),
'REMB_STR' => str_replace(' ','',$_POST['REMB']),
'CHOIX_DUREE' => $_POST['choix_duree']
);
$w = XHTML_SetFile('opt_simulation_1.tpl',$_MPM['BeginMixed'],1);
} ## end of $_POST['opt'] == $_VAR['CALCULE']
$_MPM['BeginMixed'] = array
(
'IMG_TXT_EUROS' => (__DISPLAY_EURO__ == 2) ? $_MPM['lang_money_country'] : $_VAR['IMG_TXT_EUROS'],
'IMG_ALT_EUROS' => (__DISPLAY_EURO__ == 2) ? $_MPM['lang_money_country'] : $_VAR['IMG_ALT_EUROS'],
'SIMUL_ENTER_TITLE' => sprintf($_VAR['SIMUL_ENTER_TITLE'],$_MPM['name']),
'SIMUL_ENTER_FORM_1' => $_VAR['SIMUL_ENTER_FORM_1'],
'SIMUL_ENTER_FORM_2' => $_VAR['SIMUL_ENTER_FORM_2'],
'SIMUL_ENTER_FORM_3' => $_VAR['SIMUL_ENTER_FORM_3'],
'SIMUL_ENTER_FORM_4' => $_VAR['SIMUL_ENTER_FORM_4'],
'SIMUL_ENTER_FORM_5' => $_VAR['SIMUL_ENTER_FORM_5'],
'SIMUL_ENTER_FORM_6' => $_VAR['SIMUL_ENTER_FORM_6'],
'CALCULE' => $_VAR['CALCULE'],
'MT_SIMUL' => isset($_POST['MT']) ? $_POST['MT'] : '',
'TAUX_SIMUL' => isset($_POST['taux']) ? $_POST['taux'] : '',
'DUREE_SIMUL' => isset($_POST['duree']) ? $_POST['duree'] : '',
'REMB_SIMUL' => isset($_POST['REMB']) ? $_POST['REMB'] : '',
'SELECTED_1' => isset($_POST['choix_duree']) && $_POST['choix_duree'] == 1 ? ' selected="selected"' : '',
'SELECTED_2' => isset($_POST['choix_duree']) && $_POST['choix_duree'] == 2 ? ' selected="selected"' : '',
'OPTION_SIMULATION' => $_POST['opt'] == $_VAR['CALCULE'] ? $w : ''
);
XHTML_SetFile('form_simulation_2.tpl',$_MPM['BeginMixed'],2);
break;
} ## end of switch $_POST['opt']
} else {
XHTML_DisplayLogin();
} ## end if (SQL_VerifSession())
/**
* BUILD THE FOOTER
*/
XHTML_footer();
|