Booking — Discount rule
Discount rule là quy tắc giảm giá tự động áp vào booking khi pricing: sibling (anh chị em), early bird, theo số attendee, theo profile… Đây là rule về giá, khác hẳn combine booking rule (chỉ về phạm vi edit).
Entity gốc: Tux/src/Tux.Data/Models/Discount.cs. Enums: Tux/src/Tux.Core/Enums/DiscountType.cs.
Phân loại discount (DiscountType)
| Type | Mã | Ý nghĩa |
|---|---|---|
FamilyDiscount | 1 | Giảm theo gia đình (sibling). |
Booking | 2 | Giảm theo booking (early bird). |
Profile | 3 | Giảm theo profile account/attendee. |
Manual | 9 | Giảm thủ công. |
Điều kiện áp (DiscountCondition)
| Condition | Mã | Khi nào đủ điều kiện |
|---|---|---|
SiblingDiscountBySession | 1 | Đủ số anh chị em theo session; áp cho mọi attendee trong billing. |
SiblingDiscountByTermProgramSet | 2 | Đủ số anh chị em theo TermProgramSet. |
AttendeeDiscountBySession | 6 | Áp cho attendee trong khoảng (vd attendee thứ 2, 3…) theo session. |
AttendeeDiscountByTermProgramSet | 7 | Như trên nhưng theo TermProgramSet. |
EarlyBird | 3 | Đặt trước mốc thời gian course. |
ProfileDiscount | 5 | Account/attendee có trong ProfileDiscount. |
ManualDiscount | 99 | Áp tay. |
MinValue/MaxValue là ngưỡng số lượng (sibling/attendee). ValidFrom/ValidTo giới hạn hiệu lực.
Kiểu giá trị (DiscountValueType)
| Type | Mã | Tính |
|---|---|---|
Percentage | 1 | Total × (1 − DiscountRate). |
FixedAmountPerSession | 2 | Total − DiscountAmount × số session (sàn 0). |
DiscountValueCap giới hạn mức giảm tối đa (nếu có).
Quy tắc chồng discount (DiscountRuleType)
Cấu hình ở ProgramCategory:
| Rule | Mã | Hành vi |
|---|---|---|
Highest | 0 | Chỉ giữ 1 discount cao nhất. |
HighestEachType | 1 | Giữ cao nhất mỗi type (tối đa 3 — khớp 3 slot trên line). |
Mỗi TermBookingOrderLine/TermBookingLine có tối đa 3 slot: DiscountId, Discount2Id, Discount3Id.
Đánh giá & áp ở đâu
| Bước | Code |
|---|---|
| Tính eligibility (preview, state-isolated) | Tux/src/Services/Tux.Service/Calculation/DiscountEligibilityService.cs |
| Helper eligibility in-memory (dùng chung) | .../Calculation/DiscountEligibilityHelpers.cs |
| Áp discount tự động vào order | BookingHelper.ApplyDiscount (.../Helpers/BookingHelper.cs) |
| API quản lý discount | Tux/src/Tux.Api/Controllers/DiscountController.cs |
Luồng: load discount khả dụng cho TermProgramSet (TermProgramSetDiscount) → lọc line đủ điều kiện → nhóm theo TermProgramSet → áp theo rule (Highest / HighestEachType) → ghi slot discount trên line.
Bảng liên quan
| Bảng | Vai trò |
|---|---|
Discount | Định nghĩa rule. |
TermProgramSetDiscount | Discount nào áp cho course nào. |
TermBookingOrderDiscount / TermBookingDiscount | Discount đã áp lên order / booking. |
ProfileDiscount | Cấu hình discount theo account/attendee. |
EnrollmentDiscount | Discount cho subscription enrollment (đường riêng). |
DiscountApplication / DiscountApplicationAllocation | Ghi nhận & phân bổ discount xuống line (audit billing). |
Source type (
DiscountSourceType):Calculated(0),Admin_Applied(1),Customer_Applied(2).
Tiếp theo: Combine booking rule.