update cargo type form from rate, update carton info and form
This commit is contained in:
@@ -4,9 +4,11 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/constants.dart';
|
||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||
import 'package:fcs/domain/entities/shipment_port.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import '../../../domain/entities/shipment_consignee.dart';
|
||||
import '../../../domain/entities/shipment_type.dart';
|
||||
import '../../../pagination/paginator_listener.dart';
|
||||
|
||||
@@ -17,7 +19,26 @@ class FcsShipmentModel extends BaseModel {
|
||||
int selectedIndex = 0;
|
||||
|
||||
List<ShipmentType> shipmentTypes = [];
|
||||
List<ShipmentConsignee> shipmentConsingees = [];
|
||||
List<ShipmentPort> shipmentPorts = [];
|
||||
StreamSubscription<QuerySnapshot>? _shipmentTypeListener;
|
||||
StreamSubscription<QuerySnapshot>? _shipmentConsigneeListener;
|
||||
StreamSubscription<QuerySnapshot>? _shipmentPortListener;
|
||||
|
||||
ShipmentType? getShipmentType(id) {
|
||||
var list = shipmentTypes.where((e) => e.id == id).toList();
|
||||
return list.isNotEmpty ? list.first : null;
|
||||
}
|
||||
|
||||
ShipmentConsignee? getShipmentConsignee(id) {
|
||||
var list = shipmentConsingees.where((e) => e.id == id).toList();
|
||||
return list.isNotEmpty ? list.first : null;
|
||||
}
|
||||
|
||||
ShipmentPort? getShipmentPort(id) {
|
||||
var list = shipmentPorts.where((e) => e.id == id).toList();
|
||||
return list.isNotEmpty ? list.first : null;
|
||||
}
|
||||
|
||||
onChanged(int index) {
|
||||
selectedIndex = index;
|
||||
@@ -39,7 +60,7 @@ class FcsShipmentModel extends BaseModel {
|
||||
pageQuery.where("status", isEqualTo: fcs_shipment_pending_status);
|
||||
}
|
||||
|
||||
// processing status
|
||||
// processed status
|
||||
if (index == 2) {
|
||||
col = col.where("status", isEqualTo: fcs_shipment_processed_status);
|
||||
pageQuery =
|
||||
@@ -74,7 +95,7 @@ class FcsShipmentModel extends BaseModel {
|
||||
pageQuery.where("status", isEqualTo: fcs_shipment_canceled_status);
|
||||
}
|
||||
|
||||
pageQuery = pageQuery.orderBy("shipment_number", descending: true);
|
||||
pageQuery = pageQuery.orderBy("update_time", descending: true);
|
||||
|
||||
fcsShipments?.close();
|
||||
fcsShipments = PaginatorListener<FcsShipment>(
|
||||
@@ -87,7 +108,7 @@ class FcsShipmentModel extends BaseModel {
|
||||
try {
|
||||
var snaps = await FirebaseFirestore.instance
|
||||
.collection("/$fcs_shipment_collection")
|
||||
// .where("status", isEqualTo: fcs_shipment_processed_status)
|
||||
.where("status", isEqualTo: fcs_shipment_processed_status)
|
||||
.get(const GetOptions(source: Source.server));
|
||||
fcsShipments = snaps.docs.map((documentSnapshot) {
|
||||
var fcs =
|
||||
@@ -137,13 +158,19 @@ class FcsShipmentModel extends BaseModel {
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
_loadShipmentTypes();
|
||||
_loadShipmentConsignees();
|
||||
_loadShipmentPorts();
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
fcsShipments?.close();
|
||||
_shipmentTypeListener?.cancel();
|
||||
_shipmentConsigneeListener?.cancel();
|
||||
_shipmentPortListener?.cancel();
|
||||
shipmentTypes.clear();
|
||||
shipmentConsingees.clear();
|
||||
shipmentPorts.clear();
|
||||
}
|
||||
|
||||
Future<void> _loadShipmentTypes() async {
|
||||
@@ -155,10 +182,52 @@ class FcsShipmentModel extends BaseModel {
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
shipmentTypes.clear();
|
||||
shipmentTypes = snapshot.docs.map((documentSnapshot) {
|
||||
var privilege = ShipmentType.fromMap(
|
||||
var type = ShipmentType.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return privilege;
|
||||
return type;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadShipmentConsignees() async {
|
||||
try {
|
||||
_shipmentConsigneeListener = FirebaseFirestore.instance
|
||||
.collection(
|
||||
"/$config_collection/$setting_doc_id/$shipment_consignee_collection")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
shipmentConsingees.clear();
|
||||
shipmentConsingees = snapshot.docs.map((documentSnapshot) {
|
||||
var consignee = ShipmentConsignee.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return consignee;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadShipmentPorts() async {
|
||||
try {
|
||||
_shipmentPortListener = FirebaseFirestore.instance
|
||||
.collection(
|
||||
"/$config_collection/$setting_doc_id/$shipment_port_collection")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
shipmentPorts.clear();
|
||||
shipmentPorts = snapshot.docs.map((documentSnapshot) {
|
||||
var port = ShipmentPort.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return port;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
@@ -192,7 +261,7 @@ class FcsShipmentModel extends BaseModel {
|
||||
|
||||
Future<void> invoice(String id) {
|
||||
return Services.instance.fcsShipmentService
|
||||
.updateFcsShipmentStatus(id, fcs_shipment_shipped_status);
|
||||
.updateFcsShipmentStatus(id, fcs_shipment_invoiced_status);
|
||||
}
|
||||
|
||||
Future<void> cancel(String id) {
|
||||
|
||||
Reference in New Issue
Block a user