- Odoo JSON-RPC client (no Composer, uses wp_remote_post) - Admin settings page under WooCommerce with connection test - Customer linking: search Odoo partners from WP user profile - My Account: Odoo Invoices tab with PDF proxy download - My Account: Book a Meeting tab (slot calculator + calendar.event) - WC order → Odoo sale.order auto-sync on processing status - Products matched by SKU; partner auto-created from billing info - Uninstall cleanup (options, user meta, order meta, DB table) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
120 lines
5.6 KiB
PHP
120 lines
5.6 KiB
PHP
<?php
|
||
/**
|
||
* Template: My Account – Odoo Invoices
|
||
*
|
||
* Variables available:
|
||
* $invoices array List of invoice records from Odoo
|
||
* $total int Total invoice count
|
||
* $paged int Current page
|
||
* $num_pages int Total pages
|
||
*/
|
||
|
||
defined( 'ABSPATH' ) || exit;
|
||
|
||
// Enqueue frontend assets
|
||
wp_enqueue_style( 'woodoo-frontend' );
|
||
wp_enqueue_script( 'woodoo-frontend' );
|
||
?>
|
||
|
||
<div class="woodoo-invoices">
|
||
<h3><?php esc_html_e( 'Your Invoices', 'woodoo' ); ?></h3>
|
||
|
||
<?php if ( empty( $invoices ) ) : ?>
|
||
<p class="woodoo-empty">
|
||
<?php esc_html_e( 'No invoices found.', 'woodoo' ); ?>
|
||
</p>
|
||
<?php else : ?>
|
||
|
||
<div class="woodoo-table-wrap">
|
||
<table class="woodoo-table">
|
||
<thead>
|
||
<tr>
|
||
<th><?php esc_html_e( 'Invoice #', 'woodoo' ); ?></th>
|
||
<th><?php esc_html_e( 'Date', 'woodoo' ); ?></th>
|
||
<th><?php esc_html_e( 'Due Date', 'woodoo' ); ?></th>
|
||
<th><?php esc_html_e( 'Total', 'woodoo' ); ?></th>
|
||
<th><?php esc_html_e( 'Balance Due', 'woodoo' ); ?></th>
|
||
<th><?php esc_html_e( 'Status', 'woodoo' ); ?></th>
|
||
<th><?php esc_html_e( 'Download', 'woodoo' ); ?></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ( $invoices as $inv ) :
|
||
$currency = is_array( $inv['currency_id'] ) ? $inv['currency_id'][1] : '';
|
||
$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="woodoo-inv-number">
|
||
<?php echo esc_html( $inv['name'] ?: "INV-{$inv['id']}" ); ?>
|
||
</td>
|
||
<td>
|
||
<?php echo $inv['invoice_date']
|
||
? esc_html( date_i18n( get_option( 'date_format' ), strtotime( $inv['invoice_date'] ) ) )
|
||
: '—'; ?>
|
||
</td>
|
||
<td>
|
||
<?php
|
||
if ( $inv['invoice_date_due'] ) {
|
||
$due_ts = strtotime( $inv['invoice_date_due'] );
|
||
$overdue = $pay_state === 'not_paid' && $due_ts < time();
|
||
$class = $overdue ? ' class="woodoo-overdue"' : '';
|
||
echo '<span' . $class . '>' . // phpcs:ignore WordPress.Security.EscapeOutput
|
||
esc_html( date_i18n( get_option( 'date_format' ), $due_ts ) ) .
|
||
'</span>';
|
||
if ( $overdue ) echo ' <span class="woodoo-badge woodoo-badge--red">' . esc_html__( 'Overdue', 'woodoo' ) . '</span>';
|
||
} else {
|
||
echo '—';
|
||
}
|
||
?>
|
||
</td>
|
||
<td class="woodoo-amount">
|
||
<?php echo esc_html( number_format_i18n( $inv['amount_total'], 2 ) . ' ' . $currency ); ?>
|
||
</td>
|
||
<td class="woodoo-amount">
|
||
<?php echo esc_html( number_format_i18n( $inv['amount_residual'], 2 ) . ' ' . $currency ); ?>
|
||
</td>
|
||
<td>
|
||
<span class="woodoo-badge <?php echo esc_attr( $badge_class ); ?>">
|
||
<?php echo esc_html( $badge_label ); ?>
|
||
</span>
|
||
</td>
|
||
<td>
|
||
<a href="<?php echo esc_url( $pdf_url ); ?>"
|
||
class="woodoo-btn woodoo-btn--sm"
|
||
target="_blank"
|
||
rel="noopener">
|
||
<?php esc_html_e( 'PDF', 'woodoo' ); ?>
|
||
</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">
|
||
<?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>
|