update carton info
This commit is contained in:
@@ -16,7 +16,7 @@ import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
import '../main/util.dart';
|
||||
import 'carton_editor_for_package.dart';
|
||||
import 'carton_info.dart';
|
||||
import 'mix_carton/mix_carton_editor.dart';
|
||||
import 'mix_carton/mix_carton_form.dart';
|
||||
import 'carton_row.dart';
|
||||
|
||||
class CartonEditor extends StatefulWidget {
|
||||
@@ -164,7 +164,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const MixCartonEditor()));
|
||||
builder: (context) => const MixCartonForm()));
|
||||
}
|
||||
},
|
||||
child: Icon(Icons.add_circle, color: primaryColor),
|
||||
@@ -307,7 +307,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
onTap: () async {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonInfo(box: c)),
|
||||
CupertinoPageRoute(builder: (context) => CartonInfo(carton: c)),
|
||||
);
|
||||
},
|
||||
child: CartonRow(box: c));
|
||||
|
||||
@@ -4,11 +4,8 @@ import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/carton_image_upload.dart';
|
||||
import 'package:fcs/pages/carton/carton_submit.dart';
|
||||
import 'package:fcs/pages/carton_size/model/carton_size_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
@@ -20,196 +17,149 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'carton_editor.dart';
|
||||
import '../widgets/local_button.dart';
|
||||
import 'mix_carton/mix_carton_editor.dart';
|
||||
import 'model/carton_model.dart';
|
||||
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
final NumberFormat numberFormatter = NumberFormat("#,###");
|
||||
|
||||
class CartonInfo extends StatefulWidget {
|
||||
final Package? package;
|
||||
final Carton box;
|
||||
final String? billToValue;
|
||||
final CartonSubmit? cartonSubmit;
|
||||
|
||||
CartonInfo(
|
||||
{required this.box, this.billToValue, this.package, this.cartonSubmit});
|
||||
final Carton carton;
|
||||
CartonInfo({required this.carton});
|
||||
|
||||
@override
|
||||
_CartonInfoState createState() => _CartonInfoState();
|
||||
}
|
||||
|
||||
class _CartonInfoState extends State<CartonInfo> {
|
||||
bool _isLoading = false;
|
||||
Carton? _box;
|
||||
|
||||
CartonSubmit? _cartonSubmit;
|
||||
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
final NumberFormat numberFormatter = NumberFormat("#,###");
|
||||
MultiImgController multiImgController = MultiImgController();
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
TextEditingController _cartonSizeController = new TextEditingController();
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
String? selectMixBoxType;
|
||||
|
||||
bool isMixBox = false;
|
||||
bool isFromShipments = false;
|
||||
bool isFromPackages = false;
|
||||
bool isSmallBag = false;
|
||||
bool isFromCartons = false;
|
||||
bool _isLoading = false;
|
||||
late Carton _carton;
|
||||
|
||||
bool isCutomDuty = false;
|
||||
final List<CargoType> cargoTypes = [];
|
||||
final List<CargoType> surchareItems = [];
|
||||
final List<Carton> cartons = [];
|
||||
List<CargoType> _cargoTypes = [];
|
||||
List<CargoType> _surchareItems = [];
|
||||
List<Carton> _mixCartons = [];
|
||||
List<Package> _packages = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_carton = widget.carton;
|
||||
_init();
|
||||
super.initState();
|
||||
_box = widget.box;
|
||||
_box?.billToValue = "Bill to sender";
|
||||
|
||||
//initPackage(widget.package!);
|
||||
//for shipment weight
|
||||
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
||||
.rate
|
||||
.volumetricRatio;
|
||||
_lengthController.addListener(_calShipmentWeight);
|
||||
_widthController.addListener(_calShipmentWeight);
|
||||
_heightController.addListener(_calShipmentWeight);
|
||||
multiImgController.setImageUrls = _box!.photos;
|
||||
// _updateBoxData();
|
||||
_loadPackages();
|
||||
_loadMixCartons();
|
||||
}
|
||||
|
||||
_updateBoxData() {
|
||||
_widthController.text = _box!.width.toString();
|
||||
_heightController.text = _box!.height.toString();
|
||||
_lengthController.text = _box!.length.toString();
|
||||
_cartonSizeController.text = _box!.cartonSizeName ?? "";
|
||||
isMixBox = _box!.cartonType == carton_mix_box;
|
||||
isFromShipments = _box!.cartonType == carton_from_shipments;
|
||||
isFromPackages = _box!.cartonType == carton_from_packages;
|
||||
isSmallBag = _box!.cartonType == carton_small_bag;
|
||||
isFromCartons = _box!.cartonType == carton_from_cartons;
|
||||
|
||||
selectMixBoxType = _box!.mixBoxType;
|
||||
getCartonSize();
|
||||
}
|
||||
|
||||
getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
if (c.length == _box!.length &&
|
||||
c.width == _box!.width &&
|
||||
c.height == _box!.height) {
|
||||
setState(() {
|
||||
_cartonSizeController.text = c.name ?? "";
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_loadPackages() async {
|
||||
if (!isFromPackages && !isSmallBag) return;
|
||||
|
||||
// if (_box!.cartonType == carton_from_packages && _box!.userID == null)
|
||||
// return;
|
||||
PackageModel packageModel =
|
||||
Provider.of<PackageModel>(context, listen: false);
|
||||
List<Package> packages =
|
||||
await packageModel.getPackages(_box!.userID ?? "", [
|
||||
package_processed_status,
|
||||
package_packed_status,
|
||||
package_shipped_status,
|
||||
package_delivered_status
|
||||
]);
|
||||
packages = packages.where((p) => _box!.packageIDs.contains(p.id)).toList();
|
||||
packages.forEach((p) {
|
||||
p.isChecked = true;
|
||||
});
|
||||
|
||||
setState(() {
|
||||
_box!.packages = packages;
|
||||
});
|
||||
}
|
||||
|
||||
_loadMixCartons() async {
|
||||
if (_box!.cartonType != carton_mix_box) return;
|
||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
List<Carton> catons = [];
|
||||
for (var id in _box!.mixCartonIDs) {
|
||||
Carton c = await cartonModel.getCarton(id);
|
||||
catons.add(c);
|
||||
_init() async {
|
||||
_carton.billTo = billToSender;
|
||||
_carton.cartonType = carton_from_packages;
|
||||
multiImgController.setImageUrls = _carton.photos;
|
||||
_cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList();
|
||||
_surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList();
|
||||
if (_carton.cartonType == carton_from_packages) {
|
||||
_packages = await context
|
||||
.read<PackageModel>()
|
||||
.getPackagesByIds(_carton.packageIDs);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_box!.mixCartons = catons;
|
||||
});
|
||||
}
|
||||
if (_carton.cartonType == carton_mix_carton) {
|
||||
_mixCartons = await context
|
||||
.read<CartonModel>()
|
||||
.getCartonsByIds(_carton.mixCartonIDs);
|
||||
}
|
||||
|
||||
_calShipmentWeight() {
|
||||
double l = double.tryParse(_lengthController.text) ?? 0;
|
||||
double w = double.tryParse(_widthController.text) ?? 0;
|
||||
double h = double.tryParse(_heightController.text) ?? 0;
|
||||
setState(() {
|
||||
shipmentWeight = l * w * h / volumetricRatio;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double totalWeight =
|
||||
_box!.cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
double totalPieces = surchareItems.fold(0, (sum, value) => sum + value.qty);
|
||||
_carton.cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
double totalSurchargeCount =
|
||||
_surchareItems.fold(0, (sum, value) => sum + value.qty);
|
||||
|
||||
final cartonTypeBox = DisplayText(
|
||||
text: _box!.cartonNumber,
|
||||
text: _carton.cartonNumber,
|
||||
labelTextKey: "box.number",
|
||||
);
|
||||
final cartonQrBox = DisplayText(
|
||||
iconData: AntDesign.qrcode,
|
||||
);
|
||||
|
||||
final cartonQrBox = DisplayText(iconData: AntDesign.qrcode);
|
||||
|
||||
final shipmentBox = DisplayText(
|
||||
text: _box!.fcsShipmentNumber,
|
||||
text: _carton.fcsShipmentNumber,
|
||||
labelTextKey: "box.fcs_shipment_num",
|
||||
);
|
||||
|
||||
final deliveryBox = DisplayText(
|
||||
text: "Delivery Carton",
|
||||
labelTextKey: "box.delivery_type",
|
||||
);
|
||||
|
||||
final customerNameBox = DisplayText(
|
||||
text: _box!.userName == null ? "" : _box!.userName,
|
||||
subText: Text(_box!.fcsID ?? "", style: textStyle),
|
||||
final senderBox = DisplayText(
|
||||
text: _carton.userName == null ? "" : _carton.userName,
|
||||
subText: Text(_carton.fcsID ?? "", style: textStyle),
|
||||
labelTextKey: "box.name",
|
||||
);
|
||||
|
||||
final consigneeNameBox = DisplayText(
|
||||
text: _box!.senderName != null ? _box!.senderName : "",
|
||||
subText: Text(_box!.senderFCSID ?? "", style: textStyle),
|
||||
text: _carton.senderName != null ? _carton.senderName : "",
|
||||
subText: Text(_carton.senderFCSID ?? "", style: textStyle),
|
||||
labelTextKey: "processing.consignee.name",
|
||||
);
|
||||
|
||||
final packageBox = DisplayText(
|
||||
labelTextKey: "box.package",
|
||||
);
|
||||
final cartonBox = DisplayText(
|
||||
labelTextKey: "box.shipment.boxes",
|
||||
final billWidget = Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 0, top: 15),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Ionicons.document_text_outline,
|
||||
color: primaryColor, size: 20),
|
||||
Text("Bill to",
|
||||
style: TextStyle(color: primaryColor, fontSize: 15))
|
||||
],
|
||||
)));
|
||||
|
||||
final userRowBox = Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
senderBox,
|
||||
],
|
||||
),
|
||||
),
|
||||
_carton.billTo == billToSender ? billWidget : const SizedBox()
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
consigneeNameBox,
|
||||
],
|
||||
),
|
||||
),
|
||||
_carton.billTo == billToConsignee ? billWidget : const SizedBox()
|
||||
],
|
||||
))
|
||||
],
|
||||
);
|
||||
|
||||
final cargosBox = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -232,7 +182,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _box!.cargoTypes.map((e) {
|
||||
children: _cargoTypes.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
@@ -258,7 +208,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
]),
|
||||
);
|
||||
final surchargeItemBox = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -269,7 +219,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
fontWeight: FontWeight.normal),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: 100),
|
||||
child: Text("${removeTrailingZeros(totalPieces)} pcs",
|
||||
child: Text("${removeTrailingZeros(totalSurchargeCount)} pcs",
|
||||
style: TextStyle(color: Colors.black54, fontSize: 15)))
|
||||
],
|
||||
),
|
||||
@@ -281,7 +231,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: surchareItems.map((e) {
|
||||
children: _surchareItems.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
@@ -303,7 +253,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
const SizedBox(height: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: surchareItems.map((e) {
|
||||
children: _surchareItems.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
@@ -333,18 +283,37 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
title: "Receipt File",
|
||||
);
|
||||
|
||||
final billWidget = Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 0, top: 15),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Ionicons.document_text_outline,
|
||||
color: primaryColor, size: 20),
|
||||
Text("Bill to",
|
||||
style: TextStyle(color: primaryColor, fontSize: 15))
|
||||
],
|
||||
)));
|
||||
final uploadImageBtn = Padding(
|
||||
padding: EdgeInsets.only(left: 200.0, right: 8.0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xff272262),
|
||||
elevation: 3,
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
|
||||
minimumSize: Size(10, 35),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CartonImageUpload(box: _carton)),
|
||||
);
|
||||
},
|
||||
child: const Text('Upload Images'),
|
||||
),
|
||||
);
|
||||
|
||||
final deleteBtn = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||
child: LocalButton(
|
||||
color: dangerColor,
|
||||
textKey: "box.delete.btn",
|
||||
callBack: () {
|
||||
_delete();
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -371,146 +340,92 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(
|
||||
child: shipmentBox,
|
||||
),
|
||||
Flexible(
|
||||
child: deliveryBox,
|
||||
),
|
||||
Flexible(child: shipmentBox),
|
||||
Flexible(child: deliveryBox),
|
||||
],
|
||||
),
|
||||
// isMixBox
|
||||
// ?
|
||||
// displayMixBox:Container(),
|
||||
|
||||
isMixBox
|
||||
? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
//crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
customerNameBox,
|
||||
],
|
||||
),
|
||||
),
|
||||
_box?.billToValue == billToSender
|
||||
? billWidget
|
||||
: const SizedBox(
|
||||
height: 300.0,
|
||||
)
|
||||
],
|
||||
userRowBox,
|
||||
_packages.isEmpty
|
||||
? const SizedBox()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
LocalText(context, "box.package",
|
||||
color: Colors.black54, fontSize: 15),
|
||||
const SizedBox(height: 5),
|
||||
Column(
|
||||
children: getPackageList(_packages),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
consigneeNameBox,
|
||||
],
|
||||
),
|
||||
),
|
||||
_cartonSubmit?.billToValue == billToSender
|
||||
? billWidget
|
||||
: const SizedBox()
|
||||
],
|
||||
),
|
||||
))
|
||||
],
|
||||
)
|
||||
// ,
|
||||
|
||||
// Row(
|
||||
// children: getPackageList(_box!.packages),
|
||||
// ),
|
||||
// ])
|
||||
: Container(),
|
||||
isMixBox
|
||||
? Column(
|
||||
children: [
|
||||
packageBox,
|
||||
Row(
|
||||
children: getPackageList(_box!.packages),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
cartonBox,
|
||||
Row(
|
||||
children: getCartonList(_box!.mixCartons),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
isCutomDuty ? surchargeItemBox : cargosBox,
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 200.0, right: 8.0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xff272262),
|
||||
elevation: 3,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5.0)),
|
||||
minimumSize: Size(10, 35), //////// HERE
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
CartonImageUpload(box: _box)),
|
||||
);
|
||||
},
|
||||
child: const Text('Upload Images'),
|
||||
),
|
||||
),
|
||||
_mixCartons.isEmpty
|
||||
? const SizedBox()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
LocalText(context, "box.shipment.boxes",
|
||||
color: Colors.black54, fontSize: 15),
|
||||
const SizedBox(height: 5),
|
||||
Column(children: getCartonList(_mixCartons)),
|
||||
],
|
||||
),
|
||||
),
|
||||
_cargoTypes.isEmpty ? const SizedBox() : cargosBox,
|
||||
_surchareItems.isEmpty ? const SizedBox() : surchargeItemBox,
|
||||
uploadImageBtn,
|
||||
img,
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xffff0606),
|
||||
elevation: 3,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5.0)),
|
||||
minimumSize: Size(300, 45), //////// HERE
|
||||
),
|
||||
onPressed: () {},
|
||||
child: const Text('Delete Carton',
|
||||
style: TextStyle(fontSize: 20)),
|
||||
),
|
||||
),
|
||||
deleteBtn
|
||||
]))));
|
||||
}
|
||||
|
||||
List<Widget> getPackageList(List<Package> list) {
|
||||
return list.map((p) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: Container(
|
||||
child: Row(children: <Widget>[new Text(p.trackingID ?? "")]),
|
||||
));
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> getCartonList(List<Carton> list) {
|
||||
return list.map((c) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: Container(
|
||||
child: Row(children: <Widget>[new Text(c.cartonNumber ?? '')]),
|
||||
));
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_gotoEditor() async {
|
||||
bool? updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor(carton: _box)),
|
||||
);
|
||||
if (updated ?? false) {
|
||||
// var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
// var c = await cartonModel.getCarton(widget.box.id ?? "");
|
||||
// setState(() {
|
||||
// _box = c;
|
||||
// _loadPackages();
|
||||
// _loadMixCartons();
|
||||
// _updateBoxData();
|
||||
// });
|
||||
if (_carton.cartonType == carton_mix_carton) {
|
||||
bool? updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => MixCartonEditor(carton: _carton)),
|
||||
);
|
||||
}
|
||||
// bool? updated = await Navigator.push<bool>(
|
||||
// context,
|
||||
// CupertinoPageRoute(
|
||||
// builder: (context) => MixCartonEditor(carton: _carton)),
|
||||
// );
|
||||
// if (updated ?? false) {
|
||||
// // var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
// // var c = await cartonModel.getCarton(widget.box.id ?? "");
|
||||
// // setState(() {
|
||||
// // _box = c;
|
||||
// // _loadPackages();
|
||||
// // _loadMixCartons();
|
||||
// // _updateBoxData();
|
||||
// // });
|
||||
// }
|
||||
}
|
||||
|
||||
_delete() {
|
||||
@@ -524,9 +439,9 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
await cartonModel.deleteCarton(widget.box);
|
||||
Navigator.pop(context, true);
|
||||
// var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
// await cartonModel.deleteCarton(widget.carton);
|
||||
// Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -535,40 +450,4 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> getPackageList(List<Package> _p) {
|
||||
return _p.map((p) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: Container(
|
||||
//padding:
|
||||
//EdgeInsets.only(top: 0.0),
|
||||
child: Row(children: <Widget>[new Text(p.trackingID ?? '')]),
|
||||
));
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> getCartonList(List<Carton> _c) {
|
||||
return _c.map((c) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: Container(
|
||||
//padding:
|
||||
//EdgeInsets.only(top: 0.0),
|
||||
child: Row(children: <Widget>[new Text(c.cartonNumber ?? '')]),
|
||||
));
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> getCargoList(List<CargoType> _c) {
|
||||
return _c.map((c) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
child: Container(
|
||||
//padding:
|
||||
//EdgeInsets.only(top: 0.0),
|
||||
child: Row(children: <Widget>[new Text(c.name ?? '')]),
|
||||
));
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class _CartonListState extends State<CartonList> {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CartonInfo(box: c)),
|
||||
builder: (context) => CartonInfo(carton: c)),
|
||||
);
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -19,7 +19,7 @@ class CartonListRow extends StatelessWidget {
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonInfo(box: box)),
|
||||
CupertinoPageRoute(builder: (context) => CartonInfo(carton: box)),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
|
||||
@@ -21,9 +21,8 @@ import 'mix_carton_submit.dart';
|
||||
import 'type_widget.dart';
|
||||
|
||||
class MixCartonEditor extends StatefulWidget {
|
||||
const MixCartonEditor({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
final Carton carton;
|
||||
const MixCartonEditor({Key? key, required this.carton}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MixCartonEditor> createState() => _MixCartonEditorState();
|
||||
|
||||
199
lib/pages/carton/mix_carton/mix_carton_form.dart
Normal file
199
lib/pages/carton/mix_carton/mix_carton_form.dart
Normal file
@@ -0,0 +1,199 @@
|
||||
// ignore_for_file: deprecated_member_use
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../domain/constants.dart';
|
||||
import '../../../domain/entities/carton.dart';
|
||||
import '../../../domain/entities/carton_size.dart';
|
||||
import '../../../domain/entities/fcs_shipment.dart';
|
||||
import '../../../domain/vo/local_step.dart';
|
||||
import '../../../helpers/theme.dart';
|
||||
import '../../main/util.dart';
|
||||
import '../../widgets/local_text.dart';
|
||||
import '../../widgets/progress.dart';
|
||||
import '../../widgets/step_widget.dart';
|
||||
import '../model/carton_selection_model.dart';
|
||||
import 'carton_selection_widget.dart';
|
||||
import 'mix_carton_submit.dart';
|
||||
import 'type_widget.dart';
|
||||
|
||||
class MixCartonForm extends StatefulWidget {
|
||||
const MixCartonForm({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MixCartonForm> createState() => _MixCartonFormState();
|
||||
}
|
||||
|
||||
class _MixCartonFormState extends State<MixCartonForm> {
|
||||
var dateFormatter = DateFormat('dd MMM yyyy');
|
||||
final NumberFormat numberFormatter = NumberFormat("#,###");
|
||||
List<LocalStep> steps = [
|
||||
LocalStep(lable: 'Type', stepType: StepType.TYPE),
|
||||
LocalStep(lable: 'Cartons', stepType: StepType.CARTONS),
|
||||
LocalStep(lable: 'Submit', stepType: StepType.SUBMIT)
|
||||
];
|
||||
List<Carton> _cartons = [];
|
||||
|
||||
int currentStep = 0;
|
||||
double _length = 0;
|
||||
double _width = 0;
|
||||
double _height = 0;
|
||||
|
||||
FcsShipment? _shipment;
|
||||
String _cartonSizeType = standardCarton;
|
||||
CartonSize? _standardSize;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
context.read<CartonSelectionModel>().clearSelection();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
if (currentStep == 0) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
if (currentStep > 0) {
|
||||
setState(() {
|
||||
currentStep -= 1;
|
||||
});
|
||||
}
|
||||
|
||||
return Future.value(false);
|
||||
},
|
||||
child: LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
leading: IconButton(
|
||||
icon: const Icon(CupertinoIcons.back,
|
||||
color: primaryColor, size: 25),
|
||||
onPressed: () {
|
||||
if (currentStep == 0) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
if (currentStep > 0) {
|
||||
setState(() {
|
||||
currentStep -= 1;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(context, 'boxes.new',
|
||||
color: primaryColor, fontSize: 20),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
StepperWidget(
|
||||
labels: steps.map((e) => e.lable).toList(),
|
||||
currentStep: currentStep,
|
||||
eachStepWidth: MediaQuery.of(context).size.width / 3,
|
||||
onChange: (index) {
|
||||
if (index > currentStep) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
currentStep = index;
|
||||
});
|
||||
},
|
||||
),
|
||||
getContent(currentStep)
|
||||
],
|
||||
))),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getContent(int index) {
|
||||
var step = steps[index];
|
||||
if (step.stepType == StepType.TYPE) {
|
||||
return Expanded(
|
||||
child: TypeWidget(
|
||||
shipment: _shipment,
|
||||
cartonSizeType: _cartonSizeType,
|
||||
standardSize: _standardSize,
|
||||
length: _length,
|
||||
width: _width,
|
||||
height: _height,
|
||||
onPrevious: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onContinue: (shipment, cartonSizeType,
|
||||
{standardSize, length, width, height}) {
|
||||
setState(() {
|
||||
_shipment = shipment;
|
||||
_cartonSizeType = cartonSizeType;
|
||||
_standardSize = standardSize;
|
||||
_length = length ?? 0;
|
||||
_width = width ?? 0;
|
||||
_height = height ?? 0;
|
||||
currentStep += 1;
|
||||
});
|
||||
},
|
||||
));
|
||||
} else if (step.stepType == StepType.CARTONS) {
|
||||
return Expanded(
|
||||
child: CartonSelectionWidget(
|
||||
shipment: _shipment!,
|
||||
cartons: _cartons,
|
||||
onContinue: (cartons) {
|
||||
setState(() {
|
||||
_cartons = List.from(cartons);
|
||||
currentStep += 1;
|
||||
});
|
||||
},
|
||||
onPrevious: (cartons) {
|
||||
setState(() {
|
||||
_cartons = List.from(cartons);
|
||||
currentStep -= 1;
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Expanded(
|
||||
child: MixCartonSubmit(
|
||||
cartonSizeType: _cartonSizeType,
|
||||
standardSize: _standardSize,
|
||||
length: _length,
|
||||
width: _width,
|
||||
height: _height,
|
||||
shipment: _shipment!,
|
||||
cartons: _cartons,
|
||||
onCreate: () {
|
||||
_create();
|
||||
},
|
||||
onPrevious: () {
|
||||
setState(() {
|
||||
currentStep -= 1;
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_create() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,7 @@ class CartonModel extends BaseModel {
|
||||
return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList();
|
||||
}
|
||||
|
||||
Future<Carton> getCarton(String id) async {
|
||||
Future<Carton?> getCarton(String id) async {
|
||||
String path = "/$cartons_collection";
|
||||
var snap = await FirebaseFirestore.instance.collection(path).doc(id).get();
|
||||
return Carton.fromMap(snap.data() as Map<String, dynamic>, snap.id);
|
||||
@@ -226,4 +226,19 @@ class CartonModel extends BaseModel {
|
||||
Future<List<Carton>> searchCarton(String term) async {
|
||||
return Services.instance.cartonService.searchCarton(term);
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartonsByIds(List<String> cartonIds) async {
|
||||
List<Carton> cartons = [];
|
||||
try {
|
||||
for (var e in cartonIds) {
|
||||
Carton? c = await getCarton(e);
|
||||
if (c != null) {
|
||||
cartons.add(c);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
return cartons;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,17 +25,17 @@ import 'cargo_type_addtion.dart';
|
||||
import 'carton_cargo_table.dart';
|
||||
import 'model/carton_model.dart';
|
||||
|
||||
class PackageCartonEditor extends StatefulWidget {
|
||||
class PackageCartonForm extends StatefulWidget {
|
||||
final Carton? carton;
|
||||
final bool? isNew;
|
||||
final User? consignee;
|
||||
PackageCartonEditor({this.carton, this.isNew, this.consignee});
|
||||
PackageCartonForm({this.carton, this.isNew, this.consignee});
|
||||
|
||||
@override
|
||||
_PackageCartonEditorState createState() => _PackageCartonEditorState();
|
||||
_PackageCartonFormState createState() => _PackageCartonFormState();
|
||||
}
|
||||
|
||||
class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
class _PackageCartonFormState extends State<PackageCartonForm> {
|
||||
TextEditingController _lengthCtl = new TextEditingController();
|
||||
TextEditingController _widthCtl = new TextEditingController();
|
||||
TextEditingController _heightCtl = new TextEditingController();
|
||||
@@ -295,7 +295,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id);
|
||||
_c.weight = cargo.weight;
|
||||
_c.qty = cargo.qty;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_creatCarton() async {
|
||||
@@ -349,8 +349,10 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
Navigator.pop(context, _c);
|
||||
} else {
|
||||
await cartonModel.updateCarton(carton);
|
||||
Carton _c = await cartonModel.getCarton(_carton!.id!);
|
||||
Navigator.pop(context, _c);
|
||||
Carton? _c = await cartonModel.getCarton(_carton!.id!);
|
||||
if (_c != null) {
|
||||
Navigator.pop(context, _c);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -49,8 +49,10 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
List<Carton> cartons = [];
|
||||
for (var c in _invoice?.cartons ?? []) {
|
||||
var _carton = await cartonModel.getCarton(c.id);
|
||||
_carton.isChecked = true;
|
||||
cartons.add(_carton);
|
||||
if (_carton != null) {
|
||||
_carton.isChecked = true;
|
||||
cartons.add(_carton);
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
_invoice!.cartons = cartons;
|
||||
|
||||
@@ -359,4 +359,19 @@ class PackageModel extends BaseModel {
|
||||
Future<void> packageReturn(Package package) {
|
||||
return Services.instance.packageService.packageReturn(package.id!);
|
||||
}
|
||||
|
||||
Future<List<Package>> getPackagesByIds(List<String> packageIds) async {
|
||||
List<Package> packages = [];
|
||||
try {
|
||||
for (var e in packageIds) {
|
||||
Package? p = await getPackage(e);
|
||||
if (p != null) {
|
||||
packages.add(p);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user