<?php
 /**

 */

 

include ("../conectar.php");

echo $numrec=$_GET["numrec"];
echo $horaactual = date("h:i:s A");

 $query_parametros="SELECT * FROM web_0000 ";
	 $rs_query_parametros=mysql_query($query_parametros);

   $nomcom= mysql_result($rs_query_parametros,0,"nomcom");
   $razsoc= mysql_result($rs_query_parametros,0,"razsoc");
   $cedjur= mysql_result($rs_query_parametros,0,"cedjur");
   $diremp= mysql_result($rs_query_parametros,0,"diremp");
   $numtel_empresa= mysql_result($rs_query_parametros,0,"numtel");
   $numofi= mysql_result($rs_query_parametros,0,"numofi");
   $diains= mysql_result($rs_query_parametros,0,"diains");


		
		$consulta1 = "Select * from pagos_proveedores where numrec = $numrec";
		$tabla = mysql_query($consulta1);
		$cdgpro=mysql_result($tabla,0,"cdgpro");
		$dscpro=mysql_result($tabla,0,"dscpro");
		$numfac=mysql_result($tabla,0,"numfac");
		$pagcon=mysql_result($tabla,0,"pagcon");
		$montot=mysql_result($tabla,0,"montot");
		$vuelto=mysql_result($tabla,0,"vuelto");
		$fecha=mysql_result($tabla,0,"fecrec");
		$fecha= implode("-", array_reverse(explode("-", $fecha)));
		$cdgusu=mysql_result($tabla,0,"cdgcaj");
		$monint=mysql_result($tabla,0,"monint");


  $query_cajero="SELECT * FROM usuarios WHERE codusu='$cdgusu'";
	 $rs_query_cajero=mysql_query($query_cajero);
     $cajero= mysql_result($rs_query_cajero,0,"usu");
 
	
	$consulta3 = "Select * from proveedores where cdgpro= $cdgpro";
	$tabla3 = mysql_query($consulta3);
	$saldo_cliente=mysql_result($tabla3,0,"salact");
	
?>
		



<?


if(($handle = @fopen("LPT1", "w")) === FALSE){
        die('No se puede Imprimir, Verifique la conexion con la IMPRESORA'); // Revisa la conexion con la impresora
    }
setlocale(LC_TIME, 'spanish');



fwrite($handle,chr(27). chr(64));//reinicio


//Salida: viernes 24 de febrero del 2012


fwrite($handle, chr(27). chr(112). chr(48));//ABRIR EL CAJON
fwrite($handle, chr(27). chr(32). chr(1));//ESTACIO ENTRE 
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, chr(27). chr(33). chr(56));//ESTACIO ENTRE LETRAS
//fwrite($handle, chr(27). chr(72). chr(5));//Color Rojo

fwrite($handle, "  ".$nomcom);

fwrite($handle, chr(27). chr(32). chr(0));//ESTACIO ENTRE LETRAS
fwrite($handle, chr(27). chr(33). chr(0));//ESTACIO ENTRE LETRAS
//fwrite($handle, chr(27) +"3"+ chr(17));//interlienaso
//fwrite($handle, chr(27). chr(72). chr(0));//Color Rojo
fwrite($handle, chr(27). chr(3). chr(17));//salto de linea VACIO
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
//fwrite($handle, chr(27). chr(33). chr(9));//Tamaño letra 10 
fwrite($handle,  "    ".$razsoc);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"    Cedula : ". $cedjur);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,  "    ".$diremp);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"    Tel. ".$numtel_empresa);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//CENTRADO
fwrite($handle,"    --------------------------------------------");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, chr(27). chr(33). chr(8));//ESTACIO ENTRE LETRAS
fwrite($handle, "     RECIBO DE PAGO "."       N. ".$numrec );

fwrite($handle, chr(27). chr(33). chr(0));//ESTACIO ENTRE LETRAS
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(32). chr(0));//ESTACIO ENTRE LETRAS *revisar *******
fwrite($handle, chr(27). chr(97). chr(0));//izquierda
$CAJERO = str_pad("    Cajero: " .$cajero ,27);
fwrite($handle,"    Fecha: ". $fecha."                ".$horaactual);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(0));//izquierda
fwrite($handle, chr(27). chr(33). chr(8));//ESTACIO ENTRE LETRAS
  $dsccli = substr($dsccli." ", 0,30);
