Passed
Pull Request — master (#444)
by Brian
05:33
created

GetPaid_Reports_Report_Earnings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 125
c 1
b 0
f 0
dl 0
loc 167
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
B display() 0 65 1
A get_periods() 0 11 1
A display_range_selector() 0 58 2
1
<?php
2
/**
3
 * Contains the class that displays the earnings report.
4
 *
5
 *
6
 */
7
8
defined( 'ABSPATH' ) || exit;
9
10
/**
11
 * GetPaid_Reports_Report_Earnings Class.
12
 */
13
class GetPaid_Reports_Report_Earnings {
14
15
	/**
16
	 * @var array
17
	 */
18
	public $stats;
19
20
	/**
21
	 * Class constructor.
22
	 *
23
	 */
24
	public function __construct() {
25
26
	}
27
28
	/**
29
	 * Displays the reports tab.
30
	 *
31
	 */
32
	public function display() {
33
		?>
34
35
			<div class="row">
36
				<div class="col-12">
37
					<div class="card" style="max-width:720px">
38
						<div class="card-body">
39
							<?php $this->display_range_selector(); ?>
40
							<canvas id="getpaid-chartjs-earnings"></canvas>
41
						</div>
42
					</div>
43
				</div>
44
			</div>
45
46
			<script>
47
48
				window.addEventListener( 'DOMContentLoaded', function() {
49
50
					var ctx = document.getElementById( 'getpaid-chartjs-earnings' ).getContext('2d');
51
52
					var myChart = new Chart(ctx, {
53
    type: 'bar',
54
    data: {
55
        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
56
        datasets: [{
57
            label: '# of Votes',
58
            data: [12, 19, 3, 5, 2, 3],
59
            backgroundColor: [
60
                'rgba(255, 99, 132, 0.2)',
61
                'rgba(54, 162, 235, 0.2)',
62
                'rgba(255, 206, 86, 0.2)',
63
                'rgba(75, 192, 192, 0.2)',
64
                'rgba(153, 102, 255, 0.2)',
65
                'rgba(255, 159, 64, 0.2)'
66
            ],
67
            borderColor: [
68
                'rgba(255, 99, 132, 1)',
69
                'rgba(54, 162, 235, 1)',
70
                'rgba(255, 206, 86, 1)',
71
                'rgba(75, 192, 192, 1)',
72
                'rgba(153, 102, 255, 1)',
73
                'rgba(255, 159, 64, 1)'
74
            ],
75
            borderWidth: 1
76
        }]
77
    },
78
    options: {
79
        scales: {
80
            yAxes: [{
81
                ticks: {
82
                    beginAtZero: true
83
                }
84
            }]
85
        }
86
    }
87
});
88
89
				});
90
91
			</script>
92
93
		<?php
94
95
		wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
96
		wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
97
98
	}
99
100
	/**
101
	 * Returns an array of date ranges.
102
	 *
103
	 * @return array
104
	 */
105
	public function get_periods() {
106
107
		$periods = array(
108
            'today'     => __( 'Today', 'invoicing' ),
109
            'yesterday' => __( 'Yesterday', 'invoicing' ),
110
            '7_days'    => __( 'Last 7 days', 'invoicing' ),
111
			'30_days'   => __( 'Last 30 days', 'invoicing' ),
112
			'90_days'   => __( 'Last 90 days', 'invoicing' ),
113
		);
114
115
		return apply_filters( 'getpaid_earning_periods', $periods );
116
	}
117
118
	/**
119
	 * Displays the range selector.
120
	 *
121
	 */
122
	public function display_range_selector() {
123
124
		?>
125
126
			<form method="get" class="d-block mt-4 getpaid-filter-earnings">
127
				<?php
128
129
					getpaid_hidden_field( 'page', 'wpinv-reports' );
130
					getpaid_hidden_field( 'tab', 'reports' );
131
132
					?>
133
134
					<div class="row">
135
						<div class="col-12 col-sm-4">
136
137
							<?php
138
								echo aui()->select(
139
									array(
140
										'name'        => 'date_range',
141
										'id'          => 'view' . uniqid( '_' ),
142
										'placeholder' => __( 'Select a date range', 'invoicing' ),
143
										'label'       => __( 'Date Range', 'invoicing' ),
144
										'options'     => $this->get_periods(),
145
										'value'       => isset( $_GET['date_range'] ) ? sanitize_key( $_GET['date_range'] ) : '7_days',
146
										'no_wrap'     => true,
147
									)
148
								);
149
							?>
150
151
						</div>
152
153
						<div class='getpaid-custom-range d-none col-12 col-sm-4'>
154
155
							<?php
156
157
								echo aui()->input(
158
									array(
159
										'type'        => 'datepicker',
160
										'id'          => 'getpaid_earnings_report_range',
161
										'name'        => 'reports_range',
162
										'label'       => __( 'Start Date', 'invoicing' ),
163
										'placeholder' => 'YYYY-MM-DD 00:00',
164
										'value'       => '2020-11-01 00:00 to 2020-11-05 00:00',
165
										'extra_attributes' => array(
166
											'data-mode'        => 'range',
167
											'data-date-format' => 'Y-m-d',
168
											'data-max-date'    => 'today',
169
										),
170
									)
171
								);
172
173
							?>
174
175
						</div>
176
177
						<div class="col-12 col-sm-4">
178
							<?php getpaid_submit_field( __( 'Filter', 'invoicing' ), '', 'btn-secondary' ); ?>
179
						</div>
180
181
					</div>
182
183
			</form>
184
185
		<?php
186
	}
187
188
}
189