Merge branch 'master' of tzw/fcs into master

This commit is contained in:
2024-02-10 11:20:30 +06:30
committed by Gogs
33 changed files with 1053 additions and 1499 deletions

View File

@@ -341,7 +341,12 @@
"box.select.cargo_type":"Select surcharge item",
"box.surcharge.item":"Surcharge items",
"box.package.count":"Packages ({0})",
"box.bill_to":"Bill to",
"box.delvery_carton":"Delivery carton",
"box.pick_up_carton":"Pick-up carton",
"box.delete.btn":"Delete carton",
"box.update_title":"Edit carton",
"box.update.btn":"Update carton",
"Boxes End ================================================================":"",
"Delivery Start ================================================================":"",

View File

@@ -340,6 +340,12 @@
"box.select.cargo_type":"Select surcharge item",
"box.surcharge.item":"Surcharge items",
"box.package.count":"Packages ({0})",
"box.bill_to":"Bill to",
"box.delvery_carton":"Delivery carton",
"box.pick_up_carton":"Pick-up carton",
"box.delete.btn":"Delete carton",
"box.update_title":"Edit carton",
"box.update.btn":"Update carton",
"Boxes End ================================================================":"",
"Delivery Start ================================================================":"",

View File

@@ -36,8 +36,11 @@ class Carton {
String? mixCartonNumber;
String? cartonSizeID;
String? cartonSizeName;
String? deliveryType;
String? cartonSizeType;
double cartonWeight;
String? billToValue;
String? billTo;
bool isSelected;
int rate;
@@ -149,7 +152,7 @@ class Carton {
this.packages = const [],
this.cargoTypes = const [],
this.cartonNumber,
this.billToValue,
this.billTo,
this.fcsShipmentID,
this.fcsShipmentNumber,
this.packageIDs = const [],
@@ -159,10 +162,12 @@ class Carton {
this.deliveryAddress,
this.cartonSizeID,
this.cartonSizeName,
this.cartonSizeType,
this.deliveryType,
this.mixBoxType,
this.mixCartons = const [],
this.mixCartonIDs = const [],
this.cartonWeight =0,
this.cartonWeight = 0,
this.photoUrls = const [],
this.isSelected = false});
@@ -203,7 +208,7 @@ class Carton {
List<Map<String, dynamic>>.from(map['mix_cartons'] ?? []);
var _mixCartons =
mixCartonsMaps.map((e) => Carton.fromMap(e, e["id"])).toList();
List<String> _photoUrls =
List<String> _photoUrls =
map['photo_urls'] == null ? [] : List.from(map['photo_urls']);
return Carton(
@@ -237,7 +242,7 @@ class Carton {
senderName: map['sender_name'],
mixCartonIDs: List<String>.from(map['mix_carton_ids'] ?? []),
cartonWeight: (map['carton_weight'] ?? 0).toDouble(),
photoUrls: _photoUrls,
photoUrls: _photoUrls,
);
}

View File

@@ -1,118 +0,0 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/material.dart';
class CargoTable extends StatefulWidget {
final List<CargoType>? cargoTypes;
const CargoTable({
Key? key,
this.cargoTypes,
}) : super(key: key);
@override
_CargoTableState createState() => _CargoTableState();
}
class _CargoTableState extends State<CargoTable> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
headingRowHeight: 40,
columnSpacing: 50,
showCheckboxColumn: false,
decoration: BoxDecoration(border: Border.all(color: Colors.white)),
border: TableBorder(horizontalInside: BorderSide(color: Colors.white)),
columns: [
DataColumn(
label: LocalText(
context,
"cargo.type",
color: Colors.grey,
),
),
DataColumn(
label: LocalText(
context,
"cargo.qty",
color: Colors.grey,
),
),
DataColumn(
label: LocalText(
context,
"cargo.weight",
color: Colors.grey,
),
),
],
rows: getCargoRows(context),
),
);
}
List<DataRow> getCargoRows(BuildContext context) {
if (widget.cargoTypes == null) {
return [];
}
double total = 0;
var rows = widget.cargoTypes!.map((c) {
total += c.weight;
return DataRow(
onSelectChanged: (bool? selected) async {},
cells: [
DataCell(new Text(
c.name ?? "",
style: textStyle,
)),
DataCell(c.qty == 0
? Center(
child: Text(
"-",
style: textStyle,
),
)
: Center(
child: Text(
c.qty.toString(),
style: textStyle,
),
)),
DataCell(
Text(c.weight.toStringAsFixed(2), style: textStyle),
),
],
);
}).toList();
var totalRow = DataRow(
onSelectChanged: (bool? selected) {},
cells: [
DataCell(Align(
alignment: Alignment.centerRight,
child: LocalText(
context,
"shipment.cargo.total",
color: Colors.black87,
fontWeight: FontWeight.bold,
),
)),
DataCell(Text("")),
DataCell(
Padding(
padding: const EdgeInsets.only(right: 48.0),
child: Align(
alignment: Alignment.centerRight,
child: Text(total.toStringAsFixed(2)+" lb",
style: TextStyle(fontWeight: FontWeight.bold))),
),
),
],
);
rows.add(totalRow);
return rows;
}
}

View File

@@ -1,132 +0,0 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class CargoTypeAddition extends StatefulWidget {
@override
_CargoTypeAdditionState createState() => _CargoTypeAdditionState();
}
class _CargoTypeAdditionState extends State<CargoTypeAddition> {
bool _isLoading = false;
List<CargoType> cargos = [];
List<CargoType> specialCargos = [];
@override
void initState() {
super.initState();
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
cargos = shipmentRateModel.rate.cargoTypes.map((e) => e.clone()).toList();
specialCargos = List.from(shipmentRateModel.rate.customDuties);
specialCargos =
shipmentRateModel.rate.customDuties.map((e) => e.clone()).toList();
cargos.forEach((p) {
p.isChecked = false;
p.isCutomDuty = false;
p.weight = 0;
p.qty = 0;
});
specialCargos.forEach((p) {
p.isChecked = false;
p.isCutomDuty = true;
p.weight = 0;
p.qty = 1;
});
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
List<Widget> getCargoRowList(List<CargoType> _c) {
return _c.map((c) {
return Container(
child: Container(
padding:
EdgeInsets.only(left: 10.0, right: 5.0, top: 3.0, bottom: 3.0),
child: InkWell(
onTap: () {
setState(() {
c.isChecked = !c.isChecked;
});
},
child: Row(
children: <Widget>[
Checkbox(
value: c.isChecked,
activeColor: primaryColor,
onChanged: (bool? check) {
setState(() {
c.isChecked = check ?? false;
});
}),
new Text(c.name ?? '', style: textStyle),
],
),
),
),
);
}).toList();
}
final saveBtn = fcsButton(
context,
getLocalString(context, 'box.cargo.select.btn'),
callack: () {
List<CargoType> _cargos =
this.cargos.where((c) => c.isChecked).toList();
List<CargoType> _scargos =
this.specialCargos.where((c) => c.isChecked).toList();
_cargos.addAll(_scargos);
Navigator.pop(context, _cargos);
},
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
labelKey: 'cargo.form.title',
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor),
body: Container(
padding: EdgeInsets.all(8),
child: ListView(
shrinkWrap: true,
children: <Widget>[
LocalTitle(
textKey: "box.select.cargo.title",
),
Column(
children: getCargoRowList(cargos),
),
LocalTitle(
textKey: "box.select.cargo.title",
),
Column(
children: getCargoRowList(specialCargos),
),
SizedBox(height: 30),
saveBtn,
SizedBox(height: 20),
],
),
),
),
);
}
}