fwrite($handle,"    Proveedor: " . $cdgpro ."-".$dscpro);
fwrite($handle, chr(27). chr(33). chr(0));//ESTACIO ENTRE LETRAS
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(0));//izquierda
fwrite($handle, $CAJERO);
fwrite($handle, $vencimiento);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//CENTRADO
fwrite($handle,"    --------------------------------------------");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(0));//Izquierda
fwrite($handle,"    Factura". "      Monto Aplicado"."            Saldo");
fwrite($handle, chr(27). chr(97). chr(1));//CENTRADO
fwrite($handle,"    --------------------------------------------");
fwrite($handle, chr(27). chr(32). chr(0));//ESTACIO ENTRE LETRAS *************
fwrite($handle, chr(27). chr(97). chr(0));//IzquierdERRORERR21++a
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(2));//Derecha


$sel_lineas="SELECT * FROM pagos_proveedores_recibos_lineas WHERE numrec='$numrec' ORDER BY numlinea ASC";
$rs_lineas=mysql_query($sel_lineas);
for ($i = 0; $i < mysql_num_rows($rs_lineas); $i++) {
	 $numlinea=mysql_result($rs_lineas,$i,"numlinea");
	 $salfac=mysql_result($rs_lineas,$i,"salfac");
	 $numfac=mysql_result($rs_lineas,$i,"numfac");
	 $monabo=mysql_result($rs_lineas,$i,"monabo");
	 $totfac=mysql_result($rs_lineas,$i,"totfac");
	 $monint=mysql_result($rs_lineas,$i,"monint");
	 $intfac=mysql_result($rs_lineas,$i,"intfac");
	
	
$resultado=number_format($salfac,2,".",",");
$saldo_factura=sprintf("%18s",$resultado) ;

 
$pago=number_format($monabo,2,".",",");
 $abono = sprintf("%18s",$pago) ;
   
fwrite($handle, chr(27). chr(97). chr(2));//derecha		
fwrite($handle, $numfac ." ".$abono."".$saldo_factura);		
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea								 
fwrite($handle, chr(27). chr(97). chr(1));//centrado

}

fwrite($handle, chr(27). chr(97). chr(1));//CENTRADO
fwrite($handle,"    --------------------------------------------");
fwrite($handle, chr(27). chr(33). chr(24));//ESTACIO ENTRE LETRAS
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(2));//Derecha
$total_recibo=number_format($montot,2,".",",");
$total_pago=sprintf("%13s",$total_recibo) ;
fwrite($handle,"    TOTAL:  ");
fwrite($handle,$total_pago);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
//
//$monto=number_format($pagcon,2,".",",");
//$pagado=sprintf("%13s",$monto) ;
//fwrite($handle,"Paga con:  ");
//fwrite($handle,$pagado);
//fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
//$cambio=number_format($vuelto,2,".",",");
//$saldo=sprintf("%13s",$cambio) ;
//fwrite($handle,"Vuelto:  ");
//fwrite($handle,$saldo);
//fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, chr(27). chr(33). chr(0));//ESTACIO ENTRE LETRAS
fwrite($handle,"----------------------------------------");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(2));//Derecha
$saldo_cli=number_format($saldo_cliente,2,".",",");
$saldo_cliente=sprintf("%13s",$saldo_cli) ;
fwrite($handle,"Saldo Total:   ");
fwrite($handle,$saldo_cliente);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(33). chr(0));//ESTACIO ENTRE LETRAS
fwrite($handle, chr(27). chr(97). chr(1));//CENTRADO
fwrite($handle,"    --------------------------------------------");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(29). chr(86). chr(49));//Corta el Papel



		
fclose($handle); // cierra el fichero PRN
$salida = shell_exec('lpr LPT1'); //lpr->puerto impresora, imprimir archivo PRN

echo "<script languaje='javascript' type='text/javascript'>window.close();</script>";
?>

 