update shipment type

This commit is contained in:
tzw
2024-03-01 17:27:56 +06:30
parent 1acb2057d4
commit 41a1be745e
14 changed files with 112 additions and 52 deletions

View File

@@ -3,7 +3,6 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/widgets/input_date.dart';
import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
@@ -15,6 +14,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../../domain/entities/shipment_type.dart';
import '../main/util.dart';
class FcsShipmentEditor extends StatefulWidget {
@@ -39,13 +39,14 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
FcsShipment _shipment = new FcsShipment();
bool _isLoading = false;
String? _currentShipmentType;
ShipmentType? _currentShipmentType;
bool _isNew = false;
@override
void initState() {
super.initState();
_isNew = widget.shipment == null;
var model = Provider.of<FcsShipmentModel>(context, listen: false);
if (widget.shipment != null) {
_shipment = widget.shipment!;
_shipmentNumberController.text = _shipment.shipmentNumber ?? "";
@@ -59,13 +60,13 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
_departureDateControler.text =
dateFormatter.format(_shipment.departureDate!);
_statusController.text = _shipment.status ?? "";
_currentShipmentType = _shipment.shipType;
_consigneeController.text = _shipment.consignee ?? "";
_portController.text = _shipment.port ?? "";
_destinationController.text = _shipment.destination ?? "";
// _currentShipmentType = model.shipmentTypes.where((e) => e.id == _shipment.shipmentTypeId).first;
} else {
var mainModel = Provider.of<MainModel>(context, listen: false);
_currentShipmentType = mainModel.setting!.shipmentTypes[0];
_currentShipmentType = model.shipmentTypes[0];
}
}
@@ -77,7 +78,8 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
var mainModel = Provider.of<MainModel>(context);
List<ShipmentType> shipmentTypes =
context.watch<FcsShipmentModel>().shipmentTypes;
final createBtn = Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
@@ -171,10 +173,11 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
labelText: AppTranslations.of(context)!
.text('FCSshipment.shipment_type'),
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
items: mainModel.setting!.shipmentTypes
.map((e) => DropdownMenuItem(child: Text(e), value: e))
items: shipmentTypes
.map((e) =>
DropdownMenuItem(child: Text(e.desc), value: e))
.toList(),
onChanged: (String? selected) => {
onChanged: (selected) => {
setState(() {
_currentShipmentType = selected;
})
@@ -206,7 +209,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
FcsShipment fcsShipment = FcsShipment();
fcsShipment.id = _shipment.id;
fcsShipment.shipmentNumber = _shipmentNumberController.text;
fcsShipment.shipType = _currentShipmentType!;
fcsShipment.shipmentTypeId = _currentShipmentType?.id;
fcsShipment.consignee = _consigneeController.text;
fcsShipment.port = _portController.text;
fcsShipment.destination = _destinationController.text;
@@ -262,14 +265,14 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
isDataChanged() {
if (_isNew) {
var mainModel = Provider.of<MainModel>(context, listen: false);
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
return _shipmentNumberController.text != "" ||
_cutoffDateController.text != "" ||
_arrivalDateController.text != "" ||
_consigneeController.text != "" ||
_portController.text != "" ||
_destinationController.text != "" ||
_currentShipmentType != mainModel.setting!.shipmentTypes[0];
_currentShipmentType != shipmentModel.shipmentTypes[0];
} else {
FcsShipment fcsShipment = _getPayload();
return widget.shipment!.isChangedForEdit(fcsShipment);

View File

@@ -159,7 +159,9 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
color: dangerColor,
textKey: "FCSshipment.cancel.btn",
callBack: () {
showConfirmDialog(context, "FCSshipment.cancel.confirm", () {});
showConfirmDialog(context, "FCSshipment.cancel.confirm", () {
_cancelFcsShipment();
});
},
),
);
@@ -174,10 +176,12 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
labelColor: primaryColor,
arrowColor: primaryColor,
actions: [
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _edit,
),
_fcsShipment?.status == fcs_shipment_pending_status
? IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _edit,
)
: const SizedBox(),
//menuPopWidget(context)
],
),
@@ -377,6 +381,24 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
}
}
_cancelFcsShipment() async {
setState(() {
_isLoading = true;
});
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.cancel(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
_showPDF(int id) async {
setState(() {
_isLoading = true;

View File

@@ -7,6 +7,7 @@ import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';
import '../../../domain/entities/shipment_type.dart';
import '../../../pagination/paginator_listener.dart';
class FcsShipmentModel extends BaseModel {
@@ -15,6 +16,9 @@ class FcsShipmentModel extends BaseModel {
bool isLoading = false;
int selectedIndex = 0;
List<ShipmentType> shipmentTypes = [];
StreamSubscription<QuerySnapshot>? _shipmentTypeListener;
onChanged(int index) {
selectedIndex = index;
loadFcsShipments(selectedIndex);
@@ -132,11 +136,35 @@ class FcsShipmentModel extends BaseModel {
void initUser(user) {
super.initUser(user);
_loadShipmentTypes();
}
@override
logout() async {
fcsShipments?.close();
_shipmentTypeListener?.cancel();
shipmentTypes.clear();
}
Future<void> _loadShipmentTypes() async {
try {
_shipmentTypeListener = FirebaseFirestore.instance
.collection(
"/$config_collection/$setting_doc_id/$shipment_type_collection")
.snapshots()
.listen((QuerySnapshot snapshot) {
shipmentTypes.clear();
shipmentTypes = snapshot.docs.map((documentSnapshot) {
var privilege = ShipmentType.fromMap(
documentSnapshot.data() as Map<String, dynamic>,
documentSnapshot.id);
return privilege;
}).toList();
notifyListeners();
});
} catch (e) {
log.warning("Error!! $e");
}
}
Future<void> create(FcsShipment fcsShipment) {
@@ -163,6 +191,10 @@ class FcsShipmentModel extends BaseModel {
return Services.instance.fcsShipmentService.invoiceFcsShipment(id);
}
Future<void> cancel(String id) {
return Services.instance.fcsShipmentService.cancelFcsShipment(id);
}
Future<String> report(FcsShipment fcsShipment) {
return Services.instance.fcsShipmentService.report(fcsShipment);
}