PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.5.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.5.2
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / abilities / analytics / get-dashboard-stats.php
latepoint / lib / abilities / analytics Last commit date
abstract-analytics-ability.php 3 months ago get-daily-chart-data.php 3 months ago get-dashboard-stats.php 3 months ago get-pending-bookings-count.php 3 months ago get-top-services.php 3 months ago
get-dashboard-stats.php
65 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class LatePointAbilityGetDashboardStats extends LatePointAbstractAnalyticsAbility {
7
8 protected function configure(): void {
9 $this->id = 'latepoint/get-dashboard-stats';
10 $this->label = __( 'Get dashboard stats', 'latepoint' );
11 $this->description = __( 'Returns aggregate booking statistics for a date range (defaults to current month).', 'latepoint' );
12 $this->permission = 'booking__view';
13 $this->read_only = true;
14 }
15
16 public function get_input_schema(): array {
17 return [
18 'type' => 'object',
19 'properties' => [
20 'date_from' => [
21 'type' => 'string',
22 'format' => 'date',
23 'description' => __( 'Period start (Y-m-d). Defaults to first day of current month.', 'latepoint' ),
24 ],
25 'date_to' => [
26 'type' => 'string',
27 'format' => 'date',
28 'description' => __( 'Period end (Y-m-d). Defaults to last day of current month.', 'latepoint' ),
29 ],
30 ],
31 ];
32 }
33
34 public function get_output_schema(): array {
35 return [
36 'type' => 'object',
37 'properties' => [
38 'bookings_count' => [ 'type' => 'integer' ],
39 'revenue' => [ 'type' => 'number' ],
40 'customers_count' => [ 'type' => 'integer' ],
41 'pending_count' => [ 'type' => 'integer' ],
42 ],
43 ];
44 }
45
46 public function execute( array $args ) {
47 $date_from = ! empty( $args['date_from'] ) ? sanitize_text_field( $args['date_from'] ) : wp_date( 'Y-m-01' );
48 $date_to = ! empty( $args['date_to'] ) ? sanitize_text_field( $args['date_to'] ) : wp_date( 'Y-m-t' );
49
50 $filter = new \LatePoint\Misc\Filter();
51
52 $bookings_count = (int) OsBookingHelper::get_stat_for_period( 'bookings', $date_from, $date_to, $filter );
53 $revenue = (float) OsBookingHelper::get_stat_for_period( 'price', $date_from, $date_to, $filter );
54 $customers_count = (int) ( new OsCustomerModel() )->count();
55 $pending_count = (int) ( new OsBookingModel() )->where( [ 'status' => LATEPOINT_BOOKING_STATUS_PENDING ] )->count();
56
57 return [
58 'bookings_count' => $bookings_count,
59 'revenue' => $revenue,
60 'customers_count' => $customers_count,
61 'pending_count' => $pending_count,
62 ];
63 }
64 }
65