add cartion filter and search
This commit is contained in:
@@ -4,26 +4,24 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:fcs/pagination/paginator_listener.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import '../../../domain/entities/user.dart';
|
||||
|
||||
class CartonModel extends BaseModel {
|
||||
final log = Logger('CartonModel');
|
||||
|
||||
PaginatorListener<Carton>? cartonsByFilter;
|
||||
PaginatorListener<Carton>? getBoxes;
|
||||
|
||||
int selectedIndex = 1;
|
||||
int _selectedIndexFilter = 1;
|
||||
bool isLoading = false;
|
||||
String? filterByStatus;
|
||||
User? filterBySender;
|
||||
User? filterByConsingee;
|
||||
FcsShipment? shipment;
|
||||
|
||||
List<String> cartonTypes = [
|
||||
carton_from_packages,
|
||||
carton_from_cartons,
|
||||
carton_mix_box
|
||||
];
|
||||
List<String> mixBoxTypes = [mix_delivery, mix_pickup];
|
||||
List<String> cartonTypesInfo = [
|
||||
carton_from_packages,
|
||||
carton_from_cartons,
|
||||
@@ -32,15 +30,6 @@ class CartonModel extends BaseModel {
|
||||
carton_small_bag
|
||||
];
|
||||
|
||||
int get selectedIndexFilter => _selectedIndexFilter;
|
||||
|
||||
set selectedIndexFilter(int index) {
|
||||
_selectedIndexFilter = index;
|
||||
_loadPaginationCartons(
|
||||
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
if (user != null || !user!.hasCarton()) {
|
||||
@@ -60,34 +49,83 @@ class CartonModel extends BaseModel {
|
||||
|
||||
Future<void> _initData() async {
|
||||
logout();
|
||||
_selectedIndexFilter = 1;
|
||||
_loadPaginationCartons(
|
||||
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
|
||||
|
||||
_loadPaginationCartons();
|
||||
}
|
||||
|
||||
onChanged(int index) {
|
||||
selectedIndex = index;
|
||||
loadPaginationBoxes(selectedIndex);
|
||||
filterCarton(User? consignee, User? sender, String? status) async {
|
||||
filterByStatus = status;
|
||||
|
||||
if (status == all_status) {
|
||||
filterByStatus = null;
|
||||
} else {
|
||||
filterByStatus = status;
|
||||
}
|
||||
|
||||
if (consignee?.id == all) {
|
||||
filterByConsingee = null;
|
||||
} else {
|
||||
filterByConsingee = consignee;
|
||||
}
|
||||
|
||||
if (sender?.id == all) {
|
||||
filterBySender = null;
|
||||
} else {
|
||||
filterBySender = sender;
|
||||
}
|
||||
|
||||
loadPaginationCartons();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadPaginationBoxes(int index) async {
|
||||
filterCartonByShipment(FcsShipment? fcsShipment) {
|
||||
if (fcsShipment?.id == all) {
|
||||
shipment = null;
|
||||
} else {
|
||||
shipment = fcsShipment;
|
||||
}
|
||||
|
||||
loadPaginationCartons();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
clearFilterSender() async {
|
||||
filterBySender = null;
|
||||
loadPaginationCartons();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
clearFilterConsignee() async {
|
||||
filterByConsingee = null;
|
||||
loadPaginationCartons();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadPaginationCartons() async {
|
||||
if (user == null || !user!.hasCarton()) return;
|
||||
|
||||
String path = "/$cartons_collection";
|
||||
Query col = FirebaseFirestore.instance.collection(path);
|
||||
Query pageQuery = FirebaseFirestore.instance.collection(path);
|
||||
|
||||
if (index == 1) {
|
||||
col = col.where("status",
|
||||
whereIn: [carton_packed_status, carton_shipped_status]);
|
||||
pageQuery = pageQuery.where("status",
|
||||
whereIn: [carton_packed_status, carton_shipped_status]);
|
||||
if (filterByConsingee != null) {
|
||||
col = col.where("user_id", isEqualTo: filterByConsingee!.id);
|
||||
pageQuery = pageQuery.where("user_id", isEqualTo: filterByConsingee!.id);
|
||||
}
|
||||
|
||||
if (index == 2) {
|
||||
col = col.where("is_delivered", isEqualTo: true);
|
||||
pageQuery = pageQuery.where("is_delivered", isEqualTo: true);
|
||||
if (filterBySender != null) {
|
||||
col = col.where("sender_id", isEqualTo: filterBySender!.id);
|
||||
pageQuery = pageQuery.where("sender_id", isEqualTo: filterBySender!.id);
|
||||
}
|
||||
|
||||
if (filterByStatus != null) {
|
||||
col = col.where("status", isEqualTo: filterByStatus);
|
||||
pageQuery = pageQuery.where("status", isEqualTo: filterByStatus);
|
||||
}
|
||||
|
||||
if (shipment != null) {
|
||||
col = col.where("fcs_shipment_id", isEqualTo: shipment!.id);
|
||||
pageQuery = pageQuery.where("fcs_shipment_id", isEqualTo: shipment!.id);
|
||||
}
|
||||
|
||||
pageQuery = pageQuery.orderBy("created_at", descending: true);
|
||||
@@ -98,21 +136,23 @@ class CartonModel extends BaseModel {
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
_loadPaginationCartons(String orderName) {
|
||||
_loadPaginationCartons() {
|
||||
if (user == null || !user!.hasCarton()) return null;
|
||||
String path = "/$cartons_collection";
|
||||
|
||||
Query col = FirebaseFirestore.instance.collection(path).where("carton_type",
|
||||
whereIn: [
|
||||
carton_from_packages,
|
||||
carton_from_cartons
|
||||
]).where("status", isEqualTo: carton_packed_status);
|
||||
Query col = FirebaseFirestore.instance.collection(path);
|
||||
// .where("carton_type",
|
||||
// whereIn: [
|
||||
// carton_from_packages,
|
||||
// carton_from_cartons
|
||||
// ]).where("status", isEqualTo: carton_packed_status)
|
||||
// ;
|
||||
Query pageQuery = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cartons])
|
||||
.where("status", isEqualTo: carton_packed_status)
|
||||
.orderBy(orderName, descending: true);
|
||||
// .where("carton_type",
|
||||
// whereIn: [carton_from_packages, carton_from_cartons])
|
||||
// .where("status", isEqualTo: carton_packed_status)
|
||||
.orderBy("created_at", descending: true);
|
||||
|
||||
cartonsByFilter?.close();
|
||||
cartonsByFilter = PaginatorListener<Carton>(
|
||||
|
||||
Reference in New Issue
Block a user