Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title></title>
  11. </head>
  12. <body>
  13. <?php
  14.  
  15. if (isset($_POST['check'])) {
  16. $dbhost = '127.0.0.1';
  17. $dbuser = 'root';
  18. $dbpass = '';
  19. $db = 'dbvehiculos';
  20.  
  21. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  22.  
  23. if (!$conn) {
  24. die("Fallo en conexión: " . mysqli_error());
  25.  
  26. }
  27.  
  28. $db_select = mysqli_select_db($conn, $db);
  29.  
  30. if (!$db_select) {
  31. die("Fallo en conexión a base de datos: " . mysqli_error());
  32.  
  33. }
  34.  
  35. $ID = $_POST['p_ID'];
  36.  
  37. $sql = "SELECT * FROM `test` WHERE id=$ID";
  38.  
  39. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  40.  
  41. if (!$qry) {
  42. die(mysqli_error());
  43.  
  44. }
  45. $result = mysqli_query($conn, $sql);
  46. while ($row = mysqli_fetch_object($result)) {
  47. $intAmount = (($row->monthlyAmount * $row->monthsOwed * ($row->intRate / 100)) / 30) * $row->pastDue;
  48. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  49. echo '<br>';
  50. echo 'Months past due: ' . $row->monthsOwed;
  51. echo '<br>';
  52. echo 'Interest rate per month: ' . $row->intRate;
  53. echo '<br>';
  54. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  55. echo '<br>';
  56. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  57. echo '<br>';
  58. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed));
  59. echo '<br>';
  60. echo 'Total: ' . floor(Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed));
  61. echo '<br>';
  62. echo '<br>';
  63. }
  64. ?>
  65. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  66. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  67. <tr>
  68. <td width = "100" >Account ID</td>
  69. <td><input name = "p_ID" type = "text" value="<?php echo $ID; ?>" id = "post_ID">
  70. </td>
  71. </tr>
  72. <tr>
  73. <td width = "100" >NUMBER OF MONTHS TO REMOVE</td>
  74. <td><input name = "p_Remove" type = "text" id = "post_Remove"></td>
  75. </tr>
  76. <tr>
  77. <td width = "100"> </td>
  78. <td>
  79. <input name = "recheck" type = "submit" id = "recheck" value = "RECHECK">
  80. </td>
  81. </tr>
  82. </table>
  83. </form>
  84.  
  85. <?php
  86.  
  87. mysqli_close($conn);
  88. } else if (isset($_POST['recheck'])) {
  89. $dbhost = '127.0.0.1';
  90. $dbuser = 'root';
  91. $dbpass = '';
  92. $db = 'dbvehiculos';
  93.  
  94. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  95.  
  96. if (!$conn) {
  97. die("Fallo en conexión: " . mysqli_error());
  98.  
  99. }
  100.  
  101. $db_select = mysqli_select_db($conn, $db);
  102.  
  103. if (!$db_select) {
  104. die("Fallo en conexión a base de datos: " . mysqli_error());
  105.  
  106. }
  107.  
  108. $ID = $_POST['p_ID'];
  109. $remove = $_POST['p_Remove'];
  110.  
  111. $sqlRemove = "UPDATE `test` SET monthsOwed = monthsOwed - " . $remove . " WHERE id=$ID";
  112. $qryRemove = mysqli_query($conn, $sqlRemove) or die('Consulta fallida');
  113.  
  114. if (!$qryRemove) {
  115. die(mysqli_error());
  116.  
  117. }
  118. $sql = "SELECT * FROM `test` WHERE id=$ID";
  119.  
  120. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  121.  
  122. if (!$qry) {
  123. die(mysqli_error());
  124.  
  125. }
  126. $result = mysqli_query($conn, $sql);
  127. while ($row = mysqli_fetch_object($result)) {
  128. $intAmount = (($row->monthlyAmount * ($row->intRate / 100)) / 30) * $row->pastDue;
  129. echo '<br>';
  130. echo '<br>';
  131. echo 'UPDATED AND REMOVED MONTHS';
  132. echo '<br>';
  133. echo 'RECALCULATED';
  134. echo '<br>';
  135. echo '<br>';
  136. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  137. echo '<br>';
  138. echo 'Months past due: ' . $row->monthsOwed;
  139. echo '<br>';
  140. echo 'Interest rate per month: ' . $row->intRate;
  141. echo '<br>';
  142. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  143. echo '<br>';
  144. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  145. echo '<br>';
  146. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed));
  147. echo '<br>';
  148. echo 'Total: ' . floor(Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed));
  149. echo '<br>';
  150. echo '<br>';
  151. }
  152. } else {
  153.  
  154. ?>
  155. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  156. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  157. <tr>
  158. <td width = "100">ID NUMBER</td>
  159. <td><input name = "p_ID" type = "text" id = "post_ID"></td>
  160. </tr>
  161. <tr>
  162. <td width = "100"> </td>
  163. <td> <input name = "check" type = "submit" id = "check" value = "CHECK">
  164. </td>
  165. </tr>
  166. </table>
  167. </form>
  168.  
  169. <?php
  170. }
  171. function Calculate($monthly, $rate, $months)
  172. {
  173. for ($i = 1; $i <= $months; $i++) {
  174. if ($i == 1) {
  175. $amount = ($monthly * ($rate)) + $monthly;
  176. } else if ($i <= $months) {
  177. $amount = ($amount + $monthly) + (($amount + $monthly) * ($rate));
  178. }
  179. }
  180. return $amount;
  181. }
  182. ?>
  183.  
  184.  
  185. </body>
  186. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement