<?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_clientes where numrec = $numrec";
$tabla = mysql_query($consulta1);
$cdgcli=mysql_result($tabla,0,"cdgcli");
$dsccli=mysql_result($tabla,0,"dsccli");
$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 web_0301 where cdgcli= $cdgcli";
$tabla3 = mysql_query($consulta3);
$saldo_cliente=mysql_result($tabla3,0,"salact");
	
?>
		



<?


$ip = $_SERVER['REMOTE_ADDR'] ;


  
  
if ($ip=="127.0.0.1"){

$puerto="LPT1";


  }    

if(($handle = @fopen($puerto, "w")) === FALSE){
		echo exec('Impresoras');
		echo exec('Impresoras2');
        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,"    Cliente: " . $cdgcli ."-".$dsccli);
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_clientes_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
fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(33). chr(0));//ESTACIO ENTRE LETRAS
$monto=number_format($pagcon,2,".",",");
$pagado=sprintf("%13s",$monto) ;
fwrite($handle,"Monto Recibido: ");
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,"Su Cambio:  ");
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,"    --------------------------------------------");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(33). chr(8));//ESTACIO ENTRE LETRAS
$saldo_cli=number_format($saldo_cliente,2,".",",");
$saldo_cliente=sprintf("%13s",$saldo_cli) ;
fwrite($handle,"Nuevo Saldo:   ");
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(5));//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,"     Firma y sello del cajero"  );
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"     Gracias Por Su Pago"  );
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 $puerto'); //lpr->puerto impresora, imprimir archivo PRN

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

 