update cargo type input, add package count and carton count for shipment info

This commit is contained in:
tzw
2025-03-26 15:51:47 +06:30
parent db3e290546
commit 17ca3e2a3f
11 changed files with 156 additions and 53 deletions

View File

@@ -709,5 +709,9 @@
"pickup.customer.remark":"Customer Remark", "pickup.customer.remark":"Customer Remark",
"pickup.reschedul.remark":"Reschedule Remark", "pickup.reschedul.remark":"Reschedule Remark",
"pickup.delivery.address":"Delivery address", "pickup.delivery.address":"Delivery address",
"Pickup End ===================================================================":"" "Pickup End ===================================================================":"",
"Setting Start ================================================================":"",
"setting.title":"Settings",
"Setting End ===================================================================":""
} }

View File

@@ -711,5 +711,9 @@
"pickup.customer.remark":"ဝယ်သူ မှတ်ချက်", "pickup.customer.remark":"ဝယ်သူ မှတ်ချက်",
"pickup.reschedul.remark":"Reschedule Remark", "pickup.reschedul.remark":"Reschedule Remark",
"pickup.delivery.address":"ပို့ဆောင်ရမည့်လိပ်စာ", "pickup.delivery.address":"ပို့ဆောင်ရမည့်လိပ်စာ",
"Pickup End ===================================================================":"" "Pickup End ===================================================================":"",
"Setting Start ================================================================":"",
"setting.title":"Settings",
"Setting End ===================================================================":""
} }

View File

@@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'package:fcs/pages/main/util.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:open_file/open_file.dart'; import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
@@ -53,7 +54,8 @@ Future<void> generateCartonPdf(Carton carton) async {
fontSize: 10, fontSize: 10,
)), )),
pw.SizedBox(height: 3), pw.SizedBox(height: 3),
pw.Text("${carton.actualWeight} lb", pw.Text(
"${twoDecimalFormatted(double.tryParse(removeTrailingZeros(carton.actualWeight)) ?? 0)} lb",
style: pw.TextStyle( style: pw.TextStyle(
fontSize: 10, fontSize: 10,
color: PdfColor.fromInt(0xFF757575))) color: PdfColor.fromInt(0xFF757575)))

View File

@@ -16,8 +16,8 @@ import 'cargo_type_addition_dialog.dart';
import 'mix_cargo_type_addition_dialog.dart'; import 'mix_cargo_type_addition_dialog.dart';
import 'surcharge_item_addition.dart'; import 'surcharge_item_addition.dart';
typedef OnPrevious = Function( typedef OnPrevious = Function(List<CargoType> cargoTypes,
List<CargoType> cargoTypes, List<CargoType> customDuties); List<CargoType> customDuties, double totalWeight);
typedef OnContinue = Function( typedef OnContinue = Function(
List<CargoType> cargoTypes, List<CargoType> customDuties); List<CargoType> cargoTypes, List<CargoType> customDuties);
@@ -28,16 +28,17 @@ class CargoWidget extends StatefulWidget {
final List<CargoType> surchargeItems; final List<CargoType> surchargeItems;
final OnPrevious? onPrevious; final OnPrevious? onPrevious;
final OnContinue? onContinue; final OnContinue? onContinue;
final double totalWeight;
const CargoWidget({ const CargoWidget(
super.key, {super.key,
required this.cargoTypes, required this.cargoTypes,
required this.surchargeItems, required this.surchargeItems,
this.onPrevious, this.onPrevious,
this.onContinue, this.onContinue,
required this.sender, required this.sender,
required this.consignee, required this.consignee,
}); this.totalWeight = 0});
@override @override
State<CargoWidget> createState() => _CargoWidgetState(); State<CargoWidget> createState() => _CargoWidgetState();
@@ -54,7 +55,7 @@ class _CargoWidgetState extends State<CargoWidget> {
bool get hasValueTotalWeight => bool get hasValueTotalWeight =>
totalCtl.text.isNotEmpty && totalCtl.text != '0.00'; totalCtl.text.isNotEmpty && totalCtl.text != '0.00';
bool get hasValueCargoes => bool get hasValueCargoes =>
_cargoTypes.isNotEmpty && _cargoTypes.every((e) => e.weight != 0.00); _cargoTypes.isNotEmpty && _cargoTypes.every((e) => e.weight != 0);
double get actualTotalWeight => double get actualTotalWeight =>
_cargoTypes.fold(0, (sum, value) => sum + value.weight); _cargoTypes.fold(0, (sum, value) => sum + value.weight);
@@ -67,6 +68,7 @@ class _CargoWidgetState extends State<CargoWidget> {
} }
_init() { _init() {
totalCtl.clear();
// for cargo types // for cargo types
if (widget.cargoTypes.isNotEmpty) { if (widget.cargoTypes.isNotEmpty) {
_cargoTypes = List.from(widget.cargoTypes); _cargoTypes = List.from(widget.cargoTypes);
@@ -77,6 +79,9 @@ class _CargoWidgetState extends State<CargoWidget> {
editor.addListener(inputChangeListener); editor.addListener(inputChangeListener);
cargoTypeControllers.add(editor); cargoTypeControllers.add(editor);
} }
totalCtl.text = twoDecimalFormatted(
double.tryParse(removeTrailingZeros(widget.totalWeight)) ?? 0);
_onPopulate(); _onPopulate();
} else { } else {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -130,7 +135,7 @@ class _CargoWidgetState extends State<CargoWidget> {
List<int> emptyFields = []; List<int> emptyFields = [];
for (int i = 0; i < cargoTypeControllers.length; i++) { for (int i = 0; i < cargoTypeControllers.length; i++) {
if (cargoTypeControllers[i].text.trim().isEmpty || if (cargoTypeControllers[i].text.trim().isEmpty ||
cargoTypeControllers[i].text.trim() == "0") { cargoTypeControllers[i].text.trim() == "0.00") {
emptyFields.add(i); emptyFields.add(i);
} }
} }
@@ -143,7 +148,6 @@ class _CargoWidgetState extends State<CargoWidget> {
double.tryParse(removeTrailingZeros(actualTotalWeight)) ?? 0); double.tryParse(removeTrailingZeros(actualTotalWeight)) ?? 0);
error = null; error = null;
} else { } else {
// auto populate remaining value
double totalWeight = (double.tryParse(totalCtl.text) ?? 0); double totalWeight = (double.tryParse(totalCtl.text) ?? 0);
if (actualTotalWeight > totalWeight) { if (actualTotalWeight > totalWeight) {
@@ -156,6 +160,7 @@ class _CargoWidgetState extends State<CargoWidget> {
List<int> emptyFieldIndexes = getEmptyFields(); List<int> emptyFieldIndexes = getEmptyFields();
if (emptyFieldIndexes.isNotEmpty) { if (emptyFieldIndexes.isNotEmpty) {
// auto populate remaining value
if (emptyFieldIndexes.length == 1) { if (emptyFieldIndexes.length == 1) {
_cargoTypes.asMap().entries.forEach((e) { _cargoTypes.asMap().entries.forEach((e) {
if (e.value.weight == 0) { if (e.value.weight == 0) {
@@ -164,7 +169,11 @@ class _CargoWidgetState extends State<CargoWidget> {
double.tryParse(removeTrailingZeros(e.value.weight)) ?? 0); double.tryParse(removeTrailingZeros(e.value.weight)) ?? 0);
} }
}); });
} else {
_onCheckTotalWeight(twoDecimalFormatted(totalWeight));
} }
} else {
_onCheckTotalWeight(twoDecimalFormatted(totalWeight));
} }
} }
} }
@@ -185,6 +194,18 @@ class _CargoWidgetState extends State<CargoWidget> {
} }
} }
@override
void dispose() {
for (var controller in cargoTypeControllers) {
controller.dispose();
}
for (var controller in surchargeControllers) {
controller.dispose();
}
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final senderBox = userDisplayBox(context, final senderBox = userDisplayBox(context,
@@ -281,11 +302,7 @@ class _CargoWidgetState extends State<CargoWidget> {
child: inputTextFieldWidget(context, child: inputTextFieldWidget(context,
lableText: "Total", lableText: "Total",
controller: totalCtl, onFieldSubmitted: (newValue) { controller: totalCtl, onFieldSubmitted: (newValue) {
if (hasValueCargoes) {
_onCheckTotalWeight(newValue); _onCheckTotalWeight(newValue);
} else {
_onPopulate();
}
}, },
suffixIcon: InkResponse( suffixIcon: InkResponse(
radius: 23, radius: 23,
@@ -397,13 +414,9 @@ class _CargoWidgetState extends State<CargoWidget> {
); );
final previousBtn = PreviousButton(onTap: () { final previousBtn = PreviousButton(onTap: () {
if (error != null) {
showMsgDialog(
context, "Error", "Please add the right cargo type weight");
return;
}
if (widget.onPrevious != null) { if (widget.onPrevious != null) {
widget.onPrevious!(_cargoTypes, _surchareItems); widget.onPrevious!(
_cargoTypes, _surchareItems, double.tryParse(totalCtl.text) ?? 0);
} }
}); });
@@ -595,9 +608,11 @@ class _CargoWidgetState extends State<CargoWidget> {
Function(String)? onChanged, Function(String)? onChanged,
Function(String)? onFieldSubmitted, Function(String)? onFieldSubmitted,
bool readOnly = false, bool readOnly = false,
Widget? suffixIcon}) { Widget? suffixIcon,
FocusNode? focusNode}) {
return TextFormField( return TextFormField(
controller: controller, controller: controller,
focusNode: focusNode,
style: textStyle, style: textStyle,
cursorColor: primaryColor, cursorColor: primaryColor,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,

View File

@@ -47,6 +47,7 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
List<CargoType> _cargoTypes = []; List<CargoType> _cargoTypes = [];
List<CargoType> _surchareItems = []; List<CargoType> _surchareItems = [];
double _totalWeight = 0;
int currentStep = 0; int currentStep = 0;
double _length = 0; double _length = 0;
@@ -89,6 +90,7 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
widget.carton.cargoTypes.map((e) => e.cloneForCarton()).toList(); widget.carton.cargoTypes.map((e) => e.cloneForCarton()).toList();
_surchareItems = _surchareItems =
widget.carton.surchareItems.map((e) => e.cloneForSurchage()).toList(); widget.carton.surchareItems.map((e) => e.cloneForSurchage()).toList();
_totalWeight = _cargoTypes.fold(0, (sum, value) => sum + value.weight);
// check carton size type // check carton size type
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes; List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
@@ -252,6 +254,7 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
consignee: _consignee!, consignee: _consignee!,
cargoTypes: _cargoTypes, cargoTypes: _cargoTypes,
surchargeItems: _surchareItems, surchargeItems: _surchareItems,
totalWeight: _totalWeight,
onContinue: (cargoTypes, customDuties) { onContinue: (cargoTypes, customDuties) {
setState(() { setState(() {
_cargoTypes = List.from(cargoTypes); _cargoTypes = List.from(cargoTypes);
@@ -259,8 +262,9 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
currentStep += 1; currentStep += 1;
}); });
}, },
onPrevious: (cargoTypes, customDuties) { onPrevious: (cargoTypes, customDuties, totalWeight) {
setState(() { setState(() {
_totalWeight = totalWeight;
_cargoTypes = List.from(cargoTypes); _cargoTypes = List.from(cargoTypes);
_surchareItems = List.from(customDuties); _surchareItems = List.from(customDuties);
currentStep -= 1; currentStep -= 1;

View File

@@ -50,6 +50,7 @@ class _CartonPackageFormState extends State<CartonPackageForm> {
List<CargoType> _cargoTypes = []; List<CargoType> _cargoTypes = [];
List<CargoType> _surchareItems = []; List<CargoType> _surchareItems = [];
double _totalWeight = 0;
int currentStep = 0; int currentStep = 0;
double _length = 0; double _length = 0;
@@ -188,6 +189,7 @@ class _CartonPackageFormState extends State<CartonPackageForm> {
consignee: widget.consignee, consignee: widget.consignee,
cargoTypes: _cargoTypes, cargoTypes: _cargoTypes,
surchargeItems: _surchareItems, surchargeItems: _surchareItems,
totalWeight: _totalWeight,
onContinue: (cargoTypes, customDuties) { onContinue: (cargoTypes, customDuties) {
setState(() { setState(() {
_cargoTypes = List.from(cargoTypes); _cargoTypes = List.from(cargoTypes);
@@ -195,8 +197,9 @@ class _CartonPackageFormState extends State<CartonPackageForm> {
currentStep += 1; currentStep += 1;
}); });
}, },
onPrevious: (cargoTypes, customDuties) { onPrevious: (cargoTypes, customDuties, totalWeight) {
setState(() { setState(() {
_totalWeight = totalWeight;
_cargoTypes = List.from(cargoTypes); _cargoTypes = List.from(cargoTypes);
_surchareItems = List.from(customDuties); _surchareItems = List.from(customDuties);
currentStep -= 1; currentStep -= 1;

View File

@@ -174,6 +174,7 @@ class PackageSelectionModel extends BaseModel {
.where("sender_id", isEqualTo: senderId) .where("sender_id", isEqualTo: senderId)
.where("user_id", isEqualTo: consigneeId) .where("user_id", isEqualTo: consigneeId)
.where("fcs_shipment_id", isEqualTo: shipmentId) .where("fcs_shipment_id", isEqualTo: shipmentId)
.where("delete_time", isEqualTo: 0)
.count() .count()
.get(); .get();

View File

@@ -1,5 +1,6 @@
import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/local_button.dart'; import 'package:fcs/pages/widgets/local_button.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -42,7 +43,8 @@ class PrintQrCodePage extends StatelessWidget {
TextStyle(fontSize: 16, fontFamily: "Roboto")), TextStyle(fontSize: 16, fontFamily: "Roboto")),
Padding( Padding(
padding: const EdgeInsets.only(top: 3), padding: const EdgeInsets.only(top: 3),
child: Text("${carton.actualWeight} lb", child: Text(
"${twoDecimalFormatted(double.tryParse(removeTrailingZeros(carton.actualWeight)) ?? 0)} lb",
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: labelColor, color: labelColor,

View File

@@ -42,6 +42,8 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
TextEditingController portController = TextEditingController(); TextEditingController portController = TextEditingController();
TextEditingController destinationController = TextEditingController(); TextEditingController destinationController = TextEditingController();
TextEditingController statusController = TextEditingController(); TextEditingController statusController = TextEditingController();
int _packageCount = 0;
int _cartonCount = 0;
@override @override
void initState() { void initState() {
@@ -50,14 +52,17 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
_load(); _load();
} }
_load() { _load() async {
try {
_isLoading = true;
shipmentNumberController.text = _fcsShipment.shipmentNumber ?? ""; shipmentNumberController.text = _fcsShipment.shipmentNumber ?? "";
if (_fcsShipment.cutoffDate != null) { if (_fcsShipment.cutoffDate != null) {
cutoffDateController.text = cutoffDateController.text =
dateFormatter.format(_fcsShipment.cutoffDate!); dateFormatter.format(_fcsShipment.cutoffDate!);
} }
if (_fcsShipment.etaDate != null) { if (_fcsShipment.etaDate != null) {
arrivalDateController.text = dateFormatter.format(_fcsShipment.etaDate!); arrivalDateController.text =
dateFormatter.format(_fcsShipment.etaDate!);
} }
if (_fcsShipment.departureDate != null) { if (_fcsShipment.departureDate != null) {
departureDateControler.text = departureDateControler.text =
@@ -69,6 +74,34 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
portController.text = _fcsShipment.loadingPortName ?? ''; portController.text = _fcsShipment.loadingPortName ?? '';
destinationController.text = _fcsShipment.destinationPortName ?? ''; destinationController.text = _fcsShipment.destinationPortName ?? '';
statusController.text = _fcsShipment.status ?? ""; statusController.text = _fcsShipment.status ?? "";
await Future.wait([_loadPackageCount(), _loadCartonCount()]);
} finally {
_isLoading = false;
}
if (mounted) {
setState(() {});
}
}
Future<void> _loadPackageCount() async {
int? count = await context
.read<FcsShipmentModel>()
.getPackageCount(fcsShipmentId: _fcsShipment.id ?? "");
_packageCount = count ?? 0;
if (mounted) {
setState(() {});
}
}
Future<void> _loadCartonCount() async {
int? count = await context
.read<FcsShipmentModel>()
.getCartonCount(fcsShipmentId: _fcsShipment.id ?? "");
_cartonCount = count ?? 0;
if (mounted) {
setState(() {});
}
} }
@override @override
@@ -90,13 +123,13 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
); );
final cartonBox = DisplayText( final cartonBox = DisplayText(
text: numberFormatter.format(_fcsShipment.cartonCount), text: numberFormatter.format(_cartonCount),
labelTextKey: "FCSshipment.carton", labelTextKey: "FCSshipment.carton",
iconData: MaterialCommunityIcons.package, iconData: MaterialCommunityIcons.package,
); );
final packageBox = DisplayText( final packageBox = DisplayText(
text: numberFormatter.format(_fcsShipment.packageCount), text: numberFormatter.format(_packageCount),
labelTextKey: "FCSshipment.package", labelTextKey: "FCSshipment.package",
iconData: Octicons.package, iconData: Octicons.package,
); );
@@ -196,7 +229,6 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
style: TextStyle(fontSize: 15, color: Colors.black)) style: TextStyle(fontSize: 15, color: Colors.black))
], ],
), ),
backgroundColor: Colors.white, backgroundColor: Colors.white,
labelColor: primaryColor, labelColor: primaryColor,
arrowColor: primaryColor, arrowColor: primaryColor,

View File

@@ -314,4 +314,30 @@ class FcsShipmentModel extends BaseModel {
} }
return fcsShipments; return fcsShipments;
} }
Future<int?> getPackageCount({required String fcsShipmentId}) async {
String path = "/$packages_collection";
AggregateQuerySnapshot query = await FirebaseFirestore.instance
.collection(path)
.where("fcs_shipment_id", isEqualTo: fcsShipmentId)
.where("delete_time", isEqualTo: 0)
.count()
.get();
return query.count;
}
Future<int?> getCartonCount({required String fcsShipmentId}) async {
String path = "/$cartons_collection";
AggregateQuerySnapshot query = await FirebaseFirestore.instance
.collection(path)
.where("fcs_shipment_id", isEqualTo: fcsShipmentId)
.where("delete_time", isEqualTo: 0)
.count()
.get();
return query.count;
}
} }

View File

@@ -350,6 +350,14 @@ class _HomePageState extends State<HomePage> {
btnCallback: () => Navigator.of(context).push<void>( btnCallback: () => Navigator.of(context).push<void>(
CupertinoPageRoute(builder: (context) => DeliverList()))); CupertinoPageRoute(builder: (context) => DeliverList())));
// final setttingBtn = TaskButton(
// "setting.title",
// icon: Ionicons.ios_settings_outline,
// btnCallback: () => Navigator.of(context).push<void>(CupertinoPageRoute(
// builder: (context) => StaffList(),
// )),
// );
List<Widget> widgets = []; List<Widget> widgets = [];
List<Widget> widgetsFcs = []; List<Widget> widgetsFcs = [];
widgets.add(notiBtn); widgets.add(notiBtn);
@@ -372,8 +380,10 @@ class _HomePageState extends State<HomePage> {
if (user.hasCustomers()) widgetsFcs.add(customersBtn); if (user.hasCustomers()) widgetsFcs.add(customersBtn);
if (user.hasAdmin()) widgetsFcs.add(discountBtn); if (user.hasAdmin()) widgetsFcs.add(discountBtn);
if (user.hasStaffs()) widgetsFcs.add(staffBtn); if (user.hasStaffs()) widgetsFcs.add(staffBtn);
// widgetsFcs.add(setttingBtn);
} }
widgets.add(faqBtn); widgets.add(faqBtn);
// widgets.add(setttingBtn);
final fcsToggle = ToggleButtons( final fcsToggle = ToggleButtons(
selectedColor: Colors.white, selectedColor: Colors.white,