<?php
session_start();

 $usu=$_SESSION['username'];
 

$tipo_usu=$_SESSION['tipo_usu'];


 
  date_default_timezone_set('America/Costa_Rica');

 

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


   
    $consulta = "SELECT * FROM web_0000 ";
	$resultado = $mysqli->query($consulta);
	$fila = $resultado->fetch_array();

         $nomcom = $fila["NOMCOM"];
	     $razsoc = $fila["RAZSOC"];
		 $cedjur = $fila["CEDJUR"];
		 $diremp = $fila["DIREMP"];
		 $numtel_empresa = $fila["NUMTEL"];
		 $numofi = $fila["numofi"];
		 $menfac = $fila["menfac"];
         $intmor = $fila["INTMOR"];
		 $tipimp = $fila["TIPIMP"];
		 $ter001 = $fila["TER001"];
		 $ter002 = $fila["TER002"];
		 $ter003 = $fila["TER003"];
		 $reb_imp_ser     =  $fila["reb_imp_ser"];
 
  $numcie=$_GET["numcie"];
  
$consulta = "SELECT * FROM cierres WHERE numcie='$numcie'";
$resultado = $mysqli->query($consulta);
$fila = $resultado->fetch_array();

		$monsis = $fila["monsis"];
		$mondig = $fila["mondig"];
		$monefe = $fila["monefe"];
		$moncks = $fila["monsin"];
		$monvou = $fila["monvou"];
		$mondol = $fila["mondol"];
		$monval = $fila["monval"];
		$monotr = $fila["monotr"];
		$mondif = $fila["mondif"];
		$totfac = $fila["totfac"];
		$totcre = $fila["totcre"];
		$totrec = $fila["totrec"];
		$totnotdeb = $fila["totnotdeb"];
		$totnotcre = $fila["totnotcre"];
		$totval = $fila["totval"];
		$totcom = $fila["totcom"];
		$totent = $fila["totent"];
		$totsal = $fila["totsal"];
		$totade = $fila["totade"];
		$total_impser = $fila["totimpser"];
		$cdgcaj = $fila["cdgcaj"];
		$cincuentamil = $fila["cincuentamil"];
		$veintemil    = $fila["veintemil"];
		$diezmil      = $fila["diezmil"];
		$cincomil     = $fila["cincomil"];
		$dosmil       = $fila["dosmil"];
		$mil          = $fila["mil"];
		$quinientos   = $fila["quinientos"];
		$cien         = $fila["cien"];
		$cincuenta    = $fila["cincuenta"];
		$veinticinco  = $fila["veinticinco"];
		$diez         = $fila["diez"];
		$cinco        = $fila["cinco"];
		$tipcamdol    = $fila["tipcamdol"];
		$candol       = $fila["candol"];
		$monapecaj    = $fila["monapecaj"];
		$feccie       = $fila["feccie"];
		$fecfin       = $fila["fecfin"];
        $feccie= implode("-", array_reverse(explode("-", $feccie)));
		$fecfin= implode("-", array_reverse(explode("-", $fecfin)));
		
		$total_digitado=$monefe+$monval+$moncks+$monvou+$mondol;
		//$total_sistema=$totfac+$totrec-$totnotcre + $totnotdeb + $totent +  $totade -  $totsal - $totcom - $totval - $total_impser   ;
		//$total_ventas=$totfac+$totcre;
		
					/***************REBAJO EL IMPUESTO DE SERVICIO************************************/
		if ($reb_imp_ser==1){
		
			$total_ventas=$totfac+$totcre-$total_impser;
			$total_sistema=$totfac+$totrec-$totnotcre + $totnotdeb + $totent +  $totade -  $totsal - $totcom - $totval-$total_impser  ;
		}
		
		else {
			$total_ventas=$totfac+$totcre;
			$total_sistema=$totfac+$totrec-$totnotcre + $totnotdeb + $totent +  $totade -  $totsal - $totcom - $totval  ;
		}

 

 if ($cdgcaj==9999) {
	 
	 $nomcomusu="TODOS LOS CAJEROS";
	 
	     } else {
	 
	 							
		$consulta = "SELECT * FROM usuarios  WHERE codusu=$cdgcaj ";
		$resultado = $mysqli->query($consulta);
		$row = $resultado->fetch_array();
		$nomcomusu = $row["nomcomusu"];
     }
 
 
/////////////////////////////////////////////   direccion de maquina local ////////////////////////////////////////////////////

$ip = $_SERVER["REMOTE_ADDR"];

if ($ip=="127.0.0.1"){

echo $puerto="LPT1";

  } else {
  
echo $puerto="LPT1";


  } 
  


if(($handle = @fopen($puerto, "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
if ($tipimp=="MATRIX"){  //  ************************Si la impresora es TIPO MATRIX ****************************/////////////// 

fwrite($handle,  chr(27). chr(100). chr(0));//salto de linea VACIO
fwrite($handle,  chr(27). chr(100). chr(0));//salto de linea VACIO
fwrite($handle, chr(27). chr(100). chr(0));//salto de linea
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(22));//ESTACIO ENTRE LETRAS

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, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Cierre de Caja ");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, "Del ".$feccie." Al ".$fecfin);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Cajero: ".$cdgcaj."-".$nomcomusu);
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(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
//$factura = str_pad("  N. ".$numfactura, 23);
fwrite($handle, "VALORES DIGITADOS" );
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(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(2));//Derecha
$monefe=number_format($monefe,2,".",",");
$monefe=sprintf("%13s",$monefe) ;
fwrite($handle,"Monto Efectivo     ");
fwrite($handle,$monefe);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monvou=number_format($monvou,2,".",",");
$monvou=sprintf("%13s",$monvou) ;
fwrite($handle,"Monto Vouchers     ");
fwrite($handle,$monvou);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$moncks=number_format($moncks,2,".",",");
$moncks=sprintf("%13s",$moncks) ;
fwrite($handle,"Monto SINPES      ");
fwrite($handle,$moncks);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$mondol=number_format($mondol,2,".",",");
$mondol=sprintf("%13s",$mondol) ;
fwrite($handle,"Monto Dolares      ");
fwrite($handle,$mondol);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monval=number_format($monval,2,".",",");
$monval=sprintf("%13s",$monval) ;
fwrite($handle,"Depositos     ");
fwrite($handle,$monval);


fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monotr=number_format($monotr,2,".",",");
$monotr=sprintf("%13s",$monotr) ;
fwrite($handle,"Otros Valores      ");
fwrite($handle,$monotr); 

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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_digitado=number_format($total_digitado,2,".",",");
$total_digitado=sprintf("%13s",$total_digitado) ;
fwrite($handle,"Total Digitado      ");
fwrite($handle,$total_digitado);


  if ($tipo_usu=="a" ){
  
  
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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "VALORES DEL SISTEMA" );


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totfac=number_format($totfac,2,".",",");
$totfac=sprintf("%13s",$totfac) ;
fwrite($handle,"Ventas Contado     ");
fwrite($handle,$totfac);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totrec=number_format($totrec,2,".",",");
$totrec=sprintf("%13s",$totrec) ;
fwrite($handle,"Recibos de Pago    ");
fwrite($handle,$totrec);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totent=number_format($totent,2,".",",");
$totent=sprintf("%13s",$totent) ;
fwrite($handle,"Ent. Efectivo (+)  ");
fwrite($handle,$totent);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totval=number_format($totval,2,".",",");
$totval=sprintf("%13s",$totval) ;
fwrite($handle,"Vales Func. (-)    ");
fwrite($handle,$totval);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totcom=number_format($totcom,2,".",",");
$totcom=sprintf("%13s",$totcom) ;
fwrite($handle,"Compras Cont. (-)  ");
fwrite($handle,$totcom);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totsal=number_format($totsal,2,".",",");
$totsal=sprintf("%13s",$totsal) ;
fwrite($handle,"Sal. Efectivo(-)   ");
fwrite($handle,$totsal);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totade=number_format($totade,2,".",",");
$totade=sprintf("%13s",$totade) ;
fwrite($handle,"Rec. Adelanto(+)   ");
fwrite($handle,$totade);



fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totnotcre=number_format($totnotcre,2,".",",");
$totnotcre=sprintf("%13s",$totnotcre) ;
fwrite($handle,"NC Credito (-)     ");
fwrite($handle,$totnotcre);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totnotdeb=number_format($totnotdeb,2,".",",");
$totnotdeb=sprintf("%13s",$totnotdeb) ;
fwrite($handle,"NC Debito  (+)     ");
fwrite($handle,$totnotdeb);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_impser=number_format($total_impser,2,".",",");
$total_impser=sprintf("%13s",$total_impser) ;
fwrite($handle,"Imp. Servicio (-)  ");
fwrite($handle,$total_impser);


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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_sistema=number_format($total_sistema,2,".",",");
$total_sistema=sprintf("%13s",$total_sistema) ;
fwrite($handle,"Total Sistema      ");
fwrite($handle,$total_sistema);

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "DIFERENCIA" );


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$monapecaj=number_format($monapecaj,2,".",",");
$monapecaj=sprintf("%13s",$monapecaj) ;
fwrite($handle,"Apertura Caja      ");
fwrite($handle,$monapecaj);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$total_sistema=sprintf("%13s",$total_sistema) ;
fwrite($handle,"Total Sistema      ");
fwrite($handle,$total_sistema);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$total_digitado=sprintf("%13s",$total_digitado) ;
fwrite($handle,"Total Digitado     ");
fwrite($handle,$total_digitado);


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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$mondif=number_format($mondif,2,".",",");
$mondif=sprintf("%13s",$mondif) ;
fwrite($handle,"Diferencia         ");
fwrite($handle,$mondif);

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "VENTAS TOTALES" );


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$totfac=sprintf("%13s",$totfac) ;
fwrite($handle,"Ventas Contado     ");
fwrite($handle,$totfac);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totcre=number_format($totcre,2,".",",");
$totcre=sprintf("%13s",$totcre) ;
fwrite($handle,"Ventas Credito     ");
fwrite($handle,$totcre);


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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_ventas=number_format($total_ventas,2,".",",");
$total_ventas=sprintf("%13s",$total_ventas) ;
fwrite($handle,"Total Ventas       ");
fwrite($handle,$total_ventas);


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(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,$nomcomusu);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Firma");

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(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

}      //**********************************  Cierra tipo de impresora matrix ****************************************//


if ($tipimp=="TERMICA"){  //  ************************Si la impresora es TIPO TERMICA ****************************///////////////

//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, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Cierre de Caja ");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, "Del ".$feccie." Al ".$fecfin);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Cajero: ".$cdgcaj."-".$nomcomusu);
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(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
//$factura = str_pad("  N. ".$numfactura, 23);
fwrite($handle, "VALORES DIGITADOS" );
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(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(2));//Derecha
$monefe=number_format($monefe,2,".",",");
$monefe=sprintf("%13s",$monefe) ;
fwrite($handle,"Monto Efectivo                 ");
fwrite($handle,$monefe);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monvou=number_format($monvou,2,".",",");
$monvou=sprintf("%13s",$monvou) ;
fwrite($handle,"Monto Vouchers                 ");
fwrite($handle,$monvou);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$moncks=number_format($moncks,2,".",",");
$moncks=sprintf("%13s",$moncks) ;
fwrite($handle,"Monto SINPES                  ");
fwrite($handle,$moncks);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$mondol=number_format($mondol,2,".",",");
$mondol=sprintf("%13s",$mondol) ;
fwrite($handle,"Monto Dolares                  ");
fwrite($handle,$mondol);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monval=number_format($monval,2,".",",");
$monval=sprintf("%13s",$monval) ;
fwrite($handle,"Depositos                  ");
fwrite($handle,$monval);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monotr=number_format($monotr,2,".",",");
$monotr=sprintf("%13s",$monotr) ;
fwrite($handle,"Otros Valores                  ");
fwrite($handle,$monotr);

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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_digitado=number_format($total_digitado,2,".",",");
$total_digitado=sprintf("%13s",$total_digitado) ;
fwrite($handle,"Total Digitado                 ");
fwrite($handle,$total_digitado);

  if ($tipo_usu=="a" ){

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "VALORES DEL SISTEMA" );




fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totfac=number_format($totfac,2,".",",");
$totfac=sprintf("%13s",$totfac) ;
fwrite($handle,"Ventas Contado                 ");
fwrite($handle,$totfac);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totrec=number_format($totrec,2,".",",");
$totrec=sprintf("%13s",$totrec) ;
fwrite($handle,"Recibos de Pago                ");
fwrite($handle,$totrec);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totent=number_format($totent,2,".",",");
$totent=sprintf("%13s",$totent) ;
fwrite($handle,"Entradas de Efectivo (+)       ");
fwrite($handle,$totent);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totval=number_format($totval,2,".",",");
$totval=sprintf("%13s",$totval) ;
fwrite($handle,"Vales a Funcionarios (-)       ");
fwrite($handle,$totval);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totcom=number_format($totcom,2,".",",");
$totcom=sprintf("%13s",$totcom) ;
fwrite($handle,"Compras de Contado (-)         ");
fwrite($handle,$totcom);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totsal=number_format($totsal,2,".",",");
$totsal=sprintf("%13s",$totsal) ;
fwrite($handle,"Salidas de Efectivo (-)        ");
fwrite($handle,$totsal);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totade=number_format($totade,2,".",",");
$totade=sprintf("%13s",$totade) ;
fwrite($handle,"Recibos de Adelanto (+)        ");
fwrite($handle,$totade);



fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totnotcre=number_format($totnotcre,2,".",",");
$totnotcre=sprintf("%13s",$totnotcre) ;
fwrite($handle,"Notas de Credito (-)           ");
fwrite($handle,$totnotcre);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totnotdeb=number_format($totnotdeb,2,".",",");
$totnotdeb=sprintf("%13s",$totnotdeb) ;
fwrite($handle,"Notas de Debito (+)           ");
fwrite($handle,$totnotdeb);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_impser=number_format($total_impser,2,".",",");
$total_impser=sprintf("%13s",$total_impser) ;
fwrite($handle,"Imp. Servicio   (+)           ");
fwrite($handle,$total_impser);

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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_sistema=number_format($total_sistema,2,".",",");
$total_sistema=sprintf("%13s",$total_sistema) ;
fwrite($handle,"Total Sistema                  ");
fwrite($handle,$total_sistema);

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "DIFERENCIA" );


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$monapecaj=number_format($monapecaj,2,".",",");
$monapecaj=sprintf("%13s",$monapecaj) ;
fwrite($handle,"Apertura Caja                  ");
fwrite($handle,$monapecaj);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$total_sistema=sprintf("%13s",$total_sistema) ;
fwrite($handle,"Total Sistema                  ");
fwrite($handle,$total_sistema);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$total_digitado=sprintf("%13s",$total_digitado) ;
fwrite($handle,"Total Digitado                 ");
fwrite($handle,$total_digitado);


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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$mondif=number_format($mondif,2,".",",");
$mondif=sprintf("%13s",$mondif) ;
fwrite($handle,"Diferencia                     ");
fwrite($handle,$mondif);

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "VENTAS TOTALES" );


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$totfac=sprintf("%13s",$totfac) ;
fwrite($handle,"Ventas Contado                 ");
fwrite($handle,$totfac);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totcre=number_format($totcre,2,".",",");
$totcre=sprintf("%13s",$totcre) ;
fwrite($handle,"Ventas Credito                 ");
fwrite($handle,$totcre);


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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_ventas=number_format($total_ventas,2,".",",");
$total_ventas=sprintf("%13s",$total_ventas) ;
fwrite($handle,"Total Ventas                   ");
fwrite($handle,$total_ventas);


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(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,$nomcomusu);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Firma");

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

}      //**********************************  Cierra tipo de impresora TERMICA  ****************************************//



if ($tipimp=="BEMANTECH"){  //  ************************Si la impresora es TIPO TERMICA ****************************///////////////

//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, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Cierre de Caja ");
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, "Del ".$feccie." Al ".$fecfin);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Cajero: ".$cdgcaj."-".$nomcomusu);
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(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
//$factura = str_pad("  N. ".$numfactura, 23);
fwrite($handle, "VALORES DIGITADOS" );
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(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(2));//Derecha
$monefe=number_format($monefe,2,".",",");
$monefe=sprintf("%13s",$monefe) ;
fwrite($handle,"Monto Efectivo            ");
fwrite($handle,$monefe);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monvou=number_format($monvou,2,".",",");
$monvou=sprintf("%13s",$monvou) ;
fwrite($handle,"Monto Vouchers            ");
fwrite($handle,$monvou);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$moncks=number_format($moncks,2,".",",");
$moncks=sprintf("%13s",$moncks) ;
fwrite($handle,"Monto SINPES             ");
fwrite($handle,$moncks);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$mondol=number_format($mondol,2,".",",");
$mondol=sprintf("%13s",$mondol) ;
fwrite($handle,"Monto Dolares             ");
fwrite($handle,$mondol);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monval=number_format($monval,2,".",",");
$monval=sprintf("%13s",$monval) ;
fwrite($handle,"Depositos             ");
fwrite($handle,$monval);

fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$monotr=number_format($monotr,2,".",",");
$monotr=sprintf("%13s",$monotr) ;
fwrite($handle,"Otros Valores             ");
fwrite($handle,$monotr);

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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_digitado=number_format($total_digitado,2,".",",");
$total_digitado=sprintf("%13s",$total_digitado) ;
fwrite($handle,"Total Digitado            ");
fwrite($handle,$total_digitado);

  if ($tipo_usu=="a" ){

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "VALORES DEL SISTEMA" );




fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totfac=number_format($totfac,2,".",",");
$totfac=sprintf("%13s",$totfac) ;
fwrite($handle,"Ventas Contado            ");
fwrite($handle,$totfac);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totrec=number_format($totrec,2,".",",");
$totrec=sprintf("%13s",$totrec) ;
fwrite($handle,"Recibos de Pago           ");
fwrite($handle,$totrec);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totent=number_format($totent,2,".",",");
$totent=sprintf("%13s",$totent) ;
fwrite($handle,"Entradas de Efectivo (+)  ");
fwrite($handle,$totent);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totval=number_format($totval,2,".",",");
$totval=sprintf("%13s",$totval) ;
fwrite($handle,"Vales a Funcionarios (-)  ");
fwrite($handle,$totval);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totcom=number_format($totcom,2,".",",");
$totcom=sprintf("%13s",$totcom) ;
fwrite($handle,"Compras de Contado (-)    ");
fwrite($handle,$totcom);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totsal=number_format($totsal,2,".",",");
$totsal=sprintf("%13s",$totsal) ;
fwrite($handle,"Salidas de Efectivo (-)   ");
fwrite($handle,$totsal);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totade=number_format($totade,2,".",",");
$totade=sprintf("%13s",$totade) ;
fwrite($handle,"Recibos de Adelanto (+)   ");
fwrite($handle,$totade);



fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totnotcre=number_format($totnotcre,2,".",",");
$totnotcre=sprintf("%13s",$totnotcre) ;
fwrite($handle,"Notas de Credito (-)      ");
fwrite($handle,$totnotcre);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totnotdeb=number_format($totnotdeb,2,".",",");
$totnotdeb=sprintf("%13s",$totnotdeb) ;
fwrite($handle,"Notas de Debito (+)      ");
fwrite($handle,$totnotdeb);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_impser=number_format($total_impser,2,".",",");
$total_impser=sprintf("%13s",$total_impser) ;
fwrite($handle,"Imp. Servicio   (+)      ");
fwrite($handle,$total_impser);

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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_sistema=number_format($total_sistema,2,".",",");
$total_sistema=sprintf("%13s",$total_sistema) ;
fwrite($handle,"Total Sistema             ");
fwrite($handle,$total_sistema);

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "DIFERENCIA" );


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$monapecaj=number_format($monapecaj,2,".",",");
$monapecaj=sprintf("%13s",$monapecaj) ;
fwrite($handle,"Apertura Caja             ");
fwrite($handle,$monapecaj);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$total_sistema=sprintf("%13s",$total_sistema) ;
fwrite($handle,"Total Sistema             ");
fwrite($handle,$total_sistema);


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$total_digitado=sprintf("%13s",$total_digitado) ;
fwrite($handle,"Total Digitado            ");
fwrite($handle,$total_digitado);


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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$mondif=number_format($mondif,2,".",",");
$mondif=sprintf("%13s",$mondif) ;
fwrite($handle,"Diferencia                ");
fwrite($handle,$mondif);

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(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(97). chr(1));//centrado
fwrite($handle, "VENTAS TOTALES" );


fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea

$totfac=sprintf("%13s",$totfac) ;
fwrite($handle,"Ventas Contado            ");
fwrite($handle,$totfac);

fwrite($handle, chr(27). chr(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$totcre=number_format($totcre,2,".",",");
$totcre=sprintf("%13s",$totcre) ;
fwrite($handle,"Ventas Credito            ");
fwrite($handle,$totcre);


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(97). chr(2));//Derecha
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
$total_ventas=number_format($total_ventas,2,".",",");
$total_ventas=sprintf("%13s",$total_ventas) ;
fwrite($handle,"Total Ventas              ");
fwrite($handle,$total_ventas);


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(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,$nomcomusu);
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle,"Firma");

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(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
fwrite($handle, chr(27). chr(109). chr(0));//salto de linea
fwrite($handle, chr(29). chr(27). chr(105));//Corta el Papel

}      //**********************************  Cierra tipo de impresora BEMANTECH  ****************************************//

		
fclose($handle); // cierra el fichero PRN
$salida = shell_exec('lpr $puerto'); //lpr->puerto impresora, imprimir archivo PRN
//echo system('imprimir_LPT1');
echo "<script languaje='javascript' type='text/javascript'>window.close();</script>";

?>

