<? 
session_start();
$brcode = $_SESSION['brcode'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");
?>
<link type="text/css" href="../css/form.css" rel="stylesheet" />
<link type="text/css" href="../jquery/jquery-ui.min.css" rel="stylesheet" />

<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="../jquery/jquery.jqEasyCharCounter.min.js"></script>


<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d799}
</style>
<body bgcolor=ivory>

<body class=bd >
<CENTER>
<h3>CREDIT NOTE REPORT </H3>

<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()" method=post>

<table border=1 class=report style=" width: 30%;">
<tr><td>From: </td><td> dd <input type=text size=2 name='d' value='<?print date("d",time())?>'>
			mm <input type=text size=2 name='m' value='<?print date("m",time())?>'>
			yy <input type=text size=4 name='y' value='<?print date("Y",time())?>'>
</td></tr>
<tr><td>To: </td><td>dd <input type=text size=2 name='d1' value='<?print date("d",time())?>'>
			mm <input type=text size=2 name='m1' value='<?print date("m",time())?>'>
			yy <input type=text size=4 name='y1' value='<?print date("Y",time())?>'>
</td></tr>
<tr><td  colspan=2 align=center><input type=submit value='SHOW' name='show'> 
    <input type=button value='CANCEL' onClick=document.location='../blank.html'></td>
</tr>
</table>

<br>&nbsp;
<?
if(isset($_POST['show'])) 
{
	$d=$_REQUEST['d'];
	$m=$_REQUEST['m'];
	$y=$_REQUEST['y'];
	$d1=$_REQUEST['d1'];
	$m1=$_REQUEST['m1'];
	$y1=$_REQUEST['y1'];
	$fromdt=$y."-".$m."-".$d;
	$todt=$y1."-".$m1."-".$d1;
	$sql="select vendor,refno,date,refno,before_tax,cgstamt,cgstp,sgstamt,sgstp,igstamt,igstp,expense_amount from gst_creditnote where brcode='$brcode' and date>='$fromdt' and date<='$todt' order by date ";
	$result=mysqli_query($db,$sql) or die(mysqli_error());
   	if(mysqli_num_rows($result)>0)
   	{
	?>
		Debit Note Register From <? echo implode('-', array_reverse(explode('-', $fromdt))) ?> To <? echo implode('-', array_reverse(explode('-', $todt))) ?> 
		<table bgcolor=silver cellspacing=1 cellpadding=3 width=100% class=report>
		<th>DB.No<th>Customer <th> GSTIN<th>Date <th>Before Tax<th>CGST%<th>CGST AMT<th>SGST%<th>SGST AMT<th>IGST%<th>IGST AMT<th>Net Amount 
		<?
		$tnet=0;
		$ttax=0;
		$bt=0;
		while($row=mysqli_fetch_array($result))
		{
		    $sql1="select tin from cust_master where  acname = '$row[0]' ";
	        $result1=mysqli_query($db,$sql1) or die(mysqli_error());
	        $row1=mysqli_fetch_array($result1);
		 	print "<tr bgcolor=white><td>$row[1]</td><td>$row[0]</td><td>$row1[0]</td><td width='70px'>".implode('-', array_reverse(explode('-', $row[2])))."</td><td align=center>$row[4]</td><td align='center'>$row[6]</td><td align='center'>$row[5]</td><td align='center'>$row[8]</td><td align='center'>$row[7]</td><td align='center'>$row[10]</td><td align='center'>$row[9]</td>";
//			print "<td align=right>$row[8]</td><td align=right>".round($cgstp,2)."</td><td align=right>".round($cgstamt,2)."</td><td align=right>".round($sgstp,2)."</td><td align=right>".round($sgstamt,2)."</td><td align=right>".round($igstp,2)."</td><td align=right>".round($igstamt,2)."</td><td align=right>$row[5]</td>";
			$tcgstamt=$tcgstamt+$cgstamt;
			$tsgstamt=$tsgstamt+$sgstamt;
			$tigstamt=$tigstamt+$igstamt;
			$bt+=$row[8];
		 	$ttax+=$row[6];
		 	$tnet+=$row[5];
		}
		//print "<tr bgcolor=white><td colspan=7 align=center><b>Total</td><td align=right><b>".putComa($tnet)."</td><td></td>";
		//print "<td align=right><b>".round($tcgstamt,2)."</td><td>&nbsp;</td><td align=right><b>".round($tsgstamt,2)."</td><td></td><td align=right><b>".round($tigstamt,2)."</td><td align=right><b>".putComa($bt)."</td></tr>";
		
	print "</table>";
	}
}
?>

