feat: implement CRM and tax accounting specialized services and repositories
TaxBaik CI/CD / build-and-deploy (push) Successful in 49s

Phase 2: Repository Implementation (Dapper)
- TaxProfileRepository: tax profile CRUD + risk level analysis + filing due dates
- TaxFilingScheduleRepository: schedule tracking + upcoming due dates + completion marking
- ConsultingActivityRepository: CRM activity history + pending followups + consultant tracking
- ContractRepository: contract lifecycle + active contracts + expiring alerts + MRR calculation
- RevenueTrackingRepository: invoice tracking + payment status + revenue analysis

Phase 3: Service Layer (Business Logic)
- TaxProfileService: profile creation, risk assessment, upcoming filing detection
- TaxFilingScheduleService: schedule management, deadline tracking, completion workflow
- ConsultingActivityService: activity logging, followup management, consultant productivity
- ContractService: contract management, MRR calculation, expiring contract alerts
- RevenueTrackingService: invoice creation, payment tracking, revenue analytics

Phase 4: API Controller (REST Endpoints)
- TaxProfileController: CRUD operations + high-risk filtering + upcoming filings query

Architecture Highlights:
- SOLID principles: each layer has clear responsibility
- Dapper-based repositories for data access
- Comprehensive service layer for business logic
- RESTful API design with proper error handling
- Ready for Blazor UI implementation and deployment

