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

?>

 
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>wilson po</title>

</head>
<body bgcolor="#FFFFFF" class="Normall" lang=EN-US>
<?
$fname='print.txt';

$delfile = "/tmp/print.txt";
if(file_exists($delfile))
 {
  unlink($delfile);
 }

if(!($myfile=fopen("/tmp/print.txt","w")))
{
  print("file couldnot be opened");
}
for($pocount=0;$pocount <count($po_nos);$pocount++)
{
		echo("Po No : $po_nos[$pocount]<br>");
		$sno=1;
		$invresult = mysql_query("select  distinct bcode,reference from matpo where account_year='$account_year1' and po_no = '$po_nos[$pocount]'  ") or die(mysql_error());			
		$row=mysql_fetch_row($invresult);
		
		$po_no = $po_nos[$pocount];
		$bcode = $row[0];
		$reference = $row[1];
		
		$date = substr($tdate,8,2).'-'.substr($tdate,5,2).'-'.substr($tdate,0,4);

		
		$result= mysql_query("select name,address1,address2,city,state,pin,cst,tin,taxtype,eccno,unit from supplier where bcode ='$bcode' ") or die(mysql_error());
		$row = mysql_fetch_row($result);
		$bname = $row[0].'  '.$row[10];
		$baddress1=$row[1];
		$baddress2=$row[2];
		$bcity = $row[3].','.$row[4].','.$row[5];
		$bcst=$row[6];
		$btin=$row[7];
		$btaxtype2=$row[8];
		$eccno= $row[9];

				

		$totline=0;
		
		fputs($myfile,chr(27).'C$'."\n");
		while($linecnt < 12)
		{
			fputs($myfile,"\n");
			$linecnt++;
		}
		
		fputs($myfile,chr(27).'M');		
		strcontrol($myfile,'',8);
		strcontrol($myfile,$bname,62);
		fputs($myfile,chr(14));
		strcontrol($myfile,$po_nos[$pocount],10);
		fputs($myfile,chr(18));		
		fputs($myfile,"\n");
		
		strcontrol($myfile,'',8);		
		strcontrol($myfile,$baddress1,62);		
		strcontrol($myfile,'',5);
		
		fputs($myfile,"\n");
		
		strcontrol($myfile,'',8);		
		strcontrol($myfile,$baddress2,62);
		strcontrol($myfile,'',4);
	    strcontrol($myfile,$date,15);		
		fputs($myfile,"\n");
		
		strcontrol($myfile,'',8);		
		strcontrol($myfile,$bcity,62);		
		strcontrol($myfile,'',15);		
		
		fputs($myfile,"\n");						
		

		strcontrol($myfile,'',5);		
		strcontrol($myfile,'',75);		
		
		strcontrol($myfile,$remarks,20);		
		fputs($myfile,"\n\n");
		
		strcontrol($myfile,'',13);		
		strcontrol($myfile,$reference,55);		
		fputs($myfile,"\n\n\n\n\n\n\n");	
		
		$linecnt= $linecnt+13;				
					
		$result = mysql_query("select distinct prodcode,qty,rate ,specifications,remarks,reference ,unit from matpo where account_year='$account_year1' and po_no = '$po_nos[$pocount]'  ") or die(mysql_error());
		while($row =mysql_fetch_row($result))
		{

			$prodcode =$row[0];
			$qty =$row[1];
			$rate=$row[2];
			if(!empty($row[3]))
			{
				$specifications ='(Specification: '.$row[3].')';
			}
			$remarks = $row[4];
			$reference =$row[5]; 
			$unit ='/'. $row[6];
			

			$tresult = mysql_query("select prodname,grade,COMPOSE  from rawmaterial where rawmaterial.prodcode='$prodcode'   ") or die(mysql_error());		
			$trow= mysql_fetch_row($tresult);
			$prodname = $trow[0];
			$gradecode =$trow[1];
			$composition = $trow[2];
			
			$tresult = mysql_query("select category from grade where catcode ='$gradecode'  ") or die(mysql_error());		
			$trow= mysql_fetch_row($tresult);
			$grade = $trow[0];
			strcontrol($myfile,'',5);
			strcontrol($myfile,$sno,5);

			strcontrol($myfile,$prodname,44);
			if(empty($grade))
			{
				strcontrol($myfile,'',11);
			}
			elseif(!empty($grade))
			{
			strcontrol($myfile,$grade,11);
			}
			numcontrol($myfile, number_format($qty,0),10);
			numcontrol($myfile,number_format($rate,2),10);
			strcontrol($myfile,$unit,5);
			fputs($myfile,"\n");
			
			strcontrol($myfile,'',9);
			strcontrol($myfile,$specifications,55);
			fputs($myfile,"\n");
			
			strcontrol($myfile,'',7);
			strcontrol($myfile,$remarks,50);
			fputs($myfile,"\n");						
			
			$linecnt=$linecnt+4;
			$sno++;
			
			$strs = explode(",",$composition);
			for($inc =0; $inc <= count($strs); $inc++)
			{
				$stm=trim($strs[$inc]);
				fputs($myfile,"          $stm");
				fputs($myfile,"\n");
				$linecnt++;

			}


//			strcontrol($myfile,'',7);
//			strcontrol($myfile,$composition,50);
//			fputs($myfile,"\n");			
//			$linecnt=$linecnt+4;

			
		}
		
			while($linecnt < 45)
			{
				fputs($myfile,"\n");
				$linecnt++;
			}
        fputs($myfile,"\n");					
        $sno =1;
		$result = mysql_query("select distinct qty,unit, delivery_date from matpo where account_year='$account_year1' and po_no = '$po_nos[$pocount]'  ") or die(mysql_error());
		while($row =mysql_fetch_row($result))
		{   
   
				strcontrol($myfile,'',6);
				strcontrol($myfile,$sno,5);
				strcontrol($myfile,$row[0],7);
				strcontrol($myfile,$row[1],3);
				$del_date = substr($row[2],8,2).'-'.substr($row[2],5,2).'-'.substr($row[2],0,4);
				strcontrol($myfile,$del_date,12);
				$sno++;
		}
				fputs($myfile,"\n\n\n\n");
			    $linecnt++;
			
			
			$result = mysql_query("select distinct sales_tax, excise_duty, documents, pay_terms, desp_mode, despatch_from from matpo where account_year='$account_year1' and po_no = '$po_nos[$pocount]'  ") or die(mysql_error());
			$row =mysql_fetch_row($result);	
			$salestax=$row[0];
			$exciseduty=$row[1];
			$documents=$row[2];
			$payterms=$row[3];
			$despmode=$row[4];
			$despatchfrom=$row[5];
		
		
			strcontrol($myfile,'',18);
			strcontrol($myfile,$salestax,50);	
			strcontrol($myfile,$exciseduty,50);
			fputs($myfile,"\n\n");
			$linecnt++;
	
			strcontrol($myfile,'',18);
			strcontrol($myfile,$documents,50);	
			strcontrol($myfile,$despmode,50);
			fputs($myfile,"\n\n");
			$linecnt++;			
	
			strcontrol($myfile,'',18);
			strcontrol($myfile,$payterms,50);	
			strcontrol($myfile,$despatchfrom,50);
			fputs($myfile,"\n\n");
			$linecnt++;		
		
			$linecnt=$linecnt+14;
			

			while($linecnt < 49)
			{
			
				fputs($myfile,"\n");
				$linecnt++;
				
			}

      		fputs($myfile,chr(12));


}
				

				
	//			$query = "update matpo set print_status = 'T' where po_no ='$po_no' ";
	//			mysql_query($query) or die(mysql_error());
				


//}


?>
<a href = "/wilson/dload.php?dfile=<?echo($fname);?>">Download Text file</a>
<br><br><font size=+1><center><a href= "index.html">Return to Index</a></center></font>

                                                                             
</body>
</html>
<?

function line($myfile,$maxlen)
{
for($sk=1;$sk <$maxlen;$sk++)
{ fputs($myfile,"_"); };
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," "); };
fputs($myfile,$stname);
//fputs($myfile,"\n");
}

function heading($myfile,$po_no,$date)
{





	fputs($myfile,"-------------------------------------------------------------------------\n");
	fputs($myfile," Sl.No           Particulars                Qty       Rate   Amount  \n");
	fputs($myfile,"---------------------------------------------------------------------\n");


}

?>