View File

@@ -1,260 +0,0 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/dialog_input.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/material.dart';
typedef OnRemove(CargoType cargoType);
typedef OnUpdate(CargoType cargoType);
class CargoTable extends StatefulWidget {
final List<CargoType>? cargoTypes;
final bool? isNew;
final OnRemove? onRemove;
final OnUpdate? onUpdate;
const CargoTable(
{Key? key, this.cargoTypes, this.isNew, this.onRemove, this.onUpdate})
: super(key: key);
@override
_CargoTableState createState() => _CargoTableState();
}
class _CargoTableState extends State<CargoTable> {
double totalWeight = 0;
List<CargoType>? cargoTypes;
@override
void initState() {
cargoTypes = widget.cargoTypes;
if (!widget.isNew!) {
totalWeight =
cargoTypes!.fold(0, (previous, current) => previous + current.weight);
}
super.initState();
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
showCheckboxColumn: false,
headingRowHeight: 40,
// columnSpacing: 40,
decoration: BoxDecoration(border: Border.all(color: Colors.white)),
border: TableBorder(horizontalInside: BorderSide(color: Colors.white)),
columns: [
DataColumn(
label: LocalText(
context,
"cargo.type",
color: Colors.grey,
),
),
DataColumn(
label: LocalText(
context,
"cargo.qty",
color: Colors.grey,
),
),
DataColumn(
label: LocalText(
context,
"cargo.weight",
color: Colors.grey,
),
),
],
rows: getCargoRows(context),
),
);
}
List<DataRow> getCargoRows(BuildContext context) {
if (cargoTypes == null) {
return [];
}
var rows = cargoTypes!.map((c) {
return DataRow(
onSelectChanged: (bool? selected) async {},
cells: [
DataCell(
new Text(
c.name ?? '',
style: textStyle,
),
),
DataCell(
c.isCutomDuty
? GestureDetector(
onTap: () async {
String? _t = await showDialog(
context: context,
builder: (_) => DialogInput(
label: "cargo.qty", value: c.qty.toString()));
if (_t == null) return;
setState(() {
c.qty = int.tryParse(_t) ?? 0;
});
if (widget.onUpdate != null) widget.onUpdate!(c);
},
child: Center(
child: Container(
width: 40,
padding: const EdgeInsets.all(7.0),
decoration: BoxDecoration(
border: Border.all(color: primaryColor),
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
child: new Text(
c.qty.toString(),
style: textStyle,
textAlign: TextAlign.center,
),
),
),
)
: Center(
child: new Text(
"-",
style: textStyle,
),
),
),
DataCell(
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () async {
if (this.totalWeight <= 0) {
showMsgDialog(
context, "Error", "Please insert total weight");
return;
}
String? _t = await showDialog(
context: context,
builder: (_) => DialogInput(
label: "cargo.weight",
value: c.weight.toStringAsFixed(2)));
if (_t == null) return;
setState(() {
c.weight = double.tryParse(_t) ?? 0;
});
if (c.weight != 0) {
_cal();
}
if (widget.onUpdate != null) widget.onUpdate!(c);
},
child: Container(
padding: const EdgeInsets.all(7.0),
decoration: BoxDecoration(
border: Border.all(color: primaryColor),
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
child: Text(c.weight.toStringAsFixed(2), style: textStyle),
),
),
widget.onRemove == null
? SizedBox(
width: 50,
)
: IconButton(
icon: Icon(
Icons.remove_circle,
color: primaryColor,
),
onPressed: () {
if (widget.onRemove != null) widget.onRemove!(c);
})
],
),
),
],
);
}).toList();
var totalRow = DataRow(
onSelectChanged: (bool? selected) {},
cells: [
DataCell(Align(
alignment: Alignment.centerRight,
child: LocalText(
context,
"shipment.cargo.total",
color: Colors.black87,
fontWeight: FontWeight.bold,
),
)),
DataCell(Text("")),
DataCell(
Padding(
padding: const EdgeInsets.only(right: 48.0),
child: Align(
alignment: Alignment.centerRight,
child: InkWell(
onTap: () async {
String? _t = await showDialog(
context: context,
builder: (_) => DialogInput(
label: "shipment.cargo.total",
value: totalWeight.toStringAsFixed(2)),
);
if (_t == null) return;
setState(() {
totalWeight = double.tryParse(_t) ?? 0;
});
_cal();
},
child: Container(
padding: const EdgeInsets.all(7.0),
decoration: BoxDecoration(
border: Border.all(color: primaryColor),
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
child: Text(totalWeight.toStringAsFixed(2),
style: TextStyle(fontWeight: FontWeight.bold)),
),
)),
),
),
],
);
rows.add(totalRow);
return rows;
}
_cal() {
var cargoType = autoCalWeight(cargoTypes!, totalWeight);
if (cargoType == null) return;
setState(() {
cargoTypes!.remove(cargoType);
cargoTypes!.add(cargoType);
});
if (widget.onUpdate != null) {
widget.onUpdate!(cargoType);
}
}
}
CargoType? autoCalWeight(List<CargoType> cargoTypes, double total) {
List<CargoType> noWeight = cargoTypes.where((c) => c.weight == 0).toList();
if (noWeight.length != 1) return null;
double _existing =
cargoTypes.fold(0, (previous, current) => previous + current.weight);
noWeight[0].weight = total - _existing;
return noWeight[0];
}

View File

@@ -6,7 +6,6 @@ import 'package:fcs/pages/user_search/user_search.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/local_radio.dart';
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
@@ -15,10 +14,10 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import '../main/util.dart';
import 'carton_editor_for_package.dart';
import 'carton_package_form.dart';
import 'carton_info.dart';
import 'mix_carton/mix_carton_editor.dart';
import 'carton_row.dart';
import 'mix_carton/mix_carton_form.dart';
import 'widget/carton_row.dart';
class CartonEditor extends StatefulWidget {
final Carton? carton;
@@ -34,7 +33,6 @@ class _CartonEditorState extends State<CartonEditor> {
bool _isLoading = false;
bool _isNew = false;
String _billToValue = billToSender;
String? _selectedCartonType;
User? _consignee;
@@ -156,23 +154,20 @@ class _CartonEditorState extends State<CartonEditor> {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => CartonEditorForPackage(
sender: _sender!,
consignee: _consignee!,
billToValue: _billToValue)));
builder: (context) => CartonPackageForm(
sender: _sender!,
consignee: _consignee!,
)));
}
// for mix cartion
else {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => const MixCartonEditor()));
builder: (context) => const MixCartonForm()));
}
},
child: Icon(
Icons.add_circle,
color: primaryColor,
),
child: Icon(Icons.add_circle, color: primaryColor),
),
));
@@ -268,72 +263,6 @@ class _CartonEditorState extends State<CartonEditor> {
),
);
final billRadioBox = Container(
child: Row(
children: [
Flexible(
child: InkWell(
onTap: () {
setState(() {
_billToValue = billToSender;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: billToSender,
groupValue: _billToValue,
onChanged: (p0) {
setState(() {
_billToValue = billToSender;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to_sender',
fontSize: 15,
color: _billToValue == billToSender
? primaryColor
: Colors.black),
),
)
]),
)),
Flexible(
child: InkWell(
onTap: () {
setState(() {
_billToValue = billToConsignee;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: billToConsignee,
groupValue: _billToValue,
onChanged: (p0) {
setState(() {
_billToValue = billToConsignee;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to.consignee',
fontSize: 15,
color: _billToValue == billToConsignee
? primaryColor
: Colors.black),
),
)
]),
),
)
],
),
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
@@ -358,9 +287,6 @@ class _CartonEditorState extends State<CartonEditor> {
Flexible(child: consigneeBox)
],
),
const SizedBox(height: 5),
billRadioBox,
const SizedBox(height: 5),
],
)
: Container(),
@@ -381,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));

View File

@@ -8,7 +8,7 @@ import '../../helpers/theme.dart';
import '../../localization/app_translations.dart';
import '../main/util.dart';
import '../widgets/local_text.dart';
import 'user_search_result.dart';
import 'widget/user_search_result.dart';
import 'model/carton_model.dart';
import 'model/consignee_selection_model.dart';

View File

@@ -1,85 +0,0 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/multi_img_controller.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import '../widgets/multi_img_file.dart';
typedef void FindCallBack();
class CartonImageUpload extends StatefulWidget {
final Carton? box;
const CartonImageUpload({this.box});
@override
_CartonImageUploaState createState() => _CartonImageUploaState();
}
class _CartonImageUploaState extends State<CartonImageUpload> {
bool _isLoading = false;
Carton? _box;
MultiImgController multiImgController = MultiImgController();
@override
void initState() {
super.initState();
_box = widget.box;
multiImgController.setImageUrls = _box?.photoUrls;
}
@override
Widget build(BuildContext context) {
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
labelKey: "box.imageupload.title",
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor,
actions: []
// isEdiable
// ? <Widget>[
// IconButton(
// icon: Icon(Icons.edit, color: primaryColor),
// onPressed: _gotoEditor,
// ),
// IconButton(
// icon: Icon(Icons.delete, color: primaryColor),
// onPressed: _delete,
// ),
// ]
// : [],
),
body: ListView(
children: [
Center(
child: Text("${_box?.cartonNumber}",
style: TextStyle(
color: primaryColor,
fontSize: 25,
))),
MultiImageFile(
enabled: true,
controller: multiImgController,
title: "Receipt File",
),
Center(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xff272262),
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
minimumSize: Size(300, 45), //////// HERE
),
onPressed: () {},
child:
const Text('Save', style: TextStyle(fontSize: 20)),
),
),
],
)));
}
}

View File

@@ -0,0 +1,71 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/multi_img_controller.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import '../widgets/local_button.dart';
import '../widgets/multi_img_file.dart';
typedef void FindCallBack();
class CartonImageUploadEditor extends StatefulWidget {
final Carton? box;
const CartonImageUploadEditor({this.box});
@override
_CartonImageUploaState createState() => _CartonImageUploaState();
}
class _CartonImageUploaState extends State<CartonImageUploadEditor> {
bool _isLoading = false;
Carton? _box;
MultiImgController multiImgController = MultiImgController();
@override
void initState() {
super.initState();
_box = widget.box;
multiImgController.setImageUrls = _box?.photoUrls;
}
@override
Widget build(BuildContext context) {
final saveBtn = Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: LocalButton(
textKey: "btn.save",
callBack: () {},
),
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
labelKey: "box.imageupload.title",
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor,
actions: []),
body: Padding(
padding: EdgeInsets.only(left: 12.0, right: 12),
child: ListView(
children: [
Center(
child: Text("${_box?.cartonNumber}",
style: TextStyle(
color: primaryColor,
fontSize: 25,
))),
MultiImageFile(
enabled: true,
controller: multiImgController,
title: "Receipt File",
),
saveBtn,
],
),
)));
}
}

View File

