<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];

//do_calander('#jv_date');
// Common Information

$page_title="Advanced Reports";



// End Common Information







?>




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

<!-- ======= <head> ======= -->
 <?php require_once('inc_files/inc_head.php'); ?>
<!-- ======= </head> ======= -->
 <?php
header('Content-Type: text/html; charset=utf-8');
?>

  <?php
  do_calander('#fdate');
  do_calander('#tdate');
  ?>
 
<script language="javascript">

function hide()

{

document.getElementById('pr').style.display='none';

}

</script>

 
 <script language="javascript">

function count(){



var total_unit=(document.getElementById('total_unit').value)*1; 

var unit_price=(document.getElementById('unit_price').value)*1;

document.getElementById('total_amt').value=(total_unit*unit_price);



}


function count_total_cal(){
var sub_total_amt=(document.getElementById('sub_total_amt').value)*1; 
var vat_amt=(document.getElementById('vat_amt').value)*1; 
var advance_amt=(document.getElementById('advance_amt').value)*1; 
document.getElementById('invoice_amt').value=(sub_total_amt+vat_amt)-advance_amt;

}




//window.onload = function() {
//  document.getElementById("itemin").focus();
//};






</script>

<body style="background:#FFFFFF;" >

<?php require_once "excel/inc.exporttable.php";?>

<div align="center" id="pr">

<input type="hidden" value="Print" onClick="hide();window.print();"/>

</div>


<?php 


if($_POST['report']==2507250001)
{
 $report="Date By Date Milk Receive Report";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and r.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 
 						  $sql = 'select r.tr_date from  milk_record r where 1 '.$date_con.'  group by r.tr_date order by r.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $cols = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $tr_date[$i] = $data->tr_date;
		  				 }
						 
						 
						 $sql  = 'select r.cattle_id, r.tr_date, sum(r.total_unit) as rec_qty
						  from cattle_info c, milk_record r
						 where c.cattle_id=r.cattle_id  '.$date_con.'  group by r.cattle_id, r.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $vals[$data->cattle_id][$data->tr_date] = $data->rec_qty;
						  $total_date_qty[$data->tr_date] = $total_date_qty[$data->tr_date] + $data->rec_qty;
						  $total_cattle_qty[$data->cattle_id] = $total_cattle_qty[$data->cattle_id] + $data->rec_qty;
		 				 }
 
?>


<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		
		
		
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"> <strong>For the Period of:</strong> <?php echo date('d-M-Y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-Y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th width="3%"  bgcolor="#ebf5fb" style="border:1px solid #000000;">SL</th>
		<th width="10%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Cattle No </th>
		<?php

for($i=1;$i<=$cols;$i++)
{
echo '<th  bgcolor="#ebf5fb" rowspan="0" style="white-space:nowrap; text-align:center; border:1px solid #000000;" ><strong>'.date('d-M-y',strtotime($tr_date[$i])).'</strong></th>';
}

?>

<th width="10%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Total Qty </th>
		</tr>
		</thead><tbody>
		<?php
		 $sl=1;
		
					
		
		//$sql = "select person_code, marketing_person_name from marketing_person where 1 group by person_code";
//		 $query = mysql_query($sql);
//		 while($info=mysql_fetch_object($query)){
//  		 $marketing_person_name[$info->person_code]=$info->marketing_person_name;
//		}
		

		?>
	
		
		<?php
		
		$sql="select  c.* from cattle_info c
		where 1 ".$lc_date_con.$dealer_con.$marketing_con.$lc_no_con."	group by c.cattle_id order by c.cattle_sl";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><?php echo $sl++;?></td>
		<td style="border:1px solid #000000;"><?php echo $data->cattle_no;?></td>
		<?php

for($i=1;$i<=$cols;$i++)
{
echo '<td style="border:1px solid #000000;">'.number_format($vals[$data->cattle_id][$tr_date[$i]],2).'</td>';

}

?>

<td style="border:1px solid #000000;"><?php echo number_format($total_cattle_qty[$data->cattle_id],2); $net_total_cattle_qty +=$total_cattle_qty[$data->cattle_id];?></td>
		</tr>
<?php  }?>
		<tr>
		  <td style="border:1px solid #000000;" ><div align="center"><strong> TOTAL: </strong></div></td>
		  <td style="border:1px solid #000000;" >&nbsp;</td>
		   <?php
for($i=1;$i<=$cols;$i++)

{
echo '<td style="border:1px solid #000000;"><strong>'.number_format($total_date_qty[$tr_date[$i]],2).'</strong></td>';
}
?>

<td style="border:1px solid #000000;" ><strong><?php echo number_format($net_total_cattle_qty,2); ?></strong></td>
		</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php }
elseif($_POST['report']==2507250002)
{
 $report="Date By Date Milk Receive Report";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and r.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['cattle_id']!='')
					$cattle_id_con=" and c.cattle_id='".$_POST['cattle_id']."'";
					
					if($_POST['shed_no']!='')
					$shed_no_con=" and c.shed_no='".$_POST['shed_no']."'";
					
					if($_POST['cattle_type']!='')
					$cattle_type_con=" and c.cattle_type='".$_POST['cattle_type']."'";
 
 
 						  $sql = 'select r.tr_date from  milk_record r where 1 '.$date_con.'  group by r.tr_date order by r.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $cols = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $tr_date[$i] = $data->tr_date;
		  				 }
						 
						 $sql  = 'select r.cattle_id, r.milk_schedule, r.tr_date, sum(r.total_unit) as shift_rec_qty
						  from cattle_info c, milk_record r
						 where c.cattle_id=r.cattle_id  '.$date_con.$cattle_id_con.$shed_no_con.$cattle_type_con.'  group by r.cattle_id, r.milk_schedule, r.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
				$vals_shift[$data->cattle_id][$data->milk_schedule][$data->tr_date] = $data->shift_rec_qty;
				$total_shift_date_qty[$data->milk_schedule][$data->tr_date] = $total_shift_date_qty[$data->milk_schedule][$data->tr_date] + $data->shift_rec_qty;
						  //$total_cattle_qty[$data->cattle_id] = $total_cattle_qty[$data->cattle_id] + $data->rec_qty;
		 		}
						 
						 
						 $sql  = 'select r.cattle_id, r.tr_date, sum(r.total_unit) as rec_qty
						  from cattle_info c, milk_record r
						 where c.cattle_id=r.cattle_id  '.$date_con.$cattle_id_con.$shed_no_con.$cattle_type_con.'  group by r.cattle_id, r.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $vals[$data->cattle_id][$data->tr_date] = $data->rec_qty;
						  $total_date_qty[$data->tr_date] = $total_date_qty[$data->tr_date] + $data->rec_qty;
						  $total_cattle_qty[$data->cattle_id] = $total_cattle_qty[$data->cattle_id] + $data->rec_qty;
		 				 }
 
