where('active', true)->get(); if ($targets->isEmpty()) { $this->line('No export target configured — nothing to do.'); return self::SUCCESS; } $queued = 0; foreach ($targets as $target) { // Per destination, because "arrived" is a fact about a pair. An // invoice on the office NAS and not on the off-site box is exactly // the case this exists to catch. $pending = Invoice::query() ->whereDoesntHave('exports', fn ($q) => $q ->where('export_target_id', $target->id) ->whereNotNull('exported_at')) ->orderBy('id') ->limit((int) $this->option('limit')) ->get(); foreach ($pending as $invoice) { ArchiveInvoice::dispatch($invoice, $target); $queued++; } } $this->line("Queued {$queued} copy/copies for {$targets->count()} destination(s)."); return self::SUCCESS; } }