Fix ean12 barcode generation

parent 262296b4
...@@ -5466,8 +5466,22 @@ def generate_bet_barcode(bet_id): ...@@ -5466,8 +5466,22 @@ def generate_bet_barcode(bet_id):
if not enabled or standard == 'none': if not enabled or standard == 'none':
return jsonify({"error": "Barcodes are not enabled"}), 404 return jsonify({"error": "Barcodes are not enabled"}), 404
# Format bet ID for barcode # First try to get saved barcode data from bet
barcode_data = None
session = api_bp.db_manager.get_session()
try:
from ..database.models import BetModel
bet = session.query(BetModel).filter_by(uuid=bet_uuid).first()
if bet and bet.barcode_data:
barcode_data = bet.barcode_data
logger.debug(f"Using saved barcode data for bet {bet_uuid}: {barcode_data}")
finally:
session.close()
# If no saved barcode data, format bet ID for barcode (fallback)
if not barcode_data:
barcode_data = format_bet_id_for_barcode(bet_uuid, standard) barcode_data = format_bet_id_for_barcode(bet_uuid, standard)
logger.debug(f"Using generated barcode data for bet {bet_uuid}: {barcode_data}")
# Generate barcode image # Generate barcode image
barcode_image = generate_barcode_image(barcode_data, standard, width, height) barcode_image = generate_barcode_image(barcode_data, standard, width, height)
...@@ -5521,8 +5535,22 @@ def get_bet_barcode_data(bet_id): ...@@ -5521,8 +5535,22 @@ def get_bet_barcode_data(bet_id):
"barcode_data": None "barcode_data": None
}) })
# Format bet ID for barcode # First try to get saved barcode data from bet
barcode_data = None
session = api_bp.db_manager.get_session()
try:
from ..database.models import BetModel
bet = session.query(BetModel).filter_by(uuid=bet_uuid).first()
if bet and bet.barcode_data:
barcode_data = bet.barcode_data
logger.debug(f"Using saved barcode data for bet {bet_uuid}: {barcode_data}")
finally:
session.close()
# If no saved barcode data, format bet ID for barcode (fallback)
if not barcode_data:
barcode_data = format_bet_id_for_barcode(bet_uuid, standard) barcode_data = format_bet_id_for_barcode(bet_uuid, standard)
logger.debug(f"Using generated barcode data for bet {bet_uuid}: {barcode_data}")
# Generate barcode image and convert to base64 # Generate barcode image and convert to base64
barcode_image_bytes = generate_barcode_image(barcode_data, standard, width, height) barcode_image_bytes = generate_barcode_image(barcode_data, standard, width, height)
......
...@@ -445,6 +445,8 @@ ...@@ -445,6 +445,8 @@
"fixture_id": "{{ bet.fixture_id }}", "fixture_id": "{{ bet.fixture_id }}",
"total_amount": {{ bet.total_amount|round(2) }}, "total_amount": {{ bet.total_amount|round(2) }},
"bet_count": {{ bet.bet_count }}, "bet_count": {{ bet.bet_count }},
"barcode_standard": "{{ bet.barcode_standard }}",
"barcode_data": "{{ bet.barcode_data }}",
"bet_details": [ "bet_details": [
{% for detail in bet.bet_details %} {% for detail in bet.bet_details %}
{ {
...@@ -809,11 +811,21 @@ function generateVerificationCodes(betUuid) { ...@@ -809,11 +811,21 @@ function generateVerificationCodes(betUuid) {
shouldShowQR = false; // Default to not showing on error shouldShowQR = false; // Default to not showing on error
} }
// Check barcode settings // Check barcode settings - use saved barcode data instead of regenerating
fetch(`/api/barcode-data/${betUuid}`) const betData = window.betData;
if (betData && betData.barcode_data && betData.barcode_standard) {
// Use saved barcode data from bet
fetch('/api/barcode-settings')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(settings => {
if (data.success && data.enabled && data.barcode_data && data.barcode_data.show_on_thermal && data.barcode_data.image_base64) { if (settings.success && settings.settings && settings.settings.show_on_thermal) {
// Generate barcode image using the saved barcode data
fetch(`/api/barcode/${betUuid}`)
.then(response => response.blob())
.then(blob => {
const reader = new FileReader();
reader.onload = function() {
const base64 = reader.result;
// Add barcode to receipt // Add barcode to receipt
const barcodeHtml = ` const barcodeHtml = `
<div class="receipt-barcode" id="barcode-container-${betUuid}"> <div class="receipt-barcode" id="barcode-container-${betUuid}">
...@@ -826,13 +838,20 @@ function generateVerificationCodes(betUuid) { ...@@ -826,13 +838,20 @@ function generateVerificationCodes(betUuid) {
// Display barcode // Display barcode
const barcodeElement = document.getElementById(`barcode-${betUuid}`); const barcodeElement = document.getElementById(`barcode-${betUuid}`);
if (barcodeElement) { if (barcodeElement) {
barcodeElement.innerHTML = `<img src="data:image/png;base64,${data.barcode_data.image_base64}" alt="Barcode" class="barcode-img" style="width: ${data.barcode_data.width}px; height: ${data.barcode_data.height}px;">`; barcodeElement.innerHTML = `<img src="${base64}" alt="Barcode" class="barcode-img" style="width: 200px; height: 100px;">`;
} }
};
reader.readAsDataURL(blob);
})
.catch(error => {
console.warn('Failed to generate barcode image:', error);
});
} }
}) })
.catch(error => { .catch(error => {
console.warn('Failed to check barcode settings:', error); console.warn('Failed to check barcode settings:', error);
}); });
}
} }
function printThermalReceipt() { function printThermalReceipt() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment