Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
collections_utils.dart
Go to the documentation of this file.
1import '../../features/collections/domain/entities/collection_entity.dart';
2
4
5List<CollectionEntity> filterCollections({
6 required List<CollectionEntity> collections,
7 required CollectionFilterType filterType,
8 DateTime? startDate,
9 DateTime? endDate,
10}) {
11 final now = DateTime.now();
12
13 switch (filterType) {
14 case CollectionFilterType.all:
15 return collections;
16
17 case CollectionFilterType.week:
18
19 // Define the past 7 days range
20 final startOfWeek = now.subtract(const Duration(days: 6));
21 final endOfWeek = now.add(const Duration(days: 1));
22
23 return collections.where((collection) {
24 final date = collection.dateOrder;
25 return date != null &&
26 date.isAfter(startOfWeek.subtract(const Duration(seconds: 1))) &&
27 date.isBefore(endOfWeek.add(const Duration(seconds: 1)));
28 }).toList();
29
30 case CollectionFilterType.month:
31 // Calculate the start and end dates for the current month
32 final now = DateTime.now();
33 final startDate =
34 DateTime(now.year, now.month, 1); // First day of the current month
35 final endDate = DateTime(now.year, now.month + 1, 1).subtract(
36 const Duration(seconds: 1)); // Last day of the current month
37
38 return collections.where((collection) {
39 final date = collection.dateOrder;
40 return date != null &&
41 date.isAfter(startDate.subtract(const Duration(seconds: 1))) &&
42 date.isBefore(endDate.add(const Duration(seconds: 1)));
43 }).toList();
44
45 case CollectionFilterType.calendar:
46 if (startDate == null || endDate == null) {
47 throw ArgumentError(
48 'Start date and end date must be provided for the calendar filter.');
49 }
50 return collections.where((collection) {
51 final date = collection.dateOrder;
52 return date != null &&
53 date.isAfter(startDate.subtract(const Duration(seconds: 1))) &&
54 date.isBefore(endDate.add(const Duration(seconds: 1)));
55 }).toList();
56 }
57}
58
60 num totalQuantity = 0;
61 for (var collection in collections) {
62 if (collection.orderLines != null) {
63 for (var orderLine in collection.orderLines!) {
64 if (orderLine.productQty != null) {
65 totalQuantity += orderLine.productQty!;
66 }
67 }
68 }
69 }
70
71 return totalQuantity;
72}
73
74// List<CollectionEntity> filterCollections({
75// required List<CollectionEntity> collections,
76// required CollectionFilterType filterType,
77// DateTime? startDate,
78// DateTime? endDate,
79// }) {
80// final now = DateTime.now();
81
82// switch (filterType) {
83// case CollectionFilterType.all:
84// return collections;
85// case CollectionFilterType.week:
86// final startOfWeek = now.subtract(Duration(days: now.weekday - 1));
87// final endOfWeek = startOfWeek.add(const Duration(days: 6));
88
89// return collections.where((collection) {
90// final date = collection.createDate;
91// return date != null &&
92// date.isAfter(startOfWeek.subtract(const Duration(seconds: 1))) &&
93// date.isBefore(endOfWeek.add(const Duration(seconds: 1)));
94// }).toList();
95
96// case CollectionFilterType.month:
97// final startOfMonth = DateTime(now.year, now.month, 1);
98// final endOfMonth = DateTime(now.year, now.month + 1, 0);
99
100// return collections.where((collection) {
101// final date = collection.createDate;
102// return date != null &&
103// date.isAfter(startOfMonth.subtract(const Duration(seconds: 1))) &&
104// date.isBefore(endOfMonth.add(const Duration(seconds: 1)));
105// }).toList();
106
107// case CollectionFilterType.calendar:
108// if (startDate == null || endDate == null) {
109// throw ArgumentError(
110// 'Start date and end date must be provided for calendar filter.');
111// }
112// return collections.where((collection) {
113// final date = collection.createDate;
114// return date != null &&
115// date.isAfter(startDate.subtract(const Duration(seconds: 1))) &&
116// date.isBefore(endDate.add(const Duration(seconds: 1)));
117// }).toList();
118// }
119// }
class CalenderTransactionsSummaryVeiw extends StatefulWidget collection
DateTime startDate
DateTime endDate
enum CollectionFilterType filterCollections({ required List< CollectionEntity > collections, required CollectionFilterType filterType, DateTime? startDate, DateTime? endDate, })
num calculateCollectionsTotalQuantity(List< CollectionEntity > collections)
CollectionFilterType
final List< CollectionEntity > collections