📁 File Manager
Editing:
/home/wvl7mof7402e/www/remindyourdata.live/emply/add_expense.php
<?php session_start(); include "dbconnect.php"; // Database connection if ($_SERVER['REQUEST_METHOD'] == 'POST') { $category = $_POST['expense_category']; $amount = $_POST['amount']; $date = $_POST['date']; $description = $_POST['description']; $invoice_no = isset($_POST['invoice_no']) ? $_POST['invoice_no'] : null; $vendor_name = isset($_POST['vendor_name']) ? $_POST['vendor_name'] : null; // Insert query with optional invoice_no, vendor_name fields (adjust your DB schema accordingly) $sql = "INSERT INTO expenses (expense_category, amount, date, description, invoice_no, vendor_name) VALUES (?, ?, ?, ?, ?, ?)"; if ($stmt = $con->prepare($sql)) { $stmt->bind_param("sdssss", $category, $amount, $date, $description, $invoice_no, $vendor_name); if ($stmt->execute()) { $_SESSION['message'] = "Expense added successfully!"; } else { $_SESSION['error'] = "Error adding expense."; } $stmt->close(); } else { $_SESSION['error'] = "Database error."; } header("Location: expenses_page.php"); exit(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Add Expense</title> <!-- Bootstrap 5 CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #6a11cb, #2575fc); min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 60px 20px; color: #333; } .container { background: #fff; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); padding: 40px 35px; max-width: 480px; width: 100%; } h3 { color: #2575fc; font-weight: 700; margin-bottom: 30px; text-align: center; letter-spacing: 1.2px; } label { font-weight: 600; color: #444; } .form-control { border-radius: 8px; padding: 12px 15px; border: 1.8px solid #ddd; transition: border-color 0.3s ease, box-shadow 0.3s ease; font-size: 1rem; } .form-control:focus { border-color: #2575fc; box-shadow: 0 0 8px rgba(37, 117, 252, 0.4); outline: none; } .btn-primary { background-color: #2575fc; border: none; font-weight: 700; padding: 14px 0; border-radius: 50px; font-size: 1.1rem; transition: background-color 0.3s ease; } .btn-primary:hover { background-color: #1b54d3; } .alert { text-align: center; font-size: 1.1em; border-radius: 8px; } .logout-btn { position: fixed; top: 20px; right: 20px; background-color: #e03e3e; color: white; padding: 10px 22px; border-radius: 30px; text-decoration: none; font-weight: 600; box-shadow: 0 4px 15px rgba(224, 62, 62, 0.6); transition: background-color 0.3s ease; display: flex; align-items: center; gap: 8px; } .logout-btn:hover { background-color: #b72e2e; } .form-group { margin-bottom: 22px; } /* Extra fields container */ #office-extra-fields { margin-top: 15px; background: #f0f6ff; border-radius: 8px; padding: 15px 20px; border: 1.5px solid #2575fc; } #office-extra-fields label { color: #1a3da8; } </style> </head> <body> <a href="logout.php" class="logout-btn" aria-label="Logout"> <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-box-arrow-right" viewBox="0 0 16 16"> <path fill-rule="evenodd" d="M10 12a.5.5 0 0 1 0 1H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5a.5.5 0 0 1 0 1H5a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h5z"/> <path fill-rule="evenodd" d="M15.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L14.293 7.5H6.5a.5.5 0 0 0 0 1h7.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z"/> </svg> Logout </a> <div class="container" role="main" aria-labelledby="formTitle"> <h3 id="formTitle">Add New Expense</h3> <?php if (isset($_SESSION['message'])): ?> <div class="alert alert-success" role="alert"><?= $_SESSION['message']; unset($_SESSION['message']); ?></div> <?php endif; ?> <?php if (isset($_SESSION['error'])): ?> <div class="alert alert-danger" role="alert"><?= $_SESSION['error']; unset($_SESSION['error']); ?></div> <?php endif; ?> <form method="POST" action="add_expense.php" novalidate> <div class="form-group"> <label for="expense_category">Expense Category</label> <select class="form-control" id="expense_category" name="expense_category" required aria-required="true"> <option value="">Select Category</option> <option value="office_rent">Office Rent</option> <option value="employee_salaries">Employee Salaries</option> <option value="utilities">Utilities</option> <option value="office_supplies">Office Supplies</option> <option value="software_subscriptions">Software/Subscriptions</option> <option value="miscellaneous">Miscellaneous</option> <option value="other">Other</option> </select> </div> <!-- Extra office fields (hidden by default) --> <div id="office-extra-fields" style="display:none;"> <div class="form-group"> <label for="invoice_no">Invoice Number</label> <input type="text" class="form-control" id="invoice_no" name="invoice_no" placeholder="Enter invoice number"> </div> <div class="form-group"> <label for="vendor_name">Vendor Name</label> <input type="text" class="form-control" id="vendor_name" name="vendor_name" placeholder="Enter vendor name"> </div> </div> <div class="form-group"> <label for="amount">Amount (₹)</label> <input type="number" class="form-control" id="amount" name="amount" min="0" step="0.01" required aria-required="true" placeholder="Enter amount"> </div> <div class="form-group"> <label for="date">Date</label> <input type="date" class="form-control" id="date" name="date" required aria-required="true"> </div> <div class="form-group"> <label for="description">Description</label> <textarea class="form-control" id="description" name="description" rows="3" required aria-required="true" placeholder="Brief description"></textarea> </div> <button type="submit" class="btn btn-primary w-100 mt-3" aria-label="Submit Expense"> Submit Expense </button> </form> </div> <!-- Bootstrap 5 JS Bundle --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> // Show extra fields when Office-related category is selected document.getElementById('expense_category').addEventListener('change', function() { const extraFields = document.getElementById('office-extra-fields'); if (this.value === 'office_rent' || this.value === 'office_supplies') { extraFields.style.display = 'block'; // Make fields required document.getElementById('invoice_no').required = true; document.getElementById('vendor_name').required = true; } else { extraFields.style.display = 'none'; // Remove required attribute document.getElementById('invoice_no').required = false; document.getElementById('vendor_name').required = false; } }); </script> </body> </html>
Save
Cancel