/// 出/入库 KPI 汇总(本月 + 上月同期供环比 + 待审核)。 /// 对应后端 `GET /stock-in/summary`、`/stock-out/summary`。 class StockSummary { final int monthCount; final double monthAmount; final int pendingCount; final int draftCount; final int lastMonthCount; final double lastMonthAmount; const StockSummary({ this.monthCount = 0, this.monthAmount = 0, this.pendingCount = 0, this.draftCount = 0, this.lastMonthCount = 0, this.lastMonthAmount = 0, }); factory StockSummary.fromJson(Map j) => StockSummary( monthCount: (j['month_count'] as num?)?.toInt() ?? 0, monthAmount: (j['month_amount'] as num?)?.toDouble() ?? 0, pendingCount: (j['pending_count'] as num?)?.toInt() ?? 0, draftCount: (j['draft_count'] as num?)?.toInt() ?? 0, lastMonthCount: (j['last_month_count'] as num?)?.toInt() ?? 0, lastMonthAmount: (j['last_month_amount'] as num?)?.toDouble() ?? 0, ); /// 笔数环比(%);上月为 0 时返回 null(无从比较)。 double? get countDeltaPct => lastMonthCount == 0 ? null : (monthCount - lastMonthCount) / lastMonthCount * 100; /// 金额环比(%);上月为 0 时返回 null。 double? get amountDeltaPct => lastMonthAmount == 0 ? null : (monthAmount - lastMonthAmount) / lastMonthAmount * 100; }