Skip to content

KPI - Technical Map

Auto-generated bởi codebase-doc-generator ngày 2026-03-23 (verified từ code thực). Không chỉnh sửa thủ công.

Routes

RoutePathMục đích
ROUTE_KPI_LIST/k/KPIsEntry chính của module KPI
ROUTE_KPI_CREATE/k/KPIs/createTạo KPI
ROUTE_KPI_DETAIL/k/KPIs/:idDetail KPI
ROUTE_KPI_UPDATE/k/KPIs/:id/editCập nhật KPI
ROUTE_KPI_DETAIL_METRIC/k/KPIs/:id/metricTab metric
ROUTE_KPI_DETAIL_TARGET/k/KPIs/:id/targetTab target
ROUTE_KPI_DETAIL_MY_KPI/k/KPIs/:id/my-kpiTab KPI cá nhân
ROUTE_KPI_DETAIL_BRANCH_KPI/k/KPIs/:id/branch-kpiTab KPI chi nhánh
ROUTE_BRANCH_KPI_DETAIL/k/KPIs/:id/branch-kpi/:assigneeIdDetail participant branch
ROUTE_PERSONAL_KPI_DETAIL/k/KPIs/:id/personal-kpi/:assigneeIdDetail participant personal
ROUTE_KPI_REVENUE_CREATE/k/KPIs/revenue/createTạo branch revenue KPI
ROUTE_KPI_REVENUE_EDIT/k/KPIs/revenue/editSửa branch revenue KPI
ROUTE_KPI_REVENUE_BRANCH/k/KPIs/branch-revenue/:idWrapper detail branch revenue
ROUTE_KPI_REVENUE_BRANCH_DETAIL/k/KPIs/branch-revenue/:id/detailDetail branch revenue
ROUTE_KPI_REVENUE_BRANCH_USER_CREATE/k/KPIs/branch-revenue/user-create/:idTạo KPI user trong branch revenue
ROUTE_KPI_REVENUE_BRANCH_USER_EDIT/k/KPIs/branch-revenue/user-edit/:idSửa KPI user trong branch revenue
ItemGiá trị
MODULE_KPIk
Route moduleIdkpi
Route permissionsITLeader, BOD, BranchManager, DepartmentManager, nhóm CallCenter
Dashboard runtime permissionsITLeader, ITStaff, AccountantLeader, AccountantStaffGeneral, HRLeader, HRStaff, cộng thêm BranchManager ở POS gating
Navigation titleQuản lý KPI

FE Pages (4)

PageFileVai trò
KPIspages/KPIs.tsxEntry route, hiện render KPIRevenue
KPICreatepages/KPICreate.tsxTạo KPI definition
KPIDetailpages/KPIDetail.tsxDetail KPI + tab routing
KPIUpdatepages/KPIUpdate.tsxCập nhật KPI definition

FE Components / Areas

