File "printpos.php"
Full path: /home/atrmarke/public_html/atrdemolive.site/hardware/log/printpos.php
File
size: 0.01 KB (8.52 KB bytes)
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
include("../db/cn.php");
ob_start();
// Fetch order details from the database
$orderId = isset($_GET['order_id']) ? mysqli_real_escape_string($connection, $_GET['order_id']) : null;
$orderDetails = [];
$outletName = $loginUser = $userRole = $outletAddress = $dateTime = $totalAmount = $paidBy = $customerName = $customerPhone = $discountedAmount = $discounted = $discountPer = $cashAmount = $changeAmount = $taxAmount = null;
if ($orderId) {
$query = "SELECT * FROM log_user_sales WHERE order_id = '$orderId'";
$result = mysqli_query($connection, $query);
if ($result && mysqli_num_rows($result) > 0) {
$orderDetails = mysqli_fetch_all($result, MYSQLI_ASSOC);
$order = $orderDetails[0];
$outletName = $order['outlet_name'];
$loginUser = $order['login_user'];
$userRole = $order['user_role'];
$outletAddress = $order['outlet_address'];
$dateTime = $order['date_time'];
$totalAmount = $order['net_amount'];
$paidBy = $order['paid_by'];
$customerName = $order['customer_name'];
$customerPhone = $order['customer_phone'];
$discountedAmount = $order['discount_amount'];
$discounted = $order['discounted'];
$discountPer = $order['discount_per'];
$cashAmount = $order['cash_amount'];
$changeAmount = $order['change_amount'];
$taxAmount = $order['tax_amount'];
$Area = $order['area'];
$piece = $order['piece'];
$labour_amount = $order['labour_amount'];
$date_time = $order['date_time'];
}
}
// ESC/POS Commands
$initialize = "\x1B\x40"; // Initialize printer
$lineFeed = "\x0A"; // Line feed
$cutPaper = "\x1D\x56\x42\x00"; // Cut paper
// Prepare the print content with ESC/POS commands
$content = $initialize;
$content .= "Jabbar Glass House & Aluminium Works\n";
$content .= "Camp Chowk, Jaswant Nagar Road Khanewal\n";
$content .= "Cell: 0313-0609793\n";
$content .= "Cell: 0304-0719793\n";
$content .= "Order ID: " . htmlspecialchars($orderId) . "\n";
$content .= "--------------------------------\n";
$content .= "Customer: " . htmlspecialchars($customerName) . "\n";
$content .= "Phone: " . htmlspecialchars($customerPhone) . "\n";
$content .= "Payment: " . htmlspecialchars($paidBy) . "\n";
$content .= "--------------------------------\n";
$content .= "Product Qty Price Amount\n";
$content .= "--------------------------------\n";
// Adding each product detail
foreach ($orderDetails as $order) {
$productName = htmlspecialchars($order['product_name']);
$productQty = htmlspecialchars($order['product_quantity']);
$productPrice = htmlspecialchars($order['product_price']);
$productTotal = $productQty * $productPrice;
// Make sure to format to fit the receipt width, if necessary truncate the product name
$content .= sprintf("%-10s %4s %7s %7s\n", substr($productName, 0, 10), $productQty, $productPrice, $productTotal);
}
$content .= "--------------------------------\n";
$content .= "Sub Total: " . htmlspecialchars($totalAmount) . "\n";
$content .= "Discount: " . htmlspecialchars($discounted) . "\n";
$content .= "Total: " . htmlspecialchars($totalAmount - $discounted) . "\n";
$content .= "Cash: " . htmlspecialchars($cashAmount) . "\n";
$content .= "Change: " . htmlspecialchars($changeAmount) . "\n";
$content .= "--------------------------------\n";
$content .= "Thank you for your purchase!\n";
$content .= $lineFeed;
// Send multiple cut commands to increase the cut action
$cutPaperMultiple = str_repeat($cutPaper, 3); // Adjust the number to increase the cuts
$content .= $cutPaperMultiple;
// Function to send data to the printer
function sendToPrinter($printer_ip, $data) {
$port = 9100; // Standard port for most network thermal printers
// Open a socket connection to the printer
$fp = fsockopen($printer_ip, $port, $errno, $errstr, 5);
if (!$fp) {
echo "";
return;
}
// Send the data to the printer
fwrite($fp, $data);
fclose($fp);
}
// Replace with your printer's IP address
$printer_ip = '192.168.1.100';
// Send the data to the printer
sendToPrinter($printer_ip, $content);
ob_end_flush();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Print Order</title>
<style>
@media print {
body {
width: 80mm;
margin: 0;
padding: 0;
}
.container {
width: 100%;
margin: 0;
padding: 0;
}
.no-print{
display:none;
}
.text-center {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #000;
padding: 5px;
text-align: center;
}
.mb-0, .mb-1 {
margin-bottom: 5px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="text-center">
<img src="img/print_logo.png" width="66" height="66" alt="Logo" class="logo">
<h2>Al Hafeez Shopping Mall , LHR</h2>
<p class="mb-0"></p>
<p class="mb-0">Cell: 0313-0609793</p>
<p class="mb-0">Cell: 0304-0719793</p>
<p class="mb-0">Order ID: <?php echo htmlspecialchars($orderId); ?></p>
</div>
<div>
<p><strong>Name:</strong> <?php echo htmlspecialchars($customerName); ?></p>
<p><strong>Phone:</strong> <?php echo htmlspecialchars($customerPhone); ?></p>
<p><strong>Payment:</strong> <?php echo htmlspecialchars($paidBy); ?></p>
</div>
<div>
<table>
<thead>
<tr>
<th>Product</th>
<th>Outline</th>
<th>Area</th>
<th>Piece</th>
<th>Qty</th>
<th>Price</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php foreach ($orderDetails as $order): ?>
<tr>
<td><?php echo htmlspecialchars($order['product_name']); ?></td>
<td>
<?php
if (!empty($order['l_feet']) && !empty($order['w_feet'])) {
echo htmlspecialchars($order['l_feet']) . ' x ' . htmlspecialchars($order['w_feet']) . ' feet';
} elseif (!empty($order['l_inch']) && !empty($order['w_inch'])) {
echo htmlspecialchars($order['l_inch']) . ' x ' . htmlspecialchars($order['w_inch']) . ' inches';
}
?>
</td>
<td><?php echo htmlspecialchars($order['area']); ?></td>
<td><?php echo htmlspecialchars($order['piece']); ?></td>
<td><?php echo htmlspecialchars($order['product_quantity']); ?></td>
<td><?php echo htmlspecialchars($order['product_price']); ?></td>
<td><?php echo htmlspecialchars($order['product_quantity'] * $order['product_price']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
$sub = mysqli_query($connection,"select SUM(net_amount) AS sub from log_user_sales where order_id = '$orderId'");
$rowSub = mysqli_fetch_array($sub);
?>
<div>
<p><strong>Sub:</strong> Rs <?php echo htmlspecialchars($rowSub["sub"]); ?> /-</p>
<p><strong>Labour:</strong> Rs <?php echo htmlspecialchars($labour_amount); ?> /-</p>
<p><strong>Disc:</strong> Rs <?php echo htmlspecialchars($discounted); ?> /-</p>
<p><strong>Total:</strong> Rs <?php echo htmlspecialchars($discountedAmount) . ".00"; ?> /-</p>
<p><strong>Cash:</strong> Rs <?php echo htmlspecialchars($cashAmount) . ".00"; ?> /-</p>
<p><strong>Change:</strong> Rs <?php echo htmlspecialchars($changeAmount); ?> /-</p>
</div>
<div>
<p>Generated By: Admin</p>
<p>Date: <?php echo $date_time; ?> </p>
</div>
<div>
<h6>Notes:</h6>
<p>1. Items will be returned with cash memo within 7 days.</p>
<p>2. Without sign and stamp, the bill will not be valid.</p>
</div>
<div class="text-center no-print">
<button class="no-print" onclick="window.print()">Print Invoice</button>
<button class="no-print" onclick="window.location.href='mainpos.php'">Exit</button>
</div>
</div>
</body>
</html>
<?php
?>