@@ -14,91 +14,91 @@ discard block |
||
| 14 | 14 | class GetPaid_Admin { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Local path to this plugins admin directory |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $admin_path; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Web path to this plugins admin directory |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - public $admin_url; |
|
| 17 | + * Local path to this plugins admin directory |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $admin_path; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Web path to this plugins admin directory |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + public $admin_url; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Reports components. |
|
| 32 | - * |
|
| 33 | - * @var GetPaid_Reports |
|
| 34 | - */ |
|
| 30 | + /** |
|
| 31 | + * Reports components. |
|
| 32 | + * |
|
| 33 | + * @var GetPaid_Reports |
|
| 34 | + */ |
|
| 35 | 35 | public $reports; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * Class constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct(){ |
|
| 38 | + * Class constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct(){ |
|
| 41 | 41 | |
| 42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
| 43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | - $this->reports = new GetPaid_Reports(); |
|
| 43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | + $this->reports = new GetPaid_Reports(); |
|
| 45 | 45 | |
| 46 | 46 | if ( is_admin() ) { |
| 47 | - $this->init_admin_hooks(); |
|
| 47 | + $this->init_admin_hooks(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * Init action and filter hooks |
|
| 54 | - * |
|
| 55 | - */ |
|
| 56 | - private function init_admin_hooks() { |
|
| 53 | + * Init action and filter hooks |
|
| 54 | + * |
|
| 55 | + */ |
|
| 56 | + private function init_admin_hooks() { |
|
| 57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
| 58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
| 60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
| 61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
| 62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
| 65 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
| 66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
| 65 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
| 66 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 68 | 68 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
| 69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 71 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 72 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
| 73 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 74 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
| 75 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
| 76 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 77 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 78 | - |
|
| 79 | - // Setup/welcome |
|
| 80 | - if ( ! empty( $_GET['page'] ) ) { |
|
| 81 | - switch ( $_GET['page'] ) { |
|
| 82 | - case 'gp-setup' : |
|
| 83 | - include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
| 84 | - break; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Register admin scripts |
|
| 92 | - * |
|
| 93 | - */ |
|
| 94 | - public function enqeue_scripts() { |
|
| 69 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 71 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 72 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
| 73 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 74 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
| 75 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
| 76 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 77 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 78 | + |
|
| 79 | + // Setup/welcome |
|
| 80 | + if ( ! empty( $_GET['page'] ) ) { |
|
| 81 | + switch ( $_GET['page'] ) { |
|
| 82 | + case 'gp-setup' : |
|
| 83 | + include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
| 84 | + break; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Register admin scripts |
|
| 92 | + * |
|
| 93 | + */ |
|
| 94 | + public function enqeue_scripts() { |
|
| 95 | 95 | global $current_screen, $pagenow; |
| 96 | 96 | |
| 97 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 98 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 97 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 98 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 99 | 99 | |
| 100 | 100 | if ( ! empty( $current_screen->post_type ) ) { |
| 101 | - $page = $current_screen->post_type; |
|
| 101 | + $page = $current_screen->post_type; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // General styles. |
@@ -119,54 +119,54 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Payment form scripts. |
| 122 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 122 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 123 | 123 | $this->load_payment_form_scripts(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 127 | - wp_enqueue_script( 'postbox' ); |
|
| 128 | - } |
|
| 126 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 127 | + wp_enqueue_script( 'postbox' ); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | - * Returns admin js translations. |
|
| 134 | - * |
|
| 135 | - */ |
|
| 136 | - protected function get_admin_i18() { |
|
| 133 | + * Returns admin js translations. |
|
| 134 | + * |
|
| 135 | + */ |
|
| 136 | + protected function get_admin_i18() { |
|
| 137 | 137 | global $post; |
| 138 | 138 | |
| 139 | - $date_range = array( |
|
| 140 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 141 | - ); |
|
| 139 | + $date_range = array( |
|
| 140 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 141 | + ); |
|
| 142 | 142 | |
| 143 | - if ( $date_range['period'] == 'custom' ) { |
|
| 143 | + if ( $date_range['period'] == 'custom' ) { |
|
| 144 | 144 | |
| 145 | - if ( isset( $_GET['from'] ) ) { |
|
| 146 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 147 | - } |
|
| 145 | + if ( isset( $_GET['from'] ) ) { |
|
| 146 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if ( isset( $_GET['to'] ) ) { |
|
| 150 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 151 | - } |
|
| 149 | + if ( isset( $_GET['to'] ) ) { |
|
| 150 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | $i18n = array( |
| 156 | 156 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 157 | 157 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
| 158 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 159 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 160 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 161 | - 'date_range' => $date_range, |
|
| 158 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 159 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 160 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
| 161 | + 'date_range' => $date_range, |
|
| 162 | 162 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
| 163 | 163 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
| 164 | 164 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
| 165 | 165 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
| 166 | 166 | 'tax' => wpinv_tax_amount(), |
| 167 | 167 | 'discount' => 0, |
| 168 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
| 169 | - 'currency' => wpinv_get_currency(), |
|
| 168 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
| 169 | + 'currency' => wpinv_get_currency(), |
|
| 170 | 170 | 'currency_pos' => wpinv_currency_position(), |
| 171 | 171 | 'thousand_sep' => wpinv_thousands_separator(), |
| 172 | 172 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -186,119 +186,119 @@ discard block |
||
| 186 | 186 | 'item_description' => __( 'Item Description', 'invoicing' ), |
| 187 | 187 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
| 188 | 188 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
| 189 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
| 190 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 191 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 192 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
| 193 | - 'graphs' => array_merge( ['refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'], array_keys( wpinv_get_report_graphs() ) ), |
|
| 189 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
| 190 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 191 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 192 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
| 193 | + 'graphs' => array_merge( ['refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'], array_keys( wpinv_get_report_graphs() ) ), |
|
| 194 | 194 | ); |
| 195 | 195 | |
| 196 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 196 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 197 | 197 | |
| 198 | - $invoice = new WPInv_Invoice( $post ); |
|
| 199 | - $i18n['save_invoice'] = sprintf( |
|
| 200 | - __( 'Save %s', 'invoicing' ), |
|
| 201 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 202 | - ); |
|
| 198 | + $invoice = new WPInv_Invoice( $post ); |
|
| 199 | + $i18n['save_invoice'] = sprintf( |
|
| 200 | + __( 'Save %s', 'invoicing' ), |
|
| 201 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 202 | + ); |
|
| 203 | 203 | |
| 204 | - $i18n['invoice_description'] = sprintf( |
|
| 205 | - __( '%s Description', 'invoicing' ), |
|
| 206 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 207 | - ); |
|
| 204 | + $i18n['invoice_description'] = sprintf( |
|
| 205 | + __( '%s Description', 'invoicing' ), |
|
| 206 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 207 | + ); |
|
| 208 | 208 | |
| 209 | - } |
|
| 210 | - return $i18n; |
|
| 211 | - } |
|
| 209 | + } |
|
| 210 | + return $i18n; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Change the admin footer text on GetPaid admin pages. |
|
| 215 | - * |
|
| 216 | - * @since 2.0.0 |
|
| 217 | - * @param string $footer_text |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public function admin_footer_text( $footer_text ) { |
|
| 221 | - global $current_screen; |
|
| 213 | + /** |
|
| 214 | + * Change the admin footer text on GetPaid admin pages. |
|
| 215 | + * |
|
| 216 | + * @since 2.0.0 |
|
| 217 | + * @param string $footer_text |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public function admin_footer_text( $footer_text ) { |
|
| 221 | + global $current_screen; |
|
| 222 | 222 | |
| 223 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 223 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 224 | 224 | |
| 225 | 225 | if ( ! empty( $current_screen->post_type ) ) { |
| 226 | - $page = $current_screen->post_type; |
|
| 226 | + $page = $current_screen->post_type; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // General styles. |
| 230 | 230 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
| 231 | 231 | |
| 232 | - // Change the footer text |
|
| 233 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 234 | - |
|
| 235 | - $rating_url = esc_url( |
|
| 236 | - wp_nonce_url( |
|
| 237 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 238 | - 'getpaid-nonce', |
|
| 239 | - 'getpaid-nonce' |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - |
|
| 243 | - $footer_text = sprintf( |
|
| 244 | - /* translators: %s: five stars */ |
|
| 245 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 246 | - "<a href='$rating_url'>★★★★★</a>" |
|
| 247 | - ); |
|
| 248 | - |
|
| 249 | - } else { |
|
| 250 | - |
|
| 251 | - $footer_text = sprintf( |
|
| 252 | - /* translators: %s: GetPaid */ |
|
| 253 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 254 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 255 | - ); |
|
| 256 | - |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - return $footer_text; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Redirects to wp.org to rate the plugin. |
|
| 266 | - * |
|
| 267 | - * @since 2.0.0 |
|
| 268 | - */ |
|
| 269 | - public function redirect_to_wordpress_rating_page() { |
|
| 270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 272 | - exit; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Loads payment form js. |
|
| 277 | - * |
|
| 278 | - */ |
|
| 279 | - protected function load_payment_form_scripts() { |
|
| 232 | + // Change the footer text |
|
| 233 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 234 | + |
|
| 235 | + $rating_url = esc_url( |
|
| 236 | + wp_nonce_url( |
|
| 237 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 238 | + 'getpaid-nonce', |
|
| 239 | + 'getpaid-nonce' |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + |
|
| 243 | + $footer_text = sprintf( |
|
| 244 | + /* translators: %s: five stars */ |
|
| 245 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 246 | + "<a href='$rating_url'>★★★★★</a>" |
|
| 247 | + ); |
|
| 248 | + |
|
| 249 | + } else { |
|
| 250 | + |
|
| 251 | + $footer_text = sprintf( |
|
| 252 | + /* translators: %s: GetPaid */ |
|
| 253 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
| 254 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 255 | + ); |
|
| 256 | + |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + return $footer_text; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Redirects to wp.org to rate the plugin. |
|
| 266 | + * |
|
| 267 | + * @since 2.0.0 |
|
| 268 | + */ |
|
| 269 | + public function redirect_to_wordpress_rating_page() { |
|
| 270 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 271 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 272 | + exit; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Loads payment form js. |
|
| 277 | + * |
|
| 278 | + */ |
|
| 279 | + protected function load_payment_form_scripts() { |
|
| 280 | 280 | global $post; |
| 281 | 281 | |
| 282 | 282 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
| 283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 283 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 284 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 285 | 285 | |
| 286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
| 286 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
| 288 | 288 | |
| 289 | - wp_localize_script( |
|
| 289 | + wp_localize_script( |
|
| 290 | 290 | 'wpinv-admin-payment-form-script', |
| 291 | 291 | 'wpinvPaymentFormAdmin', |
| 292 | 292 | array( |
| 293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 295 | - 'currency' => wpinv_currency_symbol(), |
|
| 296 | - 'position' => wpinv_currency_position(), |
|
| 297 | - 'decimals' => (int) wpinv_decimals(), |
|
| 298 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 299 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 301 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 293 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 294 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 295 | + 'currency' => wpinv_currency_symbol(), |
|
| 296 | + 'position' => wpinv_currency_position(), |
|
| 297 | + 'decimals' => (int) wpinv_decimals(), |
|
| 298 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 299 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 300 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 301 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 302 | 302 | ) |
| 303 | 303 | ); |
| 304 | 304 | |
@@ -307,20 +307,20 @@ discard block |
||
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
| 310 | - * Add our classes to admin pages. |
|
| 310 | + * Add our classes to admin pages. |
|
| 311 | 311 | * |
| 312 | 312 | * @param string $classes |
| 313 | 313 | * @return string |
| 314 | - * |
|
| 315 | - */ |
|
| 314 | + * |
|
| 315 | + */ |
|
| 316 | 316 | public function admin_body_class( $classes ) { |
| 317 | - global $pagenow, $post, $current_screen; |
|
| 317 | + global $pagenow, $post, $current_screen; |
|
| 318 | 318 | |
| 319 | 319 | |
| 320 | 320 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
| 321 | 321 | |
| 322 | 322 | if ( ! empty( $current_screen->post_type ) ) { |
| 323 | - $page = $current_screen->post_type; |
|
| 323 | + $page = $current_screen->post_type; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -329,68 +329,68 @@ discard block |
||
| 329 | 329 | |
| 330 | 330 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
| 331 | 331 | $classes .= ' wpinv-cpt wpinv'; |
| 332 | - } |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 334 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 335 | 335 | $classes .= ' getpaid-is-invoice-cpt'; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - return $classes; |
|
| 338 | + return $classes; |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
| 342 | - * Maybe show the AyeCode Connect Notice. |
|
| 343 | - */ |
|
| 344 | - public function init_ayecode_connect_helper(){ |
|
| 342 | + * Maybe show the AyeCode Connect Notice. |
|
| 343 | + */ |
|
| 344 | + public function init_ayecode_connect_helper(){ |
|
| 345 | 345 | |
| 346 | - // Register with the deactivation survey class. |
|
| 347 | - AyeCode_Deactivation_Survey::instance(array( |
|
| 348 | - 'slug' => 'invoicing', |
|
| 349 | - 'version' => WPINV_VERSION, |
|
| 350 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
| 351 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
| 352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
| 353 | - )); |
|
| 346 | + // Register with the deactivation survey class. |
|
| 347 | + AyeCode_Deactivation_Survey::instance(array( |
|
| 348 | + 'slug' => 'invoicing', |
|
| 349 | + 'version' => WPINV_VERSION, |
|
| 350 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
| 351 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
| 352 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
| 353 | + )); |
|
| 354 | 354 | |
| 355 | 355 | new AyeCode_Connect_Helper( |
| 356 | 356 | array( |
| 357 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 358 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 359 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 360 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 361 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 362 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 363 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 357 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 358 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 359 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 360 | + 'connect_button' => __("Connect Site","invoicing"), |
|
| 361 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
| 362 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 363 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 364 | 364 | ), |
| 365 | 365 | array( 'wpi-addons' ) |
| 366 | 366 | ); |
| 367 | 367 | |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - /** |
|
| 371 | - * Redirect users to settings on activation. |
|
| 372 | - * |
|
| 373 | - * @return void |
|
| 374 | - */ |
|
| 375 | - public function activation_redirect() { |
|
| 370 | + /** |
|
| 371 | + * Redirect users to settings on activation. |
|
| 372 | + * |
|
| 373 | + * @return void |
|
| 374 | + */ |
|
| 375 | + public function activation_redirect() { |
|
| 376 | 376 | |
| 377 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 377 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 378 | 378 | |
| 379 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 380 | - return; |
|
| 381 | - } |
|
| 379 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 380 | + return; |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - // Bail if activating from network, or bulk |
|
| 384 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 385 | - return; |
|
| 386 | - } |
|
| 383 | + // Bail if activating from network, or bulk |
|
| 384 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 385 | + return; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 388 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 389 | 389 | |
| 390 | 390 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
| 391 | 391 | exit; |
| 392 | 392 | |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | 395 | /** |
| 396 | 396 | * Fires an admin action after verifying that a user can fire them. |
@@ -404,532 +404,532 @@ discard block |
||
| 404 | 404 | |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - /** |
|
| 407 | + /** |
|
| 408 | 408 | * Duplicate invoice. |
| 409 | - * |
|
| 410 | - * @param array $args |
|
| 409 | + * |
|
| 410 | + * @param array $args |
|
| 411 | 411 | */ |
| 412 | 412 | public function duplicate_invoice( $args ) { |
| 413 | 413 | |
| 414 | - if ( empty( $args['invoice_id'] ) ) { |
|
| 415 | - return; |
|
| 416 | - } |
|
| 414 | + if ( empty( $args['invoice_id'] ) ) { |
|
| 415 | + return; |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
| 418 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
| 419 | 419 | |
| 420 | - if ( ! $invoice->exists() ) { |
|
| 421 | - return; |
|
| 422 | - } |
|
| 420 | + if ( ! $invoice->exists() ) { |
|
| 421 | + return; |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
| 425 | - $new_invoice->save(); |
|
| 424 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
| 425 | + $new_invoice->save(); |
|
| 426 | 426 | |
| 427 | - if ( $new_invoice->exists() ) { |
|
| 427 | + if ( $new_invoice->exists() ) { |
|
| 428 | 428 | |
| 429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
| 429 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
| 430 | 430 | |
| 431 | - wp_safe_redirect( |
|
| 432 | - add_query_arg( |
|
| 433 | - array( |
|
| 434 | - 'action' => 'edit', |
|
| 435 | - 'post' => $new_invoice->get_id(), |
|
| 436 | - ), |
|
| 437 | - admin_url( 'post.php' ) |
|
| 438 | - ) |
|
| 439 | - ); |
|
| 440 | - exit; |
|
| 431 | + wp_safe_redirect( |
|
| 432 | + add_query_arg( |
|
| 433 | + array( |
|
| 434 | + 'action' => 'edit', |
|
| 435 | + 'post' => $new_invoice->get_id(), |
|
| 436 | + ), |
|
| 437 | + admin_url( 'post.php' ) |
|
| 438 | + ) |
|
| 439 | + ); |
|
| 440 | + exit; |
|
| 441 | 441 | |
| 442 | - } |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
| 444 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
| 445 | 445 | |
| 446 | - } |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - /** |
|
| 448 | + /** |
|
| 449 | 449 | * Sends a payment reminder to a customer. |
| 450 | - * |
|
| 451 | - * @param array $args |
|
| 450 | + * |
|
| 451 | + * @param array $args |
|
| 452 | 452 | */ |
| 453 | 453 | public function duplicate_payment_form( $args ) { |
| 454 | 454 | |
| 455 | - if ( empty( $args['form_id'] ) ) { |
|
| 456 | - return; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 455 | + if ( empty( $args['form_id'] ) ) { |
|
| 456 | + return; |
|
| 457 | + } |
|
| 460 | 458 | |
| 461 | - if ( ! $form->exists() ) { |
|
| 462 | - return; |
|
| 463 | - } |
|
| 459 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 464 | 460 | |
| 465 | - $new_form = new GetPaid_Payment_Form(); |
|
| 466 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
| 467 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
| 468 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
| 469 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
| 470 | - $new_form->save(); |
|
| 461 | + if ( ! $form->exists() ) { |
|
| 462 | + return; |
|
| 463 | + } |
|
| 471 | 464 | |
| 472 | - if ( $new_form->exists() ) { |
|
| 473 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
| 474 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
| 475 | - } else { |
|
| 476 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
| 477 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
| 478 | - } |
|
| 465 | + $new_form = new GetPaid_Payment_Form(); |
|
| 466 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
| 467 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
| 468 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
| 469 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
| 470 | + $new_form->save(); |
|
| 471 | + |
|
| 472 | + if ( $new_form->exists() ) { |
|
| 473 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
| 474 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
| 475 | + } else { |
|
| 476 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
| 477 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - wp_redirect( $url ); |
|
| 481 | - exit; |
|
| 482 | - } |
|
| 480 | + wp_redirect( $url ); |
|
| 481 | + exit; |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - /** |
|
| 484 | + /** |
|
| 485 | 485 | * Sends a payment reminder to a customer. |
| 486 | - * |
|
| 487 | - * @param array $args |
|
| 486 | + * |
|
| 487 | + * @param array $args |
|
| 488 | 488 | */ |
| 489 | 489 | public function send_customer_invoice( $args ) { |
| 490 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
| 491 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 492 | - exit; |
|
| 493 | - } |
|
| 490 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
| 491 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 492 | + exit; |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - /** |
|
| 495 | + /** |
|
| 496 | 496 | * Sends a payment reminder to a customer. |
| 497 | - * |
|
| 498 | - * @param array $args |
|
| 497 | + * |
|
| 498 | + * @param array $args |
|
| 499 | 499 | */ |
| 500 | 500 | public function send_customer_payment_reminder( $args ) { |
| 501 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 501 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 502 | 502 | |
| 503 | - if ( $sent ) { |
|
| 504 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 505 | - } else { |
|
| 506 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 507 | - } |
|
| 503 | + if ( $sent ) { |
|
| 504 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 505 | + } else { |
|
| 506 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 507 | + } |
|
| 508 | 508 | |
| 509 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 510 | - exit; |
|
| 511 | - } |
|
| 509 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 510 | + exit; |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - /** |
|
| 513 | + /** |
|
| 514 | 514 | * Resets tax rates. |
| 515 | - * |
|
| 515 | + * |
|
| 516 | 516 | */ |
| 517 | 517 | public function admin_reset_tax_rates() { |
| 518 | 518 | |
| 519 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 520 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 521 | - exit; |
|
| 519 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 520 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 521 | + exit; |
|
| 522 | 522 | |
| 523 | - } |
|
| 523 | + } |
|
| 524 | 524 | |
| 525 | - /** |
|
| 525 | + /** |
|
| 526 | 526 | * Resets admin pages. |
| 527 | - * |
|
| 527 | + * |
|
| 528 | 528 | */ |
| 529 | 529 | public function admin_create_missing_pages() { |
| 530 | - $installer = new GetPaid_Installer(); |
|
| 531 | - $installer->create_pages(); |
|
| 532 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 533 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 534 | - exit; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - /** |
|
| 530 | + $installer = new GetPaid_Installer(); |
|
| 531 | + $installer->create_pages(); |
|
| 532 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 533 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 534 | + exit; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | 538 | * Creates an missing admin tables. |
| 539 | - * |
|
| 539 | + * |
|
| 540 | 540 | */ |
| 541 | 541 | public function admin_create_missing_tables() { |
| 542 | - global $wpdb; |
|
| 543 | - $installer = new GetPaid_Installer(); |
|
| 542 | + global $wpdb; |
|
| 543 | + $installer = new GetPaid_Installer(); |
|
| 544 | 544 | |
| 545 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 546 | - $installer->create_subscriptions_table(); |
|
| 545 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 546 | + $installer->create_subscriptions_table(); |
|
| 547 | 547 | |
| 548 | - if ( $wpdb->last_error !== '' ) { |
|
| 549 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 550 | - } |
|
| 551 | - } |
|
| 548 | + if ( $wpdb->last_error !== '' ) { |
|
| 549 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | 552 | |
| 553 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 554 | - $installer->create_invoices_table(); |
|
| 553 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 554 | + $installer->create_invoices_table(); |
|
| 555 | 555 | |
| 556 | - if ( $wpdb->last_error !== '' ) { |
|
| 557 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 558 | - } |
|
| 559 | - } |
|
| 556 | + if ( $wpdb->last_error !== '' ) { |
|
| 557 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 562 | - $installer->create_invoice_items_table(); |
|
| 561 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 562 | + $installer->create_invoice_items_table(); |
|
| 563 | 563 | |
| 564 | - if ( $wpdb->last_error !== '' ) { |
|
| 565 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 566 | - } |
|
| 567 | - } |
|
| 564 | + if ( $wpdb->last_error !== '' ) { |
|
| 565 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | - if ( ! $this->has_notices() ) { |
|
| 570 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 571 | - } |
|
| 569 | + if ( ! $this->has_notices() ) { |
|
| 570 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 571 | + } |
|
| 572 | 572 | |
| 573 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 574 | - exit; |
|
| 575 | - } |
|
| 573 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 574 | + exit; |
|
| 575 | + } |
|
| 576 | 576 | |
| 577 | - /** |
|
| 577 | + /** |
|
| 578 | 578 | * Migrates old invoices to the new database tables. |
| 579 | - * |
|
| 579 | + * |
|
| 580 | 580 | */ |
| 581 | 581 | public function admin_migrate_old_invoices() { |
| 582 | 582 | |
| 583 | - // Migrate the invoices. |
|
| 584 | - $installer = new GetPaid_Installer(); |
|
| 585 | - $installer->migrate_old_invoices(); |
|
| 583 | + // Migrate the invoices. |
|
| 584 | + $installer = new GetPaid_Installer(); |
|
| 585 | + $installer->migrate_old_invoices(); |
|
| 586 | 586 | |
| 587 | - // Show an admin message. |
|
| 588 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 587 | + // Show an admin message. |
|
| 588 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 589 | 589 | |
| 590 | - // Redirect the admin. |
|
| 591 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 592 | - exit; |
|
| 590 | + // Redirect the admin. |
|
| 591 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 592 | + exit; |
|
| 593 | 593 | |
| 594 | - } |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - /** |
|
| 596 | + /** |
|
| 597 | 597 | * Download customers. |
| 598 | - * |
|
| 598 | + * |
|
| 599 | 599 | */ |
| 600 | 600 | public function admin_download_customers() { |
| 601 | - global $wpdb; |
|
| 601 | + global $wpdb; |
|
| 602 | 602 | |
| 603 | - $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
| 603 | + $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
| 604 | 604 | |
| 605 | - header( "Content-Type:text/csv" ); |
|
| 606 | - header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
| 605 | + header( "Content-Type:text/csv" ); |
|
| 606 | + header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
| 607 | 607 | |
| 608 | - $post_types = ''; |
|
| 608 | + $post_types = ''; |
|
| 609 | 609 | |
| 610 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 611 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 612 | - } |
|
| 610 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 611 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 612 | + } |
|
| 613 | 613 | |
| 614 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 614 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 615 | 615 | |
| 616 | - $customers = $wpdb->get_col( |
|
| 617 | - $wpdb->prepare( |
|
| 618 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
| 619 | - ) |
|
| 620 | - ); |
|
| 616 | + $customers = $wpdb->get_col( |
|
| 617 | + $wpdb->prepare( |
|
| 618 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
| 619 | + ) |
|
| 620 | + ); |
|
| 621 | 621 | |
| 622 | - $columns = array( |
|
| 623 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 624 | - 'email' => __( 'Email', 'invoicing' ), |
|
| 625 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 626 | - 'state' => __( 'State', 'invoicing' ), |
|
| 627 | - 'city' => __( 'City', 'invoicing' ), |
|
| 628 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 629 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 630 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 631 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 632 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
| 633 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 634 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
| 635 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 636 | - ); |
|
| 622 | + $columns = array( |
|
| 623 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 624 | + 'email' => __( 'Email', 'invoicing' ), |
|
| 625 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 626 | + 'state' => __( 'State', 'invoicing' ), |
|
| 627 | + 'city' => __( 'City', 'invoicing' ), |
|
| 628 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 629 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 630 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 631 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 632 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
| 633 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 634 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
| 635 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
| 636 | + ); |
|
| 637 | 637 | |
| 638 | - // Output the csv column headers. |
|
| 639 | - fputcsv( $output, array_values( $columns ) ); |
|
| 638 | + // Output the csv column headers. |
|
| 639 | + fputcsv( $output, array_values( $columns ) ); |
|
| 640 | 640 | |
| 641 | - // Loop through |
|
| 642 | - $table = new WPInv_Customers_Table(); |
|
| 643 | - foreach ( $customers as $customer_id ) { |
|
| 641 | + // Loop through |
|
| 642 | + $table = new WPInv_Customers_Table(); |
|
| 643 | + foreach ( $customers as $customer_id ) { |
|
| 644 | 644 | |
| 645 | - $user = get_user_by( 'id', $customer_id ); |
|
| 646 | - $row = array(); |
|
| 647 | - if ( empty( $user ) ) { |
|
| 648 | - continue; |
|
| 649 | - } |
|
| 645 | + $user = get_user_by( 'id', $customer_id ); |
|
| 646 | + $row = array(); |
|
| 647 | + if ( empty( $user ) ) { |
|
| 648 | + continue; |
|
| 649 | + } |
|
| 650 | 650 | |
| 651 | - foreach ( array_keys( $columns ) as $column ) { |
|
| 651 | + foreach ( array_keys( $columns ) as $column ) { |
|
| 652 | 652 | |
| 653 | - $method = 'column_' . $column; |
|
| 653 | + $method = 'column_' . $column; |
|
| 654 | 654 | |
| 655 | - if ( 'name' == $column ) { |
|
| 656 | - $value = esc_html( $user->display_name ); |
|
| 657 | - } else if( 'email' == $column ) { |
|
| 658 | - $value = sanitize_email( $user->user_email ); |
|
| 659 | - } else if ( is_callable( array( $table, $method ) ) ) { |
|
| 660 | - $value = strip_tags( $table->$method( $user ) ); |
|
| 661 | - } |
|
| 655 | + if ( 'name' == $column ) { |
|
| 656 | + $value = esc_html( $user->display_name ); |
|
| 657 | + } else if( 'email' == $column ) { |
|
| 658 | + $value = sanitize_email( $user->user_email ); |
|
| 659 | + } else if ( is_callable( array( $table, $method ) ) ) { |
|
| 660 | + $value = strip_tags( $table->$method( $user ) ); |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | - if ( empty( $value ) ) { |
|
| 664 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
| 665 | - } |
|
| 663 | + if ( empty( $value ) ) { |
|
| 664 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | - $row[] = $value; |
|
| 667 | + $row[] = $value; |
|
| 668 | 668 | |
| 669 | - } |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | - fputcsv( $output, $row ); |
|
| 672 | - } |
|
| 671 | + fputcsv( $output, $row ); |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | - fclose( $output ); |
|
| 675 | - exit; |
|
| 674 | + fclose( $output ); |
|
| 675 | + exit; |
|
| 676 | 676 | |
| 677 | - } |
|
| 677 | + } |
|
| 678 | 678 | |
| 679 | - /** |
|
| 679 | + /** |
|
| 680 | 680 | * Installs a plugin. |
| 681 | - * |
|
| 682 | - * @param array $data |
|
| 681 | + * |
|
| 682 | + * @param array $data |
|
| 683 | 683 | */ |
| 684 | 684 | public function admin_install_plugin( $data ) { |
| 685 | 685 | |
| 686 | - if ( ! empty( $data['plugins'] ) ) { |
|
| 687 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 688 | - wp_cache_flush(); |
|
| 686 | + if ( ! empty( $data['plugins'] ) ) { |
|
| 687 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 688 | + wp_cache_flush(); |
|
| 689 | 689 | |
| 690 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
| 691 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
| 692 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 693 | - $installed = $upgrader->install( $plugin_zip ); |
|
| 690 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
| 691 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
| 692 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 693 | + $installed = $upgrader->install( $plugin_zip ); |
|
| 694 | 694 | |
| 695 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
| 696 | - activate_plugin( $file, '', false, true ); |
|
| 697 | - } else { |
|
| 698 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
| 699 | - } |
|
| 695 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
| 696 | + activate_plugin( $file, '', false, true ); |
|
| 697 | + } else { |
|
| 698 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
| 699 | + } |
|
| 700 | 700 | |
| 701 | - } |
|
| 701 | + } |
|
| 702 | 702 | |
| 703 | - } |
|
| 703 | + } |
|
| 704 | 704 | |
| 705 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
| 706 | - wp_safe_redirect( $redirect ); |
|
| 707 | - exit; |
|
| 705 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
| 706 | + wp_safe_redirect( $redirect ); |
|
| 707 | + exit; |
|
| 708 | 708 | |
| 709 | - } |
|
| 709 | + } |
|
| 710 | 710 | |
| 711 | - /** |
|
| 711 | + /** |
|
| 712 | 712 | * Connects a gateway. |
| 713 | - * |
|
| 714 | - * @param array $data |
|
| 713 | + * |
|
| 714 | + * @param array $data |
|
| 715 | 715 | */ |
| 716 | 716 | public function admin_connect_gateway( $data ) { |
| 717 | 717 | |
| 718 | - if ( ! empty( $data['plugin'] ) ) { |
|
| 718 | + if ( ! empty( $data['plugin'] ) ) { |
|
| 719 | 719 | |
| 720 | - $gateway = sanitize_key( $data['plugin'] ); |
|
| 721 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 720 | + $gateway = sanitize_key( $data['plugin'] ); |
|
| 721 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 722 | 722 | |
| 723 | - if ( ! empty( $connect_url ) ) { |
|
| 724 | - wp_redirect( $connect_url ); |
|
| 725 | - exit; |
|
| 726 | - } |
|
| 723 | + if ( ! empty( $connect_url ) ) { |
|
| 724 | + wp_redirect( $connect_url ); |
|
| 725 | + exit; |
|
| 726 | + } |
|
| 727 | 727 | |
| 728 | - if ( 'stripe' == $data['plugin'] ) { |
|
| 729 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 730 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 731 | - wp_cache_flush(); |
|
| 728 | + if ( 'stripe' == $data['plugin'] ) { |
|
| 729 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 730 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 731 | + wp_cache_flush(); |
|
| 732 | 732 | |
| 733 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
| 734 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
| 735 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 736 | - $upgrader->install( $plugin_zip ); |
|
| 737 | - } |
|
| 733 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
| 734 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
| 735 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 736 | + $upgrader->install( $plugin_zip ); |
|
| 737 | + } |
|
| 738 | 738 | |
| 739 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
| 740 | - } |
|
| 739 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
| 740 | + } |
|
| 741 | 741 | |
| 742 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 743 | - if ( ! empty( $connect_url ) ) { |
|
| 744 | - wp_redirect( $connect_url ); |
|
| 745 | - exit; |
|
| 746 | - } |
|
| 742 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 743 | + if ( ! empty( $connect_url ) ) { |
|
| 744 | + wp_redirect( $connect_url ); |
|
| 745 | + exit; |
|
| 746 | + } |
|
| 747 | 747 | |
| 748 | - } |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
| 751 | - wp_safe_redirect( $redirect ); |
|
| 752 | - exit; |
|
| 750 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
| 751 | + wp_safe_redirect( $redirect ); |
|
| 752 | + exit; |
|
| 753 | 753 | |
| 754 | - } |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | - /** |
|
| 756 | + /** |
|
| 757 | 757 | * Recalculates discounts. |
| 758 | - * |
|
| 758 | + * |
|
| 759 | 759 | */ |
| 760 | 760 | public function admin_recalculate_discounts() { |
| 761 | - global $wpdb; |
|
| 761 | + global $wpdb; |
|
| 762 | 762 | |
| 763 | - // Fetch all invoices that have discount codes. |
|
| 764 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 765 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 763 | + // Fetch all invoices that have discount codes. |
|
| 764 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 765 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 766 | 766 | |
| 767 | - foreach ( $invoices as $invoice ) { |
|
| 767 | + foreach ( $invoices as $invoice ) { |
|
| 768 | 768 | |
| 769 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 769 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 770 | 770 | |
| 771 | - if ( ! $invoice->exists() ) { |
|
| 772 | - continue; |
|
| 773 | - } |
|
| 771 | + if ( ! $invoice->exists() ) { |
|
| 772 | + continue; |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | - // Abort if the discount does not exist or does not apply here. |
|
| 776 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 777 | - if ( ! $discount->exists() ) { |
|
| 778 | - continue; |
|
| 779 | - } |
|
| 775 | + // Abort if the discount does not exist or does not apply here. |
|
| 776 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 777 | + if ( ! $discount->exists() ) { |
|
| 778 | + continue; |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 782 | - $invoice->recalculate_total(); |
|
| 781 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 782 | + $invoice->recalculate_total(); |
|
| 783 | 783 | |
| 784 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 785 | - $invoice->save(); |
|
| 786 | - } |
|
| 784 | + if ( $invoice->get_total_discount() > 0 ) { |
|
| 785 | + $invoice->save(); |
|
| 786 | + } |
|
| 787 | 787 | |
| 788 | - } |
|
| 788 | + } |
|
| 789 | 789 | |
| 790 | - // Show an admin message. |
|
| 791 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 790 | + // Show an admin message. |
|
| 791 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 792 | 792 | |
| 793 | - // Redirect the admin. |
|
| 794 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 795 | - exit; |
|
| 793 | + // Redirect the admin. |
|
| 794 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 795 | + exit; |
|
| 796 | 796 | |
| 797 | - } |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | 799 | /** |
| 800 | - * Returns an array of admin notices. |
|
| 801 | - * |
|
| 802 | - * @since 1.0.19 |
|
| 800 | + * Returns an array of admin notices. |
|
| 801 | + * |
|
| 802 | + * @since 1.0.19 |
|
| 803 | 803 | * @return array |
| 804 | - */ |
|
| 805 | - public function get_notices() { |
|
| 806 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 804 | + */ |
|
| 805 | + public function get_notices() { |
|
| 806 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
| 807 | 807 | return is_array( $notices ) ? $notices : array(); |
| 808 | - } |
|
| 808 | + } |
|
| 809 | 809 | |
| 810 | - /** |
|
| 811 | - * Checks if we have any admin notices. |
|
| 812 | - * |
|
| 813 | - * @since 2.0.4 |
|
| 810 | + /** |
|
| 811 | + * Checks if we have any admin notices. |
|
| 812 | + * |
|
| 813 | + * @since 2.0.4 |
|
| 814 | 814 | * @return array |
| 815 | - */ |
|
| 816 | - public function has_notices() { |
|
| 817 | - return count( $this->get_notices() ) > 0; |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Clears all admin notices |
|
| 822 | - * |
|
| 823 | - * @access public |
|
| 824 | - * @since 1.0.19 |
|
| 825 | - */ |
|
| 826 | - public function clear_notices() { |
|
| 827 | - delete_option( 'wpinv_admin_notices' ); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * Saves a new admin notice |
|
| 832 | - * |
|
| 833 | - * @access public |
|
| 834 | - * @since 1.0.19 |
|
| 835 | - */ |
|
| 836 | - public function save_notice( $type, $message ) { |
|
| 837 | - $notices = $this->get_notices(); |
|
| 838 | - |
|
| 839 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 840 | - $notices[ $type ] = array(); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - $notices[ $type ][] = $message; |
|
| 844 | - |
|
| 845 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Displays a success notice |
|
| 850 | - * |
|
| 851 | - * @param string $msg The message to qeue. |
|
| 852 | - * @access public |
|
| 853 | - * @since 1.0.19 |
|
| 854 | - */ |
|
| 855 | - public function show_success( $msg ) { |
|
| 856 | - $this->save_notice( 'success', $msg ); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * Displays a error notice |
|
| 861 | - * |
|
| 862 | - * @access public |
|
| 863 | - * @param string $msg The message to qeue. |
|
| 864 | - * @since 1.0.19 |
|
| 865 | - */ |
|
| 866 | - public function show_error( $msg ) { |
|
| 867 | - $this->save_notice( 'error', $msg ); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Displays a warning notice |
|
| 872 | - * |
|
| 873 | - * @access public |
|
| 874 | - * @param string $msg The message to qeue. |
|
| 875 | - * @since 1.0.19 |
|
| 876 | - */ |
|
| 877 | - public function show_warning( $msg ) { |
|
| 878 | - $this->save_notice( 'warning', $msg ); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - /** |
|
| 882 | - * Displays a info notice |
|
| 883 | - * |
|
| 884 | - * @access public |
|
| 885 | - * @param string $msg The message to qeue. |
|
| 886 | - * @since 1.0.19 |
|
| 887 | - */ |
|
| 888 | - public function show_info( $msg ) { |
|
| 889 | - $this->save_notice( 'info', $msg ); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Show notices |
|
| 894 | - * |
|
| 895 | - * @access public |
|
| 896 | - * @since 1.0.19 |
|
| 897 | - */ |
|
| 898 | - public function show_notices() { |
|
| 815 | + */ |
|
| 816 | + public function has_notices() { |
|
| 817 | + return count( $this->get_notices() ) > 0; |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Clears all admin notices |
|
| 822 | + * |
|
| 823 | + * @access public |
|
| 824 | + * @since 1.0.19 |
|
| 825 | + */ |
|
| 826 | + public function clear_notices() { |
|
| 827 | + delete_option( 'wpinv_admin_notices' ); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * Saves a new admin notice |
|
| 832 | + * |
|
| 833 | + * @access public |
|
| 834 | + * @since 1.0.19 |
|
| 835 | + */ |
|
| 836 | + public function save_notice( $type, $message ) { |
|
| 837 | + $notices = $this->get_notices(); |
|
| 838 | + |
|
| 839 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 840 | + $notices[ $type ] = array(); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + $notices[ $type ][] = $message; |
|
| 844 | + |
|
| 845 | + update_option( 'wpinv_admin_notices', $notices ); |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Displays a success notice |
|
| 850 | + * |
|
| 851 | + * @param string $msg The message to qeue. |
|
| 852 | + * @access public |
|
| 853 | + * @since 1.0.19 |
|
| 854 | + */ |
|
| 855 | + public function show_success( $msg ) { |
|
| 856 | + $this->save_notice( 'success', $msg ); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * Displays a error notice |
|
| 861 | + * |
|
| 862 | + * @access public |
|
| 863 | + * @param string $msg The message to qeue. |
|
| 864 | + * @since 1.0.19 |
|
| 865 | + */ |
|
| 866 | + public function show_error( $msg ) { |
|
| 867 | + $this->save_notice( 'error', $msg ); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Displays a warning notice |
|
| 872 | + * |
|
| 873 | + * @access public |
|
| 874 | + * @param string $msg The message to qeue. |
|
| 875 | + * @since 1.0.19 |
|
| 876 | + */ |
|
| 877 | + public function show_warning( $msg ) { |
|
| 878 | + $this->save_notice( 'warning', $msg ); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + /** |
|
| 882 | + * Displays a info notice |
|
| 883 | + * |
|
| 884 | + * @access public |
|
| 885 | + * @param string $msg The message to qeue. |
|
| 886 | + * @since 1.0.19 |
|
| 887 | + */ |
|
| 888 | + public function show_info( $msg ) { |
|
| 889 | + $this->save_notice( 'info', $msg ); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Show notices |
|
| 894 | + * |
|
| 895 | + * @access public |
|
| 896 | + * @since 1.0.19 |
|
| 897 | + */ |
|
| 898 | + public function show_notices() { |
|
| 899 | 899 | |
| 900 | 900 | $notices = $this->get_notices(); |
| 901 | 901 | $this->clear_notices(); |
| 902 | 902 | |
| 903 | - foreach ( $notices as $type => $messages ) { |
|
| 903 | + foreach ( $notices as $type => $messages ) { |
|
| 904 | 904 | |
| 905 | - if ( ! is_array( $messages ) ) { |
|
| 906 | - continue; |
|
| 907 | - } |
|
| 905 | + if ( ! is_array( $messages ) ) { |
|
| 906 | + continue; |
|
| 907 | + } |
|
| 908 | 908 | |
| 909 | 909 | $type = sanitize_key( $type ); |
| 910 | - foreach ( $messages as $message ) { |
|
| 910 | + foreach ( $messages as $message ) { |
|
| 911 | 911 | $message = wp_kses_post( $message ); |
| 912 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 912 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 918 | - |
|
| 919 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 920 | - $url = wp_nonce_url( |
|
| 921 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 922 | - 'getpaid-nonce', |
|
| 923 | - 'getpaid-nonce' |
|
| 924 | - ); |
|
| 925 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 926 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 927 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 928 | - break; |
|
| 929 | - } |
|
| 917 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 918 | + |
|
| 919 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 920 | + $url = wp_nonce_url( |
|
| 921 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 922 | + 'getpaid-nonce', |
|
| 923 | + 'getpaid-nonce' |
|
| 924 | + ); |
|
| 925 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 926 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 927 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 928 | + break; |
|
| 929 | + } |
|
| 930 | 930 | |
| 931 | - } |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - } |
|
| 933 | + } |
|
| 934 | 934 | |
| 935 | 935 | } |
@@ -18,691 +18,691 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GetPaid_REST_Report_Sales_Controller extends GetPaid_REST_Date_Based_Controller { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Route base. |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $rest_base = 'reports/sales'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The report data. |
|
| 30 | - * |
|
| 31 | - * @var stdClass |
|
| 32 | - */ |
|
| 33 | - public $report_data; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The report range. |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - public $report_range; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Registers the routes for the objects of the controller. |
|
| 44 | - * |
|
| 45 | - * @since 2.0.0 |
|
| 46 | - * |
|
| 47 | - * @see register_rest_route() |
|
| 48 | - */ |
|
| 49 | - public function register_namespace_routes( $namespace ) { |
|
| 50 | - |
|
| 51 | - // Get sales report. |
|
| 52 | - register_rest_route( |
|
| 53 | - $namespace, |
|
| 54 | - $this->rest_base, |
|
| 55 | - array( |
|
| 56 | - array( |
|
| 57 | - 'methods' => WP_REST_Server::READABLE, |
|
| 58 | - 'callback' => array( $this, 'get_items' ), |
|
| 59 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 60 | - 'args' => $this->get_collection_params(), |
|
| 61 | - ), |
|
| 62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Makes sure the current user has access to READ the report APIs. |
|
| 70 | - * |
|
| 71 | - * @since 2.0.0 |
|
| 72 | - * @param WP_REST_Request $request Full data about the request. |
|
| 73 | - * @return WP_Error|boolean |
|
| 74 | - */ |
|
| 75 | - public function get_items_permissions_check( $request ) { |
|
| 76 | - |
|
| 77 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 78 | - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return true; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Get sales reports. |
|
| 86 | - * |
|
| 87 | - * @param WP_REST_Request $request |
|
| 88 | - * @return array|WP_Error |
|
| 89 | - */ |
|
| 90 | - public function get_items( $request ) { |
|
| 91 | - $data = array(); |
|
| 92 | - $item = $this->prepare_item_for_response( null, $request ); |
|
| 93 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 94 | - |
|
| 95 | - return rest_ensure_response( $data ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Prepare a report sales object for serialization. |
|
| 100 | - * |
|
| 101 | - * @param null $_ |
|
| 102 | - * @param WP_REST_Request $request Request object. |
|
| 103 | - * @return WP_REST_Response $response Response data. |
|
| 104 | - */ |
|
| 105 | - public function prepare_item_for_response( $_, $request ) { |
|
| 106 | - |
|
| 107 | - // Set report range. |
|
| 108 | - $this->report_range = $this->get_date_range( $request ); |
|
| 109 | - |
|
| 110 | - $report_data = $this->get_report_data(); |
|
| 111 | - $period_totals = array(); |
|
| 112 | - |
|
| 113 | - // Setup period totals by ensuring each period in the interval has data. |
|
| 114 | - $start_date = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS; |
|
| 115 | - |
|
| 116 | - if ( 'month' === $this->groupby ) { |
|
| 117 | - $start_date = strtotime( date( 'Y-m-01', $start_date ) ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - for ( $i = 0; $i < $this->interval; $i++ ) { |
|
| 121 | - |
|
| 122 | - switch ( $this->groupby ) { |
|
| 123 | - case 'day' : |
|
| 124 | - $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
| 125 | - break; |
|
| 126 | - default : |
|
| 127 | - $time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
| 128 | - break; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // Set the defaults for each period. |
|
| 132 | - $period_totals[ $time ] = array( |
|
| 133 | - 'invoices' => 0, |
|
| 134 | - 'items' => 0, |
|
| 135 | - 'refunded_items' => 0, |
|
| 136 | - 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
| 137 | - 'subtotal' => wpinv_round_amount( 0.00 ), |
|
| 138 | - 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
| 139 | - 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
| 140 | - 'discount' => wpinv_round_amount( 0.00 ), |
|
| 141 | - ); |
|
| 142 | - |
|
| 143 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 144 | - if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
| 145 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // add total sales, total invoice count, total tax for each period |
|
| 152 | - $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
| 153 | - foreach ( $report_data->invoices as $invoice ) { |
|
| 154 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 155 | - |
|
| 156 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 157 | - continue; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 161 | - $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 162 | - $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 163 | - $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 164 | - |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - foreach ( $report_data->refunds as $invoice ) { |
|
| 168 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 169 | - |
|
| 170 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 171 | - continue; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 175 | - $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 176 | - $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 177 | - $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - foreach ( $report_data->invoice_counts as $invoice ) { |
|
| 182 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 183 | - |
|
| 184 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 185 | - $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // Add total invoice items for each period. |
|
| 191 | - foreach ( $report_data->invoice_items as $invoice_item ) { |
|
| 192 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
| 193 | - |
|
| 194 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 195 | - $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // Add total discount for each period. |
|
| 201 | - foreach ( $report_data->coupons as $discount ) { |
|
| 202 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
| 203 | - |
|
| 204 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 205 | - $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Extra fields. |
|
| 211 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 212 | - |
|
| 213 | - // Abort unprepared. |
|
| 214 | - if ( ! isset( $report_data->$key ) ) { |
|
| 215 | - continue; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // Abort defaults. |
|
| 219 | - if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
| 220 | - continue; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Set values. |
|
| 224 | - foreach ( $report_data->$key as $item ) { |
|
| 225 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $item->date ) ) : date( 'Y-m', strtotime( $item->date ) ); |
|
| 226 | - |
|
| 227 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 228 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - unset( $report_data->$key ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $report_data->totals = $period_totals; |
|
| 236 | - $report_data->grouped_by = $this->groupby; |
|
| 237 | - $report_data->interval = max( $this->interval, 1 ); |
|
| 238 | - $report_data->currency = wpinv_get_currency(); |
|
| 239 | - $report_data->currency_symbol = wpinv_currency_symbol(); |
|
| 240 | - $report_data->currency_position = wpinv_currency_position(); |
|
| 241 | - $report_data->decimal_places = wpinv_decimals(); |
|
| 242 | - $report_data->thousands_sep = wpinv_thousands_separator(); |
|
| 243 | - $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 244 | - $report_data->start_date = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ); |
|
| 245 | - $report_data->end_date = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ); |
|
| 246 | - $report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) ); |
|
| 247 | - $report_data->end_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) ); |
|
| 248 | - $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 249 | - |
|
| 250 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 251 | - $data = $report_data; |
|
| 252 | - unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
| 253 | - $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
| 254 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 255 | - |
|
| 256 | - // Wrap the data in a response object. |
|
| 257 | - $response = rest_ensure_response( $data ); |
|
| 258 | - $response->add_links( array( |
|
| 259 | - 'about' => array( |
|
| 260 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
| 261 | - ), |
|
| 262 | - ) ); |
|
| 263 | - |
|
| 264 | - return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Get report data. |
|
| 269 | - * |
|
| 270 | - * @return stdClass |
|
| 271 | - */ |
|
| 272 | - public function get_report_data() { |
|
| 273 | - if ( empty( $this->report_data ) ) { |
|
| 274 | - $this->query_report_data(); |
|
| 275 | - } |
|
| 276 | - return $this->report_data; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Get all data needed for this report and store in the class. |
|
| 281 | - */ |
|
| 282 | - protected function query_report_data() { |
|
| 283 | - |
|
| 284 | - // Prepare reports. |
|
| 285 | - $this->report_data = (object) array( |
|
| 286 | - 'invoice_counts' => $this->query_invoice_counts(),//count, post_date |
|
| 287 | - 'coupons' => $this->query_coupon_counts(), // discount_amount, post_date |
|
| 288 | - 'invoice_items' => $this->query_item_counts(), // invoice_item_count, post_date |
|
| 289 | - 'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date |
|
| 290 | - 'invoices' => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 291 | - 'refunds' => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 292 | - 'previous_range' => $this->previous_range, |
|
| 293 | - ); |
|
| 294 | - |
|
| 295 | - // Calculated totals. |
|
| 296 | - $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
| 297 | - $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
| 298 | - $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
| 299 | - $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
| 300 | - $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
| 301 | - $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
| 302 | - $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
| 303 | - $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
| 304 | - $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
| 305 | - $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
| 306 | - $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
| 307 | - $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - // Calculate average based on net. |
|
| 311 | - $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
| 312 | - $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
| 313 | - |
|
| 314 | - // Total invoices in this period, even if refunded. |
|
| 315 | - $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
| 316 | - |
|
| 317 | - // Items invoiced in this period, even if refunded. |
|
| 318 | - $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
| 319 | - |
|
| 320 | - // 3rd party filtering of report data |
|
| 321 | - $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Prepares invoice counts. |
|
| 326 | - * |
|
| 327 | - * @return array. |
|
| 328 | - */ |
|
| 329 | - protected function query_invoice_counts() { |
|
| 330 | - |
|
| 331 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 332 | - array( |
|
| 333 | - 'data' => array( |
|
| 334 | - 'ID' => array( |
|
| 335 | - 'type' => 'post_data', |
|
| 336 | - 'function' => 'COUNT', |
|
| 337 | - 'name' => 'count', |
|
| 338 | - 'distinct' => true, |
|
| 339 | - ), |
|
| 340 | - 'post_date' => array( |
|
| 341 | - 'type' => 'post_data', |
|
| 342 | - 'function' => '', |
|
| 343 | - 'name' => 'post_date', |
|
| 344 | - ), |
|
| 345 | - ), |
|
| 346 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 347 | - 'order_by' => 'post_date ASC', |
|
| 348 | - 'query_type' => 'get_results', |
|
| 349 | - 'filter_range' => $this->report_range, |
|
| 350 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Prepares coupon counts. |
|
| 358 | - * |
|
| 359 | - * @return array. |
|
| 360 | - */ |
|
| 361 | - protected function query_coupon_counts() { |
|
| 362 | - |
|
| 363 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 364 | - array( |
|
| 365 | - 'data' => array( |
|
| 366 | - 'discount' => array( |
|
| 367 | - 'type' => 'invoice_data', |
|
| 368 | - 'function' => 'SUM', |
|
| 369 | - 'name' => 'discount_amount', |
|
| 370 | - ), |
|
| 371 | - 'post_date' => array( |
|
| 372 | - 'type' => 'post_data', |
|
| 373 | - 'function' => '', |
|
| 374 | - 'name' => 'post_date', |
|
| 375 | - ), |
|
| 376 | - ), |
|
| 377 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 378 | - 'order_by' => 'post_date ASC', |
|
| 379 | - 'query_type' => 'get_results', |
|
| 380 | - 'filter_range' => $this->report_range, |
|
| 381 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 382 | - ) |
|
| 383 | - ); |
|
| 384 | - |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Prepares item counts. |
|
| 389 | - * |
|
| 390 | - * @return array. |
|
| 391 | - */ |
|
| 392 | - protected function query_item_counts() { |
|
| 393 | - |
|
| 394 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 395 | - array( |
|
| 396 | - 'data' => array( |
|
| 397 | - 'quantity' => array( |
|
| 398 | - 'type' => 'invoice_item', |
|
| 399 | - 'function' => 'SUM', |
|
| 400 | - 'name' => 'invoice_item_count', |
|
| 401 | - ), |
|
| 402 | - 'post_date' => array( |
|
| 403 | - 'type' => 'post_data', |
|
| 404 | - 'function' => '', |
|
| 405 | - 'name' => 'post_date', |
|
| 406 | - ), |
|
| 407 | - ), |
|
| 408 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 409 | - 'order_by' => 'post_date ASC', |
|
| 410 | - 'query_type' => 'get_results', |
|
| 411 | - 'filter_range' => $this->report_range, |
|
| 412 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 413 | - ) |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Prepares refunded item counts. |
|
| 420 | - * |
|
| 421 | - * @return array. |
|
| 422 | - */ |
|
| 423 | - protected function count_refunded_items() { |
|
| 424 | - |
|
| 425 | - return (int) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 426 | - array( |
|
| 427 | - 'data' => array( |
|
| 428 | - 'quantity' => array( |
|
| 429 | - 'type' => 'invoice_item', |
|
| 430 | - 'function' => 'SUM', |
|
| 431 | - 'name' => 'invoice_item_count', |
|
| 432 | - ), |
|
| 433 | - ), |
|
| 434 | - 'query_type' => 'get_var', |
|
| 435 | - 'filter_range' => $this->report_range, |
|
| 436 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
| 437 | - ) |
|
| 438 | - ); |
|
| 439 | - |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Prepares daily invoice totals. |
|
| 444 | - * |
|
| 445 | - * @return array. |
|
| 446 | - */ |
|
| 447 | - protected function query_invoice_totals() { |
|
| 448 | - |
|
| 449 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 450 | - array( |
|
| 451 | - 'data' => array( |
|
| 452 | - 'total' => array( |
|
| 453 | - 'type' => 'invoice_data', |
|
| 454 | - 'function' => 'SUM', |
|
| 455 | - 'name' => 'total_sales', |
|
| 456 | - ), |
|
| 457 | - 'tax' => array( |
|
| 458 | - 'type' => 'invoice_data', |
|
| 459 | - 'function' => 'SUM', |
|
| 460 | - 'name' => 'total_tax', |
|
| 461 | - ), |
|
| 462 | - 'discount' => array( |
|
| 463 | - 'type' => 'invoice_data', |
|
| 464 | - 'function' => 'SUM', |
|
| 465 | - 'name' => 'total_discount', |
|
| 466 | - ), |
|
| 467 | - 'fees_total' => array( |
|
| 468 | - 'type' => 'invoice_data', |
|
| 469 | - 'function' => 'SUM', |
|
| 470 | - 'name' => 'total_fees', |
|
| 471 | - ), |
|
| 472 | - 'subtotal' => array( |
|
| 473 | - 'type' => 'invoice_data', |
|
| 474 | - 'function' => 'SUM', |
|
| 475 | - 'name' => 'subtotal', |
|
| 476 | - ), |
|
| 477 | - 'post_date' => array( |
|
| 478 | - 'type' => 'post_data', |
|
| 479 | - 'function' => '', |
|
| 480 | - 'name' => 'post_date', |
|
| 481 | - ), |
|
| 482 | - ), |
|
| 483 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 484 | - 'order_by' => 'post_date ASC', |
|
| 485 | - 'query_type' => 'get_results', |
|
| 486 | - 'filter_range' => $this->report_range, |
|
| 487 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
| 488 | - ) |
|
| 489 | - ); |
|
| 490 | - |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Prepares daily invoice totals. |
|
| 495 | - * |
|
| 496 | - * @return array. |
|
| 497 | - */ |
|
| 498 | - protected function query_refunded_totals() { |
|
| 499 | - |
|
| 500 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 501 | - array( |
|
| 502 | - 'data' => array( |
|
| 503 | - 'total' => array( |
|
| 504 | - 'type' => 'invoice_data', |
|
| 505 | - 'function' => 'SUM', |
|
| 506 | - 'name' => 'total_sales', |
|
| 507 | - ), |
|
| 508 | - 'tax' => array( |
|
| 509 | - 'type' => 'invoice_data', |
|
| 510 | - 'function' => 'SUM', |
|
| 511 | - 'name' => 'total_tax', |
|
| 512 | - ), |
|
| 513 | - 'discount' => array( |
|
| 514 | - 'type' => 'invoice_data', |
|
| 515 | - 'function' => 'SUM', |
|
| 516 | - 'name' => 'total_discount', |
|
| 517 | - ), |
|
| 518 | - 'fees_total' => array( |
|
| 519 | - 'type' => 'invoice_data', |
|
| 520 | - 'function' => 'SUM', |
|
| 521 | - 'name' => 'total_fees', |
|
| 522 | - ), |
|
| 523 | - 'subtotal' => array( |
|
| 524 | - 'type' => 'invoice_data', |
|
| 525 | - 'function' => 'SUM', |
|
| 526 | - 'name' => 'subtotal', |
|
| 527 | - ), |
|
| 528 | - 'post_date' => array( |
|
| 529 | - 'type' => 'post_data', |
|
| 530 | - 'function' => '', |
|
| 531 | - 'name' => 'post_date', |
|
| 532 | - ), |
|
| 533 | - ), |
|
| 534 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 535 | - 'order_by' => 'post_date ASC', |
|
| 536 | - 'query_type' => 'get_results', |
|
| 537 | - 'filter_range' => $this->report_range, |
|
| 538 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
| 539 | - ) |
|
| 540 | - ); |
|
| 541 | - |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Get the Report's schema, conforming to JSON Schema. |
|
| 546 | - * |
|
| 547 | - * @return array |
|
| 548 | - */ |
|
| 549 | - public function get_item_schema() { |
|
| 550 | - |
|
| 551 | - $schema = array( |
|
| 552 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 553 | - 'title' => 'sales_report', |
|
| 554 | - 'type' => 'object', |
|
| 555 | - 'properties' => array( |
|
| 556 | - 'total_sales' => array( |
|
| 557 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 558 | - 'type' => 'string', |
|
| 559 | - 'context' => array( 'view' ), |
|
| 560 | - 'readonly' => true, |
|
| 561 | - ), |
|
| 562 | - 'net_sales' => array( |
|
| 563 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 564 | - 'type' => 'string', |
|
| 565 | - 'context' => array( 'view' ), |
|
| 566 | - 'readonly' => true, |
|
| 567 | - ), |
|
| 568 | - 'average_sales' => array( |
|
| 569 | - 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
| 570 | - 'type' => 'string', |
|
| 571 | - 'context' => array( 'view' ), |
|
| 572 | - 'readonly' => true, |
|
| 573 | - ), |
|
| 574 | - 'average_total_sales' => array( |
|
| 575 | - 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
| 576 | - 'type' => 'string', |
|
| 577 | - 'context' => array( 'view' ), |
|
| 578 | - 'readonly' => true, |
|
| 579 | - ), |
|
| 580 | - 'total_invoices' => array( |
|
| 581 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 582 | - 'type' => 'integer', |
|
| 583 | - 'context' => array( 'view' ), |
|
| 584 | - 'readonly' => true, |
|
| 585 | - ), |
|
| 586 | - 'total_items' => array( |
|
| 587 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 588 | - 'type' => 'integer', |
|
| 589 | - 'context' => array( 'view' ), |
|
| 590 | - 'readonly' => true, |
|
| 591 | - ), |
|
| 592 | - 'refunded_items' => array( |
|
| 593 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 594 | - 'type' => 'integer', |
|
| 595 | - 'context' => array( 'view' ), |
|
| 596 | - 'readonly' => true, |
|
| 597 | - ), |
|
| 598 | - 'total_tax' => array( |
|
| 599 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 600 | - 'type' => 'string', |
|
| 601 | - 'context' => array( 'view' ), |
|
| 602 | - 'readonly' => true, |
|
| 603 | - ), |
|
| 604 | - 'total_refunded_tax' => array( |
|
| 605 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 606 | - 'type' => 'string', |
|
| 607 | - 'context' => array( 'view' ), |
|
| 608 | - 'readonly' => true, |
|
| 609 | - ), |
|
| 610 | - 'total_fees' => array( |
|
| 611 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 612 | - 'type' => 'string', |
|
| 613 | - 'context' => array( 'view' ), |
|
| 614 | - 'readonly' => true, |
|
| 615 | - ), |
|
| 616 | - 'total_refunds' => array( |
|
| 617 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 618 | - 'type' => 'integer', |
|
| 619 | - 'context' => array( 'view' ), |
|
| 620 | - 'readonly' => true, |
|
| 621 | - ), |
|
| 622 | - 'net_refunds' => array( |
|
| 623 | - 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
| 624 | - 'type' => 'integer', |
|
| 625 | - 'context' => array( 'view' ), |
|
| 626 | - 'readonly' => true, |
|
| 627 | - ), |
|
| 628 | - 'total_discount' => array( |
|
| 629 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 630 | - 'type' => 'integer', |
|
| 631 | - 'context' => array( 'view' ), |
|
| 632 | - 'readonly' => true, |
|
| 633 | - ), |
|
| 634 | - 'totals' => array( |
|
| 635 | - 'description' => __( 'Totals.', 'invoicing' ), |
|
| 636 | - 'type' => 'array', |
|
| 637 | - 'items' => array( |
|
| 638 | - 'type' => 'array', |
|
| 639 | - ), |
|
| 640 | - 'context' => array( 'view' ), |
|
| 641 | - 'readonly' => true, |
|
| 642 | - ), |
|
| 643 | - 'interval' => array( |
|
| 644 | - 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
| 645 | - 'type' => 'integer', |
|
| 646 | - 'context' => array( 'view' ), |
|
| 647 | - 'readonly' => true, |
|
| 648 | - ), |
|
| 649 | - 'previous_range' => array( |
|
| 650 | - 'description' => __( 'The previous report period.', 'invoicing' ), |
|
| 651 | - 'type' => 'array', |
|
| 652 | - 'items' => array( |
|
| 653 | - 'type' => 'string', |
|
| 654 | - ), |
|
| 655 | - 'context' => array( 'view' ), |
|
| 656 | - 'readonly' => true, |
|
| 657 | - ), |
|
| 658 | - 'grouped_by' => array( |
|
| 659 | - 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
| 660 | - 'type' => 'string', |
|
| 661 | - 'context' => array( 'view' ), |
|
| 662 | - 'enum' => array( 'day', 'month' ), |
|
| 663 | - 'readonly' => true, |
|
| 664 | - ), |
|
| 665 | - 'currency' => array( |
|
| 666 | - 'description' => __( 'The default store currency.', 'invoicing' ), |
|
| 667 | - 'type' => 'string', |
|
| 668 | - 'context' => array( 'view' ), |
|
| 669 | - 'readonly' => true, |
|
| 670 | - ), |
|
| 671 | - 'currency_symbol' => array( |
|
| 672 | - 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
| 673 | - 'type' => 'string', |
|
| 674 | - 'context' => array( 'view' ), |
|
| 675 | - 'readonly' => true, |
|
| 676 | - ), |
|
| 677 | - 'currency_position' => array( |
|
| 678 | - 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
| 679 | - 'type' => 'string', |
|
| 680 | - 'context' => array( 'view' ), |
|
| 681 | - 'readonly' => true, |
|
| 682 | - ), |
|
| 683 | - 'decimal_places' => array( |
|
| 684 | - 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
| 685 | - 'type' => 'string', |
|
| 686 | - 'context' => array( 'view' ), |
|
| 687 | - 'readonly' => true, |
|
| 688 | - ), |
|
| 689 | - 'thousands_sep' => array( |
|
| 690 | - 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
| 691 | - 'type' => 'string', |
|
| 692 | - 'context' => array( 'view' ), |
|
| 693 | - 'readonly' => true, |
|
| 694 | - ), |
|
| 695 | - 'decimals_sep' => array( |
|
| 696 | - 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
| 697 | - 'type' => 'string', |
|
| 698 | - 'context' => array( 'view' ), |
|
| 699 | - 'readonly' => true, |
|
| 700 | - ), |
|
| 701 | - ), |
|
| 702 | - ); |
|
| 703 | - |
|
| 704 | - return $this->add_additional_fields_schema( $schema ); |
|
| 705 | - |
|
| 706 | - } |
|
| 21 | + /** |
|
| 22 | + * Route base. |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $rest_base = 'reports/sales'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The report data. |
|
| 30 | + * |
|
| 31 | + * @var stdClass |
|
| 32 | + */ |
|
| 33 | + public $report_data; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The report range. |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + public $report_range; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Registers the routes for the objects of the controller. |
|
| 44 | + * |
|
| 45 | + * @since 2.0.0 |
|
| 46 | + * |
|
| 47 | + * @see register_rest_route() |
|
| 48 | + */ |
|
| 49 | + public function register_namespace_routes( $namespace ) { |
|
| 50 | + |
|
| 51 | + // Get sales report. |
|
| 52 | + register_rest_route( |
|
| 53 | + $namespace, |
|
| 54 | + $this->rest_base, |
|
| 55 | + array( |
|
| 56 | + array( |
|
| 57 | + 'methods' => WP_REST_Server::READABLE, |
|
| 58 | + 'callback' => array( $this, 'get_items' ), |
|
| 59 | + 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 60 | + 'args' => $this->get_collection_params(), |
|
| 61 | + ), |
|
| 62 | + 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Makes sure the current user has access to READ the report APIs. |
|
| 70 | + * |
|
| 71 | + * @since 2.0.0 |
|
| 72 | + * @param WP_REST_Request $request Full data about the request. |
|
| 73 | + * @return WP_Error|boolean |
|
| 74 | + */ |
|
| 75 | + public function get_items_permissions_check( $request ) { |
|
| 76 | + |
|
| 77 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 78 | + return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Get sales reports. |
|
| 86 | + * |
|
| 87 | + * @param WP_REST_Request $request |
|
| 88 | + * @return array|WP_Error |
|
| 89 | + */ |
|
| 90 | + public function get_items( $request ) { |
|
| 91 | + $data = array(); |
|
| 92 | + $item = $this->prepare_item_for_response( null, $request ); |
|
| 93 | + $data[] = $this->prepare_response_for_collection( $item ); |
|
| 94 | + |
|
| 95 | + return rest_ensure_response( $data ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Prepare a report sales object for serialization. |
|
| 100 | + * |
|
| 101 | + * @param null $_ |
|
| 102 | + * @param WP_REST_Request $request Request object. |
|
| 103 | + * @return WP_REST_Response $response Response data. |
|
| 104 | + */ |
|
| 105 | + public function prepare_item_for_response( $_, $request ) { |
|
| 106 | + |
|
| 107 | + // Set report range. |
|
| 108 | + $this->report_range = $this->get_date_range( $request ); |
|
| 109 | + |
|
| 110 | + $report_data = $this->get_report_data(); |
|
| 111 | + $period_totals = array(); |
|
| 112 | + |
|
| 113 | + // Setup period totals by ensuring each period in the interval has data. |
|
| 114 | + $start_date = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS; |
|
| 115 | + |
|
| 116 | + if ( 'month' === $this->groupby ) { |
|
| 117 | + $start_date = strtotime( date( 'Y-m-01', $start_date ) ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + for ( $i = 0; $i < $this->interval; $i++ ) { |
|
| 121 | + |
|
| 122 | + switch ( $this->groupby ) { |
|
| 123 | + case 'day' : |
|
| 124 | + $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
| 125 | + break; |
|
| 126 | + default : |
|
| 127 | + $time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
| 128 | + break; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // Set the defaults for each period. |
|
| 132 | + $period_totals[ $time ] = array( |
|
| 133 | + 'invoices' => 0, |
|
| 134 | + 'items' => 0, |
|
| 135 | + 'refunded_items' => 0, |
|
| 136 | + 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
| 137 | + 'subtotal' => wpinv_round_amount( 0.00 ), |
|
| 138 | + 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
| 139 | + 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
| 140 | + 'discount' => wpinv_round_amount( 0.00 ), |
|
| 141 | + ); |
|
| 142 | + |
|
| 143 | + foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 144 | + if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
| 145 | + $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // add total sales, total invoice count, total tax for each period |
|
| 152 | + $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
| 153 | + foreach ( $report_data->invoices as $invoice ) { |
|
| 154 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 155 | + |
|
| 156 | + if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 157 | + continue; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 161 | + $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 162 | + $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 163 | + $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 164 | + |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + foreach ( $report_data->refunds as $invoice ) { |
|
| 168 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 169 | + |
|
| 170 | + if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 175 | + $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 176 | + $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 177 | + $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + foreach ( $report_data->invoice_counts as $invoice ) { |
|
| 182 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 183 | + |
|
| 184 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 185 | + $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // Add total invoice items for each period. |
|
| 191 | + foreach ( $report_data->invoice_items as $invoice_item ) { |
|
| 192 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
| 193 | + |
|
| 194 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 195 | + $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // Add total discount for each period. |
|
| 201 | + foreach ( $report_data->coupons as $discount ) { |
|
| 202 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
| 203 | + |
|
| 204 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 205 | + $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Extra fields. |
|
| 211 | + foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 212 | + |
|
| 213 | + // Abort unprepared. |
|
| 214 | + if ( ! isset( $report_data->$key ) ) { |
|
| 215 | + continue; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // Abort defaults. |
|
| 219 | + if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
| 220 | + continue; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Set values. |
|
| 224 | + foreach ( $report_data->$key as $item ) { |
|
| 225 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $item->date ) ) : date( 'Y-m', strtotime( $item->date ) ); |
|
| 226 | + |
|
| 227 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 228 | + $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + unset( $report_data->$key ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $report_data->totals = $period_totals; |
|
| 236 | + $report_data->grouped_by = $this->groupby; |
|
| 237 | + $report_data->interval = max( $this->interval, 1 ); |
|
| 238 | + $report_data->currency = wpinv_get_currency(); |
|
| 239 | + $report_data->currency_symbol = wpinv_currency_symbol(); |
|
| 240 | + $report_data->currency_position = wpinv_currency_position(); |
|
| 241 | + $report_data->decimal_places = wpinv_decimals(); |
|
| 242 | + $report_data->thousands_sep = wpinv_thousands_separator(); |
|
| 243 | + $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 244 | + $report_data->start_date = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ); |
|
| 245 | + $report_data->end_date = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ); |
|
| 246 | + $report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) ); |
|
| 247 | + $report_data->end_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) ); |
|
| 248 | + $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 249 | + |
|
| 250 | + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 251 | + $data = $report_data; |
|
| 252 | + unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
| 253 | + $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
| 254 | + $data = $this->filter_response_by_context( $data, $context ); |
|
| 255 | + |
|
| 256 | + // Wrap the data in a response object. |
|
| 257 | + $response = rest_ensure_response( $data ); |
|
| 258 | + $response->add_links( array( |
|
| 259 | + 'about' => array( |
|
| 260 | + 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
| 261 | + ), |
|
| 262 | + ) ); |
|
| 263 | + |
|
| 264 | + return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Get report data. |
|
| 269 | + * |
|
| 270 | + * @return stdClass |
|
| 271 | + */ |
|
| 272 | + public function get_report_data() { |
|
| 273 | + if ( empty( $this->report_data ) ) { |
|
| 274 | + $this->query_report_data(); |
|
| 275 | + } |
|
| 276 | + return $this->report_data; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Get all data needed for this report and store in the class. |
|
| 281 | + */ |
|
| 282 | + protected function query_report_data() { |
|
| 283 | + |
|
| 284 | + // Prepare reports. |
|
| 285 | + $this->report_data = (object) array( |
|
| 286 | + 'invoice_counts' => $this->query_invoice_counts(),//count, post_date |
|
| 287 | + 'coupons' => $this->query_coupon_counts(), // discount_amount, post_date |
|
| 288 | + 'invoice_items' => $this->query_item_counts(), // invoice_item_count, post_date |
|
| 289 | + 'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date |
|
| 290 | + 'invoices' => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 291 | + 'refunds' => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 292 | + 'previous_range' => $this->previous_range, |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + // Calculated totals. |
|
| 296 | + $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
| 297 | + $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
| 298 | + $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
| 299 | + $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
| 300 | + $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
| 301 | + $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
| 302 | + $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
| 303 | + $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
| 304 | + $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
| 305 | + $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
| 306 | + $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
| 307 | + $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + // Calculate average based on net. |
|
| 311 | + $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
| 312 | + $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
| 313 | + |
|
| 314 | + // Total invoices in this period, even if refunded. |
|
| 315 | + $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
| 316 | + |
|
| 317 | + // Items invoiced in this period, even if refunded. |
|
| 318 | + $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
| 319 | + |
|
| 320 | + // 3rd party filtering of report data |
|
| 321 | + $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Prepares invoice counts. |
|
| 326 | + * |
|
| 327 | + * @return array. |
|
| 328 | + */ |
|
| 329 | + protected function query_invoice_counts() { |
|
| 330 | + |
|
| 331 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 332 | + array( |
|
| 333 | + 'data' => array( |
|
| 334 | + 'ID' => array( |
|
| 335 | + 'type' => 'post_data', |
|
| 336 | + 'function' => 'COUNT', |
|
| 337 | + 'name' => 'count', |
|
| 338 | + 'distinct' => true, |
|
| 339 | + ), |
|
| 340 | + 'post_date' => array( |
|
| 341 | + 'type' => 'post_data', |
|
| 342 | + 'function' => '', |
|
| 343 | + 'name' => 'post_date', |
|
| 344 | + ), |
|
| 345 | + ), |
|
| 346 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 347 | + 'order_by' => 'post_date ASC', |
|
| 348 | + 'query_type' => 'get_results', |
|
| 349 | + 'filter_range' => $this->report_range, |
|
| 350 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Prepares coupon counts. |
|
| 358 | + * |
|
| 359 | + * @return array. |
|
| 360 | + */ |
|
| 361 | + protected function query_coupon_counts() { |
|
| 362 | + |
|
| 363 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 364 | + array( |
|
| 365 | + 'data' => array( |
|
| 366 | + 'discount' => array( |
|
| 367 | + 'type' => 'invoice_data', |
|
| 368 | + 'function' => 'SUM', |
|
| 369 | + 'name' => 'discount_amount', |
|
| 370 | + ), |
|
| 371 | + 'post_date' => array( |
|
| 372 | + 'type' => 'post_data', |
|
| 373 | + 'function' => '', |
|
| 374 | + 'name' => 'post_date', |
|
| 375 | + ), |
|
| 376 | + ), |
|
| 377 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 378 | + 'order_by' => 'post_date ASC', |
|
| 379 | + 'query_type' => 'get_results', |
|
| 380 | + 'filter_range' => $this->report_range, |
|
| 381 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 382 | + ) |
|
| 383 | + ); |
|
| 384 | + |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Prepares item counts. |
|
| 389 | + * |
|
| 390 | + * @return array. |
|
| 391 | + */ |
|
| 392 | + protected function query_item_counts() { |
|
| 393 | + |
|
| 394 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 395 | + array( |
|
| 396 | + 'data' => array( |
|
| 397 | + 'quantity' => array( |
|
| 398 | + 'type' => 'invoice_item', |
|
| 399 | + 'function' => 'SUM', |
|
| 400 | + 'name' => 'invoice_item_count', |
|
| 401 | + ), |
|
| 402 | + 'post_date' => array( |
|
| 403 | + 'type' => 'post_data', |
|
| 404 | + 'function' => '', |
|
| 405 | + 'name' => 'post_date', |
|
| 406 | + ), |
|
| 407 | + ), |
|
| 408 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 409 | + 'order_by' => 'post_date ASC', |
|
| 410 | + 'query_type' => 'get_results', |
|
| 411 | + 'filter_range' => $this->report_range, |
|
| 412 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 413 | + ) |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Prepares refunded item counts. |
|
| 420 | + * |
|
| 421 | + * @return array. |
|
| 422 | + */ |
|
| 423 | + protected function count_refunded_items() { |
|
| 424 | + |
|
| 425 | + return (int) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 426 | + array( |
|
| 427 | + 'data' => array( |
|
| 428 | + 'quantity' => array( |
|
| 429 | + 'type' => 'invoice_item', |
|
| 430 | + 'function' => 'SUM', |
|
| 431 | + 'name' => 'invoice_item_count', |
|
| 432 | + ), |
|
| 433 | + ), |
|
| 434 | + 'query_type' => 'get_var', |
|
| 435 | + 'filter_range' => $this->report_range, |
|
| 436 | + 'invoice_status' => array( 'wpi-refunded' ), |
|
| 437 | + ) |
|
| 438 | + ); |
|
| 439 | + |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Prepares daily invoice totals. |
|
| 444 | + * |
|
| 445 | + * @return array. |
|
| 446 | + */ |
|
| 447 | + protected function query_invoice_totals() { |
|
| 448 | + |
|
| 449 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 450 | + array( |
|
| 451 | + 'data' => array( |
|
| 452 | + 'total' => array( |
|
| 453 | + 'type' => 'invoice_data', |
|
| 454 | + 'function' => 'SUM', |
|
| 455 | + 'name' => 'total_sales', |
|
| 456 | + ), |
|
| 457 | + 'tax' => array( |
|
| 458 | + 'type' => 'invoice_data', |
|
| 459 | + 'function' => 'SUM', |
|
| 460 | + 'name' => 'total_tax', |
|
| 461 | + ), |
|
| 462 | + 'discount' => array( |
|
| 463 | + 'type' => 'invoice_data', |
|
| 464 | + 'function' => 'SUM', |
|
| 465 | + 'name' => 'total_discount', |
|
| 466 | + ), |
|
| 467 | + 'fees_total' => array( |
|
| 468 | + 'type' => 'invoice_data', |
|
| 469 | + 'function' => 'SUM', |
|
| 470 | + 'name' => 'total_fees', |
|
| 471 | + ), |
|
| 472 | + 'subtotal' => array( |
|
| 473 | + 'type' => 'invoice_data', |
|
| 474 | + 'function' => 'SUM', |
|
| 475 | + 'name' => 'subtotal', |
|
| 476 | + ), |
|
| 477 | + 'post_date' => array( |
|
| 478 | + 'type' => 'post_data', |
|
| 479 | + 'function' => '', |
|
| 480 | + 'name' => 'post_date', |
|
| 481 | + ), |
|
| 482 | + ), |
|
| 483 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 484 | + 'order_by' => 'post_date ASC', |
|
| 485 | + 'query_type' => 'get_results', |
|
| 486 | + 'filter_range' => $this->report_range, |
|
| 487 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
| 488 | + ) |
|
| 489 | + ); |
|
| 490 | + |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * Prepares daily invoice totals. |
|
| 495 | + * |
|
| 496 | + * @return array. |
|
| 497 | + */ |
|
| 498 | + protected function query_refunded_totals() { |
|
| 499 | + |
|
| 500 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 501 | + array( |
|
| 502 | + 'data' => array( |
|
| 503 | + 'total' => array( |
|
| 504 | + 'type' => 'invoice_data', |
|
| 505 | + 'function' => 'SUM', |
|
| 506 | + 'name' => 'total_sales', |
|
| 507 | + ), |
|
| 508 | + 'tax' => array( |
|
| 509 | + 'type' => 'invoice_data', |
|
| 510 | + 'function' => 'SUM', |
|
| 511 | + 'name' => 'total_tax', |
|
| 512 | + ), |
|
| 513 | + 'discount' => array( |
|
| 514 | + 'type' => 'invoice_data', |
|
| 515 | + 'function' => 'SUM', |
|
| 516 | + 'name' => 'total_discount', |
|
| 517 | + ), |
|
| 518 | + 'fees_total' => array( |
|
| 519 | + 'type' => 'invoice_data', |
|
| 520 | + 'function' => 'SUM', |
|
| 521 | + 'name' => 'total_fees', |
|
| 522 | + ), |
|
| 523 | + 'subtotal' => array( |
|
| 524 | + 'type' => 'invoice_data', |
|
| 525 | + 'function' => 'SUM', |
|
| 526 | + 'name' => 'subtotal', |
|
| 527 | + ), |
|
| 528 | + 'post_date' => array( |
|
| 529 | + 'type' => 'post_data', |
|
| 530 | + 'function' => '', |
|
| 531 | + 'name' => 'post_date', |
|
| 532 | + ), |
|
| 533 | + ), |
|
| 534 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 535 | + 'order_by' => 'post_date ASC', |
|
| 536 | + 'query_type' => 'get_results', |
|
| 537 | + 'filter_range' => $this->report_range, |
|
| 538 | + 'invoice_status' => array( 'wpi-refunded' ), |
|
| 539 | + ) |
|
| 540 | + ); |
|
| 541 | + |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Get the Report's schema, conforming to JSON Schema. |
|
| 546 | + * |
|
| 547 | + * @return array |
|
| 548 | + */ |
|
| 549 | + public function get_item_schema() { |
|
| 550 | + |
|
| 551 | + $schema = array( |
|
| 552 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 553 | + 'title' => 'sales_report', |
|
| 554 | + 'type' => 'object', |
|
| 555 | + 'properties' => array( |
|
| 556 | + 'total_sales' => array( |
|
| 557 | + 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 558 | + 'type' => 'string', |
|
| 559 | + 'context' => array( 'view' ), |
|
| 560 | + 'readonly' => true, |
|
| 561 | + ), |
|
| 562 | + 'net_sales' => array( |
|
| 563 | + 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 564 | + 'type' => 'string', |
|
| 565 | + 'context' => array( 'view' ), |
|
| 566 | + 'readonly' => true, |
|
| 567 | + ), |
|
| 568 | + 'average_sales' => array( |
|
| 569 | + 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
| 570 | + 'type' => 'string', |
|
| 571 | + 'context' => array( 'view' ), |
|
| 572 | + 'readonly' => true, |
|
| 573 | + ), |
|
| 574 | + 'average_total_sales' => array( |
|
| 575 | + 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
| 576 | + 'type' => 'string', |
|
| 577 | + 'context' => array( 'view' ), |
|
| 578 | + 'readonly' => true, |
|
| 579 | + ), |
|
| 580 | + 'total_invoices' => array( |
|
| 581 | + 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 582 | + 'type' => 'integer', |
|
| 583 | + 'context' => array( 'view' ), |
|
| 584 | + 'readonly' => true, |
|
| 585 | + ), |
|
| 586 | + 'total_items' => array( |
|
| 587 | + 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 588 | + 'type' => 'integer', |
|
| 589 | + 'context' => array( 'view' ), |
|
| 590 | + 'readonly' => true, |
|
| 591 | + ), |
|
| 592 | + 'refunded_items' => array( |
|
| 593 | + 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 594 | + 'type' => 'integer', |
|
| 595 | + 'context' => array( 'view' ), |
|
| 596 | + 'readonly' => true, |
|
| 597 | + ), |
|
| 598 | + 'total_tax' => array( |
|
| 599 | + 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 600 | + 'type' => 'string', |
|
| 601 | + 'context' => array( 'view' ), |
|
| 602 | + 'readonly' => true, |
|
| 603 | + ), |
|
| 604 | + 'total_refunded_tax' => array( |
|
| 605 | + 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 606 | + 'type' => 'string', |
|
| 607 | + 'context' => array( 'view' ), |
|
| 608 | + 'readonly' => true, |
|
| 609 | + ), |
|
| 610 | + 'total_fees' => array( |
|
| 611 | + 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 612 | + 'type' => 'string', |
|
| 613 | + 'context' => array( 'view' ), |
|
| 614 | + 'readonly' => true, |
|
| 615 | + ), |
|
| 616 | + 'total_refunds' => array( |
|
| 617 | + 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 618 | + 'type' => 'integer', |
|
| 619 | + 'context' => array( 'view' ), |
|
| 620 | + 'readonly' => true, |
|
| 621 | + ), |
|
| 622 | + 'net_refunds' => array( |
|
| 623 | + 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
| 624 | + 'type' => 'integer', |
|
| 625 | + 'context' => array( 'view' ), |
|
| 626 | + 'readonly' => true, |
|
| 627 | + ), |
|
| 628 | + 'total_discount' => array( |
|
| 629 | + 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 630 | + 'type' => 'integer', |
|
| 631 | + 'context' => array( 'view' ), |
|
| 632 | + 'readonly' => true, |
|
| 633 | + ), |
|
| 634 | + 'totals' => array( |
|
| 635 | + 'description' => __( 'Totals.', 'invoicing' ), |
|
| 636 | + 'type' => 'array', |
|
| 637 | + 'items' => array( |
|
| 638 | + 'type' => 'array', |
|
| 639 | + ), |
|
| 640 | + 'context' => array( 'view' ), |
|
| 641 | + 'readonly' => true, |
|
| 642 | + ), |
|
| 643 | + 'interval' => array( |
|
| 644 | + 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
| 645 | + 'type' => 'integer', |
|
| 646 | + 'context' => array( 'view' ), |
|
| 647 | + 'readonly' => true, |
|
| 648 | + ), |
|
| 649 | + 'previous_range' => array( |
|
| 650 | + 'description' => __( 'The previous report period.', 'invoicing' ), |
|
| 651 | + 'type' => 'array', |
|
| 652 | + 'items' => array( |
|
| 653 | + 'type' => 'string', |
|
| 654 | + ), |
|
| 655 | + 'context' => array( 'view' ), |
|
| 656 | + 'readonly' => true, |
|
| 657 | + ), |
|
| 658 | + 'grouped_by' => array( |
|
| 659 | + 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
| 660 | + 'type' => 'string', |
|
| 661 | + 'context' => array( 'view' ), |
|
| 662 | + 'enum' => array( 'day', 'month' ), |
|
| 663 | + 'readonly' => true, |
|
| 664 | + ), |
|
| 665 | + 'currency' => array( |
|
| 666 | + 'description' => __( 'The default store currency.', 'invoicing' ), |
|
| 667 | + 'type' => 'string', |
|
| 668 | + 'context' => array( 'view' ), |
|
| 669 | + 'readonly' => true, |
|
| 670 | + ), |
|
| 671 | + 'currency_symbol' => array( |
|
| 672 | + 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
| 673 | + 'type' => 'string', |
|
| 674 | + 'context' => array( 'view' ), |
|
| 675 | + 'readonly' => true, |
|
| 676 | + ), |
|
| 677 | + 'currency_position' => array( |
|
| 678 | + 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
| 679 | + 'type' => 'string', |
|
| 680 | + 'context' => array( 'view' ), |
|
| 681 | + 'readonly' => true, |
|
| 682 | + ), |
|
| 683 | + 'decimal_places' => array( |
|
| 684 | + 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
| 685 | + 'type' => 'string', |
|
| 686 | + 'context' => array( 'view' ), |
|
| 687 | + 'readonly' => true, |
|
| 688 | + ), |
|
| 689 | + 'thousands_sep' => array( |
|
| 690 | + 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
| 691 | + 'type' => 'string', |
|
| 692 | + 'context' => array( 'view' ), |
|
| 693 | + 'readonly' => true, |
|
| 694 | + ), |
|
| 695 | + 'decimals_sep' => array( |
|
| 696 | + 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
| 697 | + 'type' => 'string', |
|
| 698 | + 'context' => array( 'view' ), |
|
| 699 | + 'readonly' => true, |
|
| 700 | + ), |
|
| 701 | + ), |
|
| 702 | + ); |
|
| 703 | + |
|
| 704 | + return $this->add_additional_fields_schema( $schema ); |
|
| 705 | + |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | 708 | } |
@@ -12,88 +12,88 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - public $views; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + public $views; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | 25 | |
| 26 | - $this->views = array( |
|
| 26 | + $this->views = array( |
|
| 27 | 27 | |
| 28 | 28 | 'items' => array( |
| 29 | - 'label' => __( 'Items', 'invoicing' ), |
|
| 30 | - 'class' => 'GetPaid_Reports_Report_Items', |
|
| 31 | - ), |
|
| 29 | + 'label' => __( 'Items', 'invoicing' ), |
|
| 30 | + 'class' => 'GetPaid_Reports_Report_Items', |
|
| 31 | + ), |
|
| 32 | 32 | |
| 33 | - 'gateways' => array( |
|
| 34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
| 35 | - 'class' => 'GetPaid_Reports_Report_Gateways', |
|
| 36 | - ), |
|
| 33 | + 'gateways' => array( |
|
| 34 | + 'label' => __( 'Payment Methods', 'invoicing' ), |
|
| 35 | + 'class' => 'GetPaid_Reports_Report_Gateways', |
|
| 36 | + ), |
|
| 37 | 37 | |
| 38 | - 'discounts' => array( |
|
| 39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
| 40 | - 'class' => 'GetPaid_Reports_Report_Discounts', |
|
| 41 | - ), |
|
| 38 | + 'discounts' => array( |
|
| 39 | + 'label' => __( 'Discount Codes', 'invoicing' ), |
|
| 40 | + 'class' => 'GetPaid_Reports_Report_Discounts', |
|
| 41 | + ), |
|
| 42 | 42 | |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
| 46 | - |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Retrieves the current range. |
|
| 51 | - * |
|
| 52 | - */ |
|
| 53 | - public function get_range() { |
|
| 54 | - $valid_ranges = $this->get_periods(); |
|
| 55 | - |
|
| 56 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 57 | - return sanitize_key( $_GET['date_range'] ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return '7_days'; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Returns an array of date ranges. |
|
| 65 | - * |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - public function get_periods() { |
|
| 69 | - |
|
| 70 | - $periods = array( |
|
| 71 | - 'today' => __( 'Today', 'invoicing' ), |
|
| 72 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
| 73 | - 'week' => __( 'This week', 'invoicing' ), |
|
| 74 | - 'last_week' => __( 'Last week', 'invoicing' ), |
|
| 75 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
| 76 | - 'month' => __( 'This month', 'invoicing' ), |
|
| 77 | - 'last_month' => __( 'Last month', 'invoicing' ), |
|
| 78 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 79 | - 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
| 80 | - 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
| 81 | - 'year' => __( 'This year', 'invoicing' ), |
|
| 82 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
| 83 | - 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Displays the range selector. |
|
| 91 | - * |
|
| 92 | - */ |
|
| 93 | - public function display_range_selector() { |
|
| 94 | - |
|
| 95 | - $range = $this->get_range(); |
|
| 96 | - ?> |
|
| 45 | + $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
| 46 | + |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Retrieves the current range. |
|
| 51 | + * |
|
| 52 | + */ |
|
| 53 | + public function get_range() { |
|
| 54 | + $valid_ranges = $this->get_periods(); |
|
| 55 | + |
|
| 56 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 57 | + return sanitize_key( $_GET['date_range'] ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return '7_days'; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Returns an array of date ranges. |
|
| 65 | + * |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + public function get_periods() { |
|
| 69 | + |
|
| 70 | + $periods = array( |
|
| 71 | + 'today' => __( 'Today', 'invoicing' ), |
|
| 72 | + 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
| 73 | + 'week' => __( 'This week', 'invoicing' ), |
|
| 74 | + 'last_week' => __( 'Last week', 'invoicing' ), |
|
| 75 | + '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
| 76 | + 'month' => __( 'This month', 'invoicing' ), |
|
| 77 | + 'last_month' => __( 'Last month', 'invoicing' ), |
|
| 78 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 79 | + 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
| 80 | + 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
| 81 | + 'year' => __( 'This year', 'invoicing' ), |
|
| 82 | + 'last_year' => __( 'Last Year', 'invoicing' ), |
|
| 83 | + 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Displays the range selector. |
|
| 91 | + * |
|
| 92 | + */ |
|
| 93 | + public function display_range_selector() { |
|
| 94 | + |
|
| 95 | + $range = $this->get_range(); |
|
| 96 | + ?> |
|
| 97 | 97 | |
| 98 | 98 | <form method="get" class="getpaid-filter-earnings float-right"> |
| 99 | 99 | <?php getpaid_hidden_field( 'page', 'wpinv-reports' ); ?> |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | </form> |
| 116 | 116 | |
| 117 | 117 | <?php |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Displays the reports tab. |
|
| 122 | - * |
|
| 123 | - */ |
|
| 124 | - public function display() { |
|
| 125 | - ?> |
|
| 120 | + /** |
|
| 121 | + * Displays the reports tab. |
|
| 122 | + * |
|
| 123 | + */ |
|
| 124 | + public function display() { |
|
| 125 | + ?> |
|
| 126 | 126 | |
| 127 | 127 | <div class="mt-4" style="max-width: 1200px;"> |
| 128 | 128 | |
@@ -202,16 +202,16 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | <?php |
| 204 | 204 | |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Displays the left side. |
|
| 209 | - * |
|
| 210 | - */ |
|
| 211 | - public function display_left() { |
|
| 212 | - $graphs = wpinv_get_report_graphs(); |
|
| 207 | + /** |
|
| 208 | + * Displays the left side. |
|
| 209 | + * |
|
| 210 | + */ |
|
| 211 | + public function display_left() { |
|
| 212 | + $graphs = wpinv_get_report_graphs(); |
|
| 213 | 213 | |
| 214 | - ?> |
|
| 214 | + ?> |
|
| 215 | 215 | |
| 216 | 216 | <?php foreach ( $graphs as $key => $graph ) : ?> |
| 217 | 217 | <div class="row mb-4"> |
@@ -230,35 +230,35 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | <?php |
| 232 | 232 | |
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Retrieves the download url. |
|
| 237 | - * |
|
| 238 | - */ |
|
| 239 | - public function get_download_url( $graph, $file_type ) { |
|
| 240 | - |
|
| 241 | - return wp_nonce_url( |
|
| 242 | - add_query_arg( |
|
| 243 | - array( |
|
| 244 | - 'getpaid-admin-action' => 'download_graph', |
|
| 245 | - 'file_type' => urlencode( $file_type ), |
|
| 246 | - 'graph' => urlencode( $graph ), |
|
| 247 | - ) |
|
| 248 | - ), |
|
| 249 | - 'getpaid-nonce', |
|
| 250 | - 'getpaid-nonce' |
|
| 251 | - ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Retrieves the download url. |
|
| 237 | + * |
|
| 238 | + */ |
|
| 239 | + public function get_download_url( $graph, $file_type ) { |
|
| 240 | + |
|
| 241 | + return wp_nonce_url( |
|
| 242 | + add_query_arg( |
|
| 243 | + array( |
|
| 244 | + 'getpaid-admin-action' => 'download_graph', |
|
| 245 | + 'file_type' => urlencode( $file_type ), |
|
| 246 | + 'graph' => urlencode( $graph ), |
|
| 247 | + ) |
|
| 248 | + ), |
|
| 249 | + 'getpaid-nonce', |
|
| 250 | + 'getpaid-nonce' |
|
| 251 | + ); |
|
| 252 | 252 | |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Displays the right side. |
|
| 257 | - * |
|
| 258 | - */ |
|
| 259 | - public function display_right() { |
|
| 255 | + /** |
|
| 256 | + * Displays the right side. |
|
| 257 | + * |
|
| 258 | + */ |
|
| 259 | + public function display_right() { |
|
| 260 | 260 | |
| 261 | - ?> |
|
| 261 | + ?> |
|
| 262 | 262 | |
| 263 | 263 | <?php foreach ( $this->views as $key => $view ) : ?> |
| 264 | 264 | <div class="row mb-4"> |
@@ -287,10 +287,10 @@ discard block |
||
| 287 | 287 | </div> |
| 288 | 288 | <div class="card-body"> |
| 289 | 289 | <?php |
| 290 | - $class = $view['class']; |
|
| 291 | - $class = new $class(); |
|
| 292 | - $class->display_stats(); |
|
| 293 | - ?> |
|
| 290 | + $class = $view['class']; |
|
| 291 | + $class = new $class(); |
|
| 292 | + $class->display_stats(); |
|
| 293 | + ?> |
|
| 294 | 294 | </div> |
| 295 | 295 | </div> |
| 296 | 296 | </div> |
@@ -299,67 +299,67 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | <?php |
| 301 | 301 | |
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Returns a list of report cards. |
|
| 306 | - * |
|
| 307 | - */ |
|
| 308 | - public function get_cards() { |
|
| 309 | - |
|
| 310 | - $cards = array( |
|
| 311 | - 'total_sales' => array( |
|
| 312 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 313 | - 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
| 314 | - ), |
|
| 315 | - 'net_sales' => array( |
|
| 316 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 317 | - 'label' => __( 'Net Revenue', 'invoicing' ), |
|
| 318 | - ), |
|
| 319 | - 'average_sales' => array( |
|
| 320 | - 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
| 321 | - 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
| 322 | - ), |
|
| 323 | - 'average_total_sales' => array( |
|
| 324 | - 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
| 325 | - 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
| 326 | - ), |
|
| 327 | - 'total_invoices' => array( |
|
| 328 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 329 | - 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
| 330 | - ), |
|
| 331 | - 'total_items' => array( |
|
| 332 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 333 | - 'label' => __( 'Purchased Items', 'invoicing' ), |
|
| 334 | - ), |
|
| 335 | - 'refunded_items' => array( |
|
| 336 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 337 | - 'label' => __( 'Refunded Items', 'invoicing' ), |
|
| 338 | - ), |
|
| 339 | - 'total_tax' => array( |
|
| 340 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 341 | - 'label' => __( 'Tax', 'invoicing' ), |
|
| 342 | - ), |
|
| 343 | - 'total_refunded_tax' => array( |
|
| 344 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 345 | - 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
| 346 | - ), |
|
| 347 | - 'total_fees' => array( |
|
| 348 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 349 | - 'label' => __( 'Fees', 'invoicing' ), |
|
| 350 | - ), |
|
| 351 | - 'total_refunds' => array( |
|
| 352 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 353 | - 'label' => __( 'Refunded', 'invoicing' ), |
|
| 354 | - ), |
|
| 355 | - 'total_discount' => array( |
|
| 356 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 357 | - 'label' => __( 'Discounted', 'invoicing' ), |
|
| 358 | - ), |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - return apply_filters( 'wpinv_report_cards', $cards ); |
|
| 362 | - } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Returns a list of report cards. |
|
| 306 | + * |
|
| 307 | + */ |
|
| 308 | + public function get_cards() { |
|
| 309 | + |
|
| 310 | + $cards = array( |
|
| 311 | + 'total_sales' => array( |
|
| 312 | + 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 313 | + 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
| 314 | + ), |
|
| 315 | + 'net_sales' => array( |
|
| 316 | + 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 317 | + 'label' => __( 'Net Revenue', 'invoicing' ), |
|
| 318 | + ), |
|
| 319 | + 'average_sales' => array( |
|
| 320 | + 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
| 321 | + 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
| 322 | + ), |
|
| 323 | + 'average_total_sales' => array( |
|
| 324 | + 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
| 325 | + 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
| 326 | + ), |
|
| 327 | + 'total_invoices' => array( |
|
| 328 | + 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 329 | + 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
| 330 | + ), |
|
| 331 | + 'total_items' => array( |
|
| 332 | + 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 333 | + 'label' => __( 'Purchased Items', 'invoicing' ), |
|
| 334 | + ), |
|
| 335 | + 'refunded_items' => array( |
|
| 336 | + 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 337 | + 'label' => __( 'Refunded Items', 'invoicing' ), |
|
| 338 | + ), |
|
| 339 | + 'total_tax' => array( |
|
| 340 | + 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 341 | + 'label' => __( 'Tax', 'invoicing' ), |
|
| 342 | + ), |
|
| 343 | + 'total_refunded_tax' => array( |
|
| 344 | + 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 345 | + 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
| 346 | + ), |
|
| 347 | + 'total_fees' => array( |
|
| 348 | + 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 349 | + 'label' => __( 'Fees', 'invoicing' ), |
|
| 350 | + ), |
|
| 351 | + 'total_refunds' => array( |
|
| 352 | + 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 353 | + 'label' => __( 'Refunded', 'invoicing' ), |
|
| 354 | + ), |
|
| 355 | + 'total_discount' => array( |
|
| 356 | + 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 357 | + 'label' => __( 'Discounted', 'invoicing' ), |
|
| 358 | + ), |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + return apply_filters( 'wpinv_report_cards', $cards ); |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | 364 | |
| 365 | 365 | |