Files
ladill-frontdesk/app/Console/Commands/SendDailyReportCommand.php
T
isaaccladandCursor 1def8cf716
Deploy Ladill Frontdesk / deploy (push) Has been cancelled
Brand Frontdesk Laravel mail for hosts and report recipients.
Pass organization logo/name through ContactMessageMail for daily reports and campaigns, and drop the Ladill product footer.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-12 20:10:26 +00:00

53 lines
1.9 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, $organization->name, null, $organization);
$sent++;
}
}
});
$this->info("Sent {$sent} daily report email(s).");
return self::SUCCESS;
}
}