Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <?php
- if(isset($_POST['check'])){
- $dbhost = '127.0.0.1';
- $dbuser = 'root';
- $dbpass= '';
- $db = 'dbvehiculos';
- $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
- if(! $conn){
- die ("Fallo en conexión: " . mysqli_error());
- }
- $db_select = mysqli_select_db($conn, $db);
- if(! $db_select){
- die ("Fallo en conexión a base de datos: " .
- mysqli_error());
- }
- $ID = $_POST['v_ID'];
- $sql = "SELECT * FROM `test` WHERE id=$ID";
- //$sql = "INSER INTO test "
- //. "(IDVeh, Marca, Modelo, Fecha)"
- // . "(monthlyAmount, intRate)"
- // . "VALUES ('$ID', '$MAR')";
- $qry = mysqli_query($conn, $sql) or
- die ('Consulta fallida');
- if(! $qry){
- die(mysqli_error());
- }
- $result = mysqli_query($conn, $sql);
- while ($row = mysqli_fetch_object($result)) {
- $intAmount = (($row->monthlyAmount * $row->monthsOwed * ($row->intRate/100))/30)*$row->pastDue;
- echo 'Amount Owed per month: ' .$row->monthlyAmount;
- echo '<br>';
- echo 'Months past due: ' .$row->monthsOwed;
- echo '<br>';
- echo 'Interest rate per month: ' .$row->intRate;
- echo '<br>';
- echo 'Daily interest: ' .$row->intRate*$row->monthsOwed/30;
- echo '<br>';
- echo 'Rent due: ' .$row->monthlyAmount * $row->monthsOwed;
- echo '<br>';
- echo 'Interest charge: ' .(Calculate($row->monthlyAmount, $row->intRate/100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed));
- echo '<br>';
- echo 'Total: ' . floor(Calculate($row->monthlyAmount, $row->intRate/100, $row->monthsOwed));
- echo '<br>';
- echo '<br>';
- }
- ?>
- <form method = "post" action = "<?php $_PHP_SELF ?>">
- <table width = "400" border = "0" cellspacing = "1"
- cellpadding = "2">
- <tr>
- <td width = "100" >Account ID</td>
- <td><input name = "v_ID" type = "text" value="<?php echo$ID ?>"
- id = "veh_ID"></td>
- </tr>
- <tr>
- <td width = "100" >NUMBER OF MONTHS TO REMOVE</td>
- <td><input name = "v_Remove" type = "text"
- id = "veh_Remove"></td>
- </tr>
- <tr>
- <td width = "100"> </td>
- <td>
- <input name = "recheck" type = "submit" id = "recheck"
- value = "RECHECK">
- </td>
- </tr>
- </table>
- </form>
- <?php
- mysqli_close($conn);
- }
- else if(isset($_POST['recheck'])){
- $dbhost = '127.0.0.1';
- $dbuser = 'root';
- $dbpass= '';
- $db = 'dbvehiculos';
- $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
- if(! $conn){
- die ("Fallo en conexión: " . mysqli_error());
- }
- $db_select = mysqli_select_db($conn, $db);
- if(! $db_select){
- die ("Fallo en conexión a base de datos: " .
- mysqli_error());
- }
- $ID = $_POST['v_ID'];
- $remove = $_POST['v_Remove'];
- $sqlRemove = "UPDATE `test` SET monthsOwed = monthsOwed - " . $remove . " WHERE id=$ID";
- $qryRemove = mysqli_query($conn, $sqlRemove) or
- die ('Consulta fallida');
- if(! $qryRemove){
- die(mysqli_error());
- }
- $sql = "SELECT * FROM `test` WHERE id=$ID";
- //$sql = "INSER INTO test "
- //. "(IDVeh, Marca, Modelo, Fecha)"
- // . "(monthlyAmount, intRate)"
- // . "VALUES ('$ID', '$MAR')";
- $qry = mysqli_query($conn, $sql) or
- die ('Consulta fallida');
- if(! $qry){
- die(mysqli_error());
- }
- $result = mysqli_query($conn, $sql);
- while ($row = mysqli_fetch_object($result)) {
- $intAmount = (($row->monthlyAmount * ($row->intRate/100))/30)*$row->pastDue;
- echo '<br>';
- echo '<br>';
- echo 'UPDATED AND REMOVED MONTHS';
- echo '<br>';
- echo 'RECALCULATED';
- echo '<br>';
- echo '<br>';
- echo 'Amount Owed per month: ' .$row->monthlyAmount;
- echo '<br>';
- echo 'Months past due: ' .$row->monthsOwed;
- echo '<br>';
- echo 'Interest rate per month: ' .$row->intRate;
- echo '<br>';
- echo 'Daily interest: ' .$row->intRate*$row->monthsOwed/30;
- echo '<br>';
- echo 'Rent due: ' .$row->monthlyAmount * $row->monthsOwed;
- echo '<br>';
- echo 'Interest charge: ' .(Calculate($row->monthlyAmount, $row->intRate/100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed));
- echo '<br>';
- echo 'Total: ' . floor(Calculate($row->monthlyAmount, $row->intRate/100, $row->monthsOwed));
- echo '<br>';
- echo '<br>';
- }
- }
- else{
- ?>
- <form method = "post" action = "<?php $_PHP_SELF ?>">
- <table width = "400" border = "0" cellspacing = "1"
- cellpadding = "2">
- <tr>
- <td width = "100">ID NUMBER</td>
- <td><input name = "v_ID" type = "text"
- id = "veh_ID"></td>
- </tr>
- <tr>
- <td width = "100"> </td>
- <td>
- <input name = "check" type = "submit" id = "check"
- value = "CHECK">
- </td>
- </tr>
- </table>
- </form>
- <?php
- }
- function Calculate($monthly, $rate, $months){
- for ($i=1; $i<=$months; $i++){
- if($i==1){
- //does the very first month and stores it in $amount
- $amount = ($monthly * ($rate)) + $monthly;
- }
- else if ($i<=$months){
- //does every other month until 12 months
- $amount = ($amount + $monthly) + (($amount + $monthly) * ($rate));
- }
- }
- return $amount;
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement