the delivered date is not shown please fix it and provide the complete full adjusted code without affecting anything else :

<?php
// services.php
include 'db.php';

// Function to generate a unique service number
function generateServiceNumber($pdo) {
    do {
        $service_number = mt_rand(100000, 999999);
        $stmt = $pdo->prepare("SELECT COUNT(*) FROM services WHERE service_number = ?");
        $stmt->execute([$service_number]);
    } while ($stmt->fetchColumn() > 0);

    return $service_number;
}

// Handle different actions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['action'])) {
        switch ($_POST['action']) {
            case 'add_service':
                $customer_id = $_POST['customer_id'];
                $device_id = $_POST['device_id'];
                $service_date = $_POST['service_date'];
                $comments = $_POST['comments'];
                $technician_comments = $_POST['technician_comments'];
                $status = $_POST['status'];
                $delivered_date = isset($_POST['delivered_date']) ? $_POST['delivered_date'] : null;
                $service_number = generateServiceNumber($pdo);

                $stmt = $pdo->prepare("INSERT INTO services (customer_id, device_id, service_date, comments, technician_comments, service_number, status, delivered_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
                $stmt->execute([$customer_id, $device_id, $service_date, $comments, $technician_comments, $service_number, $status, $delivered_date]);

                header('Location: services.php?status=success');
                exit;

            case 'edit_service':
                $service_id = $_POST['service_id'];
                $customer_id = $_POST['customer_id'];
                $device_id = $_POST['device_id'];
                $service_date = $_POST['service_date'];
                $comments = $_POST['comments'];
                $technician_comments = $_POST['technician_comments'];
                $status = $_POST['status'];
                $delivered_date = isset($_POST['delivered_date']) ? $_POST['delivered_date'] : null;

                $stmt = $pdo->prepare("UPDATE services SET customer_id = ?, device_id = ?, service_date = ?, comments = ?, technician_comments = ?, status = ?, delivered_date = ? WHERE id = ?");
                $stmt->execute([$customer_id, $device_id, $service_date, $comments, $technician_comments, $status, $delivered_date, $service_id]);

                header('Location: services.php?status=edited');
                exit;

            case 'delete_service':
                $service_id = $_POST['service_id'];
                $stmt = $pdo->prepare("DELETE FROM services WHERE id = ?");
                $stmt->execute([$service_id]);

                header('Location: services.php?status=deleted');
                exit;
        }
    }
}

