update carton
This commit is contained in:
@@ -51,7 +51,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
List<DeliveryAddress> _deliveryAddresses = [];
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
List<CargoType> _cargoTypes = [];
|
||||
|
||||
@@ -116,7 +115,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
if (isFromPackages) _loadPackages();
|
||||
|
||||
if (!isMixBox) {
|
||||
_getDeliverAddresses();
|
||||
_getCartonSize();
|
||||
}
|
||||
} else {
|
||||
@@ -203,15 +201,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
});
|
||||
}
|
||||
|
||||
_getDeliverAddresses() async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
bool isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
this._deliveryAddresses = isFromPackages
|
||||
? await addressModel.getDeliveryAddresses(_carton.userID)
|
||||
: await addressModel.getDeliveryAddresses(_carton.receiverID);
|
||||
}
|
||||
|
||||
_getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
@@ -237,7 +226,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Widget build(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCartons = _selectedCartonType == carton_from_cartons;
|
||||
bool isMixBox = _selectedCartonType == carton_mix_box;
|
||||
|
||||
final shipmentBox = DisplayText(
|
||||
@@ -603,7 +592,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
},
|
||||
)
|
||||
: Container(),
|
||||
isFromCargos
|
||||
isFromCartons
|
||||
? Container(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Row(
|
||||
@@ -646,8 +635,14 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
builder: (context) =>
|
||||
DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddresses:
|
||||
_deliveryAddresses)),
|
||||
user: isFromPackages
|
||||
? User(
|
||||
id: _carton.userID,
|
||||
name: _carton.userName)
|
||||
: User(
|
||||
id: _carton.receiverID,
|
||||
name: _carton
|
||||
.receiverName))),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
@@ -658,7 +653,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
isFromPackages || isFromCargos
|
||||
isFromPackages || isFromCartons
|
||||
? _isNew
|
||||
? createBtn
|
||||
: saveBtn
|
||||
@@ -679,7 +674,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCartons = _selectedCartonType == carton_from_cartons;
|
||||
if (isFromPackages) {
|
||||
_loadPackages();
|
||||
c.value.packages = _carton.packages;
|
||||
@@ -812,7 +807,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
_addCarton() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCartons = _selectedCartonType == carton_from_cartons;
|
||||
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
@@ -824,12 +819,12 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (consignee == null && isFromCargos) {
|
||||
if (consignee == null && isFromCartons) {
|
||||
showMsgDialog(context, "Error", "Please select consignee's FCS ID");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender == null && isFromCargos) {
|
||||
if (sender == null && isFromCartons) {
|
||||
showMsgDialog(context, "Error", "Please select sender's FCS ID");
|
||||
return;
|
||||
}
|
||||
@@ -849,7 +844,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
if (isFromCartons) {
|
||||
carton.receiverID = consignee?.id;
|
||||
carton.receiverFCSID = consignee?.fcsID;
|
||||
carton.receiverName = consignee?.name;
|
||||
@@ -881,7 +876,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_cartons.add(_carton);
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
if (isFromCartons) {
|
||||
_cartonsForCargos.add(_carton);
|
||||
}
|
||||
|
||||
@@ -943,7 +938,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
_save() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cartons;
|
||||
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCargos)) {
|
||||
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
return;
|
||||
|
||||
@@ -88,7 +88,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
isFromShipments = _box.cartonType == carton_from_shipments;
|
||||
isFromPackages = _box.cartonType == carton_from_packages;
|
||||
isSmallBag = _box.cartonType == carton_small_bag;
|
||||
isFromCartons = _box.cartonType == carton_from_cargos;
|
||||
isFromCartons = _box.cartonType == carton_from_cartons;
|
||||
|
||||
isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
|
||||
_box.status == carton_packed_status;
|
||||
@@ -410,7 +410,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
|
||||
_gotoEditor() async {
|
||||
widget.box.mixCartons=_box.mixCartons;
|
||||
widget.box.mixCartons = _box.mixCartons;
|
||||
bool updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
|
||||
|
||||
@@ -78,7 +78,7 @@ class CartonListRow extends StatelessWidget {
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
"${box.actualWeight?.toStringAsFixed(2) ?? ''} lb",
|
||||
"${box.cartonWeight?.toStringAsFixed(2) ?? ''} lb",
|
||||
style:
|
||||
new TextStyle(fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
|
||||
@@ -9,17 +9,20 @@ import 'package:fcs/domain/vo/message.dart';
|
||||
import 'package:fcs/domain/vo/shipment_status.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:fcs/pagination/paginator_listener.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class CartonModel extends BaseModel {
|
||||
List<Carton> _boxes = [];
|
||||
List<Carton> cartons = [];
|
||||
PaginatorListener cartonsByFilter;
|
||||
|
||||
final log = Logger('CartonModel');
|
||||
List<Carton> get boxes =>
|
||||
_selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values);
|
||||
|
||||
Paginator _delivered;
|
||||
int _selectedIndex = 1;
|
||||
int _selectedIndexFilter = 1;
|
||||
bool isLoading = false;
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
@@ -60,13 +63,13 @@ class CartonModel extends BaseModel {
|
||||
|
||||
List<String> cartonTypes = [
|
||||
carton_from_packages,
|
||||
// carton_from_cargos,
|
||||
carton_from_cartons,
|
||||
carton_mix_box
|
||||
];
|
||||
List<String> mixBoxTypes = [mix_delivery, mix_pickup];
|
||||
List<String> cartonTypesInfo = [
|
||||
carton_from_packages,
|
||||
carton_from_cargos,
|
||||
carton_from_cartons,
|
||||
carton_mix_box,
|
||||
carton_from_shipments,
|
||||
carton_small_bag
|
||||
@@ -77,18 +80,45 @@ class CartonModel extends BaseModel {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
get selectedIndex => _selectedIndex;
|
||||
set selectedIndexFilter(int index) {
|
||||
_selectedIndexFilter = index;
|
||||
_loadCartonsByFilter(
|
||||
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
initData() {
|
||||
get selectedIndex => _selectedIndex;
|
||||
get selectedIndexFilter => _selectedIndexFilter;
|
||||
|
||||
initData() async {
|
||||
_selectedIndex = 1;
|
||||
_selectedIndexFilter = 1;
|
||||
_loadBoxes();
|
||||
_loadCartonForMixBox();
|
||||
|
||||
if (_delivered != null) _delivered.close();
|
||||
_delivered = _getDelivered();
|
||||
_delivered.load();
|
||||
}
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
if (user != null || !user.hasCarton()) {
|
||||
_initData();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initData() async {
|
||||
logout();
|
||||
_selectedIndexFilter = 1;
|
||||
cartonsByFilter = PaginatorListener<Carton>(
|
||||
(data, id) => Carton.fromMap(data, id), onChange: () {
|
||||
notifyListeners();
|
||||
}, rowPerLoad: 30, insertNewByListener: true);
|
||||
|
||||
_loadCartonsByFilter(
|
||||
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
|
||||
}
|
||||
|
||||
Future<void> _loadBoxes() async {
|
||||
if (user == null || !user.hasCarton()) return;
|
||||
String path = "/$cartons_collection/";
|
||||
@@ -116,30 +146,27 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadCartonForMixBox() async {
|
||||
if (user == null || !user.hasCarton()) return;
|
||||
String path = "/$cartons_collection/";
|
||||
if (cartonListener != null) cartonListener.cancel();
|
||||
cartons = [];
|
||||
Future<void> _loadCartonsByFilter(String orderName) async {
|
||||
if (user == null || !user.hasCarton()) return null;
|
||||
String path = "/$cartons_collection";
|
||||
|
||||
try {
|
||||
cartonListener = Firestore.instance
|
||||
Query listenerQuery = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cargos])
|
||||
whereIn: [carton_from_packages, carton_from_cartons])
|
||||
.where("status", isEqualTo: carton_packed_status)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("user_name")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
cartons.clear();
|
||||
cartons = snapshot.documents.map((documentSnapshot) {
|
||||
var s = Carton.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return s;
|
||||
}).toList();
|
||||
.orderBy(orderName, descending: true);
|
||||
|
||||
notifyListeners();
|
||||
});
|
||||
Query pageQuery = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cartons])
|
||||
.where("status", isEqualTo: carton_packed_status)
|
||||
.orderBy(orderName, descending: true);
|
||||
|
||||
cartonsByFilter.refresh(
|
||||
listeningQuery: listenerQuery, pageQuery: pageQuery);
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
@@ -184,8 +211,8 @@ class CartonModel extends BaseModel {
|
||||
if (listener != null) await listener.cancel();
|
||||
if (cartonListener != null) await cartonListener.cancel();
|
||||
if (_delivered != null) _delivered.close();
|
||||
if (cartonsByFilter != null) cartonsByFilter.close();
|
||||
_boxes = [];
|
||||
cartons = [];
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartons(String shipmentID) async {
|
||||
@@ -261,5 +288,4 @@ class CartonModel extends BaseModel {
|
||||
Future<List<Carton>> searchCarton(String term) async {
|
||||
return Services.instance.cartonService.searchCarton(term);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,11 +46,10 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
Carton _carton;
|
||||
bool _isLoading = false;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
List<DeliveryAddress> _deliveryAddresses = [];
|
||||
List<CargoType> _cargoTypes = [];
|
||||
CartonSize selectedCatonSize;
|
||||
bool isFromPackages;
|
||||
bool isFromCargos;
|
||||
bool isFromCartons;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -61,8 +60,8 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
_load() {
|
||||
_carton = widget.carton;
|
||||
isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
isFromCargos = _carton.cartonType == carton_from_cargos;
|
||||
_getDeliverAddresses();
|
||||
isFromCartons = _carton.cartonType == carton_from_cartons;
|
||||
|
||||
if (widget.isNew) {
|
||||
_lengthCtl.text = "0";
|
||||
_widthCtl.text = "0";
|
||||
@@ -77,18 +76,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
}
|
||||
}
|
||||
|
||||
_getDeliverAddresses() async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
|
||||
var deliveryAddresses = isFromPackages
|
||||
? await addressModel.getDeliveryAddresses(_carton.userID)
|
||||
: await addressModel.getDeliveryAddresses(_carton.receiverID);
|
||||
setState(() {
|
||||
this._deliveryAddresses = deliveryAddresses;
|
||||
});
|
||||
}
|
||||
|
||||
_getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
@@ -205,9 +192,13 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddresses: this._deliveryAddresses,
|
||||
user: widget.consignee,
|
||||
onAdded: () => _getDeliverAddresses(),
|
||||
user: isFromPackages
|
||||
? User(
|
||||
id: _carton.userID,
|
||||
name: _carton.userName)
|
||||
: User(
|
||||
id: _carton.receiverID,
|
||||
name: _carton.receiverName),
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
@@ -342,7 +333,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
if (isFromCartons) {
|
||||
carton.receiverID = _carton.receiverID;
|
||||
carton.receiverFCSID = _carton.receiverFCSID;
|
||||
carton.receiverName = _carton.receiverName;
|
||||
|
||||
Reference in New Issue
Block a user