PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.7.1
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.7.1
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / app / Services / SummaryReportService.php

SummaryReportService.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.7.1, at app/Services/SummaryReportService.php

69 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Services;
4
5 use FluentBooking\App\App;
6 use FluentBooking\App\Services\Helper;
7 use FluentBooking\App\Models\Booking;
8 use FluentBooking\Framework\Support\Arr;
9 use FluentBooking\App\Services\Libs\Emogrifier\Emogrifier;
10
11 class SummaryReportService
12 {
13 public static function maybeSendSummary()
14 {
15 $notificationSettings = Helper::getGlobalSettings('administration');
16
17 $currentDay = strtolower(gmdate('D'));
18
19 $status = Arr::get($notificationSettings, 'summary_notification');
20 $frequency = Arr::get($notificationSettings, 'notification_frequency');
21 $adminEmail = Arr::get($notificationSettings, 'admin_email');
22 $sendingDay = Arr::get($notificationSettings, 'notification_day');
23
24 if ($status != 'yes' || ($frequency == 'weekly' && $sendingDay != $currentDay)) {
25 return;
26 }
27 $reportDays = $frequency == 'daily' ? 1 : 7;
28
29 $reportDateFrom = gmdate('Y-m-d H:i:s', strtotime("-$reportDays days"));
30
31 $totalBooked = Booking::where('created_at', '>=', $reportDateFrom)
32 ->where('created_at', '<=', gmdate('Y-m-d H:i:s'))
33 ->count();
34
35 $totalCompleted = Booking::where('end_time', '>=', $reportDateFrom)
36 ->where('end_time', '<=', gmdate('Y-m-d H:i:s'))
37 ->where('status', 'completed')
38 ->count();
39
40 if (!$totalBooked && !$totalCompleted) {
41 return;
42 }
43
44 $data = [
45 'days' => $reportDays,
46 'frequency' => $frequency,
47 'totalBooked' => $totalBooked,
48 'totalCompleted' => $totalCompleted,
49 ];
50
51 $adminEmail = str_replace('{{wp.admin_email}}', get_option('admin_email'), $adminEmail);
52
53 if(!$adminEmail) {
54 return;
55 }
56
57 // translators: %d is replaced with the number of days
58 $emailSubject = sprintf(esc_html__('Email Summary of Your Bookings (Last %d Days)', 'fluent-booking'), $reportDays);
59
60 $emailBody = (string)App::make('view')->make('emails.summary_report', $data);
61
62 $emogrifier = new Emogrifier($emailBody);
63 $emogrifier->disableInvisibleNodeRemoval();
64 $emailBbody = (string)$emogrifier->emogrify();
65
66 return Mailer::send($adminEmail, $emailSubject, $emailBbody);
67 }
68 }
69