@@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Mne\BusinessRepository;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
@@ -28,14 +29,23 @@ final class DeclaredOriginStatistics
|
||||
$desk[$key] = ($desk[$key] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
$businesses = [];
|
||||
if (Schema::hasTable('existing_businesses')) {
|
||||
foreach (app(BusinessRepository::class)->query()->whereNotIn('status', ['draft', 'cancelled'])->cursor() as $business) {
|
||||
$code = $business->payload['declared_origin_country_code'] ?? null;
|
||||
$key = is_string($code) && isset($names[$code]) ? $code : '';
|
||||
$businesses[$key] = ($businesses[$key] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
// Distinct request collections; summing them could count the same investor twice.
|
||||
if ($origin !== null && $origin !== '') {
|
||||
$key = $origin === 'unknown' ? '' : $origin;
|
||||
$groups = array_intersect_key($groups, [$key => true]);
|
||||
$desk = array_intersect_key($desk, [$key => true]);
|
||||
$businesses = array_intersect_key($businesses, [$key => true]);
|
||||
}
|
||||
|
||||
return ['interests' => $this->format($groups, $names), 'desk' => $this->format($desk, $names)];
|
||||
return ['interests' => $this->format($groups, $names), 'desk' => $this->format($desk, $names), 'businesses' => $this->format($businesses, $names)];
|
||||
}
|
||||
|
||||
/** @param array<string, int> $counts
|
||||
|
||||
Reference in New Issue
Block a user