<?php
session_start();
include 'connexion.php';
if(!isset($_SESSION['username'])) {
header('Location: login.php');
exit();
}
// Récupération des factures
$query_invoices = "SELECT * FROM invoices ORDER BY id DESC";
$result_invoices = $pdo->query($query_invoices);
// Récupération des propriétaires
$query_owners = "SELECT * FROM owners ORDER BY nom ASC";
$result_owners = $pdo->query($query_owners);
?>
<!DOCTYPE html>
<html>
<head>
<title>Finance - Gestion des factures</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Gestion des factures</h2>
</div>
<div class="navbar">
<a href="home.php">Accueil</a>
<a href="payments.php">Paiements</a>
<a href="invoices.php">Factures</a>
<a href="logout.php" style="float:right">Déconnexion</a>
</div>
<div class="content">
<table>
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Appartement</th>
<th>Montant</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php while($row = $result_invoices->fetch(PDO::FETCH_ASSOC)): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['appartement']; ?></td>
<td><?php echo $row['montant']; ?></td>
<td><?php echo $row['status']; ?></td>
<td><a href="edit_invoice.php?id=<?php echo $row['id']; ?>">Modifier</a></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<br>
<h2>Créer une facture</h2>
<form method="post" action="save_invoice.php">
<label>Date :</label>
<input type="date" name="date" required>
<br>
<label>Propriétaire :</label>
<select name="owner_id" required>
<?php while($row = $result_owners->fetch(PDO::FETCH_ASSOC)): ?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['nom'] . ' ' . $row['prenom']; ?></option>
<?php endwhile; ?>
</select>
<br>
<label>Appartement :</label>
<input type="text" name="appartement" required>
<br>
<label>Montant :</label>
<input type="number" name="montant" required>
<br>
<label>Status :</label>
<select name="status" required>
<option value="non payé">Non payé</option>
<option value="payé">Payé</option>
</select>
<br>
<br>
<button type="submit" name="save_invoice">Enregistrer</button>
</form>
</div>
</table>
<div class="footer">
<p>© 2023 - Finance App</p>
</div>
</body>
</html>
Comments