LittleDemon WebShell


Linux premium274.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
Path : /home/whagcoha/mos.mwagalwaservices.com/
File Upload :
Command :
Current File : /home/whagcoha/mos.mwagalwaservices.com/invoicegen.php

<?php
require_once 'dbconfig/db.php';

$bid = isset($_GET['bid']) ? intval($_GET['bid']) : 0;

if ($bid <= 0) {
    die("Invalid request");
}

// ================= FETCH CLIENT =================
$stmt = $conn->prepare("
    SELECT site.sitename,
           CONCAT(client.firstname,' ',client.lastname) AS cname,
           client.contact, client.email
    FROM site
    JOIN client ON site.clientid = client.id
    WHERE site.id = ?
");
$stmt->bind_param("i", $bid);
$stmt->execute();
$client = $stmt->get_result()->fetch_assoc();

if (!$client) {
    die("Invoice not found");
}

// ================= FETCH ITEMS =================
$stmt = $conn->prepare("
    SELECT items.description, items.units, items.unitprice,
           iquantity.quantity,
           (items.unitprice * iquantity.quantity) AS total
    FROM iquantity
    JOIN items ON iquantity.itemid = items.id
    WHERE iquantity.siteid = ?
");
$stmt->bind_param("i", $bid);
$stmt->execute();
$items = $stmt->get_result();

// ================= TOTALS =================
$stmt = $conn->prepare("
    SELECT 
        COALESCE(SUM(items.unitprice * iquantity.quantity),0) AS subtotal,
        COALESCE(ROUND(SUM(items.unitprice * iquantity.quantity) * (labour.rate/100)),0) AS labour,
        COALESCE(ROUND(SUM(items.unitprice * iquantity.quantity) +
        (SUM(items.unitprice * iquantity.quantity) * (labour.rate/100))),0) AS total
    FROM iquantity
    JOIN items ON iquantity.itemid = items.id
    LEFT JOIN labour ON labour.siteid = iquantity.siteid
    WHERE iquantity.siteid = ?
");
$stmt->bind_param("i", $bid);
$stmt->execute();
$totals = $stmt->get_result()->fetch_assoc();

$date = date("d M Y");
$invoiceNo = "INV-" . str_pad($bid, 5, "0", STR_PAD_LEFT);
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Invoice</title>
<link href="css/bootstrap.min.css" rel="stylesheet">

<style>
body { font-size:14px; }
.invoice-box { padding:30px; }
.table td, .table th { vertical-align: middle; }

/* Hide UI elements when printing */
@media print {
    .no-print {
        display: none !important;
    }
}
</style>
</head>

<body>

<!-- ACTION BUTTONS -->
<div class="p-3 no-print">
    <button class="btn btn-primary btn-sm" onclick="window.print()">
        Print
    </button>

    <a href="index.php" class="btn btn-secondary btn-sm">
        Back
    </a>
</div>

<div class="container invoice-box">

    <!-- LOGO -->
    <div class="text-center mb-3">
        <img src="images/quote.png" class="img-fluid" style="max-height:80px;">
    </div>

    <h2 class="text-center">INVOICE</h2>
    <hr>

    <!-- CLIENT INFO -->
    <div class="row">
        <div class="col-md-6">
            <strong>Bill To:</strong><br>
            <?php echo htmlspecialchars($client['cname']); ?><br>
            <?php echo htmlspecialchars($client['contact']); ?><br>
            <?php echo htmlspecialchars($client['email']); ?>
        </div>

        <div class="col-md-6 text-end">
            <strong>Invoice No:</strong> <?php echo $invoiceNo; ?><br>
            <strong>Date:</strong> <?php echo $date; ?><br>
            <strong>Site:</strong> <?php echo htmlspecialchars($client['sitename']); ?>
        </div>
    </div>

    <br>

    <!-- ITEMS TABLE -->
    <table class="table table-bordered">
        <thead class="table-dark">
            <tr>
                <th>#</th>
                <th>Description</th>
                <th class="text-center">Qty</th>
                <th class="text-end">Unit Price</th>
                <th class="text-end">Amount</th>
            </tr>
        </thead>

        <tbody>

        <?php 
        $i = 1;
        if ($items->num_rows > 0):
            while($row = $items->fetch_assoc()):
        ?>
        <tr>
            <td><?php echo $i++; ?></td>
            <td><?php echo htmlspecialchars($row['description']); ?></td>
            <td class="text-center"><?php echo (int)$row['quantity']; ?></td>
            <td class="text-end"><?php echo number_format($row['unitprice']); ?></td>
            <td class="text-end"><?php echo number_format($row['total']); ?></td>
        </tr>
        <?php 
            endwhile;
        else:
        ?>
        <tr>
            <td colspan="5" class="text-center">No items found</td>
        </tr>
        <?php endif; ?>

        </tbody>
    </table>

    <!-- TOTALS -->
    <div class="row">
        <div class="col-md-6"></div>

        <div class="col-md-6">
            <table class="table">
                <tr>
                    <th>Subtotal:</th>
                    <td class="text-end"><?php echo number_format($totals['subtotal']); ?></td>
                </tr>
                <tr>
                    <th>Labour:</th>
                    <td class="text-end"><?php echo number_format($totals['labour']); ?></td>
                </tr>
                <tr>
                    <th>Total:</th>
                    <td class="text-end">
                        <strong><?php echo number_format($totals['total']); ?></strong>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <br>

    <!-- NOTES -->
    <p>
        <strong>Notes:</strong><br>
        Thank you for your business.
    </p>

</div>

</body>
</html>

LittleDemon - FACEBOOK
[ KELUAR ]