ajoute le téléchargement du facture en image<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Gestion d'Électricité Locale</title> <script src="https://cdn.tailwindcss.com"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <script> tailwind.config = { theme: { extend: { colors: { primary: '#1e40af', secondary: '#f97316', light: '#f8fafc', dark: '#0f172a' } } } } </script> <link rel="stylesheet" href="style.css"> </head> <body class="min-h-screen text-gray-800"> <!-- Header --> <header class="bg-primary text-white shadow-lg"> <div class="container mx-auto px-4 py-6"> <div class="flex flex-col md:flex-row justify-between items-center"> <div class="flex items-center mb-4 md:mb-0"> <i class="fas fa-bolt text-yellow-300 text-2xl mr-3"></i> <h1 class="text-2xl md:text-3xl font-bold">ÉlectriCITÉ</h1> </div> <div class="text-center md:text-right"> <p class="text-sm md:text-base">Gestion locale de la distribution électrique</p> <p class="text-xs mt-1">Système de facturation simplifié</p> </div> </div> </div> </header> <main class="container mx-auto px-4 py-8"> <div class="grid grid-cols-1 lg:grid-cols-2 gap-8"> <!-- Formulaire --> <div class="card bg-white rounded-xl p-6"> <h2 class="text-2xl font-bold text-primary mb-6 flex items-center"> <i class="fas fa-file-invoice mr-3"></i> Formulaire de consommation </h2> <form id="consumptionForm" class="space-y-5"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div> <label for="nom" class="block text-sm font-medium text-gray-700 mb-1">Nom</label> <input type="text" id="nom" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" required> </div> <div> <label for="prenom" class="block text-sm font-medium text-gray-700 mb-1">Prénom</label> <input type="text" id="prenom" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" required> </div> </div> <div> <label for="whatsapp" class="block text-sm font-medium text-gray-700 mb-1">Numéro WhatsApp</label> <input type="tel" id="whatsapp" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" placeholder="221 77 123 45 67" required> </div> <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div> <label for="ancienKw" class="block text-sm font-medium text-gray-700 mb-1">Ancien kW </label> <input type="text" id="ancienKw" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" pattern="[0-9]+([\.,][0-9]+)?" placeholder="0.00" required> </div> <div> <label for="nouveauKw" class="block text-sm font-medium text-gray-700 mb-1">Nouvel kW </label> <input type="text" id="nouveauKw" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" pattern="[0-9]+([\.,][0-9]+)?" placeholder="0.00" required> </div> </div> <div class="bg-blue-50 rounded-lg p-4 border border-blue-100"> <div class="flex items-center"> <i class="fas fa-info-circle text-blue-500 mr-2"></i> <p class="text-sm text-blue-700">Tarif : 300 F CFA par kW consommé</p> </div> </div> <div class="flex flex-col sm:flex-row gap-3 pt-4"> <button type="submit" class="btn-primary text-white font-medium py-3 px-6 rounded-lg flex-1 flex items-center justify-center"> <i class="fas fa-calculator mr-2"></i> Calculer la facture </button> <button type="button" id="historyBtn" class="btn-secondary text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center"> <i class="fas fa-history mr-2"></i> Historique </button> </div> </form> </div> <!-- Facture --> <div class="card bg-white rounded-xl p-6"> <h2 class="text-2xl font-bold text-primary mb-6 flex items-center"> <i class="fas fa-receipt mr-3"></i> Facture de consommation </h2> <div id="invoiceContainer" class="fade-in"> <div class="invoice-header text-white rounded-t-lg p-4 mb-4"> <div class="flex justify-between items-center mb-3"> <div> <h3 class="text-xl font-bold">Facture d'Électricité</h3> <p class="text-sm opacity-90">Date: <span id="invoiceDate">-</span></p> </div> <div class="text-right"> <p class="text-lg font-bold">N°: <span id="invoiceNumber">-</span></p> </div> </div> </div> <div class="mb-6"> <h4 class="text-lg font-semibold text-gray-700 mb-3">Détails du client</h4> <div class="grid grid-cols-2 gap-2 text-sm"> <p class="font-medium">Nom:</p> <p id="invoiceNom">-</p> <p class="font-medium">Prénom:</p> <p id="invoicePrenom">-</p> <p class="font-medium">Téléphone:</p> <p id="invoicePhone">-</p> </div> </div> <div class="mb-6"> <h4 class="text-lg font-semibold text-gray-700 mb-3">Détails de consommation</h4> <div class="space-y-3"> <div class="flex justify-between border-b border-gray-200 pb-2"> <span>Ancien kW :</span> <span id="oldIndex" class="font-medium">-</span> </div> <div class="flex justify-between border-b border-gray-200 pb-2"> <span>Nouvel kW :</span> <span id="newIndex" class="font-medium">-</span> </div> <div class="flex justify-between border-b border-gray-200 pb-2"> <span>Consommation en kW :</span> <span id="consumption" class="font-medium">-</span> </div> <div class="flex justify-between pt-3 text-lg font-bold"> <span>Montant à payer:</span> <span id="amountDue" class="text-secondary">-</span> </div> </div> </div> <div class="bg-gray-50 p-4 rounded-lg text-center"> <p class="text-sm text-gray-600">Merci pour votre règlement dans les plus brefs délais ! </p> </div> <div class="mt-6 flex flex-col sm:flex-row gap-3"> <button id="sendBtn" class="btn-whatsapp text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center"> <i class="fab fa-whatsapp mr-2"></i> Envoyer par WhatsApp </button> <button id="newBillBtn" class="btn-primary text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center"> <i class="fas fa-plus mr-2"></i> Nouvelle facture </button> </div> </div> </div> </div> <!-- Historique --> <div id="historySection" class="card bg-white rounded-xl p-6 mt-8 hidden"> <h2 class="text-2xl font-bold text-primary mb-6 flex items-center"> <i class="fas fa-history mr-3"></i> Historique des factures </h2> <div id="historyList" class="space-y-4 max-h-96 overflow-y-auto pr-2"> <!-- Les éléments d'historique seront insérés ici --> </div> <div class="mt-6 text-center"> <button id="closeHistoryBtn" class="btn-secondary text-white font-medium py-2 px-6 rounded-lg"> Fermer l'historique </button> </div> </div> </main> <footer class="bg-primary text-white py-6 mt-12"> <div class="container mx-auto px-4 text-center"> <p>© 2025 Gestion locale d'électricité</p> <p class="text-sm mt-2 opacity-80">Application de facturation simple et efficace</p> </div> </footer> <script src="script.js"></script> </body> </html> document.addEventListener('DOMContentLoaded', function() { const form = document.getElementById('consumptionForm'); const historyBtn = document.getElementById('historyBtn'); const historySection = document.getElementById('historySection'); const historyList = document.getElementById('historyList'); const closeHistoryBtn = document.getElementById('closeHistoryBtn'); const sendBtn = document.getElementById('sendBtn'); const newBillBtn = document.getElementById('newBillBtn'); const invoiceContainer = document.getElementById('invoiceContainer'); // Variables pour stocker les données let currentBill = {}; let history = JSON.parse(localStorage.getItem('electricityBills')) || []; // Initialiser l'affichage de l'historique updateHistoryDisplay(); // Soumission du formulaire form.addEventListener('submit', function(e) { e.preventDefault(); // Récupérer les valeurs const nom = document.getElementById('nom').value; const prenom = document.getElementById('prenom').value; const whatsapp = document.getElementById('whatsapp').value; let ancienKw = document.getElementById('ancienKw').value.replace(',', '.'); let nouveauKw = document.getElementById('nouveauKw').value.replace(',', '.'); // Vérifier si les valeurs sont des nombres valides if (isNaN(ancienKw) || isNaN(nouveauKw)) { alert('Veuillez entrer des valeurs numériques valides pour les index'); return; } ancienKw = parseFloat(ancienKw); nouveauKw = parseFloat(nouveauKw); // Validation if (nouveauKw <= ancienKw) { alert('Le nouvel index doit être supérieur à l\'ancien index'); return; } // Calculs const consommation = nouveauKw - ancienKw; const montant = consommation * 300; // Formatage de la date const now = new Date(); const dateStr = now.toLocaleDateString('fr-FR'); // Générer un numéro de facture const invoiceNumber = 'FACT-' + (1000 + history.length + 1); // Sauvegarder la facture actuelle currentBill = { id: Date.now(), invoiceNumber: invoiceNumber, nom: nom, prenom: prenom, whatsapp: whatsapp, ancienKw: ancienKw, nouveauKw: nouveauKw, consommation: consommation, montant: montant, date: dateStr }; // Mettre à jour l'affichage de la facture document.getElementById('invoiceDate').textContent = dateStr; document.getElementById('invoiceNumber').textContent = invoiceNumber; document.getElementById('invoiceNom').textContent = nom; document.getElementById('invoicePrenom').textContent = prenom; document.getElementById('invoicePhone').textContent = whatsapp; document.getElementById('oldIndex').textContent = ancienKw.toFixed(2); document.getElementById('newIndex').textContent = nouveauKw.toFixed(2); document.getElementById('consumption').textContent = consommation.toFixed(2); document.getElementById('amountDue').textContent = montant.toLocaleString('fr-FR') + ' F CFA'; // Ajouter à l'historique et sauvegarder dans localStorage history.push(currentBill); localStorage.setItem('electricityBills', JSON.stringify(history)); updateHistoryDisplay(); // Afficher la facture invoiceContainer.classList.remove('hidden'); }); // Afficher l'historique historyBtn.addEventListener('click', function() { historySection.classList.remove('hidden'); historySection.scrollIntoView({ behavior: 'smooth' }); }); // Fermer l'historique closeHistoryBtn.addEventListener('click', function() { historySection.classList.add('hidden'); }); // Envoyer par WhatsApp sendBtn.addEventListener('click', function() { if (!currentBill.nom) { alert('Veuillez calculer une facture d\'abord'); return; } const message = `Bonjour, voici votre facture ÉlectriCITÉ : *Facture:* ${currentBill.invoiceNumber} *Date:* ${currentBill.date} *Nom:* ${currentBill.nom} ${currentBill.prenom} *Ancien index:* ${currentBill.ancienKw.toFixed(2)} kW *Nouvel index:* ${currentBill.nouveauKw.toFixed(2)} kW *Consommation:* ${currentBill.consommation.toFixed(2)} kW *Montant à payer:* ${currentBill.montant.toLocaleString('fr-FR')} F CFA Merci pour votre règlement.`; const whatsappUrl = `https://wa.me/${currentBill.whatsapp.replace(/\s/g, '')}?text=${encodeURIComponent(message)}`; window.open(whatsappUrl, '_blank'); }); // Nouvelle facture newBillBtn.addEventListener('click', function() { form.reset(); document.getElementById('invoiceDate').textContent = '-'; document.getElementById('invoiceNumber').textContent = '-'; document.getElementById('invoiceNom').textContent = '-'; document.getElementById('invoicePrenom').textContent = '-'; document.getElementById('invoicePhone').textContent = '-'; document.getElementById('oldIndex').textContent = '-'; document.getElementById('newIndex').textContent = '-'; document.getElementById('consumption').textContent = '-'; document.getElementById('amountDue').textContent = '-'; }); // Mettre à jour l'affichage de l'historique function updateHistoryDisplay() { if (history.length === 0) { historyList.innerHTML = ` <div class="text-center py-8"> <i class="fas fa-inbox text-4xl text-gray-300 mb-4"></i> <p class="text-gray-500">Aucune facture dans l'historique</p> </div> `; return; } // Trier par date (plus récent en premier) const sortedHistory = [...history].sort((a, b) => b.id - a.id); let html = ''; sortedHistory.forEach((bill, index) => { html += ` <div class="history-item bg-gray-50 rounded-lg p-4 border border-gray-200"> <div class="flex justify-between items-start"> <div> <h3 class="font-bold text-lg">${bill.nom} ${bill.prenom}</h3> <p class="text-sm text-gray-600">Facture: ${bill.invoiceNumber} - ${bill.date}</p> </div> <span class="bg-secondary text-white text-xs font-bold px-2 py-1 rounded"> ${bill.consommation.toFixed(2)} kW </span> </div> <div class="mt-3 flex justify-between items-center"> <div> <p class="text-sm">Ancien: ${bill.ancienKw.toFixed(2)} kW</p> <p class="text-sm">Nouveau: ${bill.nouveauKw.toFixed(2)} kW</p> </div> <div class="text-right"> <p class="font-bold text-lg">${bill.montant.toLocaleString('fr-FR')} F CFA</p> <p class="text-xs text-gray-500">Tél: ${bill.whatsapp}</p> </div> </div> <div class="mt-3 flex justify-end"> <button class="copy-btn text-primary text-sm font-medium" data-id="${bill.id}"> <i class="fas fa-copy mr-1"></i> Copier </button> </div> </div> `; }); historyList.innerHTML = html; // Ajouter les événements pour les boutons de copie document.querySelectorAll('.copy-btn').forEach(button => { button.addEventListener('click', function() { const id = parseInt(this.getAttribute('data-id')); const bill = history.find(b => b.id === id); if (bill) { const text = `Facture ${bill.invoiceNumber} - ${bill.nom} ${bill.prenom} - ${bill.consommation.toFixed(2)} kW - ${bill.montant.toLocaleString('fr-FR')} F CFA`; navigator.clipboard.writeText(text) .then(() => { const originalText = this.innerHTML; this.innerHTML = '<i class="fas fa-check mr-1"></i> Copié!'; setTimeout(() => { this.innerHTML = originalText; }, 2000); }) .catch(err => { console.error('Erreur lors de la copie: ', err); }); } }); }); } }); @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap'); body { font-family: 'Poppins', sans-serif; background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); } .card { box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); transition: all 0.3s ease; } .card:hover { transform: translateY(-5px); box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); } .btn-primary { background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); transition: all 0.3s ease; } .btn-primary:hover { background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); transform: translateY(-2px); } .btn-secondary { background: linear-gradient(135deg, #f97316 0%, #ea580c 100%); transition: all 0.3s ease; } .btn-secondary:hover { background: linear-gradient(135deg, #ea580c 0%, #dc2626 100%); transform: translateY(-2px); } .btn-whatsapp { background: #25D366; transition: all 0.3s ease; } .btn-whatsapp:hover { background: #128C7E; transform: translateY(-2px); } .invoice-header { background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); } .history-item { border-left: 4px solid #3b82f6; } .history-item:nth-child(2n) { border-left: 4px solid #f97316; } .input-field:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); } .fade-in { animation: fadeIn 0.5s ease-in; } @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } - Initial Deployment
59a7a7b verified Download index.html from RebCode/gestle: direct link, hf CLI and curl.
- Browser
- Download file 23.9 kB
-
https://huggingface.co/spaces/RebCode/gestle/resolve/main/index.html
- Command line
-
hf download hf://spaces/RebCode/gestle/index.html
-
curl -L -o index.html https://huggingface.co/spaces/RebCode/gestle/resolve/main/index.html
23.9 kB
| <html lang="fr"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Gestion d'Électricité Locale</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <script> | |
| tailwind.config = { | |
| theme: { | |
| extend: { | |
| colors: { | |
| primary: '#1e40af', | |
| secondary: '#f97316', | |
| light: '#f8fafc', | |
| dark: '#0f172a' | |
| } | |
| } | |
| } | |
| } | |
| </script> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap'); | |
| body { | |
| font-family: 'Poppins', sans-serif; | |
| background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); | |
| } | |
| .card { | |
| box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); | |
| transition: all 0.3s ease; | |
| } | |
| .card:hover { | |
| transform: translateY(-5px); | |
| box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); | |
| } | |
| .btn-primary { | |
| background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); | |
| transition: all 0.3s ease; | |
| } | |
| .btn-primary:hover { | |
| background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); | |
| transform: translateY(-2px); | |
| } | |
| .btn-secondary { | |
| background: linear-gradient(135deg, #f97316 0%, #ea580c 100%); | |
| transition: all 0.3s ease; | |
| } | |
| .btn-secondary:hover { | |
| background: linear-gradient(135deg, #ea580c 0%, #dc2626 100%); | |
| transform: translateY(-2px); | |
| } | |
| .btn-whatsapp { | |
| background: #25D366; | |
| transition: all 0.3s ease; | |
| } | |
| .btn-whatsapp:hover { | |
| background: #128C7E; | |
| transform: translateY(-2px); | |
| } | |
| .invoice-header { | |
| background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); | |
| } | |
| .history-item { | |
| border-left: 4px solid #3b82f6; | |
| } | |
| .history-item:nth-child(2n) { | |
| border-left: 4px solid #f97316; | |
| } | |
| .input-field:focus { | |
| border-color: #3b82f6; | |
| box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); | |
| } | |
| .fade-in { | |
| animation: fadeIn 0.5s ease-in; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; transform: translateY(10px); } | |
| to { opacity: 1; transform: translateY(0); } | |
| } | |
| </style> | |
| </head> | |
| <body class="min-h-screen text-gray-800"> | |
| <!-- Header --> | |
| <header class="bg-primary text-white shadow-lg"> | |
| <div class="container mx-auto px-4 py-6"> | |
| <div class="flex flex-col md:flex-row justify-between items-center"> | |
| <div class="flex items-center mb-4 md:mb-0"> | |
| <i class="fas fa-bolt text-yellow-300 text-2xl mr-3"></i> | |
| <h1 class="text-2xl md:text-3xl font-bold">ÉlectriCITÉ</h1> | |
| </div> | |
| <div class="text-center md:text-right"> | |
| <p class="text-sm md:text-base">Gestion locale de la distribution électrique</p> | |
| <p class="text-xs mt-1">Système de facturation simplifié</p> | |
| </div> | |
| </div> | |
| </div> | |
| </header> | |
| <main class="container mx-auto px-4 py-8"> | |
| <div class="grid grid-cols-1 lg:grid-cols-2 gap-8"> | |
| <!-- Formulaire --> | |
| <div class="card bg-white rounded-xl p-6"> | |
| <h2 class="text-2xl font-bold text-primary mb-6 flex items-center"> | |
| <i class="fas fa-file-invoice mr-3"></i> | |
| Formulaire de consommation | |
| </h2> | |
| <form id="consumptionForm" class="space-y-5"> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div> | |
| <label for="nom" class="block text-sm font-medium text-gray-700 mb-1">Nom</label> | |
| <input type="text" id="nom" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" required> | |
| </div> | |
| <div> | |
| <label for="prenom" class="block text-sm font-medium text-gray-700 mb-1">Prénom</label> | |
| <input type="text" id="prenom" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" required> | |
| </div> | |
| </div> | |
| <div> | |
| <label for="whatsapp" class="block text-sm font-medium text-gray-700 mb-1">Numéro WhatsApp</label> | |
| <input type="tel" id="whatsapp" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" placeholder="221 77 123 45 67" required> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div> | |
| <label for="ancienKw" class="block text-sm font-medium text-gray-700 mb-1">Ancien indice (kW)</label> | |
| <input type="text" id="ancienKw" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" pattern="[0-9]+([\.,][0-9]+)?" placeholder="0.00" required> | |
| </div> | |
| <div> | |
| <label for="nouveauKw" class="block text-sm font-medium text-gray-700 mb-1">Nouvel indice (kW)</label> | |
| <input type="text" id="nouveauKw" class="input-field w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none" pattern="[0-9]+([\.,][0-9]+)?" placeholder="0.00" required> | |
| </div> | |
| </div> | |
| <div class="bg-blue-50 rounded-lg p-4 border border-blue-100"> | |
| <div class="flex items-center"> | |
| <i class="fas fa-info-circle text-blue-500 mr-2"></i> | |
| <p class="text-sm text-blue-700">Tarif : 300 F CFA par kW consommé</p> | |
| </div> | |
| </div> | |
| <div class="flex flex-col sm:flex-row gap-3 pt-4"> | |
| <button type="submit" class="btn-primary text-white font-medium py-3 px-6 rounded-lg flex-1 flex items-center justify-center"> | |
| <i class="fas fa-calculator mr-2"></i> | |
| Calculer la facture | |
| </button> | |
| <button type="button" id="historyBtn" class="btn-secondary text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center"> | |
| <i class="fas fa-history mr-2"></i> | |
| Historique | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| <!-- Facture --> | |
| <div class="card bg-white rounded-xl p-6"> | |
| <h2 class="text-2xl font-bold text-primary mb-6 flex items-center"> | |
| <i class="fas fa-receipt mr-3"></i> | |
| Facture de consommation | |
| </h2> | |
| <div id="invoiceContainer" class="fade-in"> | |
| <div class="invoice-header text-white rounded-t-lg p-4 mb-4"> | |
| <div class="flex justify-between items-center mb-3"> | |
| <div> | |
| <h3 class="text-xl font-bold">Facture ÉlectriCITÉ</h3> | |
| <p class="text-sm opacity-90">Date: <span id="invoiceDate">-</span></p> | |
| </div> | |
| <div class="text-right"> | |
| <p class="text-lg font-bold">N°: <span id="invoiceNumber">-</span></p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="mb-6"> | |
| <h4 class="text-lg font-semibold text-gray-700 mb-3">Détails du client</h4> | |
| <div class="grid grid-cols-2 gap-2 text-sm"> | |
| <p class="font-medium">Nom:</p> | |
| <p id="invoiceNom">-</p> | |
| <p class="font-medium">Prénom:</p> | |
| <p id="invoicePrenom">-</p> | |
| <p class="font-medium">Téléphone:</p> | |
| <p id="invoicePhone">-</p> | |
| </div> | |
| </div> | |
| <div class="mb-6"> | |
| <h4 class="text-lg font-semibold text-gray-700 mb-3">Détails de consommation</h4> | |
| <div class="space-y-3"> | |
| <div class="flex justify-between border-b border-gray-200 pb-2"> | |
| <span>Ancien index (kW):</span> | |
| <span id="oldIndex" class="font-medium">-</span> | |
| </div> | |
| <div class="flex justify-between border-b border-gray-200 pb-2"> | |
| <span>Nouvel index (kW):</span> | |
| <span id="newIndex" class="font-medium">-</span> | |
| </div> | |
| <div class="flex justify-between border-b border-gray-200 pb-2"> | |
| <span>Consommation (kW):</span> | |
| <span id="consumption" class="font-medium">-</span> | |
| </div> | |
| <div class="flex justify-between pt-3 text-lg font-bold"> | |
| <span>Montant à payer:</span> | |
| <span id="amountDue" class="text-secondary">-</span> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-gray-50 p-4 rounded-lg text-center"> | |
| <p class="text-sm text-gray-600">Merci pour votre règlement dans les 30 jours</p> | |
| </div> | |
| <div class="mt-6 flex flex-col sm:flex-row gap-3"> | |
| <button id="sendBtn" class="btn-whatsapp text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center"> | |
| <i class="fab fa-whatsapp mr-2"></i> | |
| Envoyer par WhatsApp | |
| </button> | |
| <button id="newBillBtn" class="btn-primary text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center"> | |
| <i class="fas fa-plus mr-2"></i> | |
| Nouvelle facture | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Historique --> | |
| <div id="historySection" class="card bg-white rounded-xl p-6 mt-8 hidden"> | |
| <h2 class="text-2xl font-bold text-primary mb-6 flex items-center"> | |
| <i class="fas fa-history mr-3"></i> | |
| Historique des factures | |
| </h2> | |
| <div id="historyList" class="space-y-4 max-h-96 overflow-y-auto pr-2"> | |
| <!-- Les éléments d'historique seront insérés ici --> | |
| </div> | |
| <div class="mt-6 text-center"> | |
| <button id="closeHistoryBtn" class="btn-secondary text-white font-medium py-2 px-6 rounded-lg"> | |
| Fermer l'historique | |
| </button> | |
| </div> | |
| </div> | |
| </main> | |
| <footer class="bg-primary text-white py-6 mt-12"> | |
| <div class="container mx-auto px-4 text-center"> | |
| <p>© 2023 ÉlectriCITÉ - Gestion locale d'électricité</p> | |
| <p class="text-sm mt-2 opacity-80">Application de facturation simple et efficace</p> | |
| </div> | |
| </footer> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const form = document.getElementById('consumptionForm'); | |
| const historyBtn = document.getElementById('historyBtn'); | |
| const historySection = document.getElementById('historySection'); | |
| const historyList = document.getElementById('historyList'); | |
| const closeHistoryBtn = document.getElementById('closeHistoryBtn'); | |
| const sendBtn = document.getElementById('sendBtn'); | |
| const newBillBtn = document.getElementById('newBillBtn'); | |
| const invoiceContainer = document.getElementById('invoiceContainer'); | |
| // Variables pour stocker les données | |
| let currentBill = {}; | |
| let history = JSON.parse(localStorage.getItem('electricityBills')) || []; | |
| // Initialiser l'affichage de l'historique | |
| updateHistoryDisplay(); | |
| // Soumission du formulaire | |
| form.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| // Récupérer les valeurs | |
| const nom = document.getElementById('nom').value; | |
| const prenom = document.getElementById('prenom').value; | |
| const whatsapp = document.getElementById('whatsapp').value; | |
| let ancienKw = document.getElementById('ancienKw').value.replace(',', '.'); | |
| let nouveauKw = document.getElementById('nouveauKw').value.replace(',', '.'); | |
| // Vérifier si les valeurs sont des nombres valides | |
| if (isNaN(ancienKw) || isNaN(nouveauKw)) { | |
| alert('Veuillez entrer des valeurs numériques valides pour les index'); | |
| return; | |
| } | |
| ancienKw = parseFloat(ancienKw); | |
| nouveauKw = parseFloat(nouveauKw); | |
| // Validation | |
| if (nouveauKw <= ancienKw) { | |
| alert('Le nouvel index doit être supérieur à l\'ancien index'); | |
| return; | |
| } | |
| // Calculs | |
| const consommation = nouveauKw - ancienKw; | |
| const montant = consommation * 300; | |
| // Formatage de la date | |
| const now = new Date(); | |
| const dateStr = now.toLocaleDateString('fr-FR'); | |
| // Générer un numéro de facture | |
| const invoiceNumber = 'FACT-' + (1000 + history.length + 1); | |
| // Sauvegarder la facture actuelle | |
| currentBill = { | |
| id: Date.now(), | |
| invoiceNumber: invoiceNumber, | |
| nom: nom, | |
| prenom: prenom, | |
| whatsapp: whatsapp, | |
| ancienKw: ancienKw, | |
| nouveauKw: nouveauKw, | |
| consommation: consommation, | |
| montant: montant, | |
| date: dateStr | |
| }; | |
| // Mettre à jour l'affichage de la facture | |
| document.getElementById('invoiceDate').textContent = dateStr; | |
| document.getElementById('invoiceNumber').textContent = invoiceNumber; | |
| document.getElementById('invoiceNom').textContent = nom; | |
| document.getElementById('invoicePrenom').textContent = prenom; | |
| document.getElementById('invoicePhone').textContent = whatsapp; | |
| document.getElementById('oldIndex').textContent = ancienKw.toFixed(2); | |
| document.getElementById('newIndex').textContent = nouveauKw.toFixed(2); | |
| document.getElementById('consumption').textContent = consommation.toFixed(2); | |
| document.getElementById('amountDue').textContent = montant.toLocaleString('fr-FR') + ' F CFA'; | |
| // Ajouter à l'historique et sauvegarder dans localStorage | |
| history.push(currentBill); | |
| localStorage.setItem('electricityBills', JSON.stringify(history)); | |
| updateHistoryDisplay(); | |
| // Afficher la facture | |
| invoiceContainer.classList.remove('hidden'); | |
| }); | |
| // Afficher l'historique | |
| historyBtn.addEventListener('click', function() { | |
| historySection.classList.remove('hidden'); | |
| historySection.scrollIntoView({ behavior: 'smooth' }); | |
| }); | |
| // Fermer l'historique | |
| closeHistoryBtn.addEventListener('click', function() { | |
| historySection.classList.add('hidden'); | |
| }); | |
| // Envoyer par WhatsApp | |
| sendBtn.addEventListener('click', function() { | |
| if (!currentBill.nom) { | |
| alert('Veuillez calculer une facture d\'abord'); | |
| return; | |
| } | |
| const message = `Bonjour, voici votre facture ÉlectriCITÉ : | |
| *Facture:* ${currentBill.invoiceNumber} | |
| *Date:* ${currentBill.date} | |
| *Nom:* ${currentBill.nom} ${currentBill.prenom} | |
| *Ancien index:* ${currentBill.ancienKw.toFixed(2)} kW | |
| *Nouvel index:* ${currentBill.nouveauKw.toFixed(2)} kW | |
| *Consommation:* ${currentBill.consommation.toFixed(2)} kW | |
| *Montant à payer:* ${currentBill.montant.toLocaleString('fr-FR')} F CFA | |
| Merci pour votre règlement.`; | |
| const whatsappUrl = `https://wa.me/${currentBill.whatsapp.replace(/\s/g, '')}?text=${encodeURIComponent(message)}`; | |
| window.open(whatsappUrl, '_blank'); | |
| }); | |
| // Nouvelle facture | |
| newBillBtn.addEventListener('click', function() { | |
| form.reset(); | |
| document.getElementById('invoiceDate').textContent = '-'; | |
| document.getElementById('invoiceNumber').textContent = '-'; | |
| document.getElementById('invoiceNom').textContent = '-'; | |
| document.getElementById('invoicePrenom').textContent = '-'; | |
| document.getElementById('invoicePhone').textContent = '-'; | |
| document.getElementById('oldIndex').textContent = '-'; | |
| document.getElementById('newIndex').textContent = '-'; | |
| document.getElementById('consumption').textContent = '-'; | |
| document.getElementById('amountDue').textContent = '-'; | |
| }); | |
| // Mettre à jour l'affichage de l'historique | |
| function updateHistoryDisplay() { | |
| if (history.length === 0) { | |
| historyList.innerHTML = ` | |
| <div class="text-center py-8"> | |
| <i class="fas fa-inbox text-4xl text-gray-300 mb-4"></i> | |
| <p class="text-gray-500">Aucune facture dans l'historique</p> | |
| </div> | |
| `; | |
| return; | |
| } | |
| // Trier par date (plus récent en premier) | |
| const sortedHistory = [...history].sort((a, b) => b.id - a.id); | |
| let html = ''; | |
| sortedHistory.forEach((bill, index) => { | |
| html += ` | |
| <div class="history-item bg-gray-50 rounded-lg p-4 border border-gray-200"> | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <h3 class="font-bold text-lg">${bill.nom} ${bill.prenom}</h3> | |
| <p class="text-sm text-gray-600">Facture: ${bill.invoiceNumber} - ${bill.date}</p> | |
| </div> | |
| <span class="bg-secondary text-white text-xs font-bold px-2 py-1 rounded"> | |
| ${bill.consommation.toFixed(2)} kW | |
| </span> | |
| </div> | |
| <div class="mt-3 flex justify-between items-center"> | |
| <div> | |
| <p class="text-sm">Ancien: ${bill.ancienKw.toFixed(2)} kW</p> | |
| <p class="text-sm">Nouveau: ${bill.nouveauKw.toFixed(2)} kW</p> | |
| </div> | |
| <div class="text-right"> | |
| <p class="font-bold text-lg">${bill.montant.toLocaleString('fr-FR')} F CFA</p> | |
| <p class="text-xs text-gray-500">Tél: ${bill.whatsapp}</p> | |
| </div> | |
| </div> | |
| <div class="mt-3 flex justify-end"> | |
| <button class="copy-btn text-primary text-sm font-medium" data-id="${bill.id}"> | |
| <i class="fas fa-copy mr-1"></i> Copier | |
| </button> | |
| </div> | |
| </div> | |
| `; | |
| }); | |
| historyList.innerHTML = html; | |
| // Ajouter les événements pour les boutons de copie | |
| document.querySelectorAll('.copy-btn').forEach(button => { | |
| button.addEventListener('click', function() { | |
| const id = parseInt(this.getAttribute('data-id')); | |
| const bill = history.find(b => b.id === id); | |
| if (bill) { | |
| const text = `Facture ${bill.invoiceNumber} - ${bill.nom} ${bill.prenom} - ${bill.consommation.toFixed(2)} kW - ${bill.montant.toLocaleString('fr-FR')} F CFA`; | |
| navigator.clipboard.writeText(text) | |
| .then(() => { | |
| const originalText = this.innerHTML; | |
| this.innerHTML = '<i class="fas fa-check mr-1"></i> Copié!'; | |
| setTimeout(() => { | |
| this.innerHTML = originalText; | |
| }, 2000); | |
| }) | |
| .catch(err => { | |
| console.error('Erreur lors de la copie: ', err); | |
| }); | |
| } | |
| }); | |
| }); | |
| } | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=RebCode/gestle" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |