| @@ -24,15 +24,27 @@ | ||
| 24 | 24 | if ($status != 'yes' || ($frequency == 'weekly' && $sendingDay != $currentDay)) { |
| 25 | 25 | return; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - $reportDays = $frequency == 'daily' ? 1 : 7; | |
| 28 | + $lastSend = get_option('fcom_last_summary_email_send'); | |
| 29 | + $interval = ($frequency == 'daily') ? DAY_IN_SECONDS : WEEK_IN_SECONDS; | |
| 30 | + if ($lastSend && (current_time('timestamp') - strtotime($lastSend)) < $interval) { | |
| 31 | + return; | |
| 32 | + } | |
| 29 | 33 | |
| 30 | - $reportDateFrom = gmdate('Y-m-d', time() - $reportDays * 60 * 60 * 24); | |
| 34 | + $reportDays = $frequency == 'daily' ? 1 : 7; | |
| 31 | 35 | |
| 32 | - $totalBooked = Booking::where('end_time', '>', $reportDateFrom)->count(); | |
| 33 | - $totalCompleted = Booking::where('created_at', '>', $reportDateFrom)->where('status', 'completed')->count(); | |
| 36 | + $reportDateFrom = gmdate('Y-m-d H:i:s', strtotime("-$reportDays days")); | |
| 34 | 37 | |
| 38 | + $totalBooked = Booking::where('created_at', '>=', $reportDateFrom) | |
| 39 | + ->where('created_at', '<=', gmdate('Y-m-d H:i:s')) | |
| 40 | + ->count(); | |
| 41 | + | |
| 42 | + $totalCompleted = Booking::where('end_time', '>=', $reportDateFrom) | |
| 43 | + ->where('end_time', '<=', gmdate('Y-m-d H:i:s')) | |
| 44 | + ->where('status', 'completed') | |
| 45 | + ->count(); | |
| 46 | + | |
| 35 | 47 | if (!$totalBooked && !$totalCompleted) { |
| 36 | 48 | return; |
| 37 | 49 | } |
| 38 | 50 | |
| @@ -42,16 +54,25 @@ | ||
| 42 | 54 | 'totalBooked' => $totalBooked, |
| 43 | 55 | 'totalCompleted' => $totalCompleted, |
| 44 | 56 | ]; |
| 45 | 57 | |
| 46 | - $adminEmail = str_replace('{{wp.admin_email}}', get_option('admin_email'), $adminEmail); | |
| 47 | - | |
| 58 | + $adminEmail = str_replace('{{wp.admin_email}}', (string) get_option('admin_email', ''), $adminEmail); | |
| 48 | 59 | if(!$adminEmail) { |
| 49 | 60 | return; |
| 50 | 61 | } |
| 51 | 62 | |
| 52 | - // translators: %d is replaced with the number of days | |
| 53 | - $emailSubject = sprintf(esc_html__('Email Summary of Your Bookings (Last %d Days)', 'fluent-booking'), $reportDays); | |
| 63 | + update_option('fcom_last_summary_email_send', current_time('mysql')); | |
| 64 | + | |
| 65 | + $emailSubject = sprintf( | |
| 66 | + // translators: %d: number of days for which the summary is being reported | |
| 67 | + esc_html(_n( | |
| 68 | + 'Email Summary of Your Bookings (Last %d Day)', | |
| 69 | + 'Email Summary of Your Bookings (Last %d Days)', | |
| 70 | + $reportDays, | |
| 71 | + 'fluent-booking' | |
| 72 | + )), | |
| 73 | + $reportDays | |
| 74 | + ); | |
| 54 | 75 | |
| 55 | 76 | $emailBody = (string)App::make('view')->make('emails.summary_report', $data); |
| 56 | 77 | |
| 57 | 78 | $emogrifier = new Emogrifier($emailBody); |