198 lines
10 KiB
Plaintext
198 lines
10 KiB
Plaintext
@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
|
|
|
|
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
|
|
<div class="d-flex align-center gap-4">
|
|
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
|
<div>
|
|
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Balance Details" : "Adjust Balance")</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #64748b;">Review or modify employee leave quota for the specified period.</MudText>
|
|
</div>
|
|
</div>
|
|
</MudPaper>
|
|
|
|
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
|
@if (_isInitialLoading)
|
|
{
|
|
<div class="d-flex flex-column align-center justify-center pa-10">
|
|
<MudProgressCircular Color="Color.Info" Indeterminate="true" Size="Size.Large" />
|
|
<MudText Typo="Typo.body2" Class="mt-4">Loading balance configuration...</MudText>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<MudForm @ref="_form" Model="_model">
|
|
<MudGrid Spacing="3">
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Employee</MudText>
|
|
<MudSelect T="string" @bind-Value="_model.EmployeeId"
|
|
ReadOnly="ReadOnly"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense"
|
|
AnchorOrigin="Origin.BottomLeft" TransformOrigin="Origin.TopLeft">
|
|
@foreach (var emp in _employees)
|
|
{
|
|
<MudSelectItem Value="@emp.Id">@emp.FullName (@emp.Code)</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Leave Type</MudText>
|
|
<MudSelect T="string" @bind-Value="_model.LeaveCategoryId"
|
|
ReadOnly="ReadOnly"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense"
|
|
AnchorOrigin="Origin.BottomLeft" TransformOrigin="Origin.TopLeft">
|
|
@foreach (var cat in _categories)
|
|
{
|
|
<MudSelectItem Value="@cat.Id">@cat.Name</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" sm="4">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Year</MudText>
|
|
<MudNumericField @bind-Value="_model.Year" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="4">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Entitlement (Base Quota)</MudText>
|
|
<MudNumericField @bind-Value="_model.Entitlement" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="4">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Carry Forward</MudText>
|
|
<MudNumericField @bind-Value="_model.CarryForward" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Validity Period (From)</MudText>
|
|
<MudDatePicker @bind-Date="_validFrom" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Validity Period (To)</MudText>
|
|
<MudDatePicker @bind-Date="_validTo" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-4">
|
|
<MudText Typo="Typo.button" Color="Color.Info" Style="font-weight: 800;">Calculation Summary</MudText>
|
|
<MudDivider Class="mt-2 mb-4" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="4">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Used (Days)</MudText>
|
|
<MudNumericField @bind-Value="_model.Used" ReadOnly="true" Variant="Variant.Filled" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="4">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Pending (Days)</MudText>
|
|
<MudNumericField @bind-Value="_model.Pending" ReadOnly="true" Variant="Variant.Filled" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="4">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Remaining Balance</MudText>
|
|
<MudNumericField Value="@((_model.Entitlement + _model.CarryForward) - _model.Used - _model.Pending)"
|
|
ReadOnly="true" Variant="Variant.Filled" Margin="Margin.Dense"
|
|
Style="font-weight: 900; color: #2e7d32;" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-4">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
|
|
<MudDivider Class="mt-2 mb-4" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudGrid Spacing="2">
|
|
<MudItem xs="12">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Created By</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Updated By</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "-")</MudText>
|
|
</MudItem>
|
|
</MudGrid>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudGrid Spacing="2">
|
|
<MudItem xs="12">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Created At</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Updated At</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
|
|
</MudItem>
|
|
</MudGrid>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
<div class="d-flex justify-end gap-2 mt-10">
|
|
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">@(ReadOnly ? "Back to List" : "Cancel")</MudButton>
|
|
@if (!ReadOnly)
|
|
{
|
|
<MudButton Color="Color.Info" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700; color: white;">
|
|
@if (_processing)
|
|
{
|
|
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
|
}
|
|
else
|
|
{
|
|
<MudText>Save Adjustments</MudText>
|
|
}
|
|
</MudButton>
|
|
}
|
|
</div>
|
|
</MudForm>
|
|
}
|
|
</MudPaper>
|
|
|
|
@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<EmployeeLeaveReferenceResponse> _employees = new();
|
|
private List<GetLeaveCategoryListResponse> _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; }
|
|
}
|
|
} |