?>

<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th width="3%" rowspan="2"  bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th width="10%" rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Cattle No </th>
        <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<th  colspan="3" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">
		<?php echo date('d-M-Y',strtotime($tr_date[$i]));?></div></th>
		<?php } ?>
			<th width="5%" rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"> Total </th>
</tr>
		<tr height="30" >
<?php

for($i=1;$i<=$cols;$i++)
{
			?>
		  <th width="2%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Morning</div></th>
		  <th width="1%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Afternoon</div></th>
		  <th width="2%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Total</div></th>
		  <?php } ?>
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;
		
					
		
		$sql="select  c.* from cattle_info c
		where 1 ".$cattle_id_con.$shed_no_con.$cattle_type_con."	group by c.cattle_id order by c.cattle_sl";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000;"><?php echo $data->cattle_no;?></td>
        <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<td style="border:1px solid #000000;"><?php echo $vals_shift[$data->cattle_id][1][$tr_date[$i]];?></td>
		<td style="border:1px solid #000000;"><?php echo $vals_shift[$data->cattle_id][2][$tr_date[$i]]; ?></td>
		<td style="border:1px solid #000000;"><?php echo $vals[$data->cattle_id][$tr_date[$i]];?></td>
		  
		  <?php } ?>
		  <td style="border:1px solid #000000;">
		  <?php echo number_format($total_cattle_qty[$data->cattle_id],2); $tot_total_cattle_qty +=$total_cattle_qty[$data->cattle_id];?></td>
</tr>
<?php  }?>
		<tr>
		   <td style="border:1px solid #000000;" ><div align="center"></div></td>
		   <td style="border:1px solid #000000;" ><div align="center"><strong> TOTAL: </strong></div></td>
          <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_shift_date_qty[1][$tr_date[$i]],2);?></strong></td>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_shift_date_qty[2][$tr_date[$i]],2);?></strong></td>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_date_qty[$tr_date[$i]],2);?></strong></td>
		   
		   <?php } ?>	 
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($tot_total_cattle_qty,2);?></strong></td>
</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}

elseif($_POST['report']==2507250003)
{
 $report="Daily Milk Comparison Report";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and r.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['cattle_id']!='')
					$cattle_id_con=" and c.cattle_id='".$_POST['cattle_id']."'";
					
					if($_POST['shed_no']!='')
					$shed_no_con=" and c.shed_no='".$_POST['shed_no']."'";
					
					if($_POST['cattle_type']!='')
					$cattle_type_con=" and c.cattle_type='".$_POST['cattle_type']."'";
 
 
 						  $sql = 'select m.ref_no, a.display_name as party_name from  journal_master m, sales_invoice s, accounts_reference a
						  where m.ref_no=a.ref_no and m.jv_no=s.jv_no and m.tr_from="Sales" 
						  and m.jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" group by m.ref_no order by m.ref_no';
						  $query = mysqli_query($conn,$sql);
						  $cols = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $ref_no[$i] = $data->ref_no;
						  $party_name[$i] = $data->party_name;
		  				 }
						 
						 $sql  = 'select r.milk_schedule, r.tr_date, sum(r.total_unit) as shift_rec_qty
						  from cattle_info c, milk_record r
						 where c.cattle_id=r.cattle_id  '.$date_con.'  group by r.milk_schedule, r.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
							$shift_rec_qty[$data->milk_schedule][$data->tr_date] = $data->shift_rec_qty;
							$total_shift_rec_qty[$data->milk_schedule] = $total_shift_rec_qty[$data->milk_schedule] + $data->shift_rec_qty;
							$total_date_rec_qty[$data->tr_date] = $total_date_rec_qty[$data->tr_date] + $data->shift_rec_qty;
							$net_total_rec_qty = $net_total_rec_qty + $data->shift_rec_qty;
							}
							
							 $sql  = 'select  r.tr_date, sum(r.total_unit) as calf_dranks_qty
						  from calf_drinks_milk r where 1 '.$date_con.'  group by  r.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
							$calf_dranks_qty[$data->tr_date] = $data->calf_dranks_qty;
							$tot_calf_dranks_qty = $tot_calf_dranks_qty + $data->calf_dranks_qty;
							}
						 
						 $sql  = 'select m.ref_no, m.jv_date, sum(s.total_unit) as sales_qty,  sum(s.total_amt) as sales_amt
						  from journal_master m, sales_invoice s 
						 where m.jv_no=s.jv_no and m.tr_from="Sales" and m.jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" 
						   group by m.ref_no, m.jv_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
							$sales_qty[$data->ref_no][$data->jv_date] = $data->sales_qty;
							$total_party_sales_qty[$data->ref_no] = $total_party_sales_qty[$data->ref_no] + $data->sales_qty;
							$total_date_sales_qty[$data->jv_date] = $total_date_sales_qty[$data->jv_date] + $data->sales_qty;
							
							$sales_amt[$data->ref_no][$data->jv_date] = $data->sales_amt;
							$total_party_sales_amt[$data->ref_no] = $total_party_sales_amt[$data->ref_no] + $data->sales_amt;
							$total_date_sales_amt[$data->jv_date] = $total_date_sales_amt[$data->jv_date] + $data->sales_amt;
							}
						 
 
?>

