| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <!DOCTYPE html>
- <html lang="fr">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Clients - dirCops</title>
- <script src="https://cdn.tailwindcss.com"></script>
- </head>
- <body class="bg-gray-50 min-h-screen">
- <div class="max-w-4xl mx-auto px-4 py-8">
- <header class="flex justify-between items-center mb-8">
- <h1 class="text-2xl font-semibold text-gray-800">dirCops</h1>
- <nav class="space-x-4">
- <a href="index.html" class="text-blue-600 font-medium">Clients</a>
- <a href="dashboard.html" class="text-gray-600 hover:text-blue-600">Tableau de bord</a>
- <a href="top-clients.html" class="text-gray-600 hover:text-blue-600">Top clients</a>
- <a href="quantites-clients.html" class="text-gray-600 hover:text-blue-600">Quantités</a>
- </nav>
- </header>
- <div id="error-message" class="hidden mb-4 p-3 bg-red-100 text-red-700 rounded"></div>
- <section class="bg-white rounded-lg shadow p-6 mb-6">
- <h2 class="text-lg font-medium text-gray-800 mb-4">Ajouter un client</h2>
- <form id="form-client" class="flex gap-4 items-end">
- <div class="flex-1">
- <label for="nom_client" class="block text-sm text-gray-600 mb-1">Nom du client</label>
- <input type="text" id="nom_client" name="nom" class="w-full border border-gray-300 rounded px-3 py-2" placeholder="Ex: AQUANARIA" required>
- </div>
- <button type="submit" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">Ajouter</button>
- </form>
- </section>
- <div class="mb-6">
- <label for="search" class="block text-sm font-medium text-gray-700 mb-1">Rechercher un client</label>
- <input type="text" id="search" placeholder="Nom du client..." class="w-full max-w-md border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
- </div>
- <div id="client-list" class="bg-white rounded-lg shadow overflow-hidden">
- <table class="min-w-full divide-y divide-gray-200">
- <thead class="bg-gray-100">
- <tr>
- <th class="px-4 py-3 text-left text-xs font-medium text-gray-600 uppercase">Client</th>
- <th class="px-4 py-3 text-right text-xs font-medium text-gray-600 uppercase">Actions</th>
- </tr>
- </thead>
- <tbody id="client-list-body" class="divide-y divide-gray-200">
- <tr><td colspan="2" class="px-4 py-6 text-center text-gray-500">Chargement...</td></tr>
- </tbody>
- </table>
- </div>
- </div>
- <script src="js/utils.js"></script>
- <script>
- const listBody = document.getElementById('client-list-body');
- const searchInput = document.getElementById('search');
- async function loadClients(q = '') {
- hideError();
- try {
- const clients = await apiGet('/clients.php', q ? { q } : {});
- if (clients.length === 0) {
- listBody.innerHTML = '<tr><td colspan="2" class="px-4 py-6 text-center text-gray-500">Aucun client trouvé.</td></tr>';
- return;
- }
- listBody.innerHTML = clients.map(c => {
- const nomEscaped = escapeHtml(c.nom).replace(/'/g, "\\'").replace(/"/g, '"');
- return `
- <tr class="hover:bg-gray-50">
- <td class="px-4 py-3 font-medium text-gray-900">${escapeHtml(c.nom)}</td>
- <td class="px-4 py-3 text-right">
- <a href="client.html?id=${c.id}" class="text-blue-600 hover:underline mr-4">Voir le détail</a>
- <button onclick="deleteClient(${c.id}, ${JSON.stringify(c.nom)})" class="text-red-600 hover:text-red-800" title="Supprimer">
- <svg class="w-4 h-4 inline" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
- </button>
- </td>
- </tr>
- `;
- }).join('');
- } catch (e) {
- showError(e.message);
- listBody.innerHTML = '<tr><td colspan="2" class="px-4 py-6 text-center text-red-500">Erreur de chargement.</td></tr>';
- }
- }
- function escapeHtml(text) {
- const div = document.createElement('div');
- div.textContent = text;
- return div.innerHTML;
- }
- searchInput.addEventListener('input', () => {
- const q = searchInput.value.trim();
- loadClients(q);
- });
- const formClient = document.getElementById('form-client');
- formClient.addEventListener('submit', async (e) => {
- e.preventDefault();
- hideError();
- const nom = document.getElementById('nom_client').value.trim();
- if (!nom) return;
- try {
- await apiPost('/clients.php', { nom });
- document.getElementById('nom_client').value = '';
- loadClients(searchInput.value.trim());
- } catch (err) {
- showError(err.message);
- }
- });
- window.deleteClient = async function(clientId, nomClient) {
- if (!confirm('Êtes-vous sûr de vouloir supprimer le client "' + nomClient + '" ? Cette action supprimera également toutes les factures, paiements et écheanciers associés.')) {
- return;
- }
- try {
- await apiDelete(`/clients.php?id=${clientId}`);
- loadClients(searchInput.value.trim());
- } catch (err) {
- showError(err.message);
- }
- };
- loadClients();
- </script>
- </body>
- </html>
|