@@ -3,12 +3,9 @@ import 'package:fcs/domain/entities/cargo_type.dart';
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/carton/carton_image_upload_editor.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,194 +17,167 @@ 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 '../../domain/entities/carton_size.dart';
import '../widgets/local_button.dart';
import 'carton_package_editor.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 isEdiable = false;
final List<CargoType> cargoTypes = [];
final List<CargoType> surchareItems = [];
bool _isLoading = false;
late Carton _carton;
List<CargoType> _cargoTypes = [];
List<CargoType> _surchareItems = [];
List<Carton> _mixCartons = [];
List<Package> _packages = [];
double totalWeight = 0.0;
double totalSurchargeCount = 0.0;
CartonSize? standardSize;
@override
void initState() {
_carton = widget.carton;
_init();
super.initState();
_box = widget.box;
_box?.billToValue = "Bill to sender";
_cartonSubmit = widget.cartonSubmit;
//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;
isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
_box!.status == carton_packed_status;
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 = billToConsignee;
_carton.cartonSizeType = customCarton;
_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) {
_carton.deliveryType = delivery_caton;
_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(() {});
}
_carton.cartonType = "Carton for packages";
totalWeight =
_carton.cargoTypes.fold(0, (sum, value) => sum + value.weight);
totalSurchargeCount =
_surchareItems.fold(0, (sum, value) => sum + value.qty);
}
@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);
String? boxDimension = _carton.cartonSizeType == standardCarton
? "${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(
text: _box!.cartonNumber,
text: _carton.cartonNumber,
labelTextKey: "box.number",
);
final cartonQrBox = DisplayText(
iconData: AntDesign.qrcode,
final cartonQrBox = DisplayText(iconData: AntDesign.qrcode);
final cartonSubTypeBox = DisplayText(
text: _carton.cartonType == carton_from_packages
? "Carton for packages"
: "Mix carton",
subText: boxDimension == null ? null : Text("$boxDimension"),
labelTextKey: "box.carton.type",
);
final shipmentBox = DisplayText(
text: _box!.fcsShipmentNumber,
text: _carton.fcsShipmentNumber,
labelTextKey: "box.fcs_shipment_num",
);
final deliveryBox = DisplayText(
text: "Delivery Carton",
text: _carton.deliveryType,
labelTextKey: "box.delivery_type",
);
final customerNameBox = DisplayText(
text: _box!.userName == null ? "" : _box!.userName,
subText: Text(_box!.fcsID ?? "", style: textStyle),
final senderBox = DisplayText(
text: _carton.senderName == null ? "" : _carton.senderName,
subText: Text(_carton.senderFCSID ?? "", style: textStyle),
labelTextKey: "box.name",
);
final consigneeNameBox = DisplayText(
text: _box!.senderName != null ? _box!.senderName : "",
subText: Text(_box!.senderFCSID ?? "", style: textStyle),
text: _carton.userName != null ? _carton.userName : "",
subText: Text(_carton.fcsID ?? "", style: textStyle),
labelTextKey: "processing.consignee.name",
);
final packageBox = DisplayText(
labelTextKey: "box.package",
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,
@@ -222,7 +192,6 @@ class _CartonInfoState extends State<CartonInfo> {
style: TextStyle(color: Colors.black54, fontSize: 15)))
],
),
//),
Container(
child: Padding(
padding: const EdgeInsets.only(right: 100),
@@ -230,7 +199,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(
@@ -256,7 +225,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,
@@ -267,7 +236,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)))
],
),
@@ -279,7 +248,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(
@@ -301,7 +270,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(
@@ -330,116 +299,52 @@ class _CartonInfoState extends State<CartonInfo> {
controller: multiImgController,
title: "Receipt File",
);
final displayMixBox = Container(
child: Row(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
//crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
customerNameBox,
],
),
),
_box?.billToValue == billToSender
? 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))
],
)))
: const SizedBox()
],
),
),
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
? 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))
],
)))
: const SizedBox()
],
),
))
],
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),
),
packageBox,
Row(
children: getPackageList(_box!.packages),
)
],
));
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))
],
)));
onPressed: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => CartonImageUploadEditor(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,
child: Scaffold(
appBar: LocalAppBar(
labelKey: "box.info.title",
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor,
actions: isEdiable
? <Widget>[
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _gotoEditor,
),
IconButton(
icon: Icon(Icons.delete, color: primaryColor),
onPressed: _delete,
),
]
: [],
),
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.all(10.0),
child: ListView(children: <Widget>[
@@ -450,122 +355,97 @@ class _CartonInfoState extends State<CartonInfo> {
),
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: shipmentBox,
),
Flexible(
child: deliveryBox,
),
Flexible(child: cartonSubTypeBox),
],
),
// 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()
// ],
// ),
// ),
// 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()
// ],
// ),
// ))
// ],
// ),
// packageBox,
// Row(
// children: getPackageList(_box!.packages),
// ),
// ]):Container(),
cargosBox,
surchargeItemBox,
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'),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(child: shipmentBox),
_mixCartons.isEmpty
? Flexible(child: deliveryBox)
: const SizedBox(),
],
),
_mixCartons.isEmpty ? userRowBox : const SizedBox(),
_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),
),
],
),
),
_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 {
_box!.mixCartons = _box!.mixCartons;
bool? updated = await Navigator.push<bool>(
context,
CupertinoPageRoute(builder: (context) => CartonEditor(carton: _box)),
);
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) {
var cartonModel = Provider.of<CartonModel>(context, listen: false);
var c = await cartonModel.getCarton(widget.box.id ?? "");
setState(() {
_box = c;
_loadPackages();
_loadMixCartons();
_updateBoxData();
});
Carton? c =
await context.read<CartonModel>().getCarton(widget.carton.id ?? "");
if (c == null) return;
_carton = c;
_init();
}
}
@@ -580,9 +460,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 {
@@ -591,28 +471,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> 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();
}
}

View File

@@ -17,7 +17,7 @@ import '../fcs_shipment/model/fcs_shipment_model.dart';
import 'carton_editor.dart';
import 'carton_filter.dart';
import 'carton_info.dart';
import 'carton_list_row.dart';
import 'widget/carton_list_row.dart';
class CartonList extends StatefulWidget {
@override
@@ -104,7 +104,7 @@ class _CartonListState extends State<CartonList> {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => CartonInfo(box: c)),
builder: (context) => CartonInfo(carton: c)),
);
});
}),

View File

@@ -0,0 +1,289 @@
// 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_size.dart';
import '../../../domain/entities/fcs_shipment.dart';
import '../../../domain/vo/local_step.dart';
import '../../../helpers/theme.dart';
import '../../domain/entities/cargo_type.dart';
import '../../domain/entities/carton.dart';
import '../../domain/entities/package.dart';
import '../../domain/entities/user.dart';
import '../fcs_shipment/model/fcs_shipment_model.dart';
import '../main/util.dart';
import '../package/model/package_model.dart';
import '../widgets/local_text.dart';
import '../widgets/progress.dart';
import '../widgets/step_widget.dart';
import 'cargo_widget.dart';
import 'carton_size_widget.dart';
import 'carton_submit.dart';
import 'model/package_selection_model.dart';
import 'package_selection_widget.dart';
class CartonPackageEditor extends StatefulWidget {
final Carton carton;
const CartonPackageEditor({Key? key, required this.carton}) : super(key: key);
@override
State<CartonPackageEditor> createState() => _CartonPackageEditorState();
}
class _CartonPackageEditorState extends State<CartonPackageEditor> {
var dateFormatter = DateFormat('dd MMM yyyy');
final NumberFormat numberFormatter = NumberFormat("#,###");
List<LocalStep> steps = [
LocalStep(lable: 'Size', stepType: StepType.SIZE),
LocalStep(lable: 'Packages', stepType: StepType.PACKAGES),
LocalStep(lable: 'Cargos', stepType: StepType.CARGOS),
LocalStep(lable: 'Submit', stepType: StepType.SUBMIT)
];
List<Package> _packages = [];
List<CargoType> _cargoTypes = [];
List<CargoType> _surchareItems = [];
int currentStep = 0;
double _length = 0;
double _width = 0;
double _height = 0;
String _selectedDeliveryType = delivery_caton;
String _billToValue = billToSender;
FcsShipment? _shipment;
String _cartonSizeType = standardCarton;
CartonSize? _standardSize;
bool _isLoading = false;
User? _consignee;
User? _sender;
@override
void initState() {
_init();
super.initState();
}
_init() async {
context.read<PackageSelectionModel>().clearSelection();
_sender = User(
name: widget.carton.senderName,
fcsID: widget.carton.senderFCSID,
id: widget.carton.senderID);
_consignee = User(
id: widget.carton.userID,
name: widget.carton.userName,
fcsID: widget.carton.fcsID);
_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();
var s = await context
.read<FcsShipmentModel>()
.getFcsShipment(widget.carton.fcsShipmentID ?? "");
_shipment = s;
_packages = await context
.read<PackageModel>()
.getPackagesByIds(widget.carton.packageIDs);
if (mounted) {
setState(() {});
}
}
@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, 'box.update_title',
color: primaryColor, fontSize: 20),
),
body: Column(
children: [
StepperWidget(
labels: steps.map((e) => e.lable).toList(),
currentStep: currentStep,
eachStepWidth: MediaQuery.of(context).size.width / 4,
onChange: (index) {
if (index > currentStep) {
return;
}
setState(() {
currentStep = index;
});
},
),
getContent(currentStep)
],
))),
);
}
Widget getContent(int index) {
var step = steps[index];
if (step.stepType == StepType.SIZE) {
return Expanded(
child: CartonSizeWidget(
deliveryType: _selectedDeliveryType,
billType: _billToValue,
sender: _sender!,
consignee: _consignee!,
shipment: _shipment,
cartonSizeType: _cartonSizeType,
standardSize: _standardSize,
length: _length,
width: _width,
height: _height,
onPrevious: () {
Navigator.pop(context);
},
onContinue: (deliveryType, billType, shipment, cartonSizeType,
{standardSize, length, width, height}) {
setState(() {
_selectedDeliveryType = deliveryType;
_billToValue = billType;
_shipment = shipment;
_cartonSizeType = cartonSizeType;
_standardSize = standardSize;
_length = length ?? 0;
_width = width ?? 0;
_height = height ?? 0;
currentStep += 1;
});
},
));
} else if (step.stepType == StepType.PACKAGES) {
return Expanded(
child: PackageSelectionWidget(
sender: _sender!,
consignee: _consignee!,
shipment: _shipment!,
packages: _packages,
onContinue: (packages) {
setState(() {
_packages = List.from(packages);
currentStep += 1;
});
},
onPrevious: (packages) {
setState(() {
_packages = List.from(packages);
currentStep -= 1;
});
},
),
);
} else if (step.stepType == StepType.CARGOS) {
return Expanded(
child: CargoWidget(
sender: _sender!,
consignee: _consignee!,
cargoTypes: _cargoTypes,
surchargeItems: _surchareItems,
onContinue: (cargoTypes, customDuties) {
setState(() {
_cargoTypes = List.from(cargoTypes);
_surchareItems = List.from(customDuties);
currentStep += 1;
});
},
onPrevious: (cargoTypes, customDuties) {
setState(() {
_cargoTypes = List.from(cargoTypes);
_surchareItems = List.from(customDuties);
currentStep -= 1;
});
},
),
);
} else {
return Expanded(
child: CartonSubmit(
isNew: false,
sender: _sender!,
consingee: _consignee!,
billToValue: _billToValue,
cartonSizeType: _cartonSizeType,
standardSize: _standardSize,
length: _length,
width: _width,
height: _height,
deliveryType: _selectedDeliveryType,
shipment: _shipment!,
packages: _packages,
cargoTypes: _cargoTypes,
surchareItems: _surchareItems,
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;
});
}
}
}

View File