<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th width="3%" rowspan="2"  bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th width="10%" rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Date</th>
        <th colspan="5" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Milk Receive </div></th>
        <th width="10%" rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; ">Calf Drinks Milk</th>
        <th width="10%" rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; ">Milk Quantity </th>
    <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<th  colspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">
		<?php echo $party_name[$i];?></div></th>
		<?php } ?>
			<th colspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"> <div align="center">Total Milk Sales </div></th>
          </tr>
		<tr height="30" >
		  <th width="10%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Morning</div></th>
          <th width="10%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Different</div></th>
          <th width="10%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Afternoon</div></th>
          <th width="10%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Different</div></th>
          <th width="10%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Total</div></th>
  <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		  <th width="2%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Quantity</div></th>
		  <th width="2%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Amount</div></th>
		  <?php } ?>
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Quantity</div></th>
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Amount</div></th>
		  
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;
		
					
		
		$sql="select  r.tr_date from cattle_info c, milk_record r
		where c.cattle_id=r.cattle_id ".$date_con."	group by r.tr_date order by r.tr_date";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000; white-space:nowrap;">
		<?php echo date('d-M-y',strtotime($data->tr_date));?>  <?php  $previous_date = date('Y-m-d', strtotime($data->tr_date .' -1 day'));?></td>
        <td style="border:1px solid #000000;"><?php echo number_format($shift_rec_qty[1][$data->tr_date],2);?></td>
        <td style="border:1px solid #000000;">
		<?php if($_POST['fdate']!=$data->tr_date){ echo number_format($different_morning=$shift_rec_qty[1][$data->tr_date]-$shift_rec_qty[1][$previous_date],2);}?>		</td>
        <td style="border:1px solid #000000;"><?php echo number_format($shift_rec_qty[2][$data->tr_date],2);?></td>
        <td style="border:1px solid #000000;">
		<?php if($_POST['fdate']!=$data->tr_date){ echo number_format($different_afternoon=$shift_rec_qty[2][$data->tr_date]-$shift_rec_qty[2][$previous_date],2);}?>		</td>
        <td style="border:1px solid #000000;"><?php echo number_format($total_date_rec_qty[$data->tr_date],2);?></td>
        <td style="border:1px solid #000000;"><?php echo number_format($calf_dranks_qty[$data->tr_date],2);?></td>
        <td style="border:1px solid #000000;"><?php echo number_format($milk_balance_qty=$total_date_rec_qty[$data->tr_date]-$calf_dranks_qty[$data->tr_date],2);
		$tot_milk_balance_qty +=$milk_balance_qty;?></td>
        <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<td style="border:1px solid #000000;"><?php echo $sales_qty[$ref_no[$i]][$data->tr_date];?></td>
		<td style="border:1px solid #000000;"><?php echo $sales_amt[$ref_no[$i]][$data->tr_date];?></td>
		  
		  <?php } ?>
		  <td style="border:1px solid #000000;">
		  <?php echo number_format($total_date_sales_qty[$data->tr_date],2); $grand_total_date_sales_qty +=$total_date_sales_qty[$data->tr_date];?></td>
          <td style="border:1px solid #000000;"><?php echo number_format($total_date_sales_amt[$data->tr_date],2); $grand_total_date_sales_amt +=$total_date_sales_amt[$data->tr_date];?></td>
		</tr>
<?php  }?>
		<tr>
		   <td style="border:1px solid #000000;" ><div align="center"></div></td>
		   <td style="border:1px solid #000000;" ><div align="center"><strong> TOTAL: </strong></div></td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_shift_rec_qty[1],2);?></strong></td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_shift_rec_qty[2],2);?></strong></td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($net_total_rec_qty,2);?></strong></td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($tot_calf_dranks_qty,2);?></strong></td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($tot_milk_balance_qty,2);?></strong></td>
          <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_party_sales_qty[$ref_no[$i]],2);?></strong></td>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_party_sales_amt[$ref_no[$i]],2);?></strong></td>
		   
		   <?php } ?>	 
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_sales_qty,2);?></strong></td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_sales_amt,2);?></strong></td>
		</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}
elseif($_POST['report']==2507250004)
{
 $report="Daily Sales Report";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and s.jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['item_category']!='')
					$item_category_con=" and i.item_category='".$_POST['item_category']."'";
					
					if($_POST['item_id']!='')
					$item_id_con=" and i.item_id='".$_POST['item_id']."'";
					
					if($_POST['ref_no']!='')
					$ref_no_con=" and m.ref_no='".$_POST['ref_no']."'";
 
 
 						  $sql = 'select m.jv_date from  journal_master m, sales_invoice s, item_info i
						  where m.jv_no=s.jv_no and m.tr_from="Sales" and m.year>0 and i.item_id=s.item_id 
						  and m.jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" '.$item_category_con.$item_id_con.$ref_no_con.'
						   group by m.jv_date order by m.jv_date';
						  $query = mysqli_query($conn,$sql);
						  $cols = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $jv_date[$i] = $data->jv_date;
		  				 }
						 
						 
						 
						  $sql  = 'select s.item_id, m.jv_date, sum(s.total_unit) as sales_qty,  sum(s.total_amt) as sales_amt, sum(s.discount_amt) as discount_amt
						  from journal_master m, sales_invoice s, item_info i
						 where m.jv_no=s.jv_no and m.tr_from="Sales" and m.year>0 and i.item_id=s.item_id '.$item_category_con.$item_id_con.$ref_no_con.'
						 and m.jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" 
						   group by s.item_id, m.jv_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
							$sales_qty[$data->item_id][$data->jv_date] = $data->sales_qty;
							$total_item_sales_qty[$data->item_id] = $total_item_sales_qty[$data->item_id] + $data->sales_qty;
							$total_date_sales_qty[$data->jv_date] = $total_date_sales_qty[$data->jv_date] + $data->sales_qty;
							
							$sales_amt[$data->item_id][$data->jv_date] = $data->sales_amt-$data->discount_amt;
							$total_item_sales_amt[$data->item_id] = $total_item_sales_amt[$data->item_id] + $data->sales_amt-$data->discount_amt;
							$total_date_sales_amt[$data->jv_date] = $total_date_sales_amt[$data->jv_date] + $data->sales_amt-$data->discount_amt;
							
							
							
							$sales_price[$data->item_id][$data->jv_date]=($data->sales_amt-$data->discount_amt)/$data->sales_qty;
							$avg_price[$data->item_id]=$total_item_sales_amt[$data->item_id]/$total_item_sales_qty[$data->item_id];
							}
						 
 
?>

<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th  rowspan="2"  bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th  rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">SKU</th>
        <th  rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Item</th>
        <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<th  colspan="3" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">
		<?php echo date('d-M-y',strtotime($jv_date[$i]));?></div></th>
		<?php } ?>
			<th colspan="3" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"> <div align="center">Total Sales </div></th>
          </tr>
		<tr height="30" >
		  <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		  <th  bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Quantity</div></th>
		  <th  bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Price</div></th>
		  <th  bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Amount</div></th>
		  <?php } ?>
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Quantity</div></th>
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Price</div></th>
		  <th  bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Amount</div></th>
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;			
		
		 $sql="select  i.sku_code, i.item_id, i.item_name from item_info i, sales_invoice s
		where i.item_id=s.item_id ".$date_con.$item_category_con.$item_id_con."	group by s.item_id order by i.item_category, i.sku_code";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000; white-space:nowrap;"><?php echo $data->sku_code?></td>
        <td style="border:1px solid #000000; white-space:nowrap;"><?php echo $data->item_name?></td>
        <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<td style="border:1px solid #000000;"><?php echo number_format($sales_qty[$data->item_id][$jv_date[$i]],2);?></td>
		<td style="border:1px solid #000000;"><?php echo  number_format($sales_price[$data->item_id][$jv_date[$i]],2);?></td>
		<td style="border:1px solid #000000;"><?php echo number_format($sales_amt[$data->item_id][$jv_date[$i]],2);?></td>
		  
		  <?php } ?>
		  <td style="border:1px solid #000000;"><?php echo number_format($total_item_sales_qty[$data->item_id],2); 
		  $grand_total_item_sales_qty +=$total_item_sales_qty[$data->item_id];?></td>
          <td style="border:1px solid #000000;"><?php echo number_format($avg_price[$data->item_id],2);?></td>
          <td style="border:1px solid #000000;"><?php echo number_format($total_item_sales_amt[$data->item_id],2); 
		  $grand_total_item_sales_amt +=$total_item_sales_amt[$data->item_id];?></td>
		</tr>
