‘Semanal’, 30 => ‘Mensual’, 15 => ‘Quincenal’, ); $loan_amount = isset($_GET[“loan_amount”]) ? $_GET[“loan_amount”] : 10000; $total_periods = isset($_GET[“total_periods”]) ? $_GET[“total_periods”] : 12; $annual_interest = isset($_GET[“annual_interest”]) ? $_GET[“annual_interest”] : 7; $pay_periodicity = isset($_GET[“pay_periodicity”]) ? $_GET[“pay_periodicity”] : 30; $periodicity = $periods[$pay_periodicity]; $pay_periods = ”; foreach($periods as $value => $name) { $selected = ($pay_periodicity == $value) ? ‘selected’ : ”; $pay_periods .= replace_vars($pay_period_option); } // validando el tiempo if($pay_periodicity == 30) // para meses { if($total_periods > 48) // debe ser menor que 48 meses { $error = “

El tiempo de prestamo para Rapicoop tiene que ser menor o igual a 48 meses

“; } } if($pay_periodicity == 7) // para semanas { if($total_periods > 208) // debe ser menor que 48 meses o 208 semanas { $error = “

El tiempo de prestamo para Rapicoop tiene que ser menor o igual a 48 meses

“; } } if($pay_periodicity == 15) // para quincenas { if($total_periods > 96 ) // debe ser menor que 48 meses o 96 quincenas { $error = “

El tiempo de prestamo para Rapicoop tiene que ser menor o igual a 48 meses

“; } } /* revisando las variables */ if(!is_numeric($loan_amount) or $loan_amount <= 0) { $error = "

El monto a solicitar tiene que ser numerico y mayor que cero

“; } // if($loan_amount <= 3000) { $annual_interest = 42.58; } if($loan_amount < 300) { $error = "

El monto a solicitar para Rapicoop tiene que ser mayor o igual a S/300 nuevos soles

“; } if($loan_amount > 3000) { $annual_interest = 39.29; } // if(!is_numeric($total_periods) or $total_periods <= 0) { $error = "

El tiempo tiene que ser numerico y mayor que cero.

“; } if(!is_numeric($annual_interest) or $annual_interest <= 0) { $error = "

El Interes anualtiene que ser numerico y mayor que cero.

“; } /* *———————————- * calculando *———————————- */ /* Process Loan Parameters Form in any case */ $loan_parameters_form = replace_vars($loan_parameters_form); /* If no error, then begin calculations */ if(!isset($error) && isset($_GET[‘action’])) { $c_balance = $loan_amount; //$total_periods = $loan_length * $pay_periodicity; // $mensual_interest va ser mi variable para la taza ya sea mensual anual o quincenal $mensual_interest = ( ( pow ( 1 + $annual_interest/100 , $pay_periodicity /360) ) -1 )* 100 ; $interest_percent = $mensual_interest / 100; $period_interest = $interest_percent / $pay_periodicity; // $c_period_payment = $loan_amount * ($period_interest / (1 – pow((1 + $period_interest), -($total_periods)))); formula erronea $c_period_payment = $loan_amount * ( $interest_percent * ( pow((1 + $interest_percent), ($total_periods)) ) / ( pow((1 + $interest_percent), ($total_periods)) – 1 )); $total_paid = number_format($c_period_payment * $total_periods, 2, ‘.’, ‘ ‘); $total_interest = number_format($c_period_payment * $total_periods – $loan_amount, 2, ‘.’, ‘ ‘); $total_principal = number_format($loan_amount, 2, ‘.’, ‘ ‘); $loan_amount = number_format($loan_amount, 2, ‘.’, ‘ ‘); $annual_interest = number_format($annual_interest, 2, ‘.’, ‘ ‘); $period_payment = number_format($c_period_payment, 2, ‘.’, ‘ ‘); $amortization_table_rows = ”; for($period = 1; $period <= $total_periods; $period++) { $c_interest = $c_balance * $interest_percent; $c_principal = $c_period_payment - $c_interest; $c_balance -= $c_principal; $interest = number_format($c_interest, 2, '.', ' '); $principal = number_format($c_principal, 2, '.', ' '); $balance = number_format($c_balance, 2, '.', ' '); $evenrow_row_modifier = ($period % 2) ? '' : 'class=evenrow'; $amortization_table_rows .= replace_vars($amortization_table_row); } } else { $amortization_table = ''; $loan_summary = ''; } $body = replace_vars($body); /* If headers sent, then it means that the script is used as inclusion */ if(!headers_sent()) { $send_footer = true; echo strip($header); } echo strip(replace_vars($body)); if(isset($send_footer)) { echo strip($footer); } /* *---------------------------------- * Funciones *---------------------------------- */ function replace_vars($tpl) { return preg_replace_callback("/\{(.+?)\}/", "glb", $tpl); } function glb($m) { if(isset($GLOBALS[$m[1]])) { return $GLOBALS[$m[1]]; } } function load_template($path) { /* Loads template from file */ $h = fopen($path, "r"); $file = fread($h, filesize($path)); fclose($h); preg_match_all('/(.+?)/is’, $file, $m); for($i=0; $i