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