expense_model.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 costCenterName;
  14. final String projectId;
  15. final String projectName;
  16. final String budgetSubjectId;
  17. final String budgetSubjectName;
  18. final double loanWriteoffAmount;
  19. final String paymentMethod;
  20. final String accountBankName;
  21. final String accountHolderName;
  22. final String accountId;
  23. final String accountName;
  24. final String remark;
  25. final String purpose;
  26. final String status;
  27. final String currentApproverId;
  28. final List<String> approvalChain;
  29. final DateTime createTime;
  30. final DateTime updateTime;
  31. final List<String> attachments;
  32. final String paymentStatus;
  33. final String voucherNo;
  34. final List<ExpenseDetailModel> details;
  35. final List<ApprovalRecord> approvalRecords;
  36. // 财务查验
  37. final bool isInvoiceVerified;
  38. final bool isTaxIdMatched;
  39. final bool isCategoryCompliant;
  40. // 申请来源
  41. final String sourceApplicationId;
  42. final double sourceImportAmount;
  43. // 发票附件图片
  44. final List<String> invoiceImages;
  45. // 数据库字段
  46. final String bankName;
  47. final String bankAccount;
  48. final String bankTransferNo;
  49. final String approvalInstanceId;
  50. final DateTime? applicationDate;
  51. const ExpenseModel({
  52. required this.id,
  53. required this.reportNo,
  54. required this.applicantId,
  55. required this.applicantName,
  56. required this.deptId,
  57. required this.deptName,
  58. required this.expenseType,
  59. required this.totalAmount,
  60. this.invoiceCount = 0,
  61. this.costCenterId = '',
  62. this.costCenterName = '',
  63. this.projectId = '',
  64. this.projectName = '',
  65. this.budgetSubjectId = '',
  66. this.budgetSubjectName = '',
  67. this.loanWriteoffAmount = 0.0,
  68. this.attachments = const [],
  69. this.paymentStatus = 'unpaid',
  70. this.voucherNo = '',
  71. this.paymentMethod = '',
  72. this.accountId = '',
  73. this.accountName = '',
  74. this.accountBankName = '',
  75. this.accountHolderName = '',
  76. this.remark = '',
  77. this.purpose = '',
  78. this.status = 'draft',
  79. this.currentApproverId = '',
  80. this.approvalChain = const [],
  81. required this.createTime,
  82. required this.updateTime,
  83. this.details = const [],
  84. this.approvalRecords = const [],
  85. this.isInvoiceVerified = false,
  86. this.isTaxIdMatched = false,
  87. this.isCategoryCompliant = false,
  88. this.sourceApplicationId = '',
  89. this.sourceImportAmount = 0.0,
  90. this.bankName = '',
  91. this.bankAccount = '',
  92. this.bankTransferNo = '',
  93. this.approvalInstanceId = '',
  94. this.applicationDate,
  95. this.invoiceImages = const [],
  96. });
  97. factory ExpenseModel.fromJson(Map<String, dynamic> json) {
  98. return ExpenseModel(
  99. id: json['id'] as String,
  100. reportNo: json['reportNo'] as String? ?? '',
  101. applicantId: json['applicantId'] as String? ?? '',
  102. applicantName: json['applicantName'] as String? ?? '',
  103. deptId: json['deptId'] as String? ?? '',
  104. deptName: json['deptName'] as String? ?? '',
  105. expenseType: json['expenseType'] as String? ?? '',
  106. totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0.0,
  107. invoiceCount: json['invoiceCount'] as int? ?? 0,
  108. costCenterId: json['costCenterId'] as String? ?? '',
  109. costCenterName: json['costCenterName'] as String? ?? '',
  110. projectId: json['projectId'] as String? ?? '',
  111. projectName: json['projectName'] as String? ?? '',
  112. budgetSubjectId: json['budgetSubjectId'] as String? ?? '',
  113. budgetSubjectName: json['budgetSubjectName'] as String? ?? '',
  114. loanWriteoffAmount:
  115. (json['loanWriteoffAmount'] as num?)?.toDouble() ?? 0.0,
  116. attachments:
  117. (json['attachments'] as List<dynamic>?)
  118. ?.map((e) => e as String)
  119. .toList() ??
  120. [],
  121. paymentStatus: json['paymentStatus'] as String? ?? 'unpaid',
  122. voucherNo: json['voucherNo'] as String? ?? '',
  123. paymentMethod: json['paymentMethod'] as String? ?? '',
  124. accountId: json['accountId'] as String? ?? '',
  125. accountName: json['accountName'] as String? ?? '',
  126. accountBankName: json['accountBankName'] as String? ?? '',
  127. accountHolderName: json['accountHolderName'] as String? ?? '',
  128. remark: json['remark'] as String? ?? '',
  129. purpose: json['purpose'] as String? ?? '',
  130. status: json['status'] as String? ?? 'draft',
  131. currentApproverId: json['currentApproverId'] as String? ?? '',
  132. approvalChain:
  133. (json['approvalChain'] as List<dynamic>?)
  134. ?.map((e) => e as String)
  135. .toList() ??
  136. [],
  137. createTime: DateTime.parse(json['createTime'] as String),
  138. updateTime: DateTime.parse(json['updateTime'] as String),
  139. details:
  140. (json['details'] as List<dynamic>?)
  141. ?.map(
  142. (e) => ExpenseDetailModel.fromJson(e as Map<String, dynamic>),
  143. )
  144. .toList() ??
  145. [],
  146. approvalRecords:
  147. (json['approvalRecords'] as List<dynamic>?)
  148. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  149. .toList() ??
  150. [],
  151. isInvoiceVerified: json['isInvoiceVerified'] as bool? ?? false,
  152. isTaxIdMatched: json['isTaxIdMatched'] as bool? ?? false,
  153. isCategoryCompliant: json['isCategoryCompliant'] as bool? ?? false,
  154. sourceApplicationId: json['sourceApplicationId'] as String? ?? '',
  155. sourceImportAmount:
  156. (json['sourceImportAmount'] as num?)?.toDouble() ?? 0.0,
  157. bankName: json['bankName'] as String? ?? '',
  158. bankAccount: json['bankAccount'] as String? ?? '',
  159. bankTransferNo: json['bankTransferNo'] as String? ?? '',
  160. approvalInstanceId: json['approvalInstanceId'] as String? ?? '',
  161. applicationDate: json['applicationDate'] != null
  162. ? DateTime.parse(json['applicationDate'] as String)
  163. : null,
  164. invoiceImages:
  165. (json['invoiceImages'] as List<dynamic>?)
  166. ?.map((e) => e as String)
  167. .toList() ??
  168. [],
  169. );
  170. }
  171. Map<String, dynamic> toJson() => {
  172. 'id': id,
  173. 'reportNo': reportNo,
  174. 'applicantId': applicantId,
  175. 'applicantName': applicantName,
  176. 'deptId': deptId,
  177. 'deptName': deptName,
  178. 'expenseType': expenseType,
  179. 'totalAmount': totalAmount,
  180. 'invoiceCount': invoiceCount,
  181. 'costCenterId': costCenterId,
  182. 'costCenterName': costCenterName,
  183. 'projectId': projectId,
  184. 'projectName': projectName,
  185. 'budgetSubjectId': budgetSubjectId,
  186. 'budgetSubjectName': budgetSubjectName,
  187. 'loanWriteoffAmount': loanWriteoffAmount,
  188. 'attachments': attachments,
  189. 'paymentStatus': paymentStatus,
  190. 'voucherNo': voucherNo,
  191. 'paymentMethod': paymentMethod,
  192. 'accountId': accountId,
  193. 'accountName': accountName,
  194. 'accountBankName': accountBankName,
  195. 'accountHolderName': accountHolderName,
  196. 'remark': remark,
  197. 'purpose': purpose,
  198. 'status': status,
  199. 'currentApproverId': currentApproverId,
  200. 'approvalChain': approvalChain,
  201. 'createTime': createTime.toIso8601String(),
  202. 'updateTime': updateTime.toIso8601String(),
  203. 'details': details.map((d) => d.toJson()).toList(),
  204. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  205. 'isInvoiceVerified': isInvoiceVerified,
  206. 'isTaxIdMatched': isTaxIdMatched,
  207. 'isCategoryCompliant': isCategoryCompliant,
  208. 'sourceApplicationId': sourceApplicationId,
  209. 'sourceImportAmount': sourceImportAmount,
  210. 'bankName': bankName,
  211. 'bankAccount': bankAccount,
  212. 'bankTransferNo': bankTransferNo,
  213. 'approvalInstanceId': approvalInstanceId,
  214. 'applicationDate': applicationDate?.toIso8601String(),
  215. 'invoiceImages': invoiceImages,
  216. };
  217. ExpenseModel copyWith({
  218. String? id,
  219. String? reportNo,
  220. String? applicantId,
  221. String? applicantName,
  222. String? deptId,
  223. String? deptName,
  224. String? expenseType,
  225. double? totalAmount,
  226. int? invoiceCount,
  227. String? costCenterId,
  228. String? costCenterName,
  229. String? projectId,
  230. String? projectName,
  231. String? budgetSubjectId,
  232. String? budgetSubjectName,
  233. double? loanWriteoffAmount,
  234. List<String>? attachments,
  235. String? paymentStatus,
  236. String? voucherNo,
  237. String? paymentMethod,
  238. String? accountId,
  239. String? accountName,
  240. String? accountBankName,
  241. String? accountHolderName,
  242. String? remark,
  243. String? purpose,
  244. String? status,
  245. String? currentApproverId,
  246. List<String>? approvalChain,
  247. DateTime? createTime,
  248. DateTime? updateTime,
  249. List<ExpenseDetailModel>? details,
  250. List<ApprovalRecord>? approvalRecords,
  251. bool? isInvoiceVerified,
  252. bool? isTaxIdMatched,
  253. bool? isCategoryCompliant,
  254. String? sourceApplicationId,
  255. double? sourceImportAmount,
  256. String? bankName,
  257. String? bankAccount,
  258. String? bankTransferNo,
  259. String? approvalInstanceId,
  260. DateTime? applicationDate,
  261. List<String>? invoiceImages,
  262. }) {
  263. return ExpenseModel(
  264. id: id ?? this.id,
  265. reportNo: reportNo ?? this.reportNo,
  266. applicantId: applicantId ?? this.applicantId,
  267. applicantName: applicantName ?? this.applicantName,
  268. deptId: deptId ?? this.deptId,
  269. deptName: deptName ?? this.deptName,
  270. expenseType: expenseType ?? this.expenseType,
  271. totalAmount: totalAmount ?? this.totalAmount,
  272. invoiceCount: invoiceCount ?? this.invoiceCount,
  273. costCenterId: costCenterId ?? this.costCenterId,
  274. costCenterName: costCenterName ?? this.costCenterName,
  275. projectId: projectId ?? this.projectId,
  276. projectName: projectName ?? this.projectName,
  277. budgetSubjectId: budgetSubjectId ?? this.budgetSubjectId,
  278. budgetSubjectName: budgetSubjectName ?? this.budgetSubjectName,
  279. loanWriteoffAmount: loanWriteoffAmount ?? this.loanWriteoffAmount,
  280. attachments: attachments ?? this.attachments,
  281. paymentStatus: paymentStatus ?? this.paymentStatus,
  282. voucherNo: voucherNo ?? this.voucherNo,
  283. paymentMethod: paymentMethod ?? this.paymentMethod,
  284. accountId: accountId ?? this.accountId,
  285. accountName: accountName ?? this.accountName,
  286. accountBankName: accountBankName ?? this.accountBankName,
  287. accountHolderName: accountHolderName ?? this.accountHolderName,
  288. remark: remark ?? this.remark,
  289. purpose: purpose ?? this.purpose,
  290. status: status ?? this.status,
  291. currentApproverId: currentApproverId ?? this.currentApproverId,
  292. approvalChain: approvalChain ?? this.approvalChain,
  293. createTime: createTime ?? this.createTime,
  294. updateTime: updateTime ?? this.updateTime,
  295. details: details ?? this.details,
  296. approvalRecords: approvalRecords ?? this.approvalRecords,
  297. isInvoiceVerified: isInvoiceVerified ?? this.isInvoiceVerified,
  298. isTaxIdMatched: isTaxIdMatched ?? this.isTaxIdMatched,
  299. isCategoryCompliant: isCategoryCompliant ?? this.isCategoryCompliant,
  300. sourceApplicationId: sourceApplicationId ?? this.sourceApplicationId,
  301. sourceImportAmount: sourceImportAmount ?? this.sourceImportAmount,
  302. bankName: bankName ?? this.bankName,
  303. bankAccount: bankAccount ?? this.bankAccount,
  304. bankTransferNo: bankTransferNo ?? this.bankTransferNo,
  305. approvalInstanceId: approvalInstanceId ?? this.approvalInstanceId,
  306. applicationDate: applicationDate ?? this.applicationDate,
  307. invoiceImages: invoiceImages ?? this.invoiceImages,
  308. );
  309. }
  310. }
  311. class ExpenseDetailModel {
  312. final String id;
  313. final String expenseId;
  314. final DateTime expenseDate;
  315. final String expenseType;
  316. final String expenseDesc;
  317. final double amount;
  318. final double taxAmount;
  319. final double totalAmount;
  320. final double baseAmount;
  321. final String currency;
  322. final double exchangeRate;
  323. final String invoiceNo;
  324. final String invoiceCode;
  325. final String invoiceType;
  326. final bool isDeductible;
  327. final double taxRate;
  328. final String remark;
  329. final List<String> attachments;
  330. final int sortOrder;
  331. const ExpenseDetailModel({
  332. required this.id,
  333. required this.expenseId,
  334. required this.expenseDate,
  335. required this.expenseType,
  336. required this.expenseDesc,
  337. required this.amount,
  338. this.taxAmount = 0.0,
  339. required this.totalAmount,
  340. this.baseAmount = 0.0,
  341. this.currency = 'CNY',
  342. this.exchangeRate = 1.0,
  343. this.invoiceNo = '',
  344. this.invoiceCode = '',
  345. this.invoiceType = '',
  346. this.isDeductible = false,
  347. this.taxRate = 0.0,
  348. this.remark = '',
  349. this.attachments = const [],
  350. this.sortOrder = 1,
  351. });
  352. factory ExpenseDetailModel.fromJson(Map<String, dynamic> json) {
  353. return ExpenseDetailModel(
  354. id: json['id'] as String,
  355. expenseId: json['expenseId'] as String? ?? '',
  356. expenseDate: DateTime.parse(json['expenseDate'] as String),
  357. expenseType: json['expenseType'] as String? ?? '',
  358. expenseDesc: json['expenseDesc'] as String? ?? '',
  359. amount: (json['amount'] as num?)?.toDouble() ?? 0.0,
  360. taxAmount: (json['taxAmount'] as num?)?.toDouble() ?? 0.0,
  361. totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0.0,
  362. baseAmount: (json['baseAmount'] as num?)?.toDouble() ?? 0.0,
  363. currency: json['currency'] as String? ?? 'CNY',
  364. exchangeRate: (json['exchangeRate'] as num?)?.toDouble() ?? 1.0,
  365. invoiceNo: json['invoiceNo'] as String? ?? '',
  366. invoiceCode: json['invoiceCode'] as String? ?? '',
  367. invoiceType: json['invoiceType'] as String? ?? '',
  368. isDeductible: json['isDeductible'] as bool? ?? false,
  369. taxRate: (json['taxRate'] as num?)?.toDouble() ?? 0.0,
  370. remark: json['remark'] as String? ?? '',
  371. attachments:
  372. (json['attachments'] as List<dynamic>?)
  373. ?.map((e) => e as String)
  374. .toList() ??
  375. [],
  376. sortOrder: json['sortOrder'] as int? ?? 1,
  377. );
  378. }
  379. Map<String, dynamic> toJson() => {
  380. 'id': id,
  381. 'expenseId': expenseId,
  382. 'expenseDate': expenseDate.toIso8601String(),
  383. 'expenseType': expenseType,
  384. 'expenseDesc': expenseDesc,
  385. 'amount': amount,
  386. 'taxAmount': taxAmount,
  387. 'totalAmount': totalAmount,
  388. 'baseAmount': baseAmount,
  389. 'currency': currency,
  390. 'exchangeRate': exchangeRate,
  391. 'invoiceNo': invoiceNo,
  392. 'invoiceCode': invoiceCode,
  393. 'invoiceType': invoiceType,
  394. 'isDeductible': isDeductible,
  395. 'taxRate': taxRate,
  396. 'remark': remark,
  397. 'attachments': attachments,
  398. 'sortOrder': sortOrder,
  399. };
  400. }