@@ -23,19 +23,22 @@ import 'carton_submit.dart';
import 'model/package_selection_model.dart';
import 'package_selection_widget.dart';
class CartonEditorForPackage extends StatefulWidget {
class CartonPackageForm extends StatefulWidget {
final User sender;
final User consignee;
final String billToValue;
const CartonEditorForPackage(
{Key? key, required this.sender, required this.consignee, required this.billToValue})
const CartonPackageForm(
{Key? key,
required this.sender,
required this.consignee,
})
: super(key: key);
@override
State<CartonEditorForPackage> createState() => _CartonEditorForPackageState();
State<CartonPackageForm> createState() => _CartonPackageFormState();
}
class _CartonEditorForPackageState extends State<CartonEditorForPackage> {
class _CartonPackageFormState extends State<CartonPackageForm> {
var dateFormatter = DateFormat('dd MMM yyyy');
final NumberFormat numberFormatter = NumberFormat("#,###");
List<LocalStep> steps = [
@@ -54,6 +57,8 @@ class _CartonEditorForPackageState extends State<CartonEditorForPackage> {
double _height = 0;
String _selectedDeliveryType = delivery_caton;
String _billToValue = billToSender;
FcsShipment? _shipment;
String _cartonSizeType = standardCarton;
CartonSize? _standardSize;
@@ -131,6 +136,7 @@ class _CartonEditorForPackageState extends State<CartonEditorForPackage> {
return Expanded(
child: CartonSizeWidget(
deliveryType: _selectedDeliveryType,
billType: _billToValue,
sender: widget.sender,
consignee: widget.consignee,
shipment: _shipment,
@@ -142,10 +148,11 @@ class _CartonEditorForPackageState extends State<CartonEditorForPackage> {
onPrevious: () {
Navigator.pop(context);
},
onContinue: (deliveryType, shipment, cartonSizeType,
onContinue: (deliveryType,billType ,shipment, cartonSizeType,
{standardSize, length, width, height}) {
setState(() {
_selectedDeliveryType = deliveryType;
_billToValue = billType;
_shipment = shipment;
_cartonSizeType = cartonSizeType;
_standardSize = standardSize;
@@ -205,7 +212,7 @@ class _CartonEditorForPackageState extends State<CartonEditorForPackage> {
child: CartonSubmit(
sender: widget.sender,
consingee: widget.consignee,
billToValue: widget.billToValue,
billToValue: _billToValue,
cartonSizeType: _cartonSizeType,
standardSize: _standardSize,
length: _length,

View File

@@ -21,7 +21,8 @@ import '../widgets/previous_button.dart';
typedef OnPrevious = Function();
typedef OnContinue = Function(String deliveryType,FcsShipment shipment, String cartonSizeType,
typedef OnContinue = Function(String deliveryType, String billType,
FcsShipment shipment, String cartonSizeType,
{CartonSize? standardSize, double? length, double? width, double? height});
class CartonSizeWidget extends StatefulWidget {
@@ -30,6 +31,7 @@ class CartonSizeWidget extends StatefulWidget {
final User sender;
final User consignee;
final String deliveryType;
final String billType;
final FcsShipment? shipment;
final String cartonSizeType;
final CartonSize? standardSize;
@@ -49,7 +51,8 @@ class CartonSizeWidget extends StatefulWidget {
this.height,
required this.sender,
required this.consignee,
required this.deliveryType})
required this.deliveryType,
required this.billType})
: super(key: key);
@override
@@ -60,11 +63,12 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
List<String> _deliveryTypes = [delivery_caton, pickup_carton];
FcsShipment? _shipment;
String _cartionSizeType = standardCarton;
String _cartonSizeType = standardCarton;
List<FcsShipment> _shipments = [];
CartonSize? _selectStandardSize;
late String _selectedDeliveryType;
late String _billToValue;
TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController();
@@ -78,34 +82,41 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
_init() async {
_selectedDeliveryType = widget.deliveryType;
_shipment = widget.shipment;
_cartionSizeType = widget.cartonSizeType;
_billToValue = widget.billType;
_cartonSizeType = widget.cartonSizeType;
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
_selectStandardSize = widget.standardSize ?? cartonSizes.first;
_lengthController.text =
widget.length == null ? "0" : widget.length.toString();
widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0);
_widthController.text =
widget.width == null ? "0" : widget.width.toString();
widget.width == null ? "0" : removeTrailingZeros(widget.width ?? 0);
_heightController.text =
widget.height == null ? "0" : widget.height.toString();
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
var fcsShipments =
await context.read<FcsShipmentModel>().getActiveFcsShipments();
_shipments = fcsShipments;
_shipment = widget.shipment;
if (mounted) {
setState(() {});
}
}
@override
void didUpdateWidget(covariant CartonSizeWidget oldWidget) {
_init();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
List<CartonSize> cartonSizes = context.watch<CartonSizeModel>().cartonSizes;
bool isStandardSize = _cartionSizeType == standardCarton;
bool isCustomSize = _cartionSizeType == customCarton;
bool isNoneDefinedSize = _cartionSizeType == packageCartion;
bool isStandardSize = _cartonSizeType == standardCarton;
bool isCustomSize = _cartonSizeType == customCarton;
bool isNoneDefinedSize = _cartonSizeType == packageCartion;
final senderBox = DisplayText(
text: widget.sender.name,
@@ -142,6 +153,72 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
});
});
final billRadioBox = Container(
child: Row(
children: [
Flexible(
child: InkWell(
onTap: () {
setState(() {
_billToValue = billToSender;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: billToSender,
groupValue: _billToValue,
onChanged: (p0) {
setState(() {
_billToValue = billToSender;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to_sender',
fontSize: 15,
color: _billToValue == billToSender
? primaryColor
: Colors.black),
),
)
]),
)),
Flexible(
child: InkWell(
onTap: () {
setState(() {
_billToValue = billToConsignee;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: billToConsignee,
groupValue: _billToValue,
onChanged: (p0) {
setState(() {
_billToValue = billToConsignee;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to.consignee',
fontSize: 15,
color: _billToValue == billToConsignee
? primaryColor
: Colors.black),
),
)
]),
),
)
],
),
);
final continueBtn = ContinueButton(onTap: () {
double l = double.tryParse(_lengthController.text) ?? 0;
double w = double.tryParse(_widthController.text) ?? 0;
@@ -170,7 +247,8 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
}
if (widget.onContinue != null) {
widget.onContinue!(_selectedDeliveryType,_shipment!, _cartionSizeType,
widget.onContinue!(
_selectedDeliveryType, _billToValue, _shipment!, _cartonSizeType,
standardSize: _selectStandardSize, length: l, width: w, height: h);
}
});
@@ -249,16 +327,16 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
InkWell(
onTap: () {
setState(() {
_cartionSizeType = standardCarton;
_cartonSizeType = standardCarton;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: standardCarton,
groupValue: _cartionSizeType,
groupValue: _cartonSizeType,
onChanged: (p0) {
setState(() {
_cartionSizeType = standardCarton;
_cartonSizeType = standardCarton;
});
},
),
@@ -278,16 +356,16 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
InkWell(
onTap: () {
setState(() {
_cartionSizeType = customCarton;
_cartonSizeType = customCarton;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: customCarton,
groupValue: _cartionSizeType,
groupValue: _cartonSizeType,
onChanged: (p0) {
setState(() {
_cartionSizeType = customCarton;
_cartonSizeType = customCarton;
});
},
),
@@ -307,16 +385,16 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
InkWell(
onTap: () {
setState(() {
_cartionSizeType = packageCartion;
_cartonSizeType = packageCartion;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: packageCartion,
groupValue: _cartionSizeType,
groupValue: _cartonSizeType,
onChanged: (p0) {
setState(() {
_cartionSizeType = packageCartion;
_cartonSizeType = packageCartion;
});
},
),
@@ -366,7 +444,9 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
children: [
const SizedBox(height: 8),
userRow,
LocalTitle(textKey: "box.select.delivery", topPadding: 10),
const SizedBox(height: 5),
billRadioBox,
LocalTitle(textKey: "box.select.delivery"),
const SizedBox(height: 5),
deliveryTypeBox,
const SizedBox(height: 5),

View File

@@ -35,6 +35,7 @@ class CartonSubmit extends StatelessWidget {
final List<CargoType> surchareItems;
final OnCreateCarton? onCreate;
final OnPrevious? onPrevious;
final bool isNew;
const CartonSubmit(
{Key? key,
required this.sender,
@@ -51,7 +52,8 @@ class CartonSubmit extends StatelessWidget {
this.width = 0,
this.height = 0,
this.cargoTypes = const [],
this.surchareItems = const []})
this.surchareItems = const [],
this.isNew = true})
: super(key: key);
@override
@@ -310,7 +312,8 @@ class CartonSubmit extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
child: LocalText(context, 'box.crete.carton',
child: LocalText(
context, isNew ? 'box.crete.carton' : "box.update.btn",
color: Colors.white, fontSize: 15),
),
const SizedBox(width: 5),

View File

@@ -1,5 +1,6 @@
// ignore_for_file: deprecated_member_use
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
@@ -21,9 +22,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();
@@ -51,10 +51,26 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
@override
void initState() {
context.read<CartonSelectionModel>().clearSelection();
_init();
super.initState();
}
_init() async {
var s = await context
.read<FcsShipmentModel>()
.getFcsShipment(widget.carton.fcsShipmentID ?? "");
_shipment = s;
_cartonSizeType = customCarton;
_length = widget.carton.length;
_width = widget.carton.width;
_height = widget.carton.height;
context.read<CartonSelectionModel>().clearSelection();
if (mounted) {
setState(() {});
}
}
@override
Widget build(BuildContext context) {
return WillPopScope(
@@ -91,7 +107,7 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
},
),
backgroundColor: Colors.white,
title: LocalText(context, 'boxes.new',
title: LocalText(context, 'box.update_title',
color: primaryColor, fontSize: 20),
),
body: Column(
@@ -164,6 +180,7 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
} else {
return Expanded(
child: MixCartonSubmit(
isNew: false,
cartonSizeType: _cartonSizeType,
standardSize: _standardSize,
length: _length,
@@ -172,7 +189,7 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
shipment: _shipment!,
cartons: _cartons,
onCreate: () {
_create();
_update();
},
onPrevious: () {
setState(() {
@@ -184,7 +201,7 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
}
}
_create() async {
_update() async {
setState(() {
_isLoading = true;
});

View 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;
});
}
}
}

View File

@@ -18,6 +18,7 @@ typedef OnCreateMixCarton = Function();
typedef OnPrevious = Function();
class MixCartonSubmit extends StatefulWidget {
final bool isNew;
final FcsShipment shipment;
final List<Carton> cartons;
final String cartonSizeType;
@@ -37,7 +38,8 @@ class MixCartonSubmit extends StatefulWidget {
required this.cartonSizeType,
this.length = 0,
this.width = 0,
this.height = 0})
this.height = 0,
this.isNew = true})
: super(key: key);
@override
@@ -253,7 +255,8 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
child: LocalText(context, 'box.crete.carton',
child: LocalText(context,
widget.isNew ? 'box.crete.carton' : 'box.update.btn',
color: Colors.white, fontSize: 15),
),
const SizedBox(width: 5),

View File

@@ -65,28 +65,33 @@ class _TypeWidgetState extends State<TypeWidget> {
}
_init() async {
_shipment = widget.shipment;
_cartionSizeType = widget.cartonSizeType;
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
_selectStandardSize = widget.standardSize ?? cartonSizes.first;
_cartionSizeType = widget.cartonSizeType;
_lengthController.text =
widget.length == null ? "0" : widget.length.toString();
widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0);
_widthController.text =
widget.width == null ? "0" : widget.width.toString();
widget.width == null ? "0" : removeTrailingZeros(widget.width ?? 0);
_heightController.text =
widget.height == null ? "0" : widget.height.toString();
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
var fcsShipments =
await context.read<FcsShipmentModel>().getActiveFcsShipments();
_shipments = fcsShipments;
_shipment = widget.shipment;
if (mounted) {
setState(() {});
}
}
@override
void didUpdateWidget(covariant TypeWidget oldWidget) {
_init();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
List<CartonSize> cartonSizes = context.watch<CartonSizeModel>().cartonSizes;

View File

@@ -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;
}
}

View File

@@ -144,4 +144,5 @@ class CartonSelectionModel extends BaseModel {
cartons.clear();
query = "";
}
}

View File

@@ -102,6 +102,10 @@ class PackageSelectionModel extends BaseModel {
}
}
addSelectedPackage(List<Package> list){
selectedPackageList = list;
}
Future<void> _refresh(
{required String shipmentId,
required String senderId,

View File

@@ -1,363 +0,0 @@
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton_size.dart';
import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton_size/carton_size_list.dart';
import 'package:fcs/pages/carton_size/model/carton_size_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
import 'package:fcs/pages/widgets/length_picker.dart';
import 'package:fcs/pages/widgets/local_button.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
import 'cargo_type_addtion.dart';
import 'carton_cargo_table.dart';
import 'model/carton_model.dart';
class PackageCartonEditor extends StatefulWidget {
final Carton? carton;
final bool? isNew;
final User? consignee;
PackageCartonEditor({this.carton, this.isNew, this.consignee});
@override
_PackageCartonEditorState createState() => _PackageCartonEditorState();
}
class _PackageCartonEditorState extends State<PackageCartonEditor> {
TextEditingController _lengthCtl = new TextEditingController();
TextEditingController _widthCtl = new TextEditingController();
TextEditingController _heightCtl = new TextEditingController();
Carton? _carton;
bool _isLoading = false;
DeliveryAddress? _deliveryAddress = new DeliveryAddress();
List<CargoType> _cargoTypes = [];
CartonSize? selectedCatonSize;
bool isFromPackages = false;
bool isFromCartons = false;
@override
void initState() {
super.initState();
_load();
}
_load() {
_carton = widget.carton;
isFromPackages = _carton!.cartonType == carton_from_packages;
isFromCartons = _carton!.cartonType == carton_from_cartons;
if (widget.isNew!) {
_lengthCtl.text = "0";
_widthCtl.text = "0";
_heightCtl.text = "0";
} else {
_cargoTypes = widget.carton!.cargoTypes.map((e) => e.clone()).toList();
_lengthCtl.text = _carton!.length.toString();
_widthCtl.text = _carton!.width.toString();
_heightCtl.text = _carton!.height.toString();
_deliveryAddress = _carton!.deliveryAddress;
_getCartonSize();
}
}
_getCartonSize() {
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
cartonSizeModel.cartonSizes.forEach((c) {
if (c.length == _carton!.length &&
c.width == _carton!.width &&
c.height == _carton!.height) {
selectedCatonSize = CartonSize(
id: c.id,
name: c.name,
length: c.length,
width: c.width,
height: c.height);
}
});
}
@override
Widget build(BuildContext context) {
final lengthBox = LengthPicker(
controller: _lengthCtl,
lableKey: "box.length",
isReadOnly: false,
);
final widthBox = LengthPicker(
controller: _widthCtl,
lableKey: "box.width",
isReadOnly: false,
);
final heightBox = LengthPicker(
controller: _heightCtl,
lableKey: "box.height",
isReadOnly: false,
);
final dimBox = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(FontAwesome.arrow_circle_right, color: primaryColor),
),
SizedBox(child: lengthBox, width: 80),
SizedBox(child: widthBox, width: 80),
SizedBox(child: heightBox, width: 80),
],
);
final createBtn = LocalButton(
textKey: widget.isNew! ? "box.new_carton_btn" : "box.cargo.save.btn",
callBack: _creatCarton,
);
final cargoTableTitleBox = LocalTitle(
textKey: "box.cargo.type",
trailing: IconButton(
icon: Icon(
Icons.add_circle,
color: primaryColor,
),
onPressed: () async {
List<CargoType>? cargos = await Navigator.push<List<CargoType>>(
context,
CupertinoPageRoute(builder: (context) => CargoTypeAddition()));
if (cargos == null) return;
setState(() {
_cargoTypes.addAll(
cargos.where((e) => !_cargoTypes.contains(e)).toList());
});
}),
);
final cargoTableBox = CargoTable(
isNew: widget.isNew,
cargoTypes: _cargoTypes,
onRemove: (c) => _removeCargo(c),
onUpdate: (c) => _updateCargo(c),
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(
CupertinoIcons.back,
color: primaryColor,
),
onPressed: () => Navigator.of(context).pop()),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
title: LocalText(
context,
widget.isNew! ? "boxes.create.title" : "box.edit.title",
fontSize: 20,
color: primaryColor,
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: [
cargoTableTitleBox,
cargoTableBox,
LocalTitle(textKey: "box.dimension"),
cartonSizeDropdown(),
dimBox,
LocalTitle(textKey: "box.delivery_address"),
DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
onTap: () async {
DeliveryAddress? d = await Navigator.push<DeliveryAddress>(
context,
CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection(
deliveryAddress: _deliveryAddress,
user: User(
id: _carton!.userID,
name: _carton!.userName),
)),
);
if (d == null) return;
setState(() {
_deliveryAddress = d;
});
}),
SizedBox(
height: 20,
),
createBtn
],
),
),
),
);
}
Widget cartonSizeDropdown() {
List<CartonSize> _cartonSizes =
Provider.of<CartonSizeModel>(context).getCartonSizes;
return Padding(
padding: const EdgeInsets.only(top: 10),
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 0, right: 10),
child: Icon(AntDesign.CodeSandbox, color: primaryColor),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 18.0),
child: LocalText(
context,
"box.carton_size",
color: Colors.black54,
fontSize: 16,
),
),
DropdownButton<CartonSize>(
isDense: true,
value: selectedCatonSize,
style: TextStyle(color: Colors.black, fontSize: 14),
underline: Container(
height: 1,
color: Colors.grey,
),
onChanged: (CartonSize? newValue) {
setState(() {
if (newValue!.name == MANAGE_CARTONSIZE) {
selectedCatonSize = null;
_manageCartonSize();
return;
}
selectedCatonSize = newValue;
_widthCtl.text = selectedCatonSize!.width.toString();
_heightCtl.text = selectedCatonSize!.height.toString();
_lengthCtl.text = selectedCatonSize!.length.toString();
});
},
isExpanded: true,
items: _cartonSizes
.map<DropdownMenuItem<CartonSize>>((CartonSize value) {
return DropdownMenuItem<CartonSize>(
value: value,
child: Text(value.name ?? "",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: value.name == MANAGE_CARTONSIZE
? secondaryColor
: primaryColor)),
);
}).toList(),
),
],
),
),
],
),
);
}
_manageCartonSize() {
Navigator.push<Package>(
context,
CupertinoPageRoute(builder: (context) => CartonSizeList()),
);
}
_removeCargo(CargoType cargo) {
setState(() {
_cargoTypes.remove(cargo);
});
}
_updateCargo(CargoType cargo) {
setState(() {
var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id);
_c.weight = cargo.weight;
_c.qty = cargo.qty;
});
}
_creatCarton() async {
if (_cargoTypes.length == 0) {
showMsgDialog(context, "Error", "Expect at least one cargo type");
return;
}
double l = double.parse(_lengthCtl.text);
double w = double.parse(_widthCtl.text);
double h = double.parse(_heightCtl.text);
if ((l <= 0 || w <= 0 || h <= 0)) {
showMsgDialog(context, "Error", "Invalid dimension");
return;
}
if (_deliveryAddress == null) {
showMsgDialog(context, "Error", "Invalid delivery address");
return;
}
Carton carton = Carton();
carton.id = _carton!.id;
carton.cartonType = _carton!.cartonType;
carton.fcsShipmentID = _carton!.fcsShipmentID;
carton.cargoTypes = _cargoTypes;
if (isFromPackages) {
carton.userID = _carton!.userID;
carton.packages = _carton!.packages.where((e) => e.isChecked).toList();
}
if (isFromCartons) {
carton.userID = _carton!.userID;
carton.fcsID = _carton!.fcsID;
carton.userName = _carton!.userName;
carton.senderID = _carton!.senderID;
carton.senderFCSID = _carton!.senderFCSID;
carton.senderName = _carton!.senderName;
}
carton.length = l;
carton.width = w;
carton.height = h;
carton.deliveryAddress = _deliveryAddress;
setState(() {
_isLoading = true;
});
try {
CartonModel cartonModel =
Provider.of<CartonModel>(context, listen: false);
if (widget.isNew!) {
Carton _c = await cartonModel.createCarton(carton);
Navigator.pop(context, _c);
} else {
await cartonModel.updateCarton(carton);
Carton _c = await cartonModel.getCarton(_carton!.id!);
Navigator.pop(context, _c);
}
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}

View File

@@ -60,6 +60,8 @@ class _PackageSelectionWidgetState extends State<PackageSelectionWidget> {
consigneeId: widget.consignee.id!,
senderId: widget.sender.id!);
searchModel.addSelectedPackage(widget.packages);
_controller.text = searchModel.query;
_query = searchModel.query;
if (mounted) {

View File

@@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:intl/intl.dart';
import 'carton_info.dart';
import '../carton_info.dart';
class CartonListRow extends StatelessWidget {
final Carton box;
@@ -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(

View File

@@ -1,8 +1,8 @@
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/material.dart';
import '../../../helpers/theme.dart';
import '../../domain/entities/user.dart';
import '../../../../helpers/theme.dart';
import '../../../domain/entities/user.dart';
typedef OnAction = Future<void> Function();

View File

@@ -83,7 +83,7 @@ class FcsShipmentModel extends BaseModel {
try {
var snaps = await FirebaseFirestore.instance
.collection("/$fcs_shipment_collection")
.where("status", isEqualTo: fcs_shipment_confirmed_status)
// .where("status", isEqualTo: fcs_shipment_confirmed_status)
.get(const GetOptions(source: Source.server));
fcsShipments = snaps.docs.map((documentSnapshot) {
var fcs =
@@ -97,6 +97,7 @@ class FcsShipmentModel extends BaseModel {
}
Future<FcsShipment?> getFcsShipment(String id) async {
if (id == "") return null;
try {
var snap = await FirebaseFirestore.instance
.collection("/$fcs_shipment_collection")

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -2,7 +2,7 @@ import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/cargo_type_editor.dart';
import 'package:fcs/pages/shipment/cargo_type_editor.dart';
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';