2024-02-05 11:13:12 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
2024-09-22 16:49:59 +06:30
|
|
|
import '../../../constants.dart';
|
2024-02-05 11:13:12 +06:30
|
|
|
import '../../../domain/entities/cargo_type.dart';
|
|
|
|
|
import '../../../domain/entities/carton.dart';
|
|
|
|
|
import '../../../domain/entities/carton_size.dart';
|
|
|
|
|
import '../../../domain/entities/fcs_shipment.dart';
|
|
|
|
|
import '../../../helpers/theme.dart';
|
2024-02-06 17:45:36 +06:30
|
|
|
import '../../main/util.dart';
|
2024-02-05 11:13:12 +06:30
|
|
|
import '../../widgets/local_text.dart';
|
|
|
|
|
import '../../widgets/previous_button.dart';
|
|
|
|
|
import '../../widgets/submit_text_widget.dart';
|
|
|
|
|
import "package:collection/collection.dart";
|
|
|
|
|
|
|
|
|
|
typedef OnCreateMixCarton = Function();
|
|
|
|
|
typedef OnPrevious = Function();
|
|
|
|
|
|
|
|
|
|
class MixCartonSubmit extends StatefulWidget {
|
2024-02-09 17:10:19 +06:30
|
|
|
final bool isNew;
|
2024-02-05 11:13:12 +06:30
|
|
|
final FcsShipment shipment;
|
|
|
|
|
final List<Carton> cartons;
|
|
|
|
|
final String cartonSizeType;
|
|
|
|
|
final CartonSize? standardSize;
|
|
|
|
|
final double length;
|
|
|
|
|
final double width;
|
|
|
|
|
final double height;
|
|
|
|
|
final OnCreateMixCarton? onCreate;
|
|
|
|
|
final OnPrevious? onPrevious;
|
|
|
|
|
const MixCartonSubmit(
|
|
|
|
|
{Key? key,
|
|
|
|
|
this.onCreate,
|
|
|
|
|
this.onPrevious,
|
|
|
|
|
required this.shipment,
|
|
|
|
|
this.cartons = const [],
|
|
|
|
|
this.standardSize,
|
|
|
|
|
required this.cartonSizeType,
|
|
|
|
|
this.length = 0,
|
|
|
|
|
this.width = 0,
|
2024-02-09 17:10:19 +06:30
|
|
|
this.height = 0,
|
|
|
|
|
this.isNew = true})
|
2024-02-05 11:13:12 +06:30
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<MixCartonSubmit> createState() => _MixCartonSubmitState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MixCartonSubmitState extends State<MixCartonSubmit> {
|
|
|
|
|
final NumberFormat numberFormatter = NumberFormat("#,###");
|
|
|
|
|
Map<String?, double> _mapCargosByWeight = {};
|
|
|
|
|
Map<String?, double> _mapCargosByCustomDutyFee = {};
|
2024-02-06 17:45:36 +06:30
|
|
|
double totalWeight = 0;
|
2024-02-05 11:13:12 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_init();
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_init() {
|
|
|
|
|
List<CargoType> _cargoTypes = [];
|
|
|
|
|
for (var c in widget.cartons) {
|
|
|
|
|
_cargoTypes.addAll(c.cargoTypes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get cargos by weight
|
|
|
|
|
Map<String?, List<CargoType>> _cargosByWeight =
|
|
|
|
|
groupCargos(_cargoTypes.where((e) => !e.isCutomDuty).toList());
|
|
|
|
|
|
|
|
|
|
_cargosByWeight.forEach((key, value) {
|
|
|
|
|
double total = value.fold(0, (sum, item) => sum + item.weight);
|
|
|
|
|
_mapCargosByWeight[key] = total;
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-06 17:45:36 +06:30
|
|
|
totalWeight =
|
|
|
|
|
_mapCargosByWeight.entries.fold(0, (sum, value) => sum + value.value);
|
|
|
|
|
|
2024-02-05 11:13:12 +06:30
|
|
|
// get cargos by custom duty fee
|
|
|
|
|
Map<String?, List<CargoType>> _cargosByCustomDutyFee =
|
|
|
|
|
groupCargos(_cargoTypes.where((e) => e.isCutomDuty).toList());
|
|
|
|
|
|
|
|
|
|
_cargosByCustomDutyFee.forEach((key, value) {
|
|
|
|
|
double total = value.fold(0, (sum, item) => sum + item.qty);
|
|
|
|
|
_mapCargosByCustomDutyFee[key] = total;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String?, List<CargoType>> groupCargos(List<CargoType> cargos) {
|
|
|
|
|
var groups = groupBy(cargos, (CargoType e) {
|
|
|
|
|
String? _categoryName = e.name;
|
|
|
|
|
return _categoryName;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return groups;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
String? boxDimension = widget.cartonSizeType == standardCarton
|
|
|
|
|
? "${widget.standardSize?.name} - ${widget.standardSize?.length.toInt()}”x${widget.standardSize?.width.toInt()}”x${widget.standardSize?.height.toInt()}”"
|
|
|
|
|
: widget.cartonSizeType == customCarton
|
|
|
|
|
? "${widget.length.toInt()}”x${widget.width.toInt()}”x${widget.height.toInt()}”"
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
final cartonType = Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
|
child: SubmitTextWidget(
|
|
|
|
|
labelKey: 'box.carton.type',
|
2024-02-06 17:45:36 +06:30
|
|
|
text: carton_mix_carton,
|
2024-09-23 18:36:23 +06:30
|
|
|
// subText: boxDimension,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final cartonSizeBox = Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
|
child: SubmitTextWidget(
|
|
|
|
|
labelKey: 'box.carton_size',
|
|
|
|
|
text: boxDimension ?? '',
|
2024-02-05 11:13:12 +06:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final shipmentBox = Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
|
child: SubmitTextWidget(
|
|
|
|
|
labelKey: 'box.shipment',
|
|
|
|
|
text: widget.shipment.shipmentNumber ?? '',
|
|
|
|
|
subText: widget.shipment.status ?? "",
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final cartonsBox = Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 5, bottom: 5),
|
|
|
|
|
child: LocalText(context, 'box.cartion.count',
|
|
|
|
|
translationVariables: [widget.cartons.length.toString()],
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
fontWeight: FontWeight.normal),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border.all(color: primaryColor),
|
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
|
),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: Wrap(
|
|
|
|
|
spacing: 15,
|
|
|
|
|
children: widget.cartons.map((e) {
|
|
|
|
|
return SizedBox(
|
|
|
|
|
width: MediaQuery.of(context).size.width / 2.5,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
|
|
|
child: Text(
|
|
|
|
|
e.cartonNumber ?? "",
|
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 15),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList()),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final cargosBox = Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
|
|
|
|
Padding(
|
2024-02-06 17:45:36 +06:30
|
|
|
padding: const EdgeInsets.only(left: 5, bottom: 5, right: 8),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
LocalText(context, 'box.cargo.type',
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
fontWeight: FontWeight.normal),
|
|
|
|
|
Text("${removeTrailingZeros(totalWeight)} lb",
|
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 15))
|
|
|
|
|
],
|
|
|
|
|
),
|
2024-02-05 11:13:12 +06:30
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border.all(color: primaryColor),
|
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
|
),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: _mapCargosByWeight.entries.map((e) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
e.key ?? "",
|
|
|
|
|
style:
|
|
|
|
|
TextStyle(color: Colors.black, fontSize: 15),
|
|
|
|
|
),
|
2024-02-06 17:45:36 +06:30
|
|
|
Text("${removeTrailingZeros(e.value)} lb",
|
2024-02-05 11:13:12 +06:30
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.black, fontSize: 15))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList()),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: _mapCargosByCustomDutyFee.entries.map((e) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
e.key ?? "",
|
|
|
|
|
style: TextStyle(color: labelColor, fontSize: 15),
|
|
|
|
|
),
|
|
|
|
|
Text("${numberFormatter.format(e.value)} pc",
|
|
|
|
|
style:
|
|
|
|
|
TextStyle(color: labelColor, fontSize: 15))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList()),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final createBtn = InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
if (widget.onCreate != null) {
|
|
|
|
|
widget.onCreate!();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
|
height: 45,
|
|
|
|
|
width: 150,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
|
),
|
|
|
|
|
child: TextButton(
|
|
|
|
|
onPressed: null,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Flexible(
|
2024-02-09 17:10:19 +06:30
|
|
|
child: LocalText(context,
|
|
|
|
|
widget.isNew ? 'box.crete.carton' : 'box.update.btn',
|
2024-02-05 11:13:12 +06:30
|
|
|
color: Colors.white, fontSize: 15),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
|
const Icon(
|
|
|
|
|
MaterialCommunityIcons.check_circle_outline,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
final previousBtn = PreviousButton(onTap: () {
|
|
|
|
|
if (widget.onPrevious != null) {
|
|
|
|
|
widget.onPrevious!();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView(
|
2024-02-13 11:02:46 +06:30
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.only(left: 20, right: 20, top: 15, bottom: 20),
|
2024-02-05 11:13:12 +06:30
|
|
|
children: [
|
|
|
|
|
cartonType,
|
|
|
|
|
const SizedBox(height: 10),
|
2024-09-23 18:36:23 +06:30
|
|
|
cartonSizeBox,
|
|
|
|
|
const SizedBox(height: 10),
|
2024-02-05 11:13:12 +06:30
|
|
|
shipmentBox,
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
widget.cartons.isNotEmpty ? cartonsBox : const SizedBox(),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
cargosBox,
|
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 15, right: 15),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [previousBtn, createBtn],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 20)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|