1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00
invoiceninja/app/Ninja/Repositories/ReferralRepository.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\Repositories;
2015-11-01 19:21:11 +01:00
2017-05-14 11:11:38 +02:00
use App\Models\Company;
use App\Models\DbServer;
2015-11-01 19:21:11 +01:00
class ReferralRepository
{
2017-05-14 11:11:38 +02:00
public function getCounts($referralCode)
2015-11-01 19:21:11 +01:00
{
$counts = [
'free' => 0,
2016-04-17 00:34:39 +02:00
'pro' => 0,
2017-01-30 20:40:43 +01:00
'enterprise' => 0,
2015-11-01 19:21:11 +01:00
];
2017-05-14 11:11:38 +02:00
if (! $referralCode) {
return $counts;
}
$current = config('database.default');
$databases = env('MULTI_DB_ENABLED') ? DbServer::all()->pluck('name')->toArray() : [$current];
2016-06-05 18:10:15 +02:00
2017-05-14 11:11:38 +02:00
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']++;
}
2016-04-17 00:34:39 +02:00
}
2015-11-01 19:21:11 +01:00
}
}
2017-05-14 11:11:38 +02:00
config(['database.default' => $current]);
2015-11-01 19:21:11 +01:00
return $counts;
}
2016-06-05 18:10:15 +02:00
}