mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
47 lines
1.1 KiB
PHP
Executable File
47 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Ninja\Repositories;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\DbServer;
|
|
|
|
class ReferralRepository
|
|
{
|
|
public function getCounts($referralCode)
|
|
{
|
|
$counts = [
|
|
'free' => 0,
|
|
'pro' => 0,
|
|
'enterprise' => 0,
|
|
];
|
|
|
|
if (! $referralCode) {
|
|
return $counts;
|
|
}
|
|
|
|
$current = config('database.default');
|
|
$databases = env('MULTI_DB_ENABLED') ? DbServer::all()->pluck('name')->toArray() : [$current];
|
|
|
|
foreach ($databases as $database) {
|
|
config(['database.default' => $database]);
|
|
$accounts = Company::whereReferralCode($referralCode)->get();
|
|
|
|
foreach ($accounts as $account) {
|
|
$counts['free']++;
|
|
$plan = $account->getPlanDetails(false, false);
|
|
|
|
if ($plan) {
|
|
$counts['pro']++;
|
|
if ($plan['plan'] == PLAN_ENTERPRISE) {
|
|
$counts['enterprise']++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
config(['database.default' => $current]);
|
|
|
|
return $counts;
|
|
}
|
|
}
|