Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
8.33% |
1 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
CheckCompaniesExpirationCommand | |
8.33% |
1 / 12 |
|
50.00% |
1 / 2 |
16.32 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
handle | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace App\Console\Commands; |
4 | |
5 | use App\Http\Models\Admin\Company; |
6 | use App\Http\Models\Admin\CompanyLicenses; |
7 | use App\Http\Services\Admin\Companies\CompanyService; |
8 | use Illuminate\Console\Command; |
9 | use Illuminate\Support\Facades\Log; |
10 | use Carbon\Carbon; |
11 | |
12 | class CheckCompaniesExpirationCommand extends Command |
13 | { |
14 | /** |
15 | * The name and signature of the console command. |
16 | * |
17 | * @var string |
18 | */ |
19 | protected $signature = 'app:check-company-expiration'; |
20 | |
21 | /** |
22 | * The console command description. |
23 | * |
24 | * @var string |
25 | */ |
26 | protected $description = 'Check when a company is going to expire'; |
27 | |
28 | public function __construct( |
29 | private CompanyService $companyService, |
30 | ) { |
31 | parent::__construct(); |
32 | } |
33 | |
34 | /** |
35 | * Execute the console command. |
36 | */ |
37 | public function handle() |
38 | { |
39 | $this->info($this->description); |
40 | |
41 | $companies = Company::where('deleted_at', null)->where('deactivated_at', null)->get(); |
42 | |
43 | foreach ($companies as $company) { |
44 | $companyLicense = CompanyLicenses::where('company_id', $company->id)->latest()->first(); |
45 | |
46 | $expirationDate = Carbon::parse($companyLicense->contract_end_date); |
47 | $today = Carbon::now(); |
48 | $daysUntilExpiration = $today->diffInDays($expirationDate, false); |
49 | |
50 | if ($daysUntilExpiration <= 0) { |
51 | $this->info($company->name . ' is expired on ' . $expirationDate->toString()); |
52 | Log::info($company->name . ' is expired on ' . $expirationDate->toString()); |
53 | $this->companyService->deactivateCompany($company, '', $expirationDate); |
54 | } |
55 | } |
56 | } |
57 | } |