Solution A: Core Function Dependency — After Implementation
Solution A: Core Function Dependency — After Implementation
ภาพนี้แสดงว่าหลัง implement Solution A แต่ละ Flow เรียก core function อะไรบ้าง
เปรียบเทียบกับ4.legacy-core-function-dependency.mdเพื่อดูว่าเปลี่ยนอะไรบ้าง
🔵 = function ใหม่ที่ Solution A เพิ่ม · 🔴 = function เดิมที่ถูกแก้
ภาพรวม: ทุก Flow ลงมาที่ Core เดียวกัน
Flow 1–9 ยังใช้ core เดิมทั้งหมด
Solution A เพิ่ม branch ใหม่ใน Flow 2 โดยไม่แตะ path ของ Flow อื่น
⚠️ = path แยก ไม่ผ่านupdateMemberTier()
flowchart LR
subgraph FLOWS ["Flows (Entry Points)"]
direction TB
F1["Flow1 · Sales Txn"]
F2["Flow2 · Refund/Void 🔴"]
F3A["Flow3A · Batch Accum"]
F3B["Flow3B · Batch Recalc ⚠️"]
F4["Flow4 · Maintain Tier"]
F5["Flow5 · Reconcile"]
F6p["Flow6 · Admin ADD"]
F6m["Flow6 · Admin DEDUCT 🔴"]
F7["Flow7 · Co-Brand"]
F8["Flow8 · Staff Exit"]
F9e["Flow9 · Import existing"]
F9n["Flow9 · Import new ⚠️"]
end
subgraph DECIDE ["Tier Decision"]
CTU["calculateTierToUpgrade()"]
CTA["calculateTierAdjustment()"]
CTANEW["🔵 calculateTierAdjustmentWithNewLogic()"]
CNT["calculateNewTier()"]
CNTM["calculateNewTierFromMaintainSpending()"]
CNM["calculateNewMinimumTier()"]
end
subgraph MUTATE ["Core Mutation"]
UMT["🔴 updateMemberTier()"]
PST["processSpendingAndTierUpdate() F3B only"]
CR["create() F9 new only"]
end
subgraph CALC ["Core Calculation"]
CAS["calculateAccumulateSpending()"]
CAMS["calculateAccumulateMaintainSpending()"]
CATL["🔵 calculateAccumTierLogicSpending()"]
CPMT["🔵 calculatePostUpTierMaintainSpending()"]
CA["🔴 calculateAccumulate() root of everything"]
end
subgraph RESOLVE ["Tier Date Resolution (NEW)"]
FPT["🔵 findPreviousTierInfo()"]
FQT["🔵 findQualifyingTransactionDate()"]
end
%% Upgrade path (green) — ไม่เปลี่ยน
F1 --> CTU --> UMT
F6p --> CTU
%% Downgrade path Legacy (gray) — ยังอยู่แต่ไม่ใช้ใน Flow 2 แล้ว
F5 --> CTA --> UMT
%% Downgrade path NEW (red) — Flow 2 ใช้ path ใหม่
F2 --> CTANEW --> UMT
F6m --> CTANEW
%% Co-Brand / Staff path (purple)
F7 --> CNM
F7 --> CNT --> UMT
F8 --> CNT
%% Maintain path (blue)
F4 --> CNM
F4 --> CNTM --> UMT
%% Other paths
F9e --> UMT
F3A --> CAS
%% Isolated paths (orange)
F3B --> PST
F9n --> CR
%% New logic internal links
CTANEW --> CATL
CTANEW --> FPT
CTANEW --> FQT
CTANEW --> CPMT
%% Calculation links
CTU --> CAS
CTA --> CAS
CNT --> CAS
UMT --> CAMS
CATL --> CA
CAS --> CA
CAMS --> CA
%% Node styles — Flows
style F1 fill:#1e3a5f,color:#fff
style F2 fill:#5a1a1a,color:#fff
style F3A fill:#1e3a5f,color:#fff
style F3B fill:#1e3a5f,color:#fff
style F4 fill:#1e3a5f,color:#fff
style F5 fill:#1e3a5f,color:#fff
style F6p fill:#1e3a5f,color:#fff
style F6m fill:#5a1a1a,color:#fff
style F7 fill:#1e3a5f,color:#fff
style F8 fill:#1e3a5f,color:#fff
style F9e fill:#1e3a5f,color:#fff
style F9n fill:#1e3a5f,color:#fff
%% Node styles — Decision
style CTU fill:#5c4a00,color:#fff
style CTA fill:#5c4a00,color:#fff
style CTANEW fill:#003d5c,color:#fff
style CNT fill:#5c4a00,color:#fff
style CNTM fill:#5c4a00,color:#fff
style CNM fill:#5c4a00,color:#fff
%% Node styles — Mutation
style UMT fill:#7a0000,color:#fff
style PST fill:#7a4400,color:#fff
style CR fill:#7a4400,color:#fff
%% Node styles — Calculation
style CAS fill:#004d00,color:#fff
style CAMS fill:#004d00,color:#fff
style CATL fill:#003d5c,color:#fff
style CPMT fill:#003d5c,color:#fff
style CA fill:#004d00,color:#fff
%% Node styles — Resolve (new)
style FPT fill:#003d5c,color:#fff
style FQT fill:#003d5c,color:#fff
%% Link styles — Upgrade (green)
linkStyle 0 stroke:#00cc00,stroke-width:2px
linkStyle 1 stroke:#00cc00,stroke-width:2px
linkStyle 2 stroke:#00cc00,stroke-width:2px
%% Link styles — Legacy downgrade (gray, still used by Flow5)
linkStyle 3 stroke:#888,stroke-width:1px,stroke-dasharray:4
linkStyle 4 stroke:#888,stroke-width:1px,stroke-dasharray:4
%% Link styles — New downgrade (red)
linkStyle 5 stroke:#ff4444,stroke-width:2px
linkStyle 6 stroke:#ff4444,stroke-width:2px
linkStyle 7 stroke:#ff4444,stroke-width:2px
%% Link styles — Co-Brand/Staff (purple)
linkStyle 8 stroke:#cc66ff,stroke-width:2px
linkStyle 9 stroke:#cc66ff,stroke-width:2px
linkStyle 10 stroke:#cc66ff,stroke-width:2px
linkStyle 11 stroke:#cc66ff,stroke-width:2px
%% Link styles — Maintain (blue)
linkStyle 12 stroke:#4488ff,stroke-width:2px
linkStyle 13 stroke:#4488ff,stroke-width:2px
linkStyle 14 stroke:#4488ff,stroke-width:2px
%% Link styles — Other (gray)
linkStyle 15 stroke:#888,stroke-width:1px
linkStyle 16 stroke:#888,stroke-width:1px
%% Link styles — Isolated (orange)
linkStyle 17 stroke:#ff8800,stroke-width:2px
linkStyle 18 stroke:#ff8800,stroke-width:2px
%% Link styles — New logic internal (cyan)
linkStyle 19 stroke:#00cccc,stroke-width:2px
linkStyle 20 stroke:#00cccc,stroke-width:2px
linkStyle 21 stroke:#00cccc,stroke-width:2px
linkStyle 22 stroke:#00cccc,stroke-width:2px
%% Link styles — Calculation (gray dashed)
linkStyle 23 stroke:#aaa,stroke-width:2px,stroke-dasharray:5
linkStyle 24 stroke:#aaa,stroke-width:2px,stroke-dasharray:5
linkStyle 25 stroke:#aaa,stroke-width:2px,stroke-dasharray:5
linkStyle 26 stroke:#aaa,stroke-width:2px,stroke-dasharray:5
linkStyle 27 stroke:#aaa,stroke-width:2px,stroke-dasharray:5
linkStyle 28 stroke:#aaa,stroke-width:2px,stroke-dasharray:5
linkStyle 29 stroke:#aaa,stroke-width:2px,stroke-dasharray:5
สี node: 🔵 Flows · 🟡 Decision · 🔴 Mutation · 🟢 Calculation · 🔵 New (Solution A)
สีเส้น: 🟢 upgrade · 🔴 new downgrade · ⚫ legacy downgrade (เส้นประ) · 🔵 maintain · 🟣 co-brand/staff · 🟠 isolated · 🩵 new logic internal
เปรียบเทียบ Legacy vs Solution A: Flow 2 path
flowchart LR
subgraph LEGACY ["Legacy — Flow 2"]
ANR_L["addNewRefundSalesTransaction()"]
CTA_L["calculateTierAdjustment()"]
RESET["setAccumulateMaintainSpending(0)"]
SETNOW["tierStartedAt = now"]
UMT_L["updateMemberTier()"]
ANR_L --> CTA_L --> UMT_L
UMT_L --> RESET
UMT_L --> SETNOW
end
subgraph NEW ["Solution A — Flow 2"]
ANR_N["addNewRefundSalesTransaction() 🔴"]
GUARD["Guard: originalSale > tierStartedAt? 🔵"]
SKIP["ไม่ down-tier"]
CTANEW_N["calculateTierAdjustmentWithNewLogic() 🔵"]
CATL_N["calculateAccumTierLogicSpending() 🔵"]
FPT_N["findPreviousTierInfo() 🔵"]
FQT_N["findQualifyingTransactionDate() 🔵"]
CPMT_N["calculatePostUpTierMaintainSpending() 🔵"]
UMT_N["updateMemberTier()"]
ANR_N --> GUARD
GUARD -->|"หลัง up-tier"| SKIP
GUARD -->|"ก่อน/ตอน up-tier"| CTANEW_N
CTANEW_N --> CATL_N
CTANEW_N --> FPT_N
CTANEW_N --> FQT_N
CTANEW_N --> CPMT_N
CTANEW_N --> UMT_N
end
style ANR_L fill:#5a1a1a,color:#fff
style ANR_N fill:#5a1a1a,color:#fff
style GUARD fill:#003d5c,color:#fff
style CTANEW_N fill:#003d5c,color:#fff
style CATL_N fill:#003d5c,color:#fff
style FPT_N fill:#003d5c,color:#fff
style FQT_N fill:#003d5c,color:#fff
style CPMT_N fill:#003d5c,color:#fff
style SKIP fill:#1a3a1a,color:#fff
style UMT_L fill:#7a0000,color:#fff
style UMT_N fill:#7a0000,color:#fff
style RESET fill:#7a4400,color:#fff
style SETNOW fill:#7a4400,color:#fff
style CTA_L fill:#5c4a00,color:#fff
Impact Matrix: แก้ Function นี้ → กระทบ Flow ไหน
| Function | Flow1 | Flow2 | Flow3A | Flow3B | Flow4 | Flow5 | Flow6+ | Flow6- | Flow7 | Flow8 | Flow9e | Flow9n | Impact |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
calculateAccumulate() |
✅ | ✅ | ✅ | — | — | ✅ | ✅ | ✅ | ✅ | ✅ | — | — | 🔴 CRITICAL |
calculateAccumulateSpending() |
✅ | ✅ | ✅ | — | — | ✅ | ✅ | ✅ | ✅ | ✅ | — | — | 🔴 CRITICAL |
updateMemberTier() |
✅ | ✅ | — | — | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | — | 🔴 CRITICAL |
addNewRefundSalesTransaction() 🔴 |
— | ✅ | — | — | — | — | — | ✅ | — | — | — | — | 🟠 HIGH |
calculateTierAdjustmentWithNewLogic() 🔵 |
— | ✅ | — | — | — | — | — | ✅ | — | — | — | — | 🟠 HIGH |
calculateAccumTierLogicSpending() 🔵 |
— | ✅ | — | — | — | — | — | ✅ | — | — | — | — | 🟠 HIGH |
findPreviousTierInfo() 🔵 |
— | ✅ | — | — | — | — | — | ✅ | — | — | — | — | 🟠 HIGH |
findQualifyingTransactionDate() 🔵 |
— | ✅ | — | — | — | — | — | ✅ | — | — | — | — | 🟠 HIGH |
calculatePostUpTierMaintainSpending() 🔵 |
— | ✅ | — | — | — | — | — | ✅ | — | — | — | — | 🟠 HIGH |
calculateTierAdjustment() |
— | — | — | — | — | ✅ | — | — | — | — | — | — | 🟡 ISOLATED |
calculateTierToUpgrade() |
✅ | — | — | — | — | — | ✅ | — | — | — | — | — | 🟠 HIGH |
🔵 = function ใหม่ที่ Solution A เพิ่ม
🔴 = function เดิมที่ถูกแก้
Flow6+ = Admin ADD · Flow6- = Admin DEDUCT
สรุป: สิ่งที่เปลี่ยนจาก Legacy
| Legacy | Solution A | |
|---|---|---|
| Flow 2 ใช้ tier decision | calculateTierAdjustment() |
calculateTierAdjustmentWithNewLogic() 🔵 |
| Flow 2 คำนวณ accum | rolling 24mo | calculateAccumTierLogicSpending() 🔵 |
| Flow 2 maintain หลัง down | reset = 0 | calculatePostUpTierMaintainSpending() 🔵 |
| Flow 2 หา tier dates | tierStartedAt = now |
findPreviousTierInfo() + findQualifyingTransactionDate() 🔵 |
| Flow 5 ใช้ tier decision | calculateTierAdjustment() |
calculateTierAdjustment() (ไม่เปลี่ยน) |
| Functions ที่แตะ | — | 1 แก้ + 5 เพิ่ม ใน member.entity.ts |
| Files ที่แตะ | — | member.entity.ts + recent-sales-transaction.service.ts |