update cargo type form from rate, update carton info and form

This commit is contained in:
tzw
2024-09-25 21:49:09 +06:30
parent 1be18c08a9
commit 02e079c514
51 changed files with 1407 additions and 643 deletions

View File

@@ -1,5 +1,6 @@
// ignore_for_file: deprecated_member_use
import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
@@ -14,6 +15,7 @@ import '../../domain/entities/cargo_type.dart';
import '../../domain/entities/carton.dart';
import '../../domain/entities/package.dart';
import '../../domain/entities/user.dart';
import '../carton_size/model/carton_size_model.dart';
import '../fcs_shipment/model/fcs_shipment_model.dart';
import '../main/util.dart';
import '../package/model/package_model.dart';
@@ -53,7 +55,7 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
double _width = 0;
double _height = 0;
String _selectedDeliveryType = delivery_caton;
String _selectedLastMile = delivery_caton;
String _billToValue = billToSender;
FcsShipment? _shipment;
@@ -78,20 +80,14 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
id: widget.carton.senderID);
_consignee = User(
id: widget.carton.userID,
name: widget.carton.userName,
fcsID: widget.carton.fcsID);
id: widget.carton.consigneeID,
name: widget.carton.consigneeName,
fcsID: widget.carton.consigneeFCSID);
_billToValue = widget.carton.billTo ?? billToSender;
_selectedDeliveryType = widget.carton.deliveryType ?? delivery_caton;
_cartonSizeType = widget.carton.cartonSizeType ?? customCarton;
_length = widget.carton.length;
_width = widget.carton.width;
_height = widget.carton.height;
_cargoTypes =
widget.carton.cargoTypes.where((e) => !e.isCutomDuty).toList();
_surchareItems =
widget.carton.cargoTypes.where((e) => e.isCutomDuty).toList();
_selectedLastMile = widget.carton.lastMile ?? delivery_caton;
_cargoTypes = widget.carton.cargoTypes;
_surchareItems = widget.carton.surchareItems;
var s = await context
.read<FcsShipmentModel>()
@@ -102,6 +98,30 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
.read<PackageModel>()
.getPackagesByIds(widget.carton.packageIDs);
// check carton size type
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
var sameLength =
cartonSizes.any((size) => size.length == widget.carton.length);
var sameWidth =
cartonSizes.any((size) => size.width == widget.carton.width);
var sameHeight =
cartonSizes.any((size) => size.height == widget.carton.height);
bool isStandartSize = sameLength && sameWidth && sameHeight;
if (isStandartSize) {
_cartonSizeType = standardCarton;
_standardSize = cartonSizes.firstWhere((size) =>
size.length == widget.carton.length &&
size.width == widget.carton.width &&
size.height == widget.carton.height);
} else if (widget.carton.length == 0 &&
widget.carton.width == 0 &&
widget.carton.height == 0) {
_cartonSizeType = packageCarton;
} else {
_cartonSizeType = customCarton;
}
if (mounted) {
setState(() {});
}
@@ -143,8 +163,16 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
},
),
backgroundColor: Colors.white,
title: LocalText(context, 'box.update_title',
color: primaryColor, fontSize: 20),
title: Column(
children: [
LocalText(context, 'box.update_title',
color: primaryColor, fontSize: 20),
Text(
widget.carton.cartonNumber ?? '',
style: TextStyle(color: primaryColor, fontSize: 14),
)
],
),
),
body: Column(
children: [
@@ -172,7 +200,7 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
if (step.stepType == StepType.SIZE) {
return Expanded(
child: CartonSizeWidget(
deliveryType: _selectedDeliveryType,
lastMile: _selectedLastMile,
billType: _billToValue,
sender: _sender!,
consignee: _consignee!,
@@ -188,7 +216,7 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
onContinue: (deliveryType, billType, shipment, cartonSizeType,
{standardSize, length, width, height}) {
setState(() {
_selectedDeliveryType = deliveryType;
_selectedLastMile = deliveryType;
_billToValue = billType;
_shipment = shipment;
_cartonSizeType = cartonSizeType;
@@ -256,7 +284,7 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
length: _length,
width: _width,
height: _height,
deliveryType: _selectedDeliveryType,
lastMile: _selectedLastMile,
shipment: _shipment!,
packages: _packages,
cargoTypes: _cargoTypes,
@@ -279,6 +307,40 @@ class _CartonPackageEditorState extends State<CartonPackageEditor> {
_isLoading = true;
});
try {
double length = 0;
double width = 0;
double height = 0;
if (_cartonSizeType == standardCarton) {
if (_standardSize != null) {
length = _standardSize!.length;
width = _standardSize!.width;
height = _standardSize!.height;
}
} else if (_cartonSizeType == customCarton) {
length = _length;
width = _width;
height = _height;
} else {
length = 0;
width = 0;
height = 0;
}
var carton = Carton(
cartonType: carton_from_packages,
billTo: _billToValue,
lastMile: _selectedLastMile,
fcsShipmentID: _shipment?.id,
length: length,
width: width,
height: height,
packages: _packages,
cargoTypes: _cargoTypes,
surchareItems: _surchareItems);
await context.read<CartonModel>().updateCarton(carton);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());