Component/AreaVai trò
KPIRevenue*Dashboard doanh thu theo tháng/ngày/branch/user
KpiFormForm tạo KPI
KPIUpdateFormForm cập nhật KPI
KPIInfoThông tin summary bên trái detail
MetricsTab metric definition
TargetsTab target/participant
AssigneeTab/detail participant branch hoặc personal
AutoMetricForm/*Form cấu hình các auto metric theo loại nghiệp vụ
KPIActionBộ action view/edit/cancel/delete/download

GraphQL Operations

File: diva-admin/src/modules/kpi/graphql/kpi.graphql

KPI core

OperationMục đích
getKPIsLấy danh sách KPI
getKPIStatsLấy stats KPI
GetKPIByPkLấy chi tiết KPI
createKpiTạo KPI
updateKpiUpdate KPI header
getKPITemplatesLấy KPI templates
deleteKPITemplateXóa template KPI

Metric / participant

OperationMục đích
GetKPIMetricsLấy danh mục metric
insertKpiParticipantThêm participant
deleteKpiParticipantsXóa participant
insertKpiMetricRelationsThêm metric relations
deleteKpiMetricRelationssXóa metric relations
upsertManualMetricsUpsert manual metric logs/values
getKPIMetricParticipantsLấy participant + metric detail
getKPIMetricRelationsLấy metric relations
getKPIMetricRelationLogsLấy KPI log history
getKPIMetricStatsLấy metric stats

Branch / revenue KPI

OperationMục đích
GetBranchCreateTargetData tạo target branch
InsertKPIBranchInsert kpi_branch
GetKPIMonthTargetChartChart/ranking KPI tháng
GetKPIDayTargetChartChart/ranking KPI ngày
GetKPITargetTableBảng target KPI
GetKPITargetEditLấy dữ liệu edit target
UpdateKPITargetGọi bulk update target branch
GetKPIBranchTableEmployeeBảng KPI nhân viên theo branch
GetKPIBranchCalenderCalendar KPI branch
GetKPIUserCreateTargetData tạo KPI user
GetKPIUserEditTargetData sửa KPI user
InsertKPIStaffInsert kpi_staff
SumcardKPIBranchSumcard KPI branch
DeleteKPIBranchXóa branch target
DeleteKPIStaffXóa staff target

FE Runtime logic

KPIs.tsx

LogicGhi chú
Entry renderingNếu route là ROUTE_KPI_LIST thì render KPIRevenue
POS gateKiểm tra thêm PERMISSIONS_KPI + BranchManager
Local tab stateLưu tab key trong localStorage với key customer

KPIDetail.tsx

LogicGhi chú
Detail sourceGetKPIByPk(id)
Dynamic tabsTab hiển thị theo role và type KPI
Branch manager scopeTính managedBranches từ account.branches và participant branch users
Assignee detail modeRoute sâu branch-kpi/:assigneeIdpersonal-kpi/:assigneeId ẩn tab header

KPICreate.tsx

LogicGhi chú
Header insertInsert kpi với general info + totals
Participant insertparticipants.data đi cùng insert KPI
Template captureLưu capture khi isSaved = true
Metric insertGọi insertKpiMetricRelations sau khi đã có participant map
Date normalizationfrom đầu ngày, to cuối ngày

KPIUpdate.tsx

LogicGhi chú
Delta updateTính participant/metric bị thêm, xóa, thay đổi
Participant cleanupXóa metrics trước khi xóa participant
Metric syncInsert lại metric relations mới hoặc changed
Child metric syncTách riêng nhánh update additional metric ranges

KPIUpdateForm.tsx

LogicGhi chú
Empty guardsChặn nếu chưa có metric hoặc target
Cross validationMỗi target phải có metric tương ứng
Init from existing KPIDựng lại form từ metric_relations, participants, totals
Additional metricsMap child ranges theo metric ID

KPIAction.tsx

LogicGhi chú
Edit modeChỉ hiện cho new/inprogress và non-dynamic group
Cancel modeChỉ hiện cho inprogress
Delete modeChỉ hiện cho new
DownloadCho tải metric hoặc target

KPIBuildWhere

LogicGhi chú
Disabled filterLuôn có thể ép disabled = false
Keyword searchSearch theo keywords của KPI hoặc participant user
Status filterSuy luận trạng thái từ from, to, canceled_at thay vì chỉ đọc status field
My KPI scopeHạn chế theo participant / creator / branch tùy role
Participant filtersLọc theo branch, department users, user ids, loại KPI
Date bugsetStartEndDate() dùng createDate(from, ...) cho cả nhánh to, có dấu hiệu sai logic

Core constants / enums

ConstantGiá trị / Ý nghĩa
KPI_BRANCHkpi_branch
KPI_PERSONALkpi_personal
KPI_STATUS_NEWnew
KPI_STATUS_INPROGRESSinprogress
KPI_STATUS_CLOSEDclosed
KPI_STATUS_DONEdone
KPI_STATUS_CANCELEDcanceled
KPI_STATUSESnew, inprogress, closed, canceled
KPI_RESULTSnot_achieved, need_to_improve, qualified, exceed_requirements
KPI_METRIC_GROUP_MANUALkpi_metric_group_manual

Metric catalog highlights

NhómVí dụ metric type
Revenue / salesactual_revenue, sales, order_quantity
Customernew_customers, returning_customers, customers_purchased
Contact centerminutes_on_calls, call_productivity_calls_hour, call_productivity_minutes_hour, outgoing_calls_to_customers, created_tickets, created_appointments
Campaignorders_from_campaign, sales_from_campaign, actual_revenue_from_campaign, actual_revenue_from_campaign_prepaid_card
Workload / tasktotal_workload, total_completed_workload, total_time_completed_task, completed_tasks, overdue_tasks

Store / data model

ObjectVai trò
kpiHeader KPI definition
kpi_templateKPI template capture
kpi_participantĐối tượng KPI: user hoặc branch
kpi_metricDanh mục metric
kpi_metric_relationMetric target gắn với participant
kpi_metric_relation_logLog tiến độ thực tế theo metric
kpi_statsStats tổng hợp của KPI
kpi_metric_statsStats tổng hợp của metric
kpi_branchTarget doanh thu theo chi nhánh
kpi_staffTarget doanh thu theo nhân viên
kpi_permissionMapping role nhận KPI notification / scope đặc biệt
kpi_branch_result / kpi_staff_resultRead models cho report/ranking KPI

Backend Services

ServiceVai trò
controllerCRUD tables/functions/metadata KPI
ecommerce-apiEvent triggers cho kpi_branch, kpi_staff; scheduler kpi_notification
crm-apiScheduler kpi_hotline ghi KPI log từ hotline calls

Backend Events / Schedulers

kpi_branch_insert

StepVai trò
GuardBỏ qua nếu TotalTarget <= 0
LookupLấy KpiBranchDetail + branch managers
NotifyGửi NotificationTriggerBranchKpiAssign cho branch managers

kpi_branch_update

StepVai trò
Assign case0 -> >0 thì gửi assign notification
Change case>0 -> >0 và thay đổi target thì gửi change notification
Rank lookupCó query search_kpi_branch_by_month_rank để lấy % hiện tại trước khi gửi change

kpi_staff_insert

StepVai trò
GuardBỏ qua nếu TotalTarget <= 0
NotifyGửi NotificationTriggerStaffKpiAssign cho chính user staff

kpi_staff_update

StepVai trò
Assign case0 -> >0 thì gửi assign notification
Change case>0 -> >0 và thay đổi target thì gửi change notification
History lookupQuery search_kpi_staff_history để lấy progress % hiện tại

kpi_notification

StepVai trò
kpiStaffNotificationNhắc staff chưa đạt KPI tháng hiện tại
kpiDayBranchNotificationGửi tổng hợp KPI branch theo ngày
kpiMonthBranchNotificationGửi tổng hợp KPI branch theo tháng
kpiRemindBranchNotificationNhắc branch managers theo điều kiện scheduler

kpi_hotline

StepVai trò
SourceQuét incall_callticket completed trong ngày
Per-user metricGhi call_productivity_calls_hourcall_productivity_minutes_hour dựa trên working hours
Per-branch metricGhi aggregate call count và total minutes cho branch
PersistenceGhi qua AddKpiLog(...)

AddKpiLog mechanism

StepVai trò
Participant lookupTìm kpi_participant theo reference_id
Active KPI gateChỉ nhận KPI active, không disabled, không canceled, nằm trong thời gian hiệu lực
Metric matchChỉ log vào kpi_metric_relationmetric.type_id khớp
Insert logInsert kpi_metric_relation_log với point và entity references

Domain coupling

Module/DomainKiểu liên kết
reportĐọc kpi_branch_result, kpi_staff_result, metric stats
dashboardDùng dữ liệu KPI revenue/ranking
userParticipant, role, branch ownership, department
notificationCác event/scheduler KPI gửi notification templates
crmHotline scheduler sinh KPI logs
projectsMột số metric workload/task dùng dữ liệu task domain

Rủi ro / Findings kỹ thuật

#Note
1ROUTE_KPI_LIST thực tế render KPIRevenue; tên route và entry UX không phản ánh hết việc module đang thiên về KPI doanh thu.
2KPI_PERMISSIONSPERMISSIONS_KPI không trùng nhau hoàn toàn; route-level access và screen-level access có thể lệch.
3KPI_STATUS_DONE tồn tại nhưng không nằm trong KPI_STATUSES, cho thấy enum trạng thái chưa đồng bộ hoàn chỉnh.
4useKPIBuilder.setStartEndDate() có dấu hiệu bug vì dùng from cho cả điều kiện _lte của to.
5kpi_metric_relation_log là read/write backbone cho auto metrics; KPI progress không chỉ đến từ form manual mà còn từ nhiều scheduler/event backend.