PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.38
Timetics – Appointment Booking Calendar & Scheduling v1.0.38
1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 All 64 releases
← All changes | core/reports/api-report.php +16 -59 trunk1.0.38 View file →
@@ -6,10 +6,8 @@
6 6 */
7 7
8 8 namespace Timetics\Core\Reports;
9 9
10 -defined( 'ABSPATH' ) || exit;
11 -
12 10 use Timetics\Base\Api;
13 11 use Timetics\Utils\Singleton;
14 12
15 13 /**
@@ -88,21 +86,9 @@
88 86 * @return array
89 87 */
90 88 public function generate_reports( $input_data = [] ) {
91 89 $reports = [];
92 -
93 - // Statuses that count as a real, confirmed booking for reporting.
94 - // Deliberately NOT tied to the "default_booking_status" setting —
95 - // that option controls what status a brand-new booking starts in,
96 - // not which bookings count as revenue. Reusing it here made a
97 - // booking silently drop out of totals the moment an admin approved
98 - // it on a site where new bookings default to "pending".
99 - $counted_statuses = apply_filters( 'timetics/report/counted_statuses', [ 'approved', 'completed' ] );
100 -
101 - // Staff only see their own numbers, administrators see the whole site.
102 - $booking_scope = $this->get_booking_scope_args();
103 - $customer_scope = $this->get_customer_scope_args();
104 -
90 + $default_booking_status = timetics_get_option( 'default_booking_status', 'approved' );
105 91 if ( $input_data ) {
106 92 foreach ( $input_data as $data ) {
107 93 if ( empty( $data['report'] ) || empty( $data['start_date'] ) || empty( $data['end_date'] ) ) {
108 94 continue;
@@ -114,32 +100,32 @@
114 100 ];
115 101
116 102 switch ( $data['report'] ) {
117 103 case 'total_booking':
118 - $total_booking = timetics_count_posts( array_merge( [
104 + $total_booking = timetics_count_posts( [
119 105 'post_type' => 'timetics-booking',
120 - 'post_status' => $counted_statuses,
106 + 'post_status' => $default_booking_status,
121 107 'date_range' => $date_range,
122 - ], $booking_scope ) );
108 + ] );
123 109
124 110 $reports['total_booking'] = $total_booking;
125 111 break;
126 112
127 113 case 'total_earning':
128 - $total_earning = number_format( timetics_get_total_sale( array_merge( [
114 + $total_earning = number_format( timetics_get_total_sale( [
129 115 'post_type' => 'timetics-booking',
130 - 'post_status' => $counted_statuses,
116 + 'post_status' => $default_booking_status,
131 117 'date_range' => $date_range,
132 - ], $booking_scope ) ), 2 );
118 + ] ), 2 );
133 119
134 120 $reports['total_earning'] = $total_earning;
135 121 break;
136 122
137 123 case 'total_customer':
138 - $total_customer = timetics_count_users( array_merge( [
124 + $total_customer = timetics_count_users( [
139 125 'role' => 'timetics-customer',
140 126 'date_range' => $date_range,
141 - ], $customer_scope ) );
127 + ] );
142 128
143 129 $reports['total_customer'] = $total_customer;
144 130 break;
145 131
@@ -163,16 +149,13 @@
163 149 $end_date = $date['end'];
164 150
165 151 $current_date = strtotime( $start_date );
166 152 $end_timestamp = strtotime( $end_date );
167 - $counted_statuses = apply_filters( 'timetics/report/counted_statuses', [ 'approved', 'completed' ] );
153 + $default_booking_status = timetics_get_option( 'default_booking_status', 'approved' );
168 154 $reports = [];
169 155
170 - // Staff only see their own numbers, administrators see the whole site.
171 - $booking_scope = $this->get_booking_scope_args();
172 -
173 156 while ( $current_date <= $end_timestamp ) {
174 - $current_report_date = gmdate( 'Y-m-d', $current_date );
157 + $current_report_date = date( 'Y-m-d', $current_date );
175 158
176 159 $date_range = [
177 160 'start' => $current_report_date,
178 161 'end' => $current_report_date,
@@ -178,18 +161,18 @@
178 161 'end' => $current_report_date,
179 162 ];
180 163
181 164 $booking_report = [
182 - 'cancel' => timetics_count_posts( array_merge( [
165 + 'cancel' => timetics_count_posts( [
183 166 'post_type' => 'timetics-booking',
184 167 'post_status' => 'cancel',
185 168 'date_range' => $date_range,
186 - ], $booking_scope ) ),
187 - 'completed' => timetics_count_posts( array_merge( [
169 + ] ),
170 + 'completed' => timetics_count_posts( [
188 171 'post_type' => 'timetics-booking',
189 - 'post_status' => $counted_statuses,
172 + 'post_status' => $default_booking_status,
190 173 'date_range' => $date_range,
191 - ], $booking_scope ) ),
174 + ] ),
192 175 ];
193 176
194 177 $reports[$current_report_date] = $booking_report;
195 178
@@ -196,32 +179,6 @@
196 179 $current_date = strtotime( '+1 day', $current_date );
197 180 }
198 181
199 182 return $reports;
200 - }
201 -
202 - /**
203 - * Get the booking query args that limit a report to what the current user may see
204 - *
205 - * @return array Empty for administrators, who see every booking.
206 - */
207 - protected function get_booking_scope_args() {
208 - if ( timetics_can_view_all_data() ) {
209 - return [];
210 - }
211 -
212 - return ['post__in' => timetics_get_visible_booking_ids( get_current_user_id() )];
213 - }
214 -
215 - /**
216 - * Get the user query args that limit a report to what the current user may see
217 - *
218 - * @return array Empty for administrators, who see every customer.
219 - */
220 - protected function get_customer_scope_args() {
221 - if ( timetics_can_view_all_data() ) {
222 - return [];
223 - }
224 -
225 - return ['include' => timetics_get_visible_customer_ids( get_current_user_id() )];
226 183 }
227 184 }