guard( 'manage_woocommerce', 'manage_options' ); if ( $check ) { return $check; } $params = [ 'start_date' => sanitize_text_field( $start_date ), 'end_date' => sanitize_text_field( $end_date ), ]; if ( ! empty( $branch ) && 'all' !== $branch ) { $params['branch'] = sanitize_text_field( $branch ); } $request = new \WP_REST_Request( 'GET', '/wpcafe/v2/dashboard/overview' ); $request->set_query_params( $params ); $controller = new \WpCafe\Dashboard\Controllers\Dashboard_Controller(); $data = $this->extract_response( $controller->get_overview( $request ), 'Failed to retrieve revenue data.' ); if ( isset( $data['error'] ) ) { return $data; } return [ 'period' => $params['start_date'] . ' to ' . $params['end_date'], 'total_revenue' => $data['total_revenue']['total'] ?? 0, 'orders_revenue' => $data['total_revenue']['orders_revenue'] ?? 0, 'reservations_revenue' => $data['total_revenue']['reservations_revenue'] ?? 0, 'revenue_change_pct' => $data['total_revenue']['change_percentage'] ?? 0, 'revenue_trend' => $data['total_revenue']['change_direction'] ?? 'up', 'total_orders' => $data['total_orders']['total'] ?? 0, 'total_reservations' => $data['total_reservations']['total'] ?? 0, 'total_customers' => $data['total_customers']['total'] ?? 0, 'branch' => ! empty( $branch ) ? $branch : 'all', ]; } }