update carton filter and merge api for shipment

This commit is contained in:
tzw
2024-03-02 18:15:05 +06:30
parent b1e45debc7
commit c63353636a
22 changed files with 410 additions and 150 deletions

View File

@@ -64,7 +64,11 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
_portController.text = _shipment.port ?? "";
_destinationController.text = _shipment.destination ?? "";
// _currentShipmentType = model.shipmentTypes.where((e) => e.id == _shipment.shipmentTypeId).first;
List<ShipmentType> list = model.shipmentTypes
.where((e) => e.id == _shipment.shipmentTypeId)
.toList();
_currentShipmentType = list.isNotEmpty ? list.first : null;
} else {
_currentShipmentType = model.shipmentTypes[0];
}
@@ -175,7 +179,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
items: shipmentTypes
.map((e) =>
DropdownMenuItem(child: Text(e.desc), value: e))
DropdownMenuItem(child: Text(e.name), value: e))
.toList(),
onChanged: (selected) => {
setState(() {
@@ -209,7 +213,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
FcsShipment fcsShipment = FcsShipment();
fcsShipment.id = _shipment.id;
fcsShipment.shipmentNumber = _shipmentNumberController.text;
fcsShipment.shipmentTypeId = _currentShipmentType?.id;
fcsShipment.shipmentTypeId = _currentShipmentType?.id ?? "";
fcsShipment.consignee = _consigneeController.text;
fcsShipment.port = _portController.text;
fcsShipment.destination = _destinationController.text;
@@ -230,9 +234,8 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
setState(() {
_isLoading = true;
});
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
try {
await shipmentModel.create(fcsShipment);
await context.read<FcsShipmentModel>().create(fcsShipment);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -250,9 +253,9 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
setState(() {
_isLoading = true;
});
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
try {
await shipmentModel.update(fcsShipment);
await context.read<FcsShipmentModel>().update(fcsShipment);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -59,7 +59,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
if (_fcsShipment?.departureDate != null)
_departureDateControler.text =
dateFormatter.format(_fcsShipment!.departureDate!);
_shipmentTypeControler.text = _fcsShipment!.shipType ?? "";
_shipmentTypeControler.text = _fcsShipment!.shipTypeName ?? "";
_consigneeController.text = _fcsShipment!.consignee ?? "";
_portController.text = _fcsShipment!.port ?? "";
_destinationController.text = _fcsShipment!.destination ?? "";
@@ -148,7 +148,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
final invoiceBtn = Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: LocalButton(
textKey: "FCSshipment.invoice.btn",
textKey: "FCSshipment.invoiced.btn",
callBack: _invoice,
),
);
@@ -194,19 +194,17 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Expanded(
child: cutoffDateDBox,
flex: 2,
),
Flexible(
child: etaBox,
// flex: 2,
),
Flexible(child: etaBox),
]),
Row(
children: [
Expanded(
child: cartonBox,
flex: 2,
// flex: 2,
),
Flexible(child: packageBox),
Flexible(child: packageBox)
],
),
shipTypeBox,
@@ -296,9 +294,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
_isLoading = true;
});
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.process(_fcsShipment!.id!);
await context.read<FcsShipmentModel>().process(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -320,9 +316,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
_isLoading = true;
});
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.ship(_fcsShipment!.id!);
await context.read<FcsShipmentModel>().ship(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -344,9 +338,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
_isLoading = true;
});
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.arrive(_fcsShipment!.id!);
await context.read<FcsShipmentModel>().arrive(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -368,9 +360,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
_isLoading = true;
});
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.invoice(_fcsShipment!.id!);
await context.read<FcsShipmentModel>().invoice(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -386,9 +376,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
_isLoading = true;
});
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.cancel(_fcsShipment!.id!);
await context.read<FcsShipmentModel>().cancel(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -87,7 +87,7 @@ class FcsShipmentModel extends BaseModel {
try {
var snaps = await FirebaseFirestore.instance
.collection("/$fcs_shipment_collection")
// .where("status", isEqualTo: fcs_shipment_confirmed_status)
.where("status", isEqualTo: fcs_shipment_processing_status)
.get(const GetOptions(source: Source.server));
fcsShipments = snaps.docs.map((documentSnapshot) {
var fcs =
@@ -199,12 +199,20 @@ class FcsShipmentModel extends BaseModel {
return Services.instance.fcsShipmentService.report(fcsShipment);
}
Future<List<FcsShipment>> getAllShipments() async {
Future<List<FcsShipment>> getShipments() async {
List<FcsShipment> fcsShipments = [];
try {
var snaps = await FirebaseFirestore.instance
.collection("/$fcs_shipment_collection")
.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)
.limit(shipmentCountForCartonFilter)
.get(const GetOptions(source: Source.server));
fcsShipments = snaps.docs.map((documentSnapshot) {
var fcs =