expense_application_model.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 List<ExpenseAppDetailModel> details;
  19. final List<ApprovalRecord> approvalRecords;
  20. const ExpenseApplicationModel({
  21. required this.id,
  22. required this.applicationNo,
  23. this.applicantId = '',
  24. this.applicantName = '',
  25. this.deptId = '',
  26. this.deptName = '',
  27. this.expenseType = '',
  28. this.estimatedAmount = 0.0,
  29. this.purpose = '',
  30. this.remark = '',
  31. this.status = 'draft',
  32. this.currentApproverId = '',
  33. this.approvalChain = const [],
  34. required this.createTime,
  35. required this.updateTime,
  36. this.details = const [],
  37. this.approvalRecords = const [],
  38. });
  39. factory ExpenseApplicationModel.fromJson(Map<String, dynamic> json) {
  40. return ExpenseApplicationModel(
  41. id: json['id'] as String,
  42. applicationNo: json['applicationNo'] as String? ?? '',
  43. applicantId: json['applicantId'] as String? ?? '',
  44. applicantName: json['applicantName'] as String? ?? '',
  45. deptId: json['deptId'] as String? ?? '',
  46. deptName: json['deptName'] as String? ?? '',
  47. expenseType: json['expenseType'] as String? ?? '',
  48. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  49. purpose: json['purpose'] as String? ?? '',
  50. remark: json['remark'] as String? ?? '',
  51. status: json['status'] as String? ?? 'draft',
  52. currentApproverId: json['currentApproverId'] as String? ?? '',
  53. approvalChain:
  54. (json['approvalChain'] as List<dynamic>?)
  55. ?.map((e) => e as String)
  56. .toList() ??
  57. [],
  58. createTime: DateTime.parse(json['createTime'] as String),
  59. updateTime: DateTime.parse(json['updateTime'] as String),
  60. details:
  61. (json['details'] as List<dynamic>?)
  62. ?.map((e) =>
  63. ExpenseAppDetailModel.fromJson(e as Map<String, dynamic>))
  64. .toList() ??
  65. [],
  66. approvalRecords:
  67. (json['approvalRecords'] as List<dynamic>?)
  68. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  69. .toList() ??
  70. [],
  71. );
  72. }
  73. Map<String, dynamic> toJson() => {
  74. 'id': id,
  75. 'applicationNo': applicationNo,
  76. 'applicantId': applicantId,
  77. 'applicantName': applicantName,
  78. 'deptId': deptId,
  79. 'deptName': deptName,
  80. 'expenseType': expenseType,
  81. 'estimatedAmount': estimatedAmount,
  82. 'purpose': purpose,
  83. 'remark': remark,
  84. 'status': status,
  85. 'currentApproverId': currentApproverId,
  86. 'approvalChain': approvalChain,
  87. 'createTime': createTime.toIso8601String(),
  88. 'updateTime': updateTime.toIso8601String(),
  89. 'details': details.map((d) => d.toJson()).toList(),
  90. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  91. };
  92. ExpenseApplicationModel copyWith({
  93. String? id,
  94. String? applicationNo,
  95. String? applicantId,
  96. String? applicantName,
  97. String? deptId,
  98. String? deptName,
  99. String? expenseType,
  100. double? estimatedAmount,
  101. String? purpose,
  102. String? remark,
  103. String? status,
  104. String? currentApproverId,
  105. List<String>? approvalChain,
  106. DateTime? createTime,
  107. DateTime? updateTime,
  108. List<ExpenseAppDetailModel>? details,
  109. List<ApprovalRecord>? approvalRecords,
  110. }) {
  111. return ExpenseApplicationModel(
  112. id: id ?? this.id,
  113. applicationNo: applicationNo ?? this.applicationNo,
  114. applicantId: applicantId ?? this.applicantId,
  115. applicantName: applicantName ?? this.applicantName,
  116. deptId: deptId ?? this.deptId,
  117. deptName: deptName ?? this.deptName,
  118. expenseType: expenseType ?? this.expenseType,
  119. estimatedAmount: estimatedAmount ?? this.estimatedAmount,
  120. purpose: purpose ?? this.purpose,
  121. remark: remark ?? this.remark,
  122. status: status ?? this.status,
  123. currentApproverId: currentApproverId ?? this.currentApproverId,
  124. approvalChain: approvalChain ?? this.approvalChain,
  125. createTime: createTime ?? this.createTime,
  126. updateTime: updateTime ?? this.updateTime,
  127. details: details ?? this.details,
  128. approvalRecords: approvalRecords ?? this.approvalRecords,
  129. );
  130. }
  131. }
  132. class ExpenseAppDetailModel {
  133. final String id;
  134. final String applicationId;
  135. final String itemName;
  136. final double estimatedAmount;
  137. final String remark;
  138. final int sortOrder;
  139. const ExpenseAppDetailModel({
  140. required this.id,
  141. this.applicationId = '',
  142. this.itemName = '',
  143. this.estimatedAmount = 0.0,
  144. this.remark = '',
  145. this.sortOrder = 1,
  146. });
  147. factory ExpenseAppDetailModel.fromJson(Map<String, dynamic> json) {
  148. return ExpenseAppDetailModel(
  149. id: json['id'] as String,
  150. applicationId: json['applicationId'] as String? ?? '',
  151. itemName: json['itemName'] as String? ?? '',
  152. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  153. remark: json['remark'] as String? ?? '',
  154. sortOrder: json['sortOrder'] as int? ?? 1,
  155. );
  156. }
  157. Map<String, dynamic> toJson() => {
  158. 'id': id,
  159. 'applicationId': applicationId,
  160. 'itemName': itemName,
  161. 'estimatedAmount': estimatedAmount,
  162. 'remark': remark,
  163. 'sortOrder': sortOrder,
  164. };
  165. }