expense_model.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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: (json['sourceImportAmount'] as num?)?.toDouble() ?? 0.0,
  156. bankName: json['bankName'] as String? ?? '',
  157. bankAccount: json['bankAccount'] as String? ?? '',
  158. bankTransferNo: json['bankTransferNo'] as String? ?? '',
  159. approvalInstanceId: json['approvalInstanceId'] as String? ?? '',
  160. applicationDate: json['applicationDate'] != null
  161. ? DateTime.parse(json['applicationDate'] as String)
  162. : null,
  163. invoiceImages:
  164. (json['invoiceImages'] as List<dynamic>?)
  165. ?.map((e) => e as String)
  166. .toList() ??
  167. [],
  168. );
  169. }
  170. Map<String, dynamic> toJson() => {
  171. 'id': id,
  172. 'reportNo': reportNo,
  173. 'applicantId': applicantId,
  174. 'applicantName': applicantName,
  175. 'deptId': deptId,
  176. 'deptName': deptName,
  177. 'expenseType': expenseType,
  178. 'totalAmount': totalAmount,
  179. 'invoiceCount': invoiceCount,
  180. 'costCenterId': costCenterId,
  181. 'costCenterName': costCenterName,
  182. 'projectId': projectId,
  183. 'projectName': projectName,
  184. 'budgetSubjectId': budgetSubjectId,
  185. 'budgetSubjectName': budgetSubjectName,
  186. 'loanWriteoffAmount': loanWriteoffAmount,
  187. 'attachments': attachments,
  188. 'paymentStatus': paymentStatus,
  189. 'voucherNo': voucherNo,
  190. 'paymentMethod': paymentMethod,
  191. 'accountId': accountId,
  192. 'accountName': accountName,
  193. 'accountBankName': accountBankName,
  194. 'accountHolderName': accountHolderName,
  195. 'remark': remark,
  196. 'purpose': purpose,
  197. 'status': status,
  198. 'currentApproverId': currentApproverId,
  199. 'approvalChain': approvalChain,
  200. 'createTime': createTime.toIso8601String(),
  201. 'updateTime': updateTime.toIso8601String(),
  202. 'details': details.map((d) => d.toJson()).toList(),
  203. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  204. 'isInvoiceVerified': isInvoiceVerified,
  205. 'isTaxIdMatched': isTaxIdMatched,
  206. 'isCategoryCompliant': isCategoryCompliant,
  207. 'sourceApplicationId': sourceApplicationId,
  208. 'sourceImportAmount': sourceImportAmount,
  209. 'bankName': bankName,
  210. 'bankAccount': bankAccount,
  211. 'bankTransferNo': bankTransferNo,
  212. 'approvalInstanceId': approvalInstanceId,
  213. 'applicationDate': applicationDate?.toIso8601String(),
  214. 'invoiceImages': invoiceImages,
  215. };
  216. ExpenseModel copyWith({
  217. String? id,
  218. String? reportNo,
  219. String? applicantId,
  220. String? applicantName,
  221. String? deptId,
  222. String? deptName,
  223. String? expenseType,
  224. double? totalAmount,
  225. int? invoiceCount,
  226. String? costCenterId,
  227. String? costCenterName,
  228. String? projectId,
  229. String? projectName,
  230. String? budgetSubjectId,
  231. String? budgetSubjectName,
  232. double? loanWriteoffAmount,
  233. List<String>? attachments,
  234. String? paymentStatus,
  235. String? voucherNo,
  236. String? paymentMethod,
  237. String? accountId,
  238. String? accountName,
  239. String? accountBankName,
  240. String? accountHolderName,
  241. String? remark,
  242. String? purpose,
  243. String? status,
  244. String? currentApproverId,
  245. List<String>? approvalChain,
  246. DateTime? createTime,
  247. DateTime? updateTime,
  248. List<ExpenseDetailModel>? details,
  249. List<ApprovalRecord>? approvalRecords,
  250. bool? isInvoiceVerified,
  251. bool? isTaxIdMatched,
  252. bool? isCategoryCompliant,
  253. String? sourceApplicationId,
  254. double? sourceImportAmount,
  255. String? bankName,
  256. String? bankAccount,
  257. String? bankTransferNo,
  258. String? approvalInstanceId,
  259. DateTime? applicationDate,
  260. List<String>? invoiceImages,
  261. }) {
  262. return ExpenseModel(
  263. id: id ?? this.id,
  264. reportNo: reportNo ?? this.reportNo,
  265. applicantId: applicantId ?? this.applicantId,
  266. applicantName: applicantName ?? this.applicantName,
  267. deptId: deptId ?? this.deptId,
  268. deptName: deptName ?? this.deptName,
  269. expenseType: expenseType ?? this.expenseType,
  270. totalAmount: totalAmount ?? this.totalAmount,
  271. invoiceCount: invoiceCount ?? this.invoiceCount,
  272. costCenterId: costCenterId ?? this.costCenterId,
  273. costCenterName: costCenterName ?? this.costCenterName,
  274. projectId: projectId ?? this.projectId,
  275. projectName: projectName ?? this.projectName,
  276. budgetSubjectId: budgetSubjectId ?? this.budgetSubjectId,
  277. budgetSubjectName: budgetSubjectName ?? this.budgetSubjectName,
  278. loanWriteoffAmount: loanWriteoffAmount ?? this.loanWriteoffAmount,
  279. attachments: attachments ?? this.attachments,
  280. paymentStatus: paymentStatus ?? this.paymentStatus,
  281. voucherNo: voucherNo ?? this.voucherNo,
  282. paymentMethod: paymentMethod ?? this.paymentMethod,
  283. accountId: accountId ?? this.accountId,
  284. accountName: accountName ?? this.accountName,
  285. accountBankName: accountBankName ?? this.accountBankName,
  286. accountHolderName: accountHolderName ?? this.accountHolderName,
  287. remark: remark ?? this.remark,
  288. purpose: purpose ?? this.purpose,
  289. status: status ?? this.status,
  290. currentApproverId: currentApproverId ?? this.currentApproverId,
  291. approvalChain: approvalChain ?? this.approvalChain,
  292. createTime: createTime ?? this.createTime,
  293. updateTime: updateTime ?? this.updateTime,
  294. details: details ?? this.details,
  295. approvalRecords: approvalRecords ?? this.approvalRecords,
  296. isInvoiceVerified: isInvoiceVerified ?? this.isInvoiceVerified,
  297. isTaxIdMatched: isTaxIdMatched ?? this.isTaxIdMatched,
  298. isCategoryCompliant: isCategoryCompliant ?? this.isCategoryCompliant,
  299. sourceApplicationId: sourceApplicationId ?? this.sourceApplicationId,
  300. sourceImportAmount: sourceImportAmount ?? this.sourceImportAmount,
  301. bankName: bankName ?? this.bankName,
  302. bankAccount: bankAccount ?? this.bankAccount,
  303. bankTransferNo: bankTransferNo ?? this.bankTransferNo,
  304. approvalInstanceId: approvalInstanceId ?? this.approvalInstanceId,
  305. applicationDate: applicationDate ?? this.applicationDate,
  306. invoiceImages: invoiceImages ?? this.invoiceImages,
  307. );
  308. }
  309. }
  310. class ExpenseDetailModel {
  311. final String id;
  312. final String expenseId;
  313. final DateTime expenseDate;
  314. final String expenseType;
  315. final String expenseDesc;
  316. final double amount;
  317. final double taxAmount;
  318. final double totalAmount;
  319. final double baseAmount;
  320. final String currency;
  321. final double exchangeRate;
  322. final String invoiceNo;
  323. final String invoiceCode;
  324. final String invoiceType;
  325. final bool isDeductible;
  326. final double taxRate;
  327. final String remark;
  328. final List<String> attachments;
  329. final int sortOrder;
  330. const ExpenseDetailModel({
  331. required this.id,
  332. required this.expenseId,
  333. required this.expenseDate,
  334. required this.expenseType,
  335. required this.expenseDesc,
  336. required this.amount,
  337. this.taxAmount = 0.0,
  338. required this.totalAmount,
  339. this.baseAmount = 0.0,
  340. this.currency = 'CNY',
  341. this.exchangeRate = 1.0,
  342. this.invoiceNo = '',
  343. this.invoiceCode = '',
  344. this.invoiceType = '',
  345. this.isDeductible = false,
  346. this.taxRate = 0.0,
  347. this.remark = '',
  348. this.attachments = const [],
  349. this.sortOrder = 1,
  350. });
  351. factory ExpenseDetailModel.fromJson(Map<String, dynamic> json) {
  352. return ExpenseDetailModel(
  353. id: json['id'] as String,
  354. expenseId: json['expenseId'] as String? ?? '',
  355. expenseDate: DateTime.parse(json['expenseDate'] as String),
  356. expenseType: json['expenseType'] as String? ?? '',
  357. expenseDesc: json['expenseDesc'] as String? ?? '',
  358. amount: (json['amount'] as num?)?.toDouble() ?? 0.0,
  359. taxAmount: (json['taxAmount'] as num?)?.toDouble() ?? 0.0,
  360. totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0.0,
  361. baseAmount: (json['baseAmount'] as num?)?.toDouble() ?? 0.0,
  362. currency: json['currency'] as String? ?? 'CNY',
  363. exchangeRate: (json['exchangeRate'] as num?)?.toDouble() ?? 1.0,
  364. invoiceNo: json['invoiceNo'] as String? ?? '',
  365. invoiceCode: json['invoiceCode'] as String? ?? '',
  366. invoiceType: json['invoiceType'] as String? ?? '',
  367. isDeductible: json['isDeductible'] as bool? ?? false,
  368. taxRate: (json['taxRate'] as num?)?.toDouble() ?? 0.0,
  369. remark: json['remark'] as String? ?? '',
  370. attachments:
  371. (json['attachments'] as List<dynamic>?)
  372. ?.map((e) => e as String)
  373. .toList() ??
  374. [],
  375. sortOrder: json['sortOrder'] as int? ?? 1,
  376. );
  377. }
  378. Map<String, dynamic> toJson() => {
  379. 'id': id,
  380. 'expenseId': expenseId,
  381. 'expenseDate': expenseDate.toIso8601String(),
  382. 'expenseType': expenseType,
  383. 'expenseDesc': expenseDesc,
  384. 'amount': amount,
  385. 'taxAmount': taxAmount,
  386. 'totalAmount': totalAmount,
  387. 'baseAmount': baseAmount,
  388. 'currency': currency,
  389. 'exchangeRate': exchangeRate,
  390. 'invoiceNo': invoiceNo,
  391. 'invoiceCode': invoiceCode,
  392. 'invoiceType': invoiceType,
  393. 'isDeductible': isDeductible,
  394. 'taxRate': taxRate,
  395. 'remark': remark,
  396. 'attachments': attachments,
  397. 'sortOrder': sortOrder,
  398. };
  399. }