expense_model.dart 9.5 KB

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