expense_application_model.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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: (json['expenseTypes'] as List<dynamic>?)?.map((e) => e as String).toList() ?? [],
  98. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  99. purpose: json['purpose'] as String? ?? '',
  100. remark: json['remark'] as String? ?? '',
  101. status: json['status'] as String? ?? 'draft',
  102. currentApproverId: json['currentApproverId'] as String? ?? '',
  103. approvalChain:
  104. (json['approvalChain'] as List<dynamic>?)
  105. ?.map((e) => e as String)
  106. .toList() ??
  107. [],
  108. createTime: DateTime.parse(json['createTime'] as String),
  109. updateTime: DateTime.parse(json['updateTime'] as String),
  110. estimatedStartDate: json['estimatedStartDate'] != null
  111. ? DateTime.parse(json['estimatedStartDate'] as String)
  112. : null,
  113. estimatedEndDate: json['estimatedEndDate'] != null
  114. ? DateTime.parse(json['estimatedEndDate'] as String)
  115. : null,
  116. urgency: json['urgency'] as String? ?? 'normal',
  117. projectId: json['projectId'] as String? ?? '',
  118. projectName: json['projectName'] as String? ?? '',
  119. budgetSubjectId: json['budgetSubjectId'] as String? ?? '',
  120. budgetSubjectName: json['budgetSubjectName'] as String? ?? '',
  121. availableBalance: (json['availableBalance'] as num?)?.toDouble() ?? 0.0,
  122. isTaxIncluded: json['isTaxIncluded'] as bool? ?? false,
  123. validUntil: json['validUntil'] != null ? DateTime.parse(json['validUntil'] as String) : null,
  124. referenceNo: json['referenceNo'] as String? ?? '',
  125. usageStatus: json['usageStatus'] as String? ?? 'unused',
  126. isOvernight: json['isOvernight'] as bool? ?? false,
  127. transportMode: json['transportMode'] as String? ?? '',
  128. entertainTarget: json['entertainTarget'] as String? ?? '',
  129. entertainLevel: json['entertainLevel'] as String? ?? '',
  130. guestCount: json['guestCount'] as int? ?? 0,
  131. hostCount: json['hostCount'] as int? ?? 0,
  132. entertainLocation: json['entertainLocation'] as String? ?? '',
  133. meetingDate: json['meetingDate'] != null ? DateTime.parse(json['meetingDate'] as String) : null,
  134. meetingLocation: json['meetingLocation'] as String? ?? '',
  135. details:
  136. (json['details'] as List<dynamic>?)
  137. ?.map(
  138. (e) =>
  139. ExpenseAppDetailModel.fromJson(e as Map<String, dynamic>),
  140. )
  141. .toList() ??
  142. [],
  143. attachments:
  144. (json['attachments'] as List<dynamic>?)?.map((e) => e as String).toList() ?? [],
  145. approvalRecords:
  146. (json['approvalRecords'] as List<dynamic>?)
  147. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  148. .toList() ??
  149. [],
  150. );
  151. }
  152. Map<String, dynamic> toJson() => {
  153. 'id': id,
  154. 'applicationNo': applicationNo,
  155. 'applicantId': applicantId,
  156. 'applicantName': applicantName,
  157. 'deptId': deptId,
  158. 'deptName': deptName,
  159. 'expenseType': expenseType,
  160. 'expenseTypes': expenseTypes,
  161. 'estimatedAmount': estimatedAmount,
  162. 'purpose': purpose,
  163. 'remark': remark,
  164. 'status': status,
  165. 'currentApproverId': currentApproverId,
  166. 'approvalChain': approvalChain,
  167. 'createTime': createTime.toIso8601String(),
  168. 'updateTime': updateTime.toIso8601String(),
  169. 'estimatedStartDate': estimatedStartDate?.toIso8601String(),
  170. 'estimatedEndDate': estimatedEndDate?.toIso8601String(),
  171. 'urgency': urgency,
  172. 'projectId': projectId,
  173. 'projectName': projectName,
  174. 'budgetSubjectId': budgetSubjectId,
  175. 'budgetSubjectName': budgetSubjectName,
  176. 'availableBalance': availableBalance,
  177. 'isTaxIncluded': isTaxIncluded,
  178. 'validUntil': validUntil?.toIso8601String(),
  179. 'referenceNo': referenceNo,
  180. 'usageStatus': usageStatus,
  181. 'isOvernight': isOvernight,
  182. 'transportMode': transportMode,
  183. 'entertainTarget': entertainTarget,
  184. 'entertainLevel': entertainLevel,
  185. 'guestCount': guestCount,
  186. 'hostCount': hostCount,
  187. 'entertainLocation': entertainLocation,
  188. 'meetingDate': meetingDate?.toIso8601String(),
  189. 'meetingLocation': meetingLocation,
  190. 'details': details.map((d) => d.toJson()).toList(),
  191. 'attachments': attachments,
  192. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  193. };
  194. ExpenseApplicationModel copyWith({
  195. String? id,
  196. String? applicationNo,
  197. String? applicantId,
  198. String? applicantName,
  199. String? deptId,
  200. String? deptName,
  201. String? expenseType,
  202. List<String>? expenseTypes,
  203. double? estimatedAmount,
  204. String? purpose,
  205. String? remark,
  206. String? status,
  207. String? currentApproverId,
  208. List<String>? approvalChain,
  209. DateTime? createTime,
  210. DateTime? updateTime,
  211. DateTime? estimatedStartDate,
  212. DateTime? estimatedEndDate,
  213. String? urgency,
  214. String? projectId,
  215. String? projectName,
  216. String? budgetSubjectId,
  217. String? budgetSubjectName,
  218. double? availableBalance,
  219. bool? isTaxIncluded,
  220. DateTime? validUntil,
  221. String? referenceNo,
  222. String? usageStatus,
  223. bool? isOvernight,
  224. String? transportMode,
  225. String? entertainTarget,
  226. String? entertainLevel,
  227. int? guestCount,
  228. int? hostCount,
  229. String? entertainLocation,
  230. DateTime? meetingDate,
  231. String? meetingLocation,
  232. List<ExpenseAppDetailModel>? details,
  233. List<String>? attachments,
  234. List<ApprovalRecord>? approvalRecords,
  235. }) {
  236. return ExpenseApplicationModel(
  237. id: id ?? this.id,
  238. applicationNo: applicationNo ?? this.applicationNo,
  239. applicantId: applicantId ?? this.applicantId,
  240. applicantName: applicantName ?? this.applicantName,
  241. deptId: deptId ?? this.deptId,
  242. deptName: deptName ?? this.deptName,
  243. expenseType: expenseType ?? this.expenseType,
  244. expenseTypes: expenseTypes ?? this.expenseTypes,
  245. estimatedAmount: estimatedAmount ?? this.estimatedAmount,
  246. purpose: purpose ?? this.purpose,
  247. remark: remark ?? this.remark,
  248. status: status ?? this.status,
  249. currentApproverId: currentApproverId ?? this.currentApproverId,
  250. approvalChain: approvalChain ?? this.approvalChain,
  251. createTime: createTime ?? this.createTime,
  252. updateTime: updateTime ?? this.updateTime,
  253. estimatedStartDate: estimatedStartDate ?? this.estimatedStartDate,
  254. estimatedEndDate: estimatedEndDate ?? this.estimatedEndDate,
  255. urgency: urgency ?? this.urgency,
  256. projectId: projectId ?? this.projectId,
  257. projectName: projectName ?? this.projectName,
  258. budgetSubjectId: budgetSubjectId ?? this.budgetSubjectId,
  259. budgetSubjectName: budgetSubjectName ?? this.budgetSubjectName,
  260. availableBalance: availableBalance ?? this.availableBalance,
  261. isTaxIncluded: isTaxIncluded ?? this.isTaxIncluded,
  262. validUntil: validUntil ?? this.validUntil,
  263. referenceNo: referenceNo ?? this.referenceNo,
  264. usageStatus: usageStatus ?? this.usageStatus,
  265. isOvernight: isOvernight ?? this.isOvernight,
  266. transportMode: transportMode ?? this.transportMode,
  267. entertainTarget: entertainTarget ?? this.entertainTarget,
  268. entertainLevel: entertainLevel ?? this.entertainLevel,
  269. guestCount: guestCount ?? this.guestCount,
  270. hostCount: hostCount ?? this.hostCount,
  271. entertainLocation: entertainLocation ?? this.entertainLocation,
  272. meetingDate: meetingDate ?? this.meetingDate,
  273. meetingLocation: meetingLocation ?? this.meetingLocation,
  274. details: details ?? this.details,
  275. attachments: attachments ?? this.attachments,
  276. approvalRecords: approvalRecords ?? this.approvalRecords,
  277. );
  278. }
  279. }
  280. class ExpenseAppDetailModel {
  281. final String id;
  282. final String applicationId;
  283. final String itemName;
  284. final double estimatedAmount;
  285. final String remark;
  286. final int sortOrder;
  287. final double quantity;
  288. final String unit;
  289. final double unitPrice;
  290. final double lineAmount;
  291. final String category;
  292. final String description;
  293. const ExpenseAppDetailModel({
  294. required this.id,
  295. this.applicationId = '',
  296. this.itemName = '',
  297. this.estimatedAmount = 0.0,
  298. this.remark = '',
  299. this.sortOrder = 1,
  300. this.quantity = 1,
  301. this.unit = '张',
  302. this.unitPrice = 0.0,
  303. this.lineAmount = 0.0,
  304. this.category = '',
  305. this.description = '',
  306. });
  307. factory ExpenseAppDetailModel.fromJson(Map<String, dynamic> json) {
  308. return ExpenseAppDetailModel(
  309. id: json['id'] as String,
  310. applicationId: json['applicationId'] as String? ?? '',
  311. itemName: json['itemName'] as String? ?? '',
  312. estimatedAmount: (json['estimatedAmount'] as num?)?.toDouble() ?? 0.0,
  313. remark: json['remark'] as String? ?? '',
  314. sortOrder: json['sortOrder'] as int? ?? 1,
  315. quantity: (json['quantity'] as num?)?.toDouble() ?? 1,
  316. unit: json['unit'] as String? ?? '张',
  317. unitPrice: (json['unitPrice'] as num?)?.toDouble() ?? 0.0,
  318. lineAmount: (json['lineAmount'] as num?)?.toDouble() ?? 0.0,
  319. category: json['category'] as String? ?? '',
  320. description: json['description'] as String? ?? '',
  321. );
  322. }
  323. Map<String, dynamic> toJson() => {
  324. 'id': id,
  325. 'applicationId': applicationId,
  326. 'itemName': itemName,
  327. 'estimatedAmount': estimatedAmount,
  328. 'remark': remark,
  329. 'sortOrder': sortOrder,
  330. 'quantity': quantity,
  331. 'unit': unit,
  332. 'unitPrice': unitPrice,
  333. 'lineAmount': lineAmount,
  334. 'category': category,
  335. 'description': description,
  336. };
  337. }