<?php
require_once 'config/config.php';
require_once 'config/database.php';

try {
    $stmt = db()->prepare("UPDATE sales SET subtotal = total - tax_amount - shipping_amount + discount_amount WHERE subtotal IS NULL OR subtotal = 0");
    $stmt->execute();
    $affected = $stmt->rowCount();
    echo "Successfully updated $affected sales records with subtotal values.\n";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
