update cargo type form from rate, update carton info and form
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||
import 'package:fcs/helpers/shared_pref.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:fcs/pagination/paginator_listener.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
@@ -18,8 +19,6 @@ class CartonModel extends BaseModel {
|
||||
final log = Logger('CartonModel');
|
||||
|
||||
var defaultShipment = FcsShipment(shipmentNumber: "All shipments", id: all);
|
||||
|
||||
PaginatorListener<Carton>? cartonsByFilter;
|
||||
PaginatorListener<Carton>? getBoxes;
|
||||
|
||||
String? filterByStatus;
|
||||
@@ -49,13 +48,10 @@ class CartonModel extends BaseModel {
|
||||
@override
|
||||
logout() async {
|
||||
getBoxes?.close();
|
||||
cartonsByFilter?.close();
|
||||
}
|
||||
|
||||
Future<void> _initData() async {
|
||||
logout();
|
||||
|
||||
_loadPaginationCartons();
|
||||
}
|
||||
|
||||
filterCarton(FcsShipment? fcsShipment, User? consignee, User? sender,
|
||||
@@ -140,7 +136,7 @@ class CartonModel extends BaseModel {
|
||||
pageQuery = pageQuery.where("fcs_shipment_id", isEqualTo: shipment!.id);
|
||||
}
|
||||
|
||||
pageQuery = pageQuery.orderBy("created_at", descending: true);
|
||||
pageQuery = pageQuery.orderBy("update_time", descending: true);
|
||||
|
||||
getBoxes?.close();
|
||||
getBoxes = PaginatorListener<Carton>(
|
||||
@@ -148,30 +144,6 @@ class CartonModel extends BaseModel {
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
_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 pageQuery = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
// .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>(
|
||||
col, pageQuery, (data, id) => Carton.fromMap(data, id),
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartons(String shipmentID) async {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await FirebaseFirestore.instance
|
||||
@@ -235,8 +207,18 @@ class CartonModel extends BaseModel {
|
||||
return Services.instance.cartonService.deleteCarton(carton);
|
||||
}
|
||||
|
||||
Future<Carton> createMixCarton(Carton carton) {
|
||||
return Services.instance.cartonService.createCarton(carton);
|
||||
}
|
||||
|
||||
Future<void> updateMixCarton(Carton carton) {
|
||||
return Services.instance.cartonService.updateMixCarton(carton);
|
||||
}
|
||||
|
||||
Future<List<Carton>> searchCarton(String term) async {
|
||||
|
||||
if (term != '') {
|
||||
await SharedPref.saveRecentSearch('carton_search', term);
|
||||
}
|
||||
return Services.instance.cartonService.searchCarton(term);
|
||||
}
|
||||
|
||||
@@ -277,9 +259,11 @@ class CartonModel extends BaseModel {
|
||||
uploadedURL.forEach((url) {
|
||||
carton.photoUrls.add(url);
|
||||
});
|
||||
|
||||
carton.photoUrls.removeWhere((e) => deletedUrls.contains(e));
|
||||
}
|
||||
try {
|
||||
// await Services.instance.packageService.updateReceiving(package);
|
||||
await Services.instance.cartonService.uploadCartonImages(carton);
|
||||
} catch (e) {
|
||||
// delete newly uploaded photos if fails
|
||||
try {
|
||||
|
||||
@@ -54,7 +54,7 @@ class CartonSelectionModel extends BaseModel {
|
||||
query = query.where("carton_number", isEqualTo: term);
|
||||
}
|
||||
|
||||
query = query.orderBy("created_at", descending: true);
|
||||
query = query.orderBy("update_time", descending: true);
|
||||
|
||||
if (_lastDocument != null) {
|
||||
query = query.startAfterDocument(_lastDocument!);
|
||||
|
||||
Reference in New Issue
Block a user