clvprod / index.html
CLV-Production's picture
toujours problème de réference pour les factures et devis lorsqu'en click sur les boutons correspondants - Follow Up Deployment
ef74f6a verified
Raw History Blame Contribute Delete
43.4 kB
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Peinture Pro - Devis & Factures</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">
<style>
@page {
size: A4;
margin: 0;
}
@media print {
body * {
visibility: hidden;
}
#document-to-print, #document-to-print * {
visibility: visible;
}
#document-to-print {
position: absolute;
left: 0;
top: 0;
width: 100%;
margin: 0;
padding: 0;
}
.no-print {
display: none !important;
}
}
.fade-in {
animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="bg-blue-600 text-white rounded-lg shadow-md mb-8 p-6">
<div class="flex flex-col md:flex-row justify-between items-center">
<div class="mb-4 md:mb-0">
<h1 class="text-3xl font-bold"><i class="fas fa-paint-roller mr-2"></i>Peinture Pro</h1>
<p class="text-blue-100">Devis & Factures pour peintre en bâtiment</p>
</div>
<div class="flex space-x-4">
<button id="newDocBtn" class="bg-white text-blue-600 px-4 py-2 rounded-lg font-medium hover:bg-blue-50 transition">
<i class="fas fa-plus mr-2"></i>Nouveau
</button>
<button id="saveDocBtn" class="bg-blue-700 text-white px-4 py-2 rounded-lg font-medium hover:bg-blue-800 transition">
<i class="fas fa-save mr-2"></i>Enregistrer
</button>
<button id="printDocBtn" class="bg-blue-800 text-white px-4 py-2 rounded-lg font-medium hover:bg-blue-900 transition">
<i class="fas fa-print mr-2"></i>Imprimer
</button>
</div>
</div>
</header>
<!-- Main Content -->
<div class="flex flex-col lg:flex-row gap-8">
<!-- Sidebar -->
<div class="w-full lg:w-1/3 bg-white rounded-lg shadow-md p-6 no-print">
<h2 class="text-xl font-bold mb-4 text-gray-800 border-b pb-2"><i class="fas fa-cog mr-2"></i>Paramètres</h2>
<div class="mb-6">
<label class="block text-gray-700 font-medium mb-2">Type de document</label>
<div class="flex space-x-4">
<button id="quoteBtn" class="flex-1 bg-blue-600 text-white py-2 px-4 rounded-lg font-medium hover:bg-blue-700 transition">
<i class="fas fa-file-invoice mr-2"></i>Devis
</button>
<button id="invoiceBtn" class="flex-1 bg-gray-300 text-gray-700 py-2 px-4 rounded-lg font-medium hover:bg-gray-400 transition">
<i class="fas fa-file-signature mr-2"></i>Facture
</button>
</div>
</div>
<div class="mb-6">
<label for="docNumber" class="block text-gray-700 font-medium mb-2">Numéro de document</label>
<input type="text" id="docNumber" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div class="mb-6">
<label for="docDate" class="block text-gray-700 font-medium mb-2">Date</label>
<input type="date" id="docDate" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div class="mb-6">
<label for="clientName" class="block text-gray-700 font-medium mb-2">Client</label>
<input type="text" id="clientName" placeholder="Nom du client" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 mb-2">
<input type="text" id="clientAddress" placeholder="Adresse" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 mb-2">
<input type="text" id="clientPhone" placeholder="Téléphone" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div class="mb-6">
<label class="block text-gray-700 font-medium mb-2">TVA</label>
<select id="tvaRate" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="0">0% (TVA non applicable, art. 293B du CGI)</option>
<option value="5.5">5.5%</option>
<option value="10">10%</option>
<option value="20" selected>20%</option>
</select>
</div>
<div class="mb-6">
<label for="paymentConditions" class="block text-gray-700 font-medium mb-2">Conditions de paiement</label>
<input type="text" id="paymentConditions" value="Paiement à réception de la facture" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div class="mb-6">
<label for="projectDescription" class="block text-gray-700 font-medium mb-2">Description du projet</label>
<textarea id="projectDescription" rows="3" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
</div>
<h2 class="text-xl font-bold mb-4 text-gray-800 border-b pb-2"><i class="fas fa-tasks mr-2"></i>Prestations</h2>
<div class="mb-4">
<label for="serviceDescription" class="block text-gray-700 font-medium mb-2">Description</label>
<input type="text" id="serviceDescription" placeholder="Ex: Peinture murale salon" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 mb-2">
</div>
<div class="grid grid-cols-3 gap-4 mb-4">
<div>
<label for="serviceQuantity" class="block text-gray-700 font-medium mb-2">Quantité</label>
<input type="number" id="serviceQuantity" value="1" min="1" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="serviceUnit" class="block text-gray-700 font-medium mb-2">Unité</label>
<select id="serviceUnit" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="m²">m²</option>
<option value="mètre linéaire">mètre linéaire</option>
<option value="pièce">pièce</option>
<option value="heure">heure</option>
<option value="jour">jour</option>
<option value="forfait">forfait</option>
</select>
</div>
<div>
<label for="servicePrice" class="block text-gray-700 font-medium mb-2">Prix unitaire</label>
<input type="number" id="servicePrice" step="0.01" min="0" placeholder="0.00" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
</div>
<button id="addServiceBtn" class="w-full bg-green-600 text-white py-2 px-4 rounded-lg font-medium hover:bg-green-700 transition mb-6">
<i class="fas fa-plus-circle mr-2"></i>Ajouter la prestation
</button>
<div class="bg-gray-100 p-4 rounded-lg">
<h3 class="font-bold text-gray-700 mb-2"><i class="fas fa-info-circle mr-2"></i>Informations auto-entrepreneur</h3>
<div class="mb-2">
<label for="companyName" class="block text-gray-700 text-sm">Nom de l'entreprise</label>
<input type="text" id="companyName" value="Peinture Pro" class="w-full border border-gray-300 rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500">
</div>
<div class="mb-2">
<label for="siret" class="block text-gray-700 text-sm">SIRET</label>
<input type="text" id="siret" placeholder="123 456 789 00012" class="w-full border border-gray-300 rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500">
</div>
<div class="mb-2">
<label for="ape" class="block text-gray-700 text-sm">Code APE/NAF</label>
<input type="text" id="ape" placeholder="4332Z" class="w-full border border-gray-300 rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500">
</div>
<div class="mb-2">
<label for="companyAddress" class="block text-gray-700 text-sm">Adresse</label>
<input type="text" id="companyAddress" placeholder="12 Rue des Peintres, 75000 Paris" class="w-full border border-gray-300 rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500">
</div>
<div class="mb-2">
<label for="companyPhone" class="block text-gray-700 text-sm">Téléphone</label>
<input type="text" id="companyPhone" placeholder="06 12 34 56 78" class="w-full border border-gray-300 rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500">
</div>
<div class="mb-2">
<label for="companyEmail" class="block text-gray-700 text-sm">Email</label>
<input type="email" id="companyEmail" placeholder="contact@peinturepro.fr" class="w-full border border-gray-300 rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500">
</div>
</div>
</div>
<!-- Document Preview -->
<div class="w-full lg:w-2/3">
<div id="document-to-print" class="bg-white rounded-lg shadow-md overflow-hidden fade-in">
<!-- Document Header -->
<div class="p-8 border-b">
<div class="flex justify-between items-start">
<div>
<h1 id="docTypeTitle" class="text-3xl font-bold text-blue-600">DEVIS</h1>
<p id="docTypeSubtitle" class="text-gray-500">Document n°: <span id="docNumberPreview">2023-001</span></p>
</div>
<div class="text-right">
<h2 id="companyNamePreview" class="text-xl font-bold">Peinture Pro</h2>
<p id="companyAddressPreview" class="text-gray-600">12 Rue des Peintres, 75000 Paris</p>
<p id="companyContactPreview" class="text-gray-600">Tél: 06 12 34 56 78 - contact@peinturepro.fr</p>
<p id="companyLegalPreview" class="text-sm text-gray-500">SIRET: 123 456 789 00012 - Code APE: 4332Z</p>
</div>
</div>
</div>
<!-- Client & Document Info -->
<div class="p-8 border-b">
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<div>
<h3 class="text-lg font-semibold text-gray-700 mb-2">Client</h3>
<p id="clientNamePreview" class="font-medium">M. Dupont Jean</p>
<p id="clientAddressPreview" class="text-gray-600">15 Avenue des Champs, 69000 Lyon</p>
<p id="clientPhonePreview" class="text-gray-600">Tél: 06 98 76 54 32</p>
</div>
<div>
<h3 class="text-lg font-semibold text-gray-700 mb-2">Document</h3>
<div class="grid grid-cols-2 gap-4">
<div>
<p class="text-sm text-gray-500">Date</p>
<p id="docDatePreview" class="font-medium">15/06/2023</p>
</div>
<div>
<p class="text-sm text-gray-500">TVA</p>
<p id="tvaRatePreview" class="font-medium">20%</p>
</div>
<div class="col-span-2">
<p class="text-sm text-gray-500">Conditions de paiement</p>
<p id="paymentConditionsPreview" class="font-medium">Paiement à réception de la facture</p>
</div>
</div>
</div>
</div>
</div>
<!-- Project Description -->
<div class="p-8 border-b">
<h3 class="text-lg font-semibold text-gray-700 mb-2">Description du projet</h3>
<p id="projectDescriptionPreview" class="text-gray-600">Rénovation peinture de l'appartement situé au 15 Avenue des Champs, 69000 Lyon. Préparation des supports et application de peinture acrylique mat.</p>
</div>
<!-- Services Table -->
<div class="p-8 border-b">
<h3 class="text-lg font-semibold text-gray-700 mb-4">Détail des prestations</h3>
<div class="overflow-x-auto">
<table class="w-full border-collapse">
<thead>
<tr class="bg-gray-100">
<th class="text-left py-3 px-4 font-medium text-gray-700">Description</th>
<th class="text-right py-3 px-4 font-medium text-gray-700">Quantité</th>
<th class="text-right py-3 px-4 font-medium text-gray-700">Prix unitaire</th>
<th class="text-right py-3 px-4 font-medium text-gray-700">Total HT</th>
</tr>
</thead>
<tbody id="servicesTableBody">
<!-- Services will be added here dynamically -->
</tbody>
<tfoot>
<tr>
<td colspan="3" class="text-right py-3 px-4 font-medium text-gray-700 border-t">Total HT</td>
<td id="totalHT" class="text-right py-3 px-4 font-medium border-t">0.00 €</td>
</tr>
<tr>
<td colspan="3" class="text-right py-3 px-4 font-medium text-gray-700">TVA (<span id="tvaRateValue">20</span>%)</td>
<td id="totalTVA" class="text-right py-3 px-4 font-medium">0.00 €</td>
</tr>
<tr class="bg-gray-50">
<td colspan="3" class="text-right py-3 px-4 font-bold text-gray-800">Total TTC</td>
<td id="totalTTC" class="text-right py-3 px-4 font-bold text-blue-600">0.00 €</td>
</tr>
</tfoot>
</table>
</div>
</div>
<!-- Footer -->
<div class="p-8">
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<div>
<h3 class="text-lg font-semibold text-gray-700 mb-2">Mentions légales</h3>
<p class="text-xs text-gray-500 mb-2" id="legalMentionsQuote" style="display: none;">
Ce devis est valable 30 jours à compter de la date d'émission. En cas d'acceptation, merci de nous retourner ce devis signé.
</p>
<p class="text-xs text-gray-500 mb-2" id="legalMentionsInvoice" style="display: none;">
Facture établie en application du régime micro-fiscal. TVA non applicable selon l'article 293 B du CGI.
</p>
<p class="text-xs text-gray-500">
En cas de retard de paiement, seront exigibles, conformément à l'article L. 441-6 du code de commerce, une indemnité forfaitaire pour frais de recouvrement de 40 euros (article D. 441-5 du code de commerce) ainsi qu'une indemnité calculée sur la base de trois fois le taux d'intérêt légal.
</p>
</div>
<div class="flex flex-col items-center justify-center">
<div class="mb-4">
<p class="text-sm text-gray-500 mb-1">Fait à <span id="docCity">Paris</span>, le <span id="docDateFull">15 juin 2023</span></p>
<p class="text-sm text-gray-500">Signature du client</p>
<div class="h-16 border-b border-gray-300 mt-4 w-48"></div>
</div>
<div>
<p class="text-sm text-gray-500">Signature</p>
<div class="h-16 border-b border-gray-300 mt-4 w-48"></div>
</div>
</div>
</div>
</div>
</div>
<!-- Saved Documents -->
<div class="mt-8 bg-white rounded-lg shadow-md p-6 no-print">
<h2 class="text-xl font-bold mb-4 text-gray-800 border-b pb-2"><i class="fas fa-history mr-2"></i>Documents enregistrés</h2>
<div class="overflow-x-auto">
<table class="w-full border-collapse">
<thead>
<tr class="bg-gray-100">
<th class="text-left py-3 px-4 font-medium text-gray-700">Type</th>
<th class="text-left py-3 px-4 font-medium text-gray-700">N°</th>
<th class="text-left py-3 px-4 font-medium text-gray-700">Client</th>
<th class="text-left py-3 px-4 font-medium text-gray-700">Date</th>
<th class="text-right py-3 px-4 font-medium text-gray-700">Montant</th>
<th class="text-center py-3 px-4 font-medium text-gray-700">Actions</th>
</tr>
</thead>
<tbody id="savedDocumentsBody">
<!-- Saved documents will appear here -->
<tr>
<td colspan="6" class="text-center py-4 text-gray-500">Aucun document enregistré</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Initialize date
const today = new Date();
const formattedDate = today.toISOString().split('T')[0];
document.getElementById('docDate').value = formattedDate;
updateDatePreview(formattedDate);
// Generate document number
generateDocumentNumber();
// Event listeners
document.getElementById('quoteBtn').addEventListener('click', setDocumentTypeQuote);
document.getElementById('invoiceBtn').addEventListener('click', setDocumentTypeInvoice);
document.getElementById('docNumber').addEventListener('input', updateDocNumberPreview);
document.getElementById('docDate').addEventListener('change', function() {
updateDatePreview(this.value);
});
document.getElementById('clientName').addEventListener('input', updateClientPreview);
document.getElementById('clientAddress').addEventListener('input', updateClientPreview);
document.getElementById('clientPhone').addEventListener('input', updateClientPreview);
document.getElementById('tvaRate').addEventListener('change', updateTvaRatePreview);
document.getElementById('paymentConditions').addEventListener('input', updatePaymentConditionsPreview);
document.getElementById('projectDescription').addEventListener('input', updateProjectDescriptionPreview);
document.getElementById('companyName').addEventListener('input', updateCompanyPreview);
document.getElementById('siret').addEventListener('input', updateCompanyPreview);
document.getElementById('ape').addEventListener('input', updateCompanyPreview);
document.getElementById('companyAddress').addEventListener('input', updateCompanyPreview);
document.getElementById('companyPhone').addEventListener('input', updateCompanyPreview);
document.getElementById('companyEmail').addEventListener('input', updateCompanyPreview);
document.getElementById('addServiceBtn').addEventListener('click', addService);
document.getElementById('newDocBtn').addEventListener('click', newDocument);
document.getElementById('saveDocBtn').addEventListener('click', saveDocument);
document.getElementById('printDocBtn').addEventListener('click', printDocument);
// Set default document type to quote
setDocumentTypeQuote();
});
let currentDocumentType = 'quote'; // 'quote' or 'invoice'
let services = [];
let savedDocuments = JSON.parse(localStorage.getItem('savedDocuments')) || [];
function setDocumentTypeQuote() {
currentDocumentType = 'quote';
document.getElementById('quoteBtn').classList.remove('bg-gray-300', 'text-gray-700');
document.getElementById('quoteBtn').classList.add('bg-blue-600', 'text-white');
document.getElementById('invoiceBtn').classList.remove('bg-blue-600', 'text-white');
document.getElementById('invoiceBtn').classList.add('bg-gray-300', 'text-gray-700');
document.getElementById('docTypeTitle').textContent = 'DEVIS';
document.getElementById('docTypeSubtitle').textContent = 'Devis n°: ' + document.getElementById('docNumber').value;
document.getElementById('legalMentionsQuote').style.display = 'block';
document.getElementById('legalMentionsInvoice').style.display = 'none';
generateDocumentNumber();
}
function setDocumentTypeInvoice() {
currentDocumentType = 'invoice';
document.getElementById('invoiceBtn').classList.remove('bg-gray-300', 'text-gray-700');
document.getElementById('invoiceBtn').classList.add('bg-blue-600', 'text-white');
document.getElementById('quoteBtn').classList.remove('bg-blue-600', 'text-white');
document.getElementById('quoteBtn').classList.add('bg-gray-300', 'text-gray-700');
document.getElementById('docTypeTitle').textContent = 'FACTURE';
document.getElementById('docTypeSubtitle').textContent = 'Facture n°: ' + document.getElementById('docNumber').value;
document.getElementById('legalMentionsQuote').style.display = 'none';
document.getElementById('legalMentionsInvoice').style.display = 'block';
generateDocumentNumber();
}
function generateDocumentNumber() {
const now = new Date();
const year = now.getFullYear();
let lastNumber = 0;
// Find the highest number for the current year
savedDocuments.forEach(doc => {
if (doc.type === currentDocumentType && doc.date.startsWith(year.toString())) {
const parts = doc.number.split('-');
const num = parseInt(parts[parts.length - 1]);
if (num > lastNumber) lastNumber = num;
}
});
const newNumber = lastNumber + 1;
const docNumber = currentDocumentType === 'quote'
? `DEV-${year}-${newNumber.toString().padStart(3, '0')}`
: `FAC-${year}-${newNumber.toString().padStart(3, '0')}`;
document.getElementById('docNumber').value = docNumber;
updateDocNumberPreview();
}
function updateDocNumberPreview() {
const docNumber = document.getElementById('docNumber').value;
document.getElementById('docNumberPreview').textContent = docNumber;
if (currentDocumentType === 'quote') {
document.getElementById('docTypeSubtitle').textContent = 'Document n°: ' + docNumber;
} else {
document.getElementById('docTypeSubtitle').textContent = 'Facture n°: ' + docNumber;
}
}
function updateDatePreview(dateString) {
const date = new Date(dateString);
const options = { day: '2-digit', month: '2-digit', year: 'numeric' };
const formattedDate = date.toLocaleDateString('fr-FR', options);
document.getElementById('docDatePreview').textContent = formattedDate;
// Full date for signature
const optionsFull = { day: 'numeric', month: 'long', year: 'numeric' };
document.getElementById('docDateFull').textContent = date.toLocaleDateString('fr-FR', optionsFull);
}
function updateClientPreview() {
document.getElementById('clientNamePreview').textContent = document.getElementById('clientName').value || '-';
document.getElementById('clientAddressPreview').textContent = document.getElementById('clientAddress').value || '-';
document.getElementById('clientPhonePreview').textContent = document.getElementById('clientPhone').value ? 'Tél: ' + document.getElementById('clientPhone').value : '-';
}
function updateTvaRatePreview() {
const tvaRate = document.getElementById('tvaRate').value;
document.getElementById('tvaRatePreview').textContent = tvaRate + '%';
document.getElementById('tvaRateValue').textContent = tvaRate;
calculateTotals();
}
function updatePaymentConditionsPreview() {
document.getElementById('paymentConditionsPreview').textContent = document.getElementById('paymentConditions').value || '-';
}
function updateProjectDescriptionPreview() {
document.getElementById('projectDescriptionPreview').textContent = document.getElementById('projectDescription').value || '-';
}
function updateCompanyPreview() {
document.getElementById('companyNamePreview').textContent = document.getElementById('companyName').value || 'Peinture Pro';
const companyAddress = document.getElementById('companyAddress').value;
const companyPhone = document.getElementById('companyPhone').value;
const companyEmail = document.getElementById('companyEmail').value;
document.getElementById('companyAddressPreview').textContent = companyAddress || '-';
let contactInfo = [];
if (companyPhone) contactInfo.push('Tél: ' + companyPhone);
if (companyEmail) contactInfo.push(companyEmail);
document.getElementById('companyContactPreview').textContent = contactInfo.join(' - ') || '-';
const siret = document.getElementById('siret').value;
const ape = document.getElementById('ape').value;
let legalInfo = [];
if (siret) legalInfo.push('SIRET: ' + siret);
if (ape) legalInfo.push('Code APE: ' + ape);
document.getElementById('companyLegalPreview').textContent = legalInfo.join(' - ') || '-';
}
function addService() {
const description = document.getElementById('serviceDescription').value;
const quantity = parseFloat(document.getElementById('serviceQuantity').value) || 1;
const unit = document.getElementById('serviceUnit').value;
const price = parseFloat(document.getElementById('servicePrice').value) || 0;
if (!description) {
alert('Veuillez saisir une description pour la prestation');
return;
}
const service = {
id: Date.now(),
description: description,
quantity: quantity,
unit: unit,
price: price,
total: quantity * price
};
services.push(service);
renderServices();
// Reset form
document.getElementById('serviceDescription').value = '';
document.getElementById('serviceQuantity').value = '1';
document.getElementById('servicePrice').value = '';
// Focus on description for next entry
document.getElementById('serviceDescription').focus();
}
function renderServices() {
const tbody = document.getElementById('servicesTableBody');
tbody.innerHTML = '';
if (services.length === 0) {
const tr = document.createElement('tr');
tr.innerHTML = '<td colspan="4" class="text-center py-4 text-gray-500">Aucune prestation ajoutée</td>';
tbody.appendChild(tr);
} else {
services.forEach(service => {
const tr = document.createElement('tr');
tr.className = 'border-b border-gray-200 hover:bg-gray-50';
tr.innerHTML = `
<td class="py-3 px-4">
<div class="font-medium">${service.description}</div>
<div class="text-sm text-gray-500">${service.quantity} ${service.unit}</div>
</td>
<td class="text-right py-3 px-4">${service.quantity}</td>
<td class="text-right py-3 px-4">${service.price.toFixed(2)} €</td>
<td class="text-right py-3 px-4">${service.total.toFixed(2)} €</td>
`;
tbody.appendChild(tr);
});
}
calculateTotals();
}
function calculateTotals() {
const totalHT = services.reduce((sum, service) => sum + service.total, 0);
const tvaRate = parseFloat(document.getElementById('tvaRate').value) || 0;
const totalTVA = totalHT * (tvaRate / 100);
const totalTTC = totalHT + totalTVA;
document.getElementById('totalHT').textContent = totalHT.toFixed(2) + ' €';
document.getElementById('totalTVA').textContent = totalTVA.toFixed(2) + ' €';
document.getElementById('totalTTC').textContent = totalTTC.toFixed(2) + ' €';
}
function newDocument() {
if (confirm('Voulez-vous vraiment créer un nouveau document? Les modifications non enregistrées seront perdues.')) {
services = [];
renderServices();
// Reset client fields
document.getElementById('clientName').value = '';
document.getElementById('clientAddress').value = '';
document.getElementById('clientPhone').value = '';
// Reset project description
document.getElementById('projectDescription').value = '';
updateProjectDescriptionPreview();
// Generate new document number
generateDocumentNumber();
// Reset date to today
const today = new Date();
const formattedDate = today.toISOString().split('T')[0];
document.getElementById('docDate').value = formattedDate;
updateDatePreview(formattedDate);
}
}
function saveDocument() {
const docNumber = document.getElementById('docNumber').value;
const docDate = document.getElementById('docDate').value;
const clientName = document.getElementById('clientName').value;
const totalTTC = services.reduce((sum, service) => sum + service.total, 0) * (1 + (parseFloat(document.getElementById('tvaRate').value) || 0) / 100);
if (!clientName) {
alert('Veuillez saisir le nom du client');
return;
}
if (services.length === 0) {
alert('Veuillez ajouter au moins une prestation');
return;
}
const documentData = {
id: Date.now(),
type: currentDocumentType,
number: docNumber,
date: docDate,
client: clientName,
total: totalTTC,
data: {
clientName: document.getElementById('clientName').value,
clientAddress: document.getElementById('clientAddress').value,
clientPhone: document.getElementById('clientPhone').value,
tvaRate: document.getElementById('tvaRate').value,
paymentConditions: document.getElementById('paymentConditions').value,
projectDescription: document.getElementById('projectDescription').value,
companyName: document.getElementById('companyName').value,
siret: document.getElementById('siret').value,
ape: document.getElementById('ape').value,
companyAddress: document.getElementById('companyAddress').value,
companyPhone: document.getElementById('companyPhone').value,
companyEmail: document.getElementById('companyEmail').value,
services: services
}
};
// Remove existing document with same number if it exists
savedDocuments = savedDocuments.filter(doc => doc.number !== docNumber);
savedDocuments.push(documentData);
localStorage.setItem('savedDocuments', JSON.stringify(savedDocuments));
renderSavedDocuments();
alert('Document enregistré avec succès!');
}
function renderSavedDocuments() {
const tbody = document.getElementById('savedDocumentsBody');
tbody.innerHTML = '';
if (savedDocuments.length === 0) {
const tr = document.createElement('tr');
tr.innerHTML = '<td colspan="6" class="text-center py-4 text-gray-500">Aucun document enregistré</td>';
tbody.appendChild(tr);
} else {
// Sort by date (newest first)
const sortedDocuments = [...savedDocuments].sort((a, b) => new Date(b.date) - new Date(a.date));
sortedDocuments.forEach(doc => {
const date = new Date(doc.date);
const formattedDate = date.toLocaleDateString('fr-FR');
const tr = document.createElement('tr');
tr.className = 'border-b border-gray-200 hover:bg-gray-50';
tr.innerHTML = `
<td class="py-3 px-4">${doc.type === 'quote' ? 'Devis' : 'Facture'}</td>
<td class="py-3 px-4">${doc.number}</td>
<td class="py-3 px-4">${doc.client}</td>
<td class="py-3 px-4">${formattedDate}</td>
<td class="text-right py-3 px-4">${doc.total.toFixed(2)} €</td>
<td class="text-center py-3 px-4">
<button class="text-blue-600 hover:text-blue-800 mr-2 load-doc" data-id="${doc.id}">
<i class="fas fa-edit"></i>
</button>
<button class="text-red-600 hover:text-red-800 delete-doc" data-id="${doc.id}">
<i class="fas fa-trash"></i>
</button>
</td>
`;
tbody.appendChild(tr);
});
// Add event listeners to load buttons
document.querySelectorAll('.load-doc').forEach(button => {
button.addEventListener('click', function() {
loadDocument(this.getAttribute('data-id'));
});
});
// Add event listeners to delete buttons
document.querySelectorAll('.delete-doc').forEach(button => {
button.addEventListener('click', function() {
deleteDocument(this.getAttribute('data-id'));
});
});
}
}
function loadDocument(id) {
const doc = savedDocuments.find(d => d.id == id);
if (!doc) return;
// Set document type
if (doc.type === 'quote') {
setDocumentTypeQuote();
} else {
setDocumentTypeInvoice();
}
// Set basic info
document.getElementById('docNumber').value = doc.number;
document.getElementById('docDate').value = doc.date;
// Set client info
document.getElementById('clientName').value = doc.data.clientName || '';
document.getElementById('clientAddress').value = doc.data.clientAddress || '';
document.getElementById('clientPhone').value = doc.data.clientPhone || '';
// Set TVA and payment
document.getElementById('tvaRate').value = doc.data.tvaRate || '20';
document.getElementById('paymentConditions').value = doc.data.paymentConditions || 'Paiement à réception de la facture';
// Set project description
document.getElementById('projectDescription').value = doc.data.projectDescription || '';
// Set company info
document.getElementById('companyName').value = doc.data.companyName || 'Peinture Pro';
document.getElementById('siret').value = doc.data.siret || '';
document.getElementById('ape').value = doc.data.ape || '';
document.getElementById('companyAddress').value = doc.data.companyAddress || '';
document.getElementById('companyPhone').value = doc.data.companyPhone || '';
document.getElementById('companyEmail').value = doc.data.companyEmail || '';
// Set services
services = doc.data.services || [];
// Update all previews
updateDocNumberPreview();
updateDatePreview(doc.date);
updateClientPreview();
updateTvaRatePreview();
updatePaymentConditionsPreview();
updateProjectDescriptionPreview();
updateCompanyPreview();
renderServices();
}
function deleteDocument(id) {
if (confirm('Voulez-vous vraiment supprimer ce document?')) {
savedDocuments = savedDocuments.filter(doc => doc.id != id);
localStorage.setItem('savedDocuments', JSON.stringify(savedDocuments));
renderSavedDocuments();
}
}
function printDocument() {
window.print();
}
// Initial render of saved documents
renderSavedDocuments();
</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=CLV-Production/clvprod" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>