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

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

View File

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

View File

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

View File

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

View File

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