Está en la página 1de 9

body {

font-family: Arial, sans-serif;

text-align: center;

background-color: #f5f5f5;

h1 {

color: #333;

margin: 20px 0;

#prestamoForm {

max-width: 400px;

margin: 0 auto;

padding: 60px;

background-color: #fff;

border: 4px solid #ccc;

border-radius: 5px;

box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

label {

font-weight: bold;

display: block;

margin-top: 10px;

input, select {

width: 100%;

padding: 10px;

margin: 5px 0;
border: 1px solid #ccc;

border-radius: 3px;

button {

background-color: #007bff;

color: #fff;

border: none;

padding: 10px 20px;

margin-top: 10px;

border-radius: 3px;

cursor: pointer;

button:hover {

background-color: #0056b3;

#resultado {

margin-top: 20px;

font-weight: bold;

Conexión:
<?php

class Conexion {

private $cn=null;

function conecta(){

if($this->cn==null){

$this->cn= mysqli_connect("localhost","root","","bdpresta");

}
return $this->cn;

?>
Negocio :
<?php

include_once './Conexion.php';

class Negocio {

function adicion($Nombre_del_cliente, $Monto_del_prestamo, $Meses_de_prestamo,


$Tipo_de_moneda) {

$obj = new Conexion();

$sql = "INSERT INTO prestamos (Nombre_del_cliente, Monto_del_prestamo,


Meses_de_prestamo, Tipo_de_moneda) "

. " VALUES
('$Nombre_del_cliente','$Monto_del_prestamo','$Meses_de_prestamo','$Tipo_de_moneda' )"
;

$res = mysqli_query($obj->conecta(), $sql) or

die(mysqli_error($obj->conecta()));

function anula($Nro_de_prestamo) {

$obj = new Conexion();

$sql = "delete from prestamos where Nro_de_prestamo=$Nro_de_prestamo";

$res = mysqli_query($obj->conecta(), $sql) or

die(mysqli_error($obj->conecta()));

}
function listado() {//listado total

$obj = new Conexion();

$sql = "select
Nro_de_prestamo,Nombre_del_cliente,Monto_del_prestamo,Meses_de_prestamo,Tipo_de_m
oneda from prestamos";

$res = mysqli_query($obj->conecta(), $sql) or

die(mysqli_error($obj->conecta()));

$vec = array();

while ($fila = mysqli_fetch_array($res)) {

$vec[] = $fila;

return $vec;

?>

Prestamos:
<?php

class Prestamos {

private $Nro_de_prestamo;

private $Nombre_del_cliente;

private $Monto_del_prestamo;

private $Meses_de_prestamo;

private $Tipo_de_moneda;

function __construct($Nro_de_prestamo,$Nombre_del_cliente,$Monto_del_prestamo,
$Meses_de_prestamo,$Tipo_de_moneda) {

$this->Nro_de_prestamo=$Nro_de_prestamo;

$this->Nombre_del_cliente=$Nombre_del_cliente;

$this->Monto_del_prestamo=$Monto_del_prestamo;
$this->Meses_de_prestamo=$Meses_de_prestamo;

$this->Tipo_de_moneda=$Tipo_de_moneda;

public function calcularInteres() {

if ($this->Tipo_de_moneda == '1') {

// Interés en Dólares: 1.5% por mes

return $this->Monto_del_prestamo* 0.015 * $this->Meses_de_prestamo;

} elseif ($this->Tipo_de_moneda == '2') {

// Interés en Soles: 2% por mes

return $this->Monto_del_prestamo * 0.02 * $this->Meses_de_prestamo;

} else {

return 0; // Moneda no reconocida

public function calcularSaldo() {

$interes = $this->calcularInteres();

return $this->Tipo_de_moneda + $interes;

public function calcularCuota() {

$saldo = $this->calcularSaldo();

return $saldo / $this->Meses_de_prestamo;

PagAdic
<html>

<head>

<meta charset="UTF-8">
<title></title>

<link href="css/estilos.css" rel="stylesheet" type="text/css"/>

</head>

<body>

<?php

include_once './Negocio.php';

include_once './Conexion.php';

?>

<center>

<h2>Registro de Prestamos</h2>

<form method="post">

<table class="table table-bordered">

<tr><td>Nombre_del_cliente<td><input name="Nombre_del_cliente">

<tr><td>Monto_del_prestamo<td><input name="Monto_del_prestamo"
type="number" >

<tr><td>Meses_de_prestamo<td><input name="Meses_de_prestamo"
type="number" >

<td>Tipo de Moneda</td>

<td>

<select name="Tipo_de_moneda">

<option value="1">Dólar</option>

<option value="2">Soles</option>

</select>

</td>

<tr><td> <input type="submit" name="envia">

</table>

</form>

</center>

<?php
if (isset($_REQUEST["envia"])) {

$obj = new Negocio();

$obj->adicion($_REQUEST["Nombre_del_cliente"], $_REQUEST["Monto_del_prestamo"],
$_REQUEST["Meses_de_prestamo"], $_REQUEST["Tipo_de_moneda"]);

header("location:pagListado.php");

?>

</body>

</html>

pagBorra:
<?php

include_once './Negocio.php';

$obj=new Negocio();

$obj->anula($_REQUEST["code"]);

header("location:pagListado.php");

?>

pagListado
<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Lista de Préstamos</title>

<link href="css/estilos.css" rel="stylesheet" type="text/css"/>

</head>

<body>

<center>

<h2>Lista de Préstamos</h2>

<table class="table table-bordered">

<tr>

<th>Code</th>

<th>Nombre</th>

<th>Monto</th>
<th>Moneda</th>

<th>Meses</th>

<th>Interés</th>

<th>Saldo</th>

<th>Cuota mensual</th>

<th>Anular</th>

</tr>

<?php

include_once './Negocio.php';

include_once './Prestamos.php';

$negocio = new Negocio();

$prestamos = $negocio->listado();

foreach ($prestamos as $prestamo) {

echo '<tr>';

echo '<td>' . $prestamo['Nro_de_prestamo'] . '</td>';

echo '<td>' . $prestamo['Nombre_del_cliente'] . '</td>';

echo '<td>' . $prestamo['Monto_del_prestamo'] . '</td>';

echo '<td>' . ($prestamo['Tipo_de_moneda'] == 1 ? 'Dólar' : 'Soles') . '</td>';

echo '<td>' . $prestamo['Meses_de_prestamo'] . '</td>';

// Calcula el interés, saldo y cuota mensual usando la clase Prestamos

$prestamoObj = new Prestamos(

$prestamo['Nro_de_prestamo'], $prestamo['Nombre_del_cliente'],
$prestamo['Monto_del_prestamo'], $prestamo['Meses_de_prestamo'],
$prestamo['Tipo_de_moneda']

);

$interes = $prestamoObj->calcularInteres();

$saldo = $prestamoObj->calcularSaldo();

$cuota = $prestamoObj->calcularCuota();

echo '<td>' . $interes . '</td>';


echo '<td>' . $saldo . '</td>';

echo '<td>' . $cuota . '</td>';

echo '<td><a href="pagBorra.php?code=' . $prestamo['Nro_de_prestamo'] .


'">Anular</a></td>';

echo '</tr>';

?>

</table>

</center>

</body>

</html>

También podría gustarte