- Created ExampleTest and RoutesTest for basic application response and route testing. - Implemented IsolatedDatabaseTestCase for isolated database testing. - Added unit tests for various models and services including Contract, CPE, and LeadDetail. - Developed request validation tests for CreateClientRequest, UpdateClientRequest, and ContractRequest. - Introduced Vite configuration for asset management in the Laravel application.
80 lines
2.3 KiB
PHP
80 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Contract;
|
|
|
|
class HomeService
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Show the application dashboard.
|
|
*
|
|
* @return \Illuminate\Contracts\Support\Renderable
|
|
*/
|
|
public function index()
|
|
{
|
|
$today = now();
|
|
$next60Days = now()->addDays(60);
|
|
|
|
$activeStatus = 1;
|
|
$pendingStatus = 3;
|
|
|
|
// === Contracts grouped by client type (for the chart) ===
|
|
$contractsByClientType = Contract::with('client.clientType')
|
|
->where('status_id', $activeStatus)
|
|
->get()
|
|
->groupBy(function ($contract) {
|
|
return $contract->client->clientType->description ?? 'Undefined';
|
|
})
|
|
->map(function ($group) {
|
|
return $group->count();
|
|
});
|
|
|
|
$clientLabels = $contractsByClientType->keys();
|
|
$clientData = $contractsByClientType->values();
|
|
|
|
// === Pending Contracts ===
|
|
$pendingContracts = Contract::with(['client', 'contractType'])
|
|
->where('status_id', $pendingStatus)
|
|
->orderBy('id')
|
|
->take(5)
|
|
->get();
|
|
|
|
// === Active Contracts ===
|
|
$activeContracts = Contract::with(['client', 'contractType'])
|
|
->where('status_id', $activeStatus)
|
|
->orderByDesc('id')
|
|
->take(5)
|
|
->get();
|
|
|
|
// === Upcoming Renewals (next 2 month) ===
|
|
$upcomingRenewals = Contract::with(['client', 'contractType', 'seller', 'installments' => function ($query) use ($today, $next60Days) {
|
|
$query->whereBetween('due_date', [$today, $next60Days])
|
|
->orderBy('due_date');
|
|
}])
|
|
->where('status_id', $activeStatus)
|
|
->whereBetween('validity', [$today, $next60Days])
|
|
->orderByDesc('contracts.id')
|
|
->take(5)
|
|
->get();
|
|
|
|
return [
|
|
'clientLabels' => $clientLabels,
|
|
'clientData' => $clientData,
|
|
'activeContracts' => $activeContracts,
|
|
'pendingContracts' => $pendingContracts,
|
|
'upcomingRenewals' => $upcomingRenewals
|
|
];
|
|
}
|
|
|
|
}
|