Files
fcs/lib/pages/carton/carton_info.dart

504 lines
17 KiB
Dart
Raw Normal View History

2024-09-22 16:49:59 +06:30
import 'package:fcs/constants.dart';
2024-02-05 17:28:53 +06:30
import 'package:fcs/domain/entities/cargo_type.dart';
2020-10-20 06:19:10 +06:30
import 'package:fcs/domain/entities/carton.dart';
2020-10-14 16:53:16 +06:30
import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/helpers/theme.dart';
2024-02-09 13:49:18 +06:30
import 'package:fcs/pages/carton/carton_image_upload_editor.dart';
2020-10-14 16:53:16 +06:30
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/package/model/package_model.dart';
import 'package:fcs/pages/widgets/display_text.dart';
2024-01-25 17:40:35 +06:30
import 'package:fcs/pages/widgets/local_app_bar.dart';
2020-10-14 16:53:16 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
2024-02-05 17:28:53 +06:30
import 'package:fcs/pages/widgets/multi_img_controller.dart';
import 'package:fcs/pages/widgets/multi_img_file.dart';
2020-10-14 16:53:16 +06:30
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
2021-09-10 12:00:08 +06:30
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2020-10-14 16:53:16 +06:30
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
2024-02-09 17:40:51 +06:30
import '../../domain/entities/carton_size.dart';
2024-02-09 13:35:32 +06:30
import '../widgets/local_button.dart';
2024-02-09 13:49:18 +06:30
import 'carton_package_editor.dart';
2024-02-09 13:35:32 +06:30
import 'mix_carton/mix_carton_editor.dart';
2020-10-18 02:38:46 +06:30
import 'model/carton_model.dart';
2024-02-26 17:26:25 +06:30
import 'print_qr_code_page.dart';
2020-10-14 16:53:16 +06:30
2020-10-19 05:13:49 +06:30
class CartonInfo extends StatefulWidget {
2024-02-09 13:35:32 +06:30
final Carton carton;
CartonInfo({required this.carton});
2020-10-14 16:53:16 +06:30
@override
2020-10-19 05:13:49 +06:30
_CartonInfoState createState() => _CartonInfoState();
2020-10-14 16:53:16 +06:30
}
2020-10-19 05:13:49 +06:30
class _CartonInfoState extends State<CartonInfo> {
2024-02-09 13:35:32 +06:30
final DateFormat dateFormat = DateFormat("d MMM yyyy");
final NumberFormat numberFormatter = NumberFormat("#,###");
MultiImgController _multiImgController = MultiImgController();
2024-02-09 13:35:32 +06:30
bool _isLoading = false;
late Carton _carton;
List<CargoType> _cargoTypes = [];
List<CargoType> _surchareItems = [];
List<Carton> _mixCartons = [];
List<Package> _packages = [];
2024-02-09 17:40:51 +06:30
double totalWeight = 0.0;
double totalSurchargeCount = 0.0;
CartonSize? standardSize;
2024-02-08 17:09:01 +06:30
2020-10-14 16:53:16 +06:30
@override
void initState() {
2024-02-09 13:35:32 +06:30
_carton = widget.carton;
_init();
2020-10-14 16:53:16 +06:30
super.initState();
}
2024-02-09 13:35:32 +06:30
_init() async {
2024-02-13 11:02:46 +06:30
try {
_isLoading = true;
_carton.cartonType = carton_from_packages;
2024-02-13 11:02:46 +06:30
_carton.billTo = billToConsignee;
_carton.cartonSizeType = customCarton;
_multiImgController.setImageUrls = _carton.photoUrls;
2024-02-13 11:02:46 +06:30
_cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList();
_surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList();
if (_carton.cartonType == carton_from_packages) {
_carton.deliveryType = delivery_caton;
_packages = await context
.read<PackageModel>()
.getPackagesByIds(_carton.packageIDs);
}
2021-01-10 15:56:27 +06:30
2024-02-13 11:02:46 +06:30
if (_carton.cartonType == carton_mix_carton) {
_mixCartons = await context
.read<CartonModel>()
.getCartonsByIds(_carton.mixCartonIDs);
}
2020-10-14 16:53:16 +06:30
2024-02-13 11:02:46 +06:30
if (mounted) {
setState(() {});
}
2024-02-13 11:02:46 +06:30
totalWeight =
_carton.cargoTypes.fold(0, (sum, value) => sum + value.weight);
totalSurchargeCount =
_surchareItems.fold(0, (sum, value) => sum + value.qty);
} finally {
_isLoading = false;
2024-02-09 13:35:32 +06:30
}
2020-10-14 16:53:16 +06:30
}
@override
Widget build(BuildContext context) {
2024-09-23 18:37:21 +06:30
String? boxDimension = _carton.cartonSizeType == standardCarton
2024-02-09 17:40:51 +06:30
? "${standardSize?.name} - ${standardSize?.length.toInt()}”x${standardSize?.width.toInt()}”x${standardSize?.height.toInt()}"
: _carton.cartonSizeType == customCarton
? "${_carton.length.toInt()}”x${_carton.width.toInt()}”x${_carton.height.toInt()}"
: null;
final cartonTypeBox = DisplayText(
2024-02-09 13:35:32 +06:30
text: _carton.cartonNumber,
labelTextKey: "box.number",
);
2024-02-09 13:35:32 +06:30
2024-02-26 17:26:25 +06:30
final cartonQrBox = IconButton(
onPressed: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => PrintQrCodePage(carton: _carton)),
);
},
icon: Icon(AntDesign.qrcode, color: Colors.black));
2024-02-09 17:09:05 +06:30
final cartonSubTypeBox = DisplayText(
2024-02-09 17:40:51 +06:30
text: _carton.cartonType == carton_from_packages
2024-09-23 18:37:21 +06:30
? "For packages"
2024-02-09 17:40:51 +06:30
: "Mix carton",
2024-02-09 17:09:05 +06:30
labelTextKey: "box.carton.type",
);
2024-02-09 13:35:32 +06:30
2024-09-23 18:37:21 +06:30
final billInfoBox = DisplayText(
text: _carton.billTo == billToSender
? "Sender"
: _carton.billTo == billToConsignee
? "Consignee"
: null,
labelTextKey: "box.bill_to",
);
2020-10-14 16:53:16 +06:30
final shipmentBox = DisplayText(
2024-02-09 13:35:32 +06:30
text: _carton.fcsShipmentNumber,
2020-10-14 16:53:16 +06:30
labelTextKey: "box.fcs_shipment_num",
);
2024-02-09 13:35:32 +06:30
final deliveryBox = DisplayText(
2024-02-09 17:40:51 +06:30
text: _carton.deliveryType,
labelTextKey: "box.delivery_type",
2020-10-14 16:53:16 +06:30
);
2024-09-23 18:37:21 +06:30
final cartonSizeBox = DisplayText(
subText: boxDimension == null ? null : Text("$boxDimension"),
labelTextKey: "box.carton_size",
);
2024-02-09 13:35:32 +06:30
final senderBox = DisplayText(
2024-02-09 17:40:51 +06:30
text: _carton.senderName == null ? "" : _carton.senderName,
subText: Text(_carton.senderFCSID ?? "", style: textStyle),
2020-10-14 16:53:16 +06:30
labelTextKey: "box.name",
);
2021-01-09 19:11:47 +06:30
final consigneeNameBox = DisplayText(
2024-02-09 17:09:05 +06:30
text: _carton.userName != null ? _carton.userName : "",
2024-02-09 17:40:51 +06:30
subText: Text(_carton.fcsID ?? "", style: textStyle),
2021-01-09 19:11:47 +06:30
labelTextKey: "processing.consignee.name",
2020-10-14 16:53:16 +06:30
);
2024-09-23 18:37:21 +06:30
// 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))
// ],
// )));
2024-02-09 13:35:32 +06:30
final userRowBox = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
senderBox,
],
),
),
2024-09-23 18:37:21 +06:30
// _carton.billTo == billToSender ? billWidget : const SizedBox()
2024-02-09 13:35:32 +06:30
],
),
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
consigneeNameBox,
],
),
),
2024-09-23 18:37:21 +06:30
// _carton.billTo == billToConsignee ? billWidget : const SizedBox()
2024-02-09 13:35:32 +06:30
],
))
],
2024-02-09 12:16:18 +06:30
);
2024-02-09 13:35:32 +06:30
final cargosBox = Padding(
2024-02-09 13:35:32 +06:30
padding: const EdgeInsets.only(top: 15),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
LocalText(context, 'box.cargo.type',
color: Colors.black54,
fontSize: 16,
fontWeight: FontWeight.normal),
Padding(
2024-02-13 11:02:46 +06:30
padding: EdgeInsets.only(right: 50),
child: Text("${removeTrailingZeros(totalWeight)} lb",
style: TextStyle(color: Colors.black54, fontSize: 15)))
],
),
Container(
child: Padding(
2024-02-13 11:02:46 +06:30
padding: const EdgeInsets.only(right: 50),
child: Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
2024-02-09 13:35:32 +06:30
children: _cargoTypes.map((e) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
e.name ?? "",
style:
TextStyle(color: Colors.black, fontSize: 15),
),
Text("${removeTrailingZeros(e.weight)} lb",
style: TextStyle(
color: Colors.black, fontSize: 15))
],
),
);
}).toList()),
const SizedBox(height: 10),
],
),
),
),
]),
);
final surchargeItemBox = Padding(
2024-02-09 13:35:32 +06:30
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(
2024-02-13 11:02:46 +06:30
padding: EdgeInsets.only(right: 50),
2024-02-09 13:35:32 +06:30
child: Text("${removeTrailingZeros(totalSurchargeCount)} pcs",
style: TextStyle(color: Colors.black54, fontSize: 15)))
],
),
Container(
child: Padding(
2024-02-13 17:07:22 +06:30
padding: const EdgeInsets.only(right: 60),
child: Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
2024-02-09 13:35:32 +06:30
children: _surchareItems.map((e) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
e.name ?? "",
style:
TextStyle(color: Colors.black, fontSize: 15),
),
Text(
"${removeTrailingZeros((e.qty).toDouble())} pc",
style: TextStyle(
color: Colors.black, fontSize: 15))
],
),
);
}).toList()),
const SizedBox(height: 10),
],
),
),
),
]),
);
final img = MultiImageFile(
2024-02-05 17:28:53 +06:30
enabled: false,
controller: _multiImgController,
2024-02-05 17:28:53 +06:30
title: "Receipt File",
);
2024-02-09 12:21:49 +06:30
2024-02-09 13:35:32 +06:30
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: () async {
bool? updated = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
CartonImageUploadEditor(carton: _carton)),
);
if (updated ?? false) {
Carton? c = await context
.read<CartonModel>()
.getCarton(widget.carton.id ?? "");
if (c == null) return;
_carton = c;
_init();
}
},
child: LocalText(context, "box.imageupload.title",
color: Colors.white, fontSize: 14)),
2024-02-09 13:35:32 +06:30
);
2024-02-26 17:26:25 +06:30
final deleteBtn = Padding(
2024-02-09 13:35:32 +06:30
padding: const EdgeInsets.symmetric(horizontal: 30),
child: LocalButton(
color: dangerColor,
textKey: "box.delete.btn",
callBack: () {
_delete();
},
),
);
2020-12-11 17:34:56 +06:30
2020-10-14 16:53:16 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
2024-02-09 12:21:49 +06:30
labelKey: "box.info.title",
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor,
actions: <Widget>[
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _gotoEditor),
]),
body: Container(
padding: const EdgeInsets.only(left: 20, right: 20),
child: ListView(children: <Widget>[
Row(children: [
2024-09-23 18:37:21 +06:30
Flexible(child: cartonTypeBox,flex: 1),
Flexible(
child: cartonQrBox,
),
2024-09-23 18:37:21 +06:30
]),
2024-02-09 17:40:51 +06:30
Row(
children: [
Flexible(child: cartonSubTypeBox),
],
),
2024-09-23 18:37:21 +06:30
_mixCartons.isEmpty ? userRowBox : const SizedBox(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2024-09-23 18:37:21 +06:30
Flexible(child: billInfoBox),
2024-02-09 13:35:32 +06:30
Flexible(child: shipmentBox),
2024-09-23 18:37:21 +06:30
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2024-02-09 17:09:05 +06:30
_mixCartons.isEmpty
2024-02-09 17:40:51 +06:30
? Flexible(child: deliveryBox)
: const SizedBox(),
2024-09-23 18:37:21 +06:30
Flexible(child: cartonSizeBox),
],
),
2024-02-09 13:35:32 +06:30
_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),
2024-02-09 12:16:18 +06:30
),
2024-02-09 13:35:32 +06:30
],
),
2024-02-09 12:16:18 +06:30
),
2024-02-09 13:35:32 +06:30
_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,
const SizedBox(height: 30),
img,
const SizedBox(height: 40),
2024-02-26 17:26:25 +06:30
deleteBtn,
const SizedBox(height: 20)
]))));
2024-02-06 17:42:12 +06:30
}
2020-12-11 17:34:56 +06:30
2024-02-09 13:35:32 +06:30
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();
}
2020-10-14 16:53:16 +06:30
_gotoEditor() async {
2024-02-09 13:49:18 +06:30
bool? updated = _carton.cartonType == carton_mix_carton
? await Navigator.push<bool>(
context,
CupertinoPageRoute(
builder: (context) => MixCartonEditor(carton: _carton)),
)
: await Navigator.push<bool>(
context,
CupertinoPageRoute(
builder: (context) => CartonPackageEditor(carton: _carton)),
);
if (updated ?? false) {
Carton? c =
await context.read<CartonModel>().getCarton(widget.carton.id ?? "");
if (c == null) return;
_carton = c;
_init();
2020-10-20 06:19:10 +06:30
}
}
2024-02-26 17:26:25 +06:30
_delete() {
2020-10-20 06:19:10 +06:30
showConfirmDialog(context, "box.delete.confirm", () {
_deleteCarton();
});
}
_deleteCarton() async {
setState(() {
_isLoading = true;
});
try {
2024-02-09 13:35:32 +06:30
// var cartonModel = Provider.of<CartonModel>(context, listen: false);
// await cartonModel.deleteCarton(widget.carton);
// Navigator.pop(context, true);
2020-10-20 06:19:10 +06:30
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
2020-10-14 16:53:16 +06:30
}
}