Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da0815949e |
55
assets/css/custom.css
Normal file
55
assets/css/custom.css
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* Login Page Styles */
|
||||||
|
body.login-page {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-container {
|
||||||
|
margin-top: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dashboard Styles */
|
||||||
|
#wrapper {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar-wrapper {
|
||||||
|
min-height: 100vh;
|
||||||
|
margin-left: -15rem;
|
||||||
|
transition: margin .25s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar-wrapper .sidebar-heading {
|
||||||
|
padding: 0.875rem 1.25rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar-wrapper .list-group {
|
||||||
|
width: 15rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#page-content-wrapper {
|
||||||
|
min-width: 100vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.sb-sidenav-toggled #wrapper #sidebar-wrapper {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
#sidebar-wrapper {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#page-content-wrapper {
|
||||||
|
min-width: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.sb-sidenav-toggled #wrapper #sidebar-wrapper {
|
||||||
|
margin-left: -15rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebarToggle {
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
}
|
||||||
227
customer.php
Normal file
227
customer.php
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'includes/auth.php';
|
||||||
|
$active_page = 'customer';
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
// Handle delete request
|
||||||
|
if (isset($_GET['delete_id'])) {
|
||||||
|
$delete_id = $_GET['delete_id'];
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM customers WHERE id = ?");
|
||||||
|
$stmt->execute([$delete_id]);
|
||||||
|
header("Location: customer.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle form submission for adding a new customer
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_customer'])) {
|
||||||
|
$companyName = $_POST['companyName'] ?? '';
|
||||||
|
$contactPerson = $_POST['contactPerson'] ?? '';
|
||||||
|
$email = $_POST['email'] ?? '';
|
||||||
|
$phone = $_POST['phone'] ?? '';
|
||||||
|
|
||||||
|
if (!empty($companyName)) {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO customers (companyName, contactPerson, email, phone) VALUES (?, ?, ?, ?)");
|
||||||
|
$stmt->execute([$companyName, $contactPerson, $email, $phone]);
|
||||||
|
header("Location: customer.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle form submission for updating a customer
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_customer'])) {
|
||||||
|
$id = $_POST['customer_id'];
|
||||||
|
$companyName = $_POST['companyName'] ?? '';
|
||||||
|
$contactPerson = $_POST['contactPerson'] ?? '';
|
||||||
|
$email = $_POST['email'] ?? '';
|
||||||
|
$phone = $_POST['phone'] ?? '';
|
||||||
|
|
||||||
|
if (!empty($id) && !empty($companyName)) {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("UPDATE customers SET companyName = ?, contactPerson = ?, email = ?, phone = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$companyName, $contactPerson, $email, $phone, $id]);
|
||||||
|
header("Location: customer.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all customers
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query("SELECT * FROM customers ORDER BY createdAt DESC");
|
||||||
|
$customers = $stmt->fetchAll();
|
||||||
|
|
||||||
|
include 'includes/header.php';
|
||||||
|
?>
|
||||||
|
<div class="d-flex" id="wrapper">
|
||||||
|
<?php include 'includes/sidebar.php'; ?>
|
||||||
|
<!-- Page content wrapper-->
|
||||||
|
<div id="page-content-wrapper">
|
||||||
|
<!-- Top navigation-->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<button class="btn btn-primary" id="sidebarToggle"><i class="bi bi-list"></i></button>
|
||||||
|
<ul class="navbar-nav ms-auto mt-2 mt-lg-0">
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo htmlspecialchars($_SESSION["username"]); ?></a>
|
||||||
|
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
|
||||||
|
<a class="dropdown-item" href="#!">Profile</a>
|
||||||
|
<a class="dropdown-item" href="#!">Settings</a>
|
||||||
|
<div class="dropdown-divider"></div>
|
||||||
|
<a class="dropdown-item" href="logout.php">Logout</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page content-->
|
||||||
|
<main class="container-fluid p-4">
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Customers</h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addCustomerModal">
|
||||||
|
<i class="bi bi-plus-circle"></i>
|
||||||
|
Add Customer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Company Name</th>
|
||||||
|
<th scope="col">Contact Person</th>
|
||||||
|
<th scope="col">Email</th>
|
||||||
|
<th scope="col">Phone</th>
|
||||||
|
<th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($customers)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="6" class="text-center">No customers found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($customers as $customer): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($customer['id']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($customer['companyName']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($customer['contactPerson']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($customer['email']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($customer['phone']); ?></td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-outline-primary edit-customer-btn"
|
||||||
|
data-id="<?php echo $customer['id']; ?>"
|
||||||
|
data-company-name="<?php echo htmlspecialchars($customer['companyName']); ?>"
|
||||||
|
data-contact-person="<?php echo htmlspecialchars($customer['contactPerson']); ?>"
|
||||||
|
data-email="<?php echo htmlspecialchars($customer['email']); ?>"
|
||||||
|
data-phone="<?php echo htmlspecialchars($customer['phone']); ?>"
|
||||||
|
data-bs-toggle="modal" data-bs-target="#editCustomerModal">
|
||||||
|
<i class="bi bi-pencil-square"></i>
|
||||||
|
</button>
|
||||||
|
<a href="customer.php?delete_id=<?php echo $customer['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this customer?');"><i class="bi bi-trash"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Customer Modal -->
|
||||||
|
<div class="modal fade" id="addCustomerModal" tabindex="-1" aria-labelledby="addCustomerModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addCustomerModalLabel">Add New Customer</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form method="POST" action="customer.php">
|
||||||
|
<input type="hidden" name="add_customer" value="1">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="companyName" class="form-label">Company Name</label>
|
||||||
|
<input type="text" class="form-control" id="companyName" name="companyName" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="contactPerson" class="form-label">Contact Person</label>
|
||||||
|
<input type="text" class="form-control" id="contactPerson" name="contactPerson">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="phone" class="form-label">Phone</label>
|
||||||
|
<input type="tel" class="form-control" id="phone" name="phone">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Customer</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Edit Customer Modal -->
|
||||||
|
<div class="modal fade" id="editCustomerModal" tabindex="-1" aria-labelledby="editCustomerModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="editCustomerModalLabel">Edit Customer</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form method="POST" action="customer.php">
|
||||||
|
<input type="hidden" name="update_customer" value="1">
|
||||||
|
<input type="hidden" name="customer_id" id="edit_customer_id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_companyName" class="form-label">Company Name</label>
|
||||||
|
<input type="text" class="form-control" id="edit_companyName" name="companyName" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_contactPerson" class="form-label">Contact Person</label>
|
||||||
|
<input type="text" class="form-control" id="edit_contactPerson" name="contactPerson">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_email" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="edit_email" name="email">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_phone" class="form-label">Phone</label>
|
||||||
|
<input type="tel" class="form-control" id="edit_phone" name="phone">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
var editCustomerModal = document.getElementById('editCustomerModal');
|
||||||
|
editCustomerModal.addEventListener('show.bs.modal', function (event) {
|
||||||
|
var button = event.relatedTarget;
|
||||||
|
var customerId = button.getAttribute('data-id');
|
||||||
|
var companyName = button.getAttribute('data-company-name');
|
||||||
|
var contactPerson = button.getAttribute('data-contact-person');
|
||||||
|
var email = button.getAttribute('data-email');
|
||||||
|
var phone = button.getAttribute('data-phone');
|
||||||
|
|
||||||
|
var modal = this;
|
||||||
|
modal.querySelector('#edit_customer_id').value = customerId;
|
||||||
|
modal.querySelector('#edit_companyName').value = companyName;
|
||||||
|
modal.querySelector('#edit_contactPerson').value = contactPerson;
|
||||||
|
modal.querySelector('#edit_email').value = email;
|
||||||
|
modal.querySelector('#edit_phone').value = phone;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
90
dashboard.php
Normal file
90
dashboard.php
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'includes/auth.php';
|
||||||
|
$active_page = 'dashboard';
|
||||||
|
include 'includes/header.php';
|
||||||
|
include 'db/config.php';
|
||||||
|
|
||||||
|
// Fetch total customers
|
||||||
|
$customers_query = "SELECT COUNT(*) as total_customers FROM customers";
|
||||||
|
$customers_result = db()->query($customers_query);
|
||||||
|
$total_customers = $customers_result->fetch_assoc()['total_customers'];
|
||||||
|
|
||||||
|
// Fetch total quotations
|
||||||
|
$quotations_query = "SELECT COUNT(*) as total_quotations FROM quotations";
|
||||||
|
$quotations_result = db()->query($quotations_query);
|
||||||
|
$total_quotations = $quotations_result->fetch_assoc()['total_quotations'];
|
||||||
|
|
||||||
|
// Fetch total invoices
|
||||||
|
$invoices_query = "SELECT COUNT(*) as total_invoices FROM invoices";
|
||||||
|
$invoices_result = db()->query($invoices_query);
|
||||||
|
$total_invoices = $invoices_result->fetch_assoc()['total_invoices'];
|
||||||
|
?>
|
||||||
|
<div class="d-flex" id="wrapper">
|
||||||
|
<?php include 'includes/sidebar.php'; ?>
|
||||||
|
<!-- Page content wrapper-->
|
||||||
|
<div id="page-content-wrapper">
|
||||||
|
<!-- Top navigation-->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<button class="btn btn-primary" id="sidebarToggle"><i class="bi bi-list"></i></button>
|
||||||
|
<ul class="navbar-nav ms-auto mt-2 mt-lg-0">
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo htmlspecialchars($_SESSION["username"]); ?></a>
|
||||||
|
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
|
||||||
|
<a class="dropdown-item" href="#!">Profile</a>
|
||||||
|
<a class="dropdown-item" href="#!">Settings</a>
|
||||||
|
<div class="dropdown-divider"></div>
|
||||||
|
<a class="dropdown-item" href="logout.php">Logout</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page content-->
|
||||||
|
<div class="container-fluid p-4">
|
||||||
|
<h1 class="mt-4">Dashboard</h1>
|
||||||
|
<p>Welcome to your accounting dashboard.</p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-3 col-md-6">
|
||||||
|
<div class="card bg-primary text-white mb-4">
|
||||||
|
<div class="card-body">Total Customers</div>
|
||||||
|
<div class="card-footer d-flex align-items-center justify-content-between">
|
||||||
|
<span class="small text-white"><?php echo $total_customers; ?></span>
|
||||||
|
<div class="small text-white"><i class="bi bi-chevron-right"></i></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-3 col-md-6">
|
||||||
|
<div class="card bg-warning text-white mb-4">
|
||||||
|
<div class="card-body">Total Invoices</div>
|
||||||
|
<div class="card-footer d-flex align-items-center justify-content-between">
|
||||||
|
<span class="small text-white"><?php echo $total_invoices; ?></span>
|
||||||
|
<div class="small text-white"><i class="bi bi-chevron-right"></i></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-3 col-md-6">
|
||||||
|
<div class="card bg-success text-white mb-4">
|
||||||
|
<div class="card-body">Quotations Sent</div>
|
||||||
|
<div class="card-footer d-flex align-items-center justify-content-between">
|
||||||
|
<span class="small text-white"><?php echo $total_quotations; ?></span>
|
||||||
|
<div class="small text-white"><i class="bi bi-chevron-right"></i></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-3 col-md-6">
|
||||||
|
<div class="card bg-danger text-white mb-4">
|
||||||
|
<div class="card-body">Overdue Invoices</div>
|
||||||
|
<div class="card-footer d-flex align-items-center justify-content-between">
|
||||||
|
<span class="small text-white">0</span>
|
||||||
|
<div class="small text-white"><i class="bi bi-chevron-right"></i></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
38
db/migrate.php
Normal file
38
db/migrate.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/config.php';
|
||||||
|
|
||||||
|
function run_migrations() {
|
||||||
|
$pdo = db();
|
||||||
|
$migrations_dir = __DIR__ . '/migrations';
|
||||||
|
|
||||||
|
// Ensure migrations table exists
|
||||||
|
$pdo->exec(file_get_contents($migrations_dir . '/000_create_migrations_table.sql'));
|
||||||
|
|
||||||
|
$ran_migrations_stmt = $pdo->query("SELECT migration FROM migrations");
|
||||||
|
$ran_migrations = $ran_migrations_stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
$migration_files = glob($migrations_dir . '/*.sql');
|
||||||
|
sort($migration_files);
|
||||||
|
|
||||||
|
foreach ($migration_files as $file) {
|
||||||
|
$migration_name = basename($file);
|
||||||
|
if ($migration_name === '000_create_migrations_table.sql') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($migration_name, $ran_migrations)) {
|
||||||
|
echo "Running migration: $migration_name...\n";
|
||||||
|
$sql = file_get_contents($file);
|
||||||
|
$pdo->exec($sql);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||||
|
$stmt->execute([$migration_name]);
|
||||||
|
echo "Success.\n";
|
||||||
|
} else {
|
||||||
|
echo "Migration already ran: $migration_name.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run_migrations();
|
||||||
|
|
||||||
5
db/migrations/000_create_migrations_table.sql
Normal file
5
db/migrations/000_create_migrations_table.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `migrations` (
|
||||||
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`migration` VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
`createdAt` DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
11
db/migrations/001_create_users_table.sql
Normal file
11
db/migrations/001_create_users_table.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `users` (
|
||||||
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`username` VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
`email` VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
`password` VARCHAR(255) NOT NULL,
|
||||||
|
`role` ENUM('Admin', 'Finance', 'Sales', 'Manager') NOT NULL,
|
||||||
|
`isActive` BOOLEAN DEFAULT TRUE,
|
||||||
|
`lastLogin` DATETIME,
|
||||||
|
`createdAt` DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`updatedAt` DATETIME ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
16
db/migrations/002_create_customers_table.sql
Normal file
16
db/migrations/002_create_customers_table.sql
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `customers` (
|
||||||
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`companyName` VARCHAR(255) NOT NULL,
|
||||||
|
`contactPerson` VARCHAR(255),
|
||||||
|
`email` VARCHAR(255),
|
||||||
|
`phone` VARCHAR(255),
|
||||||
|
`address` TEXT,
|
||||||
|
`billingAddress` TEXT,
|
||||||
|
`taxId` VARCHAR(255),
|
||||||
|
`paymentTerms` INT DEFAULT 30,
|
||||||
|
`currency` VARCHAR(10) DEFAULT 'USD',
|
||||||
|
`notes` TEXT,
|
||||||
|
`createdBy` INT,
|
||||||
|
`createdAt` DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (`createdBy`) REFERENCES `users`(`id`) ON DELETE SET NULL
|
||||||
|
);
|
||||||
13
db/migrations/003_create_quotations_table.sql
Normal file
13
db/migrations/003_create_quotations_table.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `quotations` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`customer_id` int(11) NOT NULL,
|
||||||
|
`quotation_number` varchar(255) NOT NULL,
|
||||||
|
`quotation_date` date NOT NULL,
|
||||||
|
`total_amount` decimal(10,2) NOT NULL,
|
||||||
|
`status` varchar(50) NOT NULL DEFAULT 'Draft',
|
||||||
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `customer_id` (`customer_id`),
|
||||||
|
CONSTRAINT `quotations_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
12
db/migrations/004_create_invoices_table.sql
Normal file
12
db/migrations/004_create_invoices_table.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `invoices` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`customer_id` int(11) NOT NULL,
|
||||||
|
`invoice_date` date NOT NULL,
|
||||||
|
`due_date` date NOT NULL,
|
||||||
|
`total` decimal(10,2) NOT NULL,
|
||||||
|
`status` varchar(20) NOT NULL DEFAULT 'Draft',
|
||||||
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `customer_id` (`customer_id`),
|
||||||
|
CONSTRAINT `invoices_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
8
includes/auth.php
Normal file
8
includes/auth.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
|
||||||
|
header("location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
4
includes/footer.php
Normal file
4
includes/footer.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
12
includes/header.php
Normal file
12
includes/header.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>K Design Accounting</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="d-flex" id="wrapper">
|
||||||
11
includes/sidebar.php
Normal file
11
includes/sidebar.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="bg-light border-end" id="sidebar-wrapper">
|
||||||
|
<div class="sidebar-heading border-bottom bg-light">K Design Accounting</div>
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
<a class="list-group-item list-group-item-action list-group-item-light p-3 <?php echo ($active_page == 'dashboard') ? 'active' : ''; ?>" href="dashboard.php"><i class="bi bi-grid-fill me-2"></i> Dashboard</a>
|
||||||
|
<a class="list-group-item list-group-item-action list-group-item-light p-3 <?php echo ($active_page == 'quotations') ? 'active' : ''; ?>" href="quotations.php"><i class="bi bi-file-earmark-text-fill me-2"></i> Quotation</a>
|
||||||
|
<a class="list-group-item list-group-item-action list-group-item-light p-3 <?php echo ($active_page == 'invoices') ? 'active' : ''; ?>" href="invoices.php"><i class="bi bi-receipt-cutoff me-2"></i> Invoice</a>
|
||||||
|
<a class="list-group-item list-group-item-action list-group-item-light p-3 <?php echo ($active_page == 'customer') ? 'active' : ''; ?>" href="customer.php"><i class="bi bi-people-fill me-2"></i> Customer</a>
|
||||||
|
<a class="list-group-item list-group-item-action list-group-item-light p-3" href="logout.php"><i class="bi bi-box-arrow-left me-2"></i> Logout</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
151
index.php
151
index.php
@ -1,150 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
require_once 'includes/auth.php';
|
||||||
@ini_set('display_errors', '1');
|
|
||||||
@error_reporting(E_ALL);
|
|
||||||
@date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
header('Location: dashboard.php');
|
||||||
$now = date('Y-m-d H:i:s');
|
exit();
|
||||||
?>
|
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>New Style</title>
|
|
||||||
<?php
|
|
||||||
// Read project preview data from environment
|
|
||||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
|
||||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|
||||||
?>
|
|
||||||
<?php if ($projectDescription): ?>
|
|
||||||
<!-- Meta description -->
|
|
||||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
|
||||||
<!-- Open Graph meta tags -->
|
|
||||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
||||||
<!-- Twitter meta tags -->
|
|
||||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($projectImageUrl): ?>
|
|
||||||
<!-- Open Graph image -->
|
|
||||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
||||||
<!-- Twitter image -->
|
|
||||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
||||||
<?php endif; ?>
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
body::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
@keyframes bg-pan {
|
|
||||||
0% { background-position: 0% 0%; }
|
|
||||||
100% { background-position: 100% 100%; }
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
.card {
|
|
||||||
background: var(--card-bg-color);
|
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
margin: 1.25rem auto 1.25rem;
|
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
from { transform: rotate(0deg); }
|
|
||||||
to { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
.hint {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 3rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1rem;
|
|
||||||
letter-spacing: -1px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: rgba(0,0,0,0.2);
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main>
|
|
||||||
<div class="card">
|
|
||||||
<h1>Analyzing your requirements and generating your website…</h1>
|
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
|
||||||
<span class="sr-only">Loading…</span>
|
|
||||||
</div>
|
|
||||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
|
||||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
|
||||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
<footer>
|
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
297
invoices.php
Normal file
297
invoices.php
Normal file
@ -0,0 +1,297 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'includes/auth.php';
|
||||||
|
$active_page = 'invoices';
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
// Handle delete request
|
||||||
|
if (isset($_GET['delete_id'])) {
|
||||||
|
$delete_id = $_GET['delete_id'];
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM invoices WHERE id = ?");
|
||||||
|
$stmt->execute([$delete_id]);
|
||||||
|
header("Location: invoices.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Add Invoice
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_invoice'])) {
|
||||||
|
$customer_id = $_POST['customer_id'];
|
||||||
|
$invoice_date = $_POST['invoice_date'];
|
||||||
|
$due_date = $_POST['due_date'];
|
||||||
|
$total = $_POST['total'];
|
||||||
|
$status = $_POST['status'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$sql = "INSERT INTO invoices (customer_id, invoice_date, due_date, total, status) VALUES (:customer_id, :invoice_date, :due_date, :total, :status)";
|
||||||
|
$stmt = db()->prepare($sql);
|
||||||
|
$stmt->execute([
|
||||||
|
':customer_id' => $customer_id,
|
||||||
|
':invoice_date' => $invoice_date,
|
||||||
|
':due_date' => $due_date,
|
||||||
|
':total' => $total,
|
||||||
|
':status' => $status
|
||||||
|
]);
|
||||||
|
header("Location: invoices.php");
|
||||||
|
exit();
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error_message = "Error adding invoice: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle form submission for updating an invoice
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_invoice'])) {
|
||||||
|
$id = $_POST['invoice_id'];
|
||||||
|
$customer_id = $_POST['customer_id'];
|
||||||
|
$invoice_date = $_POST['invoice_date'];
|
||||||
|
$due_date = $_POST['due_date'];
|
||||||
|
$total = $_POST['total'];
|
||||||
|
$status = $_POST['status'];
|
||||||
|
|
||||||
|
if (!empty($id)) {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("UPDATE invoices SET customer_id = ?, invoice_date = ?, due_date = ?, total = ?, status = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$customer_id, $invoice_date, $due_date, $total, $status, $id]);
|
||||||
|
header("Location: invoices.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch invoices and customers
|
||||||
|
try {
|
||||||
|
$invoices_stmt = db()->query("SELECT i.*, c.companyName as customer_name FROM invoices i JOIN customers c ON i.customer_id = c.id ORDER BY i.invoice_date DESC");
|
||||||
|
$invoices = $invoices_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$customers_stmt = db()->query("SELECT id, companyName FROM customers ORDER BY companyName ASC");
|
||||||
|
$customers = $customers_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error_message = "Error fetching data: " . $e->getMessage();
|
||||||
|
$invoices = [];
|
||||||
|
$customers = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'includes/header.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex" id="wrapper">
|
||||||
|
<?php include 'includes/sidebar.php'; ?>
|
||||||
|
<!-- Page content wrapper-->
|
||||||
|
<div id="page-content-wrapper">
|
||||||
|
<!-- Top navigation-->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<button class="btn btn-primary" id="sidebarToggle"><i class="bi bi-list"></i></button>
|
||||||
|
<ul class="navbar-nav ms-auto mt-2 mt-lg-0">
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo htmlspecialchars($_SESSION["username"]); ?></a>
|
||||||
|
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
|
||||||
|
<a class="dropdown-item" href="#!">Profile</a>
|
||||||
|
<a class="dropdown-item" href="#!">Settings</a>
|
||||||
|
<div class="dropdown-divider"></div>
|
||||||
|
<a class="dropdown-item" href="logout.php">Logout</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page content-->
|
||||||
|
<main class="container-fluid p-4">
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Invoices</h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addInvoiceModal">
|
||||||
|
<i class="bi bi-plus-circle"></i>
|
||||||
|
Add Invoice
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (isset($error_message)): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Customer</th>
|
||||||
|
<th scope="col">Invoice Date</th>
|
||||||
|
<th scope="col">Due Date</th>
|
||||||
|
<th scope="col">Amount</th>
|
||||||
|
<th scope="col">Status</th>
|
||||||
|
<th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($invoices)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center">No invoices found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($invoices as $invoice): ?>
|
||||||
|
<tr>
|
||||||
|
<td>INV-<?php echo htmlspecialchars($invoice['id']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($invoice['customer_name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($invoice['invoice_date']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($invoice['due_date']); ?></td>
|
||||||
|
<td>$<?php echo htmlspecialchars(number_format($invoice['total'], 2)); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
$status_class = 'bg-secondary';
|
||||||
|
if ($invoice['status'] == 'Paid') {
|
||||||
|
$status_class = 'bg-success';
|
||||||
|
} elseif ($invoice['status'] == 'Pending') {
|
||||||
|
$status_class = 'bg-warning text-dark';
|
||||||
|
} elseif ($invoice['status'] == 'Overdue') {
|
||||||
|
$status_class = 'bg-danger';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<span class="badge <?php echo $status_class; ?>"><?php echo htmlspecialchars($invoice['status']); ?></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-outline-primary edit-invoice-btn"
|
||||||
|
data-id="<?php echo $invoice['id']; ?>"
|
||||||
|
data-customer-id="<?php echo $invoice['customer_id']; ?>"
|
||||||
|
data-invoice-date="<?php echo htmlspecialchars($invoice['invoice_date']); ?>"
|
||||||
|
data-due-date="<?php echo htmlspecialchars($invoice['due_date']); ?>"
|
||||||
|
data-total="<?php echo htmlspecialchars($invoice['total']); ?>"
|
||||||
|
data-status="<?php echo htmlspecialchars($invoice['status']); ?>"
|
||||||
|
data-bs-toggle="modal" data-bs-target="#editInvoiceModal">
|
||||||
|
<i class="bi bi-pencil-square"></i>
|
||||||
|
</button>
|
||||||
|
<a href="invoices.php?delete_id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this invoice?');"><i class="bi bi-trash"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Invoice Modal -->
|
||||||
|
<div class="modal fade" id="addInvoiceModal" tabindex="-1" aria-labelledby="addInvoiceModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addInvoiceModalLabel">Add New Invoice</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form action="invoices.php" method="post">
|
||||||
|
<input type="hidden" name="add_invoice" value="1">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="customer_id" class="form-label">Customer</label>
|
||||||
|
<select class="form-select" id="customer_id" name="customer_id" required>
|
||||||
|
<option value="">Select Customer</option>
|
||||||
|
<?php foreach ($customers as $customer): ?>
|
||||||
|
<option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['companyName']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="invoice_date" class="form-label">Invoice Date</label>
|
||||||
|
<input type="date" class="form-control" id="invoice_date" name="invoice_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="due_date" class="form-label">Due Date</label>
|
||||||
|
<input type="date" class="form-control" id="due_date" name="due_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="total" class="form-label">Total Amount</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="total" name="total" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status" required>
|
||||||
|
<option value="Draft">Draft</option>
|
||||||
|
<option value="Pending">Pending</option>
|
||||||
|
<option value="Paid">Paid</option>
|
||||||
|
<option value="Overdue">Overdue</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Add Invoice</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Edit Invoice Modal -->
|
||||||
|
<div class="modal fade" id="editInvoiceModal" tabindex="-1" aria-labelledby="editInvoiceModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="editInvoiceModalLabel">Edit Invoice</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form method="POST" action="invoices.php">
|
||||||
|
<input type="hidden" name="update_invoice" value="1">
|
||||||
|
<input type="hidden" name="invoice_id" id="edit_invoice_id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_customer_id" class="form-label">Customer</label>
|
||||||
|
<select class="form-select" id="edit_customer_id" name="customer_id" required>
|
||||||
|
<?php foreach ($customers as $customer): ?>
|
||||||
|
<option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['companyName']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_invoice_date" class="form-label">Invoice Date</label>
|
||||||
|
<input type="date" class="form-control" id="edit_invoice_date" name="invoice_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_due_date" class="form-label">Due Date</label>
|
||||||
|
<input type="date" class="form-control" id="edit_due_date" name="due_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_total" class="form-label">Total Amount</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="edit_total" name="total" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="edit_status" name="status" required>
|
||||||
|
<option value="Draft">Draft</option>
|
||||||
|
<option value="Pending">Pending</option>
|
||||||
|
<option value="Paid">Paid</option>
|
||||||
|
<option value="Overdue">Overdue</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
var editInvoiceModal = document.getElementById('editInvoiceModal');
|
||||||
|
editInvoiceModal.addEventListener('show.bs.modal', function (event) {
|
||||||
|
var button = event.relatedTarget;
|
||||||
|
var invoiceId = button.getAttribute('data-id');
|
||||||
|
var customerId = button.getAttribute('data-customer-id');
|
||||||
|
var invoiceDate = button.getAttribute('data-invoice-date');
|
||||||
|
var dueDate = button.getAttribute('data-due-date');
|
||||||
|
var total = button.getAttribute('data-total');
|
||||||
|
var status = button.getAttribute('data-status');
|
||||||
|
|
||||||
|
var modal = this;
|
||||||
|
modal.querySelector('#edit_invoice_id').value = invoiceId;
|
||||||
|
modal.querySelector('#edit_customer_id').value = customerId;
|
||||||
|
modal.querySelector('#edit_invoice_date').value = invoiceDate;
|
||||||
|
modal.querySelector('#edit_due_date').value = dueDate;
|
||||||
|
modal.querySelector('#edit_total').value = total;
|
||||||
|
modal.querySelector('#edit_status').value = status;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
151
login.php
Normal file
151
login.php
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
// Check if the user is already logged in, if so, redirect to dashboard
|
||||||
|
if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) {
|
||||||
|
header("location: dashboard.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
// Check if there are any users in the database, if not, create a default admin user
|
||||||
|
try {
|
||||||
|
$stmt = $pdo->query("SELECT id FROM users LIMIT 1");
|
||||||
|
if ($stmt->rowCount() == 0) {
|
||||||
|
$default_email = "admin@example.com";
|
||||||
|
$default_password = "password";
|
||||||
|
$hashed_password = password_hash($default_password, PASSWORD_DEFAULT);
|
||||||
|
$default_username = "admin";
|
||||||
|
$default_role = "Admin";
|
||||||
|
|
||||||
|
$insert_stmt = $pdo->prepare("INSERT INTO users (username, email, password, role) VALUES (:username, :email, :password, :role)");
|
||||||
|
$insert_stmt->bindParam(':username', $default_username);
|
||||||
|
$insert_stmt->bindParam(':email', $default_email);
|
||||||
|
$insert_stmt->bindParam(':password', $hashed_password);
|
||||||
|
$insert_stmt->bindParam(':role', $default_role);
|
||||||
|
$insert_stmt->execute();
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// Don't expose error details to the user
|
||||||
|
error_log("Error checking/creating default user: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$email = $password = "";
|
||||||
|
$email_err = $password_err = $login_err = "";
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
if (empty(trim($_POST["email"]))) {
|
||||||
|
$email_err = "Please enter email.";
|
||||||
|
} else {
|
||||||
|
$email = trim($_POST["email"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty(trim($_POST["password"]))) {
|
||||||
|
$password_err = "Please enter your password.";
|
||||||
|
} else {
|
||||||
|
$password = trim($_POST["password"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($email_err) && empty($password_err)) {
|
||||||
|
$sql = "SELECT id, username, email, password, role FROM users WHERE email = :email";
|
||||||
|
|
||||||
|
if ($stmt = $pdo->prepare($sql)) {
|
||||||
|
$stmt->bindParam(":email", $param_email, PDO::PARAM_STR);
|
||||||
|
$param_email = $email;
|
||||||
|
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
if ($stmt->rowCount() == 1) {
|
||||||
|
if ($row = $stmt->fetch()) {
|
||||||
|
$id = $row["id"];
|
||||||
|
$username = $row["username"];
|
||||||
|
$hashed_password = $row["password"];
|
||||||
|
$role = $row["role"];
|
||||||
|
if (password_verify($password, $hashed_password)) {
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
$_SESSION["loggedin"] = true;
|
||||||
|
$_SESSION["id"] = $id;
|
||||||
|
$_SESSION["username"] = $username;
|
||||||
|
$_SESSION["role"] = $role;
|
||||||
|
|
||||||
|
header("location: dashboard.php");
|
||||||
|
} else {
|
||||||
|
$login_err = "Invalid email or password.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$login_err = "Invalid email or password.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Oops! Something went wrong. Please try again later.";
|
||||||
|
}
|
||||||
|
unset($stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($pdo);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login - K Design Accounting</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row vh-100">
|
||||||
|
<div class="col-md-6 d-none d-md-flex justify-content-center align-items-center" style="background: linear-gradient(to bottom right, #2B6CB0, #4A5568);">
|
||||||
|
<div class="text-white text-center p-5">
|
||||||
|
<i class="bi bi-journal-check" style="font-size: 6rem;"></i>
|
||||||
|
<h1 class="display-4 mt-3">K Design Accounting</h1>
|
||||||
|
<p class="lead">Streamline your finances with elegance and precision.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 d-flex justify-content-center align-items-center bg-light">
|
||||||
|
<div class="card shadow-lg border-0 rounded-3" style="width: 25rem;">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<h2 class="card-title text-center mb-4">Welcome Back</h2>
|
||||||
|
<?php
|
||||||
|
if (!empty($login_err)) {
|
||||||
|
echo '<div class="alert alert-danger">' . $login_err . '</div>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<form method="POST" action="login.php">
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input type="email" class="form-control <?php echo (!empty($email_err)) ? 'is-invalid' : ''; ?>" id="email" name="email" placeholder="name@example.com" required value="<?php echo $email; ?>">
|
||||||
|
<label for="email">Email address</label>
|
||||||
|
<span class="invalid-feedback"><?php echo $email_err; ?></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input type="password" class="form-control <?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>" id="password" name="password" placeholder="Password" required>
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<span class="invalid-feedback"><?php echo $password_err; ?></span>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" value="" id="rememberMe">
|
||||||
|
<label class="form-check-label" for="rememberMe">
|
||||||
|
Remember me
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<a href="#" class="text-decoration-none">Forgot password?</a>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg">Login</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7
logout.php
Normal file
7
logout.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$_SESSION = array();
|
||||||
|
session_destroy();
|
||||||
|
header("location: login.php");
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
284
quotations.php
Normal file
284
quotations.php
Normal file
@ -0,0 +1,284 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'includes/auth.php';
|
||||||
|
$active_page = 'quotations';
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
// Handle delete request
|
||||||
|
if (isset($_GET['delete_id'])) {
|
||||||
|
$delete_id = $_GET['delete_id'];
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM quotations WHERE id = ?");
|
||||||
|
$stmt->execute([$delete_id]);
|
||||||
|
header("Location: quotations.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle form submission for adding a new quotation
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_quotation'])) {
|
||||||
|
$customer_id = $_POST['customer_id'];
|
||||||
|
$quotation_number = $_POST['quotation_number'];
|
||||||
|
$quotation_date = $_POST['quotation_date'];
|
||||||
|
$total_amount = $_POST['total_amount'];
|
||||||
|
|
||||||
|
if (!empty($customer_id) && !empty($quotation_number) && !empty($quotation_date) && !empty($total_amount)) {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO quotations (customer_id, quotation_number, quotation_date, total_amount) VALUES (?, ?, ?, ?)");
|
||||||
|
$stmt->execute([$customer_id, $quotation_number, $quotation_date, $total_amount]);
|
||||||
|
}
|
||||||
|
header("Location: quotations.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle form submission for updating a quotation
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_quotation'])) {
|
||||||
|
$id = $_POST['quotation_id'];
|
||||||
|
$customer_id = $_POST['customer_id'];
|
||||||
|
$quotation_number = $_POST['quotation_number'];
|
||||||
|
$quotation_date = $_POST['quotation_date'];
|
||||||
|
$total_amount = $_POST['total_amount'];
|
||||||
|
$status = $_POST['status'];
|
||||||
|
|
||||||
|
if (!empty($id)) {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("UPDATE quotations SET customer_id = ?, quotation_number = ?, quotation_date = ?, total_amount = ?, status = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$customer_id, $quotation_number, $quotation_date, $total_amount, $status, $id]);
|
||||||
|
header("Location: quotations.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all customers for the dropdown
|
||||||
|
$pdo = db();
|
||||||
|
$customers_stmt = $pdo->query("SELECT id, companyName FROM customers ORDER BY companyName ASC");
|
||||||
|
$customers = $customers_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Fetch all quotations with customer names
|
||||||
|
$quotations_stmt = $pdo->query("
|
||||||
|
SELECT
|
||||||
|
q.id,
|
||||||
|
q.customer_id,
|
||||||
|
q.quotation_number,
|
||||||
|
q.quotation_date,
|
||||||
|
q.total_amount,
|
||||||
|
q.status,
|
||||||
|
c.companyName AS customer_name
|
||||||
|
FROM quotations q
|
||||||
|
JOIN customers c ON q.customer_id = c.id
|
||||||
|
ORDER BY q.quotation_date DESC
|
||||||
|
");
|
||||||
|
$quotations = $quotations_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
include 'includes/header.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex" id="wrapper">
|
||||||
|
<?php include 'includes/sidebar.php'; ?>
|
||||||
|
<!-- Page content wrapper-->
|
||||||
|
<div id="page-content-wrapper">
|
||||||
|
<!-- Top navigation-->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<button class="btn btn-primary" id="sidebarToggle"><i class="bi bi-list"></i></button>
|
||||||
|
<ul class="navbar-nav ms-auto mt-2 mt-lg-0">
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo htmlspecialchars($_SESSION["username"]); ?></a>
|
||||||
|
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
|
||||||
|
<a class="dropdown-item" href="#!">Profile</a>
|
||||||
|
<a class="dropdown-item" href="#!">Settings</a>
|
||||||
|
<div class="dropdown-divider"></div>
|
||||||
|
<a class="dropdown-item" href="logout.php">Logout</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page content-->
|
||||||
|
<main class="container-fluid p-4">
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Quotations</h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addQuotationModal">
|
||||||
|
<i class="bi bi-plus-circle"></i>
|
||||||
|
Add Quotation
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Customer</th>
|
||||||
|
<th scope="col">Date</th>
|
||||||
|
<th scope="col">Amount</th>
|
||||||
|
<th scope="col">Status</th>
|
||||||
|
<th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($quotations)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="6" class="text-center">No quotations found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($quotations as $quotation): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($quotation['quotation_number']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($quotation['customer_name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($quotation['quotation_date']); ?></td>
|
||||||
|
<td>$<?php echo htmlspecialchars(number_format($quotation['total_amount'], 2)); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
$status = htmlspecialchars($quotation['status']);
|
||||||
|
$badge_class = 'bg-secondary';
|
||||||
|
if ($status === 'Sent') {
|
||||||
|
$badge_class = 'bg-info text-dark';
|
||||||
|
} elseif ($status === 'Accepted') {
|
||||||
|
$badge_class = 'bg-success';
|
||||||
|
} elseif ($status === 'Rejected') {
|
||||||
|
$badge_class = 'bg-danger';
|
||||||
|
} elseif ($status === 'Draft') {
|
||||||
|
$badge_class = 'bg-warning text-dark';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<span class="badge <?php echo $badge_class; ?>"><?php echo $status; ?></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-outline-primary edit-quotation-btn"
|
||||||
|
data-id="<?php echo $quotation['id']; ?>"
|
||||||
|
data-customer-id="<?php echo $quotation['customer_id']; ?>"
|
||||||
|
data-quotation-number="<?php echo htmlspecialchars($quotation['quotation_number']); ?>"
|
||||||
|
data-quotation-date="<?php echo htmlspecialchars($quotation['quotation_date']); ?>"
|
||||||
|
data-total-amount="<?php echo htmlspecialchars($quotation['total_amount']); ?>"
|
||||||
|
data-status="<?php echo htmlspecialchars($quotation['status']); ?>"
|
||||||
|
data-bs-toggle="modal" data-bs-target="#editQuotationModal">
|
||||||
|
<i class="bi bi-pencil-square"></i>
|
||||||
|
</button>
|
||||||
|
<a href="quotations.php?delete_id=<?php echo $quotation['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this quotation?');"><i class="bi bi-trash"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Quotation Modal -->
|
||||||
|
<div class="modal fade" id="addQuotationModal" tabindex="-1" aria-labelledby="addQuotationModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addQuotationModalLabel">Add New Quotation</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form action="quotations.php" method="POST">
|
||||||
|
<input type="hidden" name="add_quotation" value="1">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="customer_id" class="form-label">Customer</label>
|
||||||
|
<select class="form-select" id="customer_id" name="customer_id" required>
|
||||||
|
<option value="" disabled selected>Select a customer</option>
|
||||||
|
<?php foreach ($customers as $customer): ?>
|
||||||
|
<option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['companyName']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="quotation_number" class="form-label">Quotation Number</label>
|
||||||
|
<input type="text" class="form-control" id="quotation_number" name="quotation_number" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="quotation_date" class="form-label">Quotation Date</label>
|
||||||
|
<input type="date" class="form-control" id="quotation_date" name="quotation_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="total_amount" class="form-label">Total Amount</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="total_amount" name="total_amount" required>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Quotation</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Edit Quotation Modal -->
|
||||||
|
<div class="modal fade" id="editQuotationModal" tabindex="-1" aria-labelledby="editQuotationModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="editQuotationModalLabel">Edit Quotation</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form method="POST" action="quotations.php">
|
||||||
|
<input type="hidden" name="update_quotation" value="1">
|
||||||
|
<input type="hidden" name="quotation_id" id="edit_quotation_id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_customer_id" class="form-label">Customer</label>
|
||||||
|
<select class="form-select" id="edit_customer_id" name="customer_id" required>
|
||||||
|
<?php foreach ($customers as $customer): ?>
|
||||||
|
<option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['companyName']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_quotation_number" class="form-label">Quotation Number</label>
|
||||||
|
<input type="text" class="form-control" id="edit_quotation_number" name="quotation_number" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_quotation_date" class="form-label">Quotation Date</label>
|
||||||
|
<input type="date" class="form-control" id="edit_quotation_date" name="quotation_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_total_amount" class="form-label">Total Amount</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="edit_total_amount" name="total_amount" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="edit_status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="edit_status" name="status" required>
|
||||||
|
<option value="Draft">Draft</option>
|
||||||
|
<option value="Sent">Sent</option>
|
||||||
|
<option value="Accepted">Accepted</option>
|
||||||
|
<option value="Rejected">Rejected</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
var editQuotationModal = document.getElementById('editQuotationModal');
|
||||||
|
editQuotationModal.addEventListener('show.bs.modal', function (event) {
|
||||||
|
var button = event.relatedTarget;
|
||||||
|
var quotationId = button.getAttribute('data-id');
|
||||||
|
var customerId = button.getAttribute('data-customer-id');
|
||||||
|
var quotationNumber = button.getAttribute('data-quotation-number');
|
||||||
|
var quotationDate = button.getAttribute('data-quotation-date');
|
||||||
|
var totalAmount = button.getAttribute('data-total-amount');
|
||||||
|
var status = button.getAttribute('data-status');
|
||||||
|
|
||||||
|
var modal = this;
|
||||||
|
modal.querySelector('#edit_quotation_id').value = quotationId;
|
||||||
|
modal.querySelector('#edit_customer_id').value = customerId;
|
||||||
|
modal.querySelector('#edit_quotation_number').value = quotationNumber;
|
||||||
|
modal.querySelector('#edit_quotation_date').value = quotationDate;
|
||||||
|
modal.querySelector('#edit_total_amount').value = totalAmount;
|
||||||
|
modal.querySelector('#edit_status').value = status;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Loading…
x
Reference in New Issue
Block a user