149 lines
7.0 KiB
PHP
149 lines
7.0 KiB
PHP
<?php
|
|
$page_title = "Quotations";
|
|
require_once 'includes/header.php';
|
|
|
|
$search = $_GET['search'] ?? '';
|
|
$where = "WHERE q.deleted_at IS NULL";
|
|
$params = [];
|
|
|
|
if ($search) {
|
|
$where .= " AND (q.quotation_number LIKE ? OR c.name LIKE ?)";
|
|
$params[] = "%$search%";
|
|
$params[] = "%$search%";
|
|
}
|
|
|
|
$query = "SELECT q.*, c.name as customer_name, c.email as customer_email
|
|
FROM quotations q
|
|
JOIN customers c ON q.customer_id = c.id
|
|
$where
|
|
ORDER BY q.created_at DESC";
|
|
$stmt = db()->prepare($query);
|
|
$stmt->execute($params);
|
|
$quotations = $stmt->fetchAll();
|
|
|
|
$msg = $_GET['msg'] ?? '';
|
|
$error = $_GET['error'] ?? '';
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="h3 mb-0">Quotations</h2>
|
|
<a href="quotation_form.php" class="btn btn-primary">
|
|
<i class="bi bi-plus-lg me-2"></i>New Quotation
|
|
</a>
|
|
</div>
|
|
|
|
<?php if ($msg): ?>
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
<?= e($msg) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<?= e($error) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card border-0 shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<form method="GET" class="row g-3">
|
|
<div class="col-md-10">
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-transparent border-end-0">
|
|
<i class="bi bi-search text-muted"></i>
|
|
</span>
|
|
<input type="text" name="search" class="form-control border-start-0 ps-0"
|
|
placeholder="Search by number or customer..." value="<?= e($search) ?>">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button type="submit" class="btn btn-light w-100">Search</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th class="ps-4">Quotation #</th>
|
|
<th>Customer</th>
|
|
<th>Date</th>
|
|
<th>Expiry</th>
|
|
<th>Status</th>
|
|
<th class="text-end">Total</th>
|
|
<th class="text-end pe-4">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($quotations)): ?>
|
|
<tr>
|
|
<td colspan="7" class="text-center py-5 text-muted">
|
|
No quotations found.
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($quotations as $q): ?>
|
|
<tr>
|
|
<td class="ps-4 fw-medium"><?= e($q['quotation_number']) ?></td>
|
|
<td>
|
|
<div><?= e($q['customer_name']) ?></div>
|
|
<small class="text-muted"><?= e($q['customer_email']) ?></small>
|
|
</td>
|
|
<td><?= date('M d, Y', strtotime($q['issue_date'])) ?></td>
|
|
<td><?= date('M d, Y', strtotime($q['expiry_date'])) ?></td>
|
|
<td>
|
|
<?php
|
|
$badge_class = 'bg-secondary';
|
|
switch($q['status']) {
|
|
case 'Sent': $badge_class = 'bg-info text-dark'; break;
|
|
case 'Approved': $badge_class = 'bg-success'; break;
|
|
case 'Rejected': $badge_class = 'bg-danger'; break;
|
|
case 'Draft': $badge_class = 'bg-warning text-dark'; break;
|
|
}
|
|
?>
|
|
<span class="badge rounded-pill <?= $badge_class ?>">
|
|
<?= $q['status'] ?>
|
|
</span>
|
|
</td>
|
|
<td class="text-end fw-bold"><?= format_currency($q['total_amount']) ?></td>
|
|
<td class="text-end pe-4">
|
|
<div class="btn-group">
|
|
<a href="quotation_form.php?id=<?= $q['id'] ?>" class="btn btn-sm btn-outline-secondary" title="Edit">
|
|
<i class="bi bi-pencil"></i>
|
|
</a>
|
|
<a href="quotation_pdf.php?id=<?= $q['id'] ?>" class="btn btn-sm btn-outline-primary" title="Download PDF" target="_blank">
|
|
<i class="bi bi-file-pdf"></i>
|
|
</a>
|
|
<a href="send_document.php?type=quotation&id=<?= $q['id'] ?>" class="btn btn-sm btn-outline-info" title="Email to Customer" onclick="return confirm('Email this quotation to <?= e($q['customer_email']) ?>?')">
|
|
<i class="bi bi-envelope"></i>
|
|
</a>
|
|
<?php if ($q['status'] === 'Sent'): ?>
|
|
<a href="send_document.php?type=quotation&id=<?= $q['id'] ?>&reminder=1" class="btn btn-sm btn-outline-warning" title="Send Follow-up" onclick="return confirm('Send follow-up reminder to <?= e($q['customer_email']) ?>?')">
|
|
<i class="bi bi-bell"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php if ($q['status'] === 'Approved'): ?>
|
|
<form action="convert_to_invoice.php" method="POST" class="d-inline">
|
|
<input type="hidden" name="csrf_token" value="<?= csrf_token() ?>">
|
|
<input type="hidden" name="quotation_id" value="<?= $q['id'] ?>">
|
|
<button type="submit" class="btn btn-sm btn-outline-success" title="Convert to Invoice" onclick="return confirm('Convert this quotation to an invoice?')">
|
|
<i class="bi bi-arrow-right-circle"></i>
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|