Database Migration V015 executed:
- 5 new specialized tables for CRM and tax accounting
- Appropriate indexes for query performance
- Foreign key constraints for data integrity
This commit is contained in:
2026-06-28 16:58:23 +09:00
parent ea40e5c002
commit c2955ad02f
13 changed files with 710 additions and 0 deletions
@@ -20,6 +20,11 @@ public static class DependencyInjection
services.AddScoped<ConsultationService>();
services.AddScoped<TaxFilingService>();
services.AddScoped<CompanyService>();
services.AddScoped<TaxProfileService>();
services.AddScoped<TaxFilingScheduleService>();
services.AddScoped<ConsultingActivityService>();
services.AddScoped<ContractService>();
services.AddScoped<RevenueTrackingService>();
return services;
}
}
@@ -0,0 +1,47 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class ConsultingActivityService(IConsultingActivityRepository repository)
{
public async Task<int> CreateAsync(int clientId, string activityType, DateTime activityDate,
string description, int? consultantId = null, DateTime? nextFollowupDate = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(activityType))
throw new ValidationException("활동 유형을 입력하세요.");
if (string.IsNullOrWhiteSpace(description))
throw new ValidationException("활동 내용을 입력하세요.");
var activity = new ConsultingActivity
{
ClientId = clientId,
ActivityType = activityType.Trim(),
ActivityDate = activityDate,
Description = description.Trim(),
AssignedConsultantId = consultantId,
NextFollowupDate = nextFollowupDate,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(activity, ct);
}
public async Task<IEnumerable<ConsultingActivity>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<ConsultingActivity>> GetPendingFollowupsAsync(CancellationToken ct = default) =>
await repository.GetPendingFollowupsAsync(ct);
public async Task<IEnumerable<ConsultingActivity>> GetConsultantActivityAsync(int consultantId, DateTime fromDate, CancellationToken ct = default) =>
await repository.GetByConsultantAsync(consultantId, fromDate, ct);
public async Task UpdateAsync(int id, string? outcome, DateTime? nextFollowupDate, CancellationToken ct = default)
{
var activity = new ConsultingActivity { Id = id, Outcome = outcome, NextFollowupDate = nextFollowupDate, UpdatedAt = DateTime.UtcNow };
await repository.UpdateAsync(activity, ct);
}
}
@@ -0,0 +1,50 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class ContractService(IContractRepository repository)
{
public async Task<int> CreateAsync(int clientId, string contractNumber, string serviceType,
DateTime startDate, decimal? monthlyFee = null, decimal? totalAmount = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(contractNumber))
throw new ValidationException("계약 번호를 입력하세요.");
if (string.IsNullOrWhiteSpace(serviceType))
throw new ValidationException("서비스 유형을 입력하세요.");
var contract = new Contract
{
ClientId = clientId,
ContractNumber = contractNumber.Trim(),
ServiceType = serviceType.Trim(),
ContractDate = DateTime.Today,
StartDate = startDate,
MonthlyFee = monthlyFee,
TotalAmount = totalAmount,
Status = "active",
PaymentStatus = "pending",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(contract, ct);
}
public async Task<Contract?> GetByIdAsync(int id, CancellationToken ct = default) =>
await repository.GetByIdAsync(id, ct);
public async Task<IEnumerable<Contract>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<Contract>> GetActiveContractsAsync(CancellationToken ct = default) =>
await repository.GetActiveContractsAsync(ct);
public async Task<IEnumerable<Contract>> GetExpiringContractsAsync(int daysAhead = 30, CancellationToken ct = default) =>
await repository.GetExpiringContractsAsync(daysAhead, ct);
public async Task<decimal> GetMonthlyRecurringRevenueAsync(CancellationToken ct = default) =>
await repository.GetMonthlyRecurringRevenueAsync(ct);
}
@@ -0,0 +1,52 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class RevenueTrackingService(IRevenueTrackingRepository repository)
{
public async Task<int> CreateAsync(int clientId, string invoiceNumber, DateTime invoiceDate,
decimal amount, string? serviceType = null, DateTime? dueDate = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(invoiceNumber))
throw new ValidationException("인보이스 번호를 입력하세요.");
if (amount <= 0)
throw new ValidationException("금액은 0보다 커야 합니다.");
var revenue = new RevenueTracking
{
ClientId = clientId,
InvoiceNumber = invoiceNumber.Trim(),
InvoiceDate = invoiceDate,
Amount = amount,
ServiceType = string.IsNullOrWhiteSpace(serviceType) ? null : serviceType.Trim(),
DueDate = dueDate,
PaymentStatus = "pending",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(revenue, ct);
}
public async Task<IEnumerable<RevenueTracking>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<RevenueTracking>> GetPendingPaymentsAsync(CancellationToken ct = default) =>
await repository.GetPendingPaymentsAsync(ct);
public async Task<IEnumerable<RevenueTracking>> GetMonthlyRevenueAsync(DateTime month, CancellationToken ct = default)
{
var startDate = new DateTime(month.Year, month.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
return await repository.GetByDateRangeAsync(startDate, endDate, ct);
}
public async Task MarkPaidAsync(int id, DateTime paymentDate, CancellationToken ct = default) =>
await repository.MarkPaidAsync(id, paymentDate, ct);
public async Task<decimal> GetTotalRevenueAsync(DateTime startDate, DateTime endDate, CancellationToken ct = default) =>
await repository.GetTotalRevenueAsync(startDate, endDate, ct);
}
@@ -0,0 +1,50 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class TaxFilingScheduleService(ITaxFilingScheduleRepository repository)
{
public async Task<int> CreateAsync(int clientId, string filingType, DateTime dueDate, int filingYear,
int? assignedToId = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(filingType))
throw new ValidationException("신고 유형을 입력하세요.");
if (dueDate < DateTime.Today)
throw new ValidationException("마감일은 오늘 이후여야 합니다.");
var schedule = new TaxFilingSchedule
{
ClientId = clientId,
FilingType = filingType.Trim(),
DueDate = dueDate,
FilingYear = filingYear,
Status = "pending",
AssignedToId = assignedToId,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(schedule, ct);
}
public async Task<TaxFilingSchedule?> GetByIdAsync(int id, CancellationToken ct = default) =>
await repository.GetByIdAsync(id, ct);
public async Task<IEnumerable<TaxFilingSchedule>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<TaxFilingSchedule>> GetUpcomingDuesAsync(int daysAhead = 30, CancellationToken ct = default) =>
await repository.GetUpcomingDuesAsync(daysAhead, ct);
public async Task MarkCompletedAsync(int id, CancellationToken ct = default) =>
await repository.MarkCompletedAsync(id, ct);
public async Task<int> GetPendingCountAsync(CancellationToken ct = default)
{
var pending = await repository.GetByStatusAsync("pending", ct);
return pending.Count();
}
}
@@ -0,0 +1,58 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class TaxProfileService(ITaxProfileRepository repository)
{
public async Task<int> CreateAsync(int clientId, string? businessType, string? businessRegistration = null,
string? accountingMethod = null, DateTime? establishmentDate = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(businessType))
throw new ValidationException("사업 유형을 입력하세요.");
var profile = new TaxProfile
{
ClientId = clientId,
BusinessType = businessType.Trim(),
BusinessRegistration = string.IsNullOrWhiteSpace(businessRegistration) ? null : businessRegistration.Trim(),
EstablishmentDate = establishmentDate,
AccountingMethod = string.IsNullOrWhiteSpace(accountingMethod) ? null : accountingMethod.Trim(),
TaxRiskLevel = "normal",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(profile, ct);
}
public async Task<TaxProfile?> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task UpdateAsync(int profileId, string? businessType, string? accountingMethod,
DateTime? nextFilingDueDate, string taxRiskLevel = "normal", CancellationToken ct = default)
{
var profile = new TaxProfile { Id = profileId };
if (!string.IsNullOrWhiteSpace(businessType))
profile.BusinessType = businessType.Trim();
if (!string.IsNullOrWhiteSpace(accountingMethod))
profile.AccountingMethod = accountingMethod.Trim();
profile.NextFilingDueDate = nextFilingDueDate;
profile.TaxRiskLevel = taxRiskLevel;
profile.UpdatedAt = DateTime.UtcNow;
await repository.UpdateAsync(profile, ct);
}
public async Task<IEnumerable<TaxProfile>> GetHighRiskProfilesAsync(CancellationToken ct = default) =>
await repository.GetByRiskLevelAsync("high", ct);
public async Task<IEnumerable<TaxProfile>> GetUpcomingFilingDuesAsync(int daysAhead = 30, CancellationToken ct = default)
{
var startDate = DateTime.Today;
var endDate = startDate.AddDays(daysAhead);
return await repository.GetUpcomingFilingDuesAsync(startDate, endDate, ct);
}
}