// Fetch customer devices
if (isset($_GET['action']) && $_GET['action'] == 'get_devices') {
    $customer_id = $_GET['customer_id'];
    $devices = $pdo->prepare("SELECT d.id, d.type, d.brand, d.model, cd.serial_number 
                              FROM devices d
                              JOIN customer_devices cd ON d.id = cd.device_id
                              WHERE cd.customer_id = ?");
    $devices->execute([$customer_id]);
    echo json_encode($devices->fetchAll(PDO::FETCH_ASSOC));
    exit;
}

// Fetch service details
if (isset($_GET['view_id'])) {
    $view_id = $_GET['view_id'];
    $stmt = $pdo->prepare("SELECT s.*, c.full_name, d.type, d.brand, d.model, cd.serial_number 
                           FROM services s
                           JOIN customers c ON s.customer_id = c.id
                           JOIN customer_devices cd ON s.device_id = cd.device_id
                           JOIN devices d ON cd.device_id = d.id
                           WHERE s.id = ?");
    $stmt->execute([$view_id]);
    $viewService = $stmt->fetch(PDO::FETCH_ASSOC);
    echo json_encode($viewService);
    exit;
}

// Fetch service for editing
$editService = null;
if (isset($_GET['edit_id'])) {
    $edit_id = $_GET['edit_id'];
    $stmt = $pdo->prepare("SELECT * FROM services WHERE id = ?");
    $stmt->execute([$edit_id]);
    $editService = $stmt->fetch(PDO::FETCH_ASSOC);
}
?>

<!DOCTYPE html>
<html lang="el">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Υπηρεσίες - Digihack</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <style>
        body {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            background-color: #f4f6f8;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            color: #333;
        }
        .container {
            flex: 1;
            margin-top: 20px;
        }
        .navbar {
            background-color: #282828;
        }
        .navbar-brand img {
            height: 40px;
        }
        .nav-link {
            color: #fff !important;
        }
        .nav-link.active {
            font-weight: bold;
            color: #d32f2f !important;
        }
        .content {
            margin-top: 40px;
        }
        .modal-header, .btn-custom, .footer {
            background-color: #d32f2f;
            color: white;
        }
        .btn-custom:hover {
            background-color: #b71c1c;
        }
        .footer a {
            color: #d32f2f;
            text-decoration: none;
        }
        .footer a:hover {
            text-decoration: underline;
        }
        .footer {
            background-color: #282828;
            color: white;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
        }
        .table-hover tbody tr:hover {
            background-color: #e9ecef;
        }
        .select2-container--default .select2-selection--single {
            height: calc(2.25rem + 2px);
        }
        .select2-container .select2-selection--single .select2-selection__rendered {
            line-height: 2.25rem;
        }
        .select2-container .select2-selection--single .select2-selection__arrow {
            height: 100%;
        }
        .alert {
            margin-top: 15px;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark">
        <a class="navbar-brand" href="#"><img src="uploads/digihack-logo-new.png" alt="Digihack"></a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item">
                    <a class="nav-link <?= ($page == 'customers') ? 'active' : '' ?>" href="customers.php">Πελάτες</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= ($page == 'services') ? 'active' : '' ?>" href="services.php">Υπηρεσίες</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= ($page == 'devices') ? 'active' : '' ?>" href="devices.php">Συσκευές</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= ($page == 'settings') ? 'active' : '' ?>" href="settings.php">Ρυθμίσεις</a>
                </li>
            </ul>
        </div>
    </nav>

    <div class="container">
        <h1 class="text-center mb-4">Διαχείριση Υπηρεσιών</h1>

        <?php if (isset($_GET['status'])): ?>
            <div class="alert alert-<?php echo $_GET['status'] == 'success' ? 'success' : ($_GET['status'] == 'edited' ? 'info' : 'danger'); ?>">
                Η υπηρεσία <?php echo ($_GET['status'] == 'success' ? 'προστέθηκε' : ($_GET['status'] == 'edited' ? 'ενημερώθηκε' : 'διαγράφηκε')); ?> επιτυχώς!
            </div>
        <?php endif; ?>

        <div class="d-flex justify-content-between mb-3">
            <button type="button" class="btn btn-outline-danger" data-toggle="modal" data-target="#serviceModal">
                <?php echo $editService ? 'Επεξεργασία Υπηρεσίας' : 'Προσθήκη Νέας Υπηρεσίας'; ?>
            </button>
        </div>

        <!-- Service Modal -->
        <div class="modal fade" id="serviceModal" tabindex="-1" aria-labelledby="serviceModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="serviceModalLabel"><?php echo $editService ? 'Επεξεργασία Υπηρεσίας' : 'Προσθήκη Νέας Υπηρεσίας'; ?></h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form action="services.php" method="post">
                            <input type="hidden" name="action" value="<?php echo $editService ? 'edit_service' : 'add_service'; ?>">
                            <?php if ($editService): ?>
                                <input type="hidden" name="service_id" value="<?php echo $editService['id']; ?>">
                            <?php endif; ?>
                            <div class="form-group">
                                <label for="customer_id">Επιλογή Πελάτη</label>
                                <select id="customer_id" name="customer_id" class="form-control select2" required onchange="fetchDevices(this.value)">
                                    <option value="">Επιλέξτε πελάτη</option>
                                    <?php
                                    $customers = $pdo->query("SELECT id, full_name FROM customers")->fetchAll(PDO::FETCH_ASSOC);
                                    foreach ($customers as $customer) {
                                        $selected = $editService && $editService['customer_id'] == $customer['id'] ? 'selected' : '';
                                        echo "<option value=\"{$customer['id']}\" $selected>{$customer['full_name']}</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="form-group" id="deviceSelectContainer" style="display:<?php echo $editService ? 'block' : 'none'; ?>;">
                                <label for="device_id">Επιλογή Συσκευής Πελάτη</label>
                                <select id="device_id" name="device_id" class="form-control" required>
                                    <?php if ($editService): ?>
                                        <?php
                                        $devices = $pdo->prepare("SELECT d.id, d.type, d.brand, d.model, cd.serial_number 
                                                                  FROM devices d
                                                                  JOIN customer_devices cd ON d.id = cd.device_id
                                                                  WHERE cd.customer_id = ?");
                                        $devices->execute([$editService['customer_id']]);
                                        foreach ($devices as $device) {
                                            $selected = $editService['device_id'] == $device['id'] ? 'selected' : '';
                                            echo "<option value=\"{$device['id']}\" $selected>{$device['type']} - {$device['brand']} - {$device['model']} - Σειριακός: {$device['serial_number']}</option>";
                                        }
                                        ?>
                                    <?php endif; ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="service_date">Ημερομηνία Υπηρεσίας</label>
                                <input type="date" class="form-control" id="service_date" name="service_date" required value="<?php echo $editService ? $editService['service_date'] : ''; ?>">
                            </div>
                            <div class="form-group">
                                <label for="comments">Σχόλια</label>
                                <textarea class="form-control" id="comments" name="comments"><?php echo $editService ? $editService['comments'] : ''; ?></textarea>
                            </div>
                            <div class="form-group">
                                <label for="technician_comments">Σχόλια Τεχνικού</label>
                                <textarea class="form-control" id="technician_comments" name="technician_comments"><?php echo $editService ? $editService['technician_comments'] : ''; ?></textarea>
                            </div>
                            <div class="form-group">
                                <label for="status">Κατάσταση</label>
                                <select id="status" name="status" class="form-control" onchange="toggleDeliveredDate(this.value)">
                                    <option value="Παραλαβή" <?php echo $editService && $editService['status'] == 'Received' ? 'selected' : ''; ?>>Παραλαβή</option>
                                    <option value="Αναμονή για Ανταλλακτικό" <?php echo $editService && $editService['status'] == 'On Hold for Part' ? 'selected' : ''; ?>>Αναμονή για Ανταλλακτικό</option>
                                    <option value="Παραδόθηκε" <?php echo $editService && $editService['status'] == 'Delivered' ? 'selected' : ''; ?>>Παραδόθηκε</option>
                                </select>
                            </div>
                            <div class="form-group" id="deliveredDateContainer" style="display:<?php echo $editService && $editService['status'] == 'Delivered' ? 'block' : 'none'; ?>;">
                                <label for="delivered_date">Ημερομηνία Παράδοσης</label>
                                <input type="date" class="form-control" id="delivered_date" name="delivered_date" value="<?php echo $editService ? $editService['delivered_date'] : ''; ?>">
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Ακύρωση</button>
                                <button type="submit" class="btn btn-outline-danger"><?php echo $editService ? 'Ενημέρωση Υπηρεσίας' : 'Προσθήκη Υπηρεσίας'; ?></button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- View Service Modal -->
        <div class="modal fade" id="viewServiceModal" tabindex="-1" aria-labelledby="viewServiceModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="viewServiceModalLabel">Προβολή Λεπτομερειών Υπηρεσίας</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div id="serviceDetails">
                            <!-- Service details will be loaded here -->
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Κλείσιμο</button>
                    </div>
                </div>
            </div>
        </div>

        <h2>Λίστα Υπηρεσιών</h2>
        <input type="text" id="serviceSearch" class="form-control mb-3" placeholder="Αναζήτηση υπηρεσιών με αριθμό υπηρεσίας ή όνομα πελάτη...">
        
        <?php
        $services = $pdo->query("SELECT s.id, s.service_number, s.service_date, c.full_name AS customer_name, s.status, s.delivered_date
                                FROM services s
                                JOIN customers c ON s.customer_id = c.id
                                ORDER BY s.service_date DESC")->fetchAll(PDO::FETCH_ASSOC);
        if (count($services) > 0): ?>
            <table class="table table-bordered table-hover mt-4">
                <thead class="thead-dark">
                    <tr>
                        <th>Αριθμός Υπηρεσίας</th>
                        <th>Πελάτης</th>
                        <th>Ημερομηνία Υπηρεσίας</th>
                        <th>Κατάσταση</th>
                        <th>Ημερομηνία Παράδοσης</th>
                        <th>Ενέργειες</th>
                    </tr>
                </thead>
                <tbody id="serviceTable">
                    <?php foreach ($services as $service): ?>
                    <tr>
                        <td><?= htmlspecialchars($service['service_number']) ?></td>
                        <td><?= htmlspecialchars($service['customer_name']) ?></td>
                        <td><?= htmlspecialchars($service['service_date']) ?></td>
                        <td><?= htmlspecialchars($service['status']) ?></td>
                        <td><?= $service['delivered_date'] ? htmlspecialchars($service['delivered_date']) : '' ?></td>
                        <td>
                            <div class="btn-group" role="group">
                                <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#viewServiceModal" data-id="<?= htmlspecialchars($service['id']) ?>">Προβολή</button>
                                <a href="services.php?edit_id=<?= htmlspecialchars($service['id']) ?>" class="btn btn-warning btn-sm">Επεξεργασία</a>
                                <form action="services.php" method="post" style="display:inline;" onsubmit="return confirmDelete();">
                                    <input type="hidden" name="action" value="delete_service">
                                    <input type="hidden" name="service_id" value="<?= htmlspecialchars($service['id']) ?>">
                                    <button type="submit" class="btn btn-danger btn-sm">Διαγραφή</button>
                                </form>
                                <a href="generate_service_pdf.php?id=<?= htmlspecialchars($service['id']) ?>" class="btn btn-secondary btn-sm" target="_blank">Εκτύπωση</a>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php else: ?>
            <p>Δεν βρέθηκαν υπηρεσίες.</p>
        <?php endif; ?>
    </div>
    <div class="footer">
        <p>&copy; 2024 Digihack. Όλα τα δικαιώματα διατηρούνται. από <a href="https://skypulse.uk" target="_blank">skypulse.uk</a></p>
    </div>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
    <script>
        $(document).ready(function() {
            $('.select2').select2({
                placeholder: 'Επιλέξτε πελάτη',
                allowClear: true
            });

            $('#serviceSearch').on('input', function() {
                let filter = this.value.toLowerCase();
                $('#serviceTable tr').each(function() {
                    let text = $(this).text().toLowerCase();
                    $(this).toggle(text.includes(filter));
                });
            });

            $('button[data-target="#viewServiceModal"]').click(function() {
                const serviceId = $(this).data('id');
                loadServiceDetails(serviceId);
            });

            <?php if ($editService): ?>
            $('#serviceModal').modal('show');
            <?php endif; ?>

            $('#status').on('change', function() {
                toggleDeliveredDate(this.value);
            });
        });

        function fetchDevices(customerId) {
            $('#deviceSelectContainer').hide();
            $('#device_id').empty();
            if (!customerId) return;

            $.getJSON('services.php?action=get_devices&customer_id=' + customerId, function(data) {
                let deviceSelect = $('#device_id');
                if (data.length > 0) {
                    data.forEach(device => {
                        deviceSelect.append(new Option(`${device.type} - ${device.brand} - ${device.model} - Σειριακός: ${device.serial_number}`, device.id));
                    });
                    $('#deviceSelectContainer').show();
                }
            });
        }

        function toggleDeliveredDate(status) {
            if (status === 'Delivered') {
                $('#deliveredDateContainer').show();
            } else {
                $('#deliveredDateContainer').hide();
            }
        }

        function confirmDelete() {
            return confirm('Είστε σίγουροι ότι θέλετε να διαγράψετε αυτήν την υπηρεσία;');
        }

        function loadServiceDetails(serviceId) {
            $.getJSON('services.php?view_id=' + serviceId, function(data) {
                if (data) {
                    $('#viewServiceModalLabel').text('Προβολή Λεπτομερειών Υπηρεσίας - ' + data.full_name);
                    $('#serviceDetails').html(
                        '<p><strong>Αριθμός Υπηρεσίας:</strong> ' + data.service_number + '</p>' +
                        '<p><strong>Πελάτης:</strong> ' + data.full_name + '</p>' +
                        '<p><strong>Συσκευή:</strong> ' + data.type + ' - ' + data.brand + ' - ' + data.model + ' - Σειριακός: ' + data.serial_number + '</p>' +
                        '<p><strong>Ημερομηνία Υπηρεσίας:</strong> ' + data.service_date + '</p>' +
                        '<p><strong>Σχόλια:</strong> ' + data.comments + '</p>' +
                        '<p><strong>Σχόλια Τεχνικού:</strong> ' + data.technician_comments + '</p>' +
                        '<p><strong>Κατάσταση:</strong> ' + data.status + '</p>' +
                        (data.delivered_date ? '<p><strong>Ημερομηνία Παράδοσης:</strong> ' + data.delivered_date + '</p>' : '') +
                        '<p><strong>Barcode:</strong> <img src="generate_barcode.php?code=' + data.service_number + '" alt="Barcode" /></p>'
                    );
                } else {
                    $('#serviceDetails').html('<p>Δεν υπάρχουν διαθέσιμες λεπτομέρειες για αυτήν την υπηρεσία.</p>');
                }
            }).fail(function() {
                $('#serviceDetails').html('<p>Σφάλμα κατά τη φόρτωση των λεπτομερειών της υπηρεσίας.</p>');
            });
        }
    </script>
</body>
</html>