@page "/admin/tax-profiles" @using TaxBaik.Web.Services.AdminClients @inject ITaxProfileBrowserClient TaxProfileClient @inject IClientBrowserClient ClientClient @inject IJSRuntime JS @attribute [Authorize] 세무 프로필
CRM & 세무관리

세무 프로필

고객별 세무 프로필, 신고 일정, 위험도 추적

@if (profiles is null) { } else if (profiles.Count == 0) {
세무 프로필이 없습니다.
} else {
@foreach (var item in profiles) { }
ID 고객 사업 유형 위험도 다음 신고 작업
@item.Id @(clientMap.GetValueOrDefault(item.ClientId, $"Client #{item.ClientId}")) @item.BusinessType @item.TaxRiskLevel @(item.NextFilingDueDate?.ToString("yyyy-MM-dd") ?? "—")
}

@(isEditMode ? "세무 프로필 수정" : "새 세무 프로필 추가")

@code { [CascadingParameter] private Task? AuthStateTask { get; set; } private List? profiles; private List clients = []; private Dictionary clientMap = new(); private bool isDialogOpen; private bool isEditMode; private TaxProfile? editingProfile; private TaxProfileForm profileForm = new(); private string ClientIdText { get => profileForm.ClientId > 0 ? profileForm.ClientId.ToString() : ""; set => profileForm.ClientId = int.TryParse(value, out var id) ? id : 0; } private string NextFilingText { get => profileForm.NextFilingDueDate?.ToString("yyyy-MM-dd") ?? ""; set => profileForm.NextFilingDueDate = DateTime.TryParse(value, out var dt) ? dt : null; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender && AuthStateTask != null) { var authState = await AuthStateTask; if (authState.User.Identity?.IsAuthenticated == true) { await LoadData(); StateHasChanged(); } } } private async Task LoadData() { try { profiles = await TaxProfileClient.GetAllAsync(); var (clientItems, _) = await ClientClient.GetPagedAsync(pageSize: 1000); clients = clientItems.ToList(); clientMap = clients.ToDictionary(c => c.Id, GetClientDisplayName); } catch (Exception ex) { await JS.InvokeVoidAsync("alert", $"데이터 로드 실패: {ex.Message}"); } } private void OpenCreateDialog() { isEditMode = false; editingProfile = null; profileForm = new TaxProfileForm { ClientId = clients.FirstOrDefault()?.Id ?? 0, TaxRiskLevel = "normal", NextFilingDueDate = DateTime.Today.AddMonths(1) }; isDialogOpen = true; } private async Task OpenEditDialog(TaxProfile profile) { isEditMode = true; editingProfile = profile; profileForm = new TaxProfileForm { ClientId = profile.ClientId, BusinessType = profile.BusinessType ?? "", TaxRiskLevel = profile.TaxRiskLevel, NextFilingDueDate = profile.NextFilingDueDate, SpecialNotes = profile.SpecialNotes }; isDialogOpen = true; await Task.CompletedTask; } private async Task SaveProfile() { if (profileForm.ClientId <= 0 || string.IsNullOrWhiteSpace(profileForm.BusinessType)) { await JS.InvokeVoidAsync("alert", "고객과 사업 유형을 입력하세요."); return; } try { if (isEditMode && editingProfile != null) { await TaxProfileClient.UpdateAsync(editingProfile.Id, profileForm.BusinessType, null, profileForm.NextFilingDueDate, profileForm.TaxRiskLevel); await JS.InvokeVoidAsync("alert", "세무 프로필이 수정되었습니다."); } else { var newId = await TaxProfileClient.CreateAsync(profileForm.ClientId, profileForm.BusinessType); if (newId > 0) { await TaxProfileClient.UpdateAsync(newId, profileForm.BusinessType, null, profileForm.NextFilingDueDate, profileForm.TaxRiskLevel); await JS.InvokeVoidAsync("alert", "세무 프로필이 추가되었습니다."); } } CloseDialog(); await LoadData(); } catch (Exception ex) { await JS.InvokeVoidAsync("alert", $"저장 실패: {ex.Message}"); } } private async Task DeleteProfile(int id) { if (!await JS.InvokeAsync("confirm", "이 세무 프로필을 삭제하시겠습니까?")) return; try { await TaxProfileClient.DeleteAsync(id); await JS.InvokeVoidAsync("alert", "세무 프로필이 삭제되었습니다."); await LoadData(); } catch (Exception ex) { await JS.InvokeVoidAsync("alert", $"삭제 실패: {ex.Message}"); } } private void CloseDialog() { isDialogOpen = false; isEditMode = false; editingProfile = null; profileForm = new(); } private static string GetClientDisplayName(Client client) => !string.IsNullOrWhiteSpace(client.CompanyName) ? client.CompanyName : !string.IsNullOrWhiteSpace(client.Name) ? client.Name : $"Client #{client.Id}"; private sealed class TaxProfileForm { public int ClientId { get; set; } public string BusinessType { get; set; } = ""; public string TaxRiskLevel { get; set; } = "normal"; public DateTime? NextFilingDueDate { get; set; } public string? SpecialNotes { get; set; } } }