update cargo type form from rate, update carton info and form
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||
import 'package:fcs/domain/entities/shipment_consignee.dart';
|
||||
import 'package:fcs/domain/entities/shipment_port.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
|
||||
@@ -30,16 +32,16 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
TextEditingController _shipmentNumberController = new TextEditingController();
|
||||
TextEditingController _cutoffDateController = new TextEditingController();
|
||||
TextEditingController _arrivalDateController = new TextEditingController();
|
||||
TextEditingController _departureDateControler = new TextEditingController();
|
||||
TextEditingController _consigneeController = new TextEditingController();
|
||||
TextEditingController _portController = new TextEditingController();
|
||||
TextEditingController _destinationController = new TextEditingController();
|
||||
TextEditingController _etaDateController = new TextEditingController();
|
||||
|
||||
TextEditingController _statusController = new TextEditingController();
|
||||
|
||||
FcsShipment _shipment = new FcsShipment();
|
||||
bool _isLoading = false;
|
||||
ShipmentType? _currentShipmentType;
|
||||
ShipmentConsignee? _currentConsignee;
|
||||
ShipmentPort? _currentLoadingPort;
|
||||
ShipmentPort? _currentDestination;
|
||||
bool _isNew = false;
|
||||
|
||||
@override
|
||||
@@ -53,24 +55,38 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
||||
if (_shipment.cutoffDate != null)
|
||||
_cutoffDateController.text =
|
||||
dateFormatter.format(_shipment.cutoffDate!);
|
||||
if (_shipment.arrivalDate != null)
|
||||
_arrivalDateController.text =
|
||||
dateFormatter.format(_shipment.arrivalDate!);
|
||||
if (_shipment.departureDate != null)
|
||||
_departureDateControler.text =
|
||||
dateFormatter.format(_shipment.departureDate!);
|
||||
_statusController.text = _shipment.status ?? "";
|
||||
_consigneeController.text = _shipment.consignee ?? "";
|
||||
_portController.text = _shipment.port ?? "";
|
||||
_destinationController.text = _shipment.destination ?? "";
|
||||
if (_shipment.etaDate != null)
|
||||
_etaDateController.text = dateFormatter.format(_shipment.etaDate!);
|
||||
|
||||
List<ShipmentType> list = model.shipmentTypes
|
||||
_statusController.text = _shipment.status ?? "";
|
||||
|
||||
List<ShipmentType> shipmentTypes = model.shipmentTypes
|
||||
.where((e) => e.id == _shipment.shipmentTypeId)
|
||||
.toList();
|
||||
_currentShipmentType =
|
||||
shipmentTypes.isNotEmpty ? shipmentTypes.first : null;
|
||||
|
||||
_currentShipmentType = list.isNotEmpty ? list.first : null;
|
||||
List<ShipmentConsignee> shipmentConsingees = model.shipmentConsingees
|
||||
.where((e) => e.id == _shipment.consigneeId)
|
||||
.toList();
|
||||
_currentConsignee =
|
||||
shipmentConsingees.isNotEmpty ? shipmentConsingees.first : null;
|
||||
|
||||
List<ShipmentPort> loadingPorts = model.shipmentPorts
|
||||
.where((e) => e.id == _shipment.loadingPortId)
|
||||
.toList();
|
||||
_currentLoadingPort = loadingPorts.isNotEmpty ? loadingPorts.first : null;
|
||||
|
||||
List<ShipmentPort> loadingDestination = model.shipmentPorts
|
||||
.where((e) => e.id == _shipment.destinationPortId)
|
||||
.toList();
|
||||
_currentDestination =
|
||||
loadingDestination.isNotEmpty ? loadingDestination.first : null;
|
||||
} else {
|
||||
_currentShipmentType = model.shipmentTypes[0];
|
||||
_currentShipmentType = model.shipmentTypes.first;
|
||||
_currentConsignee = model.shipmentConsingees.first;
|
||||
_currentLoadingPort = model.shipmentPorts.first;
|
||||
_currentDestination = model.shipmentPorts.first;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +98,111 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
List<ShipmentType> shipmentTypes =
|
||||
context.watch<FcsShipmentModel>().shipmentTypes;
|
||||
var shipmentModel = context.watch<FcsShipmentModel>();
|
||||
List<ShipmentType> shipmentTypes = shipmentModel.shipmentTypes;
|
||||
List<ShipmentConsignee> shipmentConsingees =
|
||||
shipmentModel.shipmentConsingees;
|
||||
List<ShipmentPort> shipmentPorts = shipmentModel.shipmentPorts;
|
||||
|
||||
final shipmentTypeBox = DropdownButtonFormField(
|
||||
value: _currentShipmentType == "" ? null : _currentShipmentType,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
enabledBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
focusedBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
fillColor: Colors.white,
|
||||
labelStyle: languageModel.isEng
|
||||
? newLabelStyle(color: Colors.black54, fontSize: 20)
|
||||
: newLabelStyleMM(color: Colors.black54, fontSize: 20),
|
||||
labelText:
|
||||
AppTranslations.of(context)!.text('FCSshipment.shipment_type'),
|
||||
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
|
||||
items: shipmentTypes
|
||||
.map((e) => DropdownMenuItem(child: Text(e.name), value: e))
|
||||
.toList(),
|
||||
onChanged: (selected) => {
|
||||
setState(() {
|
||||
_currentShipmentType = selected;
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
final consigneeBox = DropdownButtonFormField(
|
||||
value: _currentConsignee == "" ? null : _currentConsignee,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
enabledBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
focusedBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
fillColor: Colors.white,
|
||||
labelStyle: languageModel.isEng
|
||||
? newLabelStyle(color: Colors.black54, fontSize: 20)
|
||||
: newLabelStyleMM(color: Colors.black54, fontSize: 20),
|
||||
labelText: AppTranslations.of(context)!.text('FCSshipment.consignee'),
|
||||
icon: Icon(Icons.work, color: primaryColor)),
|
||||
items: shipmentConsingees
|
||||
.map((e) => DropdownMenuItem(child: Text(e.name), value: e))
|
||||
.toList(),
|
||||
onChanged: (selected) => {
|
||||
setState(() {
|
||||
_currentConsignee = selected;
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
final loadingPortBox = DropdownButtonFormField(
|
||||
value: _currentLoadingPort == "" ? null : _currentLoadingPort,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
enabledBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
focusedBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
fillColor: Colors.white,
|
||||
labelStyle: languageModel.isEng
|
||||
? newLabelStyle(color: Colors.black54, fontSize: 20)
|
||||
: newLabelStyleMM(color: Colors.black54, fontSize: 20),
|
||||
labelText:
|
||||
AppTranslations.of(context)!.text('FCSshipment.port_of_loading'),
|
||||
icon: Icon(FontAwesomeIcons.ship, color: primaryColor)),
|
||||
items: shipmentPorts
|
||||
.map((e) => DropdownMenuItem(child: Text(e.name), value: e))
|
||||
.toList(),
|
||||
onChanged: (selected) => {
|
||||
setState(() {
|
||||
_currentLoadingPort = selected;
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
final destinationBox = DropdownButtonFormField(
|
||||
value: _currentDestination == "" ? null : _currentDestination,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
enabledBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
focusedBorder:
|
||||
UnderlineInputBorder(borderSide: BorderSide(color: primaryColor)),
|
||||
fillColor: Colors.white,
|
||||
labelStyle: languageModel.isEng
|
||||
? newLabelStyle(color: Colors.black54, fontSize: 20)
|
||||
: newLabelStyleMM(color: Colors.black54, fontSize: 20),
|
||||
labelText: AppTranslations.of(context)!
|
||||
.text('FCSshipment.final_destination'),
|
||||
icon:
|
||||
Icon(MaterialCommunityIcons.location_enter, color: primaryColor)),
|
||||
items: shipmentPorts
|
||||
.map((e) => DropdownMenuItem(child: Text(e.name), value: e))
|
||||
.toList(),
|
||||
onChanged: (selected) => {
|
||||
setState(() {
|
||||
_currentDestination = selected;
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
final createBtn = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||
@@ -150,7 +269,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
||||
InputDate(
|
||||
labelTextKey: "FCSshipment.ETA",
|
||||
iconData: Icons.date_range,
|
||||
controller: _arrivalDateController,
|
||||
controller: _etaDateController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
@@ -160,47 +279,14 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
DropdownButtonFormField(
|
||||
value:
|
||||
_currentShipmentType == "" ? null : _currentShipmentType,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor)),
|
||||
fillColor: Colors.white,
|
||||
labelStyle: languageModel.isEng
|
||||
? newLabelStyle(color: Colors.black54, fontSize: 20)
|
||||
: newLabelStyleMM(
|
||||
color: Colors.black54, fontSize: 20),
|
||||
labelText: AppTranslations.of(context)!
|
||||
.text('FCSshipment.shipment_type'),
|
||||
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
|
||||
items: shipmentTypes
|
||||
.map((e) =>
|
||||
DropdownMenuItem(child: Text(e.name), value: e))
|
||||
.toList(),
|
||||
onChanged: (selected) => {
|
||||
setState(() {
|
||||
_currentShipmentType = selected;
|
||||
})
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
InputText(
|
||||
labelTextKey: 'FCSshipment.consignee',
|
||||
iconData: Icons.work,
|
||||
controller: _consigneeController),
|
||||
InputText(
|
||||
labelTextKey: 'FCSshipment.port_of_loading',
|
||||
iconData: FontAwesomeIcons.ship,
|
||||
controller: _portController),
|
||||
InputText(
|
||||
labelTextKey: 'FCSshipment.final_destination',
|
||||
iconData: MaterialCommunityIcons.location_enter,
|
||||
controller: _destinationController),
|
||||
SizedBox(height: 20),
|
||||
shipmentTypeBox,
|
||||
const SizedBox(height: 25),
|
||||
consigneeBox,
|
||||
const SizedBox(height: 25),
|
||||
loadingPortBox,
|
||||
const SizedBox(height: 25),
|
||||
destinationBox,
|
||||
SizedBox(height: 30),
|
||||
_isNew ? createBtn : updateBtn,
|
||||
SizedBox(height: 15)
|
||||
]),
|
||||
@@ -214,16 +300,15 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
||||
fcsShipment.id = _shipment.id;
|
||||
fcsShipment.shipmentNumber = _shipmentNumberController.text;
|
||||
fcsShipment.shipmentTypeId = _currentShipmentType?.id ?? "";
|
||||
fcsShipment.consignee = _consigneeController.text;
|
||||
fcsShipment.port = _portController.text;
|
||||
fcsShipment.destination = _destinationController.text;
|
||||
fcsShipment.consigneeId = _currentConsignee?.id ?? "";
|
||||
fcsShipment.loadingPortId = _currentLoadingPort?.id ?? "";
|
||||
fcsShipment.destinationPortId = _currentDestination?.id ?? "";
|
||||
|
||||
var cutoffDate = _cutoffDateController.text;
|
||||
var arrivalDate = _arrivalDateController.text;
|
||||
var etaDate = _etaDateController.text;
|
||||
fcsShipment.cutoffDate =
|
||||
(cutoffDate == "" ? null : dateFormatter.parse(cutoffDate))!;
|
||||
fcsShipment.arrivalDate =
|
||||
(arrivalDate == "" ? null : dateFormatter.parse(arrivalDate))!;
|
||||
fcsShipment.etaDate = (etaDate == "" ? null : dateFormatter.parse(etaDate));
|
||||
return fcsShipment;
|
||||
}
|
||||
|
||||
@@ -271,11 +356,11 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
|
||||
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
|
||||
return _shipmentNumberController.text != "" ||
|
||||
_cutoffDateController.text != "" ||
|
||||
_arrivalDateController.text != "" ||
|
||||
_consigneeController.text != "" ||
|
||||
_portController.text != "" ||
|
||||
_destinationController.text != "" ||
|
||||
_currentShipmentType != shipmentModel.shipmentTypes[0];
|
||||
_etaDateController.text != "" ||
|
||||
_currentConsignee != shipmentModel.shipmentConsingees.first ||
|
||||
_currentShipmentType != shipmentModel.shipmentTypes.first ||
|
||||
_currentLoadingPort != shipmentModel.shipmentPorts.first ||
|
||||
_currentDestination != shipmentModel.shipmentPorts.first;
|
||||
} else {
|
||||
FcsShipment fcsShipment = _getPayload();
|
||||
return widget.shipment!.isChangedForEdit(fcsShipment);
|
||||
|
||||
@@ -20,8 +20,8 @@ import 'package:provider/provider.dart';
|
||||
import 'fcs_shipment_editor.dart';
|
||||
|
||||
class FcsShipmentInfo extends StatefulWidget {
|
||||
final FcsShipment? fcsShipment;
|
||||
FcsShipmentInfo({this.fcsShipment});
|
||||
final FcsShipment fcsShipment;
|
||||
FcsShipmentInfo({required this.fcsShipment});
|
||||
|
||||
@override
|
||||
_FcsShipmentInfoState createState() => _FcsShipmentInfoState();
|
||||
@@ -29,7 +29,7 @@ class FcsShipmentInfo extends StatefulWidget {
|
||||
|
||||
class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
FcsShipment? _fcsShipment;
|
||||
late FcsShipment _fcsShipment;
|
||||
bool _isLoading = false;
|
||||
TextEditingController _shipmentNumberController = new TextEditingController();
|
||||
TextEditingController _cutoffDateController = new TextEditingController();
|
||||
@@ -49,21 +49,21 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
}
|
||||
|
||||
_load() {
|
||||
_shipmentNumberController.text = _fcsShipment?.shipmentNumber ?? "";
|
||||
if (_fcsShipment?.cutoffDate != null)
|
||||
_shipmentNumberController.text = _fcsShipment.shipmentNumber ?? "";
|
||||
if (_fcsShipment.cutoffDate != null)
|
||||
_cutoffDateController.text =
|
||||
dateFormatter.format(_fcsShipment!.cutoffDate!);
|
||||
if (_fcsShipment?.arrivalDate != null)
|
||||
_arrivalDateController.text =
|
||||
dateFormatter.format(_fcsShipment!.arrivalDate!);
|
||||
if (_fcsShipment?.departureDate != null)
|
||||
dateFormatter.format(_fcsShipment.cutoffDate!);
|
||||
if (_fcsShipment.etaDate != null)
|
||||
_arrivalDateController.text = dateFormatter.format(_fcsShipment.etaDate!);
|
||||
if (_fcsShipment.departureDate != null)
|
||||
_departureDateControler.text =
|
||||
dateFormatter.format(_fcsShipment!.departureDate!);
|
||||
_shipmentTypeControler.text = _fcsShipment!.shipTypeName ?? "";
|
||||
_consigneeController.text = _fcsShipment!.consignee ?? "";
|
||||
_portController.text = _fcsShipment!.port ?? "";
|
||||
_destinationController.text = _fcsShipment!.destination ?? "";
|
||||
_statusController.text = _fcsShipment!.status ?? "";
|
||||
dateFormatter.format(_fcsShipment.departureDate!);
|
||||
|
||||
_shipmentTypeControler.text = _fcsShipment.shipmentTypeName ?? "";
|
||||
_consigneeController.text = _fcsShipment.consigneeName ?? '';
|
||||
_portController.text = _fcsShipment.loadingPortName ?? '';
|
||||
_destinationController.text = _fcsShipment.destinationPortName ?? '';
|
||||
_statusController.text = _fcsShipment.status ?? "";
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -176,7 +176,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
labelColor: primaryColor,
|
||||
arrowColor: primaryColor,
|
||||
actions: [
|
||||
_fcsShipment?.status == fcs_shipment_pending_status
|
||||
_fcsShipment.status == fcs_shipment_pending_status
|
||||
? IconButton(
|
||||
icon: Icon(Icons.edit, color: primaryColor),
|
||||
onPressed: _edit,
|
||||
@@ -212,20 +212,20 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
portBox,
|
||||
destinationBox,
|
||||
const SizedBox(height: 30),
|
||||
_fcsShipment?.status == fcs_shipment_pending_status
|
||||
_fcsShipment.status == fcs_shipment_pending_status
|
||||
? processBtn
|
||||
: Container(),
|
||||
_fcsShipment?.status == fcs_shipment_pending_status
|
||||
_fcsShipment.status == fcs_shipment_pending_status
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 3), child: cancelBtn)
|
||||
: Container(),
|
||||
_fcsShipment?.status == fcs_shipment_processed_status
|
||||
_fcsShipment.status == fcs_shipment_processed_status
|
||||
? shipBtn
|
||||
: Container(),
|
||||
_fcsShipment?.status == fcs_shipment_shipped_status
|
||||
_fcsShipment.status == fcs_shipment_shipped_status
|
||||
? arriveBtn
|
||||
: Container(),
|
||||
_fcsShipment?.status == fcs_shipment_arrived_status
|
||||
_fcsShipment.status == fcs_shipment_arrived_status
|
||||
? invoiceBtn
|
||||
: Container(),
|
||||
SizedBox(height: 20)
|
||||
@@ -244,8 +244,8 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
);
|
||||
if (updated ?? false) {
|
||||
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
|
||||
if (_fcsShipment != null && _fcsShipment!.id != null) {
|
||||
FcsShipment? f = await shipmentModel.getFcsShipment(_fcsShipment!.id!);
|
||||
if (_fcsShipment.id != null) {
|
||||
FcsShipment? f = await shipmentModel.getFcsShipment(_fcsShipment.id!);
|
||||
if (f == null) return;
|
||||
setState(() {
|
||||
_fcsShipment = f;
|
||||
@@ -294,7 +294,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await context.read<FcsShipmentModel>().process(_fcsShipment!.id!);
|
||||
await context.read<FcsShipmentModel>().process(_fcsShipment.id!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -316,7 +316,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await context.read<FcsShipmentModel>().ship(_fcsShipment!.id!);
|
||||
await context.read<FcsShipmentModel>().ship(_fcsShipment.id!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -338,7 +338,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await context.read<FcsShipmentModel>().arrive(_fcsShipment!.id!);
|
||||
await context.read<FcsShipmentModel>().arrive(_fcsShipment.id!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -360,7 +360,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await context.read<FcsShipmentModel>().invoice(_fcsShipment!.id!);
|
||||
await context.read<FcsShipmentModel>().invoice(_fcsShipment.id!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -376,7 +376,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await context.read<FcsShipmentModel>().cancel(_fcsShipment!.id!);
|
||||
await context.read<FcsShipmentModel>().cancel(_fcsShipment.id!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -402,11 +402,11 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
||||
} else if (id == 4) {
|
||||
reportName = "manifest";
|
||||
}
|
||||
_fcsShipment!.reportName = reportName;
|
||||
_fcsShipment.reportName = reportName;
|
||||
|
||||
FcsShipmentModel fcsShipmentModel =
|
||||
Provider.of<FcsShipmentModel>(context, listen: false);
|
||||
String url = await fcsShipmentModel.report(_fcsShipment!);
|
||||
String url = await fcsShipmentModel.report(_fcsShipment);
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => PDFScreen(
|
||||
title: "",
|
||||
|
||||
@@ -43,21 +43,21 @@ class _FcsShipmentListState extends State<FcsShipmentList> {
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: LocalAppBar(labelKey: "FCSshipment.list.title", actions: [
|
||||
_menuFilteringWidget(context),
|
||||
]),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
_newShipment();
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label:
|
||||
LocalText(context, "FCSshipment.add", color: Colors.white),
|
||||
backgroundColor: primaryColor),
|
||||
body: PaginatorListView<FcsShipment>(
|
||||
paginatorListener: shipmentModel.fcsShipments!,
|
||||
rowBuilder: (p) => FcsShipmentListRow(shipment: p),
|
||||
color: primaryColor)));
|
||||
appBar: LocalAppBar(labelKey: "FCSshipment.list.title", actions: [
|
||||
_menuFilteringWidget(context),
|
||||
]),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
_newShipment();
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: LocalText(context, "FCSshipment.add", color: Colors.white),
|
||||
backgroundColor: primaryColor),
|
||||
body: PaginatorListView<FcsShipment>(
|
||||
paginatorListener: shipmentModel.fcsShipments!,
|
||||
rowBuilder: (p) => FcsShipmentListRow(shipment: p),
|
||||
color: primaryColor),
|
||||
));
|
||||
}
|
||||
|
||||
_newShipment() {
|
||||
@@ -107,7 +107,9 @@ class _FcsShipmentListState extends State<FcsShipmentList> {
|
||||
value: choice,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Flexible(child: Text("${choice.text}",style: TextStyle(color: Colors.black))),
|
||||
Flexible(
|
||||
child: Text("${choice.text}",
|
||||
style: TextStyle(color: Colors.black))),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
|
||||
@@ -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