when i edit the devices on a customer and save it the if i add an extra device or remove the existing device an add an other one then the change is not being saved if edit the cisting data then they are saved please adjust and provide the complete fixed code : 

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

// Handle form submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['action'])) {
        if ($_POST['action'] === 'add_customer') {
            // Add a new customer
            $full_name = $_POST['full_name'];
            $landline_phone = $_POST['landline_phone'];
            $cellphone_number = $_POST['cellphone_number'];
            $registration_date = date('Y-m-d');

            $stmt = $pdo->prepare("INSERT INTO customers (full_name, landline_phone, cellphone_number, registration_date) VALUES (?, ?, ?, ?)");
            $stmt->execute([$full_name, $landline_phone, $cellphone_number, $registration_date]);

            $customer_id = $pdo->lastInsertId();

            if (isset($_POST['devices'])) {
                foreach ($_POST['devices'] as $device) {
                    if (!empty($device['device_id']) && $device['device_id'] !== 'none') {
                        $device_id = $device['device_id'];
                        $serial_number = $device['serial_number'];
                        $stmt = $pdo->prepare("INSERT INTO customer_devices (customer_id, device_id, serial_number) VALUES (?, ?, ?)");
                        $stmt->execute([$customer_id, $device_id, $serial_number]);
                    }
                }
            }
        } elseif ($_POST['action'] === 'edit_customer') {
            // Edit an existing customer
            $customer_id = $_POST['customer_id'];
            $full_name = $_POST['full_name'];
            $landline_phone = $_POST['landline_phone'];
            $cellphone_number = $_POST['cellphone_number'];

            $stmt = $pdo->prepare("UPDATE customers SET full_name = ?, landline_phone = ?, cellphone_number = ? WHERE id = ?");
            $stmt->execute([$full_name, $landline_phone, $cellphone_number, $customer_id]);

            // Remove existing devices and reinsert
            $stmt = $pdo->prepare("DELETE FROM customer_devices WHERE customer_id = ?");
            $stmt->execute([$customer_id]);

            if (isset($_POST['devices'])) {
                foreach ($_POST['devices'] as $device) {
                    if (!empty($device['device_id']) && $device['device_id'] !== 'none') {
                        $device_id = $device['device_id'];
                        $serial_number = $device['serial_number'];
                        $stmt = $pdo->prepare("INSERT INTO customer_devices (customer_id, device_id, serial_number) VALUES (?, ?, ?)");
                        $stmt->execute([$customer_id, $device_id, $serial_number]);
                    }
                }
            }
        } elseif ($_POST['action'] === 'delete_customer') {
            $customer_id = $_POST['customer_id'];
            // Uses cascading deletes on customer_id
            $stmt = $pdo->prepare("DELETE FROM customers WHERE id = ?");
            $stmt->execute([$customer_id]);
        }

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

// Retrieve devices for selection
$devices = $pdo->query("SELECT id, type, brand, model FROM devices")->fetchAll(PDO::FETCH_ASSOC);

// Retrieve customers
$customers = $pdo->query("SELECT * FROM customers ORDER BY id DESC")->fetchAll(PDO::FETCH_ASSOC);

