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 6.64 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['v_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
  70. $_PHP_SELF;
  71. ?>">
  72. <table width = "400" border = "0" cellspacing = "1"
  73. cellpadding = "2">
  74. <tr>
  75. <td width = "100" >Account ID</td>
  76. <td><input name = "v_ID" type = "text" value="<?php
  77. echo $ID;
  78. ?>"
  79. id = "veh_ID"></td>
  80. </tr>
  81. <tr>
  82. <td width = "100" >NUMBER OF MONTHS TO REMOVE</td>
  83. <td><input name = "v_Remove" type = "text"
  84. id = "veh_Remove"></td>
  85. </tr>
  86. <tr>
  87. <td width = "100"> </td>
  88. <td>
  89. <input name = "recheck" type = "submit" id = "recheck"
  90. value = "RECHECK">
  91. </td>
  92. </tr>
  93. </table>
  94. </form>
  95. <?php
  96.  
  97. mysqli_close($conn);
  98. } else if (isset($_POST['recheck'])) {
  99. $dbhost = '127.0.0.1';
  100. $dbuser = 'root';
  101. $dbpass = '';
  102. $db = 'dbvehiculos';
  103.  
  104. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  105.  
  106. if (!$conn) {
  107. die("Fallo en conexión: " . mysqli_error());
  108.  
  109. }
  110.  
  111. $db_select = mysqli_select_db($conn, $db);
  112.  
  113. if (!$db_select) {
  114. die("Fallo en conexión a base de datos: " . mysqli_error());
  115.  
  116. }
  117.  
  118. $ID = $_POST['v_ID'];
  119. $remove = $_POST['v_Remove'];
  120.  
  121. $sqlRemove = "UPDATE `test` SET monthsOwed = monthsOwed - " . $remove . " WHERE id=$ID";
  122. $qryRemove = mysqli_query($conn, $sqlRemove) or die('Consulta fallida');
  123.  
  124. if (!$qryRemove) {
  125. die(mysqli_error());
  126.  
  127. }
  128. $sql = "SELECT * FROM `test` WHERE id=$ID";
  129. //$sql = "INSER INTO test "
  130. //. "(IDVeh, Marca, Modelo, Fecha)"
  131. // . "(monthlyAmount, intRate)"
  132. // . "VALUES ('$ID', '$MAR')";
  133.  
  134. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  135.  
  136. if (!$qry) {
  137. die(mysqli_error());
  138.  
  139. }
  140. $result = mysqli_query($conn, $sql);
  141. while ($row = mysqli_fetch_object($result)) {
  142. $intAmount = (($row->monthlyAmount * ($row->intRate / 100)) / 30) * $row->pastDue;
  143. echo '<br>';
  144. echo '<br>';
  145. echo 'UPDATED AND REMOVED MONTHS';
  146. echo '<br>';
  147. echo 'RECALCULATED';
  148. echo '<br>';
  149. echo '<br>';
  150. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  151. echo '<br>';
  152. echo 'Months past due: ' . $row->monthsOwed;
  153. echo '<br>';
  154. echo 'Interest rate per month: ' . $row->intRate;
  155. echo '<br>';
  156. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  157. echo '<br>';
  158. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  159. echo '<br>';
  160. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed));
  161. echo '<br>';
  162. echo 'Total: ' . floor(Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed));
  163. echo '<br>';
  164. echo '<br>';
  165. }
  166. } else {
  167.  
  168. ?>
  169. <form method = "post" action = "<?php
  170. $_PHP_SELF;
  171. ?>">
  172. <table width = "400" border = "0" cellspacing = "1"
  173. cellpadding = "2">
  174. <tr>
  175. <td width = "100">ID NUMBER</td>
  176. <td><input name = "v_ID" type = "text"
  177. id = "veh_ID"></td>
  178. </tr>
  179. <tr>
  180. <td width = "100"> </td>
  181. <td>
  182. <input name = "check" type = "submit" id = "check"
  183. value = "CHECK">
  184. </td>
  185. </tr>
  186. </table>
  187. </form>
  188.  
  189. <?php
  190. }
  191. function Calculate($monthly, $rate, $months)
  192. {
  193. for ($i = 1; $i <= $months; $i++) {
  194. if ($i == 1) {
  195. //does the very first month and stores it in $amount
  196. $amount = ($monthly * ($rate)) + $monthly;
  197. } else if ($i <= $months) {
  198. //does every other month until 12 months
  199. $amount = ($amount + $monthly) + (($amount + $monthly) * ($rate));
  200. }
  201. }
  202. return $amount;
  203. }
  204. ?>
  205.  
  206.  
  207. </body>
  208. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement