Advertisement
Guest User

Untitled

a guest
Mar 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.10 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
  89. if (isset($_POST['check'])) {
  90. $conn = Connect();
  91.  
  92. $ID = $_POST['p_ID'];
  93.  
  94. $sql = "SELECT * FROM `test` WHERE id=$ID";
  95.  
  96. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  97.  
  98. if (!$qry) {
  99. die(mysqli_error());
  100.  
  101. }
  102. $result = mysqli_query($conn, $sql);
  103. while ($row = mysqli_fetch_object($result)) {
  104. // $row->monthsOwed=(calcDate($row->dueDate));
  105. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  106. echo '<br>';
  107. echo 'Months past due: ' . $row->monthsOwed;
  108. echo '<br>';
  109. echo 'Interest rate per month: ' . $row->intRate;
  110. echo '<br>';
  111. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  112. echo '<br>';
  113. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  114. echo '<br>';
  115. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed)); //calculates the interest amount with the Calculate function
  116. echo '<br>';
  117. echo 'Total: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed)); //calculates the total amount using the Calculate function
  118. echo '<br>';
  119. echo '<br>';
  120. }
  121. mysqli_close($conn);
  122.  
  123. ?>
  124. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  125. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  126. <tr>
  127. <td width = "100" >Numero de cuenta</td>
  128. <td><input name = "p_ID" type = "text" value="<?php echo $ID; ?>" id = "post_ID">
  129. </td>
  130. </tr>
  131. <tr>
  132. <td width = "100" >Numero de meses a cancelar</td>
  133. <td><input name = "p_Remove" type = "text" id = "post_Remove"></td>
  134. </tr>
  135. <tr>
  136. <td width = "100"> </td>
  137. <td>
  138. <input name = "recheck" class="btn btn-success" type = "submit" id = "recheck" value = "Pagar">
  139. </td>
  140. </tr>
  141. </table>
  142. </form>
  143.  
  144. <?php
  145.  
  146. }
  147. //removes the entered months from the database and recalculates the amount
  148. else if (isset($_POST['recheck'])) {
  149. $conn = Connect();
  150.  
  151. $ID = $_POST['p_ID'];
  152. $remove = $_POST['p_Remove'];
  153.  
  154.  
  155. $sqlRemove = "UPDATE `test` SET monthsOwed = monthsOwed - " . $remove . " WHERE id=$ID";
  156.  
  157. $qryRemove = mysqli_query($conn, $sqlRemove) or die('Consulta fallida');
  158.  
  159. if (!$qryRemove) {
  160. die(mysqli_error());
  161.  
  162. }
  163. $sql = "SELECT * FROM `test` WHERE id=$ID";
  164.  
  165. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  166.  
  167. if (!$qry) {
  168. die(mysqli_error());
  169.  
  170. }
  171. $result = mysqli_query($conn, $sql);
  172. while ($row = mysqli_fetch_object($result)) {
  173. echo '<br>';
  174. echo '<br>';
  175. echo 'UPDATED AND REMOVED MONTHS';
  176. echo '<br>';
  177. echo 'RECALCULATED';
  178. echo '<br>';
  179. echo '<br>';
  180. echo 'Amount Owed per month: ' . $row->monthlyAmount;
  181. echo '<br>';
  182. echo 'Months past due: ' . $row->monthsOwed;
  183. echo '<br>';
  184. echo 'Interest rate per month: ' . $row->intRate;
  185. echo '<br>';
  186. echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
  187. echo '<br>';
  188. echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
  189. echo '<br>';
  190. echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed)); //calculates the interest amount with the Calculate function
  191. echo '<br>';
  192. echo 'Total: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed)); //calculates the total amount using the Calculate function
  193. echo '<br>';
  194. echo '<br>';
  195. }
  196. mysqli_close($conn);
  197. } else {
  198.  
  199. ?>
  200. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  201. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  202. <tr>
  203. <td width = "100">Numero de cuenta</td>
  204. <td><input name = "p_ID" type = "text" id = "post_ID"></td>
  205. </tr>
  206. <tr>
  207. <td width = "100"> </td>
  208. <td> <input name = "check" type = "submit" class="btn btn-primary"id = "check" value = "Revisar Cuenta">
  209. </td>
  210. </tr>
  211. </table>
  212. </form>
  213.  
  214. <?php
  215. }
  216. //function calculates the interest per month
  217. function Calculate($monthly, $rate, $months)
  218. {
  219. for ($i = 1; $i <= $months; $i++) {
  220. //first if determins the first month amount
  221. if ($i == 1) {
  222. $amount = ($monthly * ($rate)) + $monthly;
  223. }
  224. //takes the first month and calculates it into the other months
  225. else if ($i <= $months) {
  226. $amount = ($amount + $monthly) + (($amount + $monthly) * ($rate));
  227. }
  228. }
  229. return $amount;
  230. }
  231.  
  232. ?>
  233.  
  234. </div>
  235. <!--Muestra el formulario para ingresar un nuevo alquiler-->
  236. <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">
  237. <h1>Ingreso de alquiler</h1>
  238. <?php
  239. if(isset($_POST['add'])){
  240. $dbhost = '127.0.0.1';
  241. $dbuser = 'root';
  242. $dbpass= '';
  243. $db = 'proyectobd2';
  244.  
  245. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  246.  
  247. if(! $conn){
  248. die ("Fallo en conexión: " . mysqli_error());
  249.  
  250. }
  251.  
  252. $db_select = mysqli_select_db($conn, $db);
  253.  
  254. if(! $db_select){
  255. die ("Fallo en conexión a base de datos: " .
  256. mysqli_error());
  257.  
  258. }
  259.  
  260. if(! get_magic_quotes_gpc() ) {
  261. $ID = addslashes ($_POST['Amo']);
  262. $MAR = addslashes ($_POST['rate']);
  263. }else {
  264. $ID = $_POST['Amo'];
  265. $MAR = $_POST['rate'];
  266. }
  267.  
  268. $MOD = $_POST['date'];
  269. $Mon=(calcDate($MOD));
  270. $usu=$_SESSION['username'];
  271.  
  272. $sql = "INSERT INTO test "
  273. . "(id,ID_user,monthlyAmount,intRate,dueDate , payDate, pastDue,monthsOwed)"
  274. . "VALUES ('0',$usu,'$ID', '$MAR', '$MOD','NOW()','0','$Mon')";
  275.  
  276. $qry = mysqli_query($conn, $sql) or
  277. die ('Consulta fallida');
  278.  
  279. if(! $qry){
  280. die(mysqli_error());
  281.  
  282. }
  283. echo"<script>alert('Enviado correctamente')</script>";
  284.  
  285. mysqli_close($conn);
  286. }
  287. function calcDate($date){
  288. $inicio= date('y-m-d');
  289. $fin=$date;
  290. $datetime1=new DateTime($inicio);
  291. $datetime2=new DateTime($fin);
  292. $interval=$datetime2->diff($datetime1);
  293. $interyear=$interval->format("%Y");
  294. if($interyear<1){
  295. $intervalMeses=$interval->format("%m");
  296. }else{
  297. $intervalMeses=$interval->format("%m")+(12*$interyear);
  298. }
  299. return $intervalMeses;
  300. }
  301.  
  302. ?>
  303. <center>
  304. <form method="post" action="<?php $_PHP_SELF ?>">
  305. <div class="form-group mx-sm-3 mb-2">
  306. <label for="exampleInputEmail1">Pago Mensual</label>
  307. <input name="Amo" type="text" class=" form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una cantidad"> <br/>
  308. <label for="exampleInputEmail1">Tasa de interes mensual</label>
  309. <input name="rate" type="text" class="form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una tasa de interes"><br/>
  310. <label for="exampleInputEmail1">Fecha de pago</label>
  311. <input name="date" type="date" class="form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una cantidad"><br/>
  312.  
  313.  
  314. </div>
  315. <input name="add" type="submit" class="btn btn-success" id="add" value="Enviar"></input>
  316. <input class="btn btn-dark" type="reset" value="Reset">
  317.  
  318.  
  319. </form>
  320. </center>
  321.  
  322. </div>
  323.  
  324. <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">
  325. <h1>Verificar Saldo</h1>
  326. <?php
  327. $conn = mysqli_connect('localhost', 'root', "", "proyectobd2")
  328. or die('No se pudo conectar: ');
  329.  
  330.  
  331.  
  332. $use=$_SESSION['username'];
  333.  
  334. // Realizar una consul[ta MySQL
  335. $query = "SELECT * FROM test WHERE ID_user= $use";
  336. $result = mysqli_query($conn, $query) or die(' Consulta fallida: ');
  337.  
  338. // Imprimir los resultados en HTML
  339. echo "<table >\n";
  340. echo "<tr>";
  341. echo "<td>ID</td>";
  342. echo "<td>Usuario</td>";
  343. echo "<td>Monto Mensual</td>";
  344. echo "<td>Tasa de interes</td>";
  345. echo "<td>Fecha de pago</td>";
  346. echo "<td>past due</td>";
  347. echo "<td>Meses atrasados</td>";
  348.  
  349. echo "</tr>";
  350. while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  351. echo "\t<tr>\n";
  352.  
  353. foreach ($row as $col_value) {
  354. echo "\t\t<td>$col_value</td>\n";
  355. }
  356.  
  357. echo "\t</tr>\n";
  358. }
  359. echo "</table>\n";
  360.  
  361. // Liberar resultados
  362. mysqli_free_result($result);
  363.  
  364. // Cerrar la conexión
  365. mysqli_close($conn);
  366.  
  367. ?>
  368. </div>
  369. </div>
  370. </body>
  371. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement