expense_model.dart 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import '../../shared/models/approval_status.dart';
  2. class ExpenseModel {
  3. final String id;
  4. final String reportNo;
  5. final String applicantId;
  6. final String applicantName;
  7. final String deptId;
  8. final String deptName;
  9. final String expenseType;
  10. final double totalAmount;
  11. final int invoiceCount;
  12. final String costCenterId;
  13. final String projectId;
  14. final String projectName;
  15. final String budgetSubjectId;
  16. final double loanWriteoffAmount;
  17. final String paymentMethod;
  18. final String accountId;
  19. final String accountName;
  20. final String remark;
  21. final String status;
  22. final String currentApproverId;
  23. final List<String> approvalChain;
  24. final DateTime createTime;
  25. final DateTime updateTime;
  26. final List<ExpenseDetailModel> details;
  27. final List<ApprovalRecord> approvalRecords;
  28. const ExpenseModel({
  29. required this.id,
  30. required this.reportNo,
  31. required this.applicantId,
  32. required this.applicantName,
  33. required this.deptId,
  34. required this.deptName,
  35. required this.expenseType,
  36. required this.totalAmount,
  37. this.invoiceCount = 0,
  38. this.costCenterId = '',
  39. this.projectId = '',
  40. this.projectName = '',
  41. this.budgetSubjectId = '',
  42. this.loanWriteoffAmount = 0.0,
  43. this.paymentMethod = '',
  44. this.accountId = '',
  45. this.accountName = '',
  46. this.remark = '',
  47. this.status = 'draft',
  48. this.currentApproverId = '',
  49. this.approvalChain = const [],
  50. required this.createTime,
  51. required this.updateTime,
  52. this.details = const [],
  53. this.approvalRecords = const [],
  54. });
  55. factory ExpenseModel.fromJson(Map<String, dynamic> json) {
  56. return ExpenseModel(
  57. id: json['id'] as String,
  58. reportNo: json['reportNo'] as String? ?? '',
  59. applicantId: json['applicantId'] as String? ?? '',
  60. applicantName: json['applicantName'] as String? ?? '',
  61. deptId: json['deptId'] as String? ?? '',
  62. deptName: json['deptName'] as String? ?? '',
  63. expenseType: json['expenseType'] as String? ?? '',
  64. totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0.0,
  65. invoiceCount: json['invoiceCount'] as int? ?? 0,
  66. costCenterId: json['costCenterId'] as String? ?? '',
  67. projectId: json['projectId'] as String? ?? '',
  68. projectName: json['projectName'] as String? ?? '',
  69. budgetSubjectId: json['budgetSubjectId'] as String? ?? '',
  70. loanWriteoffAmount:
  71. (json['loanWriteoffAmount'] as num?)?.toDouble() ?? 0.0,
  72. paymentMethod: json['paymentMethod'] as String? ?? '',
  73. accountId: json['accountId'] as String? ?? '',
  74. accountName: json['accountName'] as String? ?? '',
  75. remark: json['remark'] as String? ?? '',
  76. status: json['status'] as String? ?? 'draft',
  77. currentApproverId: json['currentApproverId'] as String? ?? '',
  78. approvalChain:
  79. (json['approvalChain'] as List<dynamic>?)
  80. ?.map((e) => e as String)
  81. .toList() ??
  82. [],
  83. createTime: DateTime.parse(json['createTime'] as String),
  84. updateTime: DateTime.parse(json['updateTime'] as String),
  85. details:
  86. (json['details'] as List<dynamic>?)
  87. ?.map(
  88. (e) => ExpenseDetailModel.fromJson(e as Map<String, dynamic>))
  89. .toList() ??
  90. [],
  91. approvalRecords:
  92. (json['approvalRecords'] as List<dynamic>?)
  93. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  94. .toList() ??
  95. [],
  96. );
  97. }
  98. Map<String, dynamic> toJson() => {
  99. 'id': id,
  100. 'reportNo': reportNo,
  101. 'applicantId': applicantId,
  102. 'applicantName': applicantName,
  103. 'deptId': deptId,
  104. 'deptName': deptName,
  105. 'expenseType': expenseType,
  106. 'totalAmount': totalAmount,
  107. 'invoiceCount': invoiceCount,
  108. 'costCenterId': costCenterId,
  109. 'projectId': projectId,
  110. 'projectName': projectName,
  111. 'budgetSubjectId': budgetSubjectId,
  112. 'loanWriteoffAmount': loanWriteoffAmount,
  113. 'paymentMethod': paymentMethod,
  114. 'accountId': accountId,
  115. 'accountName': accountName,
  116. 'remark': remark,
  117. 'status': status,
  118. 'currentApproverId': currentApproverId,
  119. 'approvalChain': approvalChain,
  120. 'createTime': createTime.toIso8601String(),
  121. 'updateTime': updateTime.toIso8601String(),
  122. 'details': details.map((d) => d.toJson()).toList(),
  123. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  124. };
  125. ExpenseModel copyWith({
  126. String? id,
  127. String? reportNo,
  128. String? applicantId,
  129. String? applicantName,
  130. String? deptId,
  131. String? deptName,
  132. String? expenseType,
  133. double? totalAmount,
  134. int? invoiceCount,
  135. String? costCenterId,
  136. String? projectId,
  137. String? projectName,
  138. String? budgetSubjectId,
  139. double? loanWriteoffAmount,
  140. String? paymentMethod,
  141. String? accountId,
  142. String? accountName,
  143. String? remark,
  144. String? status,
  145. String? currentApproverId,
  146. List<String>? approvalChain,
  147. DateTime? createTime,
  148. DateTime? updateTime,
  149. List<ExpenseDetailModel>? details,
  150. List<ApprovalRecord>? approvalRecords,
  151. }) {
  152. return ExpenseModel(
  153. id: id ?? this.id,
  154. reportNo: reportNo ?? this.reportNo,
  155. applicantId: applicantId ?? this.applicantId,
  156. applicantName: applicantName ?? this.applicantName,
  157. deptId: deptId ?? this.deptId,
  158. deptName: deptName ?? this.deptName,
  159. expenseType: expenseType ?? this.expenseType,
  160. totalAmount: totalAmount ?? this.totalAmount,
  161. invoiceCount: invoiceCount ?? this.invoiceCount,
  162. costCenterId: costCenterId ?? this.costCenterId,
  163. projectId: projectId ?? this.projectId,
  164. projectName: projectName ?? this.projectName,
  165. budgetSubjectId: budgetSubjectId ?? this.budgetSubjectId,
  166. loanWriteoffAmount: loanWriteoffAmount ?? this.loanWriteoffAmount,
  167. paymentMethod: paymentMethod ?? this.paymentMethod,
  168. accountId: accountId ?? this.accountId,
  169. accountName: accountName ?? this.accountName,
  170. remark: remark ?? this.remark,
  171. status: status ?? this.status,
  172. currentApproverId: currentApproverId ?? this.currentApproverId,
  173. approvalChain: approvalChain ?? this.approvalChain,
  174. createTime: createTime ?? this.createTime,
  175. updateTime: updateTime ?? this.updateTime,
  176. details: details ?? this.details,
  177. approvalRecords: approvalRecords ?? this.approvalRecords,
  178. );
  179. }
  180. }
  181. class ExpenseDetailModel {
  182. final String id;
  183. final String expenseId;
  184. final DateTime expenseDate;
  185. final String expenseType;
  186. final String expenseDesc;
  187. final double amount;
  188. final double taxAmount;
  189. final double totalAmount;
  190. final String invoiceNo;
  191. final String invoiceCode;
  192. final String invoiceType;
  193. final bool isDeductible;
  194. final double taxRate;
  195. final String remark;
  196. final List<String> attachments;
  197. final int sortOrder;
  198. const ExpenseDetailModel({
  199. required this.id,
  200. required this.expenseId,
  201. required this.expenseDate,
  202. required this.expenseType,
  203. required this.expenseDesc,
  204. required this.amount,
  205. this.taxAmount = 0.0,
  206. required this.totalAmount,
  207. this.invoiceNo = '',
  208. this.invoiceCode = '',
  209. this.invoiceType = '',
  210. this.isDeductible = false,
  211. this.taxRate = 0.0,
  212. this.remark = '',
  213. this.attachments = const [],
  214. this.sortOrder = 1,
  215. });
  216. factory ExpenseDetailModel.fromJson(Map<String, dynamic> json) {
  217. return ExpenseDetailModel(
  218. id: json['id'] as String,
  219. expenseId: json['expenseId'] as String? ?? '',
  220. expenseDate: DateTime.parse(json['expenseDate'] as String),
  221. expenseType: json['expenseType'] as String? ?? '',
  222. expenseDesc: json['expenseDesc'] as String? ?? '',
  223. amount: (json['amount'] as num?)?.toDouble() ?? 0.0,
  224. taxAmount: (json['taxAmount'] as num?)?.toDouble() ?? 0.0,
  225. totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0.0,
  226. invoiceNo: json['invoiceNo'] as String? ?? '',
  227. invoiceCode: json['invoiceCode'] as String? ?? '',
  228. invoiceType: json['invoiceType'] as String? ?? '',
  229. isDeductible: json['isDeductible'] as bool? ?? false,
  230. taxRate: (json['taxRate'] as num?)?.toDouble() ?? 0.0,
  231. remark: json['remark'] as String? ?? '',
  232. attachments:
  233. (json['attachments'] as List<dynamic>?)
  234. ?.map((e) => e as String)
  235. .toList() ??
  236. [],
  237. sortOrder: json['sortOrder'] as int? ?? 1,
  238. );
  239. }
  240. Map<String, dynamic> toJson() => {
  241. 'id': id,
  242. 'expenseId': expenseId,
  243. 'expenseDate': expenseDate.toIso8601String(),
  244. 'expenseType': expenseType,
  245. 'expenseDesc': expenseDesc,
  246. 'amount': amount,
  247. 'taxAmount': taxAmount,
  248. 'totalAmount': totalAmount,
  249. 'invoiceNo': invoiceNo,
  250. 'invoiceCode': invoiceCode,
  251. 'invoiceType': invoiceType,
  252. 'isDeductible': isDeductible,
  253. 'taxRate': taxRate,
  254. 'remark': remark,
  255. 'attachments': attachments,
  256. 'sortOrder': sortOrder,
  257. };
  258. }