insert( Schema::payments_table(), $payment_data ) ? (int) $wpdb->insert_id : 0; } public function for_booking( int $booking_id ): array { global $wpdb; return $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE booking_id = %d ORDER BY created_at DESC', Schema::payments_table(), $booking_id ), ARRAY_A ) ?: []; } public function total_for_booking( int $booking_id ): float { global $wpdb; return (float) $wpdb->get_var( $wpdb->prepare( 'SELECT COALESCE(SUM(amount), 0) FROM %i WHERE booking_id = %d AND status = %s', Schema::payments_table(), $booking_id, 'completed' ) ); } public function collected_between( string $from_datetime, string $to_datetime ): float { global $wpdb; return (float) $wpdb->get_var( $wpdb->prepare( 'SELECT COALESCE(SUM(amount), 0) FROM %i WHERE status = %s AND created_at BETWEEN %s AND %s', Schema::payments_table(), 'completed', $from_datetime, $to_datetime ) ); } }