(function ($) { 'use strict'; $(function () { // Bouton de test de connexion sur la page de configuration var $testBtn = $('#esi-peppol-test-connection'); if ($testBtn.length && typeof window.esiPeppolAdmin !== 'undefined') { var $result = $('#esi-peppol-test-result'); $testBtn.on('click', function (e) { e.preventDefault(); var apiKey = $('#esi_peppol_api_key').val(); var password = $('#esi_peppol_password').val(); $result.removeClass().empty(); if (!apiKey || !password) { var msgMissing = window.esiPeppolAdmin.i18n_missing || "Veuillez renseigner l'API Key et le Password avant de tester la connexion."; $result .addClass('notice notice-error') .html('
' + msgMissing + '
'); return; } $testBtn.prop('disabled', true).addClass('updating-message'); $.post(window.esiPeppolAdmin.ajax_url, { action: 'esi_peppol_test_connection', nonce: window.esiPeppolAdmin.nonce, api_key: apiKey, password: password }) .done(function (response) { if (response && response.success) { var msg = (response.data && response.data.message) ? response.data.message : (window.esiPeppolAdmin.i18n_success || "Connexion réussie à l'API ESIPeppol."); $result .addClass('notice notice-success is-dismissible') .html('' + msg + '
'); } else { var errMsg = (response && response.data && response.data.message) ? response.data.message : (window.esiPeppolAdmin.i18n_error || 'La connexion a échoué.'); $result .addClass('notice notice-error') .html('' + errMsg + '
'); } }) .fail(function () { var msgNetwork = window.esiPeppolAdmin.i18n_network || 'Erreur de communication avec le serveur WordPress.'; $result .addClass('notice notice-error') .html('' + msgNetwork + '
'); }) .always(function () { $testBtn.prop('disabled', false).removeClass('updating-message'); }); }); } // DataTables pour le tableau du journal des échanges (invoices / documents envoyés) var $logsTable = $('#esi-peppol-logs-table'); if ($logsTable.length && $.fn.DataTable) { $logsTable.DataTable({ pageLength: 25, order: [[0, 'desc']], language: { url: 'https://cdn.datatables.net/plug-ins/1.13.8/i18n/fr-FR.json' } }); } // Actions AJAX sur la page de logs : renvoyer / vérifier le statut if ($logsTable.length && typeof window.esiPeppolAdmin !== 'undefined') { var $logsResult = $('#esi-peppol-logs-result'); var showLogsNotice = function (type, title, message, detail) { var classes = 'notice'; if (type === 'success') { classes += ' notice-success is-dismissible'; } else if (type === 'error') { classes += ' notice-error'; } else { classes += ' notice-info'; } var html = '' + title + ' ' + (message || '') + '
'; } else if (message) { html += '' + message + '
'; } if (detail) { html += '' + (window.esiPeppolAdmin.i18n_logs_detail_lbl || "Détail retour API") + ': ' + detail + '
'; } html += '| Succès | ' + (data.success ? 'Oui' : 'Non') + ' |
|---|---|
| Message | ' + (data.message || '-') + ' |
| Nom / Raison sociale | ' + customerName + ' |
|---|---|
| Nom légal | ' + customerLegalName + ' |
| Numéro TVA | ' + customerVat + ' |
| ' + customerEmail + ' | |
| Téléphone | ' + customerPhone + ' |
| Adresse | ';
html += addressLine1;
if (addressLine2) {
html += ' ' + addressLine2; } html += ' ' + postalCode + ' ' + city; html += ' ' + countryCode; html += ' |
| Taux TVA | Montant HTVA | Montant TVA | Montant TVAC |
|---|---|---|---|
| ' + vatRate.toFixed(2) + ' % | '; html += '' + taxableAmount.toFixed(2) + ' € | '; html += '' + vatAmount.toFixed(2) + ' € | '; html += '' + totalInclVat.toFixed(2) + ' € | '; html += '
| Total HTVA | ' + totalHTVA.toFixed(2) + ' € |
|---|---|
| Total TVA | ' + totalTVA.toFixed(2) + ' € |
| Total TVAC | ' + totalTVAC.toFixed(2) + ' € |
| Montant à payer | ' + payableAmount.toFixed(2) + ' € |
' + errorMsg + '
').show(); } }) .fail(function () { $modalLoading.hide(); var errorMsg = window.esiPeppolAdmin.i18n_network || 'Erreur de communication avec le serveur WordPress.'; $modalDetailsContent.html('' + errorMsg + '
').show(); }); }); } }); })(jQuery);