Files
WooDoo/templates/myaccount-invoices.php
Malin c05433689e feat: invoice email resend, smaller table, column cleanup
Email resend (replaces broken PDF download):
- New AJAX action woodoo_send_invoice_email
- Finds Odoo invoice email template via ir.model.data (cached 24h)
  with fallback search on mail.template by model
- Calls mail.template.send_mail([template_id], invoice_id, force_send=True)
  via authenticated JSON-RPC — triggers Odoo to email the invoice
- Inline success/error row appears below the invoice row, auto-hides 6s
- Button shows "Enviando…" spinner state, resets on failure

Table columns:
- Remove "Saldo pendiente" column (was amount_residual)
- Rename "Total" → "Importe"
- min-width reduced to 700px now that there are 6 columns
- Font size reduced to .8rem for denser display

JS restructured so invoice email handler always runs (no early exit),
calendar handler only runs when WooDooCalendar data is present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 17:43:39 +02:00

116 lines
5.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Template: Mi cuenta Facturas de Odoo
*
* Variables disponibles:
* $invoices array Lista de facturas desde Odoo
* $total int Total de facturas
* $paged int Página actual
* $num_pages int Total de páginas
*/
defined( 'ABSPATH' ) || exit;
wp_enqueue_style( 'woodoo-frontend' );
wp_enqueue_script( 'woodoo-frontend' );
wp_localize_script( 'woodoo-frontend', 'WooDooInvoices', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'woodoo_invoice_email' ),
] );
?>
<div class="woodoo-invoices">
<h3>Tus Facturas</h3>
<?php if ( empty( $invoices ) ) : ?>
<p class="woodoo-empty">No se han encontrado facturas.</p>
<?php else : ?>
<div class="woodoo-table-wrap">
<table class="woodoo-table woodoo-invoices-table">
<thead>
<tr>
<th class="col-number">Nº Factura</th>
<th class="col-date">Fecha</th>
<th class="col-due">Vencimiento</th>
<th class="col-amount">Importe</th>
<th class="col-status">Estado</th>
<th class="col-action">Envío</th>
</tr>
</thead>
<tbody>
<?php foreach ( $invoices as $inv ) :
$currency_name = is_array( $inv['currency_id'] ) ? $inv['currency_id'][1] : '';
$currency = WooDoo_Invoices::currency_symbol( $currency_name );
$pay_state = $inv['payment_state'] ?? 'not_paid';
$badge_class = WooDoo_Invoices::payment_state_class( $pay_state );
$badge_label = WooDoo_Invoices::payment_state_label( $pay_state );
?>
<tr>
<td class="col-number woodoo-inv-number">
<?php echo esc_html( $inv['name'] ?: 'FAC-' . $inv['id'] ); ?>
</td>
<td class="col-date woodoo-nowrap">
<?php echo $inv['invoice_date']
? esc_html( date_i18n( 'd/m/Y', strtotime( $inv['invoice_date'] ) ) )
: '—'; ?>
</td>
<td class="col-due woodoo-nowrap">
<?php
if ( $inv['invoice_date_due'] ) {
$due_ts = strtotime( $inv['invoice_date_due'] );
$overdue = ( $pay_state === 'not_paid' || $pay_state === 'partial' ) && $due_ts < time();
if ( $overdue ) {
echo '<span class="woodoo-overdue">';
echo esc_html( date_i18n( 'd/m/Y', $due_ts ) );
echo '</span> <span class="woodoo-badge woodoo-badge--red">Vencida</span>';
} else {
echo esc_html( date_i18n( 'd/m/Y', $due_ts ) );
}
} else {
echo '—';
}
?>
</td>
<td class="col-amount woodoo-amount woodoo-nowrap">
<?php echo esc_html( number_format( (float) $inv['amount_total'], 2, ',', '.' ) . ' ' . $currency ); ?>
</td>
<td class="col-status woodoo-nowrap">
<span class="woodoo-badge <?php echo esc_attr( $badge_class ); ?>">
<?php echo esc_html( $badge_label ); ?>
</span>
</td>
<td class="col-action">
<button type="button"
class="woodoo-btn woodoo-btn--sm woodoo-send-invoice"
data-id="<?php echo esc_attr( $inv['id'] ); ?>"
title="Reenviar factura por correo electrónico">
✉ Reenviar
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php if ( $num_pages > 1 ) :
$base_url = wc_get_account_endpoint_url( WooDoo_Invoices::ENDPOINT );
?>
<nav class="woodoo-pagination" aria-label="Paginación de facturas">
<?php for ( $p = 1; $p <= $num_pages; $p++ ) : ?>
<?php if ( $p === $paged ) : ?>
<span class="woodoo-page-current"><?php echo esc_html( $p ); ?></span>
<?php else : ?>
<a href="<?php echo esc_url( add_query_arg( 'invoice_page', $p, $base_url ) ); ?>">
<?php echo esc_html( $p ); ?>
</a>
<?php endif; ?>
<?php endfor; ?>
</nav>
<?php endif; ?>
<?php endif; ?>
</div>