Skip to content

Commit

Permalink
Working on a new projects billing page.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Feb 29, 2024
1 parent 268157f commit 97a6934
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 269 deletions.
136 changes: 34 additions & 102 deletions templates/projects-to-invoice.php → admin/page-billing.php
Original file line number Diff line number Diff line change
@@ -1,103 +1,19 @@
<?php
/**
* Page billing
*
* @author Pronamic <info@pronamic.eu>
* @copyright 2005-2024 Pronamic
* @license GPL-2.0-or-later
* @package Pronamic\Orbis\Projects
*/

global $wpdb;
global $orbis_is_projects_to_invoice;

$orbis_is_projects_to_invoice = true;

$extra = 'AND invoice_number IS NULL';

if ( filter_input( INPUT_GET, 'all', FILTER_VALIDATE_BOOLEAN ) ) {
$extra = '';
}

$sql = "
SELECT
project.id ,
project.name ,
project.number_seconds AS available_seconds ,
project.invoice_number AS invoice_number ,
project.invoicable ,
project.post_id AS project_post_id,
manager.ID AS project_manager_id,
manager.display_name AS project_manager_name,
principal.id AS principal_id ,
principal.name AS principal_name ,
principal.post_id AS principal_post_id,
SUM(registration.number_seconds) AS registered_seconds
FROM
$wpdb->orbis_projects AS project
LEFT JOIN
$wpdb->posts AS post
ON project.post_id = post.ID
LEFT JOIN
$wpdb->users AS manager
ON post.post_author = manager.ID
LEFT JOIN
$wpdb->orbis_companies AS principal
ON project.principal_id = principal.id
LEFT JOIN
$wpdb->orbis_timesheets AS registration
ON project.id = registration.project_id
WHERE
(
project.finished
OR
project.name LIKE '%strippenkaart%'
OR
project.name LIKE '%adwords%'
OR
project.name LIKE '%marketing%'
)
AND
project.invoicable
AND
NOT project.invoiced
AND
project.start_date > '2011-01-01'
$extra
GROUP BY
project.id
ORDER BY
principal.name
;
";

// Projects
$projects = $wpdb->get_results( $sql ); // unprepared SQL

// Managers
$managers = [];

