1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Management KPI models for executive dashboards and reporting.
//!
//! These models represent key performance indicators tracked by management,
//! supporting period-over-period comparison and trend analysis.
use chrono::NaiveDate;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
/// Category of a management KPI.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum KpiCategory {
/// Financial metrics (revenue, margin, EBITDA, etc.)
#[default]
Financial,
/// Operational metrics (throughput, cycle time, utilization, etc.)
Operational,
/// Customer metrics (NPS, retention, acquisition cost, etc.)
Customer,
/// Employee metrics (headcount, turnover, engagement, etc.)
Employee,
/// Quality metrics (defect rate, compliance, SLA adherence, etc.)
Quality,
}
/// Trend direction for a KPI relative to prior periods.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum KpiTrend {
/// KPI is moving in a favorable direction
#[default]
Improving,
/// KPI is holding steady
Stable,
/// KPI is moving in an unfavorable direction
Declining,
}
/// A management key performance indicator for a given period.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ManagementKpi {
/// Unique KPI identifier
pub kpi_id: String,
/// Company code this KPI belongs to
pub company_code: String,
/// Human-readable name of the KPI (e.g., "Gross Margin")
pub name: String,
/// Category of the KPI
pub category: KpiCategory,
/// Start of the measurement period
pub period_start: NaiveDate,
/// End of the measurement period
pub period_end: NaiveDate,
/// Actual measured value for the period
#[serde(with = "crate::serde_decimal")]
pub value: Decimal,
/// Target value for the period
#[serde(with = "crate::serde_decimal")]
pub target: Decimal,
/// Unit of measure (e.g., "%", "days", "USD")
pub unit: String,
/// Trend direction relative to prior periods
pub trend: KpiTrend,
/// Year-over-year percentage change (e.g., 0.05 = +5%)
pub year_over_year_change: Option<f64>,
/// Value from the prior period for comparison
#[serde(default, with = "crate::serde_decimal::option")]
pub prior_period_value: Option<Decimal>,
}