class FinanceRecord { final int id; final String type; // receivable | payable | receipt | payment final double amount; final double balance; final String status; // open | closed final String? refType; final int? refId; final String? partnerName; final int? partnerId; final String? recordDate; final String? remark; const FinanceRecord({ required this.id, required this.type, required this.amount, required this.balance, this.status = 'open', this.refType, this.refId, this.partnerName, this.partnerId, this.recordDate, this.remark, }); String get typeLabel { switch (type) { case 'receivable': return '应收账款'; case 'payable': return '应付账款'; case 'receipt': return '收款'; case 'payment': return '付款'; default: return type; } } /// 单据抬头(近期单据列表用):收付款显示类型,应收/应付回溯到来源单据 String get docTitle { final ref = switch (refType) { 'stock_in' => '入库单', 'stock_out' => '出库单', _ => null, }; if (ref != null) return ref; return typeLabel; } factory FinanceRecord.fromJson(Map json) => FinanceRecord( id: (json['id'] as num).toInt(), type: json['type'] as String, amount: (json['amount'] as num).toDouble(), balance: (json['balance'] as num).toDouble(), status: json['status'] as String? ?? 'open', refType: json['ref_type'] as String?, refId: json['ref_id'] != null ? (json['ref_id'] as num).toInt() : null, partnerName: (json['partner'] as Map?)?['name'] as String?, partnerId: json['partner_id'] != null ? (json['partner_id'] as num).toInt() : null, recordDate: json['record_date'] as String?, remark: json['remark'] as String?, ); } /// GET /finance/summary 行:按往来单位分组的未结清应收/应付聚合 class PartnerFinanceSummary { final int? partnerId; final String partnerName; final String type; // payable | receivable final int recordCount; final double totalAmount; const PartnerFinanceSummary({ this.partnerId, this.partnerName = '', required this.type, this.recordCount = 0, required this.totalAmount, }); factory PartnerFinanceSummary.fromJson(Map json) => PartnerFinanceSummary( partnerId: json['partner_id'] != null ? (json['partner_id'] as num).toInt() : null, partnerName: json['partner_name'] as String? ?? '', type: json['type'] as String, recordCount: (json['record_count'] as num?)?.toInt() ?? 0, totalAmount: (json['total_amount'] as num?)?.toDouble() ?? 0, ); } /// GET /finance/trend 点:月度收支(in=销售额、out=采购额,单位元)。 class TrendPoint { final String month; // "2026-01" final double inAmount; final double outAmount; const TrendPoint( {required this.month, required this.inAmount, required this.outAmount}); factory TrendPoint.fromJson(Map json) => TrendPoint( month: json['month'] as String? ?? '', inAmount: (json['in'] as num?)?.toDouble() ?? 0, outAmount: (json['out'] as num?)?.toDouble() ?? 0, ); }