Advertisement
Guest User

Untitled

a guest
Mar 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.92 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4. <!DOCTYPE html>
  5. <!--
  6. To change this license header, choose License Headers in Project Properties.
  7. To change this template file, choose Tools | Templates
  8. and open the template in the editor.
  9. -->
  10. <html>
  11. <head>
  12. <meta charset="UTF-8">
  13. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  14. <script src="dist/js/bootstrap.js" type="text/javascript"></script>
  15. <link href="dist/css/bootstrap.css" rel="stylesheet" type="text/css"/>
  16. <title>Ventanilla</title>
  17. </head>
  18. <body>
  19. <nav class="navbar navbar-expand-lg navbar-light bg-light">
  20. <!--En vez de home tiene que ir la pagina de inicio esto en la referencia y
  21. en el nombre que aparece seria como el nombre que le vamos a dar no la del login-->
  22. <a class="navbar-brand" href="PaginaInicio.php">Programación IV</a>
  23. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  24. <span class="navbar-toggler-icon"></span>
  25. </button>
  26.  
  27. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  28. <ul class="navbar-nav mr-auto">
  29. <li class="nav-item active">
  30. <!-- en esta solo la referencia a la pagina de inicio-->
  31. <a class="nav-link" href="PaginaInicio.php">Home <span class="sr-only">(current)</span></a>
  32. </li>
  33. <li class="nav-item">
  34. <a class="nav-link" href="Vista_cajero.php">Cajero</a>
  35. </li>
  36. <li class="nav-item">
  37. <a class="nav-link" href="Ventanilla.php">Ventanilla</a>
  38. </li>
  39. </ul>
  40. </div>
  41. </nav>
  42.  
  43. <!--Este seria el menu de la pagina ventanilla-->
  44. <div class="nav flex-row nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
  45. <a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Pagina principal</a>
  46. <a class="nav-link" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">Pago de Alquiler</a>
  47. <a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Ingreso de alquiler</a>
  48. <a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Verificar Saldo</a>
  49. </div>
  50.  
  51. <!--Despliega la pagina principal de ventanilla-->
  52. <div class="tab-content" id="v-pills-tabContent">
  53. <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
  54. <div class="jumbotron jumbotron-fluid" >
  55. <div class="container">
  56. <h1 class="display-4">Bienvenido <?php echo $_SESSION['username']?></h1>
  57. </div>
  58. </div>
  59. </div>
  60.  
  61. <!--Despliega la informacion para hacer un pago-->
  62. <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
  63. <h1>Pago de alquiler</h1>
  64.  
  65. <?php
  66.  
  67. //function for connecting to the database
  68. function Connect(){
  69. $dbhost = '127.0.0.1';
  70. $dbuser = 'root';
  71. $dbpass = '';
  72. $db = 'pruebaprog4';
  73.  
  74. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  75.  
  76. if (!$conn) {
  77. die("Fallo en conexión: " . mysqli_error());
  78. }
  79.  
  80. $db_select = mysqli_select_db($conn, $db);
  81.  
  82. if (!$db_select) {
  83. die("Fallo en conexión a base de datos: " . mysqli_error());
  84. }
  85. return $conn;
  86. }
  87.  
  88. //searches the database for the id number input - this runs first
  89. if (isset($_POST['check'])) {
  90. $conn = Connect();
  91.  
  92. $ID = $_POST['p_ID'];
  93.  
  94. //finds the row with the ID number
  95. $sql = "SELECT * FROM `test` WHERE id=$ID";
  96.  
  97. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  98.  
  99. if (!$qry) {
  100. die(mysqli_error());
  101.  
  102. }
  103. //result is whats returned from the database
  104. $result = mysqli_query($conn, $sql);
  105. //row is the row inside $result which has all the row information from the database like monnthlyAmount, intRate, monthsOwed, etc
  106. while ($row = mysqli_fetch_object($result)) {
  107. //this code is just showing the information in the browser
  108. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  109. echo '<br>';
  110. echo 'Months past due: ' . $row->monthsOwed;
  111. echo '<br>';
  112. echo 'Interest rate per month: ' . $row->intRate;
  113. echo '<br>';
  114. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  115. echo '<br>';
  116. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  117. echo '<br>';
  118. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed)); //calculates the interest amount with the Calculate function
  119. echo '<br>';
  120. echo 'Total: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed)); //calculates the total amount using the Calculate function
  121. echo '<br>';
  122. echo '<br>';
  123. }
  124. mysqli_close($conn);
  125.  
  126. ?>
  127. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  128. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  129. <tr>
  130. <td width = "100" >Numero de cuenta</td>
  131. <td><input name = "p_ID" type = "text" value="<?php echo $ID; ?>" id = "post_ID">
  132. </td>
  133. </tr>
  134. <tr>
  135. <td width = "100" >Numero de meses a cancelar</td>
  136. <td><input name = "p_Remove" type = "text" id = "post_Remove"></td>
  137. </tr>
  138. <tr>
  139. <td width = "100"> </td>
  140. <td>
  141. <input name = "recheck" class="btn btn-success" type = "submit" id = "recheck" value = "Pagar">
  142. </td>
  143. </tr>
  144. </table>
  145. </form>
  146.  
  147. <?php
  148.  
  149. }
  150. //removes the entered months from the database and recalculates the amount - this runs second
  151. else if (isset($_POST['recheck'])) {
  152. $conn = Connect();
  153.  
  154. $ID = $_POST['p_ID'];
  155. $remove = $_POST['p_Remove'];
  156.  
  157. //removes the typed in amount of months from the database with the ID number that was typed in at the start
  158. $sqlRemove = "UPDATE `test` SET monthsOwed = monthsOwed - " . $remove . " WHERE id=$ID";
  159.  
  160. $qryRemove = mysqli_query($conn, $sqlRemove) or die('Consulta fallida');
  161.  
  162. if (!$qryRemove) {
  163. die(mysqli_error());
  164.  
  165. }
  166. $sql = "SELECT * FROM `test` WHERE id=$ID";
  167.  
  168. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  169.  
  170. if (!$qry) {
  171. die(mysqli_error());
  172.  
  173. }
  174. //result is whats returned from the database
  175. $result = mysqli_query($conn, $sql);
  176. //row is the row inside $result which has all the row information from the database like monnthlyAmount, intRate, monthsOwed, etc
  177. while ($row = mysqli_fetch_object($result)) {
  178. //this just displays the newe information showing the months removed and the final number now
  179. echo '<br>';
  180. echo '<br>';
  181. echo 'UPDATED AND REMOVED MONTHS';
  182. echo '<br>';
  183. echo 'RECALCULATED';
  184. echo '<br>';
  185. echo '<br>';
  186. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  187. echo '<br>';
  188. echo 'Months past due: ' . $row->monthsOwed;
  189. echo '<br>';
  190. echo 'Interest rate per month: ' . $row->intRate;
  191. echo '<br>';
  192. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  193. echo '<br>';
  194. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  195. echo '<br>';
  196. //calls the calculate function and passes the data to it to get the amount
  197. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed)); //calculates the interest amount with the Calculate function
  198. echo '<br>';
  199. //calls the calculate function and passes the data to it to get the amount
  200. echo 'Total: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed)); //calculates the total amount using the Calculate function
  201. echo '<br>';
  202. echo '<br>';
  203. }
  204. mysqli_close($conn);
  205. } else {
  206.  
  207. ?>
  208. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  209. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  210. <tr>
  211. <td width = "100">Numero de cuenta</td>
  212. <td><input name = "p_ID" type = "text" id = "post_ID"></td>
  213. </tr>
  214. <tr>
  215. <td width = "100"> </td>
  216. <td> <input name = "check" type = "submit" class="btn btn-primary"id = "check" value = "Revisar Cuenta">
  217. </td>
  218. </tr>
  219. </table>
  220. </form>
  221.  
  222. <?php
  223. }
  224. //function calculates the interest per month
  225. function Calculate($monthly, $rate, $months)
  226. {
  227. for ($i = 1; $i <= $months; $i++) {
  228. //first if determins the first month amount
  229. if ($i == 1) {
  230. $amount = ($monthly * ($rate)) + $monthly;
  231. }
  232. //takes the first month and calculates it into the other months
  233. else if ($i <= $months) {
  234. $amount = ($amount + $monthly) + (($amount + $monthly) * ($rate));
  235. }
  236. }
  237. return $amount;
  238. }
  239.  
  240. ?>
  241.  
  242. </div>
  243. <!--Muestra el formulario para ingresar un nuevo alquiler-->
  244. <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">
  245. <h1>Ingreso de alquiler</h1>
  246. <?php
  247. if(isset($_POST['add'])){
  248. $dbhost = '127.0.0.1';
  249. $dbuser = 'root';
  250. $dbpass= '';
  251. $db = 'proyectobd2';
  252.  
  253. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  254.  
  255. if(! $conn){
  256. die ("Fallo en conexión: " . mysqli_error());
  257.  
  258. }
  259.  
  260. $db_select = mysqli_select_db($conn, $db);
  261.  
  262. if(! $db_select){
  263. die ("Fallo en conexión a base de datos: " .
  264. mysqli_error());
  265.  
  266. }
  267.  
  268. if(! get_magic_quotes_gpc() ) {
  269. $ID = addslashes ($_POST['Amo']);
  270. $MAR = addslashes ($_POST['rate']);
  271. }else {
  272. $ID = $_POST['Amo'];
  273. $MAR = $_POST['rate'];
  274. }
  275.  
  276. $MOD = $_POST['date'];
  277. $Mon=(calcDate($MOD));
  278. $usu=$_SESSION['username'];
  279.  
  280. $sql = "INSERT INTO test "
  281. . "(id,ID_user,monthlyAmount,intRate,dueDate , payDate, pastDue,monthsOwed)"
  282. . "VALUES ('0',$usu,'$ID', '$MAR', '$MOD','NOW()','0','$Mon')";
  283.  
  284. $qry = mysqli_query($conn, $sql) or
  285. die ('Consulta fallida');
  286.  
  287. if(! $qry){
  288. die(mysqli_error());
  289.  
  290. }
  291. echo"<script>alert('Enviado correctamente')</script>";
  292.  
  293. mysqli_close($conn);
  294. }
  295. function calcDate($date){
  296. $inicio= date('y-m-d');
  297. $fin=$date;
  298. $datetime1=new DateTime($inicio);
  299. $datetime2=new DateTime($fin);
  300. $interval=$datetime2->diff($datetime1);
  301. $interyear=$interval->format("%Y");
  302. if($interyear<1){
  303. $intervalMeses=$interval->format("%m");
  304. }else{
  305. $intervalMeses=$interval->format("%m")+(12*$interyear);
  306. }
  307. return $intervalMeses;
  308. }
  309.  
  310. ?>
  311. <center>
  312. <form method="post" action="<?php $_PHP_SELF ?>">
  313. <div class="form-group mx-sm-3 mb-2">
  314. <label for="exampleInputEmail1">Pago Mensual</label>
  315. <input name="Amo" type="text" class=" form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una cantidad"> <br/>
  316. <label for="exampleInputEmail1">Tasa de interes mensual</label>
  317. <input name="rate" type="text" class="form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una tasa de interes"><br/>
  318. <label for="exampleInputEmail1">Fecha de pago</label>
  319. <input name="date" type="date" class="form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una cantidad"><br/>
  320.  
  321.  
  322. </div>
  323. <input name="add" type="submit" class="btn btn-success" id="add" value="Enviar"></input>
  324. <input class="btn btn-dark" type="reset" value="Reset">
  325.  
  326.  
  327. </form>
  328. </center>
  329.  
  330. </div>
  331.  
  332. <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">
  333. <h1>Verificar Saldo</h1>
  334. <?php
  335. $conn = mysqli_connect('localhost', 'root', "", "proyectobd2")
  336. or die('No se pudo conectar: ');
  337.  
  338.  
  339.  
  340. $use=$_SESSION['username'];
  341.  
  342. // Realizar una consul[ta MySQL
  343. $query = "SELECT * FROM test WHERE ID_user= $use";
  344. $result = mysqli_query($conn, $query) or die(' Consulta fallida: ');
  345.  
  346. // Imprimir los resultados en HTML
  347. echo "<table >\n";
  348. echo "<tr>";
  349. echo "<td>ID</td>";
  350. echo "<td>Usuario</td>";
  351. echo "<td>Monto Mensual</td>";
  352. echo "<td>Tasa de interes</td>";
  353. echo "<td>Fecha de pago</td>";
  354. echo "<td>past due</td>";
  355. echo "<td>Meses atrasados</td>";
  356.  
  357. echo "</tr>";
  358. while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  359. echo "\t<tr>\n";
  360.  
  361. foreach ($row as $col_value) {
  362. echo "\t\t<td>$col_value</td>\n";
  363. }
  364.  
  365. echo "\t</tr>\n";
  366. }
  367. echo "</table>\n";
  368.  
  369. // Liberar resultados
  370. mysqli_free_result($result);
  371.  
  372. // Cerrar la conexión
  373. mysqli_close($conn);
  374.  
  375. ?>
  376. </div>
  377. </div>
  378. </body>
  379. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement