update carton

This commit is contained in:
Thinzar Win
2021-01-11 19:35:26 +06:30
parent 8a813023f4
commit db07e01f85
19 changed files with 211 additions and 137 deletions

View File

@@ -9,17 +9,20 @@ import 'package:fcs/domain/vo/message.dart';
import 'package:fcs/domain/vo/shipment_status.dart';
import 'package:fcs/helpers/paginator.dart';
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:fcs/pagination/paginator_listener.dart';
import 'package:logging/logging.dart';
class CartonModel extends BaseModel {
List<Carton> _boxes = [];
List<Carton> cartons = [];
PaginatorListener cartonsByFilter;
final log = Logger('CartonModel');
List<Carton> get boxes =>
_selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values);
Paginator _delivered;
int _selectedIndex = 1;
int _selectedIndexFilter = 1;
bool isLoading = false;
StreamSubscription<QuerySnapshot> listener;
@@ -60,13 +63,13 @@ class CartonModel extends BaseModel {
List<String> cartonTypes = [
carton_from_packages,
// carton_from_cargos,
carton_from_cartons,
carton_mix_box
];
List<String> mixBoxTypes = [mix_delivery, mix_pickup];
List<String> cartonTypesInfo = [
carton_from_packages,
carton_from_cargos,
carton_from_cartons,
carton_mix_box,
carton_from_shipments,
carton_small_bag
@@ -77,18 +80,45 @@ class CartonModel extends BaseModel {
notifyListeners();
}
get selectedIndex => _selectedIndex;
set selectedIndexFilter(int index) {
_selectedIndexFilter = index;
_loadCartonsByFilter(
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
notifyListeners();
}
initData() {
get selectedIndex => _selectedIndex;
get selectedIndexFilter => _selectedIndexFilter;
initData() async {
_selectedIndex = 1;
_selectedIndexFilter = 1;
_loadBoxes();
_loadCartonForMixBox();
if (_delivered != null) _delivered.close();
_delivered = _getDelivered();
_delivered.load();
}
@override
void privilegeChanged() {
if (user != null || !user.hasCarton()) {
_initData();
}
}
Future<void> _initData() async {
logout();
_selectedIndexFilter = 1;
cartonsByFilter = PaginatorListener<Carton>(
(data, id) => Carton.fromMap(data, id), onChange: () {
notifyListeners();
}, rowPerLoad: 30, insertNewByListener: true);
_loadCartonsByFilter(
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
}
Future<void> _loadBoxes() async {
if (user == null || !user.hasCarton()) return;
String path = "/$cartons_collection/";
@@ -116,30 +146,27 @@ class CartonModel extends BaseModel {
}
}
Future<void> _loadCartonForMixBox() async {
if (user == null || !user.hasCarton()) return;
String path = "/$cartons_collection/";
if (cartonListener != null) cartonListener.cancel();
cartons = [];
Future<void> _loadCartonsByFilter(String orderName) async {
if (user == null || !user.hasCarton()) return null;
String path = "/$cartons_collection";
try {
cartonListener = Firestore.instance
Query listenerQuery = Firestore.instance
.collection("$path")
.where("carton_type",
whereIn: [carton_from_packages, carton_from_cargos])
whereIn: [carton_from_packages, carton_from_cartons])
.where("status", isEqualTo: carton_packed_status)
.where("is_deleted", isEqualTo: false)
.orderBy("user_name")
.snapshots()
.listen((QuerySnapshot snapshot) {
cartons.clear();
cartons = snapshot.documents.map((documentSnapshot) {
var s = Carton.fromMap(
documentSnapshot.data, documentSnapshot.documentID);
return s;
}).toList();
.orderBy(orderName, descending: true);
notifyListeners();
});
Query pageQuery = Firestore.instance
.collection("$path")
.where("carton_type",
whereIn: [carton_from_packages, carton_from_cartons])
.where("status", isEqualTo: carton_packed_status)
.orderBy(orderName, descending: true);
cartonsByFilter.refresh(
listeningQuery: listenerQuery, pageQuery: pageQuery);
} catch (e) {
log.warning("Error!! $e");
}
@@ -184,8 +211,8 @@ class CartonModel extends BaseModel {
if (listener != null) await listener.cancel();
if (cartonListener != null) await cartonListener.cancel();
if (_delivered != null) _delivered.close();
if (cartonsByFilter != null) cartonsByFilter.close();
_boxes = [];
cartons = [];
}
Future<List<Carton>> getCartons(String shipmentID) async {
@@ -261,5 +288,4 @@ class CartonModel extends BaseModel {
Future<List<Carton>> searchCarton(String term) async {
return Services.instance.cartonService.searchCarton(term);
}
}