ultimatepos/Modules/AssetExchange/Console/AssetExchangeDailyDigest.php

45 lines
1.3 KiB
PHP

<?php
namespace Modules\AssetExchange\Console;
use App\Business;
use Illuminate\Console\Command;
use Modules\AssetExchange\Services\AssetExchangeNotificationService;
class AssetExchangeDailyDigest extends Command
{
protected $signature = 'pos:assetexchangeDailyDigest {business_id?}';
protected $description = 'Create AssetExchange daily digest and escalations';
public function __construct(
protected AssetExchangeNotificationService $notificationService
) {
parent::__construct();
}
public function handle(): int
{
$businessId = $this->argument('business_id');
$query = Business::query();
if ($businessId) {
$query->where('id', (int) $businessId);
}
$businesses = $query->get();
$processed = 0;
foreach ($businesses as $business) {
$escalated = $this->notificationService->escalateOverdueItems($business);
$summary = $this->notificationService->dailyDigest($business);
$this->line("Business {$business->id}: escalated={$escalated}, overdue_inquiries={$summary['overdue_inquiries']}, overdue_tasks={$summary['overdue_tasks']}");
$processed++;
}
$this->info("AssetExchange digest done for {$processed} business(es).");
return self::SUCCESS;
}
}