function fetchCustomerDevices($pdo, $customer_id) {
    $stmt = $pdo->prepare("SELECT cd.device_id, cd.serial_number, d.type, d.brand, d.model FROM customer_devices cd JOIN devices d ON cd.device_id = d.id WHERE cd.customer_id = ?");
    $stmt->execute([$customer_id]);
    return $stmt->fetchAll(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;
        }
        .content .form-group label {
            font-weight: bold;
        }
        .content .form-control, .content .form-control-file {
            border-radius: 5px;
        }
        .content .modal-content {
            border-radius: 10px;
        }
        .btn-custom {
            background-color: #007bff;
            color: #fff;
            border: none;
            transition: background-color 0.3s ease;
        }
        .btn-custom:hover {
            background-color: #0056b3;
        }
        .table th, .table td {
            vertical-align: middle;
        }
        .table-hover tbody tr:hover {
            background-color: #f1f1f1;
        }
        .device-item {
            margin-bottom: 15px;
        }
        .device-item .form-group {
            flex: 1 1 auto;
        }
        .device-item .select2-container {
            width: 100% !important;
        }
        .select2-container--default .select2-selection--single {
            border-radius: 0.25rem;
            height: calc(1.5em + 0.75rem + 2px);
            border-color: #ced4da;
        }
        .select2-selection__rendered {
            line-height: 1.5em;
        }
        .select2-selection__arrow {
            top: 50%;
            transform: translateY(-50%);
        }
        @media (max-width: 768px) {
            .device-item {
                flex-direction: column;
                align-items: flex-start;
            }
            .device-item .form-group, .device-item .close-btn {
                width: 100%;
            }
            .device-item .close-btn {
                text-align: right;
            }
        }
        .footer {
            background-color: #282828;
            color: white;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
        }
        .footer a {
            color: #d32f2f;
            text-decoration: none;
        }
        .footer a:hover {
            text-decoration: underline;
        }
    </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">
        <div class="content">
            <h1 class="text-center mb-4">Διαχείριση Πελατών</h1>

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

            <button type="button" class="btn btn-outline-danger mb-4" data-toggle="modal" data-target="#customerModal">
                Προσθήκη Νέου Πελάτη
            </button>

            <div class="modal fade" id="customerModal" tabindex="-1" aria-labelledby="customerModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="customerModalLabel">Προσθήκη Νέου Πελάτη</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="customers.php" method="post">
                                <input type="hidden" name="action" value="add_customer">
                                <div class="form-group">
                                    <label for="full_name">Ονοματεπώνυμο</label>
                                    <input type="text" class="form-control" id="full_name" name="full_name" required>
                                </div>
                                <div class="form-row">
                                    <div class="form-group col-md-6">
                                        <label for="landline_phone">Τηλέφωνο Σταθερό</label>
                                        <input type="text" class="form-control" id="landline_phone" name="landline_phone">
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label for="cellphone_number">Αριθμός Κινητού</label>
                                        <input type="text" class="form-control" id="cellphone_number" name="cellphone_number">
                                    </div>
                                </div>
                                <h3 class="mt-4">Συσκευές σε Κατοχή</h3>
                                <div id="device_list">
                                    <div class="device-item d-flex align-items-end">
                                        <div class="form-group mr-2">
                                            <label>Επιλογή Συσκευής</label>
                                            <select class="form-control device-select" name="devices[0][device_id]" required>
                                                <option value="" disabled selected>Επιλέξτε συσκευή</option>
                                                <option value="none">Χωρίς συσκευή</option>
                                                <?php foreach ($devices as $device): ?>
                                                    <option value="<?= $device['id'] ?>"><?= $device['type'] ?> - <?= $device['brand'] ?> - <?= $device['model'] ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="serial_number">Σειριακός Αριθμός</label>
                                            <input type="text" class="form-control serial-number" name="devices[0][serial_number]" required>
                                        </div>
                                        <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">&times;</button>
                                    </div>
                                </div>
                                <button type="button" class="btn btn-outline-danger mt-2" id="add_device">Προσθήκη Άλλης Συσκευής</button>
                                <button type="submit" class="btn btn-outline-danger mt-2 ml-2">Προσθήκη Πελάτη</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <h2>Λίστα Πελατών</h2>
            <input type="text" id="customerSearch" class="form-control mb-3" placeholder="Αναζήτηση πελατών...">
            <?php if (count($customers) > 0): ?>
                <table class="table table-bordered table-hover">
                    <thead class="thead-dark">
                        <tr>
                            <th>ID</th>
                            <th>Ονοματεπώνυμο</th>
                            <th>Τηλέφωνο Σταθερό</th>
                            <th>Αριθμός Κινητού</th>
                            <th>Ημερομηνία Εγγραφής</th>
                            <th>Ενέργειες</th>
                        </tr>
                    </thead>
                    <tbody id="customerTable">
                        <?php foreach ($customers as $customer): ?>
                        <tr>
                            <td><?= htmlspecialchars($customer['id']) ?></td>
                            <td><?= htmlspecialchars($customer['full_name']) ?></td>
                            <td><?= htmlspecialchars($customer['landline_phone']) ?></td>
                            <td><?= htmlspecialchars($customer['cellphone_number']) ?></td>
                            <td><?= htmlspecialchars($customer['registration_date']) ?></td>
                            <td>
                                <button class="btn btn-info btn-sm" data-toggle="modal" data-target="#viewCustomerModal<?= $customer['id'] ?>">Προβολή</button>
                                <button class="btn btn-warning btn-sm" data-toggle="modal" data-target="#editCustomerModal<?= $customer['id'] ?>">Επεξεργασία</button>
                                <button class="btn btn-danger btn-sm" data-toggle="modal" data-target="#deleteCustomerModal<?= $customer['id'] ?>">Διαγραφή</button>
                                <button class="btn btn-secondary btn-sm" onclick="printCustomer(<?= $customer['id'] ?>)">Εκτύπωση</button>
                            </td>
                        </tr>

                        <!-- Modal View Customer -->
                        <div class="modal fade" id="viewCustomerModal<?= $customer['id'] ?>" tabindex="-1" aria-labelledby="viewCustomerModalLabel<?= $customer['id'] ?>" aria-hidden="true">
                            <div class="modal-dialog modal-lg">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="viewCustomerModalLabel<?= $customer['id'] ?>">Προβολή Πελάτη</h5>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                    <div class="modal-body">
                                        <p><strong>Ονοματεπώνυμο:</strong> <?= htmlspecialchars($customer['full_name']) ?></p>
                                        <p><strong>Τηλέφωνο Σταθερό:</strong> <?= htmlspecialchars($customer['landline_phone']) ?></p>
                                        <p><strong>Αριθμός Κινητού:</strong> <?= htmlspecialchars($customer['cellphone_number']) ?></p>
                                        <p><strong>Ημερομηνία Εγγραφής:</strong> <?= htmlspecialchars($customer['registration_date']) ?></p>
                                        <h4>Συσκευές σε Κατοχή:</h4>
                                        <ul>
                                            <?php
                                            $customer_devices = fetchCustomerDevices($pdo, $customer['id']);
                                            foreach ($customer_devices as $device):
                                            ?>
                                            <li><?= htmlspecialchars($device['type']) ?> - <?= htmlspecialchars($device['brand']) ?> - <?= htmlspecialchars($device['model']) ?> (Σειριακός: <?= htmlspecialchars($device['serial_number']) ?>)</li>
                                            <?php endforeach; ?>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Modal Edit Customer -->
                        <div class="modal fade" id="editCustomerModal<?= $customer['id'] ?>" tabindex="-1" aria-labelledby="editCustomerModalLabel<?= $customer['id'] ?>" aria-hidden="true">
                            <div class="modal-dialog modal-lg">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="editCustomerModalLabel<?= $customer['id'] ?>">Επεξεργασία Πελάτη</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="customers.php" method="post">
                                            <input type="hidden" name="action" value="edit_customer">
                                            <input type="hidden" name="customer_id" value="<?= $customer['id'] ?>">
                                            <div class="form-group">
                                                <label for="full_name">Ονοματεπώνυμο</label>
                                                <input type="text" class="form-control" id="full_name" name="full_name" value="<?= htmlspecialchars($customer['full_name']) ?>" required>
                                            </div>
                                            <div class="form-row">
                                                <div class="form-group col-md-6">
                                                    <label for="landline_phone">Τηλέφωνο Σταθερό</label>
                                                    <input type="text" class="form-control" id="landline_phone" name="landline_phone" value="<?= htmlspecialchars($customer['landline_phone']) ?>">
                                                </div>
                                                <div class="form-group col-md-6">
                                                    <label for="cellphone_number">Αριθμός Κινητού</label>
                                                    <input type="text" class="form-control" id="cellphone_number" name="cellphone_number" value="<?= htmlspecialchars($customer['cellphone_number']) ?>">
                                                </div>
                                            </div>
                                            <h3 class="mt-4">Συσκευές σε Κατοχή:</h3>
                                            <div id="edit_device_list<?= $customer['id'] ?>">
                                                <?php
                                                $editDevices = fetchCustomerDevices($pdo, $customer['id']);
                                                foreach ($editDevices as $index => $device):
                                                ?>
                                                <div class="device-item d-flex align-items-end">
                                                    <div class="form-group mr-2">
                                                        <label>Επιλογή Συσκευής</label>
                                                        <select class="form-control device-select" name="devices[<?= $index ?>][device_id]" required>
                                                            <option value="" disabled>Επιλέξτε συσκευή</option>
                                                            <option value="none" <?= $device['device_id'] == 'none' ? 'selected' : '' ?>>Χωρίς συσκευή</option>
                                                            <?php foreach ($devices as $d): ?>
                                                                <option value="<?= $d['id'] ?>" <?= $d['id'] == $device['device_id'] ? 'selected' : '' ?>><?= $d['type'] ?> - <?= $d['brand'] ?> - <?= $d['model'] ?></option>
                                                            <?php endforeach; ?>
                                                        </select>
                                                    </div>
                                                    <div class="form-group">
                                                        <label>Σειριακός Αριθμός</label>
                                                        <input type="text" class="form-control serial-number" name="devices[<?= $index ?>][serial_number]" value="<?= htmlspecialchars($device['serial_number']) ?>" <?= $device['device_id'] == 'none' ? 'disabled' : '' ?>>
                                                    </div>
                                                    <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">&times;</button>
                                                </div>
                                                <?php endforeach; ?>
                                            </div>
                                            <button type="button" class="btn btn-outline-danger mt-2 add-edit-device" data-customer-id="<?= $customer['id'] ?>">Προσθήκη Άλλης Συσκευής</button>
                                            <button type="submit" class="btn btn-outline-danger mt-2 ml-2">Αποθήκευση Αλλαγών</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Modal Delete Customer -->
                        <div class="modal fade" id="deleteCustomerModal<?= $customer['id'] ?>" tabindex="-1" aria-labelledby="deleteCustomerModalLabel<?= $customer['id'] ?>" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="deleteCustomerModalLabel<?= $customer['id'] ?>">Διαγραφή Πελάτη</h5>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                    <div class="modal-body">
                                        <p>Είστε σίγουροι ότι θέλετε να διαγράψετε τον πελάτη: <strong><?= htmlspecialchars($customer['full_name']) ?></strong>;</p>
                                        <form action="customers.php" method="post">
                                            <input type="hidden" name="action" value="delete_customer">
                                            <input type="hidden" name="customer_id" value="<?= $customer['id'] ?>">
                                            <button type="submit" class="btn btn-danger">Διαγραφή</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else: ?>
                <p>Δεν βρέθηκαν πελάτες.</p>
            <?php endif; ?>
        </div>
    </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/@popperjs/core@2.5.4/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() {
            function initializeSelect2() {
                $('.device-select').select2({
                    placeholder: 'Επιλέξτε συσκευή ή πληκτρολογήστε για αναζήτηση',
                    allowClear: true
                });
            }

            initializeSelect2();

            $('.modal').on('shown.bs.modal', function() {
                $(this).find('.device-select').select2({
                    placeholder: 'Επιλέξτε συσκευή ή πληκτρολογήστε για αναζήτηση',
                    allowClear: true
                });
            });

            $('#add_device').on('click', function() {
                let index = $('#device_list .device-item').length;
                $('#device_list').append(`
                    <div class="device-item d-flex align-items-end">
                        <div class="form-group mr-2">
                            <label>Επιλογή Συσκευής</label>
                            <select class="form-control device-select" name="devices[${index}][device_id]" required>
                                <option value="" disabled selected>Επιλέξτε συσκευή</option>
                                <option value="none">Χωρίς συσκευή</option>
                                <?php foreach ($devices as $device): ?>
                                    <option value="<?= $device['id'] ?>"><?= $device['type'] ?> - <?= $device['brand'] ?> - <?= $device['model'] ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>Σειριακός Αριθμός</label>
                            <input type="text" class="form-control serial-number" name="devices[${index}][serial_number]" required>
                        </div>
                        <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">&times;</button>
                    </div>`);
                initializeSelect2();
            });

            $(document).on('click', '.add-edit-device', function() {
                const customerId = $(this).data('customer-id');
                let index = $('#edit_device_list' + customerId + ' .device-item').length;
                $('#edit_device_list' + customerId).append(`
                    <div class="device-item d-flex align-items-end">
                        <div class="form-group mr-2">
                            <label>Επιλογή Συσκευής</label>
                            <select class="form-control device-select" name="devices[${index}][device_id]" required>
                                <option value="" disabled selected>Επιλέξτε συσκευή</option>
                                <option value="none">Χωρίς συσκευή</option>
                                <?php foreach ($devices as $device): ?>
                                    <option value="<?= $device['id'] ?>"><?= $device['type'] ?> - <?= $device['brand'] ?> - <?= $device['model'] ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>Σειριακός Αριθμός</label>
                            <input type="text" class="form-control serial-number" name="devices[${index}][serial_number]" required>
                        </div>
                        <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">&times;</button>
                    </div>`);
                initializeSelect2();
            });

            $('#customerSearch').on('input', function() {
                const filter = this.value.toLowerCase();
                $('#customerTable tr').filter(function() {
                    $(this).toggle($(this).text().toLowerCase().indexOf(filter) > -1)
                });
            });

            window.printCustomer = function(customerId) {
                window.open('generate_customer_pdf.php?id=' + customerId, '_blank');
            };
        });

        function toggleSerialInput(selectElement) {
            const serialInput = $(selectElement).closest('.device-item').find('.serial-number');
            if (selectElement.value === 'none') {
                serialInput.val('');
                serialInput.prop('disabled', true);
            } else {
                serialInput.prop('disabled', false);
            }
        }

        function removeDevice(button) {
            $(button).closest('.device-item').remove();
        }
    </script>
