<?php include("../../include/dbconnect.php");

$result=mysqli_query($conn,"select distinct name from company where compcode = '$compcode' ") or die(mysqli_error());
$row = mysqli_fetch_row($result);
$compname = $row[0];

?>
<title>Collection details</title>
<form>
<body bgcolor="#ffffff"  topmargin=0>
<font face="Arial, Helvetica, sans-serif">
<?

$startdt = us($stdt);
$enddt = us($edt);
?>
</font>
<TABLE  width="957" BORDER=1 CELLPADDING=4 RULES=COLS  >

<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>

				
<thead>
<tr>
<td height="34" colspan="100%" ALIGN ="left"><h4 align="center"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><?echo($compname);?></font></h4></td></tr>
<tr>
      <td colspan="100%"><div align="center"><font face="Arial, Helvetica, sans-serif">Collection Summary From <? echo($stdt);?> To <?echo($edt);?></font></div></td>
    </tr>
<tr bgcolor="#DAF1A9">
<td width="54" align=center><div align="right"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Sl No </font></div></td>
<td width="574" align=center><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Customer</font></td>


<td width="156" align=center><div align="right"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Cash Collections </font></div></td>
<td width="121" align=center><div align="right"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Cheque Collections</font></div></td>

</tr>
<tr>
<td><hr></td>

<td><hr></td>
<td><hr></td>
<td><hr></td>

</tr>

</thead>
<tbody>
<?
$sl=1;
$cashtotal = 0;
$cheqtotal = 0;



	$jresult = mysqli_query($conn,"select distinct acctcode  from ledger where compcode = '$compcode' and date >='$startdt' and date <= '$enddt'  and cramt >0 and acctcode in (select acctcode from acctmast where acctgroup = '11120002') ") or die(mysqli_error());
	while($jrow = mysqli_fetch_row($jresult))
	{

	$cresult = mysqli_query($conn,"select sum(cramt) from ledger where compcode = '$compcode' and date >='$startdt' and date <= '$enddt' and (taxtype != 'Debitnote' or taxtype !='Creditnote') and cramt >0  and cheqno !='' and acctcode = '$jrow[0]' ") or die(mysqli_error());
	$crow = mysqli_fetch_row($cresult);
	$cheqamt = $crow[0];
	$cheqtotal = $cheqtotal + $cheqamt;
	
	$caresult = mysqli_query($conn,"select sum(cramt) from ledger where compcode = '$compcode' and date >='$startdt' and date <= '$enddt' and (taxtype != 'Debitnote' or taxtype !='Creditnote') and cramt >0  and cheqno ='' and acctcode = '$jrow[0]' ") or die(mysqli_error());
	$carow = mysqli_fetch_row($caresult);
	$cashamt = $carow[0];
	$cashtotal = $cashtotal+$cashamt;

	$fig = $cashamt+$cheqamt;
$presult = mysqli_query($conn,"select description from acctmast where acctcode = '$jrow[0]' ") or die(mysqli_error());
	$prow = mysqli_fetch_row($presult);
	if($fig >0)
	{
	?>
	<tr>
	<td align=left><font face="Arial, Helvetica, sans-serif">
	  <div align="center"><font face="Arial, Helvetica, sans-serif"><?echo($sl);?></font></div></td>	

	<td align=left><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><?echo($prow[0]);?></font></td>
	
	<td align=right><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">
	<? if($cashamt>0) echo $cashamt;?> 
	</font></td>
	<td align=right><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">
	<? if($cheqamt>0) echo $cheqamt;?> 
	</font></td></tr>
	<?
	}
         $sl++;       
  }
  ?>
	<tr>
<td><hr></td>

<td><hr></td>
<td><hr></td>
<td><hr></td>

</tr>		
            
	<tr>
	<td align=left><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">&nbsp;</font></td>	

	<td align=left><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Total</font></td>
	
	<td align=right><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">
	<?=$cashtotal?>
	</font></td>
	<td align=right><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">
	<?=$cheqtotal?>
	</font></td></tr>            	</tbody>
		
</table>