<?php  }?>
		<tr>
		   <td colspan="3" style="border:1px solid #000000;" ><div align="center"></div>		     <div align="center"><strong> TOTAL: </strong></div></td>
	      <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_date_sales_qty[$jv_date[$i]],2);?></strong></td>
		   <td style="border:1px solid #000000;" >&nbsp;</td>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_date_sales_amt[$jv_date[$i]],2);?></strong></td>
		   
		   <?php } ?>	 
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_item_sales_qty,2);?></strong></td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_item_sales_amt,2);?></strong></td>
		</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}elseif($_POST['report']==2511050001)
{
 $report="Sales Summary Report";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and s.jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['item_category']!='')
					$item_category_con=" and i.item_category='".$_POST['item_category']."'";
					
					if($_POST['item_id']!='')
					$item_id_con=" and i.item_id='".$_POST['item_id']."'";
					
					if($_POST['ref_no']!='')
					$ref_no_con=" and m.ref_no='".$_POST['ref_no']."'";
 
 
 						  
						 
						 
						  $sql  = 'select s.item_id,  sum(s.total_unit) as sales_qty,  sum(s.total_amt) as sales_amt, sum(s.discount_amt) as discount_amt
						  from journal_master m, sales_invoice s, item_info i
						 where m.jv_no=s.jv_no and m.tr_from="Sales" and m.year>0 and i.item_id=s.item_id '.$item_category_con.$item_id_con.$ref_no_con.'
						 and m.jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" 
						   group by s.item_id';
						  $query = mysqli_query($conn,$sql);
						  //$col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
							$sales_qty[$data->item_id] = $data->sales_qty;
							$sales_amt[$data->item_id]= $data->sales_amt;
							$discount_amt[$data->item_id]= $data->discount_amt;
							}
						 
 
?>

<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th width="2%"  rowspan="2"  bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th width="12%"  rowspan="2"  bgcolor="#ebf5fb" style="border:1px solid #000000;">Category</th>
		<th width="8%"  rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">SKU</th>
        <th width="16%"  rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Item</th>

			<th colspan="5" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"> <div align="center">Total Sales </div></th>
          </tr>
		<tr height="30" >
	
		  <th width="13%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Quantity</div></th>
		  <th width="9%" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Price</div></th>
		  <th width="12%"  bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Amount</div></th>
		  <th width="10%"  bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Discount</div></th>
		  <th width="18%"  bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">Net Sales </div></th>
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;	
		
						 $sql  = 'select id, item_category as item_category_view  from item_category where 1  group by id';
						  $query = mysqli_query($conn,$sql);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $item_category_view[$data->id]= $data->item_category_view;
		 				 }		
		
		 $sql="select  i.sku_code, i.item_category, i.item_id, i.item_name from item_info i, journal_master m,  sales_invoice s
		where m.jv_no=s.jv_no and m.tr_from='Sales' and m.year>0 and i.item_id=s.item_id ".$date_con.$item_category_con.$item_id_con."	
		group by s.item_id order by i.item_category, i.sku_code";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000;"><?php echo $item_category_view[$data->item_category];?></td>
		<td style="border:1px solid #000000; white-space:nowrap;"><?php echo $data->sku_code;?></td>
        <td style="border:1px solid #000000; white-space:nowrap;"><?php echo $data->item_name;?></td>
        
		  <td style="border:1px solid #000000;"><?php echo number_format($sales_qty[$data->item_id],2); 
		  $grand_total_item_sales_qty +=$sales_qty[$data->item_id];?></td>
          <td style="border:1px solid #000000;"><?php echo number_format($avg_price=$sales_amt[$data->item_id]/$sales_qty[$data->item_id],2);?></td>
          <td style="border:1px solid #000000;"><?php echo number_format($sales_amt[$data->item_id],2); 
		  $grand_total_item_sales_amt +=$sales_amt[$data->item_id];?></td>
		  <td style="border:1px solid #000000;"><?php echo number_format($discount_amt[$data->item_id],2); 
		  $grand_total_item_discount_amt +=$discount_amt[$data->item_id];?></td>
		  <td style="border:1px solid #000000;"><?php echo number_format($amount_after_discount=$sales_amt[$data->item_id]-$discount_amt[$data->item_id],2); 
		  $grand_total_amount_after_discount +=$sales_amt[$data->item_id]-$discount_amt[$data->item_id];?></td>
		</tr>
<?php  }?>
		<tr>
		   <td colspan="4" style="border:1px solid #000000;" ><div align="center"></div>		     <div align="center"><strong> TOTAL: </strong></div></td>
	 
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_item_sales_qty,2);?></strong></td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_item_sales_amt,2);?></strong></td>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_item_discount_amt,2);?></strong></td>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_amount_after_discount,2);?></strong></td>
		</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}
