Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
- <script src="dist/js/bootstrap.js" type="text/javascript"></script>
- <link href="dist/css/bootstrap.css" rel="stylesheet" type="text/css"/>
- <title>Ventanilla</title>
- </head>
- <body>
- <nav class="navbar navbar-expand-lg navbar-light bg-light">
- <!--En vez de home tiene que ir la pagina de inicio esto en la referencia y
- en el nombre que aparece seria como el nombre que le vamos a dar no la del login-->
- <a class="navbar-brand" href="PaginaInicio.php">Programación IV</a>
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="collapse navbar-collapse" id="navbarSupportedContent">
- <ul class="navbar-nav mr-auto">
- <li class="nav-item active">
- <!-- en esta solo la referencia a la pagina de inicio-->
- <a class="nav-link" href="PaginaInicio.php">Home <span class="sr-only">(current)</span></a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="Vista_cajero.php">Cajero</a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="Ventanilla.php">Ventanilla</a>
- </li>
- </ul>
- </div>
- </nav>
- <!--Este seria el menu de la pagina ventanilla-->
- <div class="nav flex-row nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
- <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>
- <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>
- <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>
- <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>
- </div>
- <!--Despliega la pagina principal de ventanilla-->
- <div class="tab-content" id="v-pills-tabContent">
- <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
- <div class="jumbotron jumbotron-fluid" >
- <div class="container">
- <h1 class="display-4">Bienvenido <?php echo $_SESSION['username']?></h1>
- </div>
- </div>
- </div>
- <!--Despliega la informacion para hacer un pago-->
- <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
- <h1>Pago de alquiler</h1>
- <?php
- //function for connecting to the database
- function Connect(){
- $dbhost = '127.0.0.1';
- $dbuser = 'root';
- $dbpass = '';
- $db = 'pruebaprog4';
- $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
- if (!$conn) {
- die("Fallo en conexión: " . mysqli_error());
- }
- $db_select = mysqli_select_db($conn, $db);
- if (!$db_select) {
- die("Fallo en conexión a base de datos: " . mysqli_error());
- }
- return $conn;
- }
- //searches the database for the id number input - this runs first
- if (isset($_POST['check'])) {
- $conn = Connect();
- $ID = $_POST['p_ID'];
- //finds the row with the ID number
- $sql = "SELECT * FROM `test` WHERE id=$ID";
- $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
- if (!$qry) {
- die(mysqli_error());
- }
- //result is whats returned from the database
- $result = mysqli_query($conn, $sql);
- //row is the row inside $result which has all the row information from the database like monnthlyAmount, intRate, monthsOwed, etc
- while ($row = mysqli_fetch_object($result)) {
- //this code is just showing the information in the browser
- echo 'Amount Owed per month: ' . $row->monthlyAmount;
- echo '<br>';
- echo 'Months past due: ' . $row->monthsOwed;
- echo '<br>';
- echo 'Interest rate per month: ' . $row->intRate;
- echo '<br>';
- echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
- echo '<br>';
- echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
- echo '<br>';
- echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed)); //calculates the interest amount with the Calculate function
- echo '<br>';
- echo 'Total: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed)); //calculates the total amount using the Calculate function
- echo '<br>';
- echo '<br>';
- }
- mysqli_close($conn);
- ?>
- <form method = "post" action = "<?php $_PHP_SELF; ?>">
- <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
- <tr>
- <td width = "100" >Numero de cuenta</td>
- <td><input name = "p_ID" type = "text" value="<?php echo $ID; ?>" id = "post_ID">
- </td>
- </tr>
- <tr>
- <td width = "100" >Numero de meses a cancelar</td>
- <td><input name = "p_Remove" type = "text" id = "post_Remove"></td>
- </tr>
- <tr>
- <td width = "100"> </td>
- <td>
- <input name = "recheck" class="btn btn-success" type = "submit" id = "recheck" value = "Pagar">
- </td>
- </tr>
- </table>
- </form>
- <?php
- }
- //removes the entered months from the database and recalculates the amount - this runs second
- else if (isset($_POST['recheck'])) {
- $conn = Connect();
- $ID = $_POST['p_ID'];
- $remove = $_POST['p_Remove'];
- //removes the typed in amount of months from the database with the ID number that was typed in at the start
- $sqlRemove = "UPDATE `test` SET monthsOwed = monthsOwed - " . $remove . " WHERE id=$ID";
- $qryRemove = mysqli_query($conn, $sqlRemove) or die('Consulta fallida');
- if (!$qryRemove) {
- die(mysqli_error());
- }
- $sql = "SELECT * FROM `test` WHERE id=$ID";
- $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
- if (!$qry) {
- die(mysqli_error());
- }
- //result is whats returned from the database
- $result = mysqli_query($conn, $sql);
- //row is the row inside $result which has all the row information from the database like monnthlyAmount, intRate, monthsOwed, etc
- while ($row = mysqli_fetch_object($result)) {
- //this just displays the newe information showing the months removed and the final number now
- echo '<br>';
- echo '<br>';
- echo 'UPDATED AND REMOVED MONTHS';
- echo '<br>';
- echo 'RECALCULATED';
- echo '<br>';
- echo '<br>';
- echo 'Amount Owed per month: ' . $row->monthlyAmount;
- echo '<br>';
- echo 'Months past due: ' . $row->monthsOwed;
- echo '<br>';
- echo 'Interest rate per month: ' . $row->intRate;
- echo '<br>';
- echo 'Daily interest: ' . $row->intRate * $row->monthsOwed / 30;
- echo '<br>';
- echo 'Rent due: ' . $row->monthlyAmount * $row->monthsOwed;
- echo '<br>';
- //calls the calculate function and passes the data to it to get the amount
- echo 'Interest charge: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed) - ($row->monthlyAmount * $row->monthsOwed)); //calculates the interest amount with the Calculate function
- echo '<br>';
- //calls the calculate function and passes the data to it to get the amount
- echo 'Total: ' . (Calculate($row->monthlyAmount, $row->intRate / 100, $row->monthsOwed)); //calculates the total amount using the Calculate function
- echo '<br>';
- echo '<br>';
- }
- mysqli_close($conn);
- } else {
- ?>
- <form method = "post" action = "<?php $_PHP_SELF; ?>">
- <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
- <tr>
- <td width = "100">Numero de cuenta</td>
- <td><input name = "p_ID" type = "text" id = "post_ID"></td>
- </tr>
- <tr>
- <td width = "100"> </td>
- <td> <input name = "check" type = "submit" class="btn btn-primary"id = "check" value = "Revisar Cuenta">
- </td>
- </tr>
- </table>
- </form>
- <?php
- }
- //function calculates the interest per month
- function Calculate($monthly, $rate, $months)
- {
- for ($i = 1; $i <= $months; $i++) {
- //first if determins the first month amount
- if ($i == 1) {
- $amount = ($monthly * ($rate)) + $monthly;
- }
- //takes the first month and calculates it into the other months
- else if ($i <= $months) {
- $amount = ($amount + $monthly) + (($amount + $monthly) * ($rate));
- }
- }
- return $amount;
- }
- ?>
- </div>
- <!--Muestra el formulario para ingresar un nuevo alquiler-->
- <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">
- <h1>Ingreso de alquiler</h1>
- <?php
- if(isset($_POST['add'])){
- $dbhost = '127.0.0.1';
- $dbuser = 'root';
- $dbpass= '';
- $db = 'proyectobd2';
- $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
- if(! $conn){
- die ("Fallo en conexión: " . mysqli_error());
- }
- $db_select = mysqli_select_db($conn, $db);
- if(! $db_select){
- die ("Fallo en conexión a base de datos: " .
- mysqli_error());
- }
- if(! get_magic_quotes_gpc() ) {
- $ID = addslashes ($_POST['Amo']);
- $MAR = addslashes ($_POST['rate']);
- }else {
- $ID = $_POST['Amo'];
- $MAR = $_POST['rate'];
- }
- $MOD = $_POST['date'];
- $Mon=(calcDate($MOD));
- $usu=$_SESSION['username'];
- $sql = "INSERT INTO test "
- . "(id,ID_user,monthlyAmount,intRate,dueDate , payDate, pastDue,monthsOwed)"
- . "VALUES ('0',$usu,'$ID', '$MAR', '$MOD','NOW()','0','$Mon')";
- $qry = mysqli_query($conn, $sql) or
- die ('Consulta fallida');
- if(! $qry){
- die(mysqli_error());
- }
- echo"<script>alert('Enviado correctamente')</script>";
- mysqli_close($conn);
- }
- function calcDate($date){
- $inicio= date('y-m-d');
- $fin=$date;
- $datetime1=new DateTime($inicio);
- $datetime2=new DateTime($fin);
- $interval=$datetime2->diff($datetime1);
- $interyear=$interval->format("%Y");
- if($interyear<1){
- $intervalMeses=$interval->format("%m");
- }else{
- $intervalMeses=$interval->format("%m")+(12*$interyear);
- }
- return $intervalMeses;
- }
- ?>
- <center>
- <form method="post" action="<?php $_PHP_SELF ?>">
- <div class="form-group mx-sm-3 mb-2">
- <label for="exampleInputEmail1">Pago Mensual</label>
- <input name="Amo" type="text" class=" form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una cantidad"> <br/>
- <label for="exampleInputEmail1">Tasa de interes mensual</label>
- <input name="rate" type="text" class="form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una tasa de interes"><br/>
- <label for="exampleInputEmail1">Fecha de pago</label>
- <input name="date" type="date" class="form-control-sm" maxlength="35" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="ingrese una cantidad"><br/>
- </div>
- <input name="add" type="submit" class="btn btn-success" id="add" value="Enviar"></input>
- <input class="btn btn-dark" type="reset" value="Reset">
- </form>
- </center>
- </div>
- <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">
- <h1>Verificar Saldo</h1>
- <?php
- $conn = mysqli_connect('localhost', 'root', "", "proyectobd2")
- or die('No se pudo conectar: ');
- $use=$_SESSION['username'];
- // Realizar una consul[ta MySQL
- $query = "SELECT * FROM test WHERE ID_user= $use";
- $result = mysqli_query($conn, $query) or die(' Consulta fallida: ');
- // Imprimir los resultados en HTML
- echo "<table >\n";
- echo "<tr>";
- echo "<td>ID</td>";
- echo "<td>Usuario</td>";
- echo "<td>Monto Mensual</td>";
- echo "<td>Tasa de interes</td>";
- echo "<td>Fecha de pago</td>";
- echo "<td>past due</td>";
- echo "<td>Meses atrasados</td>";
- echo "</tr>";
- while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
- echo "\t<tr>\n";
- foreach ($row as $col_value) {
- echo "\t\t<td>$col_value</td>\n";
- }
- echo "\t</tr>\n";
- }
- echo "</table>\n";
- // Liberar resultados
- mysqli_free_result($result);
- // Cerrar la conexión
- mysqli_close($conn);
- ?>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement