expense_model.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. import '../../shared/models/approval_status.dart';
  2. /// 费用报销主表,对应 [Expense] 表。
  3. class ExpenseModel {
  4. final String id;
  5. final String expenseNo;
  6. final DateTime? expenseDate;
  7. final String applicantId;
  8. final String applicantName;
  9. final String deptId;
  10. final String deptName;
  11. final String currencyCode;
  12. final bool isGenerateVoucher;
  13. final String voucherNo;
  14. final double approvedAmount;
  15. final double totalAmount;
  16. final String purpose;
  17. final String remark;
  18. final String paymentMethod;
  19. final bool isInvoiceVerified;
  20. final bool isTaxIdMatched;
  21. final bool isCategoryCompliant;
  22. final String bankTransferNo;
  23. final String paymentStatus;
  24. final String status;
  25. final String approvalInstanceId;
  26. final String previousInstanceIds;
  27. final DateTime? effectiveDate;
  28. final String auditorId;
  29. final int version;
  30. final DateTime createTime;
  31. final DateTime updateTime;
  32. final bool isDeleted;
  33. // ── 瞬态字段(API 从 ERP 实时查询,非存储) ──
  34. final String currentApproverId;
  35. final List<String> approvalChain;
  36. final List<ApprovalRecord> approvalRecords;
  37. // ── 子表 ──
  38. final List<ExpenseDetailModel> details;
  39. final List<String> attachments;
  40. const ExpenseModel({
  41. required this.id,
  42. required this.expenseNo,
  43. this.expenseDate,
  44. this.applicantId = '',
  45. this.applicantName = '',
  46. this.deptId = '',
  47. this.deptName = '',
  48. this.currencyCode = '',
  49. this.isGenerateVoucher = false,
  50. this.voucherNo = '',
  51. this.approvedAmount = 0.0,
  52. this.totalAmount = 0.0,
  53. this.purpose = '',
  54. this.remark = '',
  55. this.paymentMethod = '',
  56. this.isInvoiceVerified = false,
  57. this.isTaxIdMatched = false,
  58. this.isCategoryCompliant = false,
  59. this.bankTransferNo = '',
  60. this.paymentStatus = 'unpaid',
  61. this.status = 'draft',
  62. this.approvalInstanceId = '',
  63. this.previousInstanceIds = '',
  64. this.effectiveDate,
  65. this.auditorId = '',
  66. this.version = 1,
  67. required this.createTime,
  68. required this.updateTime,
  69. this.isDeleted = false,
  70. this.currentApproverId = '',
  71. this.approvalChain = const [],
  72. this.approvalRecords = const [],
  73. this.details = const [],
  74. this.attachments = const [],
  75. });
  76. factory ExpenseModel.fromJson(Map<String, dynamic> json) {
  77. return ExpenseModel(
  78. id: json['id'] as String? ?? '',
  79. expenseNo: json['bxNo'] as String? ?? '',
  80. expenseDate: json['bxDate'] != null
  81. ? DateTime.parse(json['bxDate'] as String)
  82. : null,
  83. applicantId: json['usr'] as String? ?? '',
  84. applicantName: json['applicantName'] as String? ?? json['usr'] as String? ?? '',
  85. deptId: json['dep'] as String? ?? '',
  86. deptName: json['deptName'] as String? ?? json['dep'] as String? ?? '',
  87. currencyCode: json['currencyCode'] as String? ?? '',
  88. isGenerateVoucher: json['isGenerateVoucher'] as bool? ?? false,
  89. voucherNo: json['voucherNo'] as String? ?? '',
  90. approvedAmount: (json['approvedAmount'] as num?)?.toDouble() ?? 0.0,
  91. totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0.0,
  92. purpose: json['reason'] as String? ?? '',
  93. remark: json['rem'] as String? ?? '',
  94. paymentMethod: json['paymentMethod'] as String? ?? '',
  95. isInvoiceVerified: json['isInvoiceVerified'] as bool? ?? false,
  96. isTaxIdMatched: json['isTaxIdMatched'] as bool? ?? false,
  97. isCategoryCompliant: json['isCategoryCompliant'] as bool? ?? false,
  98. bankTransferNo: json['bankTransferNo'] as String? ?? '',
  99. paymentStatus: json['paymentStatus'] as String? ?? 'unpaid',
  100. status: json['clsDate'] != null ? 'closed' : (json['status'] as String? ?? 'draft'),
  101. approvalInstanceId: json['approvalInstanceId'] as String? ?? '',
  102. previousInstanceIds: json['previousInstanceIds'] as String? ?? '',
  103. effectiveDate: json['effDd'] != null
  104. ? DateTime.parse(json['effDd'] as String)
  105. : null,
  106. auditorId: json['chkMan'] as String? ?? '',
  107. version: json['version'] as int? ?? 1,
  108. createTime: json['createTime'] != null
  109. ? DateTime.parse(json['createTime'] as String)
  110. : DateTime.now(),
  111. updateTime: json['updateTime'] != null
  112. ? DateTime.parse(json['updateTime'] as String)
  113. : DateTime.now(),
  114. isDeleted: json['isDeleted'] as bool? ?? false,
  115. currentApproverId: json['currentApproverId'] as String? ?? '',
  116. approvalChain:
  117. (json['approvalChain'] as List<dynamic>?)
  118. ?.map((e) => e as String)
  119. .toList() ??
  120. [],
  121. approvalRecords:
  122. (json['approvalRecords'] as List<dynamic>?)
  123. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  124. .toList() ??
  125. [],
  126. details:
  127. (json['details'] as List<dynamic>?)
  128. ?.map(
  129. (e) => ExpenseDetailModel.fromJson(e as Map<String, dynamic>),
  130. )
  131. .toList() ??
  132. [],
  133. attachments:
  134. (json['attachments'] as List<dynamic>?)
  135. ?.map((e) => e as String)
  136. .toList() ??
  137. [],
  138. );
  139. }
  140. Map<String, dynamic> toJson() => {
  141. 'id': id,
  142. 'expenseNo': expenseNo,
  143. 'expenseDate': expenseDate?.toIso8601String(),
  144. 'applicantId': applicantId,
  145. 'applicantName': applicantName,
  146. 'deptId': deptId,
  147. 'deptName': deptName,
  148. 'currencyCode': currencyCode,
  149. 'isGenerateVoucher': isGenerateVoucher,
  150. 'voucherNo': voucherNo,
  151. 'approvedAmount': approvedAmount,
  152. 'totalAmount': totalAmount,
  153. 'purpose': purpose,
  154. 'remark': remark,
  155. 'paymentMethod': paymentMethod,
  156. 'isInvoiceVerified': isInvoiceVerified,
  157. 'isTaxIdMatched': isTaxIdMatched,
  158. 'isCategoryCompliant': isCategoryCompliant,
  159. 'bankTransferNo': bankTransferNo,
  160. 'paymentStatus': paymentStatus,
  161. 'status': status,
  162. 'approvalInstanceId': approvalInstanceId,
  163. 'previousInstanceIds': previousInstanceIds,
  164. 'effectiveDate': effectiveDate?.toIso8601String(),
  165. 'auditorId': auditorId,
  166. 'version': version,
  167. 'createTime': createTime.toIso8601String(),
  168. 'updateTime': updateTime.toIso8601String(),
  169. 'isDeleted': isDeleted,
  170. 'currentApproverId': currentApproverId,
  171. 'approvalChain': approvalChain,
  172. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  173. 'details': details.map((d) => d.toJson()).toList(),
  174. 'attachments': attachments,
  175. };
  176. ExpenseModel copyWith({
  177. String? id,
  178. String? expenseNo,
  179. DateTime? expenseDate,
  180. String? applicantId,
  181. String? applicantName,
  182. String? deptId,
  183. String? deptName,
  184. String? currencyCode,
  185. bool? isGenerateVoucher,
  186. String? voucherNo,
  187. double? approvedAmount,
  188. double? totalAmount,
  189. String? purpose,
  190. String? remark,
  191. String? paymentMethod,
  192. bool? isInvoiceVerified,
  193. bool? isTaxIdMatched,
  194. bool? isCategoryCompliant,
  195. String? bankTransferNo,
  196. String? paymentStatus,
  197. String? status,
  198. String? approvalInstanceId,
  199. String? previousInstanceIds,
  200. DateTime? effectiveDate,
  201. String? auditorId,
  202. int? version,
  203. DateTime? createTime,
  204. DateTime? updateTime,
  205. bool? isDeleted,
  206. String? currentApproverId,
  207. List<String>? approvalChain,
  208. List<ApprovalRecord>? approvalRecords,
  209. List<ExpenseDetailModel>? details,
  210. List<String>? attachments,
  211. }) {
  212. return ExpenseModel(
  213. id: id ?? this.id,
  214. expenseNo: expenseNo ?? this.expenseNo,
  215. expenseDate: expenseDate ?? this.expenseDate,
  216. applicantId: applicantId ?? this.applicantId,
  217. applicantName: applicantName ?? this.applicantName,
  218. deptId: deptId ?? this.deptId,
  219. deptName: deptName ?? this.deptName,
  220. currencyCode: currencyCode ?? this.currencyCode,
  221. isGenerateVoucher: isGenerateVoucher ?? this.isGenerateVoucher,
  222. voucherNo: voucherNo ?? this.voucherNo,
  223. approvedAmount: approvedAmount ?? this.approvedAmount,
  224. totalAmount: totalAmount ?? this.totalAmount,
  225. purpose: purpose ?? this.purpose,
  226. paymentMethod: paymentMethod ?? this.paymentMethod,
  227. isInvoiceVerified: isInvoiceVerified ?? this.isInvoiceVerified,
  228. isTaxIdMatched: isTaxIdMatched ?? this.isTaxIdMatched,
  229. isCategoryCompliant: isCategoryCompliant ?? this.isCategoryCompliant,
  230. bankTransferNo: bankTransferNo ?? this.bankTransferNo,
  231. paymentStatus: paymentStatus ?? this.paymentStatus,
  232. status: status ?? this.status,
  233. approvalInstanceId: approvalInstanceId ?? this.approvalInstanceId,
  234. previousInstanceIds: previousInstanceIds ?? this.previousInstanceIds,
  235. effectiveDate: effectiveDate ?? this.effectiveDate,
  236. auditorId: auditorId ?? this.auditorId,
  237. version: version ?? this.version,
  238. createTime: createTime ?? this.createTime,
  239. updateTime: updateTime ?? this.updateTime,
  240. isDeleted: isDeleted ?? this.isDeleted,
  241. currentApproverId: currentApproverId ?? this.currentApproverId,
  242. approvalChain: approvalChain ?? this.approvalChain,
  243. approvalRecords: approvalRecords ?? this.approvalRecords,
  244. details: details ?? this.details,
  245. attachments: attachments ?? this.attachments,
  246. );
  247. }
  248. }
  249. /// 费用报销明细,对应 [ExpenseDetail] 表。
  250. class ExpenseDetailModel {
  251. final String id;
  252. final String expenseId;
  253. final String expenseApplyId;
  254. final String expenseApplyNo;
  255. final DateTime? expenseApplyDate;
  256. final String expenseCategory;
  257. final String purpose;
  258. final String projectId;
  259. final String projectName;
  260. final String costDeptId;
  261. final String costDeptName;
  262. final String acctSubjectId;
  263. final String acctSubjectName;
  264. final double amount;
  265. final double taxRate;
  266. final double taxAmount;
  267. final double totalAmount;
  268. final String currencyCode;
  269. final double exchangeRate;
  270. final double baseAmount;
  271. final double approvedAmount;
  272. final String customerVendorId;
  273. final String customerVendorName;
  274. final double offsetAmount;
  275. final String bankName;
  276. final String bankAccountName;
  277. final String bankAccount;
  278. final String sqMan;
  279. final String sqManName;
  280. final String aeNo;
  281. final String aeDd;
  282. final String remark;
  283. final int sortOrder;
  284. final List<String> attachments;
  285. final DateTime createTime;
  286. final DateTime updateTime;
  287. final bool isDeleted;
  288. const ExpenseDetailModel({
  289. required this.id,
  290. required this.expenseId,
  291. this.expenseApplyId = '',
  292. this.expenseApplyNo = '',
  293. this.expenseApplyDate,
  294. this.expenseCategory = '',
  295. this.purpose = '',
  296. this.projectId = '',
  297. this.projectName = '',
  298. this.costDeptId = '',
  299. this.costDeptName = '',
  300. this.acctSubjectId = '',
  301. this.acctSubjectName = '',
  302. required this.amount,
  303. this.taxRate = 0.0,
  304. this.taxAmount = 0.0,
  305. required this.totalAmount,
  306. this.currencyCode = '',
  307. this.exchangeRate = 1.0,
  308. this.baseAmount = 0.0,
  309. this.approvedAmount = 0.0,
  310. this.customerVendorId = '',
  311. this.customerVendorName = '',
  312. this.offsetAmount = 0.0,
  313. this.bankName = '',
  314. this.bankAccountName = '',
  315. this.bankAccount = '',
  316. this.sqMan = '',
  317. this.sqManName = '',
  318. this.aeNo = '',
  319. this.aeDd = '',
  320. this.remark = '',
  321. this.sortOrder = 1,
  322. this.attachments = const [],
  323. required this.createTime,
  324. required this.updateTime,
  325. this.isDeleted = false,
  326. });
  327. factory ExpenseDetailModel.fromJson(Map<String, dynamic> json) {
  328. return ExpenseDetailModel(
  329. id: json['id'] as String? ?? '',
  330. expenseId: json['expenseId'] as String? ?? '',
  331. expenseApplyId: json['aeNo'] as String? ?? '',
  332. expenseApplyNo: json['aeNo'] as String? ?? '',
  333. expenseApplyDate: json['aeDd'] != null
  334. ? DateTime.parse(json['aeDd'] as String)
  335. : null,
  336. expenseCategory: json['expenseCategory'] as String? ?? '',
  337. purpose: json['purpose'] as String? ?? '',
  338. projectId: json['objNo'] as String? ?? '',
  339. projectName: json['objName'] as String? ?? json['projectName'] as String? ?? '',
  340. costDeptId: json['dep'] as String? ?? '',
  341. costDeptName: json['depName'] as String? ?? json['dep'] as String? ?? '',
  342. acctSubjectId: json['accNo'] as String? ?? '',
  343. acctSubjectName: json['accName'] as String? ?? '',
  344. amount: (json['amt'] as num?)?.toDouble() ?? 0.0,
  345. taxRate: (json['taxRto'] as num?)?.toDouble() ?? 0.0,
  346. taxAmount: (json['tax'] as num?)?.toDouble() ?? 0.0,
  347. totalAmount: (json['amtn'] as num?)?.toDouble() ?? 0.0,
  348. currencyCode: json['currencyCode'] as String? ?? '',
  349. exchangeRate: (json['exchangeRate'] as num?)?.toDouble() ?? 1.0,
  350. baseAmount: (json['baseAmount'] as num?)?.toDouble() ?? 0.0,
  351. approvedAmount: (json['approvedAmount'] as num?)?.toDouble() ?? 0.0,
  352. customerVendorId: json['customerVendorId'] as String? ?? '',
  353. customerVendorName: json['cust'] as String? ?? '',
  354. offsetAmount: (json['offsetAmount'] as num?)?.toDouble() ?? 0.0,
  355. bankName: json['bankName'] as String? ?? '',
  356. bankAccountName: json['bankAccountName'] as String? ?? '',
  357. bankAccount: json['bankAccount'] as String? ?? '',
  358. sqMan: json['sqMan'] as String? ?? '',
  359. sqManName: json['sqName'] as String? ?? json['sqManName'] as String? ?? json['sqMan'] as String? ?? '',
  360. aeNo: json['aeNo'] as String? ?? '',
  361. aeDd: json['aeDd'] as String? ?? '',
  362. remark: json['rem'] as String? ?? '',
  363. sortOrder: json['itm'] as int? ?? 1,
  364. attachments:
  365. (json['attachments'] as List<dynamic>?)
  366. ?.map((e) => e as String)
  367. .toList() ??
  368. [],
  369. createTime: json['createTime'] != null
  370. ? DateTime.parse(json['createTime'] as String)
  371. : DateTime.now(),
  372. updateTime: json['updateTime'] != null
  373. ? DateTime.parse(json['updateTime'] as String)
  374. : DateTime.now(),
  375. isDeleted: json['isDeleted'] as bool? ?? false,
  376. );
  377. }
  378. Map<String, dynamic> toJson() => {
  379. 'id': id,
  380. 'expenseId': expenseId,
  381. 'expenseApplyId': expenseApplyId,
  382. 'expenseApplyNo': expenseApplyNo,
  383. 'expenseApplyDate': expenseApplyDate?.toIso8601String(),
  384. 'expenseCategory': expenseCategory,
  385. 'purpose': purpose,
  386. 'projectId': projectId,
  387. 'projectName': projectName,
  388. 'costDeptId': costDeptId,
  389. 'costDeptName': costDeptName,
  390. 'acctSubjectId': acctSubjectId,
  391. 'acctSubjectName': acctSubjectName,
  392. 'amount': amount,
  393. 'taxRate': taxRate,
  394. 'taxAmount': taxAmount,
  395. 'totalAmount': totalAmount,
  396. 'currencyCode': currencyCode,
  397. 'exchangeRate': exchangeRate,
  398. 'baseAmount': baseAmount,
  399. 'approvedAmount': approvedAmount,
  400. 'customerVendorId': customerVendorId,
  401. 'customerVendorName': customerVendorName,
  402. 'offsetAmount': offsetAmount,
  403. 'bankName': bankName,
  404. 'bankAccountName': bankAccountName,
  405. 'bankAccount': bankAccount,
  406. 'sqMan': sqMan,
  407. 'sqManName': sqManName,
  408. 'aeNo': aeNo,
  409. 'aeDd': aeDd,
  410. 'remark': remark,
  411. 'sortOrder': sortOrder,
  412. 'attachments': attachments,
  413. 'createTime': createTime.toIso8601String(),
  414. 'updateTime': updateTime.toIso8601String(),
  415. 'isDeleted': isDeleted,
  416. };
  417. ExpenseDetailModel copyWith({
  418. String? id,
  419. String? expenseId,
  420. String? expenseApplyId,
  421. String? expenseApplyNo,
  422. DateTime? expenseApplyDate,
  423. String? expenseCategory,
  424. String? purpose,
  425. String? projectId,
  426. String? projectName,
  427. String? costDeptId,
  428. String? costDeptName,
  429. String? acctSubjectId,
  430. String? acctSubjectName,
  431. double? amount,
  432. double? taxRate,
  433. double? taxAmount,
  434. double? totalAmount,
  435. String? currencyCode,
  436. double? exchangeRate,
  437. double? baseAmount,
  438. double? approvedAmount,
  439. String? customerVendorId,
  440. String? customerVendorName,
  441. double? offsetAmount,
  442. String? bankName,
  443. String? bankAccountName,
  444. String? bankAccount,
  445. String? sqMan,
  446. String? sqManName,
  447. String? aeNo,
  448. String? aeDd,
  449. String? remark,
  450. int? sortOrder,
  451. List<String>? attachments,
  452. DateTime? createTime,
  453. DateTime? updateTime,
  454. bool? isDeleted,
  455. }) {
  456. return ExpenseDetailModel(
  457. id: id ?? this.id,
  458. expenseId: expenseId ?? this.expenseId,
  459. expenseApplyId: expenseApplyId ?? this.expenseApplyId,
  460. expenseApplyNo: expenseApplyNo ?? this.expenseApplyNo,
  461. expenseApplyDate: expenseApplyDate ?? this.expenseApplyDate,
  462. expenseCategory: expenseCategory ?? this.expenseCategory,
  463. purpose: purpose ?? this.purpose,
  464. projectId: projectId ?? this.projectId,
  465. projectName: projectName ?? this.projectName,
  466. costDeptId: costDeptId ?? this.costDeptId,
  467. costDeptName: costDeptName ?? this.costDeptName,
  468. acctSubjectId: acctSubjectId ?? this.acctSubjectId,
  469. acctSubjectName: acctSubjectName ?? this.acctSubjectName,
  470. amount: amount ?? this.amount,
  471. taxRate: taxRate ?? this.taxRate,
  472. taxAmount: taxAmount ?? this.taxAmount,
  473. totalAmount: totalAmount ?? this.totalAmount,
  474. currencyCode: currencyCode ?? this.currencyCode,
  475. exchangeRate: exchangeRate ?? this.exchangeRate,
  476. baseAmount: baseAmount ?? this.baseAmount,
  477. approvedAmount: approvedAmount ?? this.approvedAmount,
  478. customerVendorId: customerVendorId ?? this.customerVendorId,
  479. customerVendorName: customerVendorName ?? this.customerVendorName,
  480. offsetAmount: offsetAmount ?? this.offsetAmount,
  481. bankName: bankName ?? this.bankName,
  482. bankAccountName: bankAccountName ?? this.bankAccountName,
  483. bankAccount: bankAccount ?? this.bankAccount,
  484. sqMan: sqMan ?? this.sqMan,
  485. sqManName: sqManName ?? this.sqManName,
  486. aeNo: aeNo ?? this.aeNo,
  487. aeDd: aeDd ?? this.aeDd,
  488. remark: remark ?? this.remark,
  489. sortOrder: sortOrder ?? this.sortOrder,
  490. attachments: attachments ?? this.attachments,
  491. createTime: createTime ?? this.createTime,
  492. updateTime: updateTime ?? this.updateTime,
  493. isDeleted: isDeleted ?? this.isDeleted,
  494. );
  495. }
  496. }