<?php 
if(isset($_POST['vacid'])){

extract($_POST);

require 'connection.php';


$flockcounter=0;
$pls=0;
?>
   <!-- <tr>
      <th   style=" font-weight: bold;  font-size: 16px; background-color: black; color: white;">Account Name</th>
      <th  style=" font-weight: bold;  font-size: 16px; background-color: black; color: white;">Amount</th>
                                    
   </tr> -->
   <?php
function dateDiffInDays($date1, $date2)  
{ 
    // Calculating the difference in timestamps 
    $diff = strtotime($date2) - strtotime($date1); 
      
    // 1 day = 24 hours 
    // 24 * 60 * 60 = 86400 seconds 
    return abs(round($diff / 86400)); 
} 
     if($vacid==4){
    // CHICKS

      ?>
<tr>
 <th style=" font-weight: bold;  font-size: 16px; background-color: yellow;">Name </th>
 <th style=" font-weight: bold;  font-size: 16px; background-color: yellow;">Chick Qty </th>
 <th style=" font-weight: bold;  font-size: 16px; background-color: yellow;">Dated Start </th>
 <th style=" font-weight: bold;  font-size: 16px; background-color: yellow;">Days </th>

</tr>
  <tr>

      <?php

           $qtyshedid = "SELECT * from accreg where accid2=1";
$run_shedid = mysqli_query($connect, $qtyshedid);
 while($rowshedid=mysqli_fetch_array($run_shedid)){
  $grpid=$rowshedid['groupid'];
  $shedgroup = "SELECT * from groupreg where groupid='$grpid'";
$run_shedgroup = mysqli_query($connect, $shedgroup);
 $rowshedgroup=mysqli_fetch_array($run_shedgroup);
  $gname=$rowshedgroup['groupname'];


  $acId=$rowshedid['accid'];
      $qrychk = "SELECT max(dated) as dateds from ledger where entrytype='Transfer' and accid='$acId'";
$run_qrychk = mysqli_query($connect, $qrychk);
 while($rowqrychk=mysqli_fetch_array($run_qrychk)){
$ddated=$rowqrychk['dateds'];
    $qrychk1 = "SELECT * from accreg where accid='$acId'";
$run_qrychk1 = mysqli_query($connect, $qrychk1);
 $rowqrychk1=mysqli_fetch_array($run_qrychk1);

      $qry22 = "SELECT sum(qty) as chickqty, min(dated) as mindate from chicksinout where accid='$acId' and dated >'$ddated'";
        $run_qry22 = mysqli_query($connect, $qry22);
       $row22=mysqli_fetch_array($run_qry22);

  
// Start date 
$date1 = $row22['mindate']; 
  
// End date 
$date2 =date("d-m-Y"); 
  
// Function call to find date difference 
$dateDiff = dateDiffInDays($date1, $date2)+1;

if($dateDiff<=4){
?> 
<tr>

 <td style=" font-weight: bold;  font-size: 16px; background-color: yellow;"><?php echo $gname; ?> </td>
 <td style=" font-weight: bold;  font-size: 16px; background-color: yellow;"><?php echo $row22['chickqty']; ?> </td>
  <td style=" font-weight: bold;  font-size: 16px; background-color: yellow;"><?php echo $date1; ?> </td>
 <td style=" font-weight: bold;  font-size: 16px; background-color: yellow;"><?php echo $dateDiff; ?> </td>
</tr>
  <tr>
<?php

}
}
// ******************************************************


// ******************************************************
}
}
}
 ?>