@@ -12,22 +12,22 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Discounts extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $field = 'discount_code'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Retrieves the discounts sql. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function get_sql( $range ) { |
|
| 25 | - global $wpdb; |
|
| 26 | - |
|
| 27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | - $clauses = $this->get_range_sql( $range ); |
|
| 29 | - |
|
| 30 | - $sql = "SELECT |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $field = 'discount_code'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Retrieves the discounts sql. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function get_sql( $range ) { |
|
| 25 | + global $wpdb; |
|
| 26 | + |
|
| 27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | + $clauses = $this->get_range_sql( $range ); |
|
| 29 | + |
|
| 30 | + $sql = "SELECT |
|
| 31 | 31 | meta.discount_code AS discount_code, |
| 32 | 32 | SUM(total) as total |
| 33 | 33 | FROM $wpdb->posts |
@@ -41,91 +41,91 @@ discard block |
||
| 41 | 41 | ORDER BY total DESC |
| 42 | 42 | "; |
| 43 | 43 | |
| 44 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
| 44 | + return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
| 45 | 45 | |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Prepares the report stats. |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - public function prepare_stats() { |
|
| 53 | - global $wpdb; |
|
| 54 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 55 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * Prepares the report stats. |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + public function prepare_stats() { |
|
| 53 | + global $wpdb; |
|
| 54 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 55 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Normalizes the report stats. |
|
| 60 | - * |
|
| 61 | - */ |
|
| 62 | - public function normalize_stats( $stats ) { |
|
| 63 | - $normalized = array(); |
|
| 64 | - $others = 0; |
|
| 65 | - $did = 0; |
|
| 58 | + /** |
|
| 59 | + * Normalizes the report stats. |
|
| 60 | + * |
|
| 61 | + */ |
|
| 62 | + public function normalize_stats( $stats ) { |
|
| 63 | + $normalized = array(); |
|
| 64 | + $others = 0; |
|
| 65 | + $did = 0; |
|
| 66 | 66 | |
| 67 | - foreach ( $stats as $stat ) { |
|
| 67 | + foreach ( $stats as $stat ) { |
|
| 68 | 68 | |
| 69 | - if ( $did > 4 ) { |
|
| 69 | + if ( $did > 4 ) { |
|
| 70 | 70 | |
| 71 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 71 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 72 | 72 | |
| 73 | - } else { |
|
| 73 | + } else { |
|
| 74 | 74 | |
| 75 | - $normalized[] = array( |
|
| 76 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 77 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
| 78 | - ); |
|
| 75 | + $normalized[] = array( |
|
| 76 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 77 | + 'discount_code' => strip_tags( $stat->discount_code ), |
|
| 78 | + ); |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $did++; |
|
| 83 | - } |
|
| 82 | + $did++; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - if ( $others > 0 ) { |
|
| 85 | + if ( $others > 0 ) { |
|
| 86 | 86 | |
| 87 | - $normalized[] = array( |
|
| 88 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 89 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
| 90 | - ); |
|
| 87 | + $normalized[] = array( |
|
| 88 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 89 | + 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
| 90 | + ); |
|
| 91 | 91 | |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $normalized; |
|
| 95 | - } |
|
| 94 | + return $normalized; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Retrieves report data. |
|
| 99 | - * |
|
| 100 | - */ |
|
| 101 | - public function get_data() { |
|
| 97 | + /** |
|
| 98 | + * Retrieves report data. |
|
| 99 | + * |
|
| 100 | + */ |
|
| 101 | + public function get_data() { |
|
| 102 | 102 | |
| 103 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 104 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 103 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 104 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 105 | 105 | |
| 106 | - shuffle( $colors ); |
|
| 106 | + shuffle( $colors ); |
|
| 107 | 107 | |
| 108 | - return array( |
|
| 109 | - 'data' => $data, |
|
| 110 | - 'backgroundColor' => $colors, |
|
| 111 | - ); |
|
| 108 | + return array( |
|
| 109 | + 'data' => $data, |
|
| 110 | + 'backgroundColor' => $colors, |
|
| 111 | + ); |
|
| 112 | 112 | |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Retrieves report labels. |
|
| 117 | - * |
|
| 118 | - */ |
|
| 119 | - public function get_labels() { |
|
| 120 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
| 121 | - } |
|
| 115 | + /** |
|
| 116 | + * Retrieves report labels. |
|
| 117 | + * |
|
| 118 | + */ |
|
| 119 | + public function get_labels() { |
|
| 120 | + return wp_list_pluck( $this->stats, 'discount_code' ); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Displays the actual report. |
|
| 125 | - * |
|
| 126 | - */ |
|
| 127 | - public function display_stats() { |
|
| 128 | - ?> |
|
| 123 | + /** |
|
| 124 | + * Displays the actual report. |
|
| 125 | + * |
|
| 126 | + */ |
|
| 127 | + public function display_stats() { |
|
| 128 | + ?> |
|
| 129 | 129 | |
| 130 | 130 | <canvas id="getpaid-chartjs-earnings-discount_code"></canvas> |
| 131 | 131 | |
@@ -154,6 +154,6 @@ discard block |
||
| 154 | 154 | </script> |
| 155 | 155 | |
| 156 | 156 | <?php |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | } |
@@ -12,23 +12,23 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Items extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $field = 'item_name'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Retrieves the earning sql. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function get_sql( $range ) { |
|
| 25 | - global $wpdb; |
|
| 26 | - |
|
| 27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | - $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 29 | - $clauses = $this->get_range_sql( $range ); |
|
| 30 | - |
|
| 31 | - $sql = "SELECT |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $field = 'item_name'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Retrieves the earning sql. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function get_sql( $range ) { |
|
| 25 | + global $wpdb; |
|
| 26 | + |
|
| 27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | + $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 29 | + $clauses = $this->get_range_sql( $range ); |
|
| 30 | + |
|
| 31 | + $sql = "SELECT |
|
| 32 | 32 | item.item_name AS item_name, |
| 33 | 33 | item.item_id AS item_id, |
| 34 | 34 | SUM(price) as total |
@@ -43,91 +43,91 @@ discard block |
||
| 43 | 43 | ORDER BY total DESC |
| 44 | 44 | "; |
| 45 | 45 | |
| 46 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 46 | + return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 47 | 47 | |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Prepares the report stats. |
|
| 52 | - * |
|
| 53 | - */ |
|
| 54 | - public function prepare_stats() { |
|
| 55 | - global $wpdb; |
|
| 56 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 58 | - } |
|
| 50 | + /** |
|
| 51 | + * Prepares the report stats. |
|
| 52 | + * |
|
| 53 | + */ |
|
| 54 | + public function prepare_stats() { |
|
| 55 | + global $wpdb; |
|
| 56 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Normalizes the report stats. |
|
| 62 | - * |
|
| 63 | - */ |
|
| 64 | - public function normalize_stats( $stats ) { |
|
| 65 | - $normalized = array(); |
|
| 66 | - $others = 0; |
|
| 67 | - $did = 0; |
|
| 60 | + /** |
|
| 61 | + * Normalizes the report stats. |
|
| 62 | + * |
|
| 63 | + */ |
|
| 64 | + public function normalize_stats( $stats ) { |
|
| 65 | + $normalized = array(); |
|
| 66 | + $others = 0; |
|
| 67 | + $did = 0; |
|
| 68 | 68 | |
| 69 | - foreach ( $stats as $stat ) { |
|
| 69 | + foreach ( $stats as $stat ) { |
|
| 70 | 70 | |
| 71 | - if ( $did > 4 ) { |
|
| 71 | + if ( $did > 4 ) { |
|
| 72 | 72 | |
| 73 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 73 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 74 | 74 | |
| 75 | - } else { |
|
| 75 | + } else { |
|
| 76 | 76 | |
| 77 | - $normalized[] = array( |
|
| 78 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | - 'item_name' => strip_tags( $stat->item_name ), |
|
| 80 | - ); |
|
| 77 | + $normalized[] = array( |
|
| 78 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | + 'item_name' => strip_tags( $stat->item_name ), |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $did++; |
|
| 85 | - } |
|
| 84 | + $did++; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - if ( $others > 0 ) { |
|
| 87 | + if ( $others > 0 ) { |
|
| 88 | 88 | |
| 89 | - $normalized[] = array( |
|
| 90 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 92 | - ); |
|
| 89 | + $normalized[] = array( |
|
| 90 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | + 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - return $normalized; |
|
| 97 | - } |
|
| 96 | + return $normalized; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Retrieves report data. |
|
| 101 | - * |
|
| 102 | - */ |
|
| 103 | - public function get_data() { |
|
| 99 | + /** |
|
| 100 | + * Retrieves report data. |
|
| 101 | + * |
|
| 102 | + */ |
|
| 103 | + public function get_data() { |
|
| 104 | 104 | |
| 105 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 105 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 107 | 107 | |
| 108 | - shuffle( $colors ); |
|
| 108 | + shuffle( $colors ); |
|
| 109 | 109 | |
| 110 | - return array( |
|
| 111 | - 'data' => $data, |
|
| 112 | - 'backgroundColor' => $colors, |
|
| 113 | - ); |
|
| 110 | + return array( |
|
| 111 | + 'data' => $data, |
|
| 112 | + 'backgroundColor' => $colors, |
|
| 113 | + ); |
|
| 114 | 114 | |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Retrieves report labels. |
|
| 119 | - * |
|
| 120 | - */ |
|
| 121 | - public function get_labels() { |
|
| 122 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 123 | - } |
|
| 117 | + /** |
|
| 118 | + * Retrieves report labels. |
|
| 119 | + * |
|
| 120 | + */ |
|
| 121 | + public function get_labels() { |
|
| 122 | + return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Displays the actual report. |
|
| 127 | - * |
|
| 128 | - */ |
|
| 129 | - public function display_stats() { |
|
| 130 | - ?> |
|
| 125 | + /** |
|
| 126 | + * Displays the actual report. |
|
| 127 | + * |
|
| 128 | + */ |
|
| 129 | + public function display_stats() { |
|
| 130 | + ?> |
|
| 131 | 131 | |
| 132 | 132 | <canvas id="getpaid-chartjs-earnings-items"></canvas> |
| 133 | 133 | |
@@ -156,6 +156,6 @@ discard block |
||
| 156 | 156 | </script> |
| 157 | 157 | |
| 158 | 158 | <?php |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | 161 | } |
@@ -12,218 +12,218 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Graph_Downloader { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Reports_Report |
|
| 17 | - */ |
|
| 18 | - public $handler; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - $this->handler = new GetPaid_Reports_Report(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Prepares the datastore handler. |
|
| 30 | - * |
|
| 31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
| 32 | - */ |
|
| 33 | - public function prepare_handler( $graph ) { |
|
| 34 | - |
|
| 35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | - wp_die( __( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return new $this->handler->views[ $graph ]['class'](); |
|
| 40 | - |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Prepares the output stream. |
|
| 45 | - * |
|
| 46 | - * @return resource |
|
| 47 | - */ |
|
| 48 | - public function prepare_output() { |
|
| 49 | - |
|
| 50 | - $output = fopen( 'php://output', 'w' ); |
|
| 51 | - |
|
| 52 | - if ( false === $output ) { |
|
| 53 | - wp_die( __( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $output; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Prepares the file type. |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function prepare_file_type( $graph ) { |
|
| 65 | - |
|
| 66 | - $file_type = empty( $_GET['file_type'] ) ? 'csv' : sanitize_text_field( $_GET['file_type'] ); |
|
| 67 | - $file_name = "getpaid-$graph-" . current_time( 'Y-m-d' ); |
|
| 68 | - |
|
| 69 | - header( "Content-Type:application/$file_type" ); |
|
| 70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 71 | - |
|
| 72 | - return $file_type; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Handles the actual download. |
|
| 77 | - * |
|
| 78 | - */ |
|
| 79 | - public function download( $graph ) { |
|
| 80 | - global $wpdb; |
|
| 81 | - |
|
| 82 | - $handler = $this->prepare_handler( $graph ); |
|
| 83 | - $stream = $this->prepare_output(); |
|
| 84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | - $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | - |
|
| 88 | - if ( 'csv' == $file_type ) { |
|
| 89 | - $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | - } else if( 'xml' == $file_type ) { |
|
| 91 | - $this->download_xml( $stats, $stream, $headers ); |
|
| 92 | - } else { |
|
| 93 | - $this->download_json( $stats, $stream, $headers ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - fclose( $stream ); |
|
| 97 | - exit; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Downloads graph as csv |
|
| 102 | - * |
|
| 103 | - * @param array $stats The stats being downloaded. |
|
| 104 | - * @param resource $stream The stream to output to. |
|
| 105 | - * @param array $headers The fields to stream. |
|
| 106 | - * @since 1.0.19 |
|
| 107 | - */ |
|
| 108 | - public function download_csv( $stats, $stream, $headers ) { |
|
| 109 | - |
|
| 110 | - // Output the csv column headers. |
|
| 111 | - fputcsv( $stream, $headers ); |
|
| 112 | - |
|
| 113 | - // Loop through |
|
| 114 | - foreach ( $stats as $stat ) { |
|
| 115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | - fputcsv( $stream, $row ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Downloads graph as json |
|
| 123 | - * |
|
| 124 | - * @param array $stats The stats being downloaded. |
|
| 125 | - * @param resource $stream The stream to output to. |
|
| 126 | - * @param array $headers The fields to stream. |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - */ |
|
| 129 | - public function download_json( $stats, $stream, $headers ) { |
|
| 130 | - |
|
| 131 | - $prepared = array(); |
|
| 132 | - |
|
| 133 | - // Loop through |
|
| 134 | - foreach ( $stats as $stat ) { |
|
| 135 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 139 | - |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Downloads graph as xml |
|
| 144 | - * |
|
| 145 | - * @param array $stats The stats being downloaded. |
|
| 146 | - * @param resource $stream The stream to output to. |
|
| 147 | - * @param array $headers The fields to stream. |
|
| 148 | - * @since 1.0.19 |
|
| 149 | - */ |
|
| 150 | - public function download_xml( $stats, $stream, $headers ) { |
|
| 151 | - |
|
| 152 | - $prepared = array(); |
|
| 153 | - |
|
| 154 | - // Loop through |
|
| 155 | - foreach ( $stats as $stat ) { |
|
| 156 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
| 160 | - $this->convert_array_xml( $prepared, $xml ); |
|
| 161 | - |
|
| 162 | - fwrite( $stream, $xml->asXML() ); |
|
| 163 | - |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Converts stats array to xml |
|
| 168 | - * |
|
| 169 | - * @access public |
|
| 170 | - * @since 1.0.19 |
|
| 171 | - */ |
|
| 172 | - public function convert_array_xml( $data, $xml ) { |
|
| 173 | - |
|
| 174 | - // Loop through |
|
| 175 | - foreach ( $data as $key => $value ) { |
|
| 176 | - |
|
| 177 | - $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key ); |
|
| 178 | - |
|
| 179 | - if ( is_array( $value ) ) { |
|
| 180 | - |
|
| 181 | - if ( is_numeric( $key ) ){ |
|
| 182 | - $key = 'item'.$key; //dealing with <0/>..<n/> issues |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $subnode = $xml->addChild( $key ); |
|
| 186 | - $this->convert_array_xml( $value, $subnode ); |
|
| 187 | - |
|
| 188 | - } else { |
|
| 189 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - } |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Reports_Report |
|
| 17 | + */ |
|
| 18 | + public $handler; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + $this->handler = new GetPaid_Reports_Report(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Prepares the datastore handler. |
|
| 30 | + * |
|
| 31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
| 32 | + */ |
|
| 33 | + public function prepare_handler( $graph ) { |
|
| 34 | + |
|
| 35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | + wp_die( __( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return new $this->handler->views[ $graph ]['class'](); |
|
| 40 | + |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Prepares the output stream. |
|
| 45 | + * |
|
| 46 | + * @return resource |
|
| 47 | + */ |
|
| 48 | + public function prepare_output() { |
|
| 49 | + |
|
| 50 | + $output = fopen( 'php://output', 'w' ); |
|
| 51 | + |
|
| 52 | + if ( false === $output ) { |
|
| 53 | + wp_die( __( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $output; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Prepares the file type. |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function prepare_file_type( $graph ) { |
|
| 65 | + |
|
| 66 | + $file_type = empty( $_GET['file_type'] ) ? 'csv' : sanitize_text_field( $_GET['file_type'] ); |
|
| 67 | + $file_name = "getpaid-$graph-" . current_time( 'Y-m-d' ); |
|
| 68 | + |
|
| 69 | + header( "Content-Type:application/$file_type" ); |
|
| 70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 71 | + |
|
| 72 | + return $file_type; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Handles the actual download. |
|
| 77 | + * |
|
| 78 | + */ |
|
| 79 | + public function download( $graph ) { |
|
| 80 | + global $wpdb; |
|
| 81 | + |
|
| 82 | + $handler = $this->prepare_handler( $graph ); |
|
| 83 | + $stream = $this->prepare_output(); |
|
| 84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | + $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | + |
|
| 88 | + if ( 'csv' == $file_type ) { |
|
| 89 | + $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | + } else if( 'xml' == $file_type ) { |
|
| 91 | + $this->download_xml( $stats, $stream, $headers ); |
|
| 92 | + } else { |
|
| 93 | + $this->download_json( $stats, $stream, $headers ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + fclose( $stream ); |
|
| 97 | + exit; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Downloads graph as csv |
|
| 102 | + * |
|
| 103 | + * @param array $stats The stats being downloaded. |
|
| 104 | + * @param resource $stream The stream to output to. |
|
| 105 | + * @param array $headers The fields to stream. |
|
| 106 | + * @since 1.0.19 |
|
| 107 | + */ |
|
| 108 | + public function download_csv( $stats, $stream, $headers ) { |
|
| 109 | + |
|
| 110 | + // Output the csv column headers. |
|
| 111 | + fputcsv( $stream, $headers ); |
|
| 112 | + |
|
| 113 | + // Loop through |
|
| 114 | + foreach ( $stats as $stat ) { |
|
| 115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | + fputcsv( $stream, $row ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Downloads graph as json |
|
| 123 | + * |
|
| 124 | + * @param array $stats The stats being downloaded. |
|
| 125 | + * @param resource $stream The stream to output to. |
|
| 126 | + * @param array $headers The fields to stream. |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + */ |
|
| 129 | + public function download_json( $stats, $stream, $headers ) { |
|
| 130 | + |
|
| 131 | + $prepared = array(); |
|
| 132 | + |
|
| 133 | + // Loop through |
|
| 134 | + foreach ( $stats as $stat ) { |
|
| 135 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Downloads graph as xml |
|
| 144 | + * |
|
| 145 | + * @param array $stats The stats being downloaded. |
|
| 146 | + * @param resource $stream The stream to output to. |
|
| 147 | + * @param array $headers The fields to stream. |
|
| 148 | + * @since 1.0.19 |
|
| 149 | + */ |
|
| 150 | + public function download_xml( $stats, $stream, $headers ) { |
|
| 151 | + |
|
| 152 | + $prepared = array(); |
|
| 153 | + |
|
| 154 | + // Loop through |
|
| 155 | + foreach ( $stats as $stat ) { |
|
| 156 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
| 160 | + $this->convert_array_xml( $prepared, $xml ); |
|
| 161 | + |
|
| 162 | + fwrite( $stream, $xml->asXML() ); |
|
| 163 | + |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Converts stats array to xml |
|
| 168 | + * |
|
| 169 | + * @access public |
|
| 170 | + * @since 1.0.19 |
|
| 171 | + */ |
|
| 172 | + public function convert_array_xml( $data, $xml ) { |
|
| 173 | + |
|
| 174 | + // Loop through |
|
| 175 | + foreach ( $data as $key => $value ) { |
|
| 176 | + |
|
| 177 | + $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key ); |
|
| 178 | + |
|
| 179 | + if ( is_array( $value ) ) { |
|
| 180 | + |
|
| 181 | + if ( is_numeric( $key ) ){ |
|
| 182 | + $key = 'item'.$key; //dealing with <0/>..<n/> issues |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $subnode = $xml->addChild( $key ); |
|
| 186 | + $this->convert_array_xml( $value, $subnode ); |
|
| 187 | + |
|
| 188 | + } else { |
|
| 189 | + $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Prepares a single row for download. |
|
| 198 | - * |
|
| 199 | - * @param stdClass|array $row The row to prepare.. |
|
| 200 | - * @param array $fields The fields to stream. |
|
| 201 | - * @since 1.0.19 |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function prepare_row( $row, $fields ) { |
|
| 196 | + /** |
|
| 197 | + * Prepares a single row for download. |
|
| 198 | + * |
|
| 199 | + * @param stdClass|array $row The row to prepare.. |
|
| 200 | + * @param array $fields The fields to stream. |
|
| 201 | + * @since 1.0.19 |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function prepare_row( $row, $fields ) { |
|
| 205 | 205 | |
| 206 | - $prepared = array(); |
|
| 207 | - $row = (array) $row; |
|
| 206 | + $prepared = array(); |
|
| 207 | + $row = (array) $row; |
|
| 208 | 208 | |
| 209 | - foreach ( $fields as $field ) { |
|
| 209 | + foreach ( $fields as $field ) { |
|
| 210 | 210 | |
| 211 | - if ( $field === 'total' ) { |
|
| 212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 213 | - continue; |
|
| 214 | - } |
|
| 211 | + if ( $field === 'total' ) { |
|
| 212 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 213 | + continue; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - if ( $field === 'total_raw' ) { |
|
| 217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 218 | - continue; |
|
| 219 | - } |
|
| 216 | + if ( $field === 'total_raw' ) { |
|
| 217 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 221 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - return $prepared; |
|
| 226 | - } |
|
| 225 | + return $prepared; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
| 32 | 32 | */ |
| 33 | - public function prepare_handler( $graph ) { |
|
| 33 | + public function prepare_handler($graph) { |
|
| 34 | 34 | |
| 35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | - wp_die( __( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 35 | + if (empty($this->handler->views[$graph])) { |
|
| 36 | + wp_die(__('Invalid Graph', 'invoicing'), 400); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - return new $this->handler->views[ $graph ]['class'](); |
|
| 39 | + return new $this->handler->views[$graph]['class'](); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function prepare_output() { |
| 49 | 49 | |
| 50 | - $output = fopen( 'php://output', 'w' ); |
|
| 50 | + $output = fopen('php://output', 'w'); |
|
| 51 | 51 | |
| 52 | - if ( false === $output ) { |
|
| 53 | - wp_die( __( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 52 | + if (false === $output) { |
|
| 53 | + wp_die(__('Unsupported server', 'invoicing'), 500); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - public function prepare_file_type( $graph ) { |
|
| 64 | + public function prepare_file_type($graph) { |
|
| 65 | 65 | |
| 66 | - $file_type = empty( $_GET['file_type'] ) ? 'csv' : sanitize_text_field( $_GET['file_type'] ); |
|
| 67 | - $file_name = "getpaid-$graph-" . current_time( 'Y-m-d' ); |
|
| 66 | + $file_type = empty($_GET['file_type']) ? 'csv' : sanitize_text_field($_GET['file_type']); |
|
| 67 | + $file_name = "getpaid-$graph-" . current_time('Y-m-d'); |
|
| 68 | 68 | |
| 69 | - header( "Content-Type:application/$file_type" ); |
|
| 70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 69 | + header("Content-Type:application/$file_type"); |
|
| 70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
| 71 | 71 | |
| 72 | 72 | return $file_type; |
| 73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
| 76 | 76 | * Handles the actual download. |
| 77 | 77 | * |
| 78 | 78 | */ |
| 79 | - public function download( $graph ) { |
|
| 79 | + public function download($graph) { |
|
| 80 | 80 | global $wpdb; |
| 81 | 81 | |
| 82 | - $handler = $this->prepare_handler( $graph ); |
|
| 82 | + $handler = $this->prepare_handler($graph); |
|
| 83 | 83 | $stream = $this->prepare_output(); |
| 84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | - $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | - |
|
| 88 | - if ( 'csv' == $file_type ) { |
|
| 89 | - $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | - } else if( 'xml' == $file_type ) { |
|
| 91 | - $this->download_xml( $stats, $stream, $headers ); |
|
| 84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
| 85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
| 86 | + $file_type = $this->prepare_file_type($graph); |
|
| 87 | + |
|
| 88 | + if ('csv' == $file_type) { |
|
| 89 | + $this->download_csv($stats, $stream, $headers); |
|
| 90 | + } else if ('xml' == $file_type) { |
|
| 91 | + $this->download_xml($stats, $stream, $headers); |
|
| 92 | 92 | } else { |
| 93 | - $this->download_json( $stats, $stream, $headers ); |
|
| 93 | + $this->download_json($stats, $stream, $headers); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - fclose( $stream ); |
|
| 96 | + fclose($stream); |
|
| 97 | 97 | exit; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -105,15 +105,15 @@ discard block |
||
| 105 | 105 | * @param array $headers The fields to stream. |
| 106 | 106 | * @since 1.0.19 |
| 107 | 107 | */ |
| 108 | - public function download_csv( $stats, $stream, $headers ) { |
|
| 108 | + public function download_csv($stats, $stream, $headers) { |
|
| 109 | 109 | |
| 110 | 110 | // Output the csv column headers. |
| 111 | - fputcsv( $stream, $headers ); |
|
| 111 | + fputcsv($stream, $headers); |
|
| 112 | 112 | |
| 113 | 113 | // Loop through |
| 114 | - foreach ( $stats as $stat ) { |
|
| 115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | - fputcsv( $stream, $row ); |
|
| 114 | + foreach ($stats as $stat) { |
|
| 115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
| 116 | + fputcsv($stream, $row); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | } |
@@ -126,16 +126,16 @@ discard block |
||
| 126 | 126 | * @param array $headers The fields to stream. |
| 127 | 127 | * @since 1.0.19 |
| 128 | 128 | */ |
| 129 | - public function download_json( $stats, $stream, $headers ) { |
|
| 129 | + public function download_json($stats, $stream, $headers) { |
|
| 130 | 130 | |
| 131 | 131 | $prepared = array(); |
| 132 | 132 | |
| 133 | 133 | // Loop through |
| 134 | - foreach ( $stats as $stat ) { |
|
| 135 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 134 | + foreach ($stats as $stat) { |
|
| 135 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 138 | + fwrite($stream, wp_json_encode($prepared)); |
|
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | |
@@ -147,19 +147,19 @@ discard block |
||
| 147 | 147 | * @param array $headers The fields to stream. |
| 148 | 148 | * @since 1.0.19 |
| 149 | 149 | */ |
| 150 | - public function download_xml( $stats, $stream, $headers ) { |
|
| 150 | + public function download_xml($stats, $stream, $headers) { |
|
| 151 | 151 | |
| 152 | 152 | $prepared = array(); |
| 153 | 153 | |
| 154 | 154 | // Loop through |
| 155 | - foreach ( $stats as $stat ) { |
|
| 156 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 155 | + foreach ($stats as $stat) { |
|
| 156 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
| 160 | - $this->convert_array_xml( $prepared, $xml ); |
|
| 160 | + $this->convert_array_xml($prepared, $xml); |
|
| 161 | 161 | |
| 162 | - fwrite( $stream, $xml->asXML() ); |
|
| 162 | + fwrite($stream, $xml->asXML()); |
|
| 163 | 163 | |
| 164 | 164 | } |
| 165 | 165 | |
@@ -169,24 +169,24 @@ discard block |
||
| 169 | 169 | * @access public |
| 170 | 170 | * @since 1.0.19 |
| 171 | 171 | */ |
| 172 | - public function convert_array_xml( $data, $xml ) { |
|
| 172 | + public function convert_array_xml($data, $xml) { |
|
| 173 | 173 | |
| 174 | 174 | // Loop through |
| 175 | - foreach ( $data as $key => $value ) { |
|
| 175 | + foreach ($data as $key => $value) { |
|
| 176 | 176 | |
| 177 | - $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key ); |
|
| 177 | + $key = preg_replace("/[^A-Za-z0-9_\-]/", '', $key); |
|
| 178 | 178 | |
| 179 | - if ( is_array( $value ) ) { |
|
| 179 | + if (is_array($value)) { |
|
| 180 | 180 | |
| 181 | - if ( is_numeric( $key ) ){ |
|
| 182 | - $key = 'item'.$key; //dealing with <0/>..<n/> issues |
|
| 181 | + if (is_numeric($key)) { |
|
| 182 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - $subnode = $xml->addChild( $key ); |
|
| 186 | - $this->convert_array_xml( $value, $subnode ); |
|
| 185 | + $subnode = $xml->addChild($key); |
|
| 186 | + $this->convert_array_xml($value, $subnode); |
|
| 187 | 187 | |
| 188 | 188 | } else { |
| 189 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 189 | + $xml->addChild($key, htmlspecialchars($value)); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | } |
@@ -201,24 +201,24 @@ discard block |
||
| 201 | 201 | * @since 1.0.19 |
| 202 | 202 | * @return array |
| 203 | 203 | */ |
| 204 | - public function prepare_row( $row, $fields ) { |
|
| 204 | + public function prepare_row($row, $fields) { |
|
| 205 | 205 | |
| 206 | 206 | $prepared = array(); |
| 207 | 207 | $row = (array) $row; |
| 208 | 208 | |
| 209 | - foreach ( $fields as $field ) { |
|
| 209 | + foreach ($fields as $field) { |
|
| 210 | 210 | |
| 211 | - if ( $field === 'total' ) { |
|
| 212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 211 | + if ($field === 'total') { |
|
| 212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
| 213 | 213 | continue; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if ( $field === 'total_raw' ) { |
|
| 217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 216 | + if ($field === 'total_raw') { |
|
| 217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
| 218 | 218 | continue; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 221 | + $prepared[$field] = strip_tags($row[$field]); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -12,47 +12,47 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function __construct() { |
|
| 20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
| 21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
| 22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
| 23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Registers the reports page. |
|
| 28 | - * |
|
| 29 | - */ |
|
| 30 | - public function register_reports_page() { |
|
| 31 | - |
|
| 32 | - add_submenu_page( |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function __construct() { |
|
| 20 | + add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
| 21 | + add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
| 22 | + add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
| 23 | + add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Registers the reports page. |
|
| 28 | + * |
|
| 29 | + */ |
|
| 30 | + public function register_reports_page() { |
|
| 31 | + |
|
| 32 | + add_submenu_page( |
|
| 33 | 33 | 'wpinv', |
| 34 | 34 | __( 'Reports', 'invoicing' ), |
| 35 | 35 | __( 'Reports', 'invoicing' ), |
| 36 | 36 | wpinv_get_capability(), |
| 37 | 37 | 'wpinv-reports', |
| 38 | 38 | array( $this, 'display_reports_page' ) |
| 39 | - ); |
|
| 39 | + ); |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Displays the reports page. |
|
| 45 | - * |
|
| 46 | - */ |
|
| 47 | - public function display_reports_page() { |
|
| 43 | + /** |
|
| 44 | + * Displays the reports page. |
|
| 45 | + * |
|
| 46 | + */ |
|
| 47 | + public function display_reports_page() { |
|
| 48 | 48 | |
| 49 | - // Prepare variables. |
|
| 50 | - $tabs = $this->get_tabs(); |
|
| 51 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
| 52 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
| 49 | + // Prepare variables. |
|
| 50 | + $tabs = $this->get_tabs(); |
|
| 51 | + $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
| 52 | + $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
| 53 | 53 | |
| 54 | - // Display the current tab. |
|
| 55 | - ?> |
|
| 54 | + // Display the current tab. |
|
| 55 | + ?> |
|
| 56 | 56 | |
| 57 | 57 | <div class="wrap"> |
| 58 | 58 | |
@@ -61,19 +61,19 @@ discard block |
||
| 61 | 61 | <nav class="nav-tab-wrapper"> |
| 62 | 62 | |
| 63 | 63 | <?php |
| 64 | - foreach( $tabs as $key => $label ) { |
|
| 64 | + foreach( $tabs as $key => $label ) { |
|
| 65 | 65 | |
| 66 | - $key = sanitize_text_field( $key ); |
|
| 67 | - $label = sanitize_text_field( $label ); |
|
| 68 | - $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
| 69 | - $url = esc_url( |
|
| 70 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
| 71 | - ); |
|
| 66 | + $key = sanitize_text_field( $key ); |
|
| 67 | + $label = sanitize_text_field( $label ); |
|
| 68 | + $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
| 69 | + $url = esc_url( |
|
| 70 | + add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
| 71 | + ); |
|
| 72 | 72 | |
| 73 | - echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
| 73 | + echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
| 74 | 74 | |
| 75 | - } |
|
| 76 | - ?> |
|
| 75 | + } |
|
| 76 | + ?> |
|
| 77 | 77 | |
| 78 | 78 | </nav> |
| 79 | 79 | |
@@ -84,60 +84,60 @@ discard block |
||
| 84 | 84 | </div> |
| 85 | 85 | <?php |
| 86 | 86 | |
| 87 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
| 88 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
| 87 | + wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
| 88 | + wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
| 89 | 89 | |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Retrieves reports page tabs. |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function get_tabs() { |
|
| 92 | + /** |
|
| 93 | + * Retrieves reports page tabs. |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function get_tabs() { |
|
| 98 | 98 | |
| 99 | - $tabs = array( |
|
| 100 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
| 101 | - 'export' => __( 'Export', 'invoicing' ), |
|
| 102 | - ); |
|
| 99 | + $tabs = array( |
|
| 100 | + 'reports' => __( 'Reports', 'invoicing' ), |
|
| 101 | + 'export' => __( 'Export', 'invoicing' ), |
|
| 102 | + ); |
|
| 103 | 103 | |
| 104 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
| 105 | - } |
|
| 104 | + return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Displays the reports tab. |
|
| 109 | - * |
|
| 110 | - */ |
|
| 111 | - public function display_reports_tab() { |
|
| 107 | + /** |
|
| 108 | + * Displays the reports tab. |
|
| 109 | + * |
|
| 110 | + */ |
|
| 111 | + public function display_reports_tab() { |
|
| 112 | 112 | |
| 113 | - $reports = new GetPaid_Reports_Report(); |
|
| 114 | - $reports->display(); |
|
| 113 | + $reports = new GetPaid_Reports_Report(); |
|
| 114 | + $reports->display(); |
|
| 115 | 115 | |
| 116 | - } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Displays the exports tab. |
|
| 120 | - * |
|
| 121 | - */ |
|
| 122 | - public function display_exports_tab() { |
|
| 118 | + /** |
|
| 119 | + * Displays the exports tab. |
|
| 120 | + * |
|
| 121 | + */ |
|
| 122 | + public function display_exports_tab() { |
|
| 123 | 123 | |
| 124 | - $exports = new GetPaid_Reports_Export(); |
|
| 125 | - $exports->display(); |
|
| 124 | + $exports = new GetPaid_Reports_Export(); |
|
| 125 | + $exports->display(); |
|
| 126 | 126 | |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Donwnloads a graph. |
|
| 131 | - * |
|
| 132 | - * @param array $args |
|
| 133 | - */ |
|
| 134 | - public function download_graph( $args ) { |
|
| 129 | + /** |
|
| 130 | + * Donwnloads a graph. |
|
| 131 | + * |
|
| 132 | + * @param array $args |
|
| 133 | + */ |
|
| 134 | + public function download_graph( $args ) { |
|
| 135 | 135 | |
| 136 | - if ( ! empty( $args['graph'] ) ) { |
|
| 137 | - $downloader = new GetPaid_Graph_Downloader(); |
|
| 138 | - $downloader->download( $args['graph'] ); |
|
| 139 | - } |
|
| 136 | + if ( ! empty( $args['graph'] ) ) { |
|
| 137 | + $downloader = new GetPaid_Graph_Downloader(); |
|
| 138 | + $downloader->download( $args['graph'] ); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports Class. |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | */ |
| 19 | 19 | public function __construct() { |
| 20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
| 21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
| 22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
| 23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
| 20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
| 21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
| 22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
| 23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | add_submenu_page( |
| 33 | 33 | 'wpinv', |
| 34 | - __( 'Reports', 'invoicing' ), |
|
| 35 | - __( 'Reports', 'invoicing' ), |
|
| 34 | + __('Reports', 'invoicing'), |
|
| 35 | + __('Reports', 'invoicing'), |
|
| 36 | 36 | wpinv_get_capability(), |
| 37 | 37 | 'wpinv-reports', |
| 38 | - array( $this, 'display_reports_page' ) |
|
| 38 | + array($this, 'display_reports_page') |
|
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | 41 | } |
@@ -48,26 +48,26 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | // Prepare variables. |
| 50 | 50 | $tabs = $this->get_tabs(); |
| 51 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
| 52 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
| 51 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
| 52 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
| 53 | 53 | |
| 54 | 54 | // Display the current tab. |
| 55 | 55 | ?> |
| 56 | 56 | |
| 57 | 57 | <div class="wrap"> |
| 58 | 58 | |
| 59 | - <h1><?php echo sanitize_text_field( $tabs[ $current_tab ] ); ?></h1> |
|
| 59 | + <h1><?php echo sanitize_text_field($tabs[$current_tab]); ?></h1> |
|
| 60 | 60 | |
| 61 | 61 | <nav class="nav-tab-wrapper"> |
| 62 | 62 | |
| 63 | 63 | <?php |
| 64 | - foreach( $tabs as $key => $label ) { |
|
| 64 | + foreach ($tabs as $key => $label) { |
|
| 65 | 65 | |
| 66 | - $key = sanitize_text_field( $key ); |
|
| 67 | - $label = sanitize_text_field( $label ); |
|
| 66 | + $key = sanitize_text_field($key); |
|
| 67 | + $label = sanitize_text_field($label); |
|
| 68 | 68 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
| 69 | 69 | $url = esc_url( |
| 70 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
| 70 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
| 71 | 71 | ); |
| 72 | 72 | |
| 73 | 73 | echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
@@ -77,15 +77,15 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | </nav> |
| 79 | 79 | |
| 80 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
| 81 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
| 80 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
| 81 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
| 82 | 82 | </div> |
| 83 | 83 | |
| 84 | 84 | </div> |
| 85 | 85 | <?php |
| 86 | 86 | |
| 87 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
| 88 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
| 87 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array('jquery'), '2.9.4', true); |
|
| 88 | + wp_enqueue_style('chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4'); |
|
| 89 | 89 | |
| 90 | 90 | } |
| 91 | 91 | |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | public function get_tabs() { |
| 98 | 98 | |
| 99 | 99 | $tabs = array( |
| 100 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
| 101 | - 'export' => __( 'Export', 'invoicing' ), |
|
| 100 | + 'reports' => __('Reports', 'invoicing'), |
|
| 101 | + 'export' => __('Export', 'invoicing'), |
|
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
| 104 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @param array $args |
| 133 | 133 | */ |
| 134 | - public function download_graph( $args ) { |
|
| 134 | + public function download_graph($args) { |
|
| 135 | 135 | |
| 136 | - if ( ! empty( $args['graph'] ) ) { |
|
| 136 | + if (!empty($args['graph'])) { |
|
| 137 | 137 | $downloader = new GetPaid_Graph_Downloader(); |
| 138 | - $downloader->download( $args['graph'] ); |
|
| 138 | + $downloader->download($args['graph']); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | } |
@@ -12,22 +12,22 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Gateways extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $field = 'gateway'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Retrieves the earning sql. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function get_sql( $range ) { |
|
| 25 | - global $wpdb; |
|
| 26 | - |
|
| 27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | - $clauses = $this->get_range_sql( $range ); |
|
| 29 | - |
|
| 30 | - $sql = "SELECT |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $field = 'gateway'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Retrieves the earning sql. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function get_sql( $range ) { |
|
| 25 | + global $wpdb; |
|
| 26 | + |
|
| 27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | + $clauses = $this->get_range_sql( $range ); |
|
| 29 | + |
|
| 30 | + $sql = "SELECT |
|
| 31 | 31 | meta.gateway AS gateway, |
| 32 | 32 | SUM(total) as total |
| 33 | 33 | FROM $wpdb->posts |
@@ -40,91 +40,91 @@ discard block |
||
| 40 | 40 | ORDER BY total DESC |
| 41 | 41 | "; |
| 42 | 42 | |
| 43 | - return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
| 43 | + return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
| 44 | 44 | |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Prepares the report stats. |
|
| 49 | - * |
|
| 50 | - */ |
|
| 51 | - public function prepare_stats() { |
|
| 52 | - global $wpdb; |
|
| 53 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 54 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Prepares the report stats. |
|
| 49 | + * |
|
| 50 | + */ |
|
| 51 | + public function prepare_stats() { |
|
| 52 | + global $wpdb; |
|
| 53 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 54 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Normalizes the report stats. |
|
| 59 | - * |
|
| 60 | - */ |
|
| 61 | - public function normalize_stats( $stats ) { |
|
| 62 | - $normalized = array(); |
|
| 63 | - $others = 0; |
|
| 64 | - $did = 0; |
|
| 57 | + /** |
|
| 58 | + * Normalizes the report stats. |
|
| 59 | + * |
|
| 60 | + */ |
|
| 61 | + public function normalize_stats( $stats ) { |
|
| 62 | + $normalized = array(); |
|
| 63 | + $others = 0; |
|
| 64 | + $did = 0; |
|
| 65 | 65 | |
| 66 | - foreach ( $stats as $stat ) { |
|
| 66 | + foreach ( $stats as $stat ) { |
|
| 67 | 67 | |
| 68 | - if ( $did > 4 ) { |
|
| 68 | + if ( $did > 4 ) { |
|
| 69 | 69 | |
| 70 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 70 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 71 | 71 | |
| 72 | - } else { |
|
| 72 | + } else { |
|
| 73 | 73 | |
| 74 | - $normalized[] = array( |
|
| 75 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 76 | - 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
| 77 | - ); |
|
| 74 | + $normalized[] = array( |
|
| 75 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 76 | + 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $did++; |
|
| 82 | - } |
|
| 81 | + $did++; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if ( $others > 0 ) { |
|
| 84 | + if ( $others > 0 ) { |
|
| 85 | 85 | |
| 86 | - $normalized[] = array( |
|
| 87 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 88 | - 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
| 89 | - ); |
|
| 86 | + $normalized[] = array( |
|
| 87 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 88 | + 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return $normalized; |
|
| 94 | - } |
|
| 93 | + return $normalized; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Retrieves report data. |
|
| 98 | - * |
|
| 99 | - */ |
|
| 100 | - public function get_data() { |
|
| 96 | + /** |
|
| 97 | + * Retrieves report data. |
|
| 98 | + * |
|
| 99 | + */ |
|
| 100 | + public function get_data() { |
|
| 101 | 101 | |
| 102 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 103 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 102 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 103 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 104 | 104 | |
| 105 | - shuffle( $colors ); |
|
| 105 | + shuffle( $colors ); |
|
| 106 | 106 | |
| 107 | - return array( |
|
| 108 | - 'data' => $data, |
|
| 109 | - 'backgroundColor' => $colors, |
|
| 110 | - ); |
|
| 107 | + return array( |
|
| 108 | + 'data' => $data, |
|
| 109 | + 'backgroundColor' => $colors, |
|
| 110 | + ); |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Retrieves report labels. |
|
| 116 | - * |
|
| 117 | - */ |
|
| 118 | - public function get_labels() { |
|
| 119 | - return wp_list_pluck( $this->stats, 'gateway' ); |
|
| 120 | - } |
|
| 114 | + /** |
|
| 115 | + * Retrieves report labels. |
|
| 116 | + * |
|
| 117 | + */ |
|
| 118 | + public function get_labels() { |
|
| 119 | + return wp_list_pluck( $this->stats, 'gateway' ); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Displays the actual report. |
|
| 124 | - * |
|
| 125 | - */ |
|
| 126 | - public function display_stats() { |
|
| 127 | - ?> |
|
| 122 | + /** |
|
| 123 | + * Displays the actual report. |
|
| 124 | + * |
|
| 125 | + */ |
|
| 126 | + public function display_stats() { |
|
| 127 | + ?> |
|
| 128 | 128 | |
| 129 | 129 | <canvas id="getpaid-chartjs-earnings-gateways"></canvas> |
| 130 | 130 | |
@@ -153,6 +153,6 @@ discard block |
||
| 153 | 153 | </script> |
| 154 | 154 | |
| 155 | 155 | <?php |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | } |
@@ -12,46 +12,46 @@ 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 ); |
|
| 45 | + $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Displays the reports tab. |
|
| 51 | - * |
|
| 52 | - */ |
|
| 53 | - public function display() { |
|
| 54 | - ?> |
|
| 49 | + /** |
|
| 50 | + * Displays the reports tab. |
|
| 51 | + * |
|
| 52 | + */ |
|
| 53 | + public function display() { |
|
| 54 | + ?> |
|
| 55 | 55 | |
| 56 | 56 | <div class="mt-4" style="max-width: 1200px;"> |
| 57 | 57 | |
@@ -69,44 +69,44 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | <?php |
| 71 | 71 | |
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Displays the left side. |
|
| 76 | - * |
|
| 77 | - */ |
|
| 78 | - public function display_left() { |
|
| 79 | - $earnings = new GetPaid_Reports_Report_Earnings(); |
|
| 80 | - $earnings->display(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Retrieves the download url. |
|
| 85 | - * |
|
| 86 | - */ |
|
| 87 | - public function get_download_url( $graph, $file_type) { |
|
| 88 | - |
|
| 89 | - return wp_nonce_url( |
|
| 90 | - add_query_arg( |
|
| 91 | - array( |
|
| 92 | - 'getpaid-admin-action' => 'download_graph', |
|
| 93 | - 'file_type' => urlencode( $file_type ), |
|
| 94 | - 'graph' => urlencode( $graph ), |
|
| 95 | - ) |
|
| 96 | - ), |
|
| 97 | - 'getpaid-nonce', |
|
| 98 | - 'getpaid-nonce' |
|
| 99 | - ); |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Displays the right side. |
|
| 105 | - * |
|
| 106 | - */ |
|
| 107 | - public function display_right() { |
|
| 108 | - |
|
| 109 | - ?> |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Displays the left side. |
|
| 76 | + * |
|
| 77 | + */ |
|
| 78 | + public function display_left() { |
|
| 79 | + $earnings = new GetPaid_Reports_Report_Earnings(); |
|
| 80 | + $earnings->display(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Retrieves the download url. |
|
| 85 | + * |
|
| 86 | + */ |
|
| 87 | + public function get_download_url( $graph, $file_type) { |
|
| 88 | + |
|
| 89 | + return wp_nonce_url( |
|
| 90 | + add_query_arg( |
|
| 91 | + array( |
|
| 92 | + 'getpaid-admin-action' => 'download_graph', |
|
| 93 | + 'file_type' => urlencode( $file_type ), |
|
| 94 | + 'graph' => urlencode( $graph ), |
|
| 95 | + ) |
|
| 96 | + ), |
|
| 97 | + 'getpaid-nonce', |
|
| 98 | + 'getpaid-nonce' |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Displays the right side. |
|
| 105 | + * |
|
| 106 | + */ |
|
| 107 | + public function display_right() { |
|
| 108 | + |
|
| 109 | + ?> |
|
| 110 | 110 | |
| 111 | 111 | <?php foreach ( $this->views as $key => $view ) : ?> |
| 112 | 112 | <div class="row mb-4"> |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | </div> |
| 136 | 136 | <div class="card-body"> |
| 137 | 137 | <?php |
| 138 | - $class = $view['class']; |
|
| 139 | - $class = new $class(); |
|
| 140 | - $class->display_stats(); |
|
| 141 | - ?> |
|
| 138 | + $class = $view['class']; |
|
| 139 | + $class = new $class(); |
|
| 140 | + $class->display_stats(); |
|
| 141 | + ?> |
|
| 142 | 142 | </div> |
| 143 | 143 | </div> |
| 144 | 144 | </div> |
@@ -147,6 +147,6 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | <?php |
| 149 | 149 | |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report Class. |
@@ -23,26 +23,26 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function __construct() { |
| 25 | 25 | |
| 26 | - $this->views = array( |
|
| 26 | + $this->views = array( |
|
| 27 | 27 | |
| 28 | 28 | 'items' => array( |
| 29 | - 'label' => __( 'Items', 'invoicing' ), |
|
| 29 | + 'label' => __('Items', 'invoicing'), |
|
| 30 | 30 | 'class' => 'GetPaid_Reports_Report_Items', |
| 31 | 31 | ), |
| 32 | 32 | |
| 33 | 33 | 'gateways' => array( |
| 34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
| 34 | + 'label' => __('Payment Methods', 'invoicing'), |
|
| 35 | 35 | 'class' => 'GetPaid_Reports_Report_Gateways', |
| 36 | 36 | ), |
| 37 | 37 | |
| 38 | 38 | 'discounts' => array( |
| 39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
| 39 | + 'label' => __('Discount Codes', 'invoicing'), |
|
| 40 | 40 | 'class' => 'GetPaid_Reports_Report_Discounts', |
| 41 | 41 | ), |
| 42 | 42 | |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
| 45 | + $this->views = apply_filters('wpinv_report_views', $this->views); |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | * Retrieves the download url. |
| 85 | 85 | * |
| 86 | 86 | */ |
| 87 | - public function get_download_url( $graph, $file_type) { |
|
| 87 | + public function get_download_url($graph, $file_type) { |
|
| 88 | 88 | |
| 89 | 89 | return wp_nonce_url( |
| 90 | 90 | add_query_arg( |
| 91 | 91 | array( |
| 92 | 92 | 'getpaid-admin-action' => 'download_graph', |
| 93 | - 'file_type' => urlencode( $file_type ), |
|
| 94 | - 'graph' => urlencode( $graph ), |
|
| 93 | + 'file_type' => urlencode($file_type), |
|
| 94 | + 'graph' => urlencode($graph), |
|
| 95 | 95 | ) |
| 96 | 96 | ), |
| 97 | 97 | 'getpaid-nonce', |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | ?> |
| 110 | 110 | |
| 111 | - <?php foreach ( $this->views as $key => $view ) : ?> |
|
| 111 | + <?php foreach ($this->views as $key => $view) : ?> |
|
| 112 | 112 | <div class="row mb-4"> |
| 113 | 113 | <div class="col-12"> |
| 114 | 114 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -118,17 +118,17 @@ discard block |
||
| 118 | 118 | <strong><?php echo $view['label']; ?></strong> |
| 119 | 119 | </div> |
| 120 | 120 | <div class="col-3"> |
| 121 | - <a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>"> |
|
| 121 | + <a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>"> |
|
| 122 | 122 | <i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i> |
| 123 | - <span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span> |
|
| 123 | + <span class="screen-reader-text"><?php _e('Download JSON', 'invoicing'); ?></span> |
|
| 124 | 124 | </a> |
| 125 | - <a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>"> |
|
| 125 | + <a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>"> |
|
| 126 | 126 | <i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i> |
| 127 | - <span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span> |
|
| 127 | + <span class="screen-reader-text"><?php _e('Download CSV', 'invoicing'); ?></span> |
|
| 128 | 128 | </a> |
| 129 | - <a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>"> |
|
| 129 | + <a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>"> |
|
| 130 | 130 | <i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i> |
| 131 | - <span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span> |
|
| 131 | + <span class="screen-reader-text"><?php _e('Download XML', 'invoicing'); ?></span> |
|
| 132 | 132 | </a> |
| 133 | 133 | </div> |
| 134 | 134 | </div> |