Ajout check num factu
This commit is contained in:
parent
2b479eb6a3
commit
f6835b4da7
@ -509,6 +509,25 @@ class PEPPOL_peppol_controller {
|
|||||||
public static function build_payload_from_order(\WC_Order $order): array {
|
public static function build_payload_from_order(\WC_Order $order): array {
|
||||||
$order_id = $order->get_id();
|
$order_id = $order->get_id();
|
||||||
$order_number = $order->get_order_number();
|
$order_number = $order->get_order_number();
|
||||||
|
$invoice_number = $order_number;
|
||||||
|
|
||||||
|
$wpo_invoice_number = (string) $order->get_meta('_wcpdf_invoice_number', true);
|
||||||
|
if ($wpo_invoice_number !== '') {
|
||||||
|
$invoice_number = $wpo_invoice_number;
|
||||||
|
} else {
|
||||||
|
$use_backup_format = !\ESI_PEPPOL\helpers\PEPPOL_Woo_Helper::esi_has_wpo_invoice_numbers();
|
||||||
|
if ($use_backup_format) {
|
||||||
|
$backup_format = (string) \get_option('esi_peppol_vat_number_format', '');
|
||||||
|
if ($backup_format !== '') {
|
||||||
|
$generated = self::build_invoice_number_from_format($backup_format, $order);
|
||||||
|
if ($generated !== '') {
|
||||||
|
$invoice_number = $generated;
|
||||||
|
$order->update_meta_data('_wcpdf_invoice_number', $generated);
|
||||||
|
$order->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$currency_code = $order->get_currency();
|
$currency_code = $order->get_currency();
|
||||||
|
|
||||||
$invoice_date = $order->get_date_created()
|
$invoice_date = $order->get_date_created()
|
||||||
@ -995,7 +1014,7 @@ class PEPPOL_peppol_controller {
|
|||||||
'document_type' => 'invoice',
|
'document_type' => 'invoice',
|
||||||
'external_reference' => $external_reference,
|
'external_reference' => $external_reference,
|
||||||
'invoice' => [
|
'invoice' => [
|
||||||
'invoice_number' => $order_number,
|
'invoice_number' => $invoice_number,
|
||||||
'invoice_date' => $invoice_date,
|
'invoice_date' => $invoice_date,
|
||||||
'due_date' => $due_date,
|
'due_date' => $due_date,
|
||||||
'currency_code' => $currency_code,
|
'currency_code' => $currency_code,
|
||||||
@ -1014,4 +1033,28 @@ class PEPPOL_peppol_controller {
|
|||||||
|
|
||||||
return \apply_filters('esi_peppol_payload_from_order', $payload, $order);
|
return \apply_filters('esi_peppol_payload_from_order', $payload, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit un numéro de facture depuis un format de secours.
|
||||||
|
* Placeholders supportés : {YYYY}, {YY}, {MM}, {DD}, {ORDER_ID}, {ORDER_NUMBER}
|
||||||
|
*/
|
||||||
|
private static function build_invoice_number_from_format(string $format, \WC_Order $order): string {
|
||||||
|
$date = $order->get_date_created();
|
||||||
|
$year = $date ? $date->date('Y') : \gmdate('Y');
|
||||||
|
$month = $date ? $date->date('m') : \gmdate('m');
|
||||||
|
$day = $date ? $date->date('d') : \gmdate('d');
|
||||||
|
|
||||||
|
$replacements = [
|
||||||
|
'{YYYY}' => $year,
|
||||||
|
'{YY}' => substr($year, -2),
|
||||||
|
'{MM}' => $month,
|
||||||
|
'{DD}' => $day,
|
||||||
|
'{ORDER_ID}' => (string) $order->get_id(),
|
||||||
|
'{ORDER_NUMBER}' => (string) $order->get_order_number(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = strtr($format, $replacements);
|
||||||
|
|
||||||
|
return trim($result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -155,12 +155,17 @@ class PEPPOL_Plugin {
|
|||||||
$password = isset($_POST['esi_peppol_password']) ? sanitize_text_field(wp_unslash($_POST['esi_peppol_password'])) : '';
|
$password = isset($_POST['esi_peppol_password']) ? sanitize_text_field(wp_unslash($_POST['esi_peppol_password'])) : '';
|
||||||
$email = isset($_POST['esi_peppol_email']) ? sanitize_email(wp_unslash($_POST['esi_peppol_email'])) : '';
|
$email = isset($_POST['esi_peppol_email']) ? sanitize_email(wp_unslash($_POST['esi_peppol_email'])) : '';
|
||||||
$logo_email_id = isset($_POST['esi_peppol_logo_email_id']) ? absint(wp_unslash($_POST['esi_peppol_logo_email_id'])) : 0;
|
$logo_email_id = isset($_POST['esi_peppol_logo_email_id']) ? absint(wp_unslash($_POST['esi_peppol_logo_email_id'])) : 0;
|
||||||
|
$vat_number_format = get_option('esi_peppol_vat_number_format', '');
|
||||||
|
if (isset($_POST['esi_peppol_vat_number_format'])) {
|
||||||
|
$vat_number_format = sanitize_text_field(wp_unslash($_POST['esi_peppol_vat_number_format']));
|
||||||
|
}
|
||||||
|
|
||||||
// Sauvegarde systématique des options
|
// Sauvegarde systématique des options
|
||||||
update_option('esi_peppol_api_key', $api_key);
|
update_option('esi_peppol_api_key', $api_key);
|
||||||
update_option('esi_peppol_password', $password);
|
update_option('esi_peppol_password', $password);
|
||||||
update_option('esi_peppol_email', $email);
|
update_option('esi_peppol_email', $email);
|
||||||
update_option('esi_peppol_logo_email_id', $logo_email_id);
|
update_option('esi_peppol_logo_email_id', $logo_email_id);
|
||||||
|
update_option('esi_peppol_vat_number_format', $vat_number_format);
|
||||||
|
|
||||||
if ($action === 'save') {
|
if ($action === 'save') {
|
||||||
$notice = __('Paramètres enregistrés avec succès.', 'esi_peppol');
|
$notice = __('Paramètres enregistrés avec succès.', 'esi_peppol');
|
||||||
@ -1291,6 +1296,14 @@ class PEPPOL_Plugin {
|
|||||||
'action_url' => admin_url('admin.php?page=esi-peppol-settings'),
|
'action_url' => admin_url('admin.php?page=esi-peppol-settings'),
|
||||||
'action_label' => __('Détecter le champ TVA', 'esi_peppol'),
|
'action_label' => __('Détecter le champ TVA', 'esi_peppol'),
|
||||||
],
|
],
|
||||||
|
'vat_number_format' => [
|
||||||
|
'completed' => false,
|
||||||
|
'value' => '',
|
||||||
|
'label' => __('Format num TVA', 'esi_peppol'),
|
||||||
|
'description' => __('Format du numéro de TVA (backup si aucun format détecté automatiquement)', 'esi_peppol'),
|
||||||
|
'action_url' => admin_url('admin.php?page=esi-peppol-settings'),
|
||||||
|
'action_label' => __('Configurer le format', 'esi_peppol'),
|
||||||
|
],
|
||||||
'api_credentials' => [
|
'api_credentials' => [
|
||||||
'completed' => false,
|
'completed' => false,
|
||||||
'value' => '',
|
'value' => '',
|
||||||
@ -1332,6 +1345,23 @@ class PEPPOL_Plugin {
|
|||||||
$status['vat_field']['value'] = $vat_field_key;
|
$status['vat_field']['value'] = $vat_field_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vérifier le format num TVA (détecté ou backup)
|
||||||
|
$detected_format = '';
|
||||||
|
if (\ESI_PEPPOL\helpers\PEPPOL_Woo_Helper::esi_has_wpo_invoice_numbers()) {
|
||||||
|
$detected_format = \ESI_PEPPOL\helpers\PEPPOL_Woo_Helper::esi_get_wpo_invoice_number_format_label();
|
||||||
|
}
|
||||||
|
$backup_format = (string) get_option('esi_peppol_vat_number_format', '');
|
||||||
|
if ($detected_format !== '') {
|
||||||
|
$status['vat_number_format']['completed'] = true;
|
||||||
|
$status['vat_number_format']['value'] = sprintf(
|
||||||
|
__('Format détecté : %s', 'esi_peppol'),
|
||||||
|
$detected_format
|
||||||
|
);
|
||||||
|
} elseif ($backup_format !== '') {
|
||||||
|
$status['vat_number_format']['completed'] = true;
|
||||||
|
$status['vat_number_format']['value'] = $backup_format;
|
||||||
|
}
|
||||||
|
|
||||||
// Vérifier les identifiants API
|
// Vérifier les identifiants API
|
||||||
$api_key = (string) get_option('esi_peppol_api_key', '');
|
$api_key = (string) get_option('esi_peppol_api_key', '');
|
||||||
$password = (string) get_option('esi_peppol_password', '');
|
$password = (string) get_option('esi_peppol_password', '');
|
||||||
|
|||||||
@ -64,9 +64,28 @@ $settings_status = \ESI_PEPPOL\controllers\PEPPOL_Plugin::check_settings_status(
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Étape 3: Identifiants API -->
|
<!-- Étape 3: Format num TVA -->
|
||||||
|
<div class="step <?php echo $settings_status['vat_number_format']['completed'] ? 'is-done' : ''; ?>"
|
||||||
|
data-step="<?php echo $settings_status['vat_number_format']['completed'] ? '✓' : '3'; ?>">
|
||||||
|
<div class="step-card">
|
||||||
|
<h3><?php echo esc_html($settings_status['vat_number_format']['label']); ?></h3>
|
||||||
|
<p><?php echo esc_html($settings_status['vat_number_format']['description']); ?></p>
|
||||||
|
<?php if ($settings_status['vat_number_format']['completed']) : ?>
|
||||||
|
<div class="step-value">
|
||||||
|
<strong><?php esc_html_e('Valeur :', 'esi_peppol'); ?></strong>
|
||||||
|
<code><?php echo esc_html($settings_status['vat_number_format']['value']); ?></code>
|
||||||
|
</div>
|
||||||
|
<?php else : ?>
|
||||||
|
<a href="<?php echo esc_url($settings_status['vat_number_format']['action_url']); ?>" class="button button-primary">
|
||||||
|
<?php echo esc_html($settings_status['vat_number_format']['action_label']); ?>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Étape 4: Identifiants API -->
|
||||||
<div class="step <?php echo $settings_status['api_credentials']['completed'] ? 'is-done' : ''; ?>"
|
<div class="step <?php echo $settings_status['api_credentials']['completed'] ? 'is-done' : ''; ?>"
|
||||||
data-step="<?php echo $settings_status['api_credentials']['completed'] ? '✓' : '3'; ?>">
|
data-step="<?php echo $settings_status['api_credentials']['completed'] ? '✓' : '4'; ?>">
|
||||||
<div class="step-card">
|
<div class="step-card">
|
||||||
<h3><?php echo esc_html($settings_status['api_credentials']['label']); ?></h3>
|
<h3><?php echo esc_html($settings_status['api_credentials']['label']); ?></h3>
|
||||||
<p><?php echo esc_html($settings_status['api_credentials']['description']); ?></p>
|
<p><?php echo esc_html($settings_status['api_credentials']['description']); ?></p>
|
||||||
@ -83,8 +102,8 @@ $settings_status = \ESI_PEPPOL\controllers\PEPPOL_Plugin::check_settings_status(
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Étape 4: Webhook -->
|
<!-- Étape 5: Webhook -->
|
||||||
<div class="step is-done" data-step="4">
|
<div class="step is-done" data-step="5">
|
||||||
<div class="step-card">
|
<div class="step-card">
|
||||||
<h3><?php echo esc_html($settings_status['webhook']['label']); ?></h3>
|
<h3><?php echo esc_html($settings_status['webhook']['label']); ?></h3>
|
||||||
<p><?php echo esc_html($settings_status['webhook']['description']); ?></p>
|
<p><?php echo esc_html($settings_status['webhook']['description']); ?></p>
|
||||||
@ -108,9 +127,9 @@ $settings_status = \ESI_PEPPOL\controllers\PEPPOL_Plugin::check_settings_status(
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Étape 5: Email (optionnel) -->
|
<!-- Étape 6: Email (optionnel) -->
|
||||||
<div class="step <?php echo $settings_status['email']['completed'] ? 'is-done' : ''; ?>"
|
<div class="step <?php echo $settings_status['email']['completed'] ? 'is-done' : ''; ?>"
|
||||||
data-step="<?php echo $settings_status['email']['completed'] ? '✓' : '5'; ?>">
|
data-step="<?php echo $settings_status['email']['completed'] ? '✓' : '6'; ?>">
|
||||||
<div class="step-card">
|
<div class="step-card">
|
||||||
<h3>
|
<h3>
|
||||||
<?php echo esc_html($settings_status['email']['label']); ?>
|
<?php echo esc_html($settings_status['email']['label']); ?>
|
||||||
|
|||||||
@ -193,6 +193,42 @@ if ($logo_email_id) {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
<label for="esi_peppol_vat_number_format"><?php esc_html_e('Format num TVA', 'esi_peppol'); ?></label>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
$backup_vat_format = (string) get_option('esi_peppol_vat_number_format', '');
|
||||||
|
$has_wpo_invoices = \ESI_PEPPOL\helpers\PEPPOL_Woo_Helper::esi_has_wpo_invoice_numbers();
|
||||||
|
$detected_format = $has_wpo_invoices
|
||||||
|
? \ESI_PEPPOL\helpers\PEPPOL_Woo_Helper::esi_get_wpo_invoice_number_format_label()
|
||||||
|
: '';
|
||||||
|
?>
|
||||||
|
<?php if ($detected_format !== '') : ?>
|
||||||
|
<p style="margin: 0;">
|
||||||
|
<strong><?php esc_html_e('Format détecté :', 'esi_peppol'); ?></strong>
|
||||||
|
<code style="margin-left: 5px; padding: 2px 6px; background-color: #fff; border: 1px solid #c3c4c7;">
|
||||||
|
<?php echo esc_html($detected_format); ?>
|
||||||
|
</code>
|
||||||
|
</p>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e('Le format est détecté automatiquement via WPO WCPDF. Le champ de backup n\'est pas requis.', 'esi_peppol'); ?>
|
||||||
|
</p>
|
||||||
|
<?php else : ?>
|
||||||
|
<input type="text"
|
||||||
|
class="regular-text"
|
||||||
|
id="esi_peppol_vat_number_format"
|
||||||
|
name="esi_peppol_vat_number_format"
|
||||||
|
value="<?php echo esc_attr($backup_vat_format); ?>"
|
||||||
|
/>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e('Utilisé comme format de secours si aucun format n\'est détecté automatiquement. Placeholders : {YYYY}, {YY}, {MM}, {DD}, {ORDER_ID}, {ORDER_NUMBER}.', 'esi_peppol'); ?>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<!-- <tr>
|
<!-- <tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="esi_peppol_logo_email"><?php esc_html_e('Logo Email', 'esi_peppol'); ?></label>
|
<label for="esi_peppol_logo_email"><?php esc_html_e('Logo Email', 'esi_peppol'); ?></label>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user