// Projects and managers
foreach ( $projects as $project ) {
// Find manager
if ( ! isset( $managers[ $project->project_manager_id ] ) ) {
$manager = new stdClass();
$manager->id = $project->project_manager_id;
$manager->name = $project->project_manager_name;
$manager->projects = [];

$managers[ $manager->id ] = $manager;
}

$project->failed = $project->registered_seconds > $project->available_seconds;

$manager = $managers[ $project->project_manager_id ];

$manager->projects[] = $project;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

ksort( $managers );

require 'projects-table-view.php';
global $wpdb;

/**
* Update billable amount.
*
* @link https://github.com/wp-orbis/wp-orbis-timesheets/blob/develop/examples/update-project-billable-amount-from-post-meta.sql
* @link https://dba.stackexchange.com/questions/217220/how-i-use-multiple-sum-with-multiple-left-joins
*/
$query = "
SELECT
project.id AS project_id,
Expand Down Expand Up @@ -165,12 +81,16 @@
$data = $wpdb->get_results( $query );

?>
<div class="panel" style="font-size: 12px;">
<table class="table table-striped table-bordered table-sm">
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>

<h2><?php \esc_html_e( 'Projects', 'orbis-projects' ); ?></h2>

<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th scope="col" colspan="3"><?php \esc_html_e( 'Principal', 'orbis-projects' ); ?></th>
<th scope="col" colspan="3"><?php \esc_html_e( 'Project', 'orbis-projects' ); ?></th>
<th scope="col" colspan="4"><?php \esc_html_e( 'Project', 'orbis-projects' ); ?></th>
<th scope="col" colspan="2"><?php \esc_html_e( 'Billable', 'orbis-projects' ); ?></th>
<th scope="col" colspan="3"><?php \esc_html_e( 'Billed', 'orbis-projects' ); ?></th>
<th scope="col" colspan="2"><?php \esc_html_e( 'Timesheet', 'orbis-projects' ); ?></th>
Expand All @@ -184,6 +104,7 @@
<th scope="col"><?php \esc_html_e( 'Orbis ID', 'orbis-projects' ); ?></th>
<th scope="col"><?php \esc_html_e( 'Post ID', 'orbis-projects' ); ?></th>
<th scope="col"><?php \esc_html_e( 'Name', 'orbis-projects' ); ?></th>
<th scope="col"><?php \esc_html_e( 'Hourly rate', 'orbis-projects' ); ?></th>

<th scope="col"><?php \esc_html_e( 'Amount', 'orbis-projects' ); ?></th>
<th scope="col"><?php \esc_html_e( 'Time', 'orbis-projects' ); ?></th>
Expand Down Expand Up @@ -242,6 +163,17 @@

?>
</td>
<td>
<?php

$hourly_rate = get_post_meta( $item->project_post_id, '_orbis_hourly_rate', true );

if ( '' !== $hourly_rate ) {
echo \esc_html( number_format_i18n( $hourly_rate, 2 ) );
}

?>
</td>

<td>
<?php echo \orbis_price( $item->project_billable_amount ); ?>
Expand Down Expand Up @@ -325,14 +257,14 @@

$url = \add_query_arg(
[
'company_id' => $item->principal_id,
'project_id' => $item->project_id,
'orbis_company_id' => $item->principal_id,
'orbis_project_id' => $item->project_id,
],
home_url( 'twinfield/invoicer' )
home_url( 'moneybird/sales-invoices/new' )
);

printf(
'<a href="%s"><i class="fas fa-file-invoice"></i></a>',
'<a href="%s"><span class="dashicons dashicons-media-spreadsheet"></span></a>',
\esc_url( $url )
);

Expand Down
29 changes: 27 additions & 2 deletions classes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class Admin {
public function __construct( $plugin ) {
$this->plugin = $plugin;

// Actions
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );

// Project post type
add_action( 'admin_menu', [ $this, 'admin_menu' ] );

$this->project_post_type = new AdminProjectPostType( $plugin );
}

Expand All @@ -31,4 +31,29 @@ public function enqueue_scripts() {
wp_enqueue_script( 'orbis-autocomplete' );
wp_enqueue_style( 'select2' );
}

/**
* Admin menu.
*
* @return void
*/
public function admin_menu() {
\add_submenu_page(
'edit.php?post_type=orbis_project',
\__( 'Orbis Projects Billing', 'orbis-projects' ),
\__( 'Billing', 'orbis-projects' ),
'manage_options',
'orbis_projects_billing',
[ $this, 'page_billing' ]
);
}

/**
* Page billing.
*
* @return void
*/
public function page_billing() {
include __DIR__ . '/../admin/page-billing.php';
}
}
21 changes: 0 additions & 21 deletions classes/Shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function __construct( $plugin ) {

add_shortcode( 'orbis_projects_active', [ $this, 'shortcode_projects_active' ] );
add_shortcode( 'orbis_projects_without_agreement', [ $this, 'shortcode_projects_without_agreement' ] );
add_shortcode( 'orbis_projects_to_invoice', [ $this, 'shortcode_projects_to_invoice' ] );
}

/**
Expand Down Expand Up @@ -61,24 +60,4 @@ public function shortcode_projects_without_agreement() {

return $return;
}

/**
* Projects to invoice
*
* @param array $atts
* @return string
*/
public function shortcode_projects_to_invoice() {
$return = '';

ob_start();

include __DIR__ . '/../templates/projects-to-invoice.php';

$return = ob_get_contents();

ob_end_clean();

return $return;
}
}
Binary file modified languages/orbis-projects-nl_NL.mo
Binary file not shown.
Loading

0 comments on commit 97a6934

Please sign in to comment.