diff --git a/templates/projects-to-invoice.php b/admin/page-billing.php similarity index 71% rename from templates/projects-to-invoice.php rename to admin/page-billing.php index bf65000..499a81a 100644 --- a/templates/projects-to-invoice.php +++ b/admin/page-billing.php @@ -1,103 +1,19 @@ + * @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, @@ -165,12 +81,16 @@ $data = $wpdb->get_results( $query ); ?> -
- +
+

+ +

+ +
- + @@ -184,6 +104,7 @@ + @@ -242,6 +163,17 @@ ?> +
+ project_post_id, '_orbis_hourly_rate', true ); + + if ( '' !== $hourly_rate ) { + echo \esc_html( number_format_i18n( $hourly_rate, 2 ) ); + } + + ?> + project_billable_amount ); ?> @@ -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( - '', + '', \esc_url( $url ) ); diff --git a/classes/Admin.php b/classes/Admin.php index ca20732..1daa262 100644 --- a/classes/Admin.php +++ b/classes/Admin.php @@ -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 ); } @@ -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'; + } } diff --git a/classes/Shortcodes.php b/classes/Shortcodes.php index 4c98715..075ca7f 100644 --- a/classes/Shortcodes.php +++ b/classes/Shortcodes.php @@ -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' ] ); } /** @@ -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; - } } diff --git a/languages/orbis-projects-nl_NL.mo b/languages/orbis-projects-nl_NL.mo index 0035c1b..bdba8a6 100644 Binary files a/languages/orbis-projects-nl_NL.mo and b/languages/orbis-projects-nl_NL.mo differ diff --git a/languages/orbis-projects-nl_NL.po b/languages/orbis-projects-nl_NL.po index 7e607c2..9f1fdce 100644 --- a/languages/orbis-projects-nl_NL.po +++ b/languages/orbis-projects-nl_NL.po @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: Orbis Projects\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/orbis-projects\n" -"POT-Creation-Date: 2024-02-15T19:23:22+00:00\n" -"PO-Revision-Date: 2024-02-15 20:23+0100\n" +"POT-Creation-Date: 2024-02-29T15:04:25+00:00\n" +"PO-Revision-Date: 2024-02-29 16:05+0100\n" "Last-Translator: Remco Tolsma \n" "Language-Team: Pronamic \n" "Language: nl_NL\n" @@ -44,7 +44,8 @@ msgstr "Pronamic" msgid "https://www.pronamic.eu/" msgstr "https://www.pronamic.nl/" -#: admin/meta-box-project-details.php:67 templates/projects-to-invoice.php:180 +#: admin/meta-box-project-details.php:67 admin/page-billing.php:100 +#: admin/page-billing.php:104 templates/projects-to-invoice.php:180 #: templates/projects-to-invoice.php:184 #: templates/projects-without-agreement.php:29 msgid "Orbis ID" @@ -66,9 +67,10 @@ msgstr "Prijs" msgid "Hourly Rate" msgstr "Uurtarief" -#: admin/meta-box-project-details.php:103 classes/AdminProjectPostType.php:47 -#: templates/projects-to-invoice.php:189 templates/projects-to-invoice.php:192 -#: templates/projects-to-invoice.php:198 +#: admin/meta-box-project-details.php:103 admin/page-billing.php:109 +#: admin/page-billing.php:112 admin/page-billing.php:118 +#: classes/AdminProjectPostType.php:47 templates/projects-to-invoice.php:189 +#: templates/projects-to-invoice.php:192 templates/projects-to-invoice.php:198 msgid "Time" msgstr "Tijd" @@ -168,9 +170,10 @@ msgstr "Datum" msgid "Invoice Number" msgstr "Factuurnummer" -#: admin/meta-box-project-invoices.php:19 templates/project-invoices.php:17 -#: templates/projects-to-invoice.php:188 templates/projects-to-invoice.php:191 -#: templates/projects-to-invoice.php:199 +#: admin/meta-box-project-invoices.php:19 admin/page-billing.php:108 +#: admin/page-billing.php:111 admin/page-billing.php:119 +#: templates/project-invoices.php:17 templates/projects-to-invoice.php:188 +#: templates/projects-to-invoice.php:191 templates/projects-to-invoice.php:199 msgid "Amount" msgstr "Bedrag" @@ -208,16 +211,75 @@ msgstr "Factuur toevoegen" msgid "Are you sure you want to delete this invoice?" msgstr "Weet je zeker dat je deze factuur wil verwijderen?" -#: classes/AdminProjectPostType.php:44 -#: templates/projects-without-agreement.php:32 -msgid "Title" -msgstr "Titel" +#: admin/page-billing.php:87 classes/ContentTypes.php:28 +#: classes/ContentTypes.php:30 classes/Plugin.php:171 +msgid "Projects" +msgstr "Projecten" -#: classes/AdminProjectPostType.php:45 templates/projects-to-invoice.php:172 +#: admin/page-billing.php:92 classes/AdminProjectPostType.php:45 +#: templates/projects-to-invoice.php:172 #: templates/projects-without-agreement.php:31 msgid "Principal" msgstr "Opdrachtgever" +#: admin/page-billing.php:93 classes/ContentTypes.php:31 classes/Plugin.php:174 +#: templates/projects-table-view.php:34 templates/projects-to-invoice.php:173 +msgid "Project" +msgstr "Project" + +#: admin/page-billing.php:94 templates/projects-to-invoice.php:174 +msgid "Billable" +msgstr "Factureerbaar" + +#: admin/page-billing.php:95 templates/projects-to-invoice.php:175 +msgid "Billed" +msgstr "Gefactureerd" + +#: admin/page-billing.php:96 templates/projects-to-invoice.php:176 +msgid "Timesheet" +msgstr "Urenregistraties" + +#: admin/page-billing.php:97 templates/projects-to-invoice.php:177 +msgid "To Bill" +msgstr "Te factureren" + +#: admin/page-billing.php:101 admin/page-billing.php:105 +#: templates/projects-to-invoice.php:181 templates/projects-to-invoice.php:185 +msgid "Post ID" +msgstr "Bericht-ID" + +#: admin/page-billing.php:102 admin/page-billing.php:106 +#: templates/projects-to-invoice.php:182 templates/projects-to-invoice.php:186 +#: templates/projects.php:155 +msgid "Name" +msgstr "Naam" + +#: admin/page-billing.php:113 classes/Theme.php:51 +#: templates/projects-to-invoice.php:193 +msgid "Invoices" +msgstr "Facturen" + +#: admin/page-billing.php:115 templates/projects-to-invoice.php:195 +msgid "Registered" +msgstr "Geregistreerd" + +#: admin/page-billing.php:116 templates/projects-to-invoice.php:196 +msgid "Available" +msgstr "Beschikbaar" + +#: classes/Admin.php:43 +msgid "Orbis Projects Billing" +msgstr "Orbis projecten facturering" + +#: classes/Admin.php:44 +msgid "Billing" +msgstr "Facturering" + +#: classes/AdminProjectPostType.php:44 +#: templates/projects-without-agreement.php:32 +msgid "Title" +msgstr "Titel" + #: classes/AdminProjectPostType.php:48 msgid "Author" msgstr "Auteur" @@ -247,22 +309,12 @@ msgstr "geopend" msgid "completed" msgstr "afgerond" -#: classes/ContentTypes.php:28 classes/ContentTypes.php:30 -#: classes/Plugin.php:129 -msgid "Projects" -msgstr "Projecten" - -#: classes/ContentTypes.php:31 classes/Plugin.php:132 -#: templates/projects-table-view.php:34 templates/projects-to-invoice.php:173 -msgid "Project" -msgstr "Project" - #: classes/ContentTypes.php:32 msgctxt "orbis_project" msgid "Add New" msgstr "Nieuw project" -#: classes/ContentTypes.php:33 classes/Plugin.php:137 +#: classes/ContentTypes.php:33 classes/Plugin.php:179 msgid "Add New Project" msgstr "Nieuw project toevoegen" @@ -270,7 +322,7 @@ msgstr "Nieuw project toevoegen" msgid "Edit Project" msgstr "Project bewerken" -#: classes/ContentTypes.php:35 classes/Plugin.php:136 +#: classes/ContentTypes.php:35 classes/Plugin.php:178 msgid "New Project" msgstr "Nieuw project" @@ -286,7 +338,7 @@ msgstr "Toon projecten" msgid "Search Projects" msgstr "Projecten zoeken" -#: classes/ContentTypes.php:39 classes/Plugin.php:134 +#: classes/ContentTypes.php:39 classes/Plugin.php:176 msgid "No projects found." msgstr "Geen projecten gevonden." @@ -437,50 +489,46 @@ msgctxt "slug" msgid "project-status" msgstr "project-status" -#: classes/Plugin.php:128 +#: classes/Plugin.php:170 msgid "Involved Persons" msgstr "Betrokken personen" -#: classes/Plugin.php:133 +#: classes/Plugin.php:175 msgid "Search project" msgstr "Zoek project" -#: classes/Plugin.php:135 +#: classes/Plugin.php:177 msgid "Add Project" msgstr "Project toevoegen" -#: classes/Plugin.php:140 +#: classes/Plugin.php:182 msgid "Person" msgstr "Persoon" -#: classes/Plugin.php:141 +#: classes/Plugin.php:183 msgid "Search person" msgstr "Zoek persoon" -#: classes/Plugin.php:142 +#: classes/Plugin.php:184 msgid "No persons found." msgstr "Geen personen gevonden." -#: classes/Plugin.php:143 +#: classes/Plugin.php:185 msgid "Add Person" msgstr "Persoon toevoegen" -#: classes/Plugin.php:144 +#: classes/Plugin.php:186 msgid "New Person" msgstr "Nieuw persoon" -#: classes/Plugin.php:145 +#: classes/Plugin.php:187 msgid "Add New Person" msgstr "Nieuw persoon toevoegen" -#: classes/Theme.php:49 +#: classes/Theme.php:50 msgid "invoices" msgstr "facturen" -#: classes/Theme.php:50 templates/projects-to-invoice.php:193 -msgid "Invoices" -msgstr "Facturen" - #: templates/project-invoices.php:19 templates/projects-table-view.php:38 msgid "Invoice" msgstr "Factuur" @@ -531,39 +579,6 @@ msgstr "Nee" msgid "Edit" msgstr "Bewerken" -#: templates/projects-to-invoice.php:174 -msgid "Billable" -msgstr "Factureerbaar" - -#: templates/projects-to-invoice.php:175 -msgid "Billed" -msgstr "Gefactureerd" - -#: templates/projects-to-invoice.php:176 -msgid "Timesheet" -msgstr "Urenregistraties" - -#: templates/projects-to-invoice.php:177 -msgid "To Bill" -msgstr "Te factureren" - -#: templates/projects-to-invoice.php:181 templates/projects-to-invoice.php:185 -msgid "Post ID" -msgstr "Bericht-ID" - -#: templates/projects-to-invoice.php:182 templates/projects-to-invoice.php:186 -#: templates/projects.php:155 -msgid "Name" -msgstr "Naam" - -#: templates/projects-to-invoice.php:195 -msgid "Registered" -msgstr "Geregistreerd" - -#: templates/projects-to-invoice.php:196 -msgid "Available" -msgstr "Beschikbaar" - #: templates/projects-without-agreement.php:30 msgid "Project Manager" msgstr "Projectleider" diff --git a/languages/orbis-projects.pot b/languages/orbis-projects.pot index 414e119..e194731 100644 --- a/languages/orbis-projects.pot +++ b/languages/orbis-projects.pot @@ -9,7 +9,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2024-02-15T19:23:22+00:00\n" +"POT-Creation-Date: 2024-02-29T15:04:25+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.10.0\n" "X-Domain: orbis-projects\n" @@ -40,6 +40,8 @@ msgid "https://www.pronamic.eu/" msgstr "" #: admin/meta-box-project-details.php:67 +#: admin/page-billing.php:100 +#: admin/page-billing.php:104 #: templates/projects-to-invoice.php:180 #: templates/projects-to-invoice.php:184 #: templates/projects-without-agreement.php:29 @@ -65,6 +67,9 @@ msgid "Hourly Rate" msgstr "" #: admin/meta-box-project-details.php:103 +#: admin/page-billing.php:109 +#: admin/page-billing.php:112 +#: admin/page-billing.php:118 #: classes/AdminProjectPostType.php:47 #: templates/projects-to-invoice.php:189 #: templates/projects-to-invoice.php:192 @@ -165,6 +170,9 @@ msgid "Invoice Number" msgstr "" #: admin/meta-box-project-invoices.php:19 +#: admin/page-billing.php:108 +#: admin/page-billing.php:111 +#: admin/page-billing.php:119 #: templates/project-invoices.php:17 #: templates/projects-to-invoice.php:188 #: templates/projects-to-invoice.php:191 @@ -208,17 +216,92 @@ msgstr "" msgid "Are you sure you want to delete this invoice?" msgstr "" -#: classes/AdminProjectPostType.php:44 -#: templates/projects-without-agreement.php:32 -msgid "Title" +#: admin/page-billing.php:87 +#: classes/ContentTypes.php:28 +#: classes/ContentTypes.php:30 +#: classes/Plugin.php:171 +msgid "Projects" msgstr "" +#: admin/page-billing.php:92 #: classes/AdminProjectPostType.php:45 #: templates/projects-to-invoice.php:172 #: templates/projects-without-agreement.php:31 msgid "Principal" msgstr "" +#: admin/page-billing.php:93 +#: classes/ContentTypes.php:31 +#: classes/Plugin.php:174 +#: templates/projects-table-view.php:34 +#: templates/projects-to-invoice.php:173 +msgid "Project" +msgstr "" + +#: admin/page-billing.php:94 +#: templates/projects-to-invoice.php:174 +msgid "Billable" +msgstr "" + +#: admin/page-billing.php:95 +#: templates/projects-to-invoice.php:175 +msgid "Billed" +msgstr "" + +#: admin/page-billing.php:96 +#: templates/projects-to-invoice.php:176 +msgid "Timesheet" +msgstr "" + +#: admin/page-billing.php:97 +#: templates/projects-to-invoice.php:177 +msgid "To Bill" +msgstr "" + +#: admin/page-billing.php:101 +#: admin/page-billing.php:105 +#: templates/projects-to-invoice.php:181 +#: templates/projects-to-invoice.php:185 +msgid "Post ID" +msgstr "" + +#: admin/page-billing.php:102 +#: admin/page-billing.php:106 +#: templates/projects-to-invoice.php:182 +#: templates/projects-to-invoice.php:186 +#: templates/projects.php:155 +msgid "Name" +msgstr "" + +#: admin/page-billing.php:113 +#: classes/Theme.php:51 +#: templates/projects-to-invoice.php:193 +msgid "Invoices" +msgstr "" + +#: admin/page-billing.php:115 +#: templates/projects-to-invoice.php:195 +msgid "Registered" +msgstr "" + +#: admin/page-billing.php:116 +#: templates/projects-to-invoice.php:196 +msgid "Available" +msgstr "" + +#: classes/Admin.php:43 +msgid "Orbis Projects Billing" +msgstr "" + +#: classes/Admin.php:44 +msgid "Billing" +msgstr "" + +#: classes/AdminProjectPostType.php:44 +#: templates/projects-without-agreement.php:32 +msgid "Title" +msgstr "" + #: classes/AdminProjectPostType.php:48 msgid "Author" msgstr "" @@ -250,26 +333,13 @@ msgstr "" msgid "completed" msgstr "" -#: classes/ContentTypes.php:28 -#: classes/ContentTypes.php:30 -#: classes/Plugin.php:129 -msgid "Projects" -msgstr "" - -#: classes/ContentTypes.php:31 -#: classes/Plugin.php:132 -#: templates/projects-table-view.php:34 -#: templates/projects-to-invoice.php:173 -msgid "Project" -msgstr "" - #: classes/ContentTypes.php:32 msgctxt "orbis_project" msgid "Add New" msgstr "" #: classes/ContentTypes.php:33 -#: classes/Plugin.php:137 +#: classes/Plugin.php:179 msgid "Add New Project" msgstr "" @@ -278,7 +348,7 @@ msgid "Edit Project" msgstr "" #: classes/ContentTypes.php:35 -#: classes/Plugin.php:136 +#: classes/Plugin.php:178 msgid "New Project" msgstr "" @@ -295,7 +365,7 @@ msgid "Search Projects" msgstr "" #: classes/ContentTypes.php:39 -#: classes/Plugin.php:134 +#: classes/Plugin.php:176 msgid "No projects found." msgstr "" @@ -446,49 +516,44 @@ msgctxt "slug" msgid "project-status" msgstr "" -#: classes/Plugin.php:128 +#: classes/Plugin.php:170 msgid "Involved Persons" msgstr "" -#: classes/Plugin.php:133 +#: classes/Plugin.php:175 msgid "Search project" msgstr "" -#: classes/Plugin.php:135 +#: classes/Plugin.php:177 msgid "Add Project" msgstr "" -#: classes/Plugin.php:140 +#: classes/Plugin.php:182 msgid "Person" msgstr "" -#: classes/Plugin.php:141 +#: classes/Plugin.php:183 msgid "Search person" msgstr "" -#: classes/Plugin.php:142 +#: classes/Plugin.php:184 msgid "No persons found." msgstr "" -#: classes/Plugin.php:143 +#: classes/Plugin.php:185 msgid "Add Person" msgstr "" -#: classes/Plugin.php:144 +#: classes/Plugin.php:186 msgid "New Person" msgstr "" -#: classes/Plugin.php:145 +#: classes/Plugin.php:187 msgid "Add New Person" msgstr "" -#: classes/Theme.php:49 -msgid "invoices" -msgstr "" - #: classes/Theme.php:50 -#: templates/projects-to-invoice.php:193 -msgid "Invoices" +msgid "invoices" msgstr "" #: templates/project-invoices.php:19 @@ -542,41 +607,6 @@ msgstr "" msgid "Edit" msgstr "" -#: templates/projects-to-invoice.php:174 -msgid "Billable" -msgstr "" - -#: templates/projects-to-invoice.php:175 -msgid "Billed" -msgstr "" - -#: templates/projects-to-invoice.php:176 -msgid "Timesheet" -msgstr "" - -#: templates/projects-to-invoice.php:177 -msgid "To Bill" -msgstr "" - -#: templates/projects-to-invoice.php:181 -#: templates/projects-to-invoice.php:185 -msgid "Post ID" -msgstr "" - -#: templates/projects-to-invoice.php:182 -#: templates/projects-to-invoice.php:186 -#: templates/projects.php:155 -msgid "Name" -msgstr "" - -#: templates/projects-to-invoice.php:195 -msgid "Registered" -msgstr "" - -#: templates/projects-to-invoice.php:196 -msgid "Available" -msgstr "" - #: templates/projects-without-agreement.php:30 msgid "Project Manager" msgstr ""