<!DOCTYPE html>
<html lang="en">

 <?php include 'head.php';?>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
}

h1, h2 {
    text-align: center;
}

.branch-list {
    list-style-type: none;
    padding: 0;
    text-align: center;
}

.branch-list li {
    margin: 10px 0;
}

.branch-list a {
    text-decoration: none;
    color: #333;
    font-weight: bold;
}

.branch-list a:hover {
    color: #4CAF50;
}

/* Add more styling as needed */

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  margin: 0 auto;
  border:2;
}

th, td {
  padding: 10px;
  text-align: left;
}

th {
  background-color: #04AA6D;
  color: white;
}
label, input {
  width: 200px;
}
</style>
<body>

  <!-- ======= Header ======= -->
  
 <?php include 'menubar.php';?>

 <?php include 'sidebar.php';?>


  <main id="main" class="main">

 <h1>Book Allot  Details </h1>
    <?php

    $db = new mysqli('localhost', "tslibrary_user", "rb!tsl838", "tslibrary_data");

    if ($db->connect_error) {
        die("Connection failed: " . $db->connect_error);
    }

 $ids = $_GET['ID'];
    // Query to select records from the book_allot_receive table
    $sql = "SELECT * FROM book_allot_receive where ID='$ids'";
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        echo '<table border="1">';
        echo '<tr><th>ID</th><th>Title</th><th>Allotment Date</th><th>Student ID</th><th>ISBN</th>
		</tr>';

        while ($row = $result->fetch_assoc()) {
            $bookreceive=$row['student_id'];
			$title=$row['book_title'] ;
			$bookallotment=$row['book_allotment_date'];
			$book_receivedate=date('d/m/Y');
			$student_id=$row['student_id'];
// 1. Define dates in desired format (DD/MM/YYYY)
$startDate = $bookallotment;
$endDate = $book_receivedate;

// 2. Convert dates to DateTime objects using Indian format
$startDateObject = DateTime::createFromFormat('d/m/Y', $startDate);
$endDateObject = DateTime::createFromFormat('d/m/Y', $endDate);

// 3. Calculate the difference using DateInterval
$dateDiff = $startDateObject->diff($endDateObject);

// 4. Extract the number of days from the DateInterval
$daysBetween = $dateDiff->days;

$amount_fees=$daysBetween*15;


			echo '<tr>';
            echo '<td>' . $row['ID'] . '</td>';
            echo '<td>' . $row['book_title'] . '</td>';
            echo '<td>' . $row['book_allotment_date'] . '</td>';
            echo '<td>' . $row['student_id'] . '</td>';
            echo '<td>' . $row['book_isbn_no'] . '</td>';
			
            echo '</tr>';
        }

        echo '</table>';
    } else {
        
    }

    $db->close();
    ?>



    <h1>Book Receive Form </h1>

    <form action="process_book_recevice.php" method="post">
        <label for="student_id"> ID:</label>
        <input type="text" name="ids" id='ids' value='<?php echo $ids ?>' required>
        <br>
		<label for="student_id">Student ID:</label>
        <input type="text" name="student_id" id='student_id' value='<?php echo $student_id ?>' required>
        <br>
		<label for="student_id">Book Allotment Date:</label>
        <input type="text" name="allotment" id='allotment' value='<?php echo $bookallotment ?>' required>
		<br>
		<label for="student_id">Receive Date:</label>
        <input type="text" name="receivedate" id='receivedate' value='<?php echo $book_receivedate ?>' required>
		<br>
      <label for="student_id">Book Name</label>
        <input type="text" name="bookname" id='bookname' value='<?php echo $title ?>' required>
		<br>
 <label for="student_id">Your Days</label>
        <input type="text" name="bookfordays" id='bookfordays' value='<?php echo $daysBetween  ?>'  required>
		<br>
          <label for="student_id">Receive Amount</label>
        <input type="text" name="amount" id='amount' value='<?php echo $amount_fees ?>'  required>Rs. 
		<br>
        <br>

        <input type="submit" value="Submit">
    </form>
	
	
	
	
</body>
</html>

   



  </main><!-- End #main -->

   <?php include 'footer.php';?>

</body>

</html>