Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Member;
|
|
use App\Models\Organization;
|
|
use App\Services\Comms\EmailService;
|
|
use App\Services\Frontdesk\ReportService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class SendDailyReportCommand extends Command
|
|
{
|
|
protected $signature = 'frontdesk:send-daily-reports';
|
|
|
|
protected $description = 'Email daily visitor summary reports to configured org admins';
|
|
|
|
public function handle(ReportService $reports, EmailService $email): int
|
|
{
|
|
$from = now()->subDay()->startOfDay();
|
|
$to = now()->subDay()->endOfDay();
|
|
$sent = 0;
|
|
|
|
Organization::query()->each(function (Organization $organization) use ($reports, $email, $from, $to, &$sent) {
|
|
$recipients = data_get($organization->settings, 'report_daily_recipients', []);
|
|
if ($recipients === []) {
|
|
return;
|
|
}
|
|
|
|
$summary = $reports->summary($organization->owner_ref, $organization, $from, $to);
|
|
$subject = "Frontdesk daily summary — {$organization->name} ({$from->toDateString()})";
|
|
$body = implode("\n", [
|
|
"Visitors checked in: {$summary['checked_in']}",
|
|
"Currently unique visitors: {$summary['unique_visitors']}",
|
|
"Contractors: {$summary['contractors']}",
|
|
"Deliveries: {$summary['deliveries']}",
|
|
"Average visit duration (min): {$summary['avg_duration_minutes']}",
|
|
]);
|
|
|
|
foreach ($recipients as $address) {
|
|
if (is_string($address) && filter_var($address, FILTER_VALIDATE_EMAIL)) {
|
|
$email->send($address, $subject, $body);
|
|
$sent++;
|
|
}
|
|
}
|
|
});
|
|
|
|
$this->info("Sent {$sent} daily report email(s).");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|