update carton filter and merge api for shipment
This commit is contained in:
@@ -17,6 +17,8 @@ import 'package:path/path.dart' as Path;
|
||||
class CartonModel extends BaseModel {
|
||||
final log = Logger('CartonModel');
|
||||
|
||||
var defaultShipment =FcsShipment(shipmentNumber: "All shipments", id: all);
|
||||
|
||||
PaginatorListener<Carton>? cartonsByFilter;
|
||||
PaginatorListener<Carton>? getBoxes;
|
||||
|
||||
@@ -56,7 +58,8 @@ class CartonModel extends BaseModel {
|
||||
_loadPaginationCartons();
|
||||
}
|
||||
|
||||
filterCarton(User? consignee, User? sender, String? status) async {
|
||||
filterCarton(FcsShipment? fcsShipment, User? consignee, User? sender,
|
||||
String? status) async {
|
||||
filterByStatus = status;
|
||||
|
||||
if (status == all_status) {
|
||||
@@ -77,6 +80,12 @@ class CartonModel extends BaseModel {
|
||||
filterBySender = sender;
|
||||
}
|
||||
|
||||
if (fcsShipment?.id == all) {
|
||||
shipment = null;
|
||||
} else {
|
||||
shipment = fcsShipment;
|
||||
}
|
||||
|
||||
loadPaginationCartons();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
75
lib/pages/carton/model/shipment_selection_model.dart
Normal file
75
lib/pages/carton/model/shipment_selection_model.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import '../../../domain/constants.dart';
|
||||
import '../../main/model/base_model.dart';
|
||||
|
||||
class ShipmentSelectionModel extends BaseModel {
|
||||
final log = Logger("ShipmentSelectionModel");
|
||||
|
||||
List<FcsShipment> _shipments = [];
|
||||
|
||||
List<FcsShipment> get getShipments {
|
||||
var list = new List<FcsShipment>.from(_shipments);
|
||||
return list
|
||||
..insert(0, FcsShipment(id: all, shipmentNumber: "All shipments"));
|
||||
}
|
||||
|
||||
bool isLoading = false;
|
||||
DocumentSnapshot? _lastDocument;
|
||||
bool ended = false;
|
||||
|
||||
Future<void> refresh() async {
|
||||
_shipments.clear();
|
||||
_lastDocument = null;
|
||||
ended = false;
|
||||
await loadMoreData();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadMoreData() async {
|
||||
int rowPerPage = 20;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
String path = "/$fcs_shipment_collection";
|
||||
Query query = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("status", whereIn: [
|
||||
fcs_shipment_processing_status,
|
||||
fcs_shipment_shipped_status,
|
||||
fcs_shipment_arrived_status,
|
||||
fcs_shipment_invoiced_status
|
||||
])
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("update_time", descending: true);
|
||||
|
||||
if (_lastDocument != null) {
|
||||
query = query.startAfterDocument(_lastDocument!);
|
||||
}
|
||||
|
||||
QuerySnapshot querySnap = await query.limit(rowPerPage).get();
|
||||
|
||||
if (querySnap.docs.isEmpty) return;
|
||||
_lastDocument = querySnap.docs[querySnap.docs.length - 1];
|
||||
|
||||
List<FcsShipment> list = querySnap.docs.map((documentSnapshot) {
|
||||
var p = FcsShipment.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return p;
|
||||
}).toList();
|
||||
|
||||
_shipments.addAll(list);
|
||||
if (list.length < rowPerPage) ended = true;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
log.warning("error:$e");
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user