<?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==4){
    // CHICKS

      ?>
      <tr>
 <td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;"> Vaccine: ND+IB </td>
<td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;">  Day: 4th </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;">Bird Day </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Vac. Day Left</th>

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

  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>1 and $dateDiff<=4){

// 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 $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 4-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop

}

// ****************************************************************************************************************************

}
// END 4 DAYS DETAIL


// START 5 DAYS DETAIL

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

      ?>
      <tr>
 <td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;"> Vaccine: INJECTION </td>
<td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;">  Day: 5th </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;">Bird Day </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Vac. Day Left</th>

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

  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>4 and $dateDiff<=5){

// 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 $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 5-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop

}

// ****************************************************************************************************************************

}
// END 5 DAYS DETAIL

// START 10th DAYS DETAIL

     if($vacid==10){
  

      ?>

      <tr>
 <td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;"> Vaccine: GUMBORO </td>
<td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;">  Day: 10th </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;">Bird Day </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Vac. Day Left</th>

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

  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>5 and $dateDiff<=10){

// 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 $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 10-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop

}

// ****************************************************************************************************************************

}
// END 10th DAYS DETAIL



// START 14 DAYS DETAIL

     if($vacid==14){
    // START 4 DAYS DETAIL

      ?>
      <tr>
 <td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;"> Vaccine: ND+IB /2nd </td>
<td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;">  Day: 14th </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;">Bird Day </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Vac. Day Left</th>

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

  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>10 and $dateDiff<=14){

// 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 $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 14-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop

}

// ****************************************************************************************************************************

}
// END 14 DAYS DETAIL




// START 24 DAYS DETAIL

     if($vacid==24){
    // CHICKS
// START 4 DAYS DETAIL

      ?>
      <tr>
 <td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;"> Vaccine: LASOTA </td>
<td colspan="2" style="color: white; font-weight: bold;  font-size: 16px; background-color: blue;">  Day: 24th </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;">Bird Day </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Vac. Day Left</th>

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

  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>14 and $dateDiff<=24){

// 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 $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 24-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop

}

// ****************************************************************************************************************************


}
// END 24 DAYS DETAIL


// START ALL VACCINE SHEDULE


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

      ?>
<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;">Vaccine Name</th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Bird Day </th>
 <th style=" font-weight: bold;  font-size: 14px; background-color: #0E1F4D; color: white;">Vac. Day Left</th>

</tr>

      <?php
// TD Color Setting
// if($sr%2==0){
// $tdclr='cyan';
// }
// else{
// $tdclr='white';

// }


$tdclr='cyan';

  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>1 and $dateDiff<=4){

// 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 'ND+IB'; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 4-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop

}

// ****************************************************************************************************************************

  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>4 and $dateDiff<=5){
// 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 'INJECTION'; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 5-$dateDiff; ?> </td>
</tr>
<?php



} // This is end of 4th day coding
} // This is end of while loop
}
// ****************************************************************************************************************************

// ****************************************************************************************************************************


  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>5 and $dateDiff<=10){
// 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 'GUMBORO'; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 10-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop
}
// ****************************************************************************************************************************

// ****************************************************************************************************************************


  $qtyshedid = "SELECT * from accreg where accid2=1";
$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']; 
  
// 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>10 and $dateDiff<=14){
// 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 'LASOTA'; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo $dateDiff; ?> </td>
 <td style=" font-weight: bold;  font-size: 14px; background-color: <?php echo $tdclr; ?>"><?php echo 14-$dateDiff; ?> </td>
</tr>
<?php

} // This is end of 4th day coding
} // This is end of while loop
}
// ****************************************************************************************************************************

// ****************************************************************************************************************************

// ****************************************************************************************************************************


}  // This is end of if vac id is 0.


// END ALL VACCINE SHEDULE



}

 ?>
