<?php   include("../../include/dbconnect.php");?>
<title>Payment Confirmation Summary Print</title>

<style type="text/css">
<!--
.style2 {color: #FF0000}
.style5 {font-family: Arial, Helvetica, sans-serif}
.style8 {font-family: Arial, Helvetica, sans-serif; color: #006600; }
body {
	background-color: #FFFFCC;
	background-repeat: no-repeat;
}
.style14 {color: #660000; font-style: italic; font-weight: bold; font-family: Arial, Helvetica, sans-serif; }
.style16 {font-family: Arial, Helvetica, sans-serif; color: #660000; }
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
}
.style21 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
.style32 {color: #000000}
.style34 {font-weight: bold; font-family: Arial, Helvetica, sans-serif; color: #660000;}
.style36 {color: #CC66FF}
-->
</style>
<body  topmargin=0>
<?php

$todate = $from_date;
$temp = $from_date;
$startdt = substr($temp,6,4).substr($temp,3,2).substr($temp,0,2);

$edt = $to_date;
$temp=$to_date;
$enddt = substr($temp,6,4).substr($temp,3,2).substr($temp,0,2);
$grtdbamt = 0;
$grtcramt = 0;
$grtbamt = 0;

$totdbamt = 0;
$totcramt = 0;
$totbamt = 0;
ledgtit($te, $todate, $edt);
for ($buyind=0;$buyind < count($bcode);$buyind++)
{

$totdbamt = 0;
$totcramt = 0;
lhead($bcode[$buyind]);

$result = mysql_query("SELECT custledger.bcode, custledger.invno, custledger.date, custledger.dbamt, custledger.cramt, custledger.crnoteno, custledger.crnotedt, custledger.crnoteamt FROM custledger WHERE  custledger.bcode='$bcode[$buyind]' order by date ");
      while($row=mysql_fetch_row($result))
    	{
          $cdate = substr($row[2],0,4).substr($row[2],5,2).substr($row[2],8,2);  		
		if ($cdate >= "$startdt"  && $cdate <= "$enddt" )
		{
	       $invno = $row[1]; 
		   $invdt = substr($row[2],8,2).'-'.substr($row[2],5,2).'-'.substr($row[2],0,4); 
		   if ($row[5]==0)
		   {
     		   $dbamt = $row[3];
	    	   $cramt = $row[4];
			}
		    else
			{
     		   $dbamt = $row[3];
	    	   $cramt = $row[4] + $row[7];
			}	   
?>
           <?
		   if ($dbamt == $cramt )
		   {
		   ?>
        	<table border =1 rules = "all"  width="710" span class = "style14">
			 <td width="124" align=left class="style8"><? echo($invno);?></td>
		    <td width="128" align=left class="style8"><? echo($invdt);?></td>
		    <td width="156" align=left class="style8"><div align="right"><? echo($dbamt);?></div></td>
           	<td width="145" align=right class="style8"><div align="right" ><? echo(number_format($cramt,2,'.',''));?> </div></td>  <strong></span></strong>
</table>
			<strong>
			<?
			$totdbamt = $totdbamt + $dbamt;
			$totcramt = $totcramt + $cramt;
			}
        	   else 
		    {
			?>
</strong>
			<table border =1 rules = "all"  width="710" span class="style2">
			  <td width="124" align=left class="style21"><? echo($invno);?></td>
              <td width="128" align=left class="style21"><? echo($invdt);?></td>
			  <td width="156" align=left class="style21"><div align="right"><? echo($dbamt);?></div></td>
              <td width="145" align=right class="style21"><div align="right"><? echo(number_format($cramt,2,'.',''));?> </div></td><strong></span></strong>
            </table>
			<?
			$totdbamt = $totdbamt + $dbamt;
			$totcramt = $totcramt + $cramt;
			}
			?>
			
<?
}
}
//<hr align = left width = 700 >
//</hr>
?>

<table  width="710" span class="style2">
	  <td width="124" align=left class="style5"></td>
      <td width="128" align=left class="style21 style32">TOTAL </td>
      <td width="156" align=left class="style5"><div align="right"><strong>
		          <?  echo(number_format($totdbamt,2,'.',''));?></strong></div></td>
    	<td width="145" align=right class="style8"><div align="right"><strong>
		        <? echo(number_format($totcramt,2,'.',''));?></strong></div></td>
</table>
<?  $totbamt = $totdbamt - $totcramt ; ?>

<table  width="710" span class="style2">
<tr>
	  <td width="124" align=left class="style5"></td>
      <td width="128" align=left class="style21 style32"><strong>Balance Amount </td>
      <td width="156" align=left class="style5"><div align="right"><strong>
         <? echo(number_format($totbamt,2,'.','')); ?>
 </div></td>
      <td width="145" align=left class="style8"><div align="right"><strong>
      <? if ($totdbamt < 0) { echo(number_format($totbamt,2,'.',''));}?>
  </strong></div></td>
		
</table>

<?
//</hr>
			$grtdbamt = $grtdbamt + $totdbamt;
			$grtcramt = $grtcramt + $totcramt;

$totdbamt = 0;
$totcramt = 0;
$totbamt = 0;
}
?>
 </strong>
<strong>

<table width="710" span class="style2">
	  <td width="124" align=left class="style5"></td>
      <td width="128" align=left class="style21 style32">Grant Total </td>
      <td width="156" align=left class="style5"><div align="right"><strong>
		          <?  echo(number_format($grtdbamt,2,'.',''));?></strong></div></td>
    	<td width="145" align=right class="style8"><div align="right"><strong>
		        <? echo(number_format($grtcramt,2,'.',''));?></strong></div></td>
</table>

<?  $grtbamt = $grtdbamt - $grtcramt ; ?>

<table  width="710" span class="style2">
<tr>
	  <td width="124" align=left class="style5"></td>
      <td width="128" align=left class="style21 style32"><strong>Balance Amount </td>
      <td width="156" align=left class="style5"><div align="right"><strong>
         <? echo(number_format($grtbamt,2,'.','')); ?>
 </div></td>
      <td width="145" align=left class="style8"><div align="right"><strong>
      <? if ($grtbamt < 0) { echo(number_format($grtbamt,2,'.',''));}?>
  </strong></div></td>
		
</table>




<?	
function lhead($bcode)
{
$presult = mysql_query("select name,unit, credit from buy where bcode = '$bcode' ");
$row11 = mysql_fetch_row($presult);
$custname = $row11[0];
$unit = $row11[1];
$credit = substr("$row11[2]",0,2);
?>
<table width="698" border=0  >
<tr><td><h4 align="left" class="style34 style36"  bgcolor="#FFCC99"><? echo($custname);?>,<? echo($unit);?> </h4></td>
<td><h4 align="left"  bgcolor="#FFCC99" class="style34 style36"> Credit Days : <? echo($credit);?> </h4></td>
</tr>
</table>

<?
//<hr align = left width = 700 >
//</hr>
?>
<table  border =1 rules = "all" width="710" span class = "style14">
<th width="124"><div align="center" class="style16">BILL NO </td></div></th>
<th width="128"><div align="center" class="style16">BILL DATE</div></th>
<th width="156"><div align="center" class="style16">DEBIT AMOUNT </div></th>
<th width="144"><div align="center" class="style16">CREDIT AMOUNT</td></div></th>

</table>
<?
//<hr align = left width = 700 >
//</hr>?>

<?
}
?>
<?
function ledgtit($temp, $todate,$edt)
 {
?>
<table width="698" height="3" border=0  rules = "all">
<tr><td><h1 align="center" class="style34">WILSON PAPER TOOLS </h1>
</tr></td>
</table>


<table rules = "all" height="1" width="700" border=0>
<tr><td><h3 align="center" class="style34">DEALERS STATEMENT FROM &nbsp;&nbsp; <? echo($todate);?>&nbsp;TO&nbsp;<? echo($edt);?></h3></td>
</tr> 
</table>


<?
}
?>
</body>
