quantites-clients.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. (function () {
  2. const typeEl = document.getElementById('type');
  3. const listEl = document.getElementById('quantites-list');
  4. async function load() {
  5. hideError();
  6. const type = typeEl.value || null;
  7. try {
  8. const params = type ? { type } : {};
  9. const data = await apiGet('/quantites-clients.php', params);
  10. if (!data.quantites_par_client || data.quantites_par_client.length === 0) {
  11. listEl.innerHTML = '<p class="text-gray-500">Aucune donnée.</p>';
  12. return;
  13. }
  14. listEl.innerHTML = `
  15. <table class="min-w-full divide-y divide-gray-200">
  16. <thead class="bg-gray-50">
  17. <tr>
  18. <th class="px-4 py-2 text-left text-xs font-medium text-gray-600">Client</th>
  19. <th class="px-4 py-2 text-right text-xs font-medium text-gray-600">Qté facturée</th>
  20. <th class="px-4 py-2 text-right text-xs font-medium text-gray-600">Qté livrée</th>
  21. <th class="px-4 py-2 text-right text-xs font-medium text-gray-600">Actions</th>
  22. </tr>
  23. </thead>
  24. <tbody class="divide-y divide-gray-200">
  25. ${data.quantites_par_client.map(c => `
  26. <tr class="hover:bg-gray-50">
  27. <td class="px-4 py-2 font-medium text-gray-900">${escapeHtml(c.nom)}</td>
  28. <td class="px-4 py-2 text-right">${formatNumber(c.qte_facturee)}</td>
  29. <td class="px-4 py-2 text-right">${formatNumber(c.qte_livree)}</td>
  30. <td class="px-4 py-2 text-right"><a href="client.html?id=${c.client_id}" class="text-blue-600 hover:underline">Voir</a></td>
  31. </tr>
  32. `).join('')}
  33. </tbody>
  34. </table>
  35. `;
  36. } catch (e) {
  37. showError(e.message);
  38. listEl.innerHTML = '<p class="text-red-500">Erreur de chargement.</p>';
  39. }
  40. }
  41. function escapeHtml(text) {
  42. const div = document.createElement('div');
  43. div.textContent = text;
  44. return div.innerHTML;
  45. }
  46. document.getElementById('btn-refresh').addEventListener('click', load);
  47. typeEl.addEventListener('change', load);
  48. load();
  49. })();