Imprimir diretamente Impressora USB Termica
estou desenvolvendo um sistema de cupons Em PHP/MYSQL e vai ser impressos esses cupons em uma impressora termica USB. o meu problema é que para impressão estou usando onload"windows.print()" mais aparece uma caixa de impressão isso então possibilita a impressão de 2 cupons ou a pessoa cancelar.. assim cancelando não tem a opção de imprimir novamente e vai gerar alguns transtornos
preciso então mandar uma impressao diretamente para impressora ..
vou postar aaixo o codigo da pagina do cupom
<?php require_once('Connections/conect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
mysql_select_db($database_conect, $conect);
$query_Recordset1 = "SELECT * FROM produtos";
$Recordset1 = mysql_query($query_Recordset1, $conect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$colname_vendas = "-1";
if (isset($_GET['numero_venda'])) {
$colname_vendas = $_GET['numero_venda'];
}
mysql_select_db($database_conect, $conect);
$query_vendas = sprintf("SELECT * FROM vendas WHERE id = %s", GetSQLValueString($colname_vendas, "int"));
$vendas = mysql_query($query_vendas, $conect) or die(mysql_error());
$row_vendas = mysql_fetch_assoc($vendas);
$totalRows_vendas = mysql_num_rows($vendas);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sem título</title>
<link href="cupom.css" rel="stylesheet" type="text/css" />
</head>
<body onload="self.print();">
<div id="box_cupom">
<strong class="titulo_cupom">BARRACA DO MORANGO</strong><br />
<img src="imagens/MORANGO.png" width="206" height="195" /> <br />
<span class="text1">Cupom Numero: <?php echo $row_vendas['id']; ?></span><br />
<span class="text1">Data e Hora: <?php echo $row_vendas['datahora']; ?></span><br />
<?php
mysql_select_db($database_conect, $conect);
$query_produtos_vendidos = "SELECT * FROM produtos_vendidos WHERE id_compra =".$row_vendas['id']."";
$produtos_vendidos = mysql_query($query_produtos_vendidos, $conect) or die(mysql_error());
$row_produtos_vendidos = mysql_fetch_assoc($produtos_vendidos);
$totalRows_produtos_vendidos = mysql_num_rows($produtos_vendidos);
?>
</p>
<table width="200" border="0">
<tr>
<td> </td>
<td>Produto</td>
<td>Preço</td>
</tr>
<?php do { ?>
<tr>
<td class="quantidadeproduto"><?php echo $row_produtos_vendidos['quantidade_produto']; ?></td>
<td class="quantidadeproduto"><?php echo $row_produtos_vendidos['nome_produto']; ?></td>
<td class="quantidadeproduto"><?php echo $row_produtos_vendidos['valor_produto']; ?></td>
</tr><?php } while ($row_produtos_vendidos = mysql_fetch_assoc($produtos_vendidos)); ?>
</table>
<span class="valorcupom">R$</span> <span class="valorcupom"><?php echo $row_vendas['valor']; ?></span>
<center><img src="imagens/qrcode.png" width="113" height="91" /></center></div>
<div class='quebrapagina'></div>
<?php
$impresso = "s";
$id_venda = $row_vendas['id'];
$updateSQL = sprintf("UPDATE vendas SET impresso=%s WHERE id=%s",
GetSQLValueString($impresso, "text"),
GetSQLValueString($id_venda, "int"));
mysql_select_db($database_conect, $conect);
$Result1 = mysql_query($updateSQL, $conect) or die(mysql_error());
?>
<script language="javascript">
setTimeout( 'fechar(); ',5000); //fecha a janela em 5 segundos
function fechar(){
if ( navigator.appName.match("Microsoft") )
{
window.open("", "_parent");
window.opener = "";
}
window.close();
}
</script>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($produtos_vendidos);
mysql_free_result($vendas);
?>Discussão (3)
Carregando comentários...