@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Leave.LeaveBalance @using Indotalent.Features.Leave.LeaveBalance.Cqrs @using Indotalent.Features.Leave.LeaveRequest @using Indotalent.Features.Leave.LeaveRequest.Cqrs @using Indotalent.Features.Leave.LeaveCategory @using Indotalent.Features.Leave.LeaveCategory.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject LeaveBalanceService LeaveBalanceService @inject LeaveRequestService LeaveRequestService @inject LeaveCategoryService LeaveCategoryService @inject ISnackbar Snackbar
@(ReadOnly ? "Balance Details" : "Adjust Balance") Review or modify employee leave quota for the specified period.
@if (_isInitialLoading) {
Loading balance configuration...
} else { Employee @foreach (var emp in _employees) { @emp.FullName (@emp.Code) } Leave Type @foreach (var cat in _categories) { @cat.Name } Year Entitlement (Base Quota) Carry Forward Validity Period (From) Validity Period (To) Calculation Summary Used (Days) Pending (Days) Remaining Balance Audit History Created By @(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System") Updated By @(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "-") Created At @DateTimeExtensions.ToString(_model.CreatedAt) Updated At @DateTimeExtensions.ToString(_model.UpdatedAt)
@(ReadOnly ? "Back to List" : "Cancel") @if (!ReadOnly) { @if (_processing) { } else { Save Adjustments } }
}
@code { [Parameter] public UpdateLeaveBalanceRequest Data { get; set; } = new(); [Parameter] public bool ReadOnly { get; set; } = false; [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private UpdateLeaveBalanceValidator _validator = new(); private UpdateLeaveBalanceRequest _model = new(); private List _employees = new(); private List _categories = new(); private bool _processing = false; private bool _isInitialLoading = true; private DateTime? _validFrom { get => _model.ValidFrom; set => _model.ValidFrom = value ?? DateTime.Today; } private DateTime? _validTo { get => _model.ValidTo; set => _model.ValidTo = value ?? DateTime.Today; } protected override async Task OnInitializedAsync() { _isInitialLoading = true; try { _model = Data; var empRes = await LeaveRequestService.GetEmployeeReferenceAsync(); if (empRes?.IsSuccess == true) _employees = empRes.Value ?? new(); var catRes = await LeaveCategoryService.GetLeaveCategoryListAsync(); if (catRes?.IsSuccess == true) _categories = catRes.Value ?? new(); } finally { _isInitialLoading = false; } } private async Task Submit() { if (ReadOnly) return; await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { _model.Remaining = (_model.Entitlement + _model.CarryForward) - _model.Used - _model.Pending; var response = await LeaveBalanceService.UpdateLeaveBalanceAsync(_model); await Task.Delay(500); if (response?.IsSuccess == true) { Snackbar.Add("Balance adjusted successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } } }