Enhance ActivityLogsTable by updating event and causer filters to utilize the Activity model directly. Introduce a new causer_id filter with improved query logic for better user experience. Add new methods in EmployeeStatisticsService for applying table aggregates, and update localization files to include new terms for employee statistics in English, Russian, and Turkmen.
This commit is contained in:
@@ -6,8 +6,10 @@ namespace App\Services\Employee;
|
||||
|
||||
use App\DTOs\EmployeeSummaryDto;
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Enums\VacationType;
|
||||
use App\Models\Employee;
|
||||
use App\Services\Vacation\VacationBalanceService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class EmployeeStatisticsService
|
||||
{
|
||||
@@ -15,6 +17,25 @@ class EmployeeStatisticsService
|
||||
private readonly VacationBalanceService $vacationBalanceService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param Builder<Employee> $query
|
||||
* @return Builder<Employee>
|
||||
*/
|
||||
public function applyTableAggregates(Builder $query, ?int $year = null): Builder
|
||||
{
|
||||
$year ??= (int) now()->year;
|
||||
|
||||
return $query
|
||||
->with(['department', 'position'])
|
||||
->withCount(['sickLeaves', 'unpaidLeaves', 'disciplinaryReports', 'explanations', 'gifts'])
|
||||
->withSum('bonuses', 'amount')
|
||||
->withSum(['vacations as annual_vacation_days_taken' => fn (Builder $vacationQuery): Builder => $vacationQuery
|
||||
->where('type', VacationType::Annual)
|
||||
->where('status', ApprovalStatus::Approved)
|
||||
->whereYear('start_date', $year),
|
||||
], 'days');
|
||||
}
|
||||
|
||||
public function summary(Employee $employee): EmployeeSummaryDto
|
||||
{
|
||||
return new EmployeeSummaryDto(
|
||||
|
||||
Reference in New Issue
Block a user