elseif($_POST['report']==2507250005)
{
 $report="Daily Cattle Feeding Expense";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and r.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['cattle_id']!='')
					$cattle_id_con=" and c.cattle_id='".$_POST['cattle_id']."'";
					
					if($_POST['shed_no']!='')
					$shed_no_con=" and c.shed_no='".$_POST['shed_no']."'";
					
					if($_POST['cattle_type']!='')
					$cattle_type_con=" and c.cattle_type='".$_POST['cattle_type']."'";
					
					
						 $sql  = 'select id, report_title  from report_title
						 where 1 group by id';
						  $query = mysqli_query($conn,$sql);
						  while($data=mysqli_fetch_object($query)){
							$report_title[$data->id] = $data->report_title;
							}
 
 
 						  $sql = 'select item_id, bangla_name from   item_info
						  where item_category=2 group by item_id order by item_id';
						  $query = mysqli_query($conn,$sql);
						  $cols = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $item_id[$i] = $data->item_id;
						  $bangla_name[$i] = $data->bangla_name;
		  				 }	 
						 
						 
						 $sql  = 'select i.item_id, s.tr_date, sum(s.total_unit) as issue_qty,  sum(s.total_amt) as issue_amt
						  from item_info i, cattle_feed_issue s 
						 where i.item_id=s.item_id and i.item_category=2 and s.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" 
						   group by i.item_id, s.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
							$issue_qty[$data->item_id][$data->tr_date] = $data->issue_qty;
							$total_item_issue_qty[$data->item_id] = $total_item_issue_qty[$data->item_id] + $data->issue_qty;
							$total_date_issue_qty[$data->tr_date] = $total_date_issue_qty[$data->tr_date] + $data->issue_qty;
							$total_date_issue_amt[$data->tr_date] = $total_date_issue_amt[$data->tr_date] + $data->issue_amt;

							}
						 
						 
						 $sql = 'select item_id, bangla_name from   item_info
						  where item_category=3 group by item_id order by item_id';
						  $query = mysqli_query($conn,$sql);
						  $colsg = mysqli_num_rows($query);
						  while($datag=mysqli_fetch_object($query)){++$ig;
						  $item_id_grass[$ig] = $datag->item_id;
						  $bangla_name[$ig] = $datag->bangla_name;
		  				 }	 
						 
						 
						 $sql  = 'select i.item_id, s.tr_date, sum(s.total_unit) as grass_issue_qty,  sum(s.total_amt) as grass_issue_amt
						  from item_info i, cattle_feed_issue s 
						 where i.item_id=s.item_id and i.item_category=3 and s.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" 
						   group by i.item_id, s.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$ig;
							$grass_issue_qty[$data->item_id][$data->tr_date] = $data->grass_issue_qty;
							$total_item_grass_issue_qty[$data->item_id] = $total_item_grass_issue_qty[$data->item_id] + $data->grass_issue_qty;
							$total_date_grass_issue_qty[$data->tr_date] = $total_date_grass_issue_qty[$data->tr_date] + $data->grass_issue_qty;
							$total_date_grass_issue_amt[$data->tr_date] = $total_date_grass_issue_amt[$data->tr_date] + $data->grass_issue_amt;

							}
 
?>

<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th  bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Date</th>
        <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">
		<?php echo $bangla_name[$i];?></div>		  </th>
		<?php } ?>
			<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center"><?php echo $report_title[1]?></div></th>
			
			
            <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center"><?php echo $report_title[2]?></div></th>
			
			  <?php

for($ig=1;$ig<=$colsg;$ig++)
{
			?>
		<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">
		<?php echo $bangla_name[$ig];?></div>		  </th>
		<?php } ?>
		
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center"><?php echo $report_title[3]?></div></th>
			
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;
		
					
		
		$sql="select  r.tr_date from cattle_info c, milk_record r
		where c.cattle_id=r.cattle_id ".$date_con."	group by r.tr_date order by r.tr_date";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000; white-space:nowrap;">
		<?php echo date('d-M-y',strtotime($data->tr_date));?></td>
        <?php
		
		for($i=1;$i<=$cols;$i++)
		{
			?>
		<td style="border:1px solid #000000;"><?php echo number_format($issue_qty[$item_id[$i]][$data->tr_date],2);?></td>
		  
		  <?php } ?>
		  <td style="border:1px solid #000000;">
		  <?php echo number_format($total_date_issue_qty[$data->tr_date],2); $grand_total_date_issue_qty +=$total_date_issue_qty[$data->tr_date];?></td>
          <td style="border:1px solid #000000;">
		  <?php echo number_format($total_date_issue_amt[$data->tr_date],2); $grand_total_date_issue_amt +=$total_date_issue_amt[$data->tr_date];?></td>
		  
		   <?php
			for($ig=1;$ig<=$colsg;$ig++)
			{
			?>
		<td style="border:1px solid #000000;"><?php echo number_format($grass_issue_qty[$item_id_grass[$ig]][$data->tr_date],2);?></td>
		  
		 <?php } ?>
		 
		 <td style="border:1px solid #000000;">
		  <?php echo number_format($total_date_grass_issue_amt[$data->tr_date],2); $grand_total_date_grass_issue_amt +=$total_date_grass_issue_amt[$data->tr_date];?></td>
		  
		</tr>
<?php  }?>
		<tr>
		   <td style="border:1px solid #000000;" ><div align="center"></div></td>
		   <td style="border:1px solid #000000;" ><div align="center"><strong> TOTAL: </strong></div></td>
          <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_item_issue_qty[$item_id[$i]],2);?></strong></td>
		   
		   <?php } ?>	 
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_issue_qty,2);?></strong></td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_issue_amt,2);?></strong></td>
		   
			<?php
			for($ig=1;$ig<=$colsg;$ig++)
			{
			?>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_item_grass_issue_qty[$item_id_grass[$ig]],2);?></strong></td>
		   
		   <?php } ?>
		   
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_grass_issue_amt,2);?></strong></td>	 
		</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}elseif($_POST['report']==2507250008)
{
 $report="Daily Cattle Medicine Expense";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and r.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['cattle_id']!='')
					$cattle_id_con=" and c.cattle_id='".$_POST['cattle_id']."'";
					
					if($_POST['shed_no']!='')
					$shed_no_con=" and c.shed_no='".$_POST['shed_no']."'";
					
					if($_POST['cattle_type']!='')
					$cattle_type_con=" and c.cattle_type='".$_POST['cattle_type']."'";
					
					
						 $sql  = 'select id, report_title  from report_title
						 where 1 group by id';
						  $query = mysqli_query($conn,$sql);
						  while($data=mysqli_fetch_object($query)){
							$report_title[$data->id] = $data->report_title;
							}
 
 
 						  $sql = 'select item_id, bangla_name from   item_info
						  where item_category=4 group by item_id order by item_id';
						  $query = mysqli_query($conn,$sql);
						  $cols = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $item_id[$i] = $data->item_id;
						  $bangla_name[$i] = $data->bangla_name;
		  				 }	 
						 
						 
						 $sql  = 'select i.item_id, s.tr_date, sum(s.total_unit) as issue_qty,  sum(s.total_amt) as issue_amt
						  from item_info i, cattle_medicine_issue s 
						 where i.item_id=s.item_id and i.item_category=4 and s.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" 
						   group by i.item_id, s.tr_date';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
							$issue_qty[$data->item_id][$data->tr_date] = $data->issue_qty;
							$total_item_issue_qty[$data->item_id] = $total_item_issue_qty[$data->item_id] + $data->issue_qty;
							$total_date_issue_qty[$data->tr_date] = $total_date_issue_qty[$data->tr_date] + $data->issue_qty;
							$total_date_issue_amt[$data->tr_date] = $total_date_issue_amt[$data->tr_date] + $data->issue_amt;

							}
						 
						 
						 //$sql = 'select item_id, bangla_name from   item_info
//						  where item_category=3 group by item_id order by item_id';
//						  $query = mysqli_query($conn,$sql);
//						  $colsg = mysqli_num_rows($query);
//						  while($datag=mysqli_fetch_object($query)){++$ig;
//						  $item_id_grass[$ig] = $datag->item_id;
//						  $bangla_name[$ig] = $datag->bangla_name;
//		  				 }	 
//						 
//						 
//						 $sql  = 'select i.item_id, s.tr_date, sum(s.total_unit) as grass_issue_qty,  sum(s.total_amt) as grass_issue_amt
//						  from item_info i, cattle_feed_issue s 
//						 where i.item_id=s.item_id and i.item_category=3 and s.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'" 
//						   group by i.item_id, s.tr_date';
//						  $query = mysqli_query($conn,$sql);
//						  $col  = mysqli_num_rows($query);
//						  while($data=mysqli_fetch_object($query)){++$ig;
//							$grass_issue_qty[$data->item_id][$data->tr_date] = $data->grass_issue_qty;
//							$total_item_grass_issue_qty[$data->item_id] = $total_item_grass_issue_qty[$data->item_id] + $data->grass_issue_qty;
//							$total_date_grass_issue_qty[$data->tr_date] = $total_date_grass_issue_qty[$data->tr_date] + $data->grass_issue_qty;
//							$total_date_grass_issue_amt[$data->tr_date] = $total_date_grass_issue_amt[$data->tr_date] + $data->grass_issue_amt;
//
//							}
 
?>

<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th  bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Date</th>
        <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">
		<?php echo $bangla_name[$i];?></div>		  </th>
		<?php } ?>
			<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center"><?php echo $report_title[1]?></div></th>
			
			
            <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center"><?php echo $report_title[2]?></div></th>
			
			  <?php

for($ig=1;$ig<=$colsg;$ig++)
{
			?>
		<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center">
		<?php echo $bangla_name[$ig];?></div>		  </th>
		<?php } ?>
		
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center"><?php echo $report_title[3]?></div></th>
			
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;
		
					
		
		$sql="select  r.tr_date from cattle_info c, milk_record r
		where c.cattle_id=r.cattle_id ".$date_con."	group by r.tr_date order by r.tr_date";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000; white-space:nowrap;">
		<?php echo date('d-M-y',strtotime($data->tr_date));?></td>
        <?php
		
		for($i=1;$i<=$cols;$i++)
		{
			?>
		<td style="border:1px solid #000000;"><?php echo number_format($issue_qty[$item_id[$i]][$data->tr_date],2);?></td>
		  
		  <?php } ?>
		  <td style="border:1px solid #000000;">
		  <?php echo number_format($total_date_issue_qty[$data->tr_date],2); $grand_total_date_issue_qty +=$total_date_issue_qty[$data->tr_date];?></td>
          <td style="border:1px solid #000000;">
		  <?php echo number_format($total_date_issue_amt[$data->tr_date],2); $grand_total_date_issue_amt +=$total_date_issue_amt[$data->tr_date];?></td>
		  
		   <?php
			for($ig=1;$ig<=$colsg;$ig++)
			{
			?>
		<td style="border:1px solid #000000;"><?php echo number_format($grass_issue_qty[$item_id_grass[$ig]][$data->tr_date],2);?></td>
		  
		 <?php } ?>
		 
		 <td style="border:1px solid #000000;">
		  <?php echo number_format($total_date_grass_issue_amt[$data->tr_date],2); $grand_total_date_grass_issue_amt +=$total_date_grass_issue_amt[$data->tr_date];?></td>
		  
		</tr>
<?php  }?>
		<tr>
		   <td style="border:1px solid #000000;" ><div align="center"></div></td>
		   <td style="border:1px solid #000000;" ><div align="center"><strong> TOTAL: </strong></div></td>
          <?php

for($i=1;$i<=$cols;$i++)
{
			?>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_item_issue_qty[$item_id[$i]],2);?></strong></td>
		   
		   <?php } ?>	 
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_issue_qty,2);?></strong></td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_issue_amt,2);?></strong></td>
		   
			<?php
			for($ig=1;$ig<=$colsg;$ig++)
			{
			?>
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($total_item_grass_issue_qty[$item_id_grass[$ig]],2);?></strong></td>
		   
		   <?php } ?>
		   
		   <td style="border:1px solid #000000;" ><strong><?php echo number_format($grand_total_date_grass_issue_amt,2);?></strong></td>	 
		</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}
elseif($_POST['report']==2507250006)
{
 $report="Cattle Information Details ";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and r.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['cattle_id']!='')
					$cattle_id_con=" and c.cattle_id='".$_POST['cattle_id']."'";
					
					if($_POST['shed_no']!='')
					$shed_no_con=" and c.shed_no='".$_POST['shed_no']."'";
					
					if($_POST['cattle_type']!='')
					$cattle_type_con=" and c.cattle_type='".$_POST['cattle_type']."'";
 
 
 						  $sql = 'select b.birth_order as birth_order_view, c.birth_order as birth_order_id  
						  from  birth_order b, calf_info c where b.id=c.birth_order  group by c.birth_order order by b.id';
						  $query = mysqli_query($conn,$sql);
						  $cols = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						  $birth_order_id[$i] = $data->birth_order_id;
						  $birth_order_view[$i] = $data->birth_order_view;
		  				 }
						 
						 
						 $sql  = 'select c.mother_id, c.birth_order, c.date_of_birth as calf_dob, c.status as calf_status
						  from calf_info c where 1   group by c.mother_id, c.birth_order';
						  $query = mysqli_query($conn,$sql);
						  $col  = mysqli_num_rows($query);
						  while($data=mysqli_fetch_object($query)){++$i;
						$calf_dob[$data->mother_id][$data->birth_order] = $data->calf_dob;
						$calf_status[$data->mother_id][$data->birth_order] = $data->calf_status;		
		 				}
						 
						 
						 //$sql  = 'select r.cattle_id, r.tr_date, sum(r.total_unit) as rec_qty
//						  from cattle_info c, milk_record r
//						 where c.cattle_id=r.cattle_id  '.$date_con.$cattle_id_con.$shed_no_con.$cattle_type_con.'  group by r.cattle_id, r.tr_date';
//						  $query = mysqli_query($conn,$sql);
//						  $col  = mysqli_num_rows($query);
//						  while($data=mysqli_fetch_object($query)){++$i;
//						  $vals[$data->cattle_id][$data->tr_date] = $data->rec_qty;
//						  $total_date_qty[$data->tr_date] = $total_date_qty[$data->tr_date] + $data->rec_qty;
//						  $total_cattle_qty[$data->cattle_id] = $total_cattle_qty[$data->cattle_id] + $data->rec_qty;
//		 				 }
 
?>



<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
			/*font-family: 'Noto Sans Bengali', 'SolaimanLipi', sans-serif;*/
		}
		
		
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Cattle No </th>
        <th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Price</th>
        <th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><strong>Shed </strong></th>
        <th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Description</th>
        <th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">No of Teeth </th>
        <th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Body Weight </th>
        <th rowspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Received Date </th>
 <?php		 
for($i=1;$i<=$cols;$i++)
{
	?>
		  <th colspan="2" bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><div align="center"><?php echo $birth_order_view[$i];?></div></th>
	 <?php } ?>
		  </tr>
		  

		<tr height="30" >
		<?php		 
for($i=1;$i<=$cols;$i++)
{
	?>
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Date Of Birth </th>
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Status</th>
		  <?php } ?>
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;
		
			 $sql  = 'select id, shed_name  from shed_info where 1 group by id';
			 $query = mysqli_query($conn,$sql);
			 while($data=mysqli_fetch_object($query)){
			 $shed_name[$data->id] = $data->shed_name;
			 }	
			 
			 $sql  = 'select *  from cattle_info_details where 1 group by cattle_id';
			 $query = mysqli_query($conn,$sql);
			 while($data=mysqli_fetch_object($query)){
			 $cattle_price[$data->cattle_id] = $data->cattle_price;
			 $cattle_introduction[$data->cattle_id] = $data->cattle_introduction;
			 $receive_date[$data->cattle_id] = $data->receive_date;
			 }	
			 
			 $sql  = 'select *  from cattle_teeth_info where 1 group by cattle_id';
			 $query = mysqli_query($conn,$sql);
			 while($data=mysqli_fetch_object($query)){
			 $no_of_teeth[$data->cattle_id] = $data->no_of_teeth;
			 }
			 
			 $sql  = 'select * from cattle_body_weight where 1 group by cattle_id';
			 $query = mysqli_query($conn,$sql);
			 while($data=mysqli_fetch_object($query)){
			 $body_weight[$data->cattle_id] = $data->body_weight;
			 }
		
		$sql="select  c.* from cattle_info c
		where 1 ".$cattle_id_con.$shed_no_con.$cattle_type_con."	group by c.cattle_id order by c.cattle_sl";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000;"><?php echo $data->cattle_no;?></td>
        <td style="border:1px solid #000000;"><?php echo number_format($cattle_price[$data->cattle_id],2); $tot_cattle_price +=$cattle_price[$data->cattle_id];?></td>
        <td style="border:1px solid #000000;"><?php echo $shed_name[$data->shed_no]?></td>
        <td style="border:1px solid #000000;"><?php echo $cattle_introduction[$data->cattle_id];?></td>
        <td style="border:1px solid #000000;"><?php echo $no_of_teeth[$data->cattle_id];?></td>
        <td style="border:1px solid #000000;"><?php echo $body_weight[$data->cattle_id];?></td>
        <td style="border:1px solid #000000;">
		<?php if($receive_date[$data->cattle_id]!="0000-00-00" && $receive_date[$data->cattle_id]!=""){
		echo date('d-M-y',strtotime($receive_date[$data->cattle_id])); }?></td>
       <?php		 
for($i=1;$i<=$cols;$i++)
{
	?>
		  <td style="border:1px solid #000000;">
		  <?php 
		  if($calf_dob[$data->cattle_id][$birth_order_id[$i]]!=""){
		  echo  date('d-M-y',strtotime($calf_dob[$data->cattle_id][$birth_order_id[$i]])); }?></td>
		  <td style="border:1px solid #000000;"><?php echo  $calf_status[$data->cattle_id][$birth_order_id[$i]];?></td>
		  
		  <?php  }?>
		</tr>
<?php  }?>
		<tr>
		   <td style="border:1px solid #000000;" ><div align="center"></div></td>
		   <td style="border:1px solid #000000;" ><div align="center"><strong> TOTAL: </strong></div></td>
           <td style="border:1px solid #000000;" ><strong><?php echo number_format($tot_cattle_price,2);?></strong></td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <td style="border:1px solid #000000;" >&nbsp;</td>
           <?php		 
for($i=1;$i<=$cols;$i++)
{
	?>
	       <td style="border:1px solid #000000;" >&nbsp;</td>
		   <td style="border:1px solid #000000;" >&nbsp;</td>
		   <?php  }?>
		</tr>
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}elseif($_POST['report']==2507250007)
{
 $report="Calf Information Details";		
  $company_sql="SELECT * FROM user_group  WHERE id='".$_SESSION['user']['group']."'";
 $company_data = find_all_field_sql($conn,$company_sql);
 
 if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and r.tr_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';
 
 

					if($_POST['cattle_id']!='')
					$cattle_id_con=" and c.cattle_id='".$_POST['cattle_id']."'";
					
					if($_POST['shed_no']!='')
					$shed_no_con=" and c.shed_no='".$_POST['shed_no']."'";
					
					if($_POST['cattle_type']!='')
					$cattle_type_con=" and c.cattle_type='".$_POST['cattle_type']."'";
 
 
 						  //$sql = 'select r.tr_date from  milk_record r where 1 '.$date_con.'  group by r.tr_date order by r.tr_date';
//						  $query = mysqli_query($conn,$sql);
//						  $cols = mysqli_num_rows($query);
//						  while($data=mysqli_fetch_object($query)){++$i;
//						  $tr_date[$i] = $data->tr_date;
//		  				 }
						 
						// $sql  = 'select r.cattle_id, r.milk_schedule, r.tr_date, sum(r.total_unit) as shift_rec_qty
//						  from cattle_info c, milk_record r
//						 where c.cattle_id=r.cattle_id  '.$date_con.$cattle_id_con.$shed_no_con.$cattle_type_con.'  group by r.cattle_id, r.milk_schedule, r.tr_date';
//						  $query = mysqli_query($conn,$sql);
//						  $col  = mysqli_num_rows($query);
//						  while($data=mysqli_fetch_object($query)){++$i;
//				$vals_shift[$data->cattle_id][$data->milk_schedule][$data->tr_date] = $data->shift_rec_qty;
//				$total_shift_date_qty[$data->milk_schedule][$data->tr_date] = $total_shift_date_qty[$data->milk_schedule][$data->tr_date] + $data->shift_rec_qty;
//						  //$total_cattle_qty[$data->cattle_id] = $total_cattle_qty[$data->cattle_id] + $data->rec_qty;
//		 		}
						 
						 
						 //$sql  = 'select r.cattle_id, r.tr_date, sum(r.total_unit) as rec_qty
//						  from cattle_info c, milk_record r
//						 where c.cattle_id=r.cattle_id  '.$date_con.$cattle_id_con.$shed_no_con.$cattle_type_con.'  group by r.cattle_id, r.tr_date';
//						  $query = mysqli_query($conn,$sql);
//						  $col  = mysqli_num_rows($query);
//						  while($data=mysqli_fetch_object($query)){++$i;
//						  $vals[$data->cattle_id][$data->tr_date] = $data->rec_qty;
//						  $total_date_qty[$data->tr_date] = $total_date_qty[$data->tr_date] + $data->rec_qty;
//						  $total_cattle_qty[$data->cattle_id] = $total_cattle_qty[$data->cattle_id] + $data->rec_qty;
//		 				 }
 
?>

<style>
		table {
		 border-collapse: collapse !important;
		}
		td {
        	/* white-space: nowrap;  */
      	}
		body{
			zoom: 90%;
		}
		.tr, .td{
			white-space: nowrap;
			border-collapse: collapse !important;
		}
		.div{
			width:150px !important;
			
		}
		.fixed_head{
		 / Important /
  background-color: red;
  position: sticky;
  z-index: 100;
  top: 0;
		}
		
		

/*table tr td{
			border-top:1px solid #000000;
			border-left:1px solid #000000;	
			}
			
			table tr th{
			border-top:1px solid #000000;
			border-left:1px solid #000000;
			border-bottom:1px solid #000000;
		 		
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}*/
		


		
		
		/*@media print {
			#ExportTable, #ExportTable .tr, #ExportTable .td{
				font-size:9px !important;
			} 
			
			#ExportTable, #ExportTable .tr a, #ExportTable .td a{
				text-decoration: none;
				color: black;
			}
			
			table tr{
				page-break-inside: avoid;
			}
			
			table tr td, table tr th{
				border-color: #868686 !important;
			}
			
			@page {
				margin-left: 0.25in;
				margin-right: 0.25in;
			}
		}*/
		</style>

<table width="100%">
	   	<tr>
		<td width="25%" align="center" style="border:0px; border-color:white;">
		<!--<img src="../../../logo/<?= $_SESSION['user']['group']?>.png" style="width:150px;">-->
		</td>
		<td  width="50%" style="border:0px; border-color:white;">
			<table width="100%"  >
				<tr align="center" >
					<td style="font-size:20px; border:0px; border-color:white;"><strong><?php echo $company_data->group_name;?></strong></td>	
				</tr>
				<tr align="center" >
					<td style="font-size:14px; border:0px; border-color:white;"><strong><?php echo $report;?></strong></td>	
				</tr>
				
	
		
		
		
		
		 <tr>
          <td colspan="15" align="center" style="font-size:14px;border:0px; border-color:white;"><strong>For the Period of:</strong> <?php echo date('d-M-y',strtotime($_POST['fdate']));?>
		   <strong>To</strong> <?php echo date('d-M-y',strtotime($_POST['tdate']));?></td>
         </tr>
			</table>
		
		</td>
		
		<td  width="25%" align="center" style="border:0px; border-color:white;">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="15" style="font-size:14px;border:0px; border-color:white;">&nbsp;</td>
		</tr>
		 
</table>
	   
	   
	   <table width="100%"  border="0" cellpadding="2" id="ExportTable"  cellspacing="0" 
	   style="font-size:14px; border: 0px solid !important; border-collapse: unset !important;">
		
		<thead class="fixed_head">
		<tr height="30" >
		<th bgcolor="#ebf5fb" style="border:1px solid #000000;"><div align="center">SL</div></th>
		<th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Calf No </th>
        <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Mother ID</th>
        <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;"><strong>Type </strong></th>
        <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Date Of Birth </th>
        <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Days</th>
        <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Month</th>
        <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Live Weight </th>
        <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Live Weight  Date </th>
		  <th bgcolor="#ebf5fb" style="border:1px solid #000000; white-space:nowrap;">Breed </th>
		</tr>
		</thead><tbody>
		
		<?php
		$sl=1;
		
			 $sql  = 'select cattle_id, cattle_no  from cattle_info where 1 group by cattle_id';
			 $query = mysqli_query($conn,$sql);
			 while($data=mysqli_fetch_object($query)){
			 $cattle_no[$data->cattle_id] = $data->cattle_no;
			 }	
			 
			
			 $sql  = 'select id,  gender as gender_type from gender where 1 group by id';
			 $query = mysqli_query($conn,$sql);
			 while($data=mysqli_fetch_object($query)){
			 $gender_type[$data->id] = $data->gender_type;
			 }
			 
			 $sql  = 'select * from cattle_breed where 1 group by id';
			 $query = mysqli_query($conn,$sql);
			 while($data=mysqli_fetch_object($query)){
			 $cattle_breed[$data->id] = $data->cattle_breed;
			 }
		
		$sql="select  c.* from calf_info c
		where 1 ".$cattle_id_con.$shed_no_con.$cattle_type_con."	group by c.calf_id order by c.gender, c.calf_sl";
		$query = mysqli_query($conn,$sql);
		while ($data = mysqli_fetch_object($query)) 
		{

		
		?>
		
		<tr>
		<td style="border:1px solid #000000;"><div align="center"><?php echo $sl++;?></div></td>
		<td style="border:1px solid #000000;"><?php echo $data->calf_no;?></td>
        <td style="border:1px solid #000000;"><?php echo $cattle_no[$data->mother_id];?></td>
        <td style="border:1px solid #000000;"><?php echo $gender_type[$data->gender]; ?></td>
        <td style="border:1px solid #000000;"><?php echo date('d-M-y',strtotime($data->date_of_birth))?></td>
        <td style="border:1px solid #000000;">
		<?php
$from_date = $data->date_of_birth;
$to_date   = date('Y-m-d');


$start = new DateTime($from_date);
$end   = new DateTime($to_date);

// Difference
$diff = $start->diff($end);

// Number of days
echo "" . $diff->days;
?>
		</td>
        <td style="border:1px solid #000000;">
		
		<?php
$from_date = $data->date_of_birth;
$to_date   = date('Y-m-d');

$start = new DateTime($from_date);
$end   = new DateTime($to_date);

// Difference in days
$diff = $start->diff($end);
$total_days = $diff->days;

// Convert days to months (with decimals)
$months = $total_days / 30;  // Average days per month

echo "" . round($months, 2);
?>
		</td>
        <td style="border:1px solid #000000;"><?php echo $data->live_weight;?></td>
        <td style="border:1px solid #000000;"><?php echo date('d-M-y',strtotime($data->live_weight_date))?></td>
		  <td style="border:1px solid #000000;"><?php echo $cattle_breed[$data->breed]?></td>
		</tr>
<?php  }?>
		
		  
		  
	
		
		
		</tbody>
</table>
	   


<?php	}?>

 
</body>

</html>