<?php 
include('include/session.php');
// session_start();
include 'include/navigation.php';
include 'connection.php';
// Establish a database connection
$dbConnection = new DbConnection();
$connection = $dbConnection->connection;
?>

<html lang="en">
<head>
    <link rel="stylesheet" href="assets/css/style.css">
    <?php include 'include/header_links.php'; ?>
</head>
<style>
    .table_one{
        width:100%;
        
    }
   .tabel_one th, td {
      padding: 5px;
      text-align:center;
      border-bottom: 1px solid #ddd;
    }

</style>
<body>
    <div class="container_main">
          <div id="warantee_button">
                    <div> <button class="reset-button"><a href="_new_order.php"><i class="fa-solid fa-backward"></i></a></button></div>
                    <div class="item-left"><a href="_cancel_order.php" class="reset-button">Cancel List</a></div>
                </div>
        

        <h1>Order Summary List</h1>
      
        <table class="table_one table-striped">
            <thead>
                <tr>
                    <th scope="col">S.no</th>
                    <th scope="col">Order_id</th>
                    <th scope="col">Cuid</th>
                    <th scope="col">Category</th>
                    <th scope="col">Product</th>
                    <th scope="col">Variation</th>
                    <th scope="col">Price</th>
                    <th scope="col">Quantity</th>
                    <th scope="col">Total Amount</th>
                    <th scope="col">Payment Reference</th>
                    <th scope="col" colspan="3">Action</th>
                    
                </tr>
            </thead>
            <tbody>
                <?php
                $query = "SELECT * FROM order_summery";
                $result = mysqli_query($connection, $query);
                $id = 1;

                if ($result && mysqli_num_rows($result) > 0) {
                    while ($row = mysqli_fetch_assoc($result)) {
                        echo "<tr>";
                        echo "<td>{$id}</td>";
                        echo "<td>{$row['order_id']}</td>";
                        echo "<td>{$row['cuid']}</td>";
                        echo '<td>' . implode("<br>", explode(",", $row['category'])) . '</td>';
                        echo '<td>' . implode("<br>", explode(",", $row['product'])) . '</td>';
                        echo '<td>' . implode("<br>", explode(",", $row['variation'])) . '</td>';
                        echo '<td>' . implode("<br>", explode(",", $row['price'])) . '</td>';
                        echo "<td>{$row['items']}</td>";
                        echo "<td>{$row['total_price']}</td>";
                       
                        echo "<td>{$row['payment_reference']}</td>";
                        // echo "<td><button type='button' class='btn btn-primary'><a href='_new_order_edit.php?id={$row['id']}'><i class='bi bi-pencil-square'></i></a></button></td>";  
                        echo "<td><button type='button' class='btn btn-warning' onclick=\"moveToOrderCancel('{$row['order_id']}', '{$row['cuid']}', '{$row['category']}', '{$row['product']}', '{$row['variation']}', '{$row['price']}', '{$row['total_price']}', '{$row['items']}', '{$row['payment_reference']}')\"><i class='bi bi-arrow-repeat'></i></button></td>";
                        echo "<td><button type='button' class='btn btn-danger'><a href='order_delete.php?order_id={$row['order_id']}'><i class='bi bi-trash'></i></a></button></td>";
                        $id++;
                        echo "</tr>";
                    }
                }
                ?>
            </tbody>
        </table>

        
    </div>
     <section class="footer">
     <?php include('include/footer_two.php');         ?>
     
 </section>
  </body>
    <?php include "include/footer_link.php"; ?>
  
    <script src="assets/script/script.js"></script>
    <script>


    function moveToOrderCancel(order_id, cuid, category, product, variation, price,items,total_price, payment_reference) {
   
    // Construct the confirmation message
    var confirmationMessage = "Are you sure you want to cancel";
       
    // Display a confirmation dialog
    var confirmation = confirm(confirmationMessage);

    if (confirmation) {
        // If the user confirms, construct the sale URL and navigate
        var saleUrl = `order_cancel.php?order_id=${order_id}&cuid=${cuid}&category=${category}&product=${product}&variation=${variation}&price=${price}&items=${items}&total_price=${total_price}&payment_reference=${payment_reference}`;
        window.location.href = saleUrl;
    }

    return false; // Prevent the default form submission behavior
}

    

</script>
</body>
</html>

