From 9b3dafd895b7a707b2fa9bf6402bf9582a877573 Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Thu, 15 May 2025 16:12:05 -0300 Subject: [PATCH 01/11] Retrieve auth_token from API response Auth token is no longer located at $response_body but at $response['headers'] --- classes/api_calls.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/classes/api_calls.php b/classes/api_calls.php index c70e995..8b0676c 100644 --- a/classes/api_calls.php +++ b/classes/api_calls.php @@ -85,6 +85,11 @@ public function login( $email, $password ) { } $this->set_auth_token( $login_call['auth_token'] ); + + $account_details = $login_call; + unset( $account_details['auth_token']); + update_option( 'wpcable_account_details', $account_details ); + } /** @@ -241,15 +246,6 @@ private function request( $url, $args = [], $method = 'POST', $headers = [] ) { } $response_body = json_decode( $response['body'], true ); - - if( isset( $response['headers'] ) ) { - - $full_header = $response['headers']->getAll(); - if ( isset( $full_header['auth-token'] ) && !empty( $full_header['auth-token'] ) ) { - - $response_body['auth_token'] = $full_header['auth-token']; - } - } if ( is_array( $response_body ) && ! empty( $response_body['errors'] ) ) { if ( false !== array_search( 'Invalid login credentials', $response_body['errors'], true ) ) { @@ -260,6 +256,12 @@ private function request( $url, $args = [], $method = 'POST', $headers = [] ) { } } + $data = $response['headers']->getAll(); + + if ( isset( $data['auth-token'] ) ) { + $response_body['auth_token'] = $data['auth-token']; + } + return $response_body; } } From 95f151ef2266a1ddf50ac7cca109302782b3cd6c Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Thu, 15 May 2025 16:18:22 -0300 Subject: [PATCH 02/11] Renames typo 'transcactions' & bumps version Also fixes database table name. --- CHANGELOG.md | 4 ++++ classes/api_data.php | 8 ++++---- classes/clients.php | 2 +- classes/stats.php | 40 ++++++++++++++++++------------------ functions/admin-page.php | 8 ++++---- functions/admin-settings.php | 4 ++-- functions/admin-tasks.php | 2 +- functions/helpers.php | 2 +- uninstall.php | 3 ++- wp-codeable.php | 14 ++++++------- 10 files changed, 46 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b32eb7a..bf00611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,3 +38,7 @@ *0.0.20 (2019-07-07)* * Update UI layout to match current WordPress standards * Apply WordPress coding standards to code + +*0.3.2 (2025-05-15)* +* Fixes assignment of auth_token from API login +* Renames typo `transcactions` to `transactions` diff --git a/classes/api_data.php b/classes/api_data.php index bf3ac0e..c554ca8 100644 --- a/classes/api_data.php +++ b/classes/api_data.php @@ -38,7 +38,7 @@ public function __construct() { global $wpdb; $this->tables = [ - 'transcactions' => $wpdb->prefix . 'codeable_transcactions', + 'transactions' => $wpdb->prefix . 'codeable_transactions', 'clients' => $wpdb->prefix . 'codeable_clients', 'amounts' => $wpdb->prefix . 'codeable_amounts', 'tasks' => $wpdb->prefix . 'codeable_tasks', @@ -241,7 +241,7 @@ private function store_transactions( $page ) { // Check if transactions already exists. $check = $wpdb->get_results( "SELECT COUNT(1) AS totalrows - FROM `{$this->tables['transcactions']}` + FROM `{$this->tables['transactions']}` WHERE id = '{$tr['id']}'; " ); @@ -267,13 +267,13 @@ private function store_transactions( $page ) { if ( $new_tr['id'] && is_int( $new_tr['id'] ) ) { if ( $exists ) { $db_res = $wpdb->update( - $this->tables['transcactions'], + $this->tables['transactions'], $new_tr, [ 'id' => $tr['id'] ] ); } else { $db_res = $wpdb->insert( - $this->tables['transcactions'], + $this->tables['transactions'], $new_tr ); } diff --git a/classes/clients.php b/classes/clients.php index 854a76c..e20c41c 100644 --- a/classes/clients.php +++ b/classes/clients.php @@ -17,7 +17,7 @@ public function __construct() { global $wpdb; $this->tables = array( - 'transactions' => $wpdb->prefix . 'codeable_transcactions', + 'transactions' => $wpdb->prefix . 'codeable_transactions', 'clients' => $wpdb->prefix . 'codeable_clients', 'amounts' => $wpdb->prefix . 'codeable_amounts', ); diff --git a/classes/stats.php b/classes/stats.php index 30d01ea..dcf3e21 100644 --- a/classes/stats.php +++ b/classes/stats.php @@ -18,7 +18,7 @@ public function __construct() { global $wpdb; $this->tables = array( - 'transcactions' => $wpdb->prefix . 'codeable_transcactions', + 'transactions' => $wpdb->prefix . 'codeable_transactions', 'clients' => $wpdb->prefix . 'codeable_clients', 'amounts' => $wpdb->prefix . 'codeable_amounts', ); @@ -38,9 +38,9 @@ public function get_dates_totals( $from_day, $from_month, $from_year, $to_day, $ SUM(debit_user_amount) as total_cost, count(1) as tasks FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' AND (dateadded BETWEEN '" . $first_date . "' AND '" . $last_date . "') @@ -69,9 +69,9 @@ public function get_days( $from_day, $from_month, $from_year, $to_day, $to_month debit_user_amount as total_cost, dateadded FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' AND (dateadded BETWEEN '" . $first_date . "' AND '" . $last_date . "') @@ -118,9 +118,9 @@ public function get_dates_average( $from_day, $from_month, $from_year, $to_day, AVG(credit_revenue_amount) as revenue, AVG(debit_user_amount) as total_cost FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' AND (dateadded BETWEEN '" . $first_date . "' AND '" . $last_date . "') @@ -216,12 +216,12 @@ public function get_first_task() { SELECT * FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' - ORDER BY " . $this->tables['transcactions'] . '.id ASC + ORDER BY " . $this->tables['transactions'] . '.id ASC LIMIT 0,1 '; @@ -238,12 +238,12 @@ public function get_last_task() { SELECT * FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' - ORDER BY " . $this->tables['transcactions'] . '.id DESC + ORDER BY " . $this->tables['transactions'] . '.id DESC LIMIT 0,1 '; @@ -270,9 +270,9 @@ public function get_amounts_range( $from_day, $from_month, $from_year, $to_day, SELECT credit_revenue_amount FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' AND (dateadded BETWEEN '" . $first_date . "' AND '" . $last_date . "') @@ -318,7 +318,7 @@ public function get_tasks_per_month( $from_day, $from_month, $from_year, $to_day SELECT DATE_FORMAT(dateadded,'%Y-%m') as dateadded, count(1) as tasks_per_month FROM - " . $this->tables['transcactions'] . " + " . $this->tables['transactions'] . " WHERE `description` = 'task_completion' AND (dateadded BETWEEN '" . $first_date . "' AND '" . $last_date . "') @@ -349,9 +349,9 @@ public function get_tasks_type( $from_day, $from_month, $from_year, $to_day, $to SUM(credit_revenue_amount) as revenue, SUM(credit_fee_amount) as fee FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' AND (dateadded BETWEEN '" . $first_date . "' AND '" . $last_date . "') @@ -391,9 +391,9 @@ public function get_preferred_count( $from_day, $from_month, $from_year, $to_day SUM(credit_revenue_amount) as revenue, SUM(credit_fee_amount) as fee FROM - ' . $this->tables['transcactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' + ' . $this->tables['transactions'] . ' LEFT JOIN ' . $this->tables['amounts'] . ' ON - ' . $this->tables['transcactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id + ' . $this->tables['transactions'] . '.task_id = ' . $this->tables['amounts'] . ".task_id WHERE `description` = 'task_completion' AND (preferred = 1 OR preferred = 0) diff --git a/functions/admin-page.php b/functions/admin-page.php index 588027e..a18c6a8 100644 --- a/functions/admin-page.php +++ b/functions/admin-page.php @@ -15,15 +15,15 @@ function wpcable_register_menu_page() { __( 'Codeable Stats', 'wpcable' ), __( 'Codeable Stats', 'wpcable' ), 'manage_options', - 'codeable_transcactions_stats', - 'codeable_transcactions_stats_cb', + 'codeable_transactions_stats', + 'codeable_transactions_stats_cb', 'data:image/svg+xml;base64,' . base64_encode( $icon_code ), 2 ); } add_action( 'admin_menu', 'wpcable_register_menu_page' ); -function codeable_transcactions_stats_cb() { +function codeable_transactions_stats_cb() { codeable_page_requires_login( __( 'Codeable Stats', 'wpcable' ) ); codeable_maybe_refresh_data(); @@ -307,7 +307,7 @@ class="value">
- +
<?php echo __( 'compare dates', 'wpcable' ); ?> diff --git a/functions/admin-settings.php b/functions/admin-settings.php index a53646e..3aa9a09 100644 --- a/functions/admin-settings.php +++ b/functions/admin-settings.php @@ -15,7 +15,7 @@ */ function wpcable_options() { add_submenu_page( - 'codeable_transcactions_stats', + 'codeable_transactions_stats', 'Estimate', 'Estimate', 'manage_options', @@ -23,7 +23,7 @@ function wpcable_options() { 'codeable_estimate_callback' ); add_submenu_page( - 'codeable_transcactions_stats', + 'codeable_transactions_stats', 'Settings', 'Settings', 'manage_options', diff --git a/functions/admin-tasks.php b/functions/admin-tasks.php index af3fc0e..55785d0 100644 --- a/functions/admin-tasks.php +++ b/functions/admin-tasks.php @@ -16,7 +16,7 @@ */ function wpcable_tasks_menu() { add_submenu_page( - 'codeable_transcactions_stats', + 'codeable_transactions_stats', 'Tasks', 'Tasks', 'manage_options', diff --git a/functions/helpers.php b/functions/helpers.php index cf032d0..8823843 100644 --- a/functions/helpers.php +++ b/functions/helpers.php @@ -227,7 +227,7 @@ function codeable_flush_all_data() { global $wpdb; $tables = [ - $wpdb->prefix . 'codeable_transcactions' => __( 'Transcactions', 'wpcable' ), + $wpdb->prefix . 'codeable_transactions' => __( 'transactions', 'wpcable' ), $wpdb->prefix . 'codeable_clients' => __( 'Clients', 'wpcable' ), $wpdb->prefix . 'codeable_amounts' => __( 'Amounts', 'wpcable' ), $wpdb->prefix . 'codeable_tasks' => __( 'Tasks', 'wpcable' ), diff --git a/uninstall.php b/uninstall.php index 3110c8d..474a861 100644 --- a/uninstall.php +++ b/uninstall.php @@ -82,7 +82,7 @@ private static function remove_plugin_options() { $prefix . 'balance', $prefix . 'average', $prefix . 'what_to_check', - $prefix . 'transcactions_version' + $prefix . 'transactions_version' ); foreach( $options as $option ) { @@ -103,6 +103,7 @@ private static function remove_plugin_tables() { $tables = array( $prefix . 'codeable_transcactions', + $prefix . 'codeable_transactions', $prefix . 'codeable_amounts', $prefix . 'codeable_clients', ); diff --git a/wp-codeable.php b/wp-codeable.php index eca0d43..2ef7168 100644 --- a/wp-codeable.php +++ b/wp-codeable.php @@ -5,9 +5,9 @@ * Plugin Name: Codeable - Expert's Stats * Plugin URI: https://github.com/codeablehq/blackbook/wiki/Expert-Stats-Plugin * Description: Get your Codeable data - * Version: 0.3.1 + * Version: 0.3.2 * Author: Spyros Vlachopoulos - * Contributors: Panagiotis Synetos, John Leskas, Justin Frydman, Jonathan Bossenger, Rob Scott, Philipp Stracker, Peter Kakoma + * Contributors: Panagiotis Synetos, John Leskas, Justin Frydman, Jonathan Bossenger, Rob Scott, Philipp Stracker, Peter Kakoma, Gabriel Reguly * Author URI: https://codeable.io/developers/spyros-vlachopoulos/ * License: GPL2 * Text Domain: wpcable @@ -130,15 +130,15 @@ function wpcable_sync_process() { function wpcable_install() { global $wpdb; - $wpcable_db_version = '0.0.3'; + $wpcable_db_version = '0.0.3.1'; - if ( get_option( 'wpcable_transcactions_version' ) !== $wpcable_db_version ) { + if ( get_option( 'wpcable_transactions_version' ) !== $wpcable_db_version ) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset_collate = $wpdb->get_charset_collate(); - $table_name = $wpdb->prefix . 'codeable_transcactions'; + $table_name = $wpdb->prefix . 'codeable_transactions'; $sql = "CREATE TABLE {$table_name} ( `id` int(11) NOT NULL, @@ -226,7 +226,7 @@ function wpcable_install() { $db_delta = dbDelta( $sql ); - update_option( 'wpcable_transcactions_version', $wpcable_db_version ); + update_option( 'wpcable_transactions_version', $wpcable_db_version ); } } @@ -243,7 +243,7 @@ function wpcable_deactivate() { function wpcable_admin_scripts( $hook ) { $plugin_hooks = [ - 'toplevel_page_codeable_transcactions_stats', + 'toplevel_page_codeable_transactions_stats', 'codeable-stats_page_codeable_tasks', 'codeable-stats_page_codeable_estimate', 'codeable-stats_page_codeable_settings', From 72285d487528128c4f0273f7bf5cceaca307e702 Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Thu, 15 May 2025 16:27:21 -0300 Subject: [PATCH 03/11] Removes more options and tables on uninstall --- uninstall.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index 474a861..591b544 100644 --- a/uninstall.php +++ b/uninstall.php @@ -82,7 +82,15 @@ private static function remove_plugin_options() { $prefix . 'balance', $prefix . 'average', $prefix . 'what_to_check', - $prefix . 'transactions_version' + $prefix . 'transcactions_version', + $prefix . 'transactions_version', + $prefix . 'auth_token', + $prefix . 'cancel_after_days', + $prefix . 'email', + $prefix . 'fee_type', + $prefix . 'last_fetch', + $prefix . 'rate', + $prefix . 'tasks_stop_at_page ', ); foreach( $options as $option ) { @@ -106,6 +114,7 @@ private static function remove_plugin_tables() { $prefix . 'codeable_transactions', $prefix . 'codeable_amounts', $prefix . 'codeable_clients', + $prefix . 'codeable_tasks', ); $wpdb->query( 'DROP TABLE IF EXISTS ' . implode( ',', $tables ) ); From e8d8736c7e51b1b460542a5cee95eb9dc8005ce2 Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Sat, 17 May 2025 15:59:02 -0300 Subject: [PATCH 04/11] Clears databasee table and option fields on uninstall/flush data Also some cosmetic changes and removal of what_to_check option field --- functions/helpers.php | 36 ++++++++++++++++++++++++++---------- uninstall.php | 17 +++++++++-------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/functions/helpers.php b/functions/helpers.php index 8823843..0de18e0 100644 --- a/functions/helpers.php +++ b/functions/helpers.php @@ -227,10 +227,10 @@ function codeable_flush_all_data() { global $wpdb; $tables = [ - $wpdb->prefix . 'codeable_transactions' => __( 'transactions', 'wpcable' ), - $wpdb->prefix . 'codeable_clients' => __( 'Clients', 'wpcable' ), - $wpdb->prefix . 'codeable_amounts' => __( 'Amounts', 'wpcable' ), - $wpdb->prefix . 'codeable_tasks' => __( 'Tasks', 'wpcable' ), + $wpdb->prefix . 'codeable_transactions' => __( 'Transactions', 'wpcable' ), + $wpdb->prefix . 'codeable_clients' => __( 'Clients', 'wpcable' ), + $wpdb->prefix . 'codeable_amounts' => __( 'Amounts', 'wpcable' ), + $wpdb->prefix . 'codeable_tasks' => __( 'Tasks', 'wpcable' ), ]; $redirect_to = ''; @@ -260,12 +260,28 @@ function codeable_flush_all_data() { // Flush object cache. wpcable_cache::flush(); - delete_option( 'wpcable_email' ); - delete_option( 'wpcable_average' ); - delete_option( 'wpcable_balance' ); - delete_option( 'wpcable_revenue' ); - delete_option( 'wpcable_last_fetch' ); - delete_option( 'wpcable_account_details' ); + $prefix = 'wpcable_'; + + $options = array( + $prefix . 'account_details', + $prefix . 'api_queue', + $prefix . 'auth_token', + $prefix . 'average', + $prefix . 'balance', + $prefix . 'cancel_after_days', + $prefix . 'email', + $prefix . 'fee_type', + $prefix . 'last_fetch', + $prefix . 'rate', + $prefix . 'revenue', + $prefix . 'tasks_stop_at_page ', + $prefix . 'transactions_version', + $prefix . 'transcactions_version', + ); + + foreach( $options as $option ) { + delete_option( $option ); + } codeable_api_logout(); diff --git a/uninstall.php b/uninstall.php index 591b544..dff0bee 100644 --- a/uninstall.php +++ b/uninstall.php @@ -78,19 +78,20 @@ private static function remove_plugin_options() { $options = array( $prefix . 'account_details', - $prefix . 'revenue', - $prefix . 'balance', - $prefix . 'average', - $prefix . 'what_to_check', - $prefix . 'transcactions_version', - $prefix . 'transactions_version', + $prefix . 'api_queue', $prefix . 'auth_token', + $prefix . 'average', + $prefix . 'balance', $prefix . 'cancel_after_days', $prefix . 'email', $prefix . 'fee_type', $prefix . 'last_fetch', $prefix . 'rate', + $prefix . 'revenue', $prefix . 'tasks_stop_at_page ', + $prefix . 'transactions_version', + $prefix . 'transcactions_version', + $prefix . 'what_to_check', ); foreach( $options as $option ) { @@ -110,11 +111,11 @@ private static function remove_plugin_tables() { $prefix = $wpdb->prefix; $tables = array( - $prefix . 'codeable_transcactions', - $prefix . 'codeable_transactions', $prefix . 'codeable_amounts', $prefix . 'codeable_clients', $prefix . 'codeable_tasks', + $prefix . 'codeable_transactions', + $prefix . 'codeable_transcactions', ); $wpdb->query( 'DROP TABLE IF EXISTS ' . implode( ',', $tables ) ); From 4b902e094ac106a8abdbdd8835c926d9223d85c8 Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Sat, 17 May 2025 16:01:39 -0300 Subject: [PATCH 05/11] Adds claims to dashboard / Fixes Completed Tasks as integer value --- functions/admin-page.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/functions/admin-page.php b/functions/admin-page.php index a18c6a8..31a1775 100644 --- a/functions/admin-page.php +++ b/functions/admin-page.php @@ -141,7 +141,7 @@ function codeable_transactions_stats_cb() {
-
+
: @@ -158,6 +158,21 @@ function codeable_transactions_stats_cb() {

+
+ +
+
+
+ +
+
+
+ : + + / + + +
From d1d20b75fc89f4676f768057d31547efc1b39eb7 Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Sat, 17 May 2025 16:30:14 -0300 Subject: [PATCH 06/11] Deals with user data comming from login No need to call profile API anymore. Average, balanc and revenue also come from login --- classes/api_calls.php | 2 ++ classes/api_data.php | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/classes/api_calls.php b/classes/api_calls.php index 8b0676c..66311e6 100644 --- a/classes/api_calls.php +++ b/classes/api_calls.php @@ -90,6 +90,8 @@ public function login( $email, $password ) { unset( $account_details['auth_token']); update_option( 'wpcable_account_details', $account_details ); + update_option( 'wpcable_average', $account_details['stats']['avg_task_size'] ); + update_option( 'wpcable_balance', $account_details['balance'] ); } /** diff --git a/classes/api_data.php b/classes/api_data.php index c554ca8..0e3f1da 100644 --- a/classes/api_data.php +++ b/classes/api_data.php @@ -57,12 +57,18 @@ public function __construct() { public function prepare_queue() { $queue = []; + /* + + Profile comes from login API call, no need to do it again. + $queue[] = [ 'task' => 'profile', 'label' => 'User profile', 'page' => 0, 'paged' => false, ]; + + */ $queue[] = [ 'task' => 'transactions', 'label' => 'Transactions', @@ -226,9 +232,8 @@ private function store_transactions( $page ) { $single_page = $this->api_calls->transactions_page( $page ); if ( 2 === $page ) { - update_option( 'wpcable_average', $single_page['average_task_size'] ); - update_option( 'wpcable_balance', $single_page['balance'] ); - update_option( 'wpcable_revenue', $single_page['revenue'] ); + //wc_get_logger()->debug( print_r( $single_page, 1 ), ['source' => 'Transactions page 2'] ); + //update_option( 'wpcable_revenue', $single_page['revenue'] ); } if ( empty( $single_page['transactions'] ) ) { @@ -297,9 +302,6 @@ private function store_transactions( $page ) { // If we find a transaction that already exists, bail out and don't continue updating all the transactions if ( $exists ) { - update_option( 'wpcable_average', $single_page['average_task_size'] ); - update_option( 'wpcable_balance', $single_page['balance'] ); - update_option( 'wpcable_revenue', $single_page['revenue'] ); return false; } From 725fa7a97119509df8280f0df4ce314564465397 Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Sat, 17 May 2025 16:25:25 -0300 Subject: [PATCH 07/11] Fixes for transactions and amounts --- classes/api_calls.php | 2 +- classes/api_data.php | 48 +++++++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/classes/api_calls.php b/classes/api_calls.php index 66311e6..3615237 100644 --- a/classes/api_calls.php +++ b/classes/api_calls.php @@ -162,7 +162,7 @@ public function self() { * @return array */ public function transactions_page( $page = 1 ) { - $url = 'users/me/transactions'; + $url = 'experts/transactions/'; $args = [ 'page' => $page ]; $transactions = $this->request( $url, $args, 'get' ); diff --git a/classes/api_data.php b/classes/api_data.php index 0e3f1da..5878b96 100644 --- a/classes/api_data.php +++ b/classes/api_data.php @@ -236,12 +236,32 @@ private function store_transactions( $page ) { //update_option( 'wpcable_revenue', $single_page['revenue'] ); } - if ( empty( $single_page['transactions'] ) ) { + if ( empty( $single_page ) ) { + return false; + } else { + // Get all data to the DB. - foreach ( $single_page['transactions'] as $tr ) { + foreach ( $single_page as $tr ) { + + if ( ! in_array( $tr['description'], array( 'ad_hoc_expert_credit', 'partial_refund', 'task_completion' ) ) ) { + + /* + ad_hoc_expert_credit + ad_hoc_expert_debit + ad_hoc_team_work + contractor_withdrawal + expert_withdrawal_request + partial_refund + task_completion + + */ + + continue; + } + // Check if transactions already exists. $check = $wpdb->get_results( @@ -253,18 +273,20 @@ private function store_transactions( $page ) { $exists = $check[0]->totalrows > 0; + $task_id = ( $tr['resources']['sub_task']['id'] ? $tr['resources']['sub_task']['id'] : $tr['resources']['project']['id'] ); + $new_tr = [ 'id' => $tr['id'], 'description' => $tr['description'], - 'dateadded' => date( 'Y-m-d H:i:s', $tr['timestamp'] ), + 'dateadded' => $tr['created_at'], 'fee_percentage' => $tr['fee_percentage'], 'fee_amount' => $tr['fee_amount'], - 'task_type' => $tr['task']['kind'], - 'task_id' => $tr['task']['id'], - 'task_title' => $tr['task']['title'], - 'parent_task_id' => ( $tr['task']['parent_task_id'] > 0 ? $tr['task']['parent_task_id'] : 0 ), - 'preferred' => $tr['task']['current_user_is_preferred_contractor'], - 'client_id' => $tr['task_client']['id'], + 'task_type' => $tr['resources']['project']['kind'], + 'task_id' => $task_id, + 'task_title' => $tr['resources']['project']['title'], + 'parent_task_id' => ( $tr['resources']['project']['parent_task_id'] > 0 ? ['resources']['project']['parent_task_id'] : 0 ), + 'preferred' => $tr['resources']['project']['current_user_is_preferred_contractor'], + 'client_id' => $tr['resources']['client']['id'], 'last_sync' => time(), ]; @@ -294,10 +316,10 @@ private function store_transactions( $page ) { $this->store_client( $tr['task_client'] ); $this->store_amount( - $tr['task']['id'], - $tr['task_client']['id'], - $tr['credit_amounts'], - $tr['debit_amounts'] + $task_id, + $tr['resources']['client']['id'], + $tr['amount'], + $tr['fee_amount'] ); // If we find a transaction that already exists, bail out and don't continue updating all the transactions From f21b563cd723caa49a8f22cbe11e56f497f79b9f Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Sat, 17 May 2025 17:05:40 -0300 Subject: [PATCH 08/11] More fixes for amounts --- classes/api_data.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/classes/api_data.php b/classes/api_data.php index 5878b96..383887b 100644 --- a/classes/api_data.php +++ b/classes/api_data.php @@ -587,7 +587,7 @@ private function store_amount( $task_id, $client_id, $credit, $debit ) { return; } - $new_amount = [ + /*$new_amount = [ 'task_id' => $task_id, 'client_id' => $client_id, 'credit_revenue_id' => $credit[0]['id'], @@ -600,6 +600,21 @@ private function store_amount( $task_id, $client_id, $credit, $debit ) { 'debit_cost_amount' => $debit[0]['amount'], 'debit_user_id' => $debit[1]['id'], 'debit_user_amount' => $debit[1]['amount'], + ];*/ + + $new_amount = [ + 'task_id' => $task_id, + 'client_id' => $client_id, + 'credit_revenue_id' => $task_id, + 'credit_revenue_amount' => $credit, + 'credit_fee_id' => $task_id, + 'credit_fee_amount' => $credit, + 'credit_user_id' => $client_id, + 'credit_user_amount' => $credit, + 'debit_cost_id' => $task_id, + 'debit_cost_amount' => $debit, + 'debit_user_id' => $client_id, + 'debit_user_amount' => $debit, ]; $wpdb->replace( $this->tables['amounts'], $new_amount ); From 8fbf9b6d118938494d3faa9d1f66e3359c60cf87 Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Mon, 26 May 2025 20:09:36 -0300 Subject: [PATCH 09/11] Update README.md, bump WP version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03428a6..3135fb4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Codeable Expert Stats Plugin Readme *Contributors:* Spyros Vlachopoulos, Panagiotis Synetos, John Leskas, Justin Frydman, Jonathan Bossenger, Rob Scott, Philipp Stracker, Milan Dinić -*Tested up to:* WordPress 5.2.2 +*Tested up to:* WordPress 6.8.1 Codeable Expert Stats plugin makes it easy for you to track and monitor your success as an expert on Codeable via an easy-to-understand dashboard for your personal/agency WordPress site. From 4801fb5378cd110bc7097d31c21bec43bb3c8a4d Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Mon, 26 May 2025 22:33:06 -0300 Subject: [PATCH 10/11] Fixes for Sub tasks --- classes/api_data.php | 50 +++++++++++++++++++++++++++++----------- functions/admin-page.php | 2 +- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/classes/api_data.php b/classes/api_data.php index 383887b..4f537a6 100644 --- a/classes/api_data.php +++ b/classes/api_data.php @@ -233,6 +233,7 @@ private function store_transactions( $page ) { if ( 2 === $page ) { //wc_get_logger()->debug( print_r( $single_page, 1 ), ['source' => 'Transactions page 2'] ); + // TODO: find out revenue //update_option( 'wpcable_revenue', $single_page['revenue'] ); } @@ -273,22 +274,45 @@ private function store_transactions( $page ) { $exists = $check[0]->totalrows > 0; - $task_id = ( $tr['resources']['sub_task']['id'] ? $tr['resources']['sub_task']['id'] : $tr['resources']['project']['id'] ); + // Is it an additional task? + if ( isset( $tr['resources']['sub_task'] ) ) { - $new_tr = [ - 'id' => $tr['id'], + $task_id = $tr['resources']['sub_task']['id']; + + $new_tr = [ + 'id' => $tr['id'], + 'description' => $tr['description'], + 'dateadded' => $tr['created_at'], + 'fee_percentage' => $tr['fee_percentage'], + 'fee_amount' => $tr['fee_amount'], + 'task_type' => $tr['resources']['sub_task']['kind'], + 'task_id' => $tr['resources']['sub_task']['id'], + 'task_title' => $tr['resources']['sub_task']['title'], + 'parent_task_id' => $tr['resources']['sub_task']['parent_task_id'], + 'preferred' => $tr['resources']['sub_task']['current_user_is_preferred_contractor'], + 'client_id' => $tr['resources']['client']['id'], + 'last_sync' => time(), + ]; + + } else { + + $task_id = $tr['resources']['project']['id']; + + $new_tr = [ + 'id' => $tr['id'], 'description' => $tr['description'], 'dateadded' => $tr['created_at'], - 'fee_percentage' => $tr['fee_percentage'], - 'fee_amount' => $tr['fee_amount'], - 'task_type' => $tr['resources']['project']['kind'], - 'task_id' => $task_id, - 'task_title' => $tr['resources']['project']['title'], - 'parent_task_id' => ( $tr['resources']['project']['parent_task_id'] > 0 ? ['resources']['project']['parent_task_id'] : 0 ), - 'preferred' => $tr['resources']['project']['current_user_is_preferred_contractor'], - 'client_id' => $tr['resources']['client']['id'], - 'last_sync' => time(), - ]; + 'fee_percentage' => $tr['fee_percentage'], + 'fee_amount' => $tr['fee_amount'], + 'task_type' => $tr['resources']['project']['kind'], + 'task_id' => $tr['resources']['project']['id'], + 'task_title' => $tr['resources']['project']['title'], + 'parent_task_id' => $tr['resources']['project']['parent_task_id'], + 'preferred' => $tr['resources']['project']['current_user_is_preferred_contractor'], + 'client_id' => $tr['resources']['client']['id'], + 'last_sync' => time(), + ]; + } // the API is returning some blank rows, ensure we have a valid client_id. if ( $new_tr['id'] && is_int( $new_tr['id'] ) ) { diff --git a/functions/admin-page.php b/functions/admin-page.php index 31a1775..a6a64ac 100644 --- a/functions/admin-page.php +++ b/functions/admin-page.php @@ -547,7 +547,7 @@ class="thickbox"> - + Subtask of ' . $tron['parent_task_id'] : '' ); ?> From 2009d2c02c45cd163772e227d32ba6aec721229e Mon Sep 17 00:00:00 2001 From: Gabriel Reguly Date: Mon, 26 May 2025 22:34:01 -0300 Subject: [PATCH 11/11] Adds ad_hoc_expert_credit as revenue --- classes/clients.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/clients.php b/classes/clients.php index e20c41c..c70895f 100644 --- a/classes/clients.php +++ b/classes/clients.php @@ -59,7 +59,7 @@ public function get_clients( $from_month = '', $from_year = '', $to_month = '', ON ' . $this->tables['transactions'] . '.task_ID = ' . $this->tables['amounts'] . ".task_ID WHERE - `description` = 'task_completion' OR `description` = 'partial_refund' + `description` = 'task_completion' or `description` = 'ad_hoc_expert_credit' OR `description` = 'partial_refund' AND (dateadded BETWEEN '" . $firstdate . "' AND '" . $lastdate . "') ";