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

extract($_POST);


require 'connection.php';

 date_default_timezone_set("Asia/Karachi");

      $d =31;
      $m = date("m");
      $y = date("Y");
     $dt1 = $y.'-'.$m.'-1';
     $dt2 = $y.'-'.$m.'-'.$d;


$sr= 1;
$qtytotal = 0;

?>


 <tr>
    <th style="background-color: black; color: white;">Sr#</th>
   <th style="background-color: black; color: white;">Company Name</th>
  <th style="background-color: black; color: white;">Bags</th>
  </tr>
  <?php
 $feedqty = "SELECT sum(ifnull(stockin,0)) as feedqty, accid FROM stockledger inner join itemreg on stockledger.itemid = itemreg.itemid where stockledger.dated>='$dt1' and stockledger.dated<='$dt2' and itemreg.catid = '2' and invoiceno='Purchase' group by stockledger.accid";
            $runqty = mysqli_query($connect, $feedqty) or die(mysqli_error($connect));
         while($row = mysqli_fetch_array($runqty)){
           if($sr%2!==0){
            $trclr='#C5D0F5';
            $trclrtxt='black';

           }
           else{
            $trclr='#1434A4';
            $trclrtxt='white';


           }
          ?>
          <tr style="font-size: 14px; font-weight: bold; background-color: <?php echo $trclr; ?>; color: <?php echo $trclrtxt; ?>">
            <td><?php echo $sr; ?></td>
            <td><?php
            $acid = $row['accid'];
            $accname = "SELECT * from accreg where accid='$acid'";
            $accnamerun = mysqli_query($connect, $accname) or die(mysqli_error($connect));
            $row2 = mysqli_fetch_array($accnamerun);
             echo $row2['accname']; ?>
               
             </td>

            <td style="font-size: 18px; font-weight: bold; background-color: <?php echo $trclr; ?>"><?php echo $row['feedqty']; ?></td>
          </tr>

         <?php 
 $sr++;
 $qtytotal = $qtytotal + $row['feedqty'];

}
?>
<tr>
  <td></td>
  <td style="font-size: 22px; color: green; font-weight: bold; border-color: white;" align="right">Total Bag: </td>
  <td style="color: green; font-size: 22px; font-weight: bold; border-color: white;"><?php echo $qtytotal; ?></td>
</tr>

<tr>
  <td colspan="3">
            <h2  style="margin-top: 50px; " class="title text-center">END DETAIL SECTION</h2>
            </td>
</tr>
<?php
}


// ****************previous month******************************
if(isset($_POST['dateddd'])){

extract($_POST);


require 'connection.php';

 date_default_timezone_set("Asia/Karachi");

      $d =31;
      $m = $_POST['dateddd'];
      $y = date("Y");
     $dt1 = $y.'-'.$m.'-1';
     $dt2 = $y.'-'.$m.'-'.$d;


$sr= 1;
$qtytotal = 0;

?>



 <tr>
    <th style="background-color: black; color: white;">Sr#</th>
   <th style="background-color: black; color: white;">Company Name</th>
  <th style="background-color: black; color: white;">Bags</th>
  </tr>
  <?php
 $feedqty = "SELECT sum(ifnull(stockin,0)) as feedqty, accid FROM stockledger inner join itemreg on stockledger.itemid = itemreg.itemid where stockledger.dated>='$dt1' and stockledger.dated<='$dt2' and itemreg.catid = '2' and invoiceno='Purchase' group by stockledger.accid";
            $runqty = mysqli_query($connect, $feedqty) or die(mysqli_error($connect));
         while($row = mysqli_fetch_array($runqty)){
           if($sr%2!==0){
            $trclr='#C5D0F5';
            $trclrtxt='black';

           }
           else{
            $trclr='#1434A4';
            $trclrtxt='white';


           }
          ?>
          <tr style="font-size: 14px; font-weight: bold; background-color: <?php echo $trclr; ?>; color: <?php echo $trclrtxt; ?>">
            <td><?php echo $sr; ?></td>
            <td><?php
            $acid = $row['accid'];
            $accname = "SELECT * from accreg where accid='$acid'";
            $accnamerun = mysqli_query($connect, $accname) or die(mysqli_error($connect));
            $row2 = mysqli_fetch_array($accnamerun);
             echo $row2['accname']; ?>
               
             </td>

            <td style="font-size: 18px; font-weight: bold; background-color: <?php echo $trclr; ?>"><?php echo $row['feedqty']; ?></td>
          </tr>

         <?php 
 $sr++;
 $qtytotal = $qtytotal + $row['feedqty'];

}
?>
<tr>
  <td></td>
  <td style="font-size: 22px; color: green; font-weight: bold; border-color: white;" align="right">Total Bag: </td>
  <td style="color: green; font-size: 22px; font-weight: bold; border-color: white;"><?php echo $qtytotal; ?></td>
</tr>

<tr>
  <td colspan="3">
            <h2  style="margin-top: 50px; " class="title text-center">END DETAIL SECTION</h2>
            </td>
</tr>
<?php
}


 ?>

   