</body>
</html>


db for reference in case needed provide sql with alter to fix the sql as well : 

-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Oct 30, 2024 at 09:59 AM
-- Server version: 10.4.32-MariaDB
-- PHP Version: 8.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `tech_store`
--

-- --------------------------------------------------------

--
-- Table structure for table `customers`
--

CREATE TABLE `customers` (
  `id` int(11) NOT NULL,
  `full_name` varchar(100) NOT NULL,
  `landline_phone` varchar(20) DEFAULT NULL,
  `cellphone_number` varchar(20) DEFAULT NULL,
  `registration_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `customer_devices`
--

CREATE TABLE `customer_devices` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  `device_id` int(11) DEFAULT NULL,
  `serial_number` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `devices`
--

CREATE TABLE `devices` (
  `id` int(11) NOT NULL,
  `type` varchar(50) NOT NULL,
  `brand` varchar(50) NOT NULL,
  `model` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `services`
--

CREATE TABLE `services` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `service_number` varchar(50) DEFAULT NULL,
  `service_date` date DEFAULT NULL,
  `comments` text DEFAULT NULL,
  `technician_comments` text DEFAULT NULL,
  `amount_paid` decimal(10,2) DEFAULT NULL,
  `device_id` int(11) DEFAULT NULL,
  `status` varchar(50) DEFAULT NULL,
  `delivered_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `settings`
--

CREATE TABLE `settings` (
  `id` int(11) NOT NULL,
  `store_name` varchar(100) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `phone_number` varchar(20) DEFAULT NULL,
  `logo_path` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `customer_devices`
--
ALTER TABLE `customer_devices`
  ADD PRIMARY KEY (`id`),
  ADD KEY `customer_devices_ibfk_1` (`customer_id`),
  ADD KEY `customer_devices_ibfk_2` (`device_id`);

--
-- Indexes for table `devices`
--
ALTER TABLE `devices`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `services`
--
ALTER TABLE `services`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `service_number` (`service_number`),
  ADD KEY `services_ibfk_1` (`customer_id`),
  ADD KEY `services_ibfk_2` (`device_id`);

--
-- Indexes for table `settings`
--
ALTER TABLE `settings`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `customer_devices`
--
ALTER TABLE `customer_devices`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `devices`
--
ALTER TABLE `devices`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `services`
--
ALTER TABLE `services`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `settings`
--
ALTER TABLE `settings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `customer_devices`
--
ALTER TABLE `customer_devices`
  ADD CONSTRAINT `customer_devices_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `customer_devices_ibfk_2` FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`);

--
-- Constraints for table `services`
--
ALTER TABLE `services`
  ADD CONSTRAINT `services_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `services_ibfk_2` FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;