

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

?>

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

</head>
<body bgcolor="#FFFFFF" class="Normall" lang=EN-US>
<?


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

if(!($myfile=fopen("/tmp/print.txt","w")))
{
  print("file couldnot be opened");
}
for($incount=0;$incount <count($invnos);$incount++)
{
		echo("Invoice No : $invnos[$incount]<br>");
		$sno=1;
		$invresult = mysql_query("select  distinct bcode,prodcode,prepare_time from labourinv where account_year='$account_year1' and invno = '$invnos[$incount]'  ") or die(mysql_error());			
		$row=mysql_fetch_row($invresult);
		
		$invno = $invnos[$incount];
		$bcode = $row[0];
		$prodcode = $row[1]; 
		$date = substr($tdate,8,2).'-'.substr($tdate,5,2).'-'.substr($tdate,0,4);
		$prepare_time= $date.'/'.$row[2];
		
		$presult = mysql_query("select  remarks,reference from labourinv where account_year='$account_year1' and invno = '$invnos[$incount]'  and drawing_no='TOTAL' ") or die(mysql_error());
		$prow= mysql_fetch_row($presult);
		$remarks = $prow[0];
		$reference =$prow[1];
		
		
		$temp_order='';
		$orderno='';
		$schedule_no='';
		$poresult = mysql_query("select distinct po_no,po_date,schedule_no,schedule_date from labourinv where account_year='$account_year1' and invno = '$invnos[$incount]'  and drawing_no != 'TOTAL' ") or die(mysql_error());
		while($porow =mysql_fetch_row($poresult))
		{
					$po_date = substr($porow[1],8,2).'-'.substr($porow[1],5,2).'-'.substr($porow[1],0,4);
					$schedule_date = substr($porow[3],8,2).'-'.substr($porow[3],5,2).'-'.substr($porow[3],0,4);
					if($temp_order != $porow[0])
					{				
						$orderno = $orderno.$porow[0].'/'.$po_date.',';
						$temp_order = $porow[0];
					}
					
					$schedule_no = $schedule_no.$porow[2].'/'.$schedule_date.',';
		}
		
		$result= mysql_query("select name,address1,address2,city,state,pin,cst,tin,taxtype,eccno,unit ,vendercode from buy 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];
		$bcst=$row[6];
		$btin=$row[7];
		$btaxtype2=$row[8];
		$eccno= $row[9];
		$vendercode=$row[11];
				

		$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,57);
		fputs($myfile,chr(14));
		strcontrol($myfile,$invnos[$incount],10);
		fputs($myfile,chr(18));		
		fputs($myfile,"\n");
		
		strcontrol($myfile,'',8);		
		strcontrol($myfile,$baddress1,57);		
		fputs($myfile,"\n");
		
		strcontrol($myfile,'',8);		
		strcontrol($myfile,$baddress2,57);
		strcontrol($myfile,'',5);		
		strcontrol($myfile,$date,20);				
		fputs($myfile,"\n");
		
		strcontrol($myfile,'',8);		
		strcontrol($myfile,$bcity,57);		
		strcontrol($myfile,'',16);
		fputs($myfile,"\n");		
			
		fputs($myfile,"");						
		strcontrol($myfile,'',8);		
		strcontrol($myfile,'',57);
		strcontrol($myfile,$orderno,35);		
		fputs($myfile,"\n\n\n");
	
		if(!empty($btin))
		{
			strcontrol($myfile,'',13);
			strcontrol($myfile,'TIN No: ',5);				
			strcontrol($myfile,$btin,50);
			strcontrol($myfile,$remarks,10);		
		}
    	fputs($myfile,"\n");

		if(!empty($bcst))
		{
			strcontrol($myfile,'',13);
			strcontrol($myfile,'CST:',5);				
			strcontrol($myfile,$bcst,50);		
		}
		else
		{
			fputs($myfile,"\n");
		}
		fputs($myfile,"\n\n\n\n\n\n");
		
		$linecnt=$linecnt+15;
		$presult = mysql_query("select  bcode,prodcode from labourinv where account_year='$account_year1' and invno = '$invnos[$incount]'  and drawing_no!='TOTAL' ") or die(mysql_error());
		$prow= mysql_fetch_row($presult);
		$bcode = $prow[0];
		$prodcode =$prow[1];
		
		
		$presult = mysql_query("select  value,round_off,gtotal  from labourinv where account_year='$account_year1' and invno = '$invnos[$incount]'  and drawing_no='TOTAL' ") or die(mysql_error());
		$prow= mysql_fetch_row($presult);
		$invvalue = $prow[0];
		$round_off =$prow[1];
		$gtotal =$prow[2];
				
					
		$result = mysql_query("select distinct drawing_no,bcode,prodcode from labourinv where account_year='$account_year1' and invno = '$invnos[$incount]'  and drawing_no != 'TOTAL' ") or die(mysql_error());
		while($row =mysql_fetch_row($result))
		
		{

			$invresult = mysql_query("select  sum(quantity),avg(rate),sum(value) from labourinv where account_year='$account_year1' and invno = '$invnos[$incount]'  and drawing_no='$row[0]' ") or die(mysql_error());
			$invrow= mysql_fetch_row($invresult);
			$qty = round($invrow[0]);
			$rate = $invrow[1],2;
			$value = $invrow[2];


			$tresult = mysql_query("select prodname from product where product.bcode like  '$row[1]%' and product.prodcode like '$row[2]%'   ") or die(mysql_error());		
			$trow= mysql_fetch_row($tresult);
			$prodname = $trow[0];			
			strcontrol($myfile,'',4);
			strcontrol($myfile,$sno,8);
			strcontrol($myfile,$row[0],20);
			strcontrol($myfile,$prodname,25);
			numcontrol($myfile, number_format($qty,0),8);
			numcontrol($myfile,number_format($rate,2),11);
			numcontrol($myfile,$number_format(value,2),15);
			fputs($myfile,"\n");
			$linecnt++;
			$sno++;
			
		}

	
	    	fputs($myfile,"\n\n\n\n\n\n\n");
		    strcontrol($myfile," ",25);
		    strcontrol($myfile,"(MATERIAL RECEIVED VIDE PARTY'S ",35);
		    fputs($myfile,"\n");


			
	       	strcontrol($myfile," ",27);
		    $sch = 'Challan No :'.$schedule_no.')';
	    	strcontrol($myfile,$sch,12);

	       	fputs($myfile,"\n");		
			$linecnt= $linecnt+9;		
		
		    strcontrol($myfile,"",80);
	    	strcontrol($myfile,'--------',18);
	    	fputs($myfile,"\n");	

		
			strcontrol($myfile,"",73);
			numcontrol($myfile,$invvalue,14);
			fputs($myfile,"\n");
			
			if($round_off>0)
			{
				strcontrol($myfile,'',12);
				strcontrol($myfile,"ADD /LESS:  ROUNDED OFF",67);
				numcontrol($myfile,$round_off,9);
				fputs($myfile,"\n\n\n\n\n");
			}
			elseif($round_off<=0)
		{
			fputs($myfile,"\n");		
		}
		
			strcontrol($myfile," ",25);
			strcontrol($myfile,"REF:",5);			
			strcontrol($myfile,$reference,40);
			fputs($myfile,"\n");	
		
			$linecnt=$linecnt+8;
			

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

	
				strcontrol($myfile,"",77);

				fputs($myfile,"\n\n\n");

					$temp = connum($gtotal).' only';
					strcontrol($myfile,"",10);
					strcontrol($myfile,$temp,67);

					numcontrol($myfile,$gtotal,10);					
					fputs($myfile," \n\n\n\n\n\n");
				

				


				fputs($myfile,chr(12));


}
				

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

					for($ln=1;$ln<=7;$ln++)
					{
						fputs($myfile,"\n");
					}
					$linecnt=1;
//}

$fname='print.txt';
?>
<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,$invno,$date)
{





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


}

?>
