expense_apply_model.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. import '../../shared/models/approval_status.dart';
  2. /// 费用申请主表,对应 [ExpenseApply] 表。
  3. class ExpenseApplyModel {
  4. final String id;
  5. final String expenseApplyNo;
  6. final DateTime? expenseApplyDate;
  7. final String applicantId;
  8. final String applicantName;
  9. final String deptId;
  10. final String deptName;
  11. final double estimatedAmount;
  12. final String urgency;
  13. final String purpose;
  14. final String remark;
  15. final DateTime? effectiveDate;
  16. final String auditorId;
  17. final String status;
  18. final String usageStatus;
  19. final DateTime? validUntil;
  20. final String referenceNo;
  21. final String approvalInstanceId;
  22. final String previousInstanceIds;
  23. final int version;
  24. final DateTime createTime;
  25. final DateTime updateTime;
  26. final bool isDeleted;
  27. // ── 瞬态字段(API 从 ERP 实时查询,非存储) ──
  28. final String currentApproverId;
  29. final List<String> approvalChain;
  30. final List<ApprovalRecord> approvalRecords;
  31. // ── 子表 ──
  32. final List<ExpenseApplyDetailModel> details;
  33. final List<String> attachments;
  34. const ExpenseApplyModel({
  35. required this.id,
  36. required this.expenseApplyNo,
  37. this.expenseApplyDate,
  38. this.applicantId = '',
  39. this.applicantName = '',
  40. this.deptId = '',
  41. this.deptName = '',
  42. this.estimatedAmount = 0.0,
  43. this.urgency = 'normal',
  44. this.purpose = '',
  45. this.remark = '',
  46. this.effectiveDate,
  47. this.auditorId = '',
  48. this.status = 'draft',
  49. this.usageStatus = 'unused',
  50. this.validUntil,
  51. this.referenceNo = '',
  52. this.approvalInstanceId = '',
  53. this.previousInstanceIds = '',
  54. this.version = 1,
  55. required this.createTime,
  56. required this.updateTime,
  57. this.isDeleted = false,
  58. this.currentApproverId = '',
  59. this.approvalChain = const [],
  60. this.approvalRecords = const [],
  61. this.details = const [],
  62. this.attachments = const [],
  63. });
  64. factory ExpenseApplyModel.fromJson(Map<String, dynamic> json) {
  65. return ExpenseApplyModel(
  66. id: json['id'] as String? ?? '',
  67. expenseApplyNo: json['applyNo'] as String? ?? '',
  68. expenseApplyDate: json['applyDate'] != null
  69. ? DateTime.parse(json['applyDate'] as String)
  70. : null,
  71. applicantId: json['usr'] as String? ?? '',
  72. applicantName: json['applicantName'] as String? ?? json['usr'] as String? ?? '',
  73. deptId: json['dept'] as String? ?? '',
  74. deptName: json['deptName'] as String? ?? json['dep'] as String? ?? '',
  75. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  76. urgency: json['priority'] as String? ?? 'normal',
  77. purpose: json['reason'] as String? ?? '',
  78. remark: json['rem'] as String? ?? '',
  79. effectiveDate: json['effDd'] != null
  80. ? DateTime.parse(json['effDd'] as String)
  81. : null,
  82. auditorId: json['chkMan'] as String? ?? '',
  83. status: json['clsDate'] != null ? 'closed' : (json['status'] as String? ?? 'draft'),
  84. usageStatus: json['usageStatus'] as String? ?? 'unused',
  85. validUntil: json['validUntil'] != null
  86. ? DateTime.parse(json['validUntil'] as String)
  87. : null,
  88. referenceNo: json['referenceNo'] as String? ?? '',
  89. approvalInstanceId: json['approvalInstanceId'] as String? ?? '',
  90. previousInstanceIds: json['previousInstanceIds'] as String? ?? '',
  91. version: json['version'] as int? ?? 1,
  92. createTime: json['createTime'] != null
  93. ? DateTime.parse(json['createTime'] as String)
  94. : DateTime.now(),
  95. updateTime: json['updateTime'] != null
  96. ? DateTime.parse(json['updateTime'] as String)
  97. : DateTime.now(),
  98. isDeleted: json['isDeleted'] as bool? ?? false,
  99. currentApproverId: json['currentApproverId'] as String? ?? '',
  100. approvalChain:
  101. (json['approvalChain'] as List<dynamic>?)
  102. ?.map((e) => e as String)
  103. .toList() ??
  104. [],
  105. approvalRecords:
  106. (json['approvalRecords'] as List<dynamic>?)
  107. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  108. .toList() ??
  109. [],
  110. details:
  111. (json['details'] as List<dynamic>?)
  112. ?.map(
  113. (e) =>
  114. ExpenseApplyDetailModel.fromJson(e as Map<String, dynamic>),
  115. )
  116. .toList() ??
  117. [],
  118. attachments:
  119. (json['attachments'] as List<dynamic>?)
  120. ?.map((e) => e as String)
  121. .toList() ??
  122. [],
  123. );
  124. }
  125. Map<String, dynamic> toJson() => {
  126. 'id': id,
  127. 'expenseApplyNo': expenseApplyNo,
  128. 'expenseApplyDate': expenseApplyDate?.toIso8601String(),
  129. 'applicantId': applicantId,
  130. 'applicantName': applicantName,
  131. 'deptId': deptId,
  132. 'deptName': deptName,
  133. 'estimatedAmount': estimatedAmount,
  134. 'urgency': urgency,
  135. 'purpose': purpose,
  136. 'remark': remark,
  137. 'effectiveDate': effectiveDate?.toIso8601String(),
  138. 'auditorId': auditorId,
  139. 'status': status,
  140. 'usageStatus': usageStatus,
  141. 'validUntil': validUntil?.toIso8601String(),
  142. 'referenceNo': referenceNo,
  143. 'approvalInstanceId': approvalInstanceId,
  144. 'previousInstanceIds': previousInstanceIds,
  145. 'version': version,
  146. 'createTime': createTime.toIso8601String(),
  147. 'updateTime': updateTime.toIso8601String(),
  148. 'isDeleted': isDeleted,
  149. 'currentApproverId': currentApproverId,
  150. 'approvalChain': approvalChain,
  151. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  152. 'details': details.map((d) => d.toJson()).toList(),
  153. 'attachments': attachments,
  154. };
  155. ExpenseApplyModel copyWith({
  156. String? id,
  157. String? expenseApplyNo,
  158. DateTime? expenseApplyDate,
  159. String? applicantId,
  160. String? applicantName,
  161. String? deptId,
  162. String? deptName,
  163. double? estimatedAmount,
  164. String? urgency,
  165. String? purpose,
  166. String? remark,
  167. DateTime? effectiveDate,
  168. String? auditorId,
  169. String? status,
  170. String? usageStatus,
  171. DateTime? validUntil,
  172. String? referenceNo,
  173. String? approvalInstanceId,
  174. String? previousInstanceIds,
  175. int? version,
  176. DateTime? createTime,
  177. DateTime? updateTime,
  178. bool? isDeleted,
  179. String? currentApproverId,
  180. List<String>? approvalChain,
  181. List<ApprovalRecord>? approvalRecords,
  182. List<ExpenseApplyDetailModel>? details,
  183. List<String>? attachments,
  184. }) {
  185. return ExpenseApplyModel(
  186. id: id ?? this.id,
  187. expenseApplyNo: expenseApplyNo ?? this.expenseApplyNo,
  188. expenseApplyDate: expenseApplyDate ?? this.expenseApplyDate,
  189. applicantId: applicantId ?? this.applicantId,
  190. applicantName: applicantName ?? this.applicantName,
  191. deptId: deptId ?? this.deptId,
  192. deptName: deptName ?? this.deptName,
  193. estimatedAmount: estimatedAmount ?? this.estimatedAmount,
  194. urgency: urgency ?? this.urgency,
  195. purpose: purpose ?? this.purpose,
  196. remark: remark ?? this.remark,
  197. effectiveDate: effectiveDate ?? this.effectiveDate,
  198. auditorId: auditorId ?? this.auditorId,
  199. status: status ?? this.status,
  200. usageStatus: usageStatus ?? this.usageStatus,
  201. validUntil: validUntil ?? this.validUntil,
  202. referenceNo: referenceNo ?? this.referenceNo,
  203. approvalInstanceId: approvalInstanceId ?? this.approvalInstanceId,
  204. previousInstanceIds: previousInstanceIds ?? this.previousInstanceIds,
  205. version: version ?? this.version,
  206. createTime: createTime ?? this.createTime,
  207. updateTime: updateTime ?? this.updateTime,
  208. isDeleted: isDeleted ?? this.isDeleted,
  209. currentApproverId: currentApproverId ?? this.currentApproverId,
  210. approvalChain: approvalChain ?? this.approvalChain,
  211. approvalRecords: approvalRecords ?? this.approvalRecords,
  212. details: details ?? this.details,
  213. attachments: attachments ?? this.attachments,
  214. );
  215. }
  216. }
  217. /// 费用申请预估明细,对应 [ExpenseApplyDetail] 表。
  218. class ExpenseApplyDetailModel {
  219. final String id;
  220. final String expenseApplyId;
  221. final String expenseCategory;
  222. final String purpose;
  223. final String projectId;
  224. final String projectName;
  225. final String costDeptId;
  226. final String costDeptName;
  227. final String acctSubjectId;
  228. final String acctSubjectName;
  229. final String sqMan;
  230. final String sqName;
  231. final DateTime? estimatedStartDate;
  232. final DateTime? estimatedEndDate;
  233. final double estimatedAmount;
  234. final String remark;
  235. final int sortOrder;
  236. final DateTime createTime;
  237. final DateTime updateTime;
  238. final bool isDeleted;
  239. const ExpenseApplyDetailModel({
  240. required this.id,
  241. this.expenseApplyId = '',
  242. this.expenseCategory = '',
  243. this.purpose = '',
  244. this.projectId = '',
  245. this.projectName = '',
  246. this.costDeptId = '',
  247. this.costDeptName = '',
  248. this.acctSubjectId = '',
  249. this.acctSubjectName = '',
  250. this.sqMan = '',
  251. this.sqName = '',
  252. this.estimatedStartDate,
  253. this.estimatedEndDate,
  254. this.estimatedAmount = 0.0,
  255. this.remark = '',
  256. this.sortOrder = 1,
  257. required this.createTime,
  258. required this.updateTime,
  259. this.isDeleted = false,
  260. });
  261. factory ExpenseApplyDetailModel.fromJson(Map<String, dynamic> json) {
  262. return ExpenseApplyDetailModel(
  263. id: json['id'] as String? ?? '',
  264. expenseApplyId: json['aeNo'] as String? ?? '',
  265. expenseCategory: json['typeNo'] as String? ?? '',
  266. purpose: json['purpose'] as String? ?? '',
  267. projectId: json['objNo'] as String? ?? '',
  268. projectName: json['objName'] as String? ?? json['projectName'] as String? ?? '',
  269. costDeptId: json['dep'] as String? ?? '',
  270. costDeptName: json['depName'] as String? ?? json['dep'] as String? ?? '',
  271. acctSubjectId: json['accNo'] as String? ?? '',
  272. acctSubjectName: json['accName'] as String? ?? '',
  273. estimatedStartDate: json['startDd'] != null
  274. ? DateTime.parse(json['startDd'] as String)
  275. : null,
  276. estimatedEndDate: json['endDd'] != null
  277. ? DateTime.parse(json['endDd'] as String)
  278. : null,
  279. estimatedAmount: (json['amtnYj'] as num?)?.toDouble() ?? 0.0,
  280. remark: json['rem'] as String? ?? '',
  281. sqMan: json['sqMan'] as String? ?? '',
  282. sqName: json['sqName'] as String? ?? '',
  283. sortOrder: json['itm'] as int? ?? 1,
  284. createTime: json['createTime'] != null
  285. ? DateTime.parse(json['createTime'] as String)
  286. : DateTime.now(),
  287. updateTime: json['updateTime'] != null
  288. ? DateTime.parse(json['updateTime'] as String)
  289. : DateTime.now(),
  290. isDeleted: json['isDeleted'] as bool? ?? false,
  291. );
  292. }
  293. Map<String, dynamic> toJson() => {
  294. 'id': id,
  295. 'expenseApplyId': expenseApplyId,
  296. 'expenseCategory': expenseCategory,
  297. 'purpose': purpose,
  298. 'projectId': projectId,
  299. 'projectName': projectName,
  300. 'costDeptId': costDeptId,
  301. 'costDeptName': costDeptName,
  302. 'acctSubjectId': acctSubjectId,
  303. 'acctSubjectName': acctSubjectName,
  304. 'sqMan': sqMan,
  305. 'sqName': sqName,
  306. 'estimatedStartDate': estimatedStartDate?.toIso8601String(),
  307. 'estimatedEndDate': estimatedEndDate?.toIso8601String(),
  308. 'estimatedAmount': estimatedAmount,
  309. 'remark': remark,
  310. 'sortOrder': sortOrder,
  311. 'createTime': createTime.toIso8601String(),
  312. 'updateTime': updateTime.toIso8601String(),
  313. 'isDeleted': isDeleted,
  314. };
  315. }