Files
fcs/lib/pages/delivery/model/delivery_model.dart

77 lines
2.1 KiB
Dart
Raw Normal View History

2020-10-16 17:57:58 +06:30
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
2020-10-21 05:40:58 +06:30
import 'package:fcs/data/services/services.dart';
2020-10-16 17:57:58 +06:30
import 'package:fcs/domain/constants.dart';
2020-10-18 02:38:46 +06:30
import 'package:fcs/domain/entities/carton.dart';
2020-10-16 17:57:58 +06:30
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';
2024-01-24 16:54:08 +06:30
import '../../../pagination/paginator_listener.dart';
2020-10-16 17:57:58 +06:30
class DeliveryModel extends BaseModel {
2020-10-21 05:40:58 +06:30
final log = Logger('DeliveryModel');
2024-01-24 16:54:08 +06:30
PaginatorListener<Carton>? getCartons;
int selectedIndex = 1;
2020-10-16 17:57:58 +06:30
2024-01-24 16:54:08 +06:30
onChanged(int index) {
selectedIndex = index;
loadPaginationCartons(selectedIndex);
2020-10-16 17:57:58 +06:30
notifyListeners();
}
2024-01-24 16:54:08 +06:30
loadPaginationCartons(int index) {
if (user == null || !user!.hasDeliveries()) return;
String path = "/$cartons_collection";
2020-10-16 17:57:58 +06:30
2024-01-24 16:54:08 +06:30
Query col = FirebaseFirestore.instance.collection(path);
Query pageQuery = FirebaseFirestore.instance.collection(path);
2020-10-16 17:57:58 +06:30
2024-01-24 16:54:08 +06:30
if (index == 1) {
col = col
.where("status", isEqualTo: carton_shipped_status)
.where("carton_type", whereIn: [
carton_from_packages,
carton_from_shipments,
carton_small_bag
]);
pageQuery = pageQuery
2020-10-21 05:40:58 +06:30
.where("status", isEqualTo: carton_shipped_status)
.where("carton_type", whereIn: [
2024-01-24 16:54:08 +06:30
carton_from_packages,
carton_from_shipments,
carton_small_bag
]);
2020-10-16 17:57:58 +06:30
}
2024-01-24 16:54:08 +06:30
if (index == 2) {
col = col
.where("is_delivered", isEqualTo: true)
.where("status", whereIn: [carton_delivered_status]);
pageQuery = pageQuery
.where("is_delivered", isEqualTo: true)
.where("status", whereIn: [carton_delivered_status]);
}
2020-10-16 17:57:58 +06:30
2024-01-24 16:54:08 +06:30
pageQuery = pageQuery.orderBy("carton_number");
2020-10-21 05:40:58 +06:30
2024-01-24 16:54:08 +06:30
getCartons?.close();
getCartons = PaginatorListener<Carton>(
col, pageQuery, (data, id) => Carton.fromMap(data, id),
rowPerLoad: 30);
2020-10-16 17:57:58 +06:30
}
void initUser(user) {
super.initUser(user);
}
@override
logout() async {
2024-01-24 16:54:08 +06:30
getCartons?.close();
2020-10-16 17:57:58 +06:30
}
2020-10-21 05:40:58 +06:30
Future<void> deliver(Carton carton) {
return Services.instance.cartonService.deliver(carton);
}
2020-10-16 17:57:58 +06:30
}