Ajout colonne + détail commande
This commit is contained in:
parent
ddda1111d1
commit
3b2dde9664
@ -40,6 +40,14 @@ class PEPPOL_Plugin {
|
|||||||
|
|
||||||
// Notice globale pour le numéro de TVA
|
// Notice globale pour le numéro de TVA
|
||||||
\add_action('admin_notices', [self::class, 'maybe_show_vat_notice']);
|
\add_action('admin_notices', [self::class, 'maybe_show_vat_notice']);
|
||||||
|
|
||||||
|
// Ajouter une colonne "Statut Peppol" dans le listing des commandes WooCommerce
|
||||||
|
if (class_exists(\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::class)) {
|
||||||
|
\add_filter('manage_edit-shop_order_columns', [\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::class, 'add_peppol_status_column'], 20);
|
||||||
|
\add_filter('manage_woocommerce_page_wc-orders_columns', [\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::class, 'add_peppol_status_column'], 20);
|
||||||
|
\add_action('manage_shop_order_posts_custom_column', [\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::class, 'show_peppol_status_column'], 10, 2);
|
||||||
|
\add_action('manage_woocommerce_page_wc-orders_custom_column', [\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::class, 'show_peppol_status_column'], 10, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,24 +191,181 @@ class PEPPOL_Plugin {
|
|||||||
wp_die(esc_html__('Vous n\'avez pas les permissions nécessaires pour accéder à cette page.', 'esi_peppol'));
|
wp_die(esc_html__('Vous n\'avez pas les permissions nécessaires pour accéder à cette page.', 'esi_peppol'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupération des dernières lignes de la table custom
|
// Vérifier si on affiche la page de détail
|
||||||
$rows = PEPPOL_Main_model::get_recent(50);
|
$detail_id = isset($_GET['detail']) ? (int) $_GET['detail'] : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||||
|
|
||||||
$template = ESI_PEPPOL_DIR . 'templates/admin/logs.php';
|
if ($detail_id > 0) {
|
||||||
|
// Afficher la page de détail
|
||||||
|
$row = PEPPOL_Main_model::get_by_id($detail_id);
|
||||||
|
|
||||||
if (file_exists($template)) {
|
if (!$row) {
|
||||||
/** @noinspection PhpIncludeInspection */
|
wp_die(esc_html__('Aucun enregistrement Peppol trouvé pour cet ID.', 'esi_peppol'));
|
||||||
include $template;
|
}
|
||||||
|
|
||||||
|
// Préparer les données pour l'affichage (même logique que ajax_get_log_details)
|
||||||
|
$data_sent = $row->data_sent ?? null;
|
||||||
|
$response_data = $row->response_data ?? null;
|
||||||
|
|
||||||
|
// Formater les données JSON si possible
|
||||||
|
$data_sent_formatted = '';
|
||||||
|
if ($data_sent) {
|
||||||
|
if (is_array($data_sent) || is_object($data_sent)) {
|
||||||
|
$data_sent_formatted = wp_json_encode($data_sent, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
} else {
|
||||||
|
$data_sent_formatted = (string) $data_sent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response_data_formatted = '';
|
||||||
|
if ($response_data) {
|
||||||
|
if (is_array($response_data) || is_object($response_data)) {
|
||||||
|
$response_data_formatted = wp_json_encode($response_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
} else {
|
||||||
|
$response_data_formatted = (string) $response_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extraire les informations financières depuis data_sent
|
||||||
|
$invoice_totals = null;
|
||||||
|
$vat_totals = null;
|
||||||
|
$customer_data = null;
|
||||||
|
|
||||||
|
if ($data_sent && (is_array($data_sent) || is_object($data_sent))) {
|
||||||
|
// Convertir en tableau si c'est un objet
|
||||||
|
$data_array = is_object($data_sent) ? (array) $data_sent : $data_sent;
|
||||||
|
|
||||||
|
// Extraire invoice_totals
|
||||||
|
if (isset($data_array['invoice_totals']) && is_array($data_array['invoice_totals'])) {
|
||||||
|
$invoice_totals = $data_array['invoice_totals'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extraire vat_totals
|
||||||
|
if (isset($data_array['vat_totals']) && is_array($data_array['vat_totals'])) {
|
||||||
|
$vat_totals = $data_array['vat_totals'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extraire les données client (buyer)
|
||||||
|
if (isset($data_array['parties']['buyer']) && is_array($data_array['parties']['buyer'])) {
|
||||||
|
$customer_data = $data_array['parties']['buyer'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupérer les informations de la commande si disponible
|
||||||
|
$order_info = null;
|
||||||
|
$order_totals = null;
|
||||||
|
if (!empty($row->id_order)) {
|
||||||
|
$order = wc_get_order($row->id_order);
|
||||||
|
if ($order) {
|
||||||
|
$order_info = [
|
||||||
|
'id' => $order->get_id(),
|
||||||
|
'number' => $order->get_order_number(),
|
||||||
|
'status' => $order->get_status(),
|
||||||
|
'total' => $order->get_total(),
|
||||||
|
'billing_name' => trim($order->get_billing_first_name() . ' ' . $order->get_billing_last_name()),
|
||||||
|
'billing_email' => $order->get_billing_email(),
|
||||||
|
'billing_phone' => $order->get_billing_phone(),
|
||||||
|
'billing_company' => $order->get_billing_company(),
|
||||||
|
'billing_address_1' => $order->get_billing_address_1(),
|
||||||
|
'billing_address_2' => $order->get_billing_address_2(),
|
||||||
|
'billing_city' => $order->get_billing_city(),
|
||||||
|
'billing_postcode' => $order->get_billing_postcode(),
|
||||||
|
'billing_country' => $order->get_billing_country(),
|
||||||
|
'billing_vat_number' => $order->get_meta('_billing_vat_number') ?: '',
|
||||||
|
'edit_link' => get_edit_post_link($row->id_order),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Calculer les totaux depuis la commande si invoice_totals n'est pas disponible
|
||||||
|
if (!$invoice_totals) {
|
||||||
|
$order_totals = [
|
||||||
|
'total_amount_excluding_vat' => $order->get_total() - $order->get_total_tax(),
|
||||||
|
'total_vat_amount' => $order->get_total_tax(),
|
||||||
|
'total_amount_including_vat' => $order->get_total(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extraire le message d'erreur depuis response_data
|
||||||
|
$error_message_to_display = $row->message ?? '';
|
||||||
|
|
||||||
|
if (!empty($response_data) && (is_array($response_data) || is_object($response_data))) {
|
||||||
|
// Convertir en tableau si c'est un objet
|
||||||
|
$error_data = is_object($response_data) ? (array) $response_data : $response_data;
|
||||||
|
|
||||||
|
if (is_array($error_data)) {
|
||||||
|
// Structure avec error.message
|
||||||
|
if (isset($error_data['error']['message'])) {
|
||||||
|
$error_message_to_display = (string) $error_data['error']['message'];
|
||||||
|
}
|
||||||
|
// Structure avec details.validation_error
|
||||||
|
elseif (isset($error_data['details']['validation_error'])) {
|
||||||
|
$error_message_to_display = (string) $error_data['details']['validation_error'];
|
||||||
|
}
|
||||||
|
// Structure avec validation_error directement
|
||||||
|
elseif (isset($error_data['validation_error'])) {
|
||||||
|
$error_message_to_display = (string) $error_data['validation_error'];
|
||||||
|
}
|
||||||
|
// Structure avec message directement
|
||||||
|
elseif (isset($error_data['message'])) {
|
||||||
|
$error_message_to_display = (string) $error_data['message'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Préparer les données pour le template
|
||||||
|
$log_data = [
|
||||||
|
'id' => $row->id,
|
||||||
|
'id_order' => $row->id_order ?? 0,
|
||||||
|
'order_info' => $order_info,
|
||||||
|
'document_id' => $row->document_id ?? '',
|
||||||
|
'peppol_document_id' => $row->peppol_document_id ?? '',
|
||||||
|
'status' => $row->status ?? '',
|
||||||
|
'success' => !empty($row->success),
|
||||||
|
'message' => $error_message_to_display,
|
||||||
|
'http_code' => $row->http_code ?? null,
|
||||||
|
'date_add' => $row->date_add ?? '',
|
||||||
|
'date_update' => $row->date_update ?? '',
|
||||||
|
'invoice_totals' => $invoice_totals ?? $order_totals,
|
||||||
|
'vat_totals' => $vat_totals,
|
||||||
|
'customer_data' => $customer_data,
|
||||||
|
'data_sent' => $data_sent_formatted,
|
||||||
|
'response_data' => $response_data_formatted,
|
||||||
|
];
|
||||||
|
|
||||||
|
$template = ESI_PEPPOL_DIR . 'templates/admin/logs-detail.php';
|
||||||
|
|
||||||
|
if (file_exists($template)) {
|
||||||
|
/** @noinspection PhpIncludeInspection */
|
||||||
|
include $template;
|
||||||
|
} else {
|
||||||
|
wp_die(esc_html__('Template de détail introuvable.', 'esi_peppol'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Afficher la liste des logs
|
||||||
|
// Récupération des dernières lignes de la table custom
|
||||||
|
$rows = PEPPOL_Main_model::get_recent(50);
|
||||||
|
|
||||||
|
$template = ESI_PEPPOL_DIR . 'templates/admin/logs.php';
|
||||||
|
|
||||||
|
if (file_exists($template)) {
|
||||||
|
/** @noinspection PhpIncludeInspection */
|
||||||
|
include $template;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function enqueue_admin_assets() {
|
public static function enqueue_admin_assets() {
|
||||||
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
|
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
|
||||||
|
|
||||||
// Ne charger les assets que sur les pages du plugin
|
// Ne charger les assets que sur les pages du plugin ou la page des commandes WooCommerce
|
||||||
$is_peppol_page = isset($_GET['page']) && strpos((string) $_GET['page'], 'esi-peppol') === 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
$is_peppol_page = isset($_GET['page']) && strpos((string) $_GET['page'], 'esi-peppol') === 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||||
|
$is_orders_page = $screen && (
|
||||||
|
strpos((string) $screen->id, 'shop_order') !== false ||
|
||||||
|
strpos((string) $screen->id, 'woocommerce_page_wc-orders') !== false ||
|
||||||
|
$screen->id === 'edit-shop_order'
|
||||||
|
);
|
||||||
|
|
||||||
if (!$is_peppol_page && $screen && strpos((string) $screen->base, 'esi-peppol') === false) {
|
if (!$is_peppol_page && !$is_orders_page && $screen && strpos((string) $screen->base, 'esi-peppol') === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -191,4 +191,71 @@ class PEPPOL_Woocommerce_controller {
|
|||||||
'</p></div>';
|
'</p></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute une colonne "Statut Peppol" dans le listing des commandes WooCommerce.
|
||||||
|
*
|
||||||
|
* @param array $columns Colonnes existantes.
|
||||||
|
* @return array Colonnes modifiées.
|
||||||
|
*/
|
||||||
|
public static function add_peppol_status_column(array $columns): array {
|
||||||
|
$new_columns = [];
|
||||||
|
|
||||||
|
foreach ($columns as $key => $column) {
|
||||||
|
$new_columns[$key] = $column;
|
||||||
|
|
||||||
|
// Ajouter la colonne "Statut Peppol" après la colonne "Commande" ou "order_title"
|
||||||
|
if ('order_title' === $key || 'order_number' === $key || 'order_status' === $key) {
|
||||||
|
$new_columns['peppol_status'] = __('Statut Peppol', 'esi_peppol');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si aucune colonne appropriée n'a été trouvée, ajouter à la fin
|
||||||
|
if (!isset($new_columns['peppol_status'])) {
|
||||||
|
$new_columns['peppol_status'] = __('Statut Peppol', 'esi_peppol');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new_columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche le contenu de la colonne "Statut Peppol" dans le listing des commandes.
|
||||||
|
*
|
||||||
|
* @param string $column Nom de la colonne.
|
||||||
|
* @param int|object $order ID de la commande ou objet commande.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function show_peppol_status_column(string $column, $order): void {
|
||||||
|
if ('peppol_status' !== $column) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupérer l'ID de la commande
|
||||||
|
$order_id = is_numeric($order) ? (int) $order : (is_object($order) ? $order->get_id() : 0);
|
||||||
|
|
||||||
|
if (!$order_id) {
|
||||||
|
echo '<span class="na">–</span>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupérer le log Peppol associé à cette commande
|
||||||
|
$log = \ESI_PEPPOL\models\PEPPOL_Main_model::get_by_order_id($order_id);
|
||||||
|
|
||||||
|
if (!$log || empty($log->status)) {
|
||||||
|
echo '<span class="na">–</span>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Afficher le macaron cliquable vers la page de détail
|
||||||
|
$detail_url = \admin_url('admin.php?page=esi-peppol-logs&detail=' . $log->id);
|
||||||
|
$status_class = 'statut statut-' . \strtolower(\sanitize_html_class($log->status));
|
||||||
|
|
||||||
|
\printf(
|
||||||
|
'<a href="%s" class="%s" title="%s">%s</a>',
|
||||||
|
\esc_url($detail_url),
|
||||||
|
\esc_attr($status_class),
|
||||||
|
\esc_attr__('Voir les détails du log Peppol', 'esi_peppol'),
|
||||||
|
\esc_html($log->status)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -106,6 +106,23 @@
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Styles pour les liens de statut (macarons cliquables) */
|
||||||
|
a.statut {
|
||||||
|
text-decoration: none;
|
||||||
|
transition: opacity 0.2s ease, transform 0.1s ease;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.statut:hover {
|
||||||
|
opacity: 0.85;
|
||||||
|
text-decoration: none;
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
a.statut:visited {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
/* Couleurs par défaut pour les statuts communs */
|
/* Couleurs par défaut pour les statuts communs */
|
||||||
.statut-success,
|
.statut-success,
|
||||||
.statut-succès,
|
.statut-succès,
|
||||||
|
|||||||
@ -75,7 +75,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions AJAX sur la page de logs : renvoyer / vérifier le statut
|
// Actions AJAX sur la page de logs : renvoyer / vérifier le statut
|
||||||
if ($logsTable.length && typeof window.esiPeppolAdmin !== 'undefined') {
|
// Utiliser la délégation d'événements sur le document pour fonctionner aussi sur la page de détail
|
||||||
|
if (typeof window.esiPeppolAdmin !== 'undefined') {
|
||||||
var $logsResult = $('#esi-peppol-logs-result');
|
var $logsResult = $('#esi-peppol-logs-result');
|
||||||
|
|
||||||
var showLogsNotice = function (type, title, message, detail) {
|
var showLogsNotice = function (type, title, message, detail) {
|
||||||
@ -107,7 +108,8 @@
|
|||||||
.append(html);
|
.append(html);
|
||||||
};
|
};
|
||||||
|
|
||||||
$logsTable.on('click', '.esi-peppol-log-resend', function (e) {
|
// Gestionnaire pour le bouton "Réenvoyer" (fonctionne dans le tableau et sur la page de détail)
|
||||||
|
$(document).on('click', '.esi-peppol-log-resend', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var $btn = $(this);
|
var $btn = $(this);
|
||||||
|
|||||||
263
templates/admin/logs-detail.php
Normal file
263
templates/admin/logs-detail.php
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var array $log_data */
|
||||||
|
$logs_url = admin_url('admin.php?page=esi-peppol-logs');
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php esc_html_e('Détails du log', 'esi_peppol'); ?></h1>
|
||||||
|
|
||||||
|
<div class="esi-peppol-log-details-content">
|
||||||
|
<?php
|
||||||
|
// 1. Section Statut
|
||||||
|
?>
|
||||||
|
<div class="esi-peppol-log-details-section">
|
||||||
|
<h3><?php esc_html_e('Statut', 'esi_peppol'); ?></h3>
|
||||||
|
<table class="widefat">
|
||||||
|
<tr>
|
||||||
|
<th style="width: 200px;"><?php esc_html_e('Succès', 'esi_peppol'); ?></th>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
echo $log_data['success']
|
||||||
|
? '<span style="color:green;font-weight:bold;">' . esc_html__('Oui', 'esi_peppol') . '</span>'
|
||||||
|
: '<span style="color:red;font-weight:bold;">' . esc_html__('Non', 'esi_peppol') . '</span>';
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Message', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($log_data['message'] ?: '-'); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php if (!empty($log_data['order_info']['number'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Commande', 'esi_peppol'); ?></th>
|
||||||
|
<td>
|
||||||
|
<a href="<?php echo esc_url($log_data['order_info']['edit_link']); ?>" target="_blank">
|
||||||
|
#<?php echo esc_html($log_data['order_info']['number']); ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php elseif (!empty($log_data['id_order'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Commande', 'esi_peppol'); ?></th>
|
||||||
|
<td>#<?php echo esc_html($log_data['id_order']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($log_data['document_id'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Document ID', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($log_data['document_id']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($log_data['peppol_document_id'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Peppol Document ID', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($log_data['peppol_document_id']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($log_data['status'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Statut', 'esi_peppol'); ?></th>
|
||||||
|
<td>
|
||||||
|
<span class="statut statut-<?php echo esc_attr(strtolower(sanitize_html_class($log_data['status']))); ?>">
|
||||||
|
<?php echo esc_html($log_data['status']); ?>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($log_data['http_code'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Code HTTP', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($log_data['http_code']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($log_data['date_add'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Date ajout', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($log_data['date_add']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($log_data['date_update'])) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Dernière mise à jour', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($log_data['date_update']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// 2. Section Données client
|
||||||
|
if (!empty($log_data['customer_data']) || (!empty($log_data['order_info']) && (!empty($log_data['order_info']['billing_name']) || !empty($log_data['order_info']['billing_company'])))) :
|
||||||
|
$customer = $log_data['customer_data'] ?? [];
|
||||||
|
$order_info = $log_data['order_info'] ?? [];
|
||||||
|
|
||||||
|
$customer_name = $customer['name'] ?? $order_info['billing_company'] ?? $order_info['billing_name'] ?? '-';
|
||||||
|
$customer_legal_name = $customer['legal_name'] ?? $customer['name'] ?? $order_info['billing_company'] ?? $order_info['billing_name'] ?? '-';
|
||||||
|
$customer_vat = $customer['vat_number'] ?? $order_info['billing_vat_number'] ?? '-';
|
||||||
|
$customer_email = ($customer['contact']['contact_email'] ?? null) ?: ($order_info['billing_email'] ?? '-');
|
||||||
|
$customer_phone = ($customer['contact']['contact_phone'] ?? null) ?: ($order_info['billing_phone'] ?? '-');
|
||||||
|
|
||||||
|
$address = $customer['address'] ?? [];
|
||||||
|
$address_line_1 = $address['address_line_1'] ?? $order_info['billing_address_1'] ?? '-';
|
||||||
|
$address_line_2 = $address['address_line_2'] ?? $order_info['billing_address_2'] ?? '';
|
||||||
|
$city = $address['city'] ?? $order_info['billing_city'] ?? '-';
|
||||||
|
$postal_code = $address['postal_code'] ?? $order_info['billing_postcode'] ?? '-';
|
||||||
|
$country_code = $address['country_code'] ?? $order_info['billing_country'] ?? '-';
|
||||||
|
?>
|
||||||
|
<div class="esi-peppol-log-details-section">
|
||||||
|
<h3><?php esc_html_e('Données client', 'esi_peppol'); ?></h3>
|
||||||
|
<table class="widefat">
|
||||||
|
<tr>
|
||||||
|
<th style="width: 200px;"><?php esc_html_e('Nom / Raison sociale', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($customer_name); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php if ($customer_legal_name && $customer_legal_name !== $customer_name) : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Nom légal', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($customer_legal_name); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Numéro TVA', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($customer_vat); ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Email', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($customer_email); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php if ($customer_phone && $customer_phone !== '-') : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Téléphone', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html($customer_phone); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Adresse', 'esi_peppol'); ?></th>
|
||||||
|
<td>
|
||||||
|
<?php echo esc_html($address_line_1); ?>
|
||||||
|
<?php if ($address_line_2) : ?>
|
||||||
|
<br><?php echo esc_html($address_line_2); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
<br><?php echo esc_html($postal_code . ' ' . $city); ?>
|
||||||
|
<br><?php echo esc_html($country_code); ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// 3. Section Détails TVA par taux
|
||||||
|
if (!empty($log_data['vat_totals']) && is_array($log_data['vat_totals']) && count($log_data['vat_totals']) > 0) :
|
||||||
|
?>
|
||||||
|
<div class="esi-peppol-log-details-section">
|
||||||
|
<h3><?php esc_html_e('Détails TVA', 'esi_peppol'); ?></h3>
|
||||||
|
<table class="widefat">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Taux TVA', 'esi_peppol'); ?></th>
|
||||||
|
<th><?php esc_html_e('Montant HTVA', 'esi_peppol'); ?></th>
|
||||||
|
<th><?php esc_html_e('Montant TVA', 'esi_peppol'); ?></th>
|
||||||
|
<th><?php esc_html_e('Montant TVAC', 'esi_peppol'); ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($log_data['vat_totals'] as $vat) : ?>
|
||||||
|
<?php
|
||||||
|
$vat_rate = floatval($vat['vat_rate'] ?? 0);
|
||||||
|
$taxable_amount = floatval($vat['taxable_amount'] ?? 0);
|
||||||
|
$vat_amount = floatval($vat['vat_amount'] ?? 0);
|
||||||
|
$total_incl_vat = $taxable_amount + $vat_amount;
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo esc_html(number_format($vat_rate, 2, ',', ' ') . ' %'); ?></td>
|
||||||
|
<td><?php echo esc_html(number_format($taxable_amount, 2, ',', ' ') . ' €'); ?></td>
|
||||||
|
<td><?php echo esc_html(number_format($vat_amount, 2, ',', ' ') . ' €'); ?></td>
|
||||||
|
<td><?php echo esc_html(number_format($total_incl_vat, 2, ',', ' ') . ' €'); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// 4. Section Totaux
|
||||||
|
if (!empty($log_data['invoice_totals'])) :
|
||||||
|
$totals = $log_data['invoice_totals'];
|
||||||
|
$total_htva = floatval($totals['total_amount_excluding_vat'] ?? 0);
|
||||||
|
$total_tva = floatval($totals['total_vat_amount'] ?? 0);
|
||||||
|
$total_tvac = floatval($totals['total_amount_including_vat'] ?? 0);
|
||||||
|
?>
|
||||||
|
<div class="esi-peppol-log-details-section">
|
||||||
|
<h3><?php esc_html_e('Totaux', 'esi_peppol'); ?></h3>
|
||||||
|
<table class="widefat">
|
||||||
|
<tr>
|
||||||
|
<th style="width: 200px;"><?php esc_html_e('Total HTVA', 'esi_peppol'); ?></th>
|
||||||
|
<td><strong><?php echo esc_html(number_format($total_htva, 2, ',', ' ') . ' €'); ?></strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Total TVA', 'esi_peppol'); ?></th>
|
||||||
|
<td><strong><?php echo esc_html(number_format($total_tva, 2, ',', ' ') . ' €'); ?></strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Total TVAC', 'esi_peppol'); ?></th>
|
||||||
|
<td><strong><?php echo esc_html(number_format($total_tvac, 2, ',', ' ') . ' €'); ?></strong></td>
|
||||||
|
</tr>
|
||||||
|
<?php if (!empty($totals['total_payable_amount'])) : ?>
|
||||||
|
<?php $payable_amount = floatval($totals['total_payable_amount']); ?>
|
||||||
|
<tr>
|
||||||
|
<th><?php esc_html_e('Montant à payer', 'esi_peppol'); ?></th>
|
||||||
|
<td><?php echo esc_html(number_format($payable_amount, 2, ',', ' ') . ' €'); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// 5. Section Données envoyées (JSON)
|
||||||
|
if (!empty($log_data['data_sent'])) :
|
||||||
|
?>
|
||||||
|
<div class="esi-peppol-log-details-section">
|
||||||
|
<h3><?php esc_html_e('Données envoyées', 'esi_peppol'); ?></h3>
|
||||||
|
<pre class="esi-peppol-json-display" style="background: #f5f5f5; padding: 15px; border: 1px solid #ddd; border-radius: 4px; overflow-x: auto; max-height: 500px; overflow-y: auto;"><?php echo esc_html($log_data['data_sent']); ?></pre>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// 6. Section Données de réponse (JSON)
|
||||||
|
if (!empty($log_data['response_data'])) :
|
||||||
|
?>
|
||||||
|
<div class="esi-peppol-log-details-section">
|
||||||
|
<h3><?php esc_html_e('Données de réponse', 'esi_peppol'); ?></h3>
|
||||||
|
<pre class="esi-peppol-json-display" style="background: #f5f5f5; padding: 15px; border: 1px solid #ddd; border-radius: 4px; overflow-x: auto; max-height: 500px; overflow-y: auto;"><?php echo esc_html($log_data['response_data']); ?></pre>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="esi-peppol-log-details-actions" style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd;">
|
||||||
|
<a href="<?php echo esc_url($logs_url); ?>" class="button button-secondary">
|
||||||
|
<span class="dashicons dashicons-arrow-left-alt" style="vertical-align: middle;"></span>
|
||||||
|
<?php esc_html_e('Retour vers les logs', 'esi_peppol'); ?>
|
||||||
|
</a>
|
||||||
|
<?php if (!empty($log_data['id_order'])) : ?>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="button button-primary esi-peppol-log-resend"
|
||||||
|
data-order-id="<?php echo esc_attr($log_data['id_order']); ?>"
|
||||||
|
style="margin-left: 10px;"
|
||||||
|
>
|
||||||
|
<span class="dashicons dashicons-update" style="vertical-align: middle;"></span>
|
||||||
|
<?php esc_html_e('Envoyer de nouveau', 'esi_peppol'); ?>
|
||||||
|
</button>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="esi-peppol-logs-result"></div>
|
||||||
|
</div>
|
||||||
@ -42,6 +42,21 @@ if ($order instanceof WC_Order) {
|
|||||||
$customer_email = $order->get_billing_email();
|
$customer_email = $order->get_billing_email();
|
||||||
$customer_phone = $order->get_billing_phone();
|
$customer_phone = $order->get_billing_phone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Récupérer le log Peppol associé à cette commande pour obtenir l'ID du log
|
||||||
|
$log_id = null;
|
||||||
|
if (class_exists('\ESI_PEPPOL\models\PEPPOL_Main_model')) {
|
||||||
|
$log = \ESI_PEPPOL\models\PEPPOL_Main_model::get_by_order_id($order_id);
|
||||||
|
if ($log && !empty($log->id)) {
|
||||||
|
$log_id = (int) $log->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construire l'URL vers la page de détail ou la page de logs
|
||||||
|
$logs_url = admin_url('admin.php?page=esi-peppol-logs');
|
||||||
|
if ($log_id) {
|
||||||
|
$logs_url = admin_url('admin.php?page=esi-peppol-logs&detail=' . $log_id);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
|
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||||
@ -311,7 +326,7 @@ if ($order instanceof WC_Order) {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p style="color: #333333; font-size: 15px; line-height: 24px; margin: 22px 0 22px 0; font-family: Arial, Helvetica, sans-serif;">
|
<p style="color: #333333; font-size: 15px; line-height: 24px; margin: 22px 0 22px 0; font-family: Arial, Helvetica, sans-serif;">
|
||||||
<?php esc_html_e('Veuillez vérifier la configuration de votre connecteur Peppol et consulter les logs pour plus de détails.', 'esi_peppol'); ?>
|
<?php esc_html_e('Ce message a pour but de vous informer qu\'un problème est survenu lors de l\'envoi de la facture vers Peppol. Aucune action immédiate n\'est nécessaire : une fois le problème corrigé, la facture pourra être renvoyée facilement à l\'aide du bouton « Ré-envoyer » disponible dans la liste des logs.', 'esi_peppol'); ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- BUTTON - Compatible Outlook -->
|
<!-- BUTTON - Compatible Outlook -->
|
||||||
@ -319,17 +334,17 @@ if ($order instanceof WC_Order) {
|
|||||||
<tr>
|
<tr>
|
||||||
<td align="center" style="padding: 8px 0 28px 0;">
|
<td align="center" style="padding: 8px 0 28px 0;">
|
||||||
<!--[if mso]>
|
<!--[if mso]>
|
||||||
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="<?php echo esc_url(admin_url('admin.php?page=esi-peppol-logs')); ?>" style="height:48px;v-text-anchor:middle;width:220px;" arcsize="10%" strokecolor="#0B3C61" fillcolor="#0B3C61">
|
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="<?php echo esc_url($logs_url); ?>" style="height:48px;v-text-anchor:middle;width:220px;" arcsize="10%" strokecolor="#0B3C61" fillcolor="#0B3C61">
|
||||||
<w:anchorlock/>
|
<w:anchorlock/>
|
||||||
<center style="color:#ffffff;font-family:Arial,Helvetica,sans-serif;font-size:15px;font-weight:bold;"><?php esc_html_e('Consulter les logs', 'esi_peppol'); ?> →</center>
|
<center style="color:#ffffff;font-family:Arial,Helvetica,sans-serif;font-size:15px;font-weight:bold;"><?php echo $log_id ? esc_html__('Voir les détails', 'esi_peppol') : esc_html__('Consulter les logs', 'esi_peppol'); ?> →</center>
|
||||||
</v:roundrect>
|
</v:roundrect>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
<!--[if !mso]><!-->
|
<!--[if !mso]><!-->
|
||||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0">
|
<table role="presentation" cellspacing="0" cellpadding="0" border="0">
|
||||||
<tr>
|
<tr>
|
||||||
<td style="border-radius: 5px; background-color: #0B3C61;">
|
<td style="border-radius: 5px; background-color: #0B3C61;">
|
||||||
<a href="<?php echo esc_url(admin_url('admin.php?page=esi-peppol-logs')); ?>" target="_blank" style="display: inline-block; background-color: #0B3C61; color: #ffffff; font-size: 15px; font-weight: bold; text-decoration: none; padding: 14px 35px; border-radius: 5px; font-family: Arial, Helvetica, sans-serif; border: none;">
|
<a href="<?php echo esc_url($logs_url); ?>" target="_blank" style="display: inline-block; background-color: #0B3C61; color: #ffffff; font-size: 15px; font-weight: bold; text-decoration: none; padding: 14px 35px; border-radius: 5px; font-family: Arial, Helvetica, sans-serif; border: none;">
|
||||||
<?php esc_html_e('Consulter les logs', 'esi_peppol'); ?> →
|
<?php echo $log_id ? esc_html__('Voir les détails', 'esi_peppol') : esc_html__('Consulter les logs', 'esi_peppol'); ?> →
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user