sirnails / BloomQuote

Quote management app for a florist
2 stars 0 forks source link

Feature Suggestion: Sort quotes #26

Open sirnails opened 3 months ago

sirnails commented 3 months ago

Project: BloomQuote
Feature Type: Usability Improvement

Overview

BloomQuote, a web-based platform, streamlines the process of creating custom quote proposals and managing events for florists. The software provides users with a comprehensive platform to efficiently capture and organize the details of a customer's wedding quotation. This suggestion aims to enhance the usability of the "List of Quotes" screen by allowing users to sort quotes by date or by name.

Current Functionality

The current implementation of the "List of Quotes" screen displays all quotes created by the user in a table format, listing key details such as ID, wedding date, bride name, groom name, total cost, and available actions. However, there is no option to sort these quotes based on any criteria.

Proposed Enhancement

Introduce the ability to sort the list of quotes by either the wedding date or the bride's name. This enhancement will improve the user experience by making it easier to find specific quotes, especially when dealing with a large number of entries.

Implementation Details

  1. Add Sorting Controls: Add two sorting buttons or a dropdown menu above the quotes table to allow users to choose the sorting criteria (by date or by name).

  2. Modify Backend Logic: Update the QuoteController::list_quotes() method to accept a sorting parameter and modify the database query to order the results based on the selected criteria.

  3. Update Views: Modify the list_quotes.php view to include sorting controls and ensure the table displays quotes in the correct order based on the user's selection.

PHP Code Changes

Controller (QuoteController.php):

public function list_quotes() {
    $user_id = $_SESSION['user_id'];
    $sort_by = isset($_GET['sort_by']) ? InputHelper::sanitizeString($_GET['sort_by']) : 'date';

    if ($sort_by === 'name') {
        $quotes = $this->quoteModel->getQuotesByUserIdSortedByName($user_id);
    } else {
        $quotes = $this->quoteModel->getQuotesByUserIdSortedByDate($user_id);
    }

    include_once './app/views/quote/list_quotes.php';
}

Model (Quote.php):

public function getQuotesByUserIdSortedByDate($user_id) {
    $stmt = $this->db->prepare("SELECT * FROM quotes WHERE user_id = ? ORDER BY wedding_date ASC");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    return $stmt->get_result();
}

public function getQuotesByUserIdSortedByName($user_id) {
    $stmt = $this->db->prepare("SELECT * FROM quotes WHERE user_id = ? ORDER BY bride_name ASC, groom_name ASC");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    return $stmt->get_result();
}

View (list_quotes.php):

<?php include_once './app/views/partials/navbar.php'; ?>

<h1>Your Quotes</h1>
<a href="index.php?action=create_quote" class="btn btn-primary mb-3">Create New Quote</a>
<div class="mb-3">
    <label for="sort_by" class="form-label">Sort By:</label>
    <select id="sort_by" class="form-select" onchange="sortQuotes(this.value)">
        <option value="date">Wedding Date</option>
        <option value="name">Bride Name</option>
    </select>
</div>
<table class="table table-striped">
    <thead>
        <tr>
            <th>ID</th>
            <th>Wedding Date</th>
            <th>Bride Name</th>
            <th>Groom Name</th>
            <th>Total Cost</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <?php while ($quote = $quotes->fetch_assoc()) { ?>
            <tr>
                <td><?php echo $quote['id']; ?></td>
                <td><?php echo $quote['wedding_date']; ?></td>
                <td><?php echo $quote['bride_name']; ?></td>
                <td><?php echo $quote['groom_name']; ?></td>
                <td>£<?php echo number_format($quote['total_cost'], 2); ?></td>
                <td>
                    <a href="index.php?action=show_quote&id=<?php echo $quote['id']; ?>" class="btn btn-info">View</a>
                </td>
            </tr>
        <?php } ?>
    </tbody>
</table>

<script>
function sortQuotes(criteria) {
    window.location.href = `index.php?action=view_quotes&sort_by=${criteria}`;
}
</script>

<?php include_once './app/views/partials/footer.php'; ?>

Benefits