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

extract($_POST);

require 'connection.php';
$vacid=$_POST['vacid'];

$flockcounter=0;
$pls=0;
$sr=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)); 
} 
// START 4 DAYS DETAIL

     if($vacid==1){
    // CHICKS

      ?>
      <tr>
 <td colspan="4" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;"> READY FLOCK DETAIL Above 35 Days </td>

</tr>
<tr>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Shed Name </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Bird Qty </th>
  <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Dated </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Bird Day </th>


</tr>
  <tr>
<!-- ******************************************************************************************* -->
<?php
$tdclr='cyan';

  $qtyshedid = "SELECT * from accreg where accid2=1 and groupid<>17";
$run_shedid = mysqli_query($connect, $qtyshedid);
 while($rowshedid=mysqli_fetch_array($run_shedid)){
  $sr=$sr+1;
  $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']; 
      $rundate = $date1;
      $dat= date_create($rundate);
      $dated1=date_format($dat,"d-m-Y");
// End date 
$date2 =date("d-m-Y"); 
  

// Function call to find date difference 
$dateDiff = dateDiffInDays($date1, $date2)+1;

// START CHECKING VACCINE BY  DAY DIFF



if($dateDiff>=35 and $dateDiff<=150){

// TD Color Setting
 if($tdclr=='cyan'){
 $tdclr='white';
 }
 else{
 $tdclr='cyan';

 }

?> 
<tr>

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

</tr>
<?php

}
} // This is end of while loop

}


} // End of if

} // End of body

 ?>
