248 lines
8.9 KiB
Plaintext
248 lines
8.9 KiB
Plaintext
@page "/admin/tax-profiles"
|
|
@using TaxBaik.Web.Services.AdminClients
|
|
@inject ITaxProfileBrowserClient TaxProfileClient
|
|
@inject IClientBrowserClient ClientClient
|
|
@inject ISnackbar Snackbar
|
|
@inject IDialogService DialogService
|
|
@attribute [Authorize]
|
|
|
|
<PageTitle>세무 프로필</PageTitle>
|
|
|
|
<section class="admin-page-hero">
|
|
<div>
|
|
<MudText Typo="Typo.caption" Class="admin-eyebrow">CRM & 세무관리</MudText>
|
|
<MudText Typo="Typo.h4" Class="admin-page-title">세무 프로필</MudText>
|
|
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객별 세무 프로필, 신고 일정, 위험도 추적</MudText>
|
|
</div>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OpenCreateDialog" StartIcon="@Icons.Material.Filled.Add">
|
|
새 프로필 추가
|
|
</MudButton>
|
|
</section>
|
|
|
|
@if (profiles == null)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" Class="mt-4" />
|
|
}
|
|
else if (profiles.Count == 0)
|
|
{
|
|
<MudAlert Severity="Severity.Info" Class="mt-4">세무 프로필이 없습니다.</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudDataGrid T="TaxProfile"
|
|
Items="@profiles"
|
|
Dense="true"
|
|
Hover="true"
|
|
Striped="true"
|
|
Virtualize="true"
|
|
RowsPerPage="30"
|
|
Class="admin-grid mt-4">
|
|
<Columns>
|
|
<PropertyColumn Property="x => x.Id" Title="ID" Sortable="true" />
|
|
<TemplateColumn Title="고객">
|
|
<CellTemplate>
|
|
@if (clientMap.TryGetValue(context.Item.ClientId, out var clientName))
|
|
{
|
|
<MudLink Href="@($"/taxbaik/admin/clients/{context.Item.ClientId}")" Color="Color.Primary">
|
|
@clientName
|
|
</MudLink>
|
|
}
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
<PropertyColumn Property="x => x.BusinessType" Title="사업 유형" />
|
|
<TemplateColumn Title="위험도">
|
|
<CellTemplate>
|
|
<MudChip Size="Size.Small" Color="@GetRiskColor(context.Item.TaxRiskLevel)" Variant="Variant.Filled">
|
|
@context.Item.TaxRiskLevel
|
|
</MudChip>
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
<TemplateColumn Title="다음 신고">
|
|
<CellTemplate>
|
|
@if (context.Item.NextFilingDueDate.HasValue)
|
|
{
|
|
@context.Item.NextFilingDueDate.Value.ToString("yyyy-MM-dd")
|
|
}
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
<TemplateColumn Title="작업" Sortable="false">
|
|
<CellTemplate>
|
|
<MudButtonGroup Size="Size.Small" Variant="Variant.Outlined">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" OnClick="@(async () => await OpenEditDialog(context.Item))" />
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="@(async () => await DeleteProfile(context.Item.Id))" />
|
|
</MudButtonGroup>
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
</Columns>
|
|
</MudDataGrid>
|
|
}
|
|
|
|
<!-- Create/Edit Dialog -->
|
|
<MudDialog @bind-IsVisible="isDialogOpen" Options="new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true }">
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">@(isEditMode ? "세무 프로필 수정" : "새 세무 프로필 추가")</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
<MudForm @ref="form">
|
|
<MudSelect T="int" @bind-Value="profileForm.ClientId" Label="고객" Required="true" Variant="Variant.Outlined" FullWidth="true" Class="mb-4">
|
|
@foreach (var client in clients)
|
|
{
|
|
<MudSelectItem Value="@client.Id">@client.CompanyName</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
<MudTextField T="string" @bind-Value="profileForm.BusinessType" Label="사업 유형" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" />
|
|
<MudSelect T="string" @bind-Value="profileForm.TaxRiskLevel" Label="위험도" Variant="Variant.Outlined" FullWidth="true" Class="mb-4">
|
|
<MudSelectItem Value="@("low")">낮음</MudSelectItem>
|
|
<MudSelectItem Value="@("normal")">보통</MudSelectItem>
|
|
<MudSelectItem Value="@("high")">높음</MudSelectItem>
|
|
</MudSelect>
|
|
<MudDatePicker @bind-Date="profileForm.NextFilingDueDate" Label="다음 신고 예정일" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" />
|
|
<MudTextField T="string" @bind-Value="profileForm.SpecialNotes" Label="특수 사항" Variant="Variant.Outlined" FullWidth="true" Lines="2" />
|
|
</MudForm>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="CloseDialog">취소</MudButton>
|
|
<MudButton Color="Color.Primary" OnClick="SaveProfile">저장</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
private List<TaxProfile>? profiles;
|
|
private List<Client> clients = [];
|
|
private Dictionary<int, string> clientMap = new();
|
|
private MudForm? form;
|
|
private bool isDialogOpen;
|
|
private bool isEditMode;
|
|
private TaxProfile? editingProfile;
|
|
private TaxProfileForm profileForm = new();
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await LoadData();
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private async Task LoadData()
|
|
{
|
|
try
|
|
{
|
|
profiles = await TaxProfileClient.GetAllAsync();
|
|
var (clientItems, _) = await ClientClient.GetPagedAsync();
|
|
clients = clientItems.ToList();
|
|
clientMap = clients.ToDictionary(c => c.Id, c => c.CompanyName ?? "");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"데이터 로드 실패: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private void OpenCreateDialog()
|
|
{
|
|
isEditMode = false;
|
|
editingProfile = null;
|
|
profileForm = new();
|
|
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;
|
|
}
|
|
|
|
private async Task SaveProfile()
|
|
{
|
|
try
|
|
{
|
|
if (isEditMode)
|
|
{
|
|
await TaxProfileClient.UpdateAsync(
|
|
editingProfile!.Id,
|
|
profileForm.BusinessType,
|
|
null,
|
|
profileForm.NextFilingDueDate,
|
|
profileForm.TaxRiskLevel);
|
|
Snackbar.Add("세무 프로필이 업데이트되었습니다.", Severity.Success);
|
|
}
|
|
else
|
|
{
|
|
var newId = await TaxProfileClient.CreateAsync(
|
|
profileForm.ClientId,
|
|
profileForm.BusinessType);
|
|
if (newId > 0)
|
|
{
|
|
Snackbar.Add("세무 프로필이 추가되었습니다.", Severity.Success);
|
|
}
|
|
}
|
|
CloseDialog();
|
|
await LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private async Task DeleteProfile(int id)
|
|
{
|
|
var parameters = new DialogParameters();
|
|
parameters.Add("Title", "삭제 확인");
|
|
parameters.Add("Message", "이 세무 프로필을 삭제하시겠습니까?");
|
|
|
|
var dialog = await DialogService.ShowAsync<ConfirmDialog>("", parameters);
|
|
var result = await dialog.Result;
|
|
|
|
if (result?.Canceled ?? true)
|
|
return;
|
|
|
|
try
|
|
{
|
|
await TaxProfileClient.DeleteAsync(id);
|
|
Snackbar.Add("세무 프로필이 삭제되었습니다.", Severity.Success);
|
|
await LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private void CloseDialog()
|
|
{
|
|
isDialogOpen = false;
|
|
isEditMode = false;
|
|
editingProfile = null;
|
|
profileForm = new();
|
|
}
|
|
|
|
private Color GetRiskColor(string riskLevel) => riskLevel switch
|
|
{
|
|
"high" => Color.Error,
|
|
"normal" => Color.Warning,
|
|
"low" => Color.Success,
|
|
_ => Color.Default
|
|
};
|
|
|
|
private 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; }
|
|
}
|
|
}
|