expense_application_model.dart 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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) : null,
  74. estimatedEndDate: json['estimatedEndDate'] != null
  75. ? DateTime.parse(json['estimatedEndDate'] as String) : null,
  76. urgency: json['urgency'] as String? ?? 'normal',
  77. projectId: json['projectId'] as String? ?? '',
  78. projectName: json['projectName'] as String? ?? '',
  79. budgetSubjectId: json['budgetSubjectId'] as String? ?? '',
  80. details:
  81. (json['details'] as List<dynamic>?)
  82. ?.map((e) =>
  83. ExpenseAppDetailModel.fromJson(e as Map<String, dynamic>))
  84. .toList() ??
  85. [],
  86. approvalRecords:
  87. (json['approvalRecords'] as List<dynamic>?)
  88. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  89. .toList() ??
  90. [],
  91. );
  92. }
  93. Map<String, dynamic> toJson() => {
  94. 'id': id,
  95. 'applicationNo': applicationNo,
  96. 'applicantId': applicantId,
  97. 'applicantName': applicantName,
  98. 'deptId': deptId,
  99. 'deptName': deptName,
  100. 'expenseType': expenseType,
  101. 'estimatedAmount': estimatedAmount,
  102. 'purpose': purpose,
  103. 'remark': remark,
  104. 'status': status,
  105. 'currentApproverId': currentApproverId,
  106. 'approvalChain': approvalChain,
  107. 'createTime': createTime.toIso8601String(),
  108. 'updateTime': updateTime.toIso8601String(),
  109. 'estimatedStartDate': estimatedStartDate?.toIso8601String(),
  110. 'estimatedEndDate': estimatedEndDate?.toIso8601String(),
  111. 'urgency': urgency,
  112. 'projectId': projectId,
  113. 'projectName': projectName,
  114. 'budgetSubjectId': budgetSubjectId,
  115. 'details': details.map((d) => d.toJson()).toList(),
  116. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  117. };
  118. ExpenseApplicationModel copyWith({
  119. String? id,
  120. String? applicationNo,
  121. String? applicantId,
  122. String? applicantName,
  123. String? deptId,
  124. String? deptName,
  125. String? expenseType,
  126. double? estimatedAmount,
  127. String? purpose,
  128. String? remark,
  129. String? status,
  130. String? currentApproverId,
  131. List<String>? approvalChain,
  132. DateTime? createTime,
  133. DateTime? updateTime,
  134. DateTime? estimatedStartDate,
  135. DateTime? estimatedEndDate,
  136. String? urgency,
  137. String? projectId,
  138. String? projectName,
  139. String? budgetSubjectId,
  140. List<ExpenseAppDetailModel>? details,
  141. List<ApprovalRecord>? approvalRecords,
  142. }) {
  143. return ExpenseApplicationModel(
  144. id: id ?? this.id,
  145. applicationNo: applicationNo ?? this.applicationNo,
  146. applicantId: applicantId ?? this.applicantId,
  147. applicantName: applicantName ?? this.applicantName,
  148. deptId: deptId ?? this.deptId,
  149. deptName: deptName ?? this.deptName,
  150. expenseType: expenseType ?? this.expenseType,
  151. estimatedAmount: estimatedAmount ?? this.estimatedAmount,
  152. purpose: purpose ?? this.purpose,
  153. remark: remark ?? this.remark,
  154. status: status ?? this.status,
  155. currentApproverId: currentApproverId ?? this.currentApproverId,
  156. approvalChain: approvalChain ?? this.approvalChain,
  157. createTime: createTime ?? this.createTime,
  158. updateTime: updateTime ?? this.updateTime,
  159. estimatedStartDate: estimatedStartDate ?? this.estimatedStartDate,
  160. estimatedEndDate: estimatedEndDate ?? this.estimatedEndDate,
  161. urgency: urgency ?? this.urgency,
  162. projectId: projectId ?? this.projectId,
  163. projectName: projectName ?? this.projectName,
  164. budgetSubjectId: budgetSubjectId ?? this.budgetSubjectId,
  165. details: details ?? this.details,
  166. approvalRecords: approvalRecords ?? this.approvalRecords,
  167. );
  168. }
  169. }
  170. class ExpenseAppDetailModel {
  171. final String id;
  172. final String applicationId;
  173. final String itemName;
  174. final double estimatedAmount;
  175. final String remark;
  176. final int sortOrder;
  177. const ExpenseAppDetailModel({
  178. required this.id,
  179. this.applicationId = '',
  180. this.itemName = '',
  181. this.estimatedAmount = 0.0,
  182. this.remark = '',
  183. this.sortOrder = 1,
  184. });
  185. factory ExpenseAppDetailModel.fromJson(Map<String, dynamic> json) {
  186. return ExpenseAppDetailModel(
  187. id: json['id'] as String,
  188. applicationId: json['applicationId'] as String? ?? '',
  189. itemName: json['itemName'] as String? ?? '',
  190. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  191. remark: json['remark'] as String? ?? '',
  192. sortOrder: json['sortOrder'] as int? ?? 1,
  193. );
  194. }
  195. Map<String, dynamic> toJson() => {
  196. 'id': id,
  197. 'applicationId': applicationId,
  198. 'itemName': itemName,
  199. 'estimatedAmount': estimatedAmount,
  200. 'remark': remark,
  201. 'sortOrder': sortOrder,
  202. };
  203. }