<?php include("../../include/dbconnect.php"); 
$delfile = "/tmp/print.txt";
$f_date = substr($from_date,6,4).'-'.substr($from_date,3,2).'-'.substr($from_date,0,2);
$t_date = substr($to_date,6,4).'-'.substr($to_date,3,2).'-'.substr($to_date,0,2);
if(file_exists($delfile))
 {
  unlink($delfile);
 }

$fname = 'print.txt';
if(!($myfile=fopen("/tmp/print.txt","w")))
{
  print("file couldnot be opened");
}

$pgno=1;
$kount=1;

$result=mysql_query(" select name from company where  compcode='$compcode' order by name") or die(mysql_error());
$row=mysql_fetch_row($result);
$company=$row[0];

$string1='Itemwise Statement from '. $stdt. ' to  ' .$edt;


title($myfile,$company,$string1);
$kount=$kount+6;	

?>

<table width=771  border=0>
<tr><td width="993" align ="center"  bgcolor="#FFFF00"><h5>Customer wise Items and Drawing No with Rate</td></tr></table>

<table width="772" border="0">
</tr>
			 <tr><td colspan="20"><hr></td></tr>
<tr>
<td width="85" align="right"><font size="-1">Sl No</font></td>				
<td width="285" align="center"><font size="-1">Item Name</font></td>
<td width="262" align="center"><font size="-1">Drawing No</font></td>				
<td width="122" align="center"><font size="-1">Rate</font></td>				


</tr>
			 <tr><td colspan="20"><hr></td></tr>


<?
if($kount>=55)
{
	$pgno++;
	fputs($myfile,"_________________________________________________________________________________________________________________________________________________________\n");
	fputs($myfile,chr(12).chr(13).chr(18)."\n");
	fputs($myfile,"                                                                                                 Page No : $pgno\n");
	$kount=0;
	title($myfile,$company,$string1);
	$kount=$kount+6;		
}

	


for($ind=0;$ind < count($bcode);$ind++)
{
	$temp_drawing='';
	$sl=1;
	$qtytot =0;
	
	$bresult = mysql_query("select name,unit from buy where bcode = '$bcode[$ind]' ") or die(mysql_error());
	$brow = mysql_fetch_row($bresult);
	$bname = $brow[0].'&nbsp;&nbsp;'.$brow[1];
	$bstatus ='F';
	$totstatus ='F';
	$dresult = mysql_query("select distinct product.prodname,product.drawing_no,orders.rate  from orders,product where orders.bcode ='$bcode[$ind]' and orders.bcode = product.bcode and orders.prodcode = product.prodcode order by product.prodname ")or die(mysql_error());
	while($drow = mysql_fetch_row($dresult))
	{

		if($bstatus == 'F')
		{
			?>
			
			<tr bgcolor="#FAF8B4"><td colspan="20"><? echo($bname);?></td></tr>
			<?
			$bstatus='T';		
		}
		
	  ?>		
		
		<tr bgcolor="#D3E4D1">

		<td width="85" align="center"><font size="-1" color="<? echo($clr);?>"><? echo($sl);?></font></td>															
		<td width="285" align="left"><font size="-1" color="<? echo($clr);?>"><? echo($drow[0]);?></font></td>
		<td width="262" align="left"><font size="-1" color="<? echo($clr);?>" ><?  echo($drow[1]);?></font></td>		
		<td width="122" align="right"><font size="-1" color="<? echo($clr);?>"><? echo($drow[2]);?> </font></td></tr>				

		<?  


					
		$sl++;
	}
}								
?>

</table>

    <br>
    <br><font size=1><center><a href= "../../index.html">Return to index page</center></font>
                                                                             
</body>
</form>

<?

function title($myfile,$company,$string1) 
{
	fputs($myfile,chr(18).chr(14));
	fputs($myfile,"$company \n\n");
	fputs($myfile,"$string1 \n");
	fputs($myfile,chr(27).'M');
	fputs($myfile,"_________________________________________________________________________________________________________________________________________________________\n");
	fputs($myfile,"Date     Inv No   Buyer                               Product                                Rate    Qty     Amount     VAT       E1 Sales     Total Amt.\n"); 
	fputs($myfile,"_________________________________________________________________________________________________________________________________________________________\n");
}

function strcontrol($myfile,$stname,$maxlen)
{
	$plen = strlen($stname);
	$tlen = $maxlen-$plen;
	fputs($myfile,$stname);
	for($sk=1;$sk <$tlen;$sk++)
	{ fputs($myfile," "); };
}




function numcontrol($myfile,$stname,$maxlen)
{
	$plen = strlen($stname);
	$tlen = $maxlen-$plen;
	for($sk=1;$sk <$tlen;$sk++)
		{ fputs($myfile," "); };
	if($stname >0)
	{
		fputs($myfile,$stname);
	}
	else
	{
	fputs($myfile,"    ");
	}
}
?>