@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Payroll.Deduction @using Indotalent.Features.Payroll.Deduction.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject DeductionService DeductionService @inject ISnackbar Snackbar @(ReadOnly ? "Deduction Details" : "Edit Deduction Component") @(ReadOnly ? "Viewing deduction component specification." : "Modify existing deduction element.") Component Code Component Name Category Statutory Loan Penalty Internal Tax Treatment Calculation Method Status Active Inactive Description Audit History Created At @DateTimeExtensions.ToString(_model.CreatedAt) Created By @(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System") Last Updated At @DateTimeExtensions.ToString(_model.UpdatedAt) Last Updated By @(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System") @(ReadOnly ? "Back to List" : "Cancel") @if (!ReadOnly) { @if (_processing) { Processing... } else { Save Changes } } @code { [Parameter] public UpdateDeductionRequest 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 UpdateDeductionValidator _validator = new(); private UpdateDeductionRequest _model = new(); private bool _processing = false; protected override void OnInitialized() { _model = new UpdateDeductionRequest { Id = Data.Id, Code = Data.Code, Name = Data.Name, Category = Data.Category, PreTax = Data.PreTax, CalculationMethod = Data.CalculationMethod, Status = Data.Status, Description = Data.Description, CreatedAt = Data.CreatedAt, CreatedBy = Data.CreatedBy, UpdatedAt = Data.UpdatedAt, UpdatedBy = Data.UpdatedBy }; } private async Task Submit() { if (ReadOnly) return; await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var res = await DeductionService.UpdateDeductionAsync(_model); await Task.Delay(500); if (res != null && res.IsSuccess) { Snackbar.Add("Updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } } }