update carton form ,info and filter

This commit is contained in:
tzw
2024-10-01 18:15:53 +06:30
parent 02e079c514
commit 41fdc3ef43
13 changed files with 123 additions and 109 deletions

View File

@@ -15,7 +15,6 @@ class CartonDataProvider {
Future<Carton> createCarton(Carton carton) async {
var data = await requestAPI("/cartons", "POST",
payload: carton.toMap(), token: await getToken());
print("carton data:${data}");
return Carton.fromMap(data, data['id']);
}
@@ -32,7 +31,6 @@ class CartonDataProvider {
Future<Carton> createMixCarton(Carton carton) async {
var data = await requestAPI("/cartons", "POST",
payload: carton.toMapForMix(), token: await getToken());
print("carton mix data:${data}");
return Carton.fromMap(data, data['id']);
}

View File

@@ -44,7 +44,10 @@ class CargoType {
factory CargoType.fromMapForCargo(Map<String, dynamic> map, String id) {
return CargoType(
id: id, name: map['name'], weight: map['weight']?.toDouble() ?? 0);
id: id,
name: map['name'],
weight: map['weight']?.toDouble() ?? 0,
displayIndex: map['display_index'] ?? 0);
}
factory CargoType.fromMapForsurcharge(Map<String, dynamic> map, String id) {

View File

@@ -12,14 +12,14 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
);
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
Config(
flavor: Flavor.DEV,
color: Colors.blue,
apiURL:"http://192.168.100.150:9090",
apiURL: "http://192.168.100.150:9090",
// apiURL: "https://asia-northeast1-fcs-dev1.cloudfunctions.net/API13",
reportURL: "http://petrok.mokkon.com:7071",
reportProjectID: "fcs-dev",

View File

@@ -92,6 +92,8 @@ class _CartonInfoState extends State<CartonInfo> {
_mixCartons = await context
.read<CartonModel>()
.getCartonsByIds(_carton.cartonIDs);
_cargoTypes.sort((a, b) => a.name!.compareTo(b.name!));
_surchareItems.sort((a, b) => a.name!.compareTo(b.name!));
}
totalWeight =
@@ -156,13 +158,17 @@ class _CartonInfoState extends State<CartonInfo> {
);
final lastMileBox = DisplayText(
text: _carton.lastMile == delivery_caton ? 'Delivery' : 'Pick-up',
text: _carton.lastMile == delivery_caton
? 'Delivery'
: _carton.lastMile == pickup_carton
? 'Pick-up'
: '',
labelTextKey: "box.delivery_type",
);
final cartonSizeBox = DisplayText(
subText: Text("${boxDimension ?? 'No defined size'}"),
labelTextKey: "box.carton_size",
labelTextKey: "box.select_carton_size",
);
final senderBox = DisplayText(
@@ -192,6 +198,7 @@ class _CartonInfoState extends State<CartonInfo> {
final userRowBox = Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Row(
@@ -228,7 +235,7 @@ class _CartonInfoState extends State<CartonInfo> {
);
final cargosBox = Padding(
padding: const EdgeInsets.only(top: 15),
padding: const EdgeInsets.only(top: 20),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -237,10 +244,13 @@ class _CartonInfoState extends State<CartonInfo> {
color: Colors.black54,
fontSize: 16,
fontWeight: FontWeight.normal),
Padding(
_cargoTypes.isNotEmpty
? Padding(
padding: EdgeInsets.only(right: 50),
child: Text("${removeTrailingZeros(totalWeight)} lb",
textAlign: TextAlign.end,
style: TextStyle(color: Colors.black54, fontSize: 15)))
: const SizedBox()
],
),
Container(
@@ -262,38 +272,25 @@ class _CartonInfoState extends State<CartonInfo> {
TextStyle(color: Colors.black, fontSize: 15),
),
Text("${removeTrailingZeros(e.weight)} lb",
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black, fontSize: 15))
],
),
);
}).toList()),
const SizedBox(height: 10),
],
),
),
),
]),
);
final surchargeItemBox = Padding(
padding: const EdgeInsets.only(top: 15),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
LocalText(context, 'box.surcharge.item',
color: Colors.black54,
fontSize: 16,
fontWeight: FontWeight.normal),
Padding(
padding: EdgeInsets.only(right: 50),
child: Text("${removeTrailingZeros(totalSurchargeCount)} pcs",
style: TextStyle(color: Colors.black54, fontSize: 15)))
],
),
final surchargeItemBox =
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Container(
child: Padding(
padding: const EdgeInsets.only(right: 60),
padding: const EdgeInsets.only(right: 50),
child: Column(
children: [
Column(
@@ -306,24 +303,21 @@ class _CartonInfoState extends State<CartonInfo> {
children: [
Text(
e.name ?? "",
style:
TextStyle(color: Colors.black, fontSize: 15),
style: TextStyle(color: Colors.black, fontSize: 15),
),
Text(
"${removeTrailingZeros((e.qty).toDouble())} pc",
style: TextStyle(
color: Colors.black, fontSize: 15))
Text("${removeTrailingZeros((e.qty).toDouble())} pc",
textAlign: TextAlign.end,
style:
TextStyle(color: Colors.black, fontSize: 15))
],
),
);
}).toList()),
const SizedBox(height: 10),
],
),
),
),
]),
);
]);
final img = MultiImageFile(
enabled: false,
@@ -447,10 +441,13 @@ class _CartonInfoState extends State<CartonInfo> {
],
),
),
_cargoTypes.isEmpty ? const SizedBox() : cargosBox,
_surchareItems.isEmpty ? const SizedBox() : surchargeItemBox,
cargosBox,
surchargeItemBox,
const SizedBox(height: 10),
uploadImageBtn,
const SizedBox(height: 30),
_carton.photoUrls.isNotEmpty
? const SizedBox(height: 10)
: const SizedBox(),
img,
_carton.photoUrls.isNotEmpty
? const SizedBox(height: 40)

View File

@@ -89,15 +89,6 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
_cargoTypes = widget.carton.cargoTypes;
_surchareItems = widget.carton.surchareItems;
var s = await context
.read<FcsShipmentModel>()
.getFcsShipment(widget.carton.fcsShipmentID ?? "");
_shipment = s;
_packages = await context
.read<PackageModel>()
.getPackagesByIds(widget.carton.packageIDs);
// check carton size type
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
@@ -120,8 +111,20 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
_cartonSizeType = packageCarton;
} else {
_cartonSizeType = customCarton;
_length = widget.carton.length.toDouble();
_width = widget.carton.width.toDouble();
_height = widget.carton.height.toDouble();
}
var s = await context
.read<FcsShipmentModel>()
.getFcsShipment(widget.carton.fcsShipmentID ?? "");
_shipment = s;
_packages = await context
.read<PackageModel>()
.getPackagesByIds(widget.carton.packageIDs);
if (mounted) {
setState(() {});
}
@@ -328,7 +331,10 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
}
var carton = Carton(
id: widget.carton.id,
cartonType: carton_from_packages,
senderID: widget.carton.senderID,
consigneeID: widget.carton.consigneeID,
billTo: _billToValue,
lastMile: _selectedLastMile,
fcsShipmentID: _shipment?.id,

View File

@@ -61,8 +61,6 @@ class CartonSizeWidget extends StatefulWidget {
}
class _CartonSizeWidgetState extends State<CartonSizeWidget> {
// List<String> _deliveryTypes = [delivery_caton, pickup_carton];
FcsShipment? _shipment;
String _cartonSizeType = standardCarton;
@@ -85,7 +83,6 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
_selectedLastmile = widget.lastMile;
_billToValue = widget.billType;
_cartonSizeType = widget.cartonSizeType;
_lengthController.text =
widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0);
_widthController.text =
@@ -95,7 +92,6 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
_getStandardCartonSize();
_loadShipment();
if (mounted) {
setState(() {});
}

View File

@@ -191,7 +191,7 @@ class CartonSubmit extends StatelessWidget {
final cartonSizeBox = Padding(
padding: const EdgeInsets.only(top: 10),
child: SubmitTextWidget(
labelKey: 'box.carton_size',
labelKey: 'box.select_carton_size',
text: boxDimension ?? 'No defined size',
),
);

View File

@@ -82,6 +82,9 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
_cartonSizeType = packageCarton;
} else {
_cartonSizeType = customCarton;
_length = widget.carton.length.toDouble();
_width = widget.carton.width.toDouble();
_height = widget.carton.height.toDouble();
}
var s = await context
@@ -269,7 +272,7 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
width: width,
height: height,
cartons: _cartons);
await context.read<CartonModel>().updateCarton(carton);
await context.read<CartonModel>().updateMixCarton(carton);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -48,8 +48,8 @@ class MixCartonSubmit extends StatefulWidget {
class _MixCartonSubmitState extends State<MixCartonSubmit> {
final NumberFormat numberFormatter = NumberFormat("#,###");
Map<String?, double> _mapCargosByWeight = {};
Map<String?, double> _mapCargosByCustomDutyFee = {};
Map<String?, double> _mapCargos = {};
Map<String?, double> _mapSurchargeItems = {};
double totalWeight = 0;
@override
@@ -59,30 +59,37 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
}
_init() {
// get cargos by weight
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());
_cargoTypes.sort((a, b) => a.name!.compareTo(b.name!));
Map<String?, List<CargoType>> _cargosByWeight = groupCargos(_cargoTypes);
_cargosByWeight.forEach((key, value) {
double total = value.fold(0, (sum, item) => sum + item.weight);
_mapCargosByWeight[key] = total;
_mapCargos[key] = total;
});
totalWeight =
_mapCargosByWeight.entries.fold(0, (sum, value) => sum + value.value);
totalWeight = _mapCargos.entries.fold(0, (sum, value) => sum + value.value);
// get surcharge items
List<CargoType> _surchargeItems = [];
for (var c in widget.cartons) {
_surchargeItems.addAll(c.surchareItems);
}
_surchargeItems.sort((a, b) => a.name!.compareTo(b.name!));
// get cargos by custom duty fee
Map<String?, List<CargoType>> _cargosByCustomDutyFee =
groupCargos(_cargoTypes.where((e) => e.isCutomDuty).toList());
groupCargos(_surchargeItems);
_cargosByCustomDutyFee.forEach((key, value) {
double total = value.fold(0, (sum, item) => sum + item.qty);
_mapCargosByCustomDutyFee[key] = total;
_mapSurchargeItems[key] = total;
});
if (mounted) {
@@ -116,7 +123,7 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
final cartonSizeBox = Padding(
padding: const EdgeInsets.only(top: 10),
child: SubmitTextWidget(
labelKey: 'box.carton_size',
labelKey: 'box.select_carton_size',
text: boxDimension ?? 'No defined size',
),
);
@@ -195,7 +202,7 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _mapCargosByWeight.entries.map((e) {
children: _mapCargos.entries.map((e) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
@@ -216,7 +223,7 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
const SizedBox(height: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _mapCargosByCustomDutyFee.entries.map((e) {
children: _mapSurchargeItems.entries.map((e) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(

View File

@@ -117,13 +117,15 @@ class CartonModel extends BaseModel {
Query pageQuery = FirebaseFirestore.instance.collection(path);
if (filterByConsingee != null) {
col = col.where("user_id", isEqualTo: filterByConsingee!.id);
pageQuery = pageQuery.where("user_id", isEqualTo: filterByConsingee!.id);
col = col.where("consignee_user_id", isEqualTo: filterByConsingee!.id);
pageQuery = pageQuery.where("consignee_user_id",
isEqualTo: filterByConsingee!.id);
}
if (filterBySender != null) {
col = col.where("sender_id", isEqualTo: filterBySender!.id);
pageQuery = pageQuery.where("sender_id", isEqualTo: filterBySender!.id);
col = col.where("sender_user_id", isEqualTo: filterBySender!.id);
pageQuery =
pageQuery.where("sender_user_id", isEqualTo: filterBySender!.id);
}
if (filterByStatus != null) {
@@ -208,7 +210,7 @@ class CartonModel extends BaseModel {
}
Future<Carton> createMixCarton(Carton carton) {
return Services.instance.cartonService.createCarton(carton);
return Services.instance.cartonService.createMixCarton(carton);
}
Future<void> updateMixCarton(Carton carton) {

View File

@@ -91,8 +91,8 @@ class ConsigneeSelectionModel extends BaseModel {
Query query = FirebaseFirestore.instance
.collection(path)
.where("is_sys_admin", isEqualTo: false)
.where("is_deleted", isEqualTo: false)
.orderBy("message_time", descending: true);
.where("delete_time", isEqualTo: 0)
.orderBy("update_time", descending: true);
if (_lastDocument != null) {
query = query.startAfterDocument(_lastDocument!);

View File

@@ -93,8 +93,8 @@ class SenderSelectionModel extends BaseModel {
Query query = FirebaseFirestore.instance
.collection(path)
.where("is_sys_admin", isEqualTo: false)
.where("is_deleted", isEqualTo: false)
.orderBy("message_time", descending: true);
.where("delete_time", isEqualTo: 0)
.orderBy("update_time", descending: true);
if (_lastDocument != null) {
query = query.startAfterDocument(_lastDocument!);

View File

@@ -84,12 +84,12 @@ class _CargoEditorState extends State<CargoEditor> {
controller: _displayIndexController,
textInputType: TextInputType.number,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
return "Please insert display index";
}
return null;
},
// validator: (value) {
// if (value == null || value.isEmpty) {
// return "Please insert display index";
// }
// return null;
// },
);
final defaultBox = Padding(
@@ -189,7 +189,9 @@ class _CargoEditorState extends State<CargoEditor> {
CargoType _cargo = CargoType(
name: _descController.text,
rate: double.parse(_rateController.text),
displayIndex: int.parse(_displayIndexController.text),
displayIndex: _displayIndexController.text == ''
? 0
: int.parse(_displayIndexController.text),
isDefault: _isDefault);
if (_isNew) {
await shipmentRateModel.addCargoType(_cargo);