expense_application_model.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import '../../shared/models/approval_status.dart';
  2. class ExpenseApplicationModel {
  3. final String id;
  4. final String applicationNo;
  5. final String applicantId;
  6. final String applicantName;
  7. final String deptId;
  8. final String deptName;
  9. final String expenseType;
  10. final double estimatedAmount;
  11. final String purpose;
  12. final String remark;
  13. final String status;
  14. final String currentApproverId;
  15. final List<String> approvalChain;
  16. final DateTime createTime;
  17. final DateTime updateTime;
  18. final DateTime? estimatedStartDate;
  19. final DateTime? estimatedEndDate;
  20. final String urgency;
  21. final String projectId;
  22. final String projectName;
  23. final String budgetSubjectId;
  24. final List<ExpenseAppDetailModel> details;
  25. final List<ApprovalRecord> approvalRecords;
  26. const ExpenseApplicationModel({
  27. required this.id,
  28. required this.applicationNo,
  29. this.applicantId = '',
  30. this.applicantName = '',
  31. this.deptId = '',
  32. this.deptName = '',
  33. this.expenseType = '',
  34. this.estimatedAmount = 0.0,
  35. this.purpose = '',
  36. this.remark = '',
  37. this.status = 'draft',
  38. this.currentApproverId = '',
  39. this.approvalChain = const [],
  40. required this.createTime,
  41. required this.updateTime,
  42. this.estimatedStartDate,
  43. this.estimatedEndDate,
  44. this.urgency = 'normal',
  45. this.projectId = '',
  46. this.projectName = '',
  47. this.budgetSubjectId = '',
  48. this.details = const [],
  49. this.approvalRecords = const [],
  50. });
  51. factory ExpenseApplicationModel.fromJson(Map<String, dynamic> json) {
  52. return ExpenseApplicationModel(
  53. id: json['id'] as String,
  54. applicationNo: json['applicationNo'] as String? ?? '',
  55. applicantId: json['applicantId'] as String? ?? '',
  56. applicantName: json['applicantName'] as String? ?? '',
  57. deptId: json['deptId'] as String? ?? '',
  58. deptName: json['deptName'] as String? ?? '',
  59. expenseType: json['expenseType'] as String? ?? '',
  60. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  61. purpose: json['purpose'] as String? ?? '',
  62. remark: json['remark'] as String? ?? '',
  63. status: json['status'] as String? ?? 'draft',
  64. currentApproverId: json['currentApproverId'] as String? ?? '',
  65. approvalChain:
  66. (json['approvalChain'] as List<dynamic>?)
  67. ?.map((e) => e as String)
  68. .toList() ??
  69. [],
  70. createTime: DateTime.parse(json['createTime'] as String),
  71. updateTime: DateTime.parse(json['updateTime'] as String),
  72. estimatedStartDate: json['estimatedStartDate'] != null
  73. ? DateTime.parse(json['estimatedStartDate'] as String)
  74. : null,
  75. estimatedEndDate: json['estimatedEndDate'] != null
  76. ? DateTime.parse(json['estimatedEndDate'] as String)
  77. : null,
  78. urgency: json['urgency'] as String? ?? 'normal',
  79. projectId: json['projectId'] as String? ?? '',
  80. projectName: json['projectName'] as String? ?? '',
  81. budgetSubjectId: json['budgetSubjectId'] as String? ?? '',
  82. details:
  83. (json['details'] as List<dynamic>?)
  84. ?.map(
  85. (e) =>
  86. ExpenseAppDetailModel.fromJson(e as Map<String, dynamic>),
  87. )
  88. .toList() ??
  89. [],
  90. approvalRecords:
  91. (json['approvalRecords'] as List<dynamic>?)
  92. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  93. .toList() ??
  94. [],
  95. );
  96. }
  97. Map<String, dynamic> toJson() => {
  98. 'id': id,
  99. 'applicationNo': applicationNo,
  100. 'applicantId': applicantId,
  101. 'applicantName': applicantName,
  102. 'deptId': deptId,
  103. 'deptName': deptName,
  104. 'expenseType': expenseType,
  105. 'estimatedAmount': estimatedAmount,
  106. 'purpose': purpose,
  107. 'remark': remark,
  108. 'status': status,
  109. 'currentApproverId': currentApproverId,
  110. 'approvalChain': approvalChain,
  111. 'createTime': createTime.toIso8601String(),
  112. 'updateTime': updateTime.toIso8601String(),
  113. 'estimatedStartDate': estimatedStartDate?.toIso8601String(),
  114. 'estimatedEndDate': estimatedEndDate?.toIso8601String(),
  115. 'urgency': urgency,
  116. 'projectId': projectId,
  117. 'projectName': projectName,
  118. 'budgetSubjectId': budgetSubjectId,
  119. 'details': details.map((d) => d.toJson()).toList(),
  120. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  121. };
  122. ExpenseApplicationModel copyWith({
  123. String? id,
  124. String? applicationNo,
  125. String? applicantId,
  126. String? applicantName,
  127. String? deptId,
  128. String? deptName,
  129. String? expenseType,
  130. double? estimatedAmount,
  131. String? purpose,
  132. String? remark,
  133. String? status,
  134. String? currentApproverId,
  135. List<String>? approvalChain,
  136. DateTime? createTime,
  137. DateTime? updateTime,
  138. DateTime? estimatedStartDate,
  139. DateTime? estimatedEndDate,
  140. String? urgency,
  141. String? projectId,
  142. String? projectName,
  143. String? budgetSubjectId,
  144. List<ExpenseAppDetailModel>? details,
  145. List<ApprovalRecord>? approvalRecords,
  146. }) {
  147. return ExpenseApplicationModel(
  148. id: id ?? this.id,
  149. applicationNo: applicationNo ?? this.applicationNo,
  150. applicantId: applicantId ?? this.applicantId,
  151. applicantName: applicantName ?? this.applicantName,
  152. deptId: deptId ?? this.deptId,
  153. deptName: deptName ?? this.deptName,
  154. expenseType: expenseType ?? this.expenseType,
  155. estimatedAmount: estimatedAmount ?? this.estimatedAmount,
  156. purpose: purpose ?? this.purpose,
  157. remark: remark ?? this.remark,
  158. status: status ?? this.status,
  159. currentApproverId: currentApproverId ?? this.currentApproverId,
  160. approvalChain: approvalChain ?? this.approvalChain,
  161. createTime: createTime ?? this.createTime,
  162. updateTime: updateTime ?? this.updateTime,
  163. estimatedStartDate: estimatedStartDate ?? this.estimatedStartDate,
  164. estimatedEndDate: estimatedEndDate ?? this.estimatedEndDate,
  165. urgency: urgency ?? this.urgency,
  166. projectId: projectId ?? this.projectId,
  167. projectName: projectName ?? this.projectName,
  168. budgetSubjectId: budgetSubjectId ?? this.budgetSubjectId,
  169. details: details ?? this.details,
  170. approvalRecords: approvalRecords ?? this.approvalRecords,
  171. );
  172. }
  173. }
  174. class ExpenseAppDetailModel {
  175. final String id;
  176. final String applicationId;
  177. final String itemName;
  178. final double estimatedAmount;
  179. final String remark;
  180. final int sortOrder;
  181. const ExpenseAppDetailModel({
  182. required this.id,
  183. this.applicationId = '',
  184. this.itemName = '',
  185. this.estimatedAmount = 0.0,
  186. this.remark = '',
  187. this.sortOrder = 1,
  188. });
  189. factory ExpenseAppDetailModel.fromJson(Map<String, dynamic> json) {
  190. return ExpenseAppDetailModel(
  191. id: json['id'] as String,
  192. applicationId: json['applicationId'] as String? ?? '',
  193. itemName: json['itemName'] as String? ?? '',
  194. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  195. remark: json['remark'] as String? ?? '',
  196. sortOrder: json['sortOrder'] as int? ?? 1,
  197. );
  198. }
  199. Map<String, dynamic> toJson() => {
  200. 'id': id,
  201. 'applicationId': applicationId,
  202. 'itemName': itemName,
  203. 'estimatedAmount': estimatedAmount,
  204. 'remark': remark,
  205. 'sortOrder': sortOrder,
  206. };
  207. }