Nothing Special   »   [go: up one dir, main page]

Nouveau Document Texte

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

<?

php
session_start();
include("connection.php");

if (!isset($_SESSION['username'])) {
header("Location: login.php");
exit();
}

$username = $_SESSION['username'];

if (!isset($_GET['id']) || empty($_GET['id'])) {
die("ID de commande non spécifié.");
}

$id = mysqli_real_escape_string($conn, $_GET['id']);

$sql = "SELECT * FROM `open_orders_26.06` WHERE `id` = ?";


$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 'i', $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);

if (!$result) {
die("Query Failed: " . mysqli_error($conn));
}

$order = mysqli_fetch_assoc($result);

if (!$order) {
die("Commande non trouvée.");
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$produit_declared = mysqli_real_escape_string($conn,
$_POST['produit_declared']);
$date_declaration = mysqli_real_escape_string($conn,
$_POST['date_declaration']);
$heure_declaration = mysqli_real_escape_string($conn,
$_POST['heure_declaration']);
$date_enregistrement = date('Y-m-d H:i:s', strtotime('-1 hour'));
$id = mysqli_real_escape_string($conn, $_POST['id']);
$previous_qty_restante = (int)$_POST['previous_qty_restante'];

$remaining_qty = $previous_qty_restante - $produit_declared;

$update_sql = "UPDATE `open_orders_26.06` SET `produit declaree` = ?,


`date_declaration` = ?, `heure_declaration` = ?, `qte restante` = ?,
`date_enregistrement` = ? WHERE `id` = ?";
$update_stmt = mysqli_prepare($conn, $update_sql);
mysqli_stmt_bind_param($update_stmt, 'sssiis', $produit_declared,
$date_declaration, $heure_declaration, $remaining_qty, $date_enregistrement, $id);
mysqli_stmt_execute($update_stmt);

if (mysqli_stmt_affected_rows($update_stmt) > 0) {
echo "<div class='alert alert-success'>Les informations ont été mises à
jour.</div>";

// Insertion dans l'historique des mises à jour


$insert_history_sql = "INSERT INTO `order_updates` (`id`, `produit
declaree`, `date_declaration`, `heure_declaration`, `date_enregistrement`,
`username`) VALUES (?, ?, ?, ?, ?, ?)";
$insert_history_stmt = mysqli_prepare($conn, $insert_history_sql);
mysqli_stmt_bind_param($insert_history_stmt, 'iissss', $id,
$produit_declared, $date_declaration, $heure_declaration, $date_enregistrement,
$username);
mysqli_stmt_execute($insert_history_stmt);

$order['produit declaree'] = $produit_declared;


$order['qte restante'] = $remaining_qty;
$order['date_declaration'] = $date_declaration;
$order['heure_declaration'] = $heure_declaration;
$order['date_enregistrement'] = $date_enregistrement;
} else {
echo "<div class='alert alert-danger'>Une erreur est survenue lors de la
mise à jour.</div>";
}
}
?>

<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Détails de la Commande</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
color: #343a40;
}
.container {
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
.table th, .table td {
vertical-align: middle;
}
.table th {
background-color: #f0f0f0;
}
.btn {
transition: transform 0.2s, box-shadow 0.2s;
}
.btn:hover {
transform: scale(1.02);
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.form-label {
font-weight: bold;
}
</style>
<script>
function updateRemainingQuantity() {
var previousQtyRestante =
parseInt(document.getElementById('previous_qty_restante').value);
var produitDeclared =
parseInt(document.getElementById('produit_declared').value) || 0;
var remainingQty = previousQtyRestante - produitDeclared;
document.getElementById('remaining_qty_display').innerText =
remainingQty;
}
</script>
</head>
<body>

<div class="container mt-5">


<div class="d-flex justify-content-between align-items-center mb-4">
<a href="dashboard.php">
<img src="images.jfif" alt="Logo de WECO" style="height: 50px;">
</a>
<a href="dashboard.php" class="btn btn-secondary">Retour</a>
</div>
<h1>Détails de la Commande</h1>
<?php if ($order): ?>
<table class="table table-bordered">
<tbody>
<tr>
<th>ID</th>
<td><?php echo htmlspecialchars($order['id']); ?></td>
</tr>
<tr>
<th>AG</th>
<td><?php echo htmlspecialchars($order['AG']); ?></td>
</tr>
<tr>
<th>Abt.</th>
<td><?php echo htmlspecialchars($order['Abt.']); ?></td>
</tr>
<tr>
<th>Work Center</th>
<td><?php echo htmlspecialchars($order['work center']); ?></td>
</tr>
<tr>
<th>AG Bezeichnung</th>
<td><?php echo htmlspecialchars($order['AG Bezeichnung']); ?></td>
</tr>
<tr>
<th>Auftrags-Nr.</th>
<td><?php echo htmlspecialchars($order['Auftrags-Nr.']); ?></td>
</tr>
<tr>
<th>ST</th>
<td><?php echo htmlspecialchars($order['ST']); ?></td>
</tr>
<tr>
<th>Teile-Nr</th>
<td><?php echo htmlspecialchars($order['Teile-Nr']); ?></td>
</tr>
<tr>
<th>Bezeichnung 1</th>
<td><?php echo htmlspecialchars($order['Bezeichnung 1']); ?></td>
</tr>
<tr>
<th>Start</th>
<td><?php echo htmlspecialchars($order['Start']); ?></td>
</tr>
<tr>
<th>Ende</th>
<td><?php echo htmlspecialchars($order['Ende']); ?></td>
</tr>
<tr>
<th>Quantité Totale</th>
<td><?php echo htmlspecialchars($order['qty totale']); ?></td>
</tr>
<tr>
<th>Quantité Restante</th>
<td><?php echo htmlspecialchars($order['qte restante']); ?></td>
</tr>
<tr>
<th>Quantité Produite</th>
<td><?php echo htmlspecialchars($order['Qte produite']); ?></td>
</tr>
<tr>
<th>Temps Restant</th>
<td><?php echo htmlspecialchars($order['time remaining']); ?></td>
</tr>
<tr>
<th>Utilisateur</th>
<td><?php echo htmlspecialchars($order['username']); ?></td>
</tr>
<tr>
<th>Temps Produit</th>
<td><?php echo htmlspecialchars($order['temps produit']); ?></td>
</tr>
<tr>
<th>Temps Déclaré</th>
<td><?php echo htmlspecialchars($order['temps declaré']); ?></td>
</tr>
<tr>
<th>Produit Déclaré</th>
<td><?php echo htmlspecialchars($order['produit declaree']);
?></td>
</tr>
<tr>
<th>Date de production</th>
<td><?php echo htmlspecialchars($order['date_declaration']);
?></td>
</tr>
<tr>
<th>Heure de production</th>
<td><?php echo htmlspecialchars($order['heure_declaration']);
?></td>
</tr>
<tr>
<th>Date et Heure de déclaration</th>
<td><?php echo htmlspecialchars($order['date_enregistrement']); ?
></td>
</tr>
</tbody>
</table>
<form method="post" class="mb-4">
<input type="hidden" name="id" value="<?php echo $order['id']; ?>">
<div class="mb-3">
<label for="produit_declared" class="form-label">Produit
Déclaré</label>
<input type="number" id="produit_declared" name="produit_declared"
class="form-control" > </div>
<div class="mb-3">
<label for="date_declaration" class="form-label">Date de la
Déclaration</label>
<input type="date" id="date_declaration" name="date_declaration"
class="form-control">
</div>
<div class="mb-3">
<label for="heure_declaration" class="form-label">Heure de la
Déclaration</label>
<input type="time" id="heure_declaration" name="heure_declaration"
class="form-control">
</div>
<input type="hidden" id="previous_qty_restante"
name="previous_qty_restante" value="<?php echo $order['qte restante']; ?>">
<button type="submit" name="save" class="btn
btn-primary">Enregistrer</button>
</form>
<div>
<strong>Quantité Restante - Produit Déclaré: </strong>
<span id="remaining_qty_display"><?php echo htmlspecialchars($order['qte
restante']); ?></span>
</div>
<?php endif; ?>
</div>
</body>
</html>

You might also like