Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 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. //$sql = "INSER INTO test "
  39. //. "(IDVeh, Marca, Modelo, Fecha)"
  40. // . "(monthlyAmount, intRate)"
  41. // . "VALUES ('$ID', '$MAR')";
  42.  
  43. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  44.  
  45. if (!$qry) {
  46. die(mysqli_error());
  47.  
  48. }
  49. $result = mysqli_query($conn, $sql);
  50. while ($row = mysqli_fetch_object($result)) {
  51. $intAmount = (($row->monthlyAmount * $row->monthsOwed * ($row->intRate / 100)) / 30) * $row->pastDue;
  52. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  53. echo '<br>';
  54. echo 'Months past due: ' . $row->monthsOwed;
  55. echo '<br>';
  56. echo 'Interest rate per month: ' . $row->intRate;
  57. echo '<br>';
  58. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  59. echo '<br>';
  60. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  61. echo '<br>';
  62. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed));
  63. echo '<br>';
  64. echo 'Total: ' . floor(Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed));
  65. echo '<br>';
  66. echo '<br>';
  67. }
  68. ?>
  69. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  70. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  71. <tr>
  72. <td width = "100" >Account ID</td>
  73. <td><input name = "p_ID" type = "text" value="<?php echo $ID; ?>" id = "post_ID">
  74. </td>
  75. </tr>
  76. <tr>
  77. <td width = "100" >NUMBER OF MONTHS TO REMOVE</td>
  78. <td><input name = "p_Remove" type = "text" id = "post_Remove"></td>
  79. </tr>
  80. <tr>
  81. <td width = "100"> </td>
  82. <td>
  83. <input name = "recheck" type = "submit" id = "recheck" value = "RECHECK">
  84. </td>
  85. </tr>
  86. </table>
  87. </form>
  88.  
  89. <?php
  90.  
  91. mysqli_close($conn);
  92. } else if (isset($_POST['recheck'])) {
  93. $dbhost = '127.0.0.1';
  94. $dbuser = 'root';
  95. $dbpass = '';
  96. $db = 'dbvehiculos';
  97.  
  98. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  99.  
  100. if (!$conn) {
  101. die("Fallo en conexión: " . mysqli_error());
  102.  
  103. }
  104.  
  105. $db_select = mysqli_select_db($conn, $db);
  106.  
  107. if (!$db_select) {
  108. die("Fallo en conexión a base de datos: " . mysqli_error());
  109.  
  110. }
  111.  
  112. $ID = $_POST['p_ID'];
  113. $remove = $_POST['p_Remove'];
  114.  
  115. $sqlRemove = "UPDATE `test` SET monthsOwed = monthsOwed - " . $remove . " WHERE id=$ID";
  116. $qryRemove = mysqli_query($conn, $sqlRemove) or die('Consulta fallida');
  117.  
  118. if (!$qryRemove) {
  119. die(mysqli_error());
  120.  
  121. }
  122. $sql = "SELECT * FROM `test` WHERE id=$ID";
  123. //$sql = "INSER INTO test "
  124. //. "(IDVeh, Marca, Modelo, Fecha)"
  125. // . "(monthlyAmount, intRate)"
  126. // . "VALUES ('$ID', '$MAR')";
  127.  
  128. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  129.  
  130. if (!$qry) {
  131. die(mysqli_error());
  132.  
  133. }
  134. $result = mysqli_query($conn, $sql);
  135. while ($row = mysqli_fetch_object($result)) {
  136. $intAmount = (($row->monthlyAmount * ($row->intRate / 100)) / 30) * $row->pastDue;
  137. echo '<br>';
  138. echo '<br>';
  139. echo 'UPDATED AND REMOVED MONTHS';
  140. echo '<br>';
  141. echo 'RECALCULATED';
  142. echo '<br>';
  143. echo '<br>';
  144. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  145. echo '<br>';
  146. echo 'Months past due: ' . $row->monthsOwed;
  147. echo '<br>';
  148. echo 'Interest rate per month: ' . $row->intRate;
  149. echo '<br>';
  150. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  151. echo '<br>';
  152. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  153. echo '<br>';
  154. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed));
  155. echo '<br>';
  156. echo 'Total: ' . floor(Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed));
  157. echo '<br>';
  158. echo '<br>';
  159. }
  160. } else {
  161.  
  162. ?>
  163. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  164. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  165. <tr>
  166. <td width = "100">ID NUMBER</td>
  167. <td><input name = "p_ID" type = "text" id = "post_ID"></td>
  168. </tr>
  169. <tr>
  170. <td width = "100"> </td>
  171. <td> <input name = "check" type = "submit" id = "check" value = "CHECK">
  172. </td>
  173. </tr>
  174. </table>
  175. </form>
  176.  
  177. <?php
  178. }
  179. function Calculate($monthly, $rate, $months)
  180. {
  181. for ($i = 1; $i <= $months; $i++) {
  182. if ($i == 1) {
  183. $amount = ($monthly * ($rate)) + $monthly;
  184. } else if ($i <= $months) {
  185. $amount = ($amount + $monthly) + (($amount + $monthly) * ($rate));
  186. }
  187. }
  188. return $amount;
  189. }
  190. ?>
  191.  
  192.  
  193. </body>
  194. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement