Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions StorageProject.Api/Endpoints/StaffEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,6 @@ public static RouteGroupBuilder MapStaffEndpoints(this IEndpointRouteBuilder app
});

// 8. Access Credentials Management (UC08)
group.MapPost("/credentials/{id}/revoke", async (string id, ClaimsPrincipal user, IStaffService staffService, CancellationToken ct) =>
{
var role = user.GetUserRole();
if (role.Equals("CUSTOMER", StringComparison.OrdinalIgnoreCase)) return Results.Forbid();

try
{
var userId = user.GetUserId();
await staffService.RevokeCredentialAsync(userId, id, ct);
return Results.Ok(new { message = "Thu hồi phương thức truy cập thành công." });
}
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException)
{
return Results.BadRequest(new { error = ex.Message });
}
});

group.MapPost("/credentials/reissue", async (ReissueCredentialRequest request, ClaimsPrincipal user, IStaffService staffService, CancellationToken ct) =>
{
var role = user.GetUserRole();
Expand Down
1 change: 0 additions & 1 deletion StorageProject.Core/Interfaces/IStaffService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ public interface IStaffService
Task SubmitReturnInspectionAsync(long userId, string id, ReturnInspectionRequest request, CancellationToken ct = default);
Task AddTicketResponseAsync(long userId, string id, TicketResponseRequest request, CancellationToken ct = default);
Task UpdateUnitStatusAsync(long userId, string id, UpdateUnitStatusRequest request, CancellationToken ct = default);
Task RevokeCredentialAsync(long userId, string id, CancellationToken ct = default);
Task ReissueCredentialAsync(long userId, ReissueCredentialRequest request, CancellationToken ct = default);
}
14 changes: 10 additions & 4 deletions StorageProject.Core/Policies/RefundPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,23 @@ public static decimal UnusedRent(decimal rentPaid, DateOnly start, DateOnly end,
/// Phí quá hạn theo tham số chính sách OVERDUE (B02): PERCENTAGE = % tiền thuê tháng mỗi ngày trễ,
/// FIXED = số tiền cố định mỗi ngày trễ. Thiếu hoặc không hỗ trợ cách tính thì báo lỗi, không tự đặt mức phí.
/// </summary>
public static decimal OverdueFeeFor(string? calculationType, decimal? value, decimal monthlyRate, int overdueDays)
public static decimal OverdueFeeFor(string? calculationType, decimal? value, decimal baseAmount, int overdueDays, decimal? maxCap = null)
{
if (overdueDays <= 0) return 0;
if (value is not decimal v || v < 0)
throw new InvalidOperationException("Chưa cấu hình chính sách phí quá hạn (B02). Cần cấu hình trước khi tính hoàn cọc.");
return calculationType switch
var fee = calculationType switch
{
"PERCENTAGE" => Money(monthlyRate * v / 100m * overdueDays),
"DEPOSIT_PERCENT_PER_DAY" => Math.Min(baseAmount, Money(baseAmount * v / 100m * overdueDays)),
"PERCENTAGE" => Money(baseAmount * v / 100m * overdueDays),
"FIXED" => Money(v * overdueDays),
_ => throw new InvalidOperationException("Chính sách phí quá hạn (B02) phải tính theo % tiền thuê tháng hoặc số tiền cố định mỗi ngày.")
_ => throw new InvalidOperationException("Chính sách phí quá hạn (B02) phải tính theo % tiền cọc mỗi ngày, % tiền thuê tháng hoặc số tiền cố định mỗi ngày.")
};
if (maxCap.HasValue && maxCap.Value >= 0)
{
fee = Math.Min(fee, maxCap.Value);
}
return fee;
}

private static decimal Money(decimal v) => Math.Round(v, 0, MidpointRounding.AwayFromZero);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public void Configure(EntityTypeBuilder<Policy> b)
t.HasCheckConstraint("CK_policies_policy_type",
"[PolicyType] IN ('DEPOSIT','RENEWAL','CANCELLATION','RETURN','OVERDUE','EXTRA_FEE','DISCOUNT','FEE_WAIVER','PRICE_RANGE')");
t.HasCheckConstraint("CK_policies_calculation_type",
"[CalculationType] IS NULL OR [CalculationType] IN ('FIXED','PERCENTAGE','RANGE','RULE')");
"[CalculationType] IS NULL OR [CalculationType] IN ('FIXED','PERCENTAGE','RANGE','RULE','DEPOSIT_PERCENT_PER_DAY')");
t.HasCheckConstraint("CK_policies_status", "[Status] IN ('DRAFT','ACTIVE','INACTIVE','EXPIRED')");
});
b.HasKey(p => p.PolicyId);
b.Property(p => p.PolicyId).UseIdentityColumn();
b.Property(p => p.PolicyName).IsRequired().HasMaxLength(150);
b.Property(p => p.PolicyType).IsRequired().HasMaxLength(30);
b.Property(p => p.CalculationType).HasMaxLength(20);
b.Property(p => p.CalculationType).HasMaxLength(30);
b.Property(p => p.Value).HasColumnType("decimal(15,2)");
b.Property(p => p.MinValue).HasColumnType("decimal(15,2)");
b.Property(p => p.MaxValue).HasColumnType("decimal(15,2)");
Expand Down
6 changes: 3 additions & 3 deletions StorageProject.Infrastructure/Data/DbSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ public static async Task EnsurePoliciesAsync(AppDbContext context, long adminUse
{
PolicyName = "Phí phạt quá hạn thanh toán",
PolicyType = "OVERDUE",
CalculationType = "PERCENTAGE",
Value = 5.0m, // 5% tiền thuê tháng mỗi ngày trả kho trễ (D27)
RuleDescription = "Phí quá hạn: 5% tiền thuê tháng cho mỗi ngày trả kho trễ, trừ vào tiền cọc",
CalculationType = "DEPOSIT_PERCENT_PER_DAY",
Value = 5.0m, // 5% cọc ban đầu mỗi ngày trễ (D32)
RuleDescription = "Phí quá hạn: 5% tiền cọc ban đầu cho mỗi ngày trả kho trễ, tối đa 100% cọc, trừ vào tiền cọc",
EffectiveFrom = DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-30)),
Status = "ACTIVE",
CreatedAt = DateTime.UtcNow,
Expand Down
Loading