150 lines
7.0 KiB
PHP
150 lines
7.0 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'includes/functions.php';
|
|
require_once 'mail/MailService.php';
|
|
|
|
start_secure_session();
|
|
require_login();
|
|
|
|
$message = '';
|
|
$technicians = get_users_by_role('technician');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$customer_name = $_POST['customer_name'] ?? '';
|
|
$customer_email = $_POST['customer_email'] ?? '';
|
|
$job_type = $_POST['job_type'] ?? '';
|
|
$status = $_POST['status'] ?? 'Pending Dispatch';
|
|
$address = $_POST['address'] ?? '';
|
|
$technician_id = $_POST['technician_id'] ?? null;
|
|
|
|
if (create_work_order($customer_name, $customer_email, $job_type, $status, $address, $technician_id)) {
|
|
if (!empty($customer_email)) {
|
|
$subject = "Work Order Created";
|
|
$body = "<p>Dear {$customer_name},</p><p>Your work order for <strong>{$job_type}</strong> has been created.</p><p>Thank you!</p>";
|
|
MailService::sendMail($customer_email, $subject, $body);
|
|
}
|
|
header("Location: index.php");
|
|
exit;
|
|
} else {
|
|
$message = "Failed to create work order.";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Create Work Order - RedSolutions CRM</title>
|
|
<meta name="description" content="Create a new work order in RedSolutions CRM.">
|
|
<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?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body class="d-flex">
|
|
|
|
<div class="sidebar d-flex flex-column p-3">
|
|
<a href="index.php" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
|
|
<i class="bi bi-buildings me-2"></i>
|
|
<span class="fs-4">Flatlogic</span>
|
|
</a>
|
|
<hr>
|
|
<ul class="nav nav-pills flex-column mb-auto">
|
|
<li class="nav-item">
|
|
<a href="index.php" class="nav-link text-white active" aria-current="page">
|
|
<i class="bi bi-speedometer2 me-2"></i>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="reports.php" class="nav-link text-white">
|
|
<i class="bi bi-bar-chart-line me-2"></i>
|
|
Reports
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="inventory.php" class="nav-link text-white">
|
|
<i class="bi bi-box-seam me-2"></i>
|
|
Inventory
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
<hr>
|
|
<div class="dropdown">
|
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle me-2"></i>
|
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<main class="main-content flex-grow-1 p-4">
|
|
<header class="header">
|
|
<h1>Create New Work Order</h1>
|
|
<a href="index.php" class="btn btn-outline-secondary"><i class="bi bi-arrow-left me-2"></i> Back to Dashboard</a>
|
|
</header>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-danger"><?php echo $message; ?></div>
|
|
<?php endif; ?>
|
|
<form action="create_work_order.php" method="POST">
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="customer_name" class="form-label">Customer Name</label>
|
|
<input type="text" class="form-control" id="customer_name" name="customer_name" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="customer_email" class="form-label">Customer Email</label>
|
|
<input type="email" class="form-control" id="customer_email" name="customer_email">
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="job_type" class="form-label">Job Type</label>
|
|
<input type="text" class="form-control" id="job_type" name="job_type" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select class="form-select" id="status" name="status">
|
|
<option>Pending Dispatch</option>
|
|
<option>In Progress</option>
|
|
<option>On Hold</option>
|
|
<option>Completed</option>
|
|
<option>Canceled</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="technician_id" class="form-label">Assign Technician</label>
|
|
<select class="form-select" id="technician_id" name="technician_id">
|
|
<option value="">Unassigned</option>
|
|
<?php foreach ($technicians as $technician): ?>
|
|
<option value="<?php echo $technician['id']; ?>"><?php echo htmlspecialchars($technician['username']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="address" class="form-label">Service Address</label>
|
|
<input type="text" class="form-control" id="address" name="address" required>
|
|
</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="notes" class="form-label">Notes / Description</label>
|
|
<textarea class="form-control" id="notes" name="notes" rows="4"></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Create Work Order</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|