| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- (function () {
- const typeEl = document.getElementById('type');
- const listEl = document.getElementById('quantites-list');
- async function load() {
- hideError();
- const type = typeEl.value || null;
- try {
- const params = type ? { type } : {};
- const data = await apiGet('/quantites-clients.php', params);
- if (!data.quantites_par_client || data.quantites_par_client.length === 0) {
- listEl.innerHTML = '<p class="text-gray-500">Aucune donnée.</p>';
- return;
- }
- listEl.innerHTML = `
- <table class="min-w-full divide-y divide-gray-200">
- <thead class="bg-gray-50">
- <tr>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-600">Client</th>
- <th class="px-4 py-2 text-right text-xs font-medium text-gray-600">Qté facturée</th>
- <th class="px-4 py-2 text-right text-xs font-medium text-gray-600">Qté livrée</th>
- <th class="px-4 py-2 text-right text-xs font-medium text-gray-600">Actions</th>
- </tr>
- </thead>
- <tbody class="divide-y divide-gray-200">
- ${data.quantites_par_client.map(c => `
- <tr class="hover:bg-gray-50">
- <td class="px-4 py-2 font-medium text-gray-900">${escapeHtml(c.nom)}</td>
- <td class="px-4 py-2 text-right">${formatNumber(c.qte_facturee)}</td>
- <td class="px-4 py-2 text-right">${formatNumber(c.qte_livree)}</td>
- <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>
- </tr>
- `).join('')}
- </tbody>
- </table>
- `;
- } catch (e) {
- showError(e.message);
- listEl.innerHTML = '<p class="text-red-500">Erreur de chargement.</p>';
- }
- }
- function escapeHtml(text) {
- const div = document.createElement('div');
- div.textContent = text;
- return div.innerHTML;
- }
- document.getElementById('btn-refresh').addEventListener('click', load);
- typeEl.addEventListener('change', load);
- load();
- })();
|