Domain Events Catalog
Commands · Events · Queries
Danh mục Commands, Domain Events và Queries đã ghi trên trang này phủ tới AP. Hệ thống hiện có 41 bounded context · 30 Kafka topic — catalog dưới đây mới phủ 22/41 — chưa viết Analytics · CatalogImport · Customs · Documents · EInvoice · Files · FixedAssets · Fx · MasterData · Payroll · Prepaid · Pricing · Reporting · Returns · Sensors · Sites · Subcontracting · Tooling · Warehouse. Nguồn sự thật là CLAUDE.md.
Naming Conventions & Chuẩn Event
| Loại | Pattern | Ví dụ | Tense |
|---|---|---|---|
| Command | VerbNoun | StartProductionOrder | Hiện tại (imperative) |
| Domain Event | NounVerbed | ProductionOrderStarted | Quá khứ (past tense) |
| Query | GetNoun / ListNoun | GetProductionOrderById | Hiện tại |
| Saga | NounSaga | ProductionOrderSaga | Noun |
Kafka Topic Mapping
| Topic | Partition key | Retention | Modules publish |
|---|---|---|---|
production.events | aggregate_id (order_id) | Vĩnh viễn | Production |
quality.events | aggregate_id (inspection_id) | Vĩnh viễn | Quality |
maintenance.events | aggregate_id (wo_id) | Vĩnh viễn | Maintenance |
inventory.events | aggregate_id (material_id) | Vĩnh viễn | Inventory |
finance.events | aggregate_id (ledger_id) | Vĩnh viễn | Finance |
Mọi Domain Event đều được wrap trong envelope trước khi publish lên Kafka. Payload bên trong là event-specific.
{
"eventId": "uuid",
"eventType": "ProductionOrderStarted",
"aggregateType": "ProductionOrder",
"aggregateId": "uuid",
"version": 1,
"occurredAt": "2026-06-29T09:15:00Z",
"correlationId": "uuid",
"causationId": "uuid",
"tenantId": "tenant_abc",
"payload": { /* event-specific data */ }
}
Event Flow tổng thể giữa các Modules
Production Module
| Loại | Tên | Trigger / Mô tả | Topic |
|---|---|---|---|
| Command | CreateProductionOrder | Tạo lệnh sản xuất mới từ kế hoạch | — |
| Command | StartProductionOrder | Operator bắt đầu sản xuất trên máy | — |
| Command | RecordProductionOutput | Ghi nhận số lượng hoàn thành theo ca | — |
| Command | CompleteProductionOrder | Đánh dấu lệnh hoàn thành | — |
| Command | PauseProductionOrder | Tạm dừng (máy hỏng, thiếu NVL) | — |
| Command | CancelProductionOrder | Hủy lệnh sản xuất kèm lý do | — |
| Event | ProductionOrderCreated | Lệnh được tạo thành công | production.events |
| Event | ProductionStarted | Sản xuất bắt đầu; lock NVL ở Inventory | production.events |
| Event | ProductionOutputRecorded | Cập nhật số lượng thực tế | production.events |
| Event | ProductionOrderCompleted | Hoàn thành; trigger Quality + Finance | production.events |
| Event | ProductionOrderPaused | Tạm dừng kèm reason_code | production.events |
| Event | ProductionOrderCancelled | Hủy; release NVL đã reserve | production.events |
| Query | GetProductionOrderById | Chi tiết 1 lệnh | — |
| Query | ListProductionOrders | Danh sách theo filter (status, date, machine) | — |
| Query | GetProductionDashboard | Dashboard tổng hợp theo ngày/ca | — |
| Query | GetMachineUtilization | OEE + utilization theo máy / thời gian | — |
Payload — ProductionOrderCreated
{
"orderId": "uuid",
"orderNumber": "PO-2026-001234",
"productId": "uuid",
"productCode": "FG-001",
"plannedQty": 500,
"unit": "PCS",
"machineId": "uuid",
"machineCode": "MC-01",
"shift": "MORNING",
"plannedStart": "2026-06-30T06:00:00Z",
"plannedEnd": "2026-06-30T14:00:00Z",
"bomVersion": "v2.3",
"materials": [
{ "materialId": "uuid", "code": "RM-001", "qty": 1000, "unit": "KG" }
]
}
Quality Module
| Loại | Tên | Trigger / Mô tả | Topic |
|---|---|---|---|
| Command | CreateQualityInspection | Tạo phiếu kiểm tra cho lô hàng | — |
| Command | RecordInspectionResult | Nhập kết quả đo từng thông số | — |
| Command | SubmitInspectionVerdict | Kết luận PASS / FAIL cho phiếu | — |
| Command | RaiseNonConformance | Tạo phiếu NCR cho sản phẩm không đạt | — |
| Command | DispositionNonConformance | Quyết định xử lý: rework / scrap / accept | — |
| Command | CloseNonConformance | Đóng NCR sau khi verify corrective action | — |
| Event | QualityInspectionCreated | Phiếu kiểm tra được tạo | quality.events |
| Event | InspectionResultRecorded | Kết quả từng thông số được ghi nhận | quality.events |
| Event | InspectionPassed | Lô hàng đạt — trigger nhập kho | quality.events |
| Event | InspectionFailed | Lô hàng không đạt — trigger NCR | quality.events |
| Event | NonConformanceRaised | NCR được tạo kèm defect details | quality.events |
| Event | NonConformanceDispositioned | Quyết định xử lý được đưa ra | quality.events |
| Event | NonConformanceClosed | NCR đã đóng — audit trail complete | quality.events |
| Query | GetInspectionById | Chi tiết phiếu kiểm tra | — |
| Query | GetQualityDashboard | Pass rate, NCR count, top defects | — |
| Query | GetTraceabilityReport | Full traceability theo product lot | — |
Maintenance Module
| Loại | Tên | Trigger / Mô tả | Topic |
|---|---|---|---|
| Command | RegisterAsset | Đăng ký thiết bị / máy mới vào hệ thống | — |
| Command | SchedulePreventiveMaintenance | Lên lịch PM định kỳ | — |
| Command | ReportAssetBreakdown | Operator báo cáo máy hỏng | — |
| Command | CreateWorkOrder | Tạo lệnh công việc bảo trì | — |
| Command | StartWorkOrder | Technician bắt đầu bảo trì | — |
| Command | CompleteWorkOrder | Hoàn thành bảo trì + ghi findings | — |
| Event | AssetRegistered | Tài sản mới được đăng ký | maintenance.events |
| Event | AssetBreakdownReported | Sự cố được báo cáo — trigger CM work order | maintenance.events |
| Event | MaintenanceScheduled | PM được lên lịch | maintenance.events |
| Event | WorkOrderCreated | Lệnh công việc được tạo | maintenance.events |
| Event | WorkOrderStarted | Bảo trì bắt đầu | maintenance.events |
| Event | WorkOrderCompleted | Bảo trì xong — trigger inventory (phụ tùng) + asset update | maintenance.events |
| Event | PredictiveAlertRaised | AI phát hiện dị thường — gợi ý PM sớm | maintenance.events |
| Query | GetAssetHistory | Lịch sử bảo trì đầy đủ của 1 tài sản | — |
| Query | GetMaintenanceDashboard | MTBF, MTTR, pending work orders | — |
| Query | GetUpcomingMaintenanceSchedule | Lịch PM trong 30 ngày tới | — |
Inventory Module
| Loại | Tên | Trigger / Mô tả | Topic |
|---|---|---|---|
| Command | ReserveMaterial | Reserve số lượng NVL cho Production Order | — |
| Command | ReleaseMaterialReservation | Hủy reserve khi lệnh bị cancel | — |
| Command | DeductStock | Trừ tồn kho khi sản xuất hoàn thành | — |
| Command | ReceiveStock | Nhập kho (từ mua hàng hoặc sản xuất) | — |
| Command | TransferStock | Chuyển kho giữa các location | — |
| Command | AdjustStock | Điều chỉnh tồn kho sau kiểm kê | — |
| Event | MaterialReserved | NVL đã được reserve thành công | inventory.events |
| Event | MaterialReservationFailed | Không đủ tồn kho để reserve | inventory.events |
| Event | MaterialReservationReleased | Reserve được hủy | inventory.events |
| Event | StockDeducted | Tồn kho được trừ — trigger Finance | inventory.events |
| Event | StockReceived | Nhập kho thành công | inventory.events |
| Event | StockTransferred | Chuyển kho hoàn thành | inventory.events |
| Event | LowStockAlertRaised | Tồn kho xuống dưới reorder point | inventory.events |
| Query | GetStockLevel | Tồn kho hiện tại theo material + location | — |
| Query | GetStockMovementHistory | Lịch sử xuất nhập tồn | — |
| Query | GetReorderAlerts | Danh sách NVL cần đặt hàng lại | — |
Finance Module
| Loại | Tên | Trigger / Mô tả | Topic |
|---|---|---|---|
| Command | PostCostEntry | Hạch toán chi phí vào sổ cái | — |
| Command | CalculateProductionCost | Tính giá thành sau khi lệnh hoàn thành | — |
| Event | CostEntryPosted | Bút toán đã được ghi nhận | finance.events |
| Event | ProductionCostCalculated | Giá thành đã tính xong | finance.events |
| Query | GetProductionCostReport | Báo cáo giá thành theo lệnh / sản phẩm | — |
| Query | GetCostCenterSummary | Tổng hợp chi phí theo cost center | — |
Auth / IAM Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | RegisterUser | Đăng ký tài khoản mới trong tenant | — |
| Command | Login | Xác thực → trả access token (30 phút) + refresh token (14 ngày) | — |
| Command | RefreshToken | Rotate refresh token; dùng lại token đã revoke → revoke ALL của user | — |
| Command | Logout | Revoke refresh token hiện tại | — |
| Command | AssignRoles | Gán role cho user (Admin, Production, Quality…) | — |
| Command | ChangePassword | Đổi mật khẩu → revoke all refresh tokens | — |
| Command | Activate / Deactivate | Kích hoạt hoặc khoá tài khoản | — |
| Query | GetUser / ListUsers | Tra cứu thông tin user trong tenant | — |
Auth dùng bảng users + refresh_tokens (SHA-256 hash). Password hash dùng PBKDF2 600k iterations. JWT claims: sub, tenant_id, role.
Bill of Materials Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateBom | Tạo BOM mới — Draft; version tự tăng theo product | — |
| Command | AddComponent | Thêm vật liệu / sub-assembly vào BOM | — |
| Command | RemoveComponent | Xoá component khỏi BOM Draft | — |
| Command | ActivateBom | Kích hoạt → auto obsolete BOM Active cũ cùng product | — |
| Command | ObsoleteBom | Đánh dấu BOM không còn hiệu lực | — |
| Event | BomCreated | BOM mới được tạo | bom.events |
| Event | ComponentAdded / Removed | Danh sách vật liệu thay đổi | bom.events |
| Event | BomActivated | BOM có hiệu lực — Planning/MRP sử dụng | bom.events |
| Event | BomObsoleted | BOM hết hiệu lực | bom.events |
| Query | GetActiveByProduct | Lấy BOM đang Active của sản phẩm | — |
| Query | ExplodeBom | Explode multi-level + cycle guard → danh sách NVL lá | — |
Production Planning / MRP Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateProductionPlan | Tạo kế hoạch sản xuất theo kỳ (Draft) | — |
| Command | AddPlanLine | Thêm dòng: sản phẩm + qty + máy + due date | — |
| Command | RunMrp | Explode Active BOM × qty → so sánh Inventory → Shortage list | — |
| Command | ReleasePlan | Release kế hoạch (bắt buộc đã RunMRP); sửa line → invalidate MRP | — |
| Command | ClosePlan / CancelPlan | Đóng hoặc huỷ kế hoạch | — |
| Event | ProductionPlanCreated | Kế hoạch mới được tạo | planning.events |
| Event | MrpCompleted | MRP chạy xong — có shortage list | planning.events |
| Event | PlanReleased | Kế hoạch Released → tạo Production Orders | planning.events |
| Query | GetDispatchList | Danh sách lệnh theo due date / machine — điều phối shop floor | — |
Approval Workflow Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | SubmitApprovalRequest | Gửi yêu cầu phê duyệt (auto-submit sau Release / NCR Disposition) | — |
| Command | Decide | Approver Approve / Reject; Sequential → next step; Parallel → chờ đủ | — |
| Command | EscalateOverdue | SLA quá hạn → escalate lên cấp trên | — |
| Command | Delegate | Uỷ quyền cho người khác (không re-delegate) | — |
| Command | CancelRequest | Huỷ yêu cầu phê duyệt | — |
| Event | ApprovalRequestSubmitted | Yêu cầu đã được gửi | approval.events |
| Event | StepApproved / StepRejected | Từng bước được phê duyệt hoặc từ chối | approval.events |
| Event | ApprovalCompleted / Rejected | Toàn bộ luồng hoàn tất | approval.events |
| Event | StepEscalated | Bước bị escalate do quá SLA | approval.events |
| Event | StepDelegated | Bước được uỷ quyền | approval.events |
Notification Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | PublishNotification | Publish thông báo → push SignalR + lưu inbox | — |
| Command | MarkRead / MarkAllRead | Đánh dấu đã đọc | — |
| Command | Dismiss | Ẩn thông báo khỏi inbox | — |
| Event | NotificationPublished | Thông báo được tạo và đẩy | notification.events |
| Event | NotificationRead / Dismissed | Trạng thái đọc thay đổi | notification.events |
| Query | GetUnreadNotifications | Inbox chưa đọc của user | — |
Traceability Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateLot | Tạo lot nguyên liệu / thành phẩm | — |
| Command | IssueToOrder | Xuất lot cho Production Order | — |
| Command | LinkParent | Liên kết lot con với lot cha (genealogy) | — |
| Command | CloseLot | Đóng lot khi sử dụng xong | — |
| Event | LotCreated | Lot mới được tạo | traceability.events |
| Event | LotIssuedToOrder | Lot được xuất cho lệnh sản xuất | traceability.events |
| Event | LotLinked | Quan hệ cha-con được thiết lập | traceability.events |
| Event | LotClosed | Lot đóng lại | traceability.events |
| Query | TraceBackward | Tìm nguyên liệu đầu vào của một sản phẩm | — |
| Query | TraceForward | Tìm mọi sản phẩm có dùng nguyên liệu đó | — |
CAPA Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | OpenCapaCase | Mở vấn đề CAPA mới | — |
| Command | Investigate | Bắt đầu điều tra nguyên nhân gốc rễ | — |
| Command | DefineActionPlan | Xác định kế hoạch hành động khắc phục | — |
| Command | StartImplementation | Bắt đầu thực hiện hành động | — |
| Command | SubmitVerification | Gửi bằng chứng xác nhận hiệu quả | — |
| Command | Verify / Cancel | Xác nhận CAPA hiệu quả hoặc huỷ | — |
| Event | CapaCaseOpened | Vấn đề CAPA được mở | capa.events |
| Event | ActionPlanDefined | Kế hoạch hành động được xác định | capa.events |
| Event | CapaVerified / Closed | CAPA được xác nhận hiệu quả và đóng | capa.events |
Shift Management Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | ScheduleShift | Lên lịch ca — cần supervisor, line, target output | — |
| Command | StartShift | Bắt đầu ca (cần supervisor) | — |
| Command | RecordHandover | Ghi nhận bàn giao ca (chỉ khi Active) | — |
| Command | CloseShift | Đóng ca (chỉ sau khi đã handover) | — |
| Event | ShiftScheduled | Ca được lên lịch | shift.events |
| Event | ShiftStarted | Ca bắt đầu | shift.events |
| Event | ShiftHandoverRecorded | Bàn giao ca được ghi nhận | shift.events |
| Event | ShiftClosed | Ca kết thúc — dùng cho OEE tính Availability | shift.events |
Procurement Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreatePurchaseOrder | Tạo PO mới — Draft; PO number PO-{year}-{seq} | — |
| Command | AddLine / RemoveLine | Thêm/xoá dòng vật liệu (chỉ Draft) | — |
| Command | SubmitForApproval | Gửi duyệt (cần ≥1 line) | — |
| Command | Approve / Reject | Phê duyệt hoặc từ chối PO | — |
| Command | ReceiveGoods | Nhận hàng từng dòng — auto ReceiveStock Inventory; auto Received khi đủ | — |
| Command | ClosePO / CancelPO | Đóng hoặc huỷ PO | — |
| Event | PurchaseOrderCreated | PO được tạo | procurement.events |
| Event | PurchaseOrderApproved | PO được phê duyệt | procurement.events |
| Event | GoodsReceived | Nhận hàng → hook ReceiveStock Inventory | procurement.events |
| Event | PurchaseOrderReceived / Closed | PO hoàn tất | procurement.events |
GoodsReceived → IGoodsReceiptInventoryHook → ReceiveStock tự động.
LowStockAlertRaised → ILowStockPurchaseHook → tạo draft PO supplier TBD, dedup PO mở.
Engineering Change Order Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateEcoRequest | Tạo ECO Draft — ECO number ECO-{year}-{seq} | — |
| Command | AddChangeLine | Thêm dòng thay đổi (AddComponent / RemoveComponent / ModifySpec) | — |
| Command | SubmitEco | Gửi ECO để phê duyệt | — |
| Command | ApproveEco | Phê duyệt → auto implement: tạo BOM revision mới + Activate | — |
| Command | RejectEco / CancelEco | Từ chối hoặc huỷ ECO | — |
| Event | EcoRequestCreated | ECO được tạo | eco.events |
| Event | EcoRequestSubmitted | ECO gửi để duyệt | eco.events |
| Event | EcoRequestApproved | ECO được duyệt | eco.events |
| Event | EcoRequestImplemented | BOM mới đã được tạo và kích hoạt — auto sau Approved | eco.events |
| Event | EcoRequestRejected / Cancelled | ECO bị từ chối hoặc huỷ | eco.events |
Calibration Management Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | ScheduleCalibration | Lên lịch hiệu chuẩn — CAL number CAL-{year}-{seq}; scheduledDate ≥ hôm nay | — |
| Command | StartCalibration | Bắt đầu thực hiện hiệu chuẩn | — |
| Command | RecordPass | Ghi nhận đạt — cần nextDueDate > scheduledDate | — |
| Command | RecordFail | Ghi nhận không đạt — thiết bị cần đưa ra ngoài | — |
| Command | CancelCalibration | Huỷ lịch hiệu chuẩn | — |
| Event | CalibrationScheduled | Lịch hiệu chuẩn được tạo | calibration.events |
| Event | CalibrationStarted | Hiệu chuẩn bắt đầu | calibration.events |
| Event | CalibrationPassed | Đạt — ghi nhận kết quả và ngày hiệu chuẩn tiếp theo | calibration.events |
| Event | CalibrationFailed | Không đạt — thiết bị đo cần xử lý | calibration.events |
| Query | GetOverdueCalibrations | Danh sách thiết bị quá hạn hiệu chuẩn | — |
Sensor OEE Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | IngestSensorReadings | Nhận batch readings + uptime events từ PLC/edge — anonymous, key-auth tuỳ chọn | — |
| Command | RecalculateOeeSnapshot | Tính lại OEE A×P×Q cho 1 máy / ca / ngày và upsert vào snapshot | — |
| Query | GetMachineOee | OEE snapshot 1 máy theo ngày + ca | — |
| Query | GetPlantSensorOee | Toàn nhà máy — tất cả máy trong ngày | — |
A = uptime / planned × 100 · P = min(100, cycles × idealCycleSec / uptimeSec × 100) · Q = goodCount / cycles × 100 · OEE = A × P × Q / 10 000
Dữ liệu lưu trong sensor_readings + machine_uptime_events (Postgres range-partitioned monthly) + oee_daily_snapshots.
Sales Module (Order-to-Cash)
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateSalesOrder | Tạo đơn bán — SO number SO-{year}-{seq:D6} | — |
| Command | AddSoLine / RemoveSoLine | Sửa dòng chỉ khi Draft; sản phẩm trùng trong SO → DUPLICATE_LINE | — |
| Command | ConfirmSalesOrder | Xác nhận — cần ≥1 dòng (EMPTY_ORDER) | — |
| Command | ShipGoods | Giao hàng từng phần theo dòng; không vượt outstanding (OVER_SHIPMENT) | — |
| Command | InvoiceSalesOrder | Chỉ từ trạng thái Shipped | — |
| Event | SalesOrderConfirmed | Đơn bán được xác nhận | sales.events |
| Event | SalesOrderGoodsShipped | Giao hàng — hook trừ kho theo mã sản phẩm, reference SO {số SO} | sales.events |
| Event | SalesOrderInvoiced | Đơn bán đã xuất hoá đơn | sales.events |
Routing Module (quy trình công nghệ)
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateRouting | Tạo quy trình cho sản phẩm — revision tự tăng | — |
| Command | AddRoutingStep | Thêm bước: sequence · operationCode · workCenterCode · setupMinutes (một lần/lô) · minutesPerUnit (nhân theo SL) | — |
| Command | ActivateRouting | Kích hoạt — bản Active cũ tự Obsolete; partial unique index bảo đảm 1 Active/sản phẩm | — |
| Event | RoutingCreated / RoutingStepAdded | Dựng quy trình | routing.events |
| Event | RoutingActivated / RoutingObsoleted | Đổi bản hiệu lực | routing.events |
| Event | ProductionOperationsPlanned | Sau khi Release lệnh SX: chụp Routing Active thành công đoạn của lệnh — chụp lại, không tham chiếu sống, đổi quy trình chuẩn không làm thay đổi lệnh đang chạy | production.events |
| Event | ProductionOperationStarted / OutputRecorded / Completed | Chạy tuần tự (PREVIOUS_OPERATION_OPEN); bán thành phẩm chảy sang bước sau; ActualQty lấy ở bước CUỐI | production.events |
| Event | ProductionLaborBooked | Chấm công theo công đoạn — đơn giá giờ chốt vào bản ghi, không tham chiếu sang nhân sự | production.events |
Ledger Module — Sổ cái kế toán kép
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateJournalEntry | Dựng bút toán; PostImmediately để dựng và ghi sổ một lần — đường dùng cho bút toán tự động | — |
| Command | PostJournalEntry | Ghi sổ — tổng Nợ phải bằng tổng Có (UNBALANCED_ENTRY), kiểm lúc ghi sổ chứ không lúc thêm dòng | — |
| Command | ReverseJournalEntry | Đảo bút toán — bút toán gốc và bút toán đảo ghi trong cùng một transaction | — |
| Command | ClosePeriod / ReopenPeriod | Khoá lần lượt (EARLIER_PERIOD_OPEN); còn nháp thì không khoá (PERIOD_HAS_DRAFTS) | — |
| Event | JournalEntryDrafted / LineAdded / LineRemoved | Dựng chứng từ; số dòng tăng đơn điệu, không lấy lại số đã xoá | ledger.events |
| Event | JournalEntryPosted | Ghi sổ — dòng chảy vào bảng chỉ-thêm gl_postings | ledger.events |
| Event | JournalEntryReversed | Bút toán gốc vẫn nằm trên sổ, chỉ đánh dấu đã đảo | ledger.events |
| Query | GetTrialBalance | Bảng cân đối phát sinh — isBalanced kiểm cả ba cặp cột | — |
| Query | GetAccountLedger | Sổ cái tài khoản có số dư luỹ kế | — |
Accounts Receivable Module
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateArInvoice / IssueArInvoice | Hoá đơn bán — thuế tính trên từng dòng rồi cộng, các mặt hàng có thuế suất khác nhau | — |
| Command | PostArReceipt | Phiếu thu — gán vượt số thực thu bị chặn; thu nhiều hơn tổng đã gán thì được (tiền trả trước) | — |
| Command | CancelArReceipt | Huỷ phiếu thu — hoàn lại số đã trừ trên từng hoá đơn, sinh bút toán ngược | — |
| Event | ArInvoiceIssued | Sự kiện mang đủ dữ liệu (số hoá đơn, tên khách, tenant) để bên nghe không phải tra read model do consumer group khác dựng | ar.events |
| Event | ArInvoicePaymentApplied / Reversed | Trừ nợ và hoàn lại — thu vượt số còn nợ bị chặn (OVER_PAYMENT) | ar.events |
| Event | ArReceiptPosted / Cancelled | Phiếu thu và mọi hoá đơn nó trừ nợ ghi trong cùng một transaction | ar.events |
| Query | GetArAging | Bảng tuổi nợ — chưa đến hạn · 1-30 · 31-60 · 61-90 · >90 | — |
| Query | GetArStatement | Đối chiếu công nợ theo khách hàng, có số dư luỹ kế | — |
Accounts Payable Module — đối chiếu 3 chiều
| Loại | Tên | Mô tả | Topic |
|---|---|---|---|
| Command | CreateApInvoice | Hoá đơn NCC — nhận trùng số hoá đơn bị chặn (DUPLICATE_SUPPLIER_INVOICE), trả tiền hai lần cho một lần mua | — |
| Command | MatchApInvoice | Đối chiếu 3 chiều: đơn mua ↔ phiếu nhập ↔ hoá đơn. Đối chiếu số lượng theo số ĐÃ NHẬN, không theo số đã đặt | — |
| Command | ApproveApInvoice | Đối chiếu không đạt vẫn duyệt được nhưng bắt buộc nêu lý do, lý do nằm lại vĩnh viễn trên sổ | — |
| Command | PostApPayment | Phiếu chi — phải gán HẾT vào hoá đơn (ALLOCATION_MISMATCH) | — |
| Event | ApInvoiceMatched | Kết quả đối chiếu: Matched · NotOnOrder · OverInvoiced · PriceVariance | ap.events |
| Event | ApInvoiceApproved | Sinh hai bút toán: Nợ 3388 / Có 331 và Nợ 133 / Có 331 | ap.events |
| Event | ApPaymentPosted / Cancelled | Chi tiền và huỷ chi — bút toán ngược, không sửa bút toán cũ | ap.events |
| Query | GetApAging | Bảng tuổi nợ phải trả | — |
| Query | GetGrni | Hàng đã nhận chưa có hoá đơn — giải trình số dư tài khoản 3388 | — |
Saga Flows — Cross-module Workflows
Sagas điều phối các luồng nghiệp vụ phức tạp span nhiều Bounded Context. Mỗi Saga lắng nghe Events và phát Commands đến module khác.
Các Saga chính trong hệ thống
| Saga | Trigger | Modules tham gia | Compensating action |
|---|---|---|---|
| ProductionCompletionSaga | ProductionOrderCompleted |
Production → Inventory → Quality → Finance | Release stock reservation nếu Quality fail |
| MaterialReservationSaga | ProductionOrderCreated |
Production → Inventory | Cancel order nếu không đủ NVL |
| BreakdownResponseSaga | AssetBreakdownReported |
Maintenance → Production → Inventory | Reschedule production order |
| PredictiveMaintenanceSaga | PredictiveAlertRaised |
Maintenance → Production (schedule window) | Dismiss alert nếu không xác nhận |