Skip to content

Fix QSL label sorting to prioritize QSL VIA over call sign#3301

Merged
magicbug merged 2 commits into
masterfrom
copilot/fix-3041
Jul 30, 2025
Merged

Fix QSL label sorting to prioritize QSL VIA over call sign#3301
magicbug merged 2 commits into
masterfrom
copilot/fix-3041

Conversation

Copilot AI commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

This change addresses the ARRL Outgoing QSL Bureau requirement that QSL cards be sorted by parent prefix with QSL VIA call signs taking priority over the station worked call sign.

Problem

The current QSL label printing functionality sorts labels by DXCC and then by the worked call sign (COL_CALL). However, the ARRL Outgoing QSL Bureau wants cards sorted by the QSL VIA call sign when available, as that's how they process and route the cards.

Solution

Modified the sorting logic in Labels_model.php to use a SQL CASE statement that prioritizes QSL VIA over the worked call sign:

ORDER BY 
    COL_DXCC ASC,
    CASE 
        WHEN COL_QSL_VIA IS NOT NULL AND COL_QSL_VIA != '' 
        THEN COL_QSL_VIA 
        ELSE COL_CALL 
    END ASC

Changes Made

  • Updated export_printrequested() function to sort by QSL VIA when available, falling back to call sign
  • Updated export_printrequestedids() function with the same sorting logic
  • Maintains existing DXCC-first sorting which already follows ARRL DXCC entity numbering

Result

QSL labels now print in the correct order for the ARRL Outgoing QSL Bureau:

  1. First by DXCC (parent prefix/country)
  2. Within each DXCC group, by QSL VIA call sign when populated, or by worked call sign when QSL VIA is empty

This ensures that cards going through QSL managers are properly grouped together as expected by the bureau's processing workflow.

Fixes #3041.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: magicbug <84308+magicbug@users.noreply.github.com>
Copilot AI changed the title [WIP] QSL Label Print Order Fix QSL label sorting to prioritize QSL VIA over call sign Jul 30, 2025
Copilot AI requested a review from magicbug July 30, 2025 15:30
@magicbug magicbug marked this pull request as ready for review July 30, 2025 15:33
Copilot AI review requested due to automatic review settings July 30, 2025 15:33
@magicbug magicbug merged commit 41af9e0 into master Jul 30, 2025
2 of 3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes QSL label sorting to comply with ARRL Outgoing QSL Bureau requirements by prioritizing QSL VIA call signs over worked call signs in the sorting order.

  • Updated sorting logic to use QSL VIA call sign when available, falling back to worked call sign
  • Applied consistent sorting across both QSL label export functions
  • Maintains existing DXCC-first sorting structure

$this->db->where_in('COL_QSL_SENT', array('R', 'Q'));
$this->db->order_by("COL_DXCC", "ASC");
$this->db->order_by("COL_CALL", "ASC");
$this->db->order_by("CASE WHEN COL_QSL_VIA IS NOT NULL AND COL_QSL_VIA != '' THEN COL_QSL_VIA ELSE COL_CALL END", "ASC");

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complex CASE statement is duplicated in both functions. Consider extracting this SQL expression into a private method or class constant to improve maintainability and reduce code duplication.

Suggested change
$this->db->order_by("CASE WHEN COL_QSL_VIA IS NOT NULL AND COL_QSL_VIA != '' THEN COL_QSL_VIA ELSE COL_CALL END", "ASC");
$this->db->order_by($this->_get_case_order_by_expression(), "ASC");

Copilot uses AI. Check for mistakes.
$this->db->where('station_profile.user_id', $this->session->userdata('user_id'));
$this->db->where_in('COL_PRIMARY_KEY', $ids);
$this->db->order_by("COL_DXCC", "ASC");
$this->db->order_by("CASE WHEN COL_QSL_VIA IS NOT NULL AND COL_QSL_VIA != '' THEN COL_QSL_VIA ELSE COL_CALL END", "ASC");

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is missing the satellite-related order_by clauses that are present in export_printrequested(). Consider whether COL_SAT_NAME, COL_SAT_MODE, and COL_BAND_RX sorting should also be applied here for consistency.

Suggested change
$this->db->order_by("CASE WHEN COL_QSL_VIA IS NOT NULL AND COL_QSL_VIA != '' THEN COL_QSL_VIA ELSE COL_CALL END", "ASC");
$this->db->order_by("CASE WHEN COL_QSL_VIA IS NOT NULL AND COL_QSL_VIA != '' THEN COL_QSL_VIA ELSE COL_CALL END", "ASC");
$this->db->order_by("COL_SAT_NAME", "ASC");
$this->db->order_by("COL_SAT_MODE", "ASC");
$this->db->order_by("COL_BAND_RX", "ASC");

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QSL Label Print Order

3 participants