expense_model.dart 16 KB

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