@using Indotalent.Features.Organization.Employee @using Indotalent.Features.Organization.Employee.Cqrs @using Features.Root.Shared @using MudBlazor @inject EmployeeService EmployeeService @inject IDialogService DialogService @inject ISnackbar Snackbar Employee Deduction Details Manage deduction components for @EmployeeName @(!string.IsNullOrEmpty(_displayCode) ? $"({_displayCode})" : "") List of Deductions Add Deduction @if (_isLoading) { } else if (!_deductions.Any()) { No deduction components assigned for this employee. } else { Deduction Component Category Amount Description Status Actions @context.DeductionName @context.DeductionCategory (@context.Amount.ToString("N0")) @context.Description } @code { [Parameter] public string EmployeeId { get; set; } = string.Empty; [Parameter] public string EmployeeName { get; set; } = string.Empty; [Parameter] public string EmployeeCode { get; set; } = string.Empty; [Parameter] public EventCallback OnBack { get; set; } private List _deductions = new(); private bool _isLoading = true; private string _displayCode = string.Empty; protected override async Task OnInitializedAsync() { _displayCode = EmployeeCode; await LoadData(); } private async Task LoadData() { _isLoading = true; StateHasChanged(); var response = await EmployeeService.GetEmployeeDeductionListAsync(EmployeeId); if (response?.IsSuccess == true) { _deductions = response.Value ?? new(); if (_deductions.Any() && string.IsNullOrEmpty(_displayCode)) { _displayCode = _deductions.First().EmployeeCode ?? string.Empty; } } _isLoading = false; StateHasChanged(); } private async Task OnAdd() { var parameters = new DialogParameters { ["EmployeeId"] = EmployeeId }; var options = new DialogOptions { CloseButton = true, BackdropClick = false }; var dialog = await DialogService.ShowAsync<_EmployeeDeductionCreateForm>("Add Employee Deduction", parameters, options); var result = await dialog.Result; if (result != null && !result.Canceled) await LoadData(); } private async Task OnEdit(GetEmployeeDeductionListResponse context) { var parameters = new DialogParameters { ["Id"] = context.Id }; var options = new DialogOptions { CloseButton = true, BackdropClick = false }; var dialog = await DialogService.ShowAsync<_EmployeeDeductionUpdateForm>("Edit Employee Deduction", parameters, options); var result = await dialog.Result; if (result != null && !result.Canceled) await LoadData(); } private async Task OnDelete(GetEmployeeDeductionListResponse context) { var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, $"{context.DeductionName} from {EmployeeName}" } }); var result = await dialog.Result; if (result != null && !result.Canceled) { var success = await EmployeeService.DeleteEmployeeDeductionByIdAsync(context.Id!); if (success) { Snackbar.Add("Deduction component removed", Severity.Success); await LoadData(); } } } }