You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
2.6 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:qadirneyriz/services/report/report.dart';
  3. import 'package:qadirneyriz/utils/enums/status.dart';
  4. class ReportState extends ChangeNotifier {
  5. ReportApi reportApi = ReportApi();
  6. // set date for filters
  7. String fromDate = '';
  8. String toDate = '';
  9. void setFromDates(String? newFromDate) {
  10. fromDate = newFromDate ?? '';
  11. notifyListeners();
  12. }
  13. void setToDates(String? newToDate) {
  14. toDate = newToDate ?? '';
  15. notifyListeners();
  16. }
  17. // clear filters
  18. void clearFilters() {
  19. selectedLocationId = null;
  20. selectedManagersId = null;
  21. selectedStatusId = null;
  22. selectedSubjectId = null;
  23. fromDate = '';
  24. toDate = '';
  25. notifyListeners();
  26. }
  27. // is filter Not empty
  28. bool hasActiveFilters() {
  29. return selectedLocationId != null ||
  30. selectedManagersId != null ||
  31. selectedStatusId != null ||
  32. selectedSubjectId != null ||
  33. fromDate.isNotEmpty ||
  34. toDate.isNotEmpty;
  35. }
  36. // get filters location meetings
  37. int? selectedLocationId;
  38. void selectLocation(int? locationId) {
  39. selectedLocationId = locationId;
  40. notifyListeners();
  41. }
  42. // get filters subjects meetings
  43. int? selectedSubjectId;
  44. void selectSubject(int? subjectId) {
  45. selectedSubjectId = subjectId;
  46. notifyListeners();
  47. }
  48. // get filters meeting managers
  49. int? selectedManagersId;
  50. void selectManager(int? managerId) {
  51. selectedManagersId = managerId;
  52. notifyListeners();
  53. }
  54. // all meeting status filters
  55. int? selectedStatusId;
  56. void selectStatusMeeting(int? statusId) {
  57. selectedStatusId = statusId;
  58. notifyListeners();
  59. }
  60. // download report
  61. Status statusDownload = Status.empty;
  62. String? messageDownload;
  63. Future<Status> downloadReport(
  64. {String? fromDate,
  65. String? toDate,
  66. int? location,
  67. int? subject,
  68. int? meetingManager,
  69. int? status}) async {
  70. statusDownload = Status.loading;
  71. notifyListeners();
  72. try {
  73. final result = await reportApi.downloadReport(
  74. fromDate: fromDate,
  75. toDate: toDate,
  76. location: location,
  77. subject: subject,
  78. meetingManager: meetingManager,
  79. status: status);
  80. if (result == null) {
  81. statusDownload = Status.error;
  82. } else {
  83. if (result.isOk) {
  84. statusDownload = Status.ready;
  85. messageDownload = result.message ?? '';
  86. } else {
  87. statusDownload = Status.error;
  88. }
  89. }
  90. } catch (e) {
  91. statusDownload = Status.error;
  92. }
  93. notifyListeners();
  94. return statusDownload;
  95. }
  96. }