<?php
/**
 * Fix unit name from "Pcss" to "Pcs" in products table
 */
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/core/Database.php';

try {
    // Update products where unit is "Pcss" to "Pcs"
    $stmt = db()->prepare("UPDATE products SET unit = 'Pcs' WHERE unit = 'Pcss'");
    $stmt->execute();
    $affectedRows = $stmt->rowCount();
    
    echo "Fixed $affectedRows product(s) - changed unit from 'Pcss' to 'Pcs'\n";
    
    if ($affectedRows > 0) {
        echo "✓ Successfully updated product units\n";
    } else {
        echo "✓ No products found with unit 'Pcss' (already fixed or doesn't exist)\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    exit(1);
}
