expense_application_model.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. import '../../shared/models/approval_status.dart';
  2. class ExpenseApplicationModel {
  3. final String id;
  4. final String applicationNo;
  5. final String applicantId;
  6. final String applicantName;
  7. final String deptId;
  8. final String deptName;
  9. final String expenseType;
  10. final List<String> expenseTypes;
  11. final double estimatedAmount;
  12. final String purpose;
  13. final String remark;
  14. final String status;
  15. final String currentApproverId;
  16. final List<String> approvalChain;
  17. final DateTime createTime;
  18. final DateTime updateTime;
  19. final DateTime? estimatedStartDate;
  20. final DateTime? estimatedEndDate;
  21. final String urgency;
  22. final String projectId;
  23. final String projectName;
  24. final String budgetSubjectId;
  25. final String budgetSubjectName;
  26. final double availableBalance;
  27. final bool isTaxIncluded;
  28. final DateTime? validUntil;
  29. final String referenceNo;
  30. final String usageStatus;
  31. // 差旅费专用
  32. final bool isOvernight;
  33. final String transportMode;
  34. // 招待费专用
  35. final String entertainTarget;
  36. final String entertainLevel;
  37. final int guestCount;
  38. final int hostCount;
  39. final String entertainLocation;
  40. // 会议费专用
  41. final DateTime? meetingDate;
  42. final String meetingLocation;
  43. final List<ExpenseAppDetailModel> details;
  44. final List<String> attachments;
  45. final List<ApprovalRecord> approvalRecords;
  46. const ExpenseApplicationModel({
  47. required this.id,
  48. required this.applicationNo,
  49. this.applicantId = '',
  50. this.applicantName = '',
  51. this.deptId = '',
  52. this.deptName = '',
  53. this.expenseType = '',
  54. this.expenseTypes = const [],
  55. this.estimatedAmount = 0.0,
  56. this.purpose = '',
  57. this.remark = '',
  58. this.status = 'draft',
  59. this.currentApproverId = '',
  60. this.approvalChain = const [],
  61. required this.createTime,
  62. required this.updateTime,
  63. this.estimatedStartDate,
  64. this.estimatedEndDate,
  65. this.urgency = 'normal',
  66. this.projectId = '',
  67. this.projectName = '',
  68. this.budgetSubjectId = '',
  69. this.budgetSubjectName = '',
  70. this.availableBalance = 0.0,
  71. this.isTaxIncluded = false,
  72. this.validUntil,
  73. this.referenceNo = '',
  74. this.usageStatus = 'unused',
  75. this.isOvernight = false,
  76. this.transportMode = '',
  77. this.entertainTarget = '',
  78. this.entertainLevel = '',
  79. this.guestCount = 0,
  80. this.hostCount = 0,
  81. this.entertainLocation = '',
  82. this.meetingDate,
  83. this.meetingLocation = '',
  84. this.details = const [],
  85. this.attachments = const [],
  86. this.approvalRecords = const [],
  87. });
  88. factory ExpenseApplicationModel.fromJson(Map<String, dynamic> json) {
  89. return ExpenseApplicationModel(
  90. id: json['id'] as String,
  91. applicationNo: json['applicationNo'] as String? ?? '',
  92. applicantId: json['applicantId'] as String? ?? '',
  93. applicantName: json['applicantName'] as String? ?? '',
  94. deptId: json['deptId'] as String? ?? '',
  95. deptName: json['deptName'] as String? ?? '',
  96. expenseType: json['expenseType'] as String? ?? '',
  97. expenseTypes:
  98. (json['expenseTypes'] as List<dynamic>?)
  99. ?.map((e) => e as String)
  100. .toList() ??
  101. [],
  102. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  103. purpose: json['purpose'] as String? ?? '',
  104. remark: json['remark'] as String? ?? '',
  105. status: json['status'] as String? ?? 'draft',
  106. currentApproverId: json['currentApproverId'] as String? ?? '',
  107. approvalChain:
  108. (json['approvalChain'] as List<dynamic>?)
  109. ?.map((e) => e as String)
  110. .toList() ??
  111. [],
  112. createTime: DateTime.parse(json['createTime'] as String),
  113. updateTime: DateTime.parse(json['updateTime'] as String),
  114. estimatedStartDate: json['estimatedStartDate'] != null
  115. ? DateTime.parse(json['estimatedStartDate'] as String)
  116. : null,
  117. estimatedEndDate: json['estimatedEndDate'] != null
  118. ? DateTime.parse(json['estimatedEndDate'] as String)
  119. : null,
  120. urgency: json['urgency'] as String? ?? 'normal',
  121. projectId: json['projectId'] as String? ?? '',
  122. projectName: json['projectName'] as String? ?? '',
  123. budgetSubjectId: json['budgetSubjectId'] as String? ?? '',
  124. budgetSubjectName: json['budgetSubjectName'] as String? ?? '',
  125. availableBalance: (json['availableBalance'] as num?)?.toDouble() ?? 0.0,
  126. isTaxIncluded: json['isTaxIncluded'] as bool? ?? false,
  127. validUntil: json['validUntil'] != null
  128. ? DateTime.parse(json['validUntil'] as String)
  129. : null,
  130. referenceNo: json['referenceNo'] as String? ?? '',
  131. usageStatus: json['usageStatus'] as String? ?? 'unused',
  132. isOvernight: json['isOvernight'] as bool? ?? false,
  133. transportMode: json['transportMode'] as String? ?? '',
  134. entertainTarget: json['entertainTarget'] as String? ?? '',
  135. entertainLevel: json['entertainLevel'] as String? ?? '',
  136. guestCount: json['guestCount'] as int? ?? 0,
  137. hostCount: json['hostCount'] as int? ?? 0,
  138. entertainLocation: json['entertainLocation'] as String? ?? '',
  139. meetingDate: json['meetingDate'] != null
  140. ? DateTime.parse(json['meetingDate'] as String)
  141. : null,
  142. meetingLocation: json['meetingLocation'] as String? ?? '',
  143. details:
  144. (json['details'] as List<dynamic>?)
  145. ?.map(
  146. (e) =>
  147. ExpenseAppDetailModel.fromJson(e as Map<String, dynamic>),
  148. )
  149. .toList() ??
  150. [],
  151. attachments:
  152. (json['attachments'] as List<dynamic>?)
  153. ?.map((e) => e as String)
  154. .toList() ??
  155. [],
  156. approvalRecords:
  157. (json['approvalRecords'] as List<dynamic>?)
  158. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  159. .toList() ??
  160. [],
  161. );
  162. }
  163. Map<String, dynamic> toJson() => {
  164. 'id': id,
  165. 'applicationNo': applicationNo,
  166. 'applicantId': applicantId,
  167. 'applicantName': applicantName,
  168. 'deptId': deptId,
  169. 'deptName': deptName,
  170. 'expenseType': expenseType,
  171. 'expenseTypes': expenseTypes,
  172. 'estimatedAmount': estimatedAmount,
  173. 'purpose': purpose,
  174. 'remark': remark,
  175. 'status': status,
  176. 'currentApproverId': currentApproverId,
  177. 'approvalChain': approvalChain,
  178. 'createTime': createTime.toIso8601String(),
  179. 'updateTime': updateTime.toIso8601String(),
  180. 'estimatedStartDate': estimatedStartDate?.toIso8601String(),
  181. 'estimatedEndDate': estimatedEndDate?.toIso8601String(),
  182. 'urgency': urgency,
  183. 'projectId': projectId,
  184. 'projectName': projectName,
  185. 'budgetSubjectId': budgetSubjectId,
  186. 'budgetSubjectName': budgetSubjectName,
  187. 'availableBalance': availableBalance,
  188. 'isTaxIncluded': isTaxIncluded,
  189. 'validUntil': validUntil?.toIso8601String(),
  190. 'referenceNo': referenceNo,
  191. 'usageStatus': usageStatus,
  192. 'isOvernight': isOvernight,
  193. 'transportMode': transportMode,
  194. 'entertainTarget': entertainTarget,
  195. 'entertainLevel': entertainLevel,
  196. 'guestCount': guestCount,
  197. 'hostCount': hostCount,
  198. 'entertainLocation': entertainLocation,
  199. 'meetingDate': meetingDate?.toIso8601String(),
  200. 'meetingLocation': meetingLocation,
  201. 'details': details.map((d) => d.toJson()).toList(),
  202. 'attachments': attachments,
  203. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  204. };
  205. ExpenseApplicationModel copyWith({
  206. String? id,
  207. String? applicationNo,
  208. String? applicantId,
  209. String? applicantName,
  210. String? deptId,
  211. String? deptName,
  212. String? expenseType,
  213. List<String>? expenseTypes,
  214. double? estimatedAmount,
  215. String? purpose,
  216. String? remark,
  217. String? status,
  218. String? currentApproverId,
  219. List<String>? approvalChain,
  220. DateTime? createTime,
  221. DateTime? updateTime,
  222. DateTime? estimatedStartDate,
  223. DateTime? estimatedEndDate,
  224. String? urgency,
  225. String? projectId,
  226. String? projectName,
  227. String? budgetSubjectId,
  228. String? budgetSubjectName,
  229. double? availableBalance,
  230. bool? isTaxIncluded,
  231. DateTime? validUntil,
  232. String? referenceNo,
  233. String? usageStatus,
  234. bool? isOvernight,
  235. String? transportMode,
  236. String? entertainTarget,
  237. String? entertainLevel,
  238. int? guestCount,
  239. int? hostCount,
  240. String? entertainLocation,
  241. DateTime? meetingDate,
  242. String? meetingLocation,
  243. List<ExpenseAppDetailModel>? details,
  244. List<String>? attachments,
  245. List<ApprovalRecord>? approvalRecords,
  246. }) {
  247. return ExpenseApplicationModel(
  248. id: id ?? this.id,
  249. applicationNo: applicationNo ?? this.applicationNo,
  250. applicantId: applicantId ?? this.applicantId,
  251. applicantName: applicantName ?? this.applicantName,
  252. deptId: deptId ?? this.deptId,
  253. deptName: deptName ?? this.deptName,
  254. expenseType: expenseType ?? this.expenseType,
  255. expenseTypes: expenseTypes ?? this.expenseTypes,
  256. estimatedAmount: estimatedAmount ?? this.estimatedAmount,
  257. purpose: purpose ?? this.purpose,
  258. remark: remark ?? this.remark,
  259. status: status ?? this.status,
  260. currentApproverId: currentApproverId ?? this.currentApproverId,
  261. approvalChain: approvalChain ?? this.approvalChain,
  262. createTime: createTime ?? this.createTime,
  263. updateTime: updateTime ?? this.updateTime,
  264. estimatedStartDate: estimatedStartDate ?? this.estimatedStartDate,
  265. estimatedEndDate: estimatedEndDate ?? this.estimatedEndDate,
  266. urgency: urgency ?? this.urgency,
  267. projectId: projectId ?? this.projectId,
  268. projectName: projectName ?? this.projectName,
  269. budgetSubjectId: budgetSubjectId ?? this.budgetSubjectId,
  270. budgetSubjectName: budgetSubjectName ?? this.budgetSubjectName,
  271. availableBalance: availableBalance ?? this.availableBalance,
  272. isTaxIncluded: isTaxIncluded ?? this.isTaxIncluded,
  273. validUntil: validUntil ?? this.validUntil,
  274. referenceNo: referenceNo ?? this.referenceNo,
  275. usageStatus: usageStatus ?? this.usageStatus,
  276. isOvernight: isOvernight ?? this.isOvernight,
  277. transportMode: transportMode ?? this.transportMode,
  278. entertainTarget: entertainTarget ?? this.entertainTarget,
  279. entertainLevel: entertainLevel ?? this.entertainLevel,
  280. guestCount: guestCount ?? this.guestCount,
  281. hostCount: hostCount ?? this.hostCount,
  282. entertainLocation: entertainLocation ?? this.entertainLocation,
  283. meetingDate: meetingDate ?? this.meetingDate,
  284. meetingLocation: meetingLocation ?? this.meetingLocation,
  285. details: details ?? this.details,
  286. attachments: attachments ?? this.attachments,
  287. approvalRecords: approvalRecords ?? this.approvalRecords,
  288. );
  289. }
  290. }
  291. class ExpenseAppDetailModel {
  292. final String id;
  293. final String applicationId;
  294. final String itemName;
  295. final double estimatedAmount;
  296. final String remark;
  297. final int sortOrder;
  298. final double quantity;
  299. final String unit;
  300. final double unitPrice;
  301. final double lineAmount;
  302. final String category;
  303. final String description;
  304. const ExpenseAppDetailModel({
  305. required this.id,
  306. this.applicationId = '',
  307. this.itemName = '',
  308. this.estimatedAmount = 0.0,
  309. this.remark = '',
  310. this.sortOrder = 1,
  311. this.quantity = 1,
  312. this.unit = '张',
  313. this.unitPrice = 0.0,
  314. this.lineAmount = 0.0,
  315. this.category = '',
  316. this.description = '',
  317. });
  318. factory ExpenseAppDetailModel.fromJson(Map<String, dynamic> json) {
  319. return ExpenseAppDetailModel(
  320. id: json['id'] as String,
  321. applicationId: json['applicationId'] as String? ?? '',
  322. itemName: json['itemName'] as String? ?? '',
  323. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  324. remark: json['remark'] as String? ?? '',
  325. sortOrder: json['sortOrder'] as int? ?? 1,
  326. quantity: (json['quantity'] as num?)?.toDouble() ?? 1,
  327. unit: json['unit'] as String? ?? '张',
  328. unitPrice: (json['unitPrice'] as num?)?.toDouble() ?? 0.0,
  329. lineAmount: (json['lineAmount'] as num?)?.toDouble() ?? 0.0,
  330. category: json['category'] as String? ?? '',
  331. description: json['description'] as String? ?? '',
  332. );
  333. }
  334. Map<String, dynamic> toJson() => {
  335. 'id': id,
  336. 'applicationId': applicationId,
  337. 'itemName': itemName,
  338. 'estimatedAmount': estimatedAmount,
  339. 'remark': remark,
  340. 'sortOrder': sortOrder,
  341. 'quantity': quantity,
  342. 'unit': unit,
  343. 'unitPrice': unitPrice,
  344. 'lineAmount': lineAmount,
  345. 'category': category,
  346. 'description': description,
  347. };
  348. }