skip to Main Content

I have a coffee program made with jquery and HTML that is now working perfectly.

I just want to skip the need to press the print button after pressing placing order. After clicking place order I would like it to just print 2 copies.

The current code for the printing process:

 alert_toast("Data successfully saved.",'success')
      setTimeout(function(){
           var nw = window.open('../receipt.php?id='+resp,"_blank","width=900,height=600")
           setTimeout(function(){
                 nw.print()
                 setTimeout(function(){
                     nw.close()
                     location.reload()
                 },500)
            },500)
       },500)

Code for Receipt.php

<?php 
include 'db_connect.php';
$order = $conn->query("SELECT * FROM orders where id = {$_GET['id']}");
foreach($order->fetch_array() as $k => $v){
$$k= $v;
}
$items = $conn->query("SELECT o.*,p.name FROM order_items o inner join products p on p.id = o.product_id where o.order_id = $id ");
?>

<style>
.flex{
    display: inline-flex;
    width: 100%;
}
.w-50{
    width: 50%;
}
.text-center{
    text-align:center;
}
.text-right{
    text-align:right;
}
table.wborder{
    width: 100%;
    border-collapse: collapse;
}
table.wborder>tbody>tr, table.wborder>tbody>tr>td{
    border:1px solid;
}
p{
    margin:unset;
}

</style>
<div class="container-fluid">
<p class="text-center"><b><?php echo $amount_tendered > 0 ? 
"Receipt" : "Bill" ?></b></p>
<hr>
<div class="flex">
    <div class="w-100">
        <?php if($amount_tendered > 0): ?>
        <p><b>Cafe 365 - Thank you for your Order!</b></p>
    <?php endif; ?>
        <p><b><?php $now = new DateTime();
 echo $now->format('Y-m-d H:i:s');
?></b></p>
    </div>
</div>
<hr>
<p><b>Order List</b></p>
<table width="100%">
    <thead>
        <tr>
            <td><b>QTY</b></td>
            <td><b>Order</b></td>
            <td class="text-right"><b>Amount</b></td>
        </tr>
    </thead>
    <tbody>
        <?php 
        while($row = $items->fetch_assoc()):
        ?>
        <tr>
            <td><?php echo $row['qty'] ?></td>
            <td><p><?php echo $row['name'] ?></p><?php 
if($row['qty'] > 0): ?><small>(R<?php echo 
number_format($row['price'],2) ?>)</small> <?php endif; ?></td>
            <td class="text-right">R<?php echo 
number_format($row['amount'],2) ?></td>
        </tr>
        <?php endwhile; ?>
    </tbody>
</table>
<hr>
<table width="100%">
    <tbody>
        <tr>
            <td><b>Total Amount</b></td>
            <td class="text-right"><b>R<?php echo 
number_format($total_amount,2) ?></b></td>
        </tr>
        <?php if($amount_tendered > 0): ?>


    
    <?php endif; ?>
        
    </tbody>
</table>
<hr>

</div>

I am not sure how to change this. Still learning

2

Answers


  1. Chosen as BEST ANSWER

    I was able to fix it by enabling Kiosk mode on chrome

    editing the chrome shortcut on the machine and adding --kiosk --kiosk-printing after the chrome.exe"

    it now prints immediately


  2. First part of your codes seems to be in another page and after placing the order, you are opening a new window to show the receipt. correct? If you want to print the receipt then you need to write the printing code inside the receipt.php not in the current file. So inside the receipt.php you can run the print on page load:

    <body onload="window.print()">
    

    Footnote: your receipt.php file is missing the body tag. If you dont want to use body tag for a reason, you can also initiate the print on page load like this:

    <script>
    window.onload = function() { window.print(); }
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search