Skip to content

Commit

Permalink
Import project invoices section from orbis-4 theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Jan 30, 2024
1 parent 34de5a2 commit f8a7bcc
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
21 changes: 21 additions & 0 deletions classes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function __construct( $plugin ) {
$this->plugin = $plugin;

\add_filter( 'post_class', [ $this, 'post_class' ] );

\add_filter( 'orbis_project_sections', [ $this, 'project_sections' ] );
}

/**
Expand All @@ -34,4 +36,23 @@ public function post_class( $classes ) {

return $classes;
}

/**
* Project sections.
*
* @param array $sections Sections.
* @return array
*/
public function project_sections( $sections ) {
$sections[] = [
'id' => 'invoices',
'slug' => __( 'invoices', 'orbis-projects' ),
'name' => __( 'Invoices', 'orbis-projects' ),
'callback' => function () {
include __DIR__ . '/../templates/project-invoices.php';
},
];

return $sections;
}
}
110 changes: 110 additions & 0 deletions templates/project-invoices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

global $post;

use Pronamic\WordPress\Money\Money;

$orbis_project = new Pronamic\Orbis\Projects\Project( $post );
$invoices = $orbis_project->get_invoices();

if ( $invoices && $invoices[0]->id ) : ?>

<div class="table-responsive">
<table class="table table-striped mb-0">
<thead>
<tr>
<th class="border-top-0"><?php esc_html_e( 'Date', 'orbis-projects' ); ?></th>
<th class="border-top-0"><?php esc_html_e( 'Amount', 'orbis-projects' ); ?></th>
<th class="border-top-0"><?php esc_html_e( 'Hours', 'orbis-projects' ); ?></th>
<th class="border-top-0"><?php esc_html_e( 'Invoice Number', 'orbis-projects' ); ?></th>
<th class="border-top-0"><?php esc_html_e( 'User', 'orbis-projects' ); ?></th>
</tr>
</thead>
<?php
$amount_total = 0;
$hours_total = 0;
?>
<tbody>
<?php foreach ( $invoices as $invoice ) : ?>
<?php
$amount_total += $invoice->amount;
$hours_total += $invoice->seconds;
?>
<tr id="post-<?php the_ID(); ?>">
<td>
<?php echo esc_html( date_format( new DateTime( $invoice->create_date ), 'd-m-Y' ) ); ?>
</td>
<td>
<?php
$amount = new Money( $invoice->amount, 'EUR' );
echo esc_html( $amount->format_i18n() );
?>
</td>
<td>
<?php
if ( $invoice->seconds ) {
echo esc_html( orbis_time( $invoice->seconds ) );
}
?>
</td>
<td>
<?php
$invoice_link = orbis_get_invoice_link( $invoice->invoice_number );

if ( ! empty( $invoice_link ) ) {
printf(
'<a href="%s" target="_blank">%s</a>',
esc_attr( $invoice_link ),
esc_html( $invoice->invoice_number )
);
} else {
echo esc_html( $invoice->invoice_number );
}

if ( get_post_meta( $post->ID, '_orbis_project_invoice_number', true ) === $invoice->invoice_number ) {
printf(
' <span title="%s">✓</span>',
esc_html__( 'This is the final invoice.', 'orbis-projects' )
);
}
?>
</td>
<td>
<?php echo esc_html( $invoice->display_name ); ?>
</td>
</tr>

<?php endforeach; ?>
<tr>
<td>
<strong><?php esc_html_e( 'Total:', 'orbis-projects' ); ?></strong>
</td>
<td>
<strong>
<?php
$amount_total = new Money( $amount_total, 'EUR' );
echo esc_html( $amount_total->format_i18n() );
?>
</strong>
</td>
<td>
<strong><?php echo esc_html( orbis_time( $hours_total ) ); ?></strong>
</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>

<?php wp_reset_postdata(); ?>

<?php else : ?>

<div class="card-body">
<p class="text-muted m-0">
<?php esc_html_e( 'No invoices found.', 'orbis-projects' ); ?>
</p>
</div>

<?php endif; ?>

0 comments on commit f8a7bcc

Please sign in to comment.