Files
WooDoo/templates/myaccount-invoices.php
Malin 02c8fee174 fix: Spanish frontend, wider columns, currency symbols, PDF download
PDF fix:
- Replace session-cookie auth with HTTP Basic Auth (username:api_key)
  which is natively supported by Odoo 17+ report endpoints
- Validate response is actually a PDF (%PDF header check) before serving
- Return a descriptive Spanish error if HTTP code != 200 or body is not PDF

Frontend → Spanish:
- All invoice template text in Spanish (Nº Factura, Vencimiento, etc.)
- All calendar/booking template text in Spanish
- Payment state labels: Pendiente / Parcial / En cobro / Pagado / Anulado
- "Vencida" badge for overdue invoices
- Error/notice messages in Spanish across both pages

Currency symbols:
- Add currency_symbol() helper mapping ISO codes to symbols
- EUR → €, USD → $, GBP → £, etc. (25 currencies mapped)

Column widths:
- Switch invoice table to table-layout:fixed with explicit column widths
- col-number: 180px nowrap so reference never wraps across lines
- Date/due/amount/status columns all fixed-width and nowrap
- Add .woodoo-nowrap utility class

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

122 lines
5.8 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' );
?>
<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">Total</th>
<th class="col-balance">Saldo pendiente</th>
<th class="col-status">Estado</th>
<th class="col-download">PDF</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 );
$pdf_url = add_query_arg( [
'action' => 'woodoo_invoice_pdf',
'invoice_id' => $inv['id'],
'nonce' => wp_create_nonce( 'woodoo_invoice_pdf' ),
], admin_url( 'admin-ajax.php' ) );
?>
<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-balance woodoo-amount woodoo-nowrap">
<?php echo esc_html( number_format( (float) $inv['amount_residual'], 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-download">
<a href="<?php echo esc_url( $pdf_url ); ?>"
class="woodoo-btn woodoo-btn--sm"
target="_blank"
rel="noopener"
title="Descargar factura en PDF">
↓ PDF
</a>
</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>