<?php
require("header.php")
?>
<style>
  .btn-group>.btn:not(:last-child):not(.dropdown-toggle) {
    background: black;
  }

  .btn-group>.btn-group:not(:first-child)>.btn {
    background: black;
  }

  .page-item.active .page-link {
    background: black;
  }

  .dt-button-collection .dropdown-menu .buttons-columnVisibility {
    background-color: black;
  }
</style>

<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-sm-6">
          <!-- <h1>Update Product Price</h1> -->
        </div>
        <div class="col-sm-6">

        </div>
      </div>
    </div><!-- /.container-fluid -->
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-12">
          <!-- /.card -->

          <div class="card card-secondary">
            <div class="card-header" style="background-color: black;">
              <h3 class="card-title">Update Product Price!</h3>
              <ol class="breadcrumb float-sm-right" style="background-color: black;">
                <li class="breadcrumb-item"><a href="#">Home</a></li>
                <li class="breadcrumb-item">Price Update</li>
                <li class="breadcrumb-item active">Update Credits</li>
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>Sr. No</th>
                    <th>Date /Time</th>
                    <th>Salt</th>
                    <th>product name</th>
                    <th>Origin</th>
                    <th>Quantity</th>
                    <th>Credits</th>

                    <th>Price Update</th>

                  </tr>
                </thead>
                <tbody>
                  <?php
                  $a = 0;
                  include('connection.php');

                  $sql = "SELECT * FROM product ORDER By date_time";
                  $res = mysqli_query($conn, $sql);
                  while ($row = mysqli_fetch_array($res)) {

                    $a++
                  ?>
                    <tr>
                      <td><?php echo $a; ?></td>
                      <td><?php echo $row['date_time']; ?></td>
                      <td><?php echo $row['salt']; ?></td>
                      <td><?php echo $row['product_name']; ?></td>
                      <td><?php echo $row['origin']; ?></td>
                      <td><?php echo $row['quantity']; ?></td>

                      <td><?php echo $row['price']; ?></td>

                      <td>

                        <button type="button" class="btn text-white  recheck-btn" style="background-color: black;" data-toggle="modal" data-target="#exampleModal<?php echo $row['id']; ?>">
                          Update
                        </button>
                      </td>
                    </tr>
                    <!-- Modal -->
                    <div class="modal fade" id="exampleModal<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header" style="background-color: black;">
                            <h5 class="modal-title" id="exampleModalLabel">Update Price</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                            </button>
                          </div>
                          <div class="modal-body">
                            <form action="product_price_update.php" method="post">

                              <div class="form-group">
                                <label for="exampleInputEmail1">Old Price : </label>
                                <input type="text" class="form-control" value="<?php echo $row['price']; ?>" readonly>
                                <input type="hidden" class="form-control" name="id" value="<?php echo $row['id']; ?>">
                              </div>
                              <div class="form-group">
                                <label for="exampleInputEmail1">New Product Price :</label>
                                <input type="text" class="form-control" name="price">
                              </div>
                              <div class="modal-footer">
                                <button type="button" class="btn btn-dark" data-dismiss="modal">Close</button>
                                <button type="submit" name="update" class="btn btn-dark">Update</button>
                              </div>
                            </form>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!-- madal end -->
                  <?php } ?>
                </tbody>
                <!-- Modal Start -->

                <!-- modal end -->

              </table>

            </div>

          </div>
          <!-- /.card-body -->

        </div>

        <!-- /.card -->
      </div>

      <!-- /.col -->
    </div>
    <!-- /.row -->

    <!-- /.container-fluid -->
  </section>
  <!-- /.content -->
</div>
<!-- for searching -->
<!-- Sweet Alert  start-->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 1) { ?>
  <script>
    Swal.fire(
      'Good job!',
      'Successfully updated!',
      'success'
    ).then(() => {
      window.location.href = "product_price.php";
    });
  </script>
<?php } ?>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 2) { ?>
  <script>
    Swal.fire(
      'Oops...',
      'Something went wrong!!',
      'error'
    ).then(() => {
      window.location.href = "product_price.php";
    });
  </script>
<?php } ?>


<?php
require("footer.php")
?>