expense_apply_model.dart 12 KB

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