Files
WooDoo/templates/myaccount-invoices.php

116 lines
5.4 KiB
PHP
Raw Permalink Normal View History

<?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"> 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>