
<?php include("../../include/dbconnect.php"); 
$month = substr($month_year,0,2);
$year = substr($month_year,3,4);

$fday = $year.'-'.$month.'-01';
$lday = lastday($month,$year);
?>
<table border="1">
<tr>
<td>Transaction ID</td>
<td>Date</td>
<td>Dbamt</td>
<td>Cramt</td>
<td>Difference</td>
<td>Type</td>
</tr>
<?

$result = mysqli_query($conn,"select distinct trans_id,date,amttype from ledger where compcode ='$compcode' and branch_code = '$branch' and account_year = '$account_year' and date >= '$fday' and date <= '$lday' order by trans_id ") or die(mysqli_error());
while($row = mysqli_fetch_row($result))
{
	$myresult = mysqli_query($conn,"select sum(dbamt),sum(cramt) from ledger where compcode = '$compcode' and branch_code = '$branch' and account_year = '$account_year' and trans_id = '$row[0]' ") or die(mysqli_error());
	$myrow = mysqli_fetch_row($myresult);
	?>
<tr>
<td><?=$row[0]?></td>
<td><?=british($row[1])?></td>
<td><?=$myrow[0]?></td>
<td><?=$myrow[1]?></td>
<td><?=$myrow[0]-$myrow[1]?></td>
<td><?=$row[2]?></td>
</tr>
    <?

	$kyresult = mysqli_query($conn,"select dbamt,cramt,narration from ledger where compcode = '$compcode' and branch_code = '$branch' and account_year = '$account_year' and trans_id = '$row[0]'  and acctcode = '' ") or die(mysqli_error());

	$k = mysqli_num_rows($kyresult);
	if($k >0)
	{
	$kyrow = mysqli_fetch_row($kyresult);		
		?>
		<tr>
<td><?=$row[0]?></td>
<td><?=british($row[1])?></td>
<td><?=$kyrow[0]?></td>
<td><?=$kyrow[1]?></td>
<td><?=$kyrow[2]?></td>
<td>GL Missing for this Transaction</td>
</tr>
<?
	}
	
	
	
	
}

function lastday($month, $year) {
   if (empty($month)) {
      $month = date('m');
   }
   if (empty($year)) {
      $year = date('Y');
   }
   $result = strtotime("{$year}-{$month}-01");
   $result = strtotime('-1 second', strtotime('+1 month', $result));
   return date('Y-m-d', $result);
}

?>


 









