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/store_expenses.php
<?php
include 'protect.php';
include 'db.php';
require_once __DIR__ . '/brand_header.php';
require_once __DIR__ . '/store_expense_helpers.php';

$rawMonth = date('Y-m');
if (isset($_GET['month']) && $_GET['month'] !== '') {
    $rawMonth = $_GET['month'];
} elseif (isset($_POST['month']) && $_POST['month'] !== '') {
    $rawMonth = $_POST['month'];
}
$selectedMonth = normalizeExpenseMonth((string) $rawMonth);
$message = '';
$error = '';
$expenses = array();
$monthlyTotal = 0.0;
$totalsByAccount = array();

function h($value)
{
    return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = isset($_POST['action']) ? trim((string) $_POST['action']) : '';

    try {
        if ($action === 'add_expense') {
            addStoreExpense(
                $conn,
                isset($_POST['expense_date']) ? (string) $_POST['expense_date'] : '',
                isset($_POST['entry_type']) ? (string) $_POST['entry_type'] : 'Store Use',
                isset($_POST['qbo_account']) ? (string) $_POST['qbo_account'] : '',
                isset($_POST['item_description']) ? (string) $_POST['item_description'] : '',
                isset($_POST['quantity']) ? (string) $_POST['quantity'] : '',
                isset($_POST['unit_price']) ? (string) $_POST['unit_price'] : '',
                isset($_POST['notes']) ? (string) $_POST['notes'] : ''
            );
            $message = 'Store expense saved.';
        } elseif ($action === 'delete_expense') {
            deleteStoreExpense($conn, isset($_POST['expense_id']) ? (int) $_POST['expense_id'] : 0);
            $message = 'Store expense deleted.';
        }
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
}

try {
    ensureStoreExpensesTable($conn);
    $expenses = fetchStoreExpensesByMonth($conn, $selectedMonth);
    $monthlyTotal = storeExpenseMonthlyTotal($expenses);
    $totalsByAccount = storeExpenseTotalsByAccount($expenses);
} catch (Exception $e) {
    $error = $e->getMessage();
}

$months = [];
for ($i = 0; $i < 24; $i++) {
    $months[] = date('Y-m', strtotime("-{$i} months"));
}

if (!empty($_GET['export']) && $_GET['export'] === 'qbo') {
    $csv = exportStoreExpensesQboCsv($expenses);
    if (isset($_SESSION['store_name']) && $_SESSION['store_name'] !== '') {
        $exportStoreName = $_SESSION['store_name'];
    } elseif (isset($_SESSION['store_db']) && $_SESSION['store_db'] !== '') {
        $exportStoreName = $_SESSION['store_db'];
    } else {
        $exportStoreName = 'HouseTabPro';
    }
    $filename = storeExpenseExportFilename((string) $exportStoreName, $selectedMonth);

    header('Content-Type: text/csv; charset=UTF-8');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    echo $csv;
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Store Expenses</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 30px;
            background: #f8fafc;
            color: #1f2937;
        }

        .container {
            max-width: 1100px;
            margin: 0 auto;
            background: #fff;
            padding: 28px;
            border-radius: 16px;
            box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
        }

        .toolbar {
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            gap: 16px;
            flex-wrap: wrap;
            margin-bottom: 16px;
        }

        .toolbar form {
            display: flex;
            gap: 12px;
            align-items: flex-end;
            flex-wrap: wrap;
        }

        .toolbar label {
            margin-bottom: 4px;
            font-size: 0.92rem;
        }

        label {
            display: block;
            font-weight: 700;
            margin-bottom: 6px;
            color: #475569;
        }

        input, select, textarea {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #cbd5e1;
            border-radius: 10px;
            font: inherit;
            box-sizing: border-box;
        }

        textarea {
            min-height: 88px;
            resize: vertical;
        }

        .btn {
            display: inline-block;
            padding: 11px 16px;
            background: #1d4ed8;
            color: #fff;
            text-decoration: none;
            border: none;
            border-radius: 10px;
            font-weight: 700;
            cursor: pointer;
            line-height: 1.1;
        }

        .toolbar .btn {
            padding: 9px 13px;
            font-size: 0.92rem;
        }

        .toolbar select {
            padding: 8px 10px;
            font-size: 0.94rem;
        }

        .btn-secondary {
            background: #64748b;
        }

        .btn-danger {
            background: #b91c1c;
        }

        .grid {
            display: grid;
            grid-template-columns: 1.1fr 0.9fr;
            gap: 22px;
            margin-bottom: 24px;
        }

        .card {
            background: #f8fafc;
            border: 1px solid #e5e7eb;
            border-radius: 16px;
            padding: 20px;
        }

        .card h2 {
            margin-top: 0;
        }

        .form-grid {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 16px;
        }

        .form-grid .full {
            grid-column: 1 / -1;
        }

        .entry-grid {
            display: grid;
            grid-template-columns: 1.1fr 0.7fr 0.8fr;
            gap: 16px;
            margin-top: 8px;
        }

        .summary-total {
            font-size: 32px;
            font-weight: 800;
            color: #0f172a;
        }

        .title-line {
            display: flex;
            align-items: baseline;
            gap: 12px;
            flex-wrap: wrap;
        }

        .title-note {
            color: #64748b;
            font-size: 0.95rem;
        }

        .msg {
            margin-bottom: 16px;
            padding: 12px 14px;
            border-radius: 10px;
        }

        .msg.ok {
            background: #ecfdf5;
            border: 1px solid #86efac;
            color: #166534;
            transition: opacity 0.8s ease, transform 0.8s ease;
        }

        .msg.fade-out {
            opacity: 0;
            transform: translateY(-4px);
        }

        .msg.err {
            background: #fef2f2;
            border: 1px solid #fca5a5;
            color: #991b1b;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }

        th, td {
            text-align: left;
            padding: 10px 8px;
            border-bottom: 1px solid #e5e7eb;
            vertical-align: top;
        }

        th {
            background: #eff6ff;
            white-space: nowrap;
        }

        .muted {
            color: #64748b;
            font-size: 0.92rem;
        }

        .empty {
            padding: 18px 0;
            color: #64748b;
        }

        .entry-row {
            cursor: pointer;
        }

        .entry-row:hover {
            background: #f8fafc;
        }

        .entry-link {
            color: #1d4ed8;
            font-weight: 700;
            text-decoration: none;
        }

        @media (max-width: 900px) {
            .grid {
                grid-template-columns: 1fr;
            }

            .form-grid {
                grid-template-columns: 1fr;
            }

            .entry-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
    <?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
    <?php renderAppBrandHeader(); ?>

    <div class="toolbar">
        <div>
            <div class="title-line">
                <h1 style="margin:0;">Store Expenses</h1>
                <div class="title-note">Track monthly supplies, maintenance, toilet paper, cleaning items, and other store-use purchases.</div>
            </div>
        </div>

        <form method="get">
            <div>
                <label for="month">Month</label>
                <select id="month" name="month">
                    <?php foreach ($months as $month): ?>
                        <option value="<?php echo h($month); ?>" <?php echo $selectedMonth === $month ? 'selected' : ''; ?>>
                            <?php echo h(date('F Y', strtotime($month . '-01'))); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div>
                <button class="btn btn-secondary" type="submit">View Month</button>
            </div>
            <div>
                <a class="btn" href="store_expenses.php?month=<?php echo h(urlencode($selectedMonth)); ?>&export=qbo">Export QBO CSV</a>
            </div>
            <div>
                <a class="btn btn-secondary" href="index.php">Back to Dashboard</a>
            </div>
        </form>
    </div>

    <?php if ($error !== ''): ?>
        <div class="msg err"><?php echo h($error); ?></div>
    <?php endif; ?>

    <div class="grid">
        <div class="card">
            <h2>Add Expense</h2>
            <form method="post">
                <input type="hidden" name="action" value="add_expense">
                <input type="hidden" name="month" value="<?php echo h($selectedMonth); ?>">

                <div class="form-grid">
                    <div>
                        <label for="expense_date">Expense Date</label>
                        <input id="expense_date" name="expense_date" type="date" value="<?php echo h(date('Y-m-d')); ?>" required>
                    </div>
                    <div>
                        <label for="qbo_account">QBO Account / Category</label>
                        <input id="qbo_account" name="qbo_account" type="text" placeholder="Supplies, Repairs & Maintenance, Office Supplies..." required>
                    </div>
                    <div class="full">
                        <label for="entry_type">Write-Off Type</label>
                        <select id="entry_type" name="entry_type">
                            <?php foreach (storeExpenseEntryTypeOptions() as $entryTypeOption): ?>
                                <option value="<?php echo h($entryTypeOption); ?>"><?php echo h($entryTypeOption); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="full">
                        <label for="item_description">Item Description</label>
                        <input id="item_description" name="item_description" type="text" placeholder="Cleaning supplies, toilet paper, repair parts..." required>
                    </div>
                    <div class="entry-grid full">
                        <div>
                            <label for="quantity">Quantity</label>
                            <input id="quantity" name="quantity" type="number" step="0.01" min="0.01" value="1.00" required>
                        </div>
                        <div>
                            <label for="unit_price">Price</label>
                            <input id="unit_price" name="unit_price" type="number" step="0.01" min="0.00" placeholder="0.00" required>
                        </div>
                        <div style="display:flex;align-items:flex-end;">
                            <div class="muted" style="padding-bottom:10px;">Total is calculated automatically in the monthly list and export.</div>
                        </div>
                    </div>
                    <div class="full">
                        <label for="notes">Notes</label>
                        <textarea id="notes" name="notes" placeholder="Optional note for yourself or for the QBO memo field"></textarea>
                    </div>
                </div>

                <div style="margin-top:18px;">
                    <button class="btn" type="submit">Save Expense</button>
                </div>
            </form>
        </div>

        <div class="card">
            <h2><?php echo h(date('F Y', strtotime($selectedMonth . '-01'))); ?> Summary</h2>
            <?php if ($message !== ''): ?>
                <div id="expense-save-message" class="msg ok" style="margin-top:0;"><?php echo h($message); ?></div>
            <?php endif; ?>
            <div class="summary-total">$<?php echo h(number_format($monthlyTotal, 2)); ?></div>
            <div class="muted" style="margin-top:8px;">Monthly total for store operating expenses entered here.</div>

            <h3 style="margin:24px 0 12px;">Totals by QBO Account</h3>
            <?php if (!$totalsByAccount): ?>
                <div class="empty">No expenses entered for this month yet.</div>
            <?php else: ?>
                <table>
                    <thead>
                        <tr>
                            <th>QBO Account</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($totalsByAccount as $account => $total): ?>
                        <tr>
                            <td><?php echo h($account); ?></td>
                            <td>$<?php echo h(number_format($total, 2)); ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div>
    </div>

    <div class="card">
        <h2 style="margin-top:0;"><?php echo h(date('F Y', strtotime($selectedMonth . '-01'))); ?> Entries</h2>
        <div class="muted" style="margin-bottom:10px;">
            The QBO export from this page includes the write-off type, account, description, quantity, price, and amount. Your QBO account/category names should match what exists in your QuickBooks company.
        </div>

        <?php if (!$expenses): ?>
            <div class="empty">No store expenses have been entered for this month.</div>
        <?php else: ?>
            <table>
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Type</th>
                        <th>Account</th>
                        <th>Description</th>
                        <th>Qty</th>
                        <th>Price</th>
                        <th>Total</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                <?php foreach ($expenses as $expense): ?>
                    <tr class="entry-row" onclick="window.location.href='store_expense_detail.php?expense_id=<?php echo h((string) $expense['id']); ?>&month=<?php echo h(urlencode($selectedMonth)); ?>';">
                        <td><?php echo h($expense['expense_date']); ?></td>
                        <td><?php echo h(isset($expense['entry_type']) ? $expense['entry_type'] : 'Store Use'); ?></td>
                        <td><?php echo h($expense['qbo_account']); ?></td>
                        <td>
                            <a class="entry-link" href="store_expense_detail.php?expense_id=<?php echo h((string) $expense['id']); ?>&month=<?php echo h(urlencode($selectedMonth)); ?>" onclick="event.stopPropagation();">
                                <?php echo h($expense['item_description']); ?>
                            </a>
                            <?php if (!empty($expense['notes'])): ?>
                                <div class="muted" style="margin-top:4px;"><?php echo h($expense['notes']); ?></div>
                            <?php endif; ?>
                        </td>
                        <td><?php echo h(number_format((float) $expense['quantity'], 2)); ?></td>
                        <td>$<?php echo h(number_format((float) $expense['unit_price'], 2)); ?></td>
                        <td>$<?php echo h(number_format((float) (isset($expense['line_total']) ? $expense['line_total'] : 0), 2)); ?></td>
                        <td>
                            <a class="btn btn-secondary" href="store_expense_detail.php?expense_id=<?php echo h((string) $expense['id']); ?>&month=<?php echo h(urlencode($selectedMonth)); ?>" onclick="event.stopPropagation();" style="padding:8px 11px;font-size:0.9rem;">Edit</a>
                            <form method="post" onsubmit="return confirm('Delete this store expense entry?');" style="margin-top:8px;">
                                <input type="hidden" name="action" value="delete_expense">
                                <input type="hidden" name="month" value="<?php echo h($selectedMonth); ?>">
                                <input type="hidden" name="expense_id" value="<?php echo h((string) $expense['id']); ?>">
                                <button class="btn btn-danger" type="submit" onclick="event.stopPropagation();" style="padding:8px 11px;font-size:0.9rem;">Delete</button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        <?php endif; ?>
    </div>
</div>
<script>
var expenseSaveMessage = document.getElementById('expense-save-message');
if (expenseSaveMessage) {
    window.setTimeout(function () {
        expenseSaveMessage.className += ' fade-out';
        window.setTimeout(function () {
            if (expenseSaveMessage && expenseSaveMessage.parentNode) {
                expenseSaveMessage.parentNode.removeChild(expenseSaveMessage);
            }
        }, 900);
    }, 10000);
}
</script>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit