Jump to content

How to Create PHP Print Button?


marcosevaristo

Recommended Posts

Hello I have a problem in my Script and I'm not able to solve it, it's the following: I want to create a button that prints several different receipts, several lunch orders on one page and I want them all to have a print button for printing the receipt below:

#This is the Button#

<button id="botaoPrint" class="btn_1">Imprimir Pedido <i class="icon-print-2" aria-hidden="true"></i></button></a>


#The receipt#

</center>
<div>
<div class="container">
<div style="margin: 0 auto;align-items: center;display: flex;flex-direction: row;flex-wrap: wrap;justify-content: center;" class="row justify-content-center ">
<article class="col-md-4">
<div id="divImprimir" style="background-color: #fdfbe3;" class="boxed-md boxed-padded">
<?php

$dataex = explode(' ', $data);
$dataex[0] = explode('-', $dataex[0]);
$dataex[0] = array_reverse($dataex[0]);
$dataex[0] = implode('/', $dataex[0]);

$dataformatada = $dataex[0].' - '.$dataex[1];

$nome = str_replace('%20', ' ', $nome);
$nomeCliente = $nome;
$telefoneformatado = formatPhone($telefone);

$taxaPedido = Check::Real($valor_taxa);
$valorTroco = Check::Real($valor_troco);
$totalPedido = Check::Real($total);

$resumoPedidosFormatado = str_replace('*', '', $resumo_pedidos);
$resumoPedidosFormatado = str_replace('<b>', '', $resumoPedidosFormatado);
$resumoPedidosFormatado = str_replace('</b>', '', $resumoPedidosFormatado);

$telefoneEmpresaFormatado = formatPhone($telefone_empresa);

echo "<b>".$nome_empresa."</b>";
echo ".\n <br />";

echo (!empty($end_rua_n_empresa) && !empty($end_bairro_empresa) && !empty($cidade_empresa) && !empty($end_uf_empresa) ? $end_rua_n_empresa.' <br /> '.$end_bairro_empresa : 'Defina_um_endereço').' - '.$cidade_empresa.' - '.$end_uf_empresa;
echo "\n <br />";
echo "Telefone: {$telefoneEmpresaFormatado}";


echo "\n <br />";
echo "\n <br />";

echo "<b>PEDIDO: #{$codigo_pedido}</b>\n <br />";
echo "{$dataformatada} <br />";
echo "\n <br />";
echo "-----------------------------"."\n <br />";
if($opcao_delivery != 'true'):
echo "{$msg_delivery_false}\n <br />";
echo "Observações: {$name_observacao_mesa}\n <br />";
else:
echo "Rua: {$rua}, Nº {$unidade}\n <br />";
echo "Bairro: {$bairro}\n <br />";
echo "Cidade: {$cidade} - {$uf}\n <br />";
echo "Complemento: {$complemento}\n <br />";
echo "Observação: {$observacao}\n <br />";
endif;
echo "-----------------------------"."\n <br />";
echo "\n <br />";


echo "DADOS DO CLIENTE: <br />";

echo "NOME: {$nomeCliente}\n <br />";
echo "TEL: {$telefoneformatado}\n <br />";

echo "-----------------------------"."\n <br />";
echo "\n <br />";

echo "RESUMO DO PEDIDO: <br />";
echo "{$resumoPedidosFormatado}";

echo "-----------------------------"."\n <br />";

echo "PAGAMENTO: {$forma_pagamento}\n <br />";
echo (!empty($sub_total) || $sub_total != '0.00' ? "SUBTOTAL: R$ ".Check::Real($sub_total)." \n <br />" : "" );
if(!empty($desconto) && $desconto != 0):
echo "DESCONTO: {$desconto}% \n <br />";
endif;
if($valor_taxa != '0.00'):
echo "DELIVERY: R$ {$taxaPedido}\n <br />";
endif;
echo "TOTAL: R$ {$totalPedido} \n <br />";
if(!empty($valor_troco) && $valor_troco != '0.00'):
echo "TROCO PARA: R$ {$valorTroco}\n <br />";
endif;
echo "-----------------------------"." \n <br />";

echo "\n <br />";

echo "***OBRIGADO E BOM APETITE*** \n <br />";
?>
</div>
</article>
</div>
</div>
</div>
<center>


-----------------------------------------------------------------
*COMMAND TO PRINT*
 

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#botaoPrint2').click(function(){
$('#divImprimir').printThis({
doctypeString: '<meta charset="utf-8">',
importStyle: true,
base: false,
});
});
});
</script>

 

Edited by Barand
code tags added
Link to comment
Share on other sites

 

this is the code that prints, i fixed it is *botaoprint* 

what should i do to fix this bug please help me!!

<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#botaoPrint').click(function(){ $('#divImprimir').printThis({ doctypeString: '<meta charset="utf-8">', importStyle: true, base: false, }); }); }); </script>

 

 

Link to comment
Share on other sites

Do not use an ID to identify the buttons. Find another solution. Consider learning more about HTML while you're at it.

Hint: the best solution is something that you're already using elsewhere in the markup.

Oh. And please don't solicit help through PMs.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.