expense_model.dart 9.7 KB

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