<?php 
// echo "<h2>Maintenance en cours</h2>";
// exit();
 // ini_set('display_errors', 1);

define("ADMIN", true);
require_once("../../common/lib.php");
require_once("../../common/define.php");
define("TITLE_ELEMENT", "Suivi de Production Quotidien");

if(!isset($_SESSION['user'])){
    header("Location: login.php");
    exit();
}elseif($_SESSION['user']['type'] == "registered"){
    unset($_SESSION['user']);
    $_SESSION['msg_error'][] = "Access denied.";
    header("Location: login.php");
    exit();
}

require_once("../includes/fn_module.php"); ?>
<!DOCTYPE html>
<head>
    <?php  include("../includes/inc_header_common.php"); ?>
	<?php  include("../includes/functions.php"); ?>


    <style>

        table th, table td { text-align: center; vertical-align: middle; }
    </style>
</head>
<body>
    <div id="wrapper">
        <?php 
		include(SYSBASE.ADMIN_FOLDER."/includes/inc_top.php");

		
		?>
        <div id="page-wrapper">
            <div class="page-header">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-6">
                            <h1><i class="fa fa-dashboard"></i> Suivi de Production Quotidien</h1>
                        </div>
						<div class="col-md-6" style="padding-top: 15px;text-align: right;">

<div class="mb-3">
    <a href="export_excel.php" class="btn btn-success btn-sm">📊 Exporter Excel</a>
    <a href="export_pdf.php" class="btn btn-danger btn-sm" target="_blank">📄 Exporter PDF</a>
</div>

                        </div>
                    </div>
                </div>
            </div>
<?

$stmt = $db->prepare("SELECT * FROM pm_resume_journee ORDER BY date_jour DESC, ligne ASC");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>
    <div class="container">
        <div class="table-responsive">
            <table class="table table-bordered table-striped table-hover" id="resumeTable">
                <thead class="table-dark">
                    <tr>
                        <th>Date</th>
                        <th>Ligne</th>
                        <th>Début</th>
                        <th>Fin</th>
                        <th>Cadence</th>
                        <th>Qté Carton</th>
                        <th>Temps Palettage</th>
                        <th>Temps Arrêt</th>
                        <th>% Arrêt</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($rows as $row): ?>
                        <tr>
                            <td><?= htmlspecialchars($row['date_jour']) ?></td>
                            <td><?= htmlspecialchars($row['ligne']) ?></td>
                            <td><?= htmlspecialchars($row['demarage']) ?></td>
                            <td><?= htmlspecialchars($row['last_declaration']) ?></td>
                            <td><?= htmlspecialchars($row['cadence_sachets']) ?></td>
                            <td><?= htmlspecialchars($row['qte_carton']) ?></td>
                            <td><?= htmlspecialchars($row['temps_pallette_std']) ?></td>
                            <td><?= htmlspecialchars($row['temps_arret']) ?></td>
                            <td><?= htmlspecialchars($row['pourcentage_arret']) ?></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>

		</div>
    </div>
</body>
</html>
<?php 
$_SESSION['msg_error'] = array();
$_SESSION['msg_success'] = array();
$_SESSION['msg_notice'] = array(); ?>
