<?php
/**
 * Simple QR Code Generator using Google Charts API
 * This generates a QR code URL that can be displayed as an image
 */

function generateQRCodeURL($data, $size = 200) {
    // Using Google Charts API to generate QR code
    // This is a free service and doesn't require any library
    return 'https://chart.googleapis.com/chart?chs=' . $size . 'x' . $size . '&chld=L|0&cht=qr&chl=' . urlencode($data);
}

/**
 * Generate QR code for product with SR NO (Serial Number)
 * @param int $productId Product ID
 * @param int $srNo Product SR NO (Serial Number)
 * @param int $size QR code size in pixels (default 200)
 * @return string QR code image URL
 */
function getProductQRCode($productId, $srNo = null, $size = 200) {
    $productUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/ecoms/product.php?id=' . $productId;
    
    // Add SR NO to URL if available
    if (!empty($srNo)) {
        $productUrl .= '&sr=' . $srNo;
    }
    
    return generateQRCodeURL($productUrl, $size);
}

/**
 * Format product information with SR NO for display
 * @param int $srNo Serial Number
 * @param string $title Product Title
 * @return string Formatted product info
 */
function formatProductSRNo($srNo) {
    if (empty($srNo)) return '';
    return str_pad($srNo, 5, '0', STR_PAD_LEFT); // Format as 00001, 00002, etc.
}
?>

