Merge branch 'master' of https://git.mokkon.com/sainw/fcs
This commit is contained in:
@@ -275,7 +275,7 @@
|
||||
"box.packages":"Packages",
|
||||
"box.tracking.id":"Tracking ID",
|
||||
"box.market":"Market",
|
||||
"box.cargo.save.btn":"Save",
|
||||
"box.cargo.save.btn":"Select",
|
||||
"box.type.title":"Carton types",
|
||||
"box.shipment.boxes":"Cartons",
|
||||
"box.shipment_number":"Shipment number",
|
||||
@@ -300,6 +300,7 @@
|
||||
"box.min_caton.form.title":"Mix Carton",
|
||||
"box.mix_carton_btn":"Create mix carton",
|
||||
"box.mix_type":"Mix Box Types",
|
||||
"box.selection":"Carton Selection",
|
||||
"Boxes End ================================================================":"",
|
||||
|
||||
"Delivery Start ================================================================":"",
|
||||
|
||||
@@ -275,7 +275,7 @@
|
||||
"box.packages":"အထုပ်များ",
|
||||
"box.tracking.id":"Tracking ID",
|
||||
"box.market":"အွန်လိုင်စျေးဆိုင်",
|
||||
"box.cargo.save.btn":"သိမ်းဆည်းမည်",
|
||||
"box.cargo.save.btn":"ရွေးမည်",
|
||||
"box.type.title":"သေတ္တာအမျိုးအစားများ",
|
||||
"box.shipment.boxes":"သေတ္တာများ",
|
||||
"box.shipment_number":"ပို့ဆောင်နံပါတ်",
|
||||
@@ -300,6 +300,7 @@
|
||||
"box.min_caton.form.title":"Mix Carton",
|
||||
"box.mix_carton_btn":"Create mix carton",
|
||||
"box.mix_type":"Mix Box Types",
|
||||
"box.selection":"သေတ္တာ ရွေးချယ်ခြင်း",
|
||||
"Boxes End ================================================================":"",
|
||||
|
||||
"Delivery Start ================================================================":"",
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/helpers/api_helper.dart';
|
||||
import 'package:fcs/helpers/firebase_helper.dart';
|
||||
@@ -11,9 +14,10 @@ class CartonDataProvider {
|
||||
static final CartonDataProvider instance = CartonDataProvider._();
|
||||
CartonDataProvider._();
|
||||
|
||||
Future<void> createCarton(Carton carton) async {
|
||||
return await requestAPI("/cartons", "POST",
|
||||
Future<Carton> createCarton(Carton carton) async {
|
||||
var data = await requestAPI("/cartons", "POST",
|
||||
payload: carton.toMap(), token: await getToken());
|
||||
return Carton.fromMap(data, data['id']);
|
||||
}
|
||||
|
||||
Future<void> updateCarton(Carton carton) async {
|
||||
@@ -30,4 +34,32 @@ class CartonDataProvider {
|
||||
return await requestAPI("/cartons/deliver", "PUT",
|
||||
payload: carton.toMap(), token: await getToken());
|
||||
}
|
||||
|
||||
Future<List<Carton>> searchCarton(String term) async {
|
||||
if (term == null || term == '') return List();
|
||||
|
||||
// var bytes = utf8.encode(term);
|
||||
// var base64Str = base64.encode(bytes);
|
||||
// HtmlEscape htmlEscape = const HtmlEscape();
|
||||
// String escapeBuyer = htmlEscape.convert(base64Str);
|
||||
|
||||
try {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await Firestore.instance
|
||||
.collection(path)
|
||||
.where("carton_number", isEqualTo: term)
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cargos])
|
||||
.where("status", isEqualTo: carton_packed_status)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("user_name")
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
log.warning("carton error:" + e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class RateDataProvider {
|
||||
.collection(config_collection)
|
||||
.document(rate_doc_id)
|
||||
.collection(cargo_types_collection)
|
||||
.where("custom_duty", isEqualTo: false)
|
||||
.snapshots();
|
||||
|
||||
await for (var snaps in snapshots) {
|
||||
@@ -48,18 +49,19 @@ class RateDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<CustomDuty>> _customDutiesStream() async* {
|
||||
List<CustomDuty> customDuries = [];
|
||||
Stream<List<CargoType>> _customDutiesStream() async* {
|
||||
List<CargoType> customDuries = [];
|
||||
Stream<QuerySnapshot> snapshots = Firestore.instance
|
||||
.collection(config_collection)
|
||||
.document(rate_doc_id)
|
||||
.collection(custom_duties_collection)
|
||||
.collection(cargo_types_collection)
|
||||
.where("custom_duty", isEqualTo: true)
|
||||
.snapshots();
|
||||
|
||||
await for (var snaps in snapshots) {
|
||||
customDuries = [];
|
||||
customDuries = snaps.documents.map((snap) {
|
||||
return CustomDuty.fromMap(snap.data, snap.documentID);
|
||||
return CargoType.fromMap(snap.data, snap.documentID);
|
||||
}).toList();
|
||||
yield customDuries;
|
||||
}
|
||||
@@ -84,7 +86,7 @@ class RateDataProvider {
|
||||
|
||||
StreamSubscription<Rate> rateListener;
|
||||
StreamSubscription<List<CargoType>> cargoListener;
|
||||
StreamSubscription<List<CustomDuty>> customListener;
|
||||
StreamSubscription<List<CargoType>> customListener;
|
||||
StreamSubscription<List<DiscountByWeight>> discountListener;
|
||||
Stream<Rate> rate() {
|
||||
Future<void> _start() async {
|
||||
|
||||
@@ -15,7 +15,7 @@ class CartonServiceImp implements CartonService {
|
||||
final CartonDataProvider cartonDataProvider;
|
||||
|
||||
@override
|
||||
Future<void> createCarton(Carton carton) {
|
||||
Future<Carton> createCarton(Carton carton) {
|
||||
return cartonDataProvider.createCarton(carton);
|
||||
}
|
||||
|
||||
@@ -33,4 +33,9 @@ class CartonServiceImp implements CartonService {
|
||||
Future<void> deliver(Carton carton) {
|
||||
return cartonDataProvider.deliver(carton);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Carton>> searchCarton(String term) {
|
||||
return cartonDataProvider.searchCarton(term);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
|
||||
abstract class CartonService {
|
||||
Future<void> createCarton(Carton carton);
|
||||
Future<Carton> createCarton(Carton carton);
|
||||
Future<void> updateCarton(Carton carton);
|
||||
Future<void> deleteCarton(Carton carton);
|
||||
Future<void> deliver(Carton carton);
|
||||
Future<List<Carton>> searchCarton(String term);
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ const shipment_courier_dropoff = "Courier drop off";
|
||||
|
||||
//Carton types
|
||||
const carton_from_packages = "From packages";
|
||||
const carton_from_cargos="From cargos";
|
||||
const carton_from_shipments = "From shipments";
|
||||
const carton_mix_carton = "Mix carton";
|
||||
const carton_small_bag = "Small bag";
|
||||
|
||||
@@ -5,23 +5,13 @@ class CargoType {
|
||||
double weight;
|
||||
bool isChecked;
|
||||
int qty;
|
||||
bool isCutomDuty = false;
|
||||
bool isCutomDuty;
|
||||
double customDutyFee;
|
||||
|
||||
double get calAmount => (calRate ?? 0) * (calWeight ?? 0);
|
||||
|
||||
double calRate;
|
||||
double calWeight;
|
||||
|
||||
factory CargoType.fromMap(Map<String, dynamic> map, String id) {
|
||||
return CargoType(
|
||||
id: id,
|
||||
name: map['name'],
|
||||
rate: map['rate']?.toDouble() ?? 0,
|
||||
weight: map['weight']?.toDouble() ?? 0,
|
||||
calWeight: map['cal_weight']?.toDouble() ?? 0,
|
||||
calRate: map['cal_rate']?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
CargoType(
|
||||
{this.id,
|
||||
this.name,
|
||||
@@ -31,7 +21,21 @@ class CargoType {
|
||||
this.calRate,
|
||||
this.isChecked = false,
|
||||
this.qty = 0,
|
||||
this.isCutomDuty = false});
|
||||
this.isCutomDuty,
|
||||
this.customDutyFee});
|
||||
|
||||
factory CargoType.fromMap(Map<String, dynamic> map, String id) {
|
||||
return CargoType(
|
||||
id: id,
|
||||
name: map['name'],
|
||||
rate: map['rate']?.toDouble() ?? 0,
|
||||
weight: map['weight']?.toDouble() ?? 0,
|
||||
calWeight: map['cal_weight']?.toDouble() ?? 0,
|
||||
calRate: map['cal_rate']?.toDouble() ?? 0,
|
||||
isCutomDuty: map['custom_duty'] ?? false,
|
||||
customDutyFee: (map['custom_duty_fee'] ?? 0).toDouble(),
|
||||
qty: (map['qty'] ?? 0).toInt());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
@@ -41,6 +45,9 @@ class CargoType {
|
||||
'weight': weight,
|
||||
'cal_weight': calWeight,
|
||||
'cal_rate': calRate,
|
||||
'custom_duty': isCutomDuty,
|
||||
'custom_duty_fee': customDutyFee,
|
||||
'qty': qty
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,4 +69,10 @@ class CargoType {
|
||||
bool isChangedForEdit(CargoType cargoType) {
|
||||
return cargoType.name != this.name || cargoType.rate != this.rate;
|
||||
}
|
||||
|
||||
bool isChangedForEditCustomDuty(CargoType cargoType) {
|
||||
return cargoType.name != this.name ||
|
||||
cargoType.customDutyFee != this.customDutyFee ||
|
||||
cargoType.rate != this.rate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,10 @@ class Carton {
|
||||
String id;
|
||||
String shipmentID;
|
||||
String shipmentNumber;
|
||||
String senderID;
|
||||
String senderFCSID;
|
||||
String senderName;
|
||||
String receiverID;
|
||||
String receiverFCSID;
|
||||
String receiverName;
|
||||
String receiverAddress;
|
||||
@@ -38,7 +40,6 @@ class Carton {
|
||||
String mixCartonNumber;
|
||||
String cartonSizeID;
|
||||
String cartonSizeName;
|
||||
String mixBoxType;
|
||||
|
||||
int rate;
|
||||
int weight;
|
||||
@@ -56,6 +57,11 @@ class Carton {
|
||||
DeliveryAddress deliveryAddress;
|
||||
Shipment shipment;
|
||||
|
||||
//for mix box
|
||||
String mixBoxType;
|
||||
List<Carton> mixCartons;
|
||||
List<String> mixCartonIDs;
|
||||
|
||||
int get amount => rate != null && weight != null ? rate * weight : 0;
|
||||
|
||||
String get packageNumber =>
|
||||
@@ -126,8 +132,10 @@ class Carton {
|
||||
{this.id,
|
||||
this.shipmentID,
|
||||
this.shipmentNumber,
|
||||
this.senderID,
|
||||
this.senderFCSID,
|
||||
this.senderName,
|
||||
this.receiverID,
|
||||
this.receiverFCSID,
|
||||
this.receiverName,
|
||||
this.receiverNumber,
|
||||
@@ -164,13 +172,16 @@ class Carton {
|
||||
this.deliveryAddress,
|
||||
this.cartonSizeID,
|
||||
this.cartonSizeName,
|
||||
this.mixBoxType});
|
||||
this.mixBoxType,
|
||||
this.mixCartons,
|
||||
this.mixCartonIDs});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
|
||||
List _cargoTypes = cargoTypes?.map((c) => c.toMap())?.toList() ?? [];
|
||||
List _packages = packages?.map((c) => c.toJson())?.toList();
|
||||
List _mixCartons = mixCartons?.map((c) => c.toJson())?.toList();
|
||||
return {
|
||||
"id": id,
|
||||
'id': id,
|
||||
'fcs_shipment_id': fcsShipmentID,
|
||||
'user_id': userID,
|
||||
'cargo_types': _cargoTypes,
|
||||
@@ -181,6 +192,14 @@ class Carton {
|
||||
'delivery_address': deliveryAddress?.toMap(),
|
||||
'carton_type': cartonType,
|
||||
'mix_carton_id': mixCartonID,
|
||||
'mix_box_type': mixBoxType,
|
||||
'mix_cartons': _mixCartons,
|
||||
'receiver_id': receiverID,
|
||||
'receiver_fcs_id': receiverFCSID,
|
||||
'receiver_name': receiverName,
|
||||
'sender_id': senderID,
|
||||
'sender_fcs_id': senderFCSID,
|
||||
'sender_name': senderName
|
||||
};
|
||||
}
|
||||
|
||||
@@ -192,6 +211,11 @@ class Carton {
|
||||
List<Map<String, dynamic>>.from(map['cargo_types'] ?? []);
|
||||
var cargoTypes =
|
||||
cargoTypesMaps.map((e) => CargoType.fromMap(e, e["id"])).toList();
|
||||
var mixCartonsMaps =
|
||||
List<Map<String, dynamic>>.from(map['mix_cartons'] ?? []);
|
||||
var _mixCartons =
|
||||
mixCartonsMaps.map((e) => Carton.fromMap(e, e["id"])).toList();
|
||||
|
||||
return Carton(
|
||||
id: docID,
|
||||
arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null,
|
||||
@@ -199,9 +223,9 @@ class Carton {
|
||||
shipmentNumber: map['shipment_number'],
|
||||
receiverNumber: map['receiver_number'],
|
||||
boxNumber: map['box_number'],
|
||||
length: map['length'],
|
||||
width: map['width'],
|
||||
height: map['height'],
|
||||
length: double.tryParse(map['length']?.toString()),
|
||||
width: double.tryParse(map['width']?.toString()),
|
||||
height: double.tryParse(map['height']?.toString()),
|
||||
userName: map['user_name'],
|
||||
fcsID: map['fcs_id'],
|
||||
cartonType: map['carton_type'],
|
||||
@@ -215,7 +239,44 @@ class Carton {
|
||||
status: map['status'],
|
||||
packageIDs: List<String>.from(map['package_ids'] ?? []),
|
||||
deliveryAddress: _da,
|
||||
cargoTypes: cargoTypes);
|
||||
cargoTypes: cargoTypes,
|
||||
mixBoxType: map['mix_box_type'],
|
||||
mixCartons: _mixCartons,
|
||||
receiverID: map['receiver_id'],
|
||||
receiverFCSID: map['receiver_fcs_id'],
|
||||
receiverName: map['receiver_name'],
|
||||
senderID: map['sender_id'],
|
||||
senderFCSID: map['sender_fcs_id'],
|
||||
senderName: map['sender_name'],
|
||||
mixCartonIDs: List<String>.from(map['mix_carton_ids'] ?? []),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
|
||||
List _packages = packages?.map((c) => c.toJson())?.toList();
|
||||
List _mixCartons = mixCartons?.map((c) => c.toJson())?.toList();
|
||||
return {
|
||||
'id': id,
|
||||
'fcs_shipment_id': fcsShipmentID,
|
||||
'user_id': userID,
|
||||
'cargo_types': _cargoTypes,
|
||||
'packages': _packages,
|
||||
'length': length,
|
||||
'width': width,
|
||||
'height': height,
|
||||
'delivery_address': deliveryAddress?.toMap(),
|
||||
'carton_type': cartonType,
|
||||
'mix_carton_id': mixCartonID,
|
||||
'mix_box_type': mixBoxType,
|
||||
'mix_cartons': _mixCartons,
|
||||
'receiver_id': receiverID,
|
||||
'receiver_fcs_id': receiverFCSID,
|
||||
'receiver_name': receiverName,
|
||||
'sender_id': senderID,
|
||||
'sender_fcs_id': senderFCSID,
|
||||
'sender_name': senderName
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -26,6 +26,21 @@ class CartonSize {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
if (identical(this, other)) {
|
||||
return true;
|
||||
}
|
||||
return other.id == this.id;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
int result = 17;
|
||||
result = 37 * result + id.hashCode;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isChangedForEdit(CartonSize cartonSize) {
|
||||
return cartonSize.name != this.name ||
|
||||
cartonSize.length != this.length ||
|
||||
|
||||
@@ -138,6 +138,14 @@ class Package {
|
||||
package.fcsID != this.fcsID;
|
||||
}
|
||||
|
||||
bool isChangedForEditProcessing(Package package) {
|
||||
return package.trackingID != this.trackingID ||
|
||||
package.fcsID != this.fcsID ||
|
||||
package.market != this.market ||
|
||||
package.desc != this.desc ||
|
||||
package.remark != this.remark;
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is Package && other.id == id;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
|
||||
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
||||
|
||||
import 'cargo_type.dart';
|
||||
@@ -12,7 +12,7 @@ class Rate {
|
||||
double diffWeightRate;
|
||||
|
||||
List<CargoType> cargoTypes;
|
||||
List<CustomDuty> customDuties;
|
||||
List<CargoType> customDuties;
|
||||
List<DiscountByWeight> discountByWeights;
|
||||
|
||||
DiscountByWeight getDiscountByWeight(double weight) {
|
||||
|
||||
@@ -7,6 +7,7 @@ class DeliveryAddress {
|
||||
String state;
|
||||
String phoneNumber;
|
||||
bool isDefault;
|
||||
String userID;
|
||||
DeliveryAddress(
|
||||
{this.id,
|
||||
this.fullName,
|
||||
@@ -15,6 +16,7 @@ class DeliveryAddress {
|
||||
this.city,
|
||||
this.state,
|
||||
this.phoneNumber,
|
||||
this.userID,
|
||||
this.isDefault = false});
|
||||
|
||||
factory DeliveryAddress.fromMap(Map<String, dynamic> map, String docID) {
|
||||
@@ -39,6 +41,7 @@ class DeliveryAddress {
|
||||
'city': city,
|
||||
'state': state,
|
||||
'phone_number': phoneNumber,
|
||||
'user_id': userID,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
CustomDuty customDuty = await Navigator.of(context).push(
|
||||
CargoType customDuty = await Navigator.of(context).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
CustomList(selected: true)));
|
||||
@@ -143,14 +143,20 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
|
||||
);
|
||||
}
|
||||
|
||||
_addCustom(CustomDuty customDuty) {
|
||||
_addCustom(CargoType customDuty) {
|
||||
if (customDuty == null) return;
|
||||
|
||||
if (cargos.any((c) => c.name == customDuty.productType)) return;
|
||||
if (cargos.any((c) => c.name == customDuty.name)) return;
|
||||
|
||||
// setState(() {
|
||||
// cargos.add(CargoType(
|
||||
// name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0));
|
||||
// });
|
||||
|
||||
setState(() {
|
||||
cargos.add(CargoType(
|
||||
name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0));
|
||||
customDuty.qty = 1;
|
||||
customDuty.isChecked = false;
|
||||
cargos.add(customDuty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,8 @@ class _CargoTableState extends State<CargoTable> {
|
||||
context: context,
|
||||
builder: (_) => DialogInput(
|
||||
label: "shipment.cargo.total",
|
||||
value: totalWeight.toStringAsFixed(2)));
|
||||
value: totalWeight.toStringAsFixed(2)),
|
||||
);
|
||||
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
|
||||
@@ -10,13 +10,17 @@ import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/carton_package_table.dart';
|
||||
import 'package:fcs/pages/carton_search/carton_search.dart';
|
||||
import 'package:fcs/pages/carton_size/carton_size_list.dart';
|
||||
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
||||
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
import 'package:fcs/pages/user_search/user_serach.dart';
|
||||
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
||||
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
||||
import 'package:fcs/pages/widgets/length_picker.dart';
|
||||
import 'package:fcs/pages/widgets/local_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
||||
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
|
||||
@@ -27,9 +31,9 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'carton_list_row.dart';
|
||||
import 'cargo_type_addtion.dart';
|
||||
import 'carton_cargo_table.dart';
|
||||
import 'carton_row.dart';
|
||||
import 'mix_carton_editor.dart';
|
||||
import 'model/carton_model.dart';
|
||||
import '../carton_size/model/carton_size_model.dart';
|
||||
import 'package_carton_editor.dart';
|
||||
@@ -47,21 +51,31 @@ 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 = [];
|
||||
|
||||
Carton _carton;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
User _user;
|
||||
String _selectedCartonType;
|
||||
String _selectedMixType;
|
||||
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
FcsShipment _fcsShipment;
|
||||
List<FcsShipment> _fcsShipments;
|
||||
Carton _mixCarton;
|
||||
List<Carton> _cartons = [];
|
||||
CartonSize selectedCatonSize;
|
||||
|
||||
//for mix carton
|
||||
List<Carton> _mixCartons = [];
|
||||
String _selectedMixBoxType;
|
||||
|
||||
//for carton from cargos
|
||||
User consignee;
|
||||
User sender;
|
||||
List<Carton> _cartonsForCargos = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -82,9 +96,29 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_heightController.text = _carton.height.toString();
|
||||
_lengthController.text = _carton.length.toString();
|
||||
_selectedCartonType = _carton.cartonType;
|
||||
_cargoTypes = List.from(_carton.cargoTypes);
|
||||
_isNew = false;
|
||||
_user = User(fcsID: _carton.fcsID, name: _carton.userName);
|
||||
_loadPackages();
|
||||
_user = User(
|
||||
id: _carton.userID, fcsID: _carton.fcsID, name: _carton.userName);
|
||||
consignee = User(
|
||||
id: _carton.receiverID,
|
||||
fcsID: _carton.receiverFCSID,
|
||||
name: _carton.receiverName);
|
||||
sender = User(
|
||||
id: _carton.senderID,
|
||||
fcsID: _carton.senderID,
|
||||
name: _carton.senderName);
|
||||
_selectedMixBoxType = _carton.mixBoxType ?? "";
|
||||
this._mixCartons =
|
||||
_carton.mixCartons == null ? [] : List.from(_carton.mixCartons);
|
||||
bool isMixBox = _carton.cartonType == carton_mix_box;
|
||||
bool isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
if (isFromPackages) _loadPackages();
|
||||
|
||||
if (!isMixBox) {
|
||||
_getDeliverAddresses();
|
||||
_getCartonSize();
|
||||
}
|
||||
} else {
|
||||
_carton = Carton(
|
||||
cargoTypes: [],
|
||||
@@ -95,14 +129,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_heightController.text = "0";
|
||||
_isNew = true;
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_selectedMixType = mix_delivery;
|
||||
_selectedMixBoxType = mix_delivery;
|
||||
_loadFcsShipments();
|
||||
_cartons = [Carton(cartonNumber: "A100B-1#3", userName: "Seven 7")];
|
||||
|
||||
_mixCartons = [
|
||||
Carton(cartonNumber: "A100B-1#1", userName: "Seven 7"),
|
||||
Carton(cartonNumber: "A100B-1#2", userName: "Seven 7"),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,19 +180,19 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
setState(() {
|
||||
_carton.packages = packages;
|
||||
});
|
||||
_populateDeliveryAddress();
|
||||
// _populateDeliveryAddress();
|
||||
}
|
||||
|
||||
_populateDeliveryAddress() {
|
||||
if (_carton.packages == null) return;
|
||||
var d = _carton.packages
|
||||
.firstWhere((p) => p.isChecked && p.deliveryAddress != null,
|
||||
orElse: () => null)
|
||||
?.deliveryAddress;
|
||||
setState(() {
|
||||
_deliveryAddress = d;
|
||||
});
|
||||
}
|
||||
// _populateDeliveryAddress() {
|
||||
// if (_carton.packages == null) return;
|
||||
// var d = _carton.packages
|
||||
// .firstWhere((p) => p.isChecked && p.deliveryAddress != null,
|
||||
// orElse: () => null)
|
||||
// ?.deliveryAddress;
|
||||
// setState(() {
|
||||
// _deliveryAddress = d;
|
||||
// });
|
||||
// }
|
||||
|
||||
_calShipmentWeight() {
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
@@ -175,6 +203,31 @@ 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) {
|
||||
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
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
@@ -183,6 +236,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isMixBox = _selectedCartonType == carton_mix_box;
|
||||
|
||||
final shipmentBox = DisplayText(
|
||||
@@ -219,13 +274,12 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_isNew
|
||||
? IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () =>
|
||||
searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this._user = u;
|
||||
_loadPackages();
|
||||
});
|
||||
}))
|
||||
}, popPage: true))
|
||||
: Container(),
|
||||
],
|
||||
));
|
||||
@@ -238,7 +292,9 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
final createBtn = LocalButton(
|
||||
textKey: "box.complete.packaging",
|
||||
callBack: _save,
|
||||
callBack: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
|
||||
final saveBtn = LocalButton(
|
||||
@@ -264,54 +320,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
if (_user == null && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Please select customer");
|
||||
return;
|
||||
}
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID =
|
||||
_isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.userID = _user?.id;
|
||||
carton.packages =
|
||||
_carton.packages.where((e) => e.isChecked).toList();
|
||||
|
||||
carton.cargoTypes = _carton.cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
|
||||
carton.deliveryAddress = _carton.deliveryAddress;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
PackageCartonEditor(carton: carton, isNew: _isNew)),
|
||||
);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}),
|
||||
onPressed: _addCarton),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -330,16 +339,16 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
Row(
|
||||
children: boxModel.mixTypes.map((e) {
|
||||
children: boxModel.mixBoxTypes.map((e) {
|
||||
return Row(
|
||||
children: [
|
||||
Radio(
|
||||
value: e,
|
||||
groupValue: _selectedMixType,
|
||||
groupValue: _selectedMixBoxType,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_selectedMixType = v;
|
||||
_selectedMixBoxType = v;
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -352,6 +361,36 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
),
|
||||
);
|
||||
|
||||
final mixTypeDisplayBox = Container(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 5),
|
||||
child: LocalText(
|
||||
context,
|
||||
"box.mix_type",
|
||||
color: primaryColor,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.check,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
Text(_selectedMixBoxType ?? "")
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final mixcartonTitleBox = Container(
|
||||
child: LocalTitle(
|
||||
textKey: "box.mix_caton_title",
|
||||
@@ -360,15 +399,140 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => MixCartonEditor()),
|
||||
);
|
||||
onPressed: () async {
|
||||
searchCarton(context, callbackCartonSelect: (c) {
|
||||
_addMixCarton(c);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
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.clear();
|
||||
_cargoTypes.addAll(cargos);
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
final cargoTableBox = CargoTable(
|
||||
isNew: _isNew,
|
||||
cargoTypes: _cargoTypes,
|
||||
onAdd: (c) => _addCargo(c),
|
||||
onRemove: (c) => _removeCargo(c),
|
||||
);
|
||||
|
||||
final lengthBox = LengthPicker(
|
||||
controller: _lengthController,
|
||||
lableKey: "box.length",
|
||||
isReadOnly: true,
|
||||
);
|
||||
final widthBox = LengthPicker(
|
||||
controller: _widthController,
|
||||
lableKey: "box.width",
|
||||
isReadOnly: true,
|
||||
);
|
||||
final heightBox = LengthPicker(
|
||||
controller: _heightController,
|
||||
lableKey: "box.height",
|
||||
isReadOnly: true,
|
||||
);
|
||||
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 createMixCarton = LocalButton(
|
||||
textKey: _isNew ? "box.mix_carton_btn" : "btn.save",
|
||||
callBack: _creatMixCarton,
|
||||
);
|
||||
|
||||
final consigneefcsIDBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: consignee != null ? consignee.fcsID : "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this.consignee = u;
|
||||
});
|
||||
}, popPage: true)),
|
||||
],
|
||||
);
|
||||
|
||||
final consigneeNameBox = DisplayText(
|
||||
text: consignee != null ? consignee.name : "",
|
||||
labelTextKey: "processing.consignee.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final consigneeBox = Container(
|
||||
child: Column(
|
||||
children: [
|
||||
consigneefcsIDBox,
|
||||
consigneeNameBox,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final shipperIDBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: sender != null ? sender.fcsID : "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this.sender = u;
|
||||
});
|
||||
}, popPage: true)),
|
||||
],
|
||||
);
|
||||
|
||||
final shipperNamebox = DisplayText(
|
||||
text: sender != null ? sender.name : "",
|
||||
labelTextKey: "processing.shipper.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final shipperBox = Container(
|
||||
child: Column(
|
||||
children: [
|
||||
shipperIDBox,
|
||||
shipperNamebox,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -391,7 +555,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(
|
||||
context,
|
||||
"box.info.title",
|
||||
_isNew ? "box.info.title" : "box.edit.title",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
@@ -408,44 +572,98 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
cartonTypeBox,
|
||||
LocalTitle(textKey: "box.shipment_info"),
|
||||
_isNew ? fcsShipmentsBox : shipmentBox,
|
||||
isMixBox ? mixTypeBox : Container(),
|
||||
isMixBox
|
||||
? _isNew
|
||||
? mixTypeBox
|
||||
: mixTypeDisplayBox
|
||||
: Container(),
|
||||
...(isMixBox
|
||||
? [
|
||||
mixcartonTitleBox,
|
||||
Column(
|
||||
children: _getMixCartons(
|
||||
context,
|
||||
this._mixCartons,
|
||||
)),
|
||||
children: _getMixCartons(context, this._mixCartons)),
|
||||
]
|
||||
: [
|
||||
fcsIDBox,
|
||||
namebox,
|
||||
CartonPackageTable(
|
||||
isFromPackages ? fcsIDBox : Container(),
|
||||
isFromPackages ? namebox : Container(),
|
||||
isFromPackages
|
||||
? CartonPackageTable(
|
||||
packages: _carton.packages,
|
||||
onSelect: (p, checked) {
|
||||
if (checked &&
|
||||
_deliveryAddress != null &&
|
||||
p.deliveryAddress?.id != _deliveryAddress.id) {
|
||||
p.deliveryAddress?.id !=
|
||||
_deliveryAddress.id) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
p.isChecked = checked;
|
||||
});
|
||||
_populateDeliveryAddress();
|
||||
// _populateDeliveryAddress();
|
||||
},
|
||||
)
|
||||
: Container(),
|
||||
isFromCargos
|
||||
? Container(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(child: consigneeBox),
|
||||
Flexible(child: shipperBox)
|
||||
],
|
||||
),
|
||||
cartonTitleBox,
|
||||
Column(
|
||||
)
|
||||
: Container(),
|
||||
_isNew ? cartonTitleBox : Container(),
|
||||
_isNew
|
||||
? Column(
|
||||
children: _getCartons(
|
||||
context,
|
||||
this._cartons,
|
||||
)),
|
||||
isFromPackages
|
||||
? this._cartons
|
||||
: this._cartonsForCargos))
|
||||
: Container(),
|
||||
_isNew ? Container() : cargoTableTitleBox,
|
||||
_isNew ? Container() : cargoTableBox,
|
||||
_isNew
|
||||
? Container()
|
||||
: LocalTitle(textKey: "box.dimension"),
|
||||
_isNew ? Container() : cartonSizeDropdown(),
|
||||
_isNew ? Container() : dimBox,
|
||||
_isNew
|
||||
? Container()
|
||||
: LocalTitle(textKey: "box.delivery_address"),
|
||||
_isNew
|
||||
? Container()
|
||||
: DefaultDeliveryAddress(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
labelKey: "box.delivery_address",
|
||||
onTap: () async {
|
||||
DeliveryAddress d =
|
||||
await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddresses:
|
||||
_deliveryAddresses)),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
_deliveryAddress = d;
|
||||
});
|
||||
}),
|
||||
]),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
createBtn,
|
||||
isFromPackages || isFromCargos
|
||||
? _isNew
|
||||
? createBtn
|
||||
: saveBtn
|
||||
: Container(),
|
||||
isMixBox ? createMixCarton : Container(),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
@@ -456,19 +674,33 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
_addCarton(Carton carton) {
|
||||
if (carton == null) return;
|
||||
this._cartons.add(carton);
|
||||
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
|
||||
return cartons.asMap().entries.map((c) {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
if (isFromPackages) {
|
||||
_loadPackages();
|
||||
c.value.packages = _carton.packages;
|
||||
Carton _c = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => PackageCartonEditor(
|
||||
carton: c.value,
|
||||
isNew: false,
|
||||
consignee: _user,
|
||||
)),
|
||||
);
|
||||
if (_c == null) return;
|
||||
cartons.removeWhere((item) => item.id == _c.id);
|
||||
cartons.insert(c.key, _c);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
|
||||
return cartons.map((c) {
|
||||
return InkWell(
|
||||
onTap: () {},
|
||||
},
|
||||
child: CartonRow(
|
||||
key: ValueKey(c.id),
|
||||
box: c,
|
||||
key: ValueKey(c.value.id),
|
||||
box: c.value,
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
@@ -476,17 +708,16 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
List<Widget> _getMixCartons(BuildContext context, List<Carton> cartons) {
|
||||
return cartons.map((c) {
|
||||
return InkWell(
|
||||
onTap: () {},
|
||||
child: CartonRow(
|
||||
return CartonRow(
|
||||
key: ValueKey(c.id),
|
||||
box: c,
|
||||
),
|
||||
onRemove: (carton) {
|
||||
_removeMixCarton(carton);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
CartonSize selectedCatonSize;
|
||||
Widget cartonSizeDropdown() {
|
||||
List<CartonSize> _cartonSizes =
|
||||
Provider.of<CartonSizeModel>(context).getCartonSizes;
|
||||
@@ -565,70 +796,204 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
// bool isFromShipment = _selectedCartonType == carton_from_shipments;
|
||||
// bool isSmallBag = _selectedCartonType == carton_small_bag;
|
||||
// if (_user == null && (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Please select customer");
|
||||
// return;
|
||||
// }
|
||||
// if (_fcsShipment == null && _isNew) {
|
||||
// showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
// return;
|
||||
// }
|
||||
// if ((_carton.cargoTypes?.length ?? 0) == 0 &&
|
||||
// (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
// return;
|
||||
// }
|
||||
// double l = double.parse(_lengthController.text, (s) => 0);
|
||||
// double w = double.parse(_widthController.text, (s) => 0);
|
||||
// double h = double.parse(_heightController.text, (s) => 0);
|
||||
// if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) {
|
||||
// showMsgDialog(context, "Error", "Invalid dimension");
|
||||
// return;
|
||||
// }
|
||||
// if (_deliveryAddress == null && (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Invalid delivery address");
|
||||
// return;
|
||||
// }
|
||||
// if (isSmallBag && _mixCarton == null && _isNew) {
|
||||
// showMsgDialog(context, "Error", "Invalid mix carton");
|
||||
// return;
|
||||
// }
|
||||
_addCargo(CargoType cargo) {
|
||||
if (cargo == null) return;
|
||||
setState(() {
|
||||
_cargoTypes.remove(cargo);
|
||||
_cargoTypes.add(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
// Carton carton = Carton();
|
||||
// carton.id = _carton.id;
|
||||
// carton.cartonType = _selectedCartonType;
|
||||
// carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
// carton.userID = _user?.id;
|
||||
// carton.cargoTypes = _carton.cargoTypes;
|
||||
// carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
// carton.mixCartonID = _mixCarton?.id;
|
||||
// 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 (_isNew) {
|
||||
// await cartonModel.createCarton(carton);
|
||||
// } else {
|
||||
// await cartonModel.updateCarton(carton);
|
||||
// }
|
||||
// Navigator.pop(context, true);
|
||||
// } catch (e) {
|
||||
// showMsgDialog(context, "Error", e.toString());
|
||||
// } finally {
|
||||
// setState(() {
|
||||
// _isLoading = false;
|
||||
// });
|
||||
// }
|
||||
_removeCargo(CargoType cargo) {
|
||||
setState(() {
|
||||
_cargoTypes.remove(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_addCarton() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_user == null && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Please select FCS ID");
|
||||
return;
|
||||
}
|
||||
|
||||
if (consignee == null && isFromCargos) {
|
||||
showMsgDialog(context, "Error", "Please select consignee's FCS ID");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender == null && isFromCargos) {
|
||||
showMsgDialog(context, "Error", "Please select sender's FCS ID");
|
||||
return;
|
||||
}
|
||||
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
if (isFromPackages) {
|
||||
carton.userID = _user?.id;
|
||||
carton.fcsID = _user?.fcsID;
|
||||
carton.userName = _user?.name;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
carton.receiverID = consignee?.id;
|
||||
carton.receiverFCSID = consignee?.fcsID;
|
||||
carton.receiverName = consignee?.name;
|
||||
carton.senderID = sender?.id;
|
||||
carton.senderFCSID = sender?.fcsID;
|
||||
carton.senderName = sender?.name;
|
||||
}
|
||||
|
||||
carton.cargoTypes = _carton.cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
carton.deliveryAddress = _carton.deliveryAddress;
|
||||
|
||||
try {
|
||||
Carton _c = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => PackageCartonEditor(
|
||||
carton: carton,
|
||||
isNew: _isNew,
|
||||
consignee: _user,
|
||||
)),
|
||||
);
|
||||
if (_c == null) return;
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
Carton _carton = await cartonModel.getCarton(_c.id);
|
||||
if (isFromPackages) {
|
||||
_cartons.add(_carton);
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
_cartonsForCargos.add(_carton);
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
_addMixCarton(Carton carton) {
|
||||
if (carton == null) return;
|
||||
if (this._mixCartons.any((c) => c.id == carton.id)) return;
|
||||
setState(() {
|
||||
this._mixCartons.add(carton);
|
||||
});
|
||||
}
|
||||
|
||||
_removeMixCarton(Carton carton) {
|
||||
setState(() {
|
||||
this._mixCartons.removeWhere((c) => c.id == carton.id);
|
||||
});
|
||||
}
|
||||
|
||||
_creatMixCarton() async {
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
if ((this._mixCartons?.length ?? 0) == 0) {
|
||||
showMsgDialog(context, "Error", "Expect at least one carton");
|
||||
return;
|
||||
}
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.mixBoxType = _selectedMixBoxType;
|
||||
carton.mixCartons = this._mixCartons;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
if (_isNew) {
|
||||
await cartonModel.createCarton(carton);
|
||||
} else {
|
||||
await cartonModel.updateCarton(carton);
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_save() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCargos)) {
|
||||
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
return;
|
||||
}
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
if ((l <= 0 || w <= 0 || h <= 0) && (isFromPackages || isFromCargos)) {
|
||||
showMsgDialog(context, "Error", "Invalid dimension");
|
||||
return;
|
||||
}
|
||||
if (_deliveryAddress == null && (isFromPackages || isFromCargos)) {
|
||||
showMsgDialog(context, "Error", "Invalid delivery address");
|
||||
return;
|
||||
}
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
if (isFromPackages) {
|
||||
carton.userID = _user?.id;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
if (isFromCargos) {
|
||||
carton.receiverID = consignee?.id;
|
||||
carton.senderID = sender?.id;
|
||||
}
|
||||
|
||||
carton.cargoTypes = _cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
carton.deliveryAddress = _deliveryAddress;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
await cartonModel.updateCarton(carton);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/carton_size.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton_size/model/carton_size_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
@@ -49,19 +51,20 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
String selectMixBoxType;
|
||||
List<Carton> _cartons = [];
|
||||
|
||||
bool isMixBox;
|
||||
bool isFromShipments;
|
||||
bool isFromPackages;
|
||||
bool isSmallBag;
|
||||
bool isFromCartons;
|
||||
bool isEdiable;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_box = widget.box;
|
||||
|
||||
// _box.cartonType = carton_from_cargos;
|
||||
// _box.cartonType = carton_mix_box;
|
||||
//for shipment weight
|
||||
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
||||
.rate
|
||||
@@ -72,6 +75,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
|
||||
_updateBoxData();
|
||||
_loadPackages();
|
||||
_loadMixCartons();
|
||||
}
|
||||
|
||||
_updateBoxData() {
|
||||
@@ -84,20 +88,25 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
isFromShipments = _box.cartonType == carton_from_shipments;
|
||||
isFromPackages = _box.cartonType == carton_from_packages;
|
||||
isSmallBag = _box.cartonType == carton_small_bag;
|
||||
isEdiable = !isMixBox &&
|
||||
(isFromPackages || isSmallBag) &&
|
||||
isFromCartons = _box.cartonType == carton_from_cargos;
|
||||
|
||||
isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
|
||||
_box.status == carton_packed_status;
|
||||
selectMixBoxType = _box.mixBoxType ?? "Mix Delivery";
|
||||
_cartons = [
|
||||
Carton(
|
||||
cartonNumber: "A100B-1#1",
|
||||
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||
userName: "Seven 7"),
|
||||
Carton(
|
||||
cartonNumber: "A100B-1#2",
|
||||
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||
userName: "Seven 7"),
|
||||
];
|
||||
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 {
|
||||
@@ -122,6 +131,20 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
});
|
||||
}
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_box.mixCartons = catons;
|
||||
});
|
||||
}
|
||||
|
||||
_calShipmentWeight() {
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
@@ -164,6 +187,55 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final consigneefcsIDBox = DisplayText(
|
||||
text: _box.receiverFCSID != null ? _box.receiverFCSID : "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
);
|
||||
|
||||
final consigneeNameBox = DisplayText(
|
||||
text: _box.receiverName != null ? _box.receiverName : "",
|
||||
labelTextKey: "processing.consignee.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final consigneeBox = Container(
|
||||
child: Column(
|
||||
children: [
|
||||
consigneefcsIDBox,
|
||||
consigneeNameBox,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final shipperIDBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: _box.senderFCSID != null ? _box.senderFCSID : "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
)),
|
||||
],
|
||||
);
|
||||
|
||||
final shipperNamebox = DisplayText(
|
||||
text: _box.senderName != null ? _box.senderName : "",
|
||||
labelTextKey: "processing.shipper.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final shipperBox = Container(
|
||||
child: Column(
|
||||
children: [
|
||||
shipperIDBox,
|
||||
shipperNamebox,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final lengthBox = LengthPicker(
|
||||
controller: _lengthController,
|
||||
lableKey: "box.length",
|
||||
@@ -275,17 +347,29 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
cartonTypeBox,
|
||||
LocalTitle(textKey: "box.shipment_info"),
|
||||
shipmentBox,
|
||||
isSmallBag ? mixCartonNumberBox : Container(),
|
||||
isMixBox ? Container() : fcsIDBox,
|
||||
isMixBox ? Container() : customerNameBox,
|
||||
isMixBox ? mixTypeBox : Container(),
|
||||
isMixBox ? LocalTitle(textKey: "boxes.title") : Container(),
|
||||
// isSmallBag ? mixCartonNumberBox : Container(),
|
||||
isMixBox
|
||||
? Column(
|
||||
children: _getCartons(
|
||||
context,
|
||||
this._cartons,
|
||||
))
|
||||
? Container()
|
||||
: isFromPackages
|
||||
? fcsIDBox
|
||||
: Container(),
|
||||
isMixBox
|
||||
? Container()
|
||||
: isFromPackages
|
||||
? customerNameBox
|
||||
: Container(),
|
||||
isFromCartons
|
||||
? Row(
|
||||
children: [
|
||||
Flexible(child: consigneeBox),
|
||||
Flexible(child: shipperBox)
|
||||
],
|
||||
)
|
||||
: Container(),
|
||||
isMixBox ? mixTypeBox : Container(),
|
||||
isMixBox ? LocalTitle(textKey: "box.mix_caton_title") : Container(),
|
||||
isMixBox
|
||||
? Column(children: _getCartons(context, _box.mixCartons))
|
||||
: Container(),
|
||||
isFromPackages || isSmallBag
|
||||
? CartonPackageTable(
|
||||
@@ -294,7 +378,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
: Container(),
|
||||
isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"),
|
||||
isMixBox ? Container() : cargoTableBox,
|
||||
...(isFromPackages
|
||||
...(isFromPackages || isFromCartons
|
||||
? [
|
||||
LocalTitle(textKey: "box.dimension"),
|
||||
cartonSizeBox,
|
||||
@@ -326,6 +410,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
|
||||
_gotoEditor() async {
|
||||
widget.box.mixCartons=_box.mixCartons;
|
||||
bool updated = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
|
||||
@@ -335,9 +420,10 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
var c = await cartonModel.getCarton(widget.box.id);
|
||||
setState(() {
|
||||
_box = c;
|
||||
_loadPackages();
|
||||
_loadMixCartons();
|
||||
_updateBoxData();
|
||||
});
|
||||
_loadPackages();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton_search/carton_search.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 'carton_row.dart';
|
||||
|
||||
class MixCartonEditor extends StatefulWidget {
|
||||
final Carton box;
|
||||
MixCartonEditor({this.box});
|
||||
|
||||
@override
|
||||
_MixCartonEditorState createState() => _MixCartonEditorState();
|
||||
}
|
||||
|
||||
class _MixCartonEditorState extends State<MixCartonEditor> {
|
||||
Carton _box;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
List<Carton> _cartons = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.box != null) {
|
||||
_box = widget.box;
|
||||
_isNew = false;
|
||||
} else {
|
||||
_isNew = true;
|
||||
_box = Carton(cargoTypes: []);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final createBtn = LocalButton(
|
||||
textKey: "box.mix_carton_btn",
|
||||
callBack: _creatCarton,
|
||||
);
|
||||
|
||||
final cargoTableTitleBox = LocalTitle(
|
||||
textKey: "boxes.title",
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () => searchCarton(context, callbackCartonSelect: (c) {
|
||||
_addMixCarton(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,
|
||||
"box.min_caton.form.title",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
cargoTableTitleBox,
|
||||
Column(
|
||||
children: _getCartons(
|
||||
context,
|
||||
this._cartons,
|
||||
)),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
createBtn
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
|
||||
return cartons.map((c) {
|
||||
return CartonRow(
|
||||
key: ValueKey(c.id),
|
||||
box: c,
|
||||
onRemove: (carton) {
|
||||
_removeMixCarton(carton);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_addMixCarton(Carton carton) {
|
||||
if (carton == null) return;
|
||||
if (this._cartons.any((c) => c.cartonNumber == carton.cartonNumber)) return;
|
||||
setState(() {
|
||||
this._cartons.add(carton);
|
||||
});
|
||||
}
|
||||
|
||||
_removeMixCarton(Carton carton) {
|
||||
setState(() {
|
||||
this._cartons.remove(carton);
|
||||
});
|
||||
}
|
||||
|
||||
_creatCarton() {}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import 'package:logging/logging.dart';
|
||||
|
||||
class CartonModel extends BaseModel {
|
||||
List<Carton> _boxes = [];
|
||||
List<Carton> cartons = [];
|
||||
final log = Logger('CartonModel');
|
||||
List<Carton> get boxes =>
|
||||
_selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values);
|
||||
@@ -22,6 +23,7 @@ class CartonModel extends BaseModel {
|
||||
bool isLoading = false;
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
StreamSubscription<QuerySnapshot> cartonListener;
|
||||
static List<ShipmentStatus> statusHistory = [
|
||||
ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true),
|
||||
ShipmentStatus(status: "Shipped", date: DateTime(2020, 6, 5), done: false),
|
||||
@@ -56,10 +58,15 @@ class CartonModel extends BaseModel {
|
||||
});
|
||||
}
|
||||
|
||||
List<String> cartonTypes = [carton_from_packages, carton_mix_box];
|
||||
List<String> mixTypes = [mix_delivery, mix_pickup];
|
||||
List<String> cartonTypes = [
|
||||
carton_from_packages,
|
||||
// carton_from_cargos,
|
||||
carton_mix_box
|
||||
];
|
||||
List<String> mixBoxTypes = [mix_delivery, mix_pickup];
|
||||
List<String> cartonTypesInfo = [
|
||||
carton_from_packages,
|
||||
carton_from_cargos,
|
||||
carton_mix_box,
|
||||
carton_from_shipments,
|
||||
carton_small_bag
|
||||
@@ -75,6 +82,7 @@ class CartonModel extends BaseModel {
|
||||
initData() {
|
||||
_selectedIndex = 1;
|
||||
_loadBoxes();
|
||||
_loadCartonForMixBox();
|
||||
|
||||
if (_delivered != null) _delivered.close();
|
||||
_delivered = _getDelivered();
|
||||
@@ -108,6 +116,35 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadCartonForMixBox() async {
|
||||
if (user == null || !user.hasCarton()) return;
|
||||
String path = "/$cartons_collection/";
|
||||
if (cartonListener != null) cartonListener.cancel();
|
||||
cartons = [];
|
||||
try {
|
||||
cartonListener = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("carton_type",
|
||||
whereIn: [carton_from_packages, carton_from_cargos])
|
||||
.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();
|
||||
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
}
|
||||
|
||||
Paginator _getDelivered() {
|
||||
if (user == null || !user.hasCarton()) return null;
|
||||
|
||||
@@ -145,8 +182,10 @@ class CartonModel extends BaseModel {
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
if (cartonListener != null) await cartonListener.cancel();
|
||||
if (_delivered != null) _delivered.close();
|
||||
_boxes = [];
|
||||
cartons = [];
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartons(String shipmentID) async {
|
||||
@@ -207,7 +246,7 @@ class CartonModel extends BaseModel {
|
||||
return Carton.fromMap(snap.data, snap.documentID);
|
||||
}
|
||||
|
||||
Future<void> createCarton(Carton carton) {
|
||||
Future<Carton> createCarton(Carton carton) {
|
||||
return Services.instance.cartonService.createCarton(carton);
|
||||
}
|
||||
|
||||
@@ -220,38 +259,7 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<List<Carton>> searchCarton(String term) async {
|
||||
if (term == null || term == '') return List();
|
||||
|
||||
List<Carton> _cartons = [];
|
||||
|
||||
try {
|
||||
_cartons = [
|
||||
Carton(
|
||||
cartonNumber: "A100B-1#1",
|
||||
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||
userName: "Seven 7"),
|
||||
Carton(
|
||||
cartonNumber: "A100B-1#2",
|
||||
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||
userName: "Seven 7"),
|
||||
Carton(
|
||||
cartonNumber: "A100B-1#3",
|
||||
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||
userName: "Seven 7"),
|
||||
Carton(
|
||||
cartonNumber: "A100B-1#4",
|
||||
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||
userName: "Seven 7"),
|
||||
Carton(
|
||||
cartonNumber: "A100B-1#5",
|
||||
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||
userName: "Seven 7"),
|
||||
];
|
||||
} catch (e) {
|
||||
// permission error
|
||||
log.warning("user error:" + e.toString());
|
||||
return null;
|
||||
}
|
||||
return _cartons;
|
||||
return Services.instance.cartonService.searchCarton(term);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
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';
|
||||
@@ -29,7 +31,8 @@ import 'model/carton_model.dart';
|
||||
class PackageCartonEditor extends StatefulWidget {
|
||||
final Carton carton;
|
||||
final bool isNew;
|
||||
PackageCartonEditor({this.carton, this.isNew});
|
||||
final User consignee;
|
||||
PackageCartonEditor({this.carton, this.isNew, this.consignee});
|
||||
|
||||
@override
|
||||
_PackageCartonEditorState createState() => _PackageCartonEditorState();
|
||||
@@ -43,27 +46,65 @@ 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;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.isNew) {
|
||||
_load();
|
||||
}
|
||||
|
||||
_load() {
|
||||
_carton = widget.carton;
|
||||
isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
isFromCargos = _carton.cartonType == carton_from_cargos;
|
||||
_getDeliverAddresses();
|
||||
if (widget.isNew) {
|
||||
_lengthCtl.text = "0";
|
||||
_widthCtl.text = "0";
|
||||
_heightCtl.text = "0";
|
||||
} else {
|
||||
_carton = widget.carton;
|
||||
_cargoTypes = List.from(widget.carton.cargoTypes);
|
||||
_lengthCtl.text = _carton.length.toString();
|
||||
_widthCtl.text = _carton.width.toString();
|
||||
_heightCtl.text = _carton.height.toString();
|
||||
_deliveryAddress = _carton.deliveryAddress;
|
||||
_getCartonSize();
|
||||
}
|
||||
}
|
||||
|
||||
_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) {
|
||||
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(
|
||||
@@ -94,7 +135,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
],
|
||||
);
|
||||
final createBtn = LocalButton(
|
||||
textKey: "box.new_carton_btn",
|
||||
textKey: widget.isNew ? "box.new_carton_btn" : "box.cargo.save.btn",
|
||||
callBack: _creatCarton,
|
||||
);
|
||||
|
||||
@@ -164,6 +205,9 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _deliveryAddress,
|
||||
deliveryAddresses: this._deliveryAddresses,
|
||||
user: widget.consignee,
|
||||
onAdded: () => _getDeliverAddresses(),
|
||||
)),
|
||||
);
|
||||
if (d == null) return;
|
||||
@@ -182,7 +226,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
CartonSize selectedCatonSize;
|
||||
Widget cartonSizeDropdown() {
|
||||
List<CartonSize> _cartonSizes =
|
||||
Provider.of<CartonSizeModel>(context).getCartonSizes;
|
||||
@@ -293,10 +336,21 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _carton.cartonType;
|
||||
carton.fcsShipmentID = _carton.fcsShipmentID;
|
||||
carton.userID = _carton.userID;
|
||||
carton.cargoTypes = _cargoTypes;
|
||||
if (isFromPackages) {
|
||||
carton.userID = _carton.userID;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
// carton.cartonSizeID = selectedCatonSize?.id;
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
carton.receiverID = _carton.receiverID;
|
||||
carton.receiverFCSID = _carton.receiverFCSID;
|
||||
carton.receiverName = _carton.receiverName;
|
||||
carton.senderID = _carton.senderID;
|
||||
carton.senderFCSID = _carton.senderFCSID;
|
||||
carton.senderName = _carton.senderName;
|
||||
}
|
||||
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
@@ -308,11 +362,13 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
if (widget.isNew) {
|
||||
await cartonModel.createCarton(carton);
|
||||
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);
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/model/carton_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/barcode_scanner.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'carton_list_row.dart';
|
||||
@@ -21,7 +24,7 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
|
||||
PartSearchDelegate({this.callbackCartonSelect});
|
||||
|
||||
@override
|
||||
String get searchFieldLabel => 'Search by Carton Number/Customer Name';
|
||||
String get searchFieldLabel => 'Search by Carton Number';
|
||||
|
||||
@override
|
||||
ThemeData appBarTheme(BuildContext context) {
|
||||
@@ -40,6 +43,11 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
|
||||
@override
|
||||
List<Widget> buildActions(BuildContext context) {
|
||||
return [
|
||||
IconButton(
|
||||
icon: Icon(MaterialCommunityIcons.barcode_scan,
|
||||
size: 30, color: Colors.white),
|
||||
onPressed: () => _scan(context),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.clear),
|
||||
onPressed: () => query = '',
|
||||
@@ -106,17 +114,41 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
|
||||
|
||||
@override
|
||||
Widget buildSuggestions(BuildContext context) {
|
||||
final cartonModel = Provider.of<CartonModel>(context);
|
||||
return Container(
|
||||
child: Center(
|
||||
child: Opacity(
|
||||
opacity: 0.2,
|
||||
child: Icon(
|
||||
MaterialCommunityIcons.package,
|
||||
color: primaryColor,
|
||||
size: 200,
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: ListView(
|
||||
children: cartonModel.cartons
|
||||
.map((u) => CartonListRow(
|
||||
carton: u,
|
||||
callbackCartonSelect: callbackCartonSelect,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_scan(BuildContext context) async {
|
||||
PermissionStatus permission =
|
||||
await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
|
||||
if (permission != PermissionStatus.granted) {
|
||||
Map<PermissionGroup, PermissionStatus> permissions =
|
||||
await PermissionHandler()
|
||||
.requestPermissions([PermissionGroup.camera]);
|
||||
if (permissions[PermissionGroup.camera] != PermissionStatus.granted) {
|
||||
showMsgDialog(context, "Error", "Camera permission is not granted");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String barcode = await scanBarcode();
|
||||
if (barcode != null) {
|
||||
query = barcode;
|
||||
showResults(context);
|
||||
}
|
||||
} catch (e) {
|
||||
print('error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class _CustomerListState extends State<CustomerList> {
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: Colors.white),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
_select(u);
|
||||
})),
|
||||
],
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
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/delivery_address/model/delivery_address_model.dart';
|
||||
@@ -12,7 +13,8 @@ import 'package:provider/provider.dart';
|
||||
|
||||
class DeliveryAddressEditor extends StatefulWidget {
|
||||
final DeliveryAddress deliveryAddress;
|
||||
DeliveryAddressEditor({this.deliveryAddress});
|
||||
final User user;
|
||||
DeliveryAddressEditor({this.deliveryAddress, this.user});
|
||||
|
||||
@override
|
||||
_DeliveryAddressEditorState createState() => _DeliveryAddressEditorState();
|
||||
@@ -195,6 +197,9 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
if (widget.user != null) {
|
||||
deliveryAddress.userID = widget.user.id;
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
@@ -202,7 +207,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
try {
|
||||
await deliveryAddressModel.createDeliveryAddress(deliveryAddress);
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context,true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -225,7 +230,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
try {
|
||||
await deliveryAddressModel.updateDeliveryAddress(deliveryAddress);
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context,true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -247,7 +252,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
DeliveryAddressModel deliveryAddressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
await deliveryAddressModel.deleteDeliveryAddress(_deliveryAddress);
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context,true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
|
||||
@@ -84,4 +84,16 @@ class DeliveryAddressModel extends BaseModel {
|
||||
return Services.instance.deliveryAddressService
|
||||
.selectDefalutDeliveryAddress(deliveryAddress);
|
||||
}
|
||||
|
||||
Future<List<DeliveryAddress>> getDeliveryAddresses(String userID) async {
|
||||
String path = "$delivery_address_collection/";
|
||||
var querySnap = await Firestore.instance
|
||||
.collection('users')
|
||||
.document("$userID")
|
||||
.collection("$path")
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
.map((e) => DeliveryAddress.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,12 +77,12 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
customerId = u.id;
|
||||
customerName = u.name;
|
||||
});
|
||||
})),
|
||||
},popPage: true)),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -70,19 +70,20 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
bool canChangeDeliveryAddress =
|
||||
_package?.status == package_received_status ||
|
||||
_package?.status == package_processed_status;
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
|
||||
final trackingIdBox = DisplayText(
|
||||
text: _package?.trackingID??"",
|
||||
text: _package?.trackingID ?? "",
|
||||
labelTextKey: "package.tracking.id",
|
||||
iconData: MaterialCommunityIcons.barcode_scan,
|
||||
);
|
||||
var fcsIDBox = DisplayText(
|
||||
text: _package?.fcsID??"",
|
||||
text: _package?.fcsID ?? "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
);
|
||||
final customerNameBox = DisplayText(
|
||||
text: _package?.userName??"",
|
||||
text: _package?.userName ?? "",
|
||||
labelTextKey: "package.create.name",
|
||||
iconData: Icons.perm_identity,
|
||||
);
|
||||
@@ -121,7 +122,7 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _package.deliveryAddress,
|
||||
)),
|
||||
deliveryAddresses: deliveryAddressModel.deliveryAddresses)),
|
||||
);
|
||||
if (d == null) return;
|
||||
_changeDeliverayAddress(d);
|
||||
@@ -158,7 +159,9 @@ class _PackageInfoState extends State<PackageInfo> {
|
||||
widget.isSearchResult ? Container() : fcsIDBox,
|
||||
widget.isSearchResult ? Container() : customerNameBox,
|
||||
widget.isSearchResult ? Container() : marketBox,
|
||||
_package==null || _package.photoUrls.length == 0 ? Container() : img,
|
||||
_package == null || _package.photoUrls.length == 0
|
||||
? Container()
|
||||
: img,
|
||||
widget.isSearchResult ? Container() : descBox,
|
||||
remarkBox,
|
||||
_package?.status == package_received_status &&
|
||||
|
||||
@@ -47,7 +47,7 @@ class _PackageNewState extends State<PackageNew> {
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this.user = u;
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/market.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/entities/user.dart';
|
||||
@@ -7,7 +8,9 @@ import 'package:fcs/pages/market/model/market_model.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/package/tracking_id_page.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package_search/package_serach.dart';
|
||||
import 'package:fcs/pages/widgets/barcode_scanner.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
||||
@@ -32,59 +35,60 @@ class PackageEditor extends StatefulWidget {
|
||||
class _PackageEditorState extends State<PackageEditor> {
|
||||
TextEditingController _remarkCtl = new TextEditingController();
|
||||
TextEditingController _descCtl = new TextEditingController();
|
||||
TextEditingController _trackingIDCtl = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
MultiImgController multiImgController = MultiImgController();
|
||||
Package _package = Package();
|
||||
Package _package;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.package != null) {
|
||||
_isNew = false;
|
||||
_package = widget.package;
|
||||
_trackingIDCtl.text = _package.trackingID;
|
||||
_package = Package();
|
||||
_loadPackageData(null);
|
||||
}
|
||||
|
||||
_loadPackageData(String id) async {
|
||||
if (id != null) {
|
||||
PackageModel packageModel =
|
||||
Provider.of<PackageModel>(context, listen: false);
|
||||
Package package = await packageModel.getPackage(id);
|
||||
if (package != null) {
|
||||
if (package.status != package_received_status) {
|
||||
showMsgDialog(context, "Error",
|
||||
"Invalid package status, expected '$package_received_status' status");
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_package = package;
|
||||
});
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
selectedMarket = _package.market ?? "";
|
||||
_descCtl.text = _package.desc;
|
||||
_remarkCtl.text = _package.remark;
|
||||
multiImgController.setImageFiles = _package.photoFiles;
|
||||
} else {
|
||||
_isNew = true;
|
||||
}
|
||||
multiImgController.setImageUrls = _package.photoUrls;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final trackingIDBox = Container(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
var trackingIDBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: InputText(
|
||||
iconData: MaterialCommunityIcons.barcode_scan,
|
||||
child: DisplayText(
|
||||
text: _package.trackingID,
|
||||
labelTextKey: "processing.tracking.id",
|
||||
controller: _trackingIDCtl,
|
||||
iconData: MaterialCommunityIcons.barcode_scan,
|
||||
)),
|
||||
InkWell(
|
||||
onTap: _scan,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
MaterialCommunityIcons.barcode_scan,
|
||||
color: primaryColor,
|
||||
),
|
||||
Text("Scan")
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchPackage(context, callbackPackageSelect: (u) {
|
||||
_loadPackageData(u.id);
|
||||
Navigator.pop(context);
|
||||
})),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
);
|
||||
|
||||
final descBox = InputText(
|
||||
labelTextKey: 'processing.desc',
|
||||
@@ -114,7 +118,15 @@ class _PackageEditorState extends State<PackageEditor> {
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
onPressed: () {
|
||||
if (isDataChanged()) {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
@@ -235,31 +247,6 @@ class _PackageEditorState extends State<PackageEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
_scan() async {
|
||||
PermissionStatus permission =
|
||||
await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
|
||||
if (permission != PermissionStatus.granted) {
|
||||
Map<PermissionGroup, PermissionStatus> permissions =
|
||||
await PermissionHandler()
|
||||
.requestPermissions([PermissionGroup.camera]);
|
||||
if (permissions[PermissionGroup.camera] != PermissionStatus.granted) {
|
||||
showMsgDialog(context, "Error", "Camera permission is not granted");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String barcode = await scanBarcode();
|
||||
if (barcode != null) {
|
||||
setState(() {
|
||||
_trackingIDCtl.text = barcode;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
print('error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
_selectPackage() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
@@ -267,21 +254,17 @@ class _PackageEditorState extends State<PackageEditor> {
|
||||
PackageModel packageModel =
|
||||
Provider.of<PackageModel>(context, listen: false);
|
||||
try {
|
||||
Package package=await packageModel.getPackageByTrackingID(_trackingIDCtl.text);
|
||||
package.trackingID = _trackingIDCtl.text;
|
||||
package.market = selectedMarket;
|
||||
package.desc = _descCtl.text;
|
||||
package.remark = _remarkCtl.text;
|
||||
package.photoFiles = _isNew
|
||||
? multiImgController.getAddedFile
|
||||
: multiImgController.getUpdatedFile;
|
||||
package.fcsID=widget.consignee.fcsID;
|
||||
package.senderFCSID=widget.sender?.fcsID;
|
||||
_package.market = selectedMarket;
|
||||
_package.desc = _descCtl.text;
|
||||
_package.remark = _remarkCtl.text;
|
||||
_package.photoFiles = multiImgController.getUpdatedFile;
|
||||
_package.fcsID = widget.consignee.fcsID;
|
||||
_package.senderFCSID = widget.sender?.fcsID;
|
||||
|
||||
await packageModel.updateProcessing(package,
|
||||
await packageModel.updateProcessing(_package,
|
||||
multiImgController.getAddedFile, multiImgController.getDeletedUrl);
|
||||
|
||||
Navigator.pop<Package>(context, package);
|
||||
Navigator.pop<Package>(context, _package);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
@@ -290,4 +273,11 @@ class _PackageEditorState extends State<PackageEditor> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
return selectedMarket != null ||
|
||||
_descCtl.text != "" ||
|
||||
_remarkCtl.text != "" ||
|
||||
multiImgController.getAddedFile.isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class _ProcessingEditEditorState extends State<ProcessingEditEditor> {
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this._user = u;
|
||||
});
|
||||
@@ -267,10 +267,23 @@ class _ProcessingEditEditorState extends State<ProcessingEditEditor> {
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
if (isNew) {
|
||||
return _user.fcsID != "" ||
|
||||
selectedMarket != "" ||
|
||||
selectedMarket != null ||
|
||||
_descCtl.text != "" ||
|
||||
_remarkCtl.text != "" ||
|
||||
multiImgController.getAddedFile.isNotEmpty;
|
||||
} else {
|
||||
var _package = Package(
|
||||
trackingID: widget.package.trackingID,
|
||||
fcsID: _user.fcsID,
|
||||
market: selectedMarket,
|
||||
desc: _descCtl.text,
|
||||
remark: _remarkCtl.text,
|
||||
photoUrls: widget.package.photoUrls);
|
||||
return widget.package.isChangedForEditProcessing(_package) ||
|
||||
multiImgController.getAddedFile.isNotEmpty ||
|
||||
multiImgController.getDeletedUrl.isNotEmpty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this.consignee = u;
|
||||
});
|
||||
})),
|
||||
}, popPage: true)),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -104,11 +104,11 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this.sender = u;
|
||||
});
|
||||
})),
|
||||
}, popPage: true)),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -148,7 +148,8 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
|
||||
),
|
||||
onPressed: () async {
|
||||
if (this.consignee == null) {
|
||||
showMsgDialog(context, "Warning", "Please select 'Consignee'");
|
||||
showMsgDialog(
|
||||
context, "Warning", "Please select 'Consignee'");
|
||||
return;
|
||||
}
|
||||
Package _package = await Navigator.push<Package>(
|
||||
@@ -181,13 +182,7 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
|
||||
icon:
|
||||
new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
|
||||
onPressed: () {
|
||||
if (isDataChanged()) {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
@@ -290,16 +285,4 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
if (_isNew) {
|
||||
return this.packages.isNotEmpty || consignee != null || sender != null;
|
||||
} else {
|
||||
Processing _processing = Processing(
|
||||
userID: consignee.fcsID,
|
||||
fcsID: sender.fcsID,
|
||||
packages: this.packages);
|
||||
return widget.processing.isChangedForEdit(_processing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class _ProcessingEditorState extends State<ProcessingEditor> {
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this._user = u;
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
@@ -12,7 +12,7 @@ import 'package:provider/provider.dart';
|
||||
import 'model/shipment_rate_model.dart';
|
||||
|
||||
class CustomEditor extends StatefulWidget {
|
||||
final CustomDuty custom;
|
||||
final CargoType custom;
|
||||
CustomEditor({this.custom});
|
||||
|
||||
@override
|
||||
@@ -25,7 +25,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
TextEditingController _shipmentRateController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
CustomDuty _custom = new CustomDuty();
|
||||
CargoType _custom = new CargoType();
|
||||
bool _isNew = false;
|
||||
|
||||
@override
|
||||
@@ -33,11 +33,10 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
super.initState();
|
||||
if (widget.custom != null) {
|
||||
_custom = widget.custom;
|
||||
_productController.text = _custom.productType;
|
||||
_feeController.text = _custom.fee.toStringAsFixed(2);
|
||||
_shipmentRateController.text = _custom.shipmentRate == null
|
||||
? ""
|
||||
: _custom.shipmentRate.toStringAsFixed(2);
|
||||
_productController.text = _custom.name;
|
||||
_feeController.text = _custom.customDutyFee.toStringAsFixed(2);
|
||||
_shipmentRateController.text =
|
||||
_custom.rate == null ? "" : _custom.rate.toStringAsFixed(2);
|
||||
} else {
|
||||
_isNew = true;
|
||||
}
|
||||
@@ -123,11 +122,10 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
CustomDuty _customduty = CustomDuty(
|
||||
productType: _productController.text,
|
||||
fee: double.parse(_feeController.text),
|
||||
shipmentRate: double.parse(_shipmentRateController.text));
|
||||
print('_customduty => $_customduty');
|
||||
CargoType _customduty = CargoType(
|
||||
name: _productController.text,
|
||||
customDutyFee: double.parse(_feeController.text),
|
||||
rate: double.parse(_shipmentRateController.text));
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addCustomDuty(_customduty);
|
||||
} else {
|
||||
@@ -173,12 +171,11 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
_feeController.text != "" ||
|
||||
_shipmentRateController.text != "";
|
||||
} else {
|
||||
CustomDuty _customduty = CustomDuty(
|
||||
productType: _productController.text,
|
||||
fee: double.parse(_feeController.text),
|
||||
// shipmentRate: double.parse(_shipmentRateController.text)
|
||||
);
|
||||
return widget.custom.isChangedForEdit(_customduty);
|
||||
CargoType _customduty = CargoType(
|
||||
name: _productController.text,
|
||||
customDutyFee: double.parse(_feeController.text),
|
||||
rate: double.parse(_shipmentRateController.text));
|
||||
return widget.custom.isChangedForEditCustomDuty(_customduty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
@@ -74,8 +75,7 @@ class _CustomListState extends State<CustomList> {
|
||||
),
|
||||
itemCount: shipmentRateModel.rate.customDuties.length,
|
||||
itemBuilder: (context, index) {
|
||||
CustomDuty custom =
|
||||
shipmentRateModel.rate.customDuties[index];
|
||||
CargoType custom = shipmentRateModel.rate.customDuties[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
_selected
|
||||
@@ -86,11 +86,11 @@ class _CustomListState extends State<CustomList> {
|
||||
},
|
||||
child: Container(
|
||||
child: _row(
|
||||
custom.productType,
|
||||
"\$ " + custom.fee.toStringAsFixed(2),
|
||||
custom.shipmentRate == null
|
||||
custom.name,
|
||||
"Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2),
|
||||
custom.rate == null
|
||||
? ""
|
||||
: "\$ " + custom.shipmentRate.toStringAsFixed(2)),
|
||||
: "Shipment rate \$ " + custom.rate.toStringAsFixed(2)),
|
||||
),
|
||||
);
|
||||
}),
|
||||
@@ -120,7 +120,7 @@ class _CustomListState extends State<CustomList> {
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: 3.0),
|
||||
child: Text(
|
||||
"\$ " + "$shipmentRate",
|
||||
"$shipmentRate",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 14),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -50,16 +50,18 @@ class ShipmentRateModel extends BaseModel {
|
||||
|
||||
//CustomDuty
|
||||
|
||||
Future<void> addCustomDuty(CustomDuty customDuty) {
|
||||
return Services.instance.rateService.createCustomDuty(customDuty);
|
||||
Future<void> addCustomDuty(CargoType customDuty) {
|
||||
customDuty.isCutomDuty=true;
|
||||
return Services.instance.rateService.createCargoType(customDuty);
|
||||
}
|
||||
|
||||
Future<void> updateCustomDuty(CustomDuty customDuty) {
|
||||
return Services.instance.rateService.updateCustomDuty(customDuty);
|
||||
Future<void> updateCustomDuty(CargoType customDuty) {
|
||||
customDuty.isCutomDuty=true;
|
||||
return Services.instance.rateService.updateCargoType(customDuty);
|
||||
}
|
||||
|
||||
Future<void> deleteCustomDuty(String id) {
|
||||
return Services.instance.rateService.deleteCustomDuty(id);
|
||||
return Services.instance.rateService.deleteCargoType(id);
|
||||
}
|
||||
|
||||
//Discount by weight
|
||||
|
||||
@@ -145,14 +145,10 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
"Volumetric Ratio",
|
||||
"${rate.volumetricRatio.toStringAsFixed(2)}",
|
||||
"in3 per pound"),
|
||||
_row(
|
||||
"Weight difference discount",
|
||||
"${rate.diffDiscountWeight.toStringAsFixed(2)}",
|
||||
"pounds"),
|
||||
_row(
|
||||
"Weight difference rate",
|
||||
"\$ ${rate.diffWeightRate.toStringAsFixed(2)}",
|
||||
""),
|
||||
_row("Weight difference discount",
|
||||
"${rate.diffDiscountWeight.toStringAsFixed(2)}", "pounds"),
|
||||
_row("Weight difference rate",
|
||||
"\$ ${rate.diffWeightRate.toStringAsFixed(2)}", ""),
|
||||
Divider(
|
||||
color: Colors.grey,
|
||||
),
|
||||
@@ -195,10 +191,10 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> getCustonWidget(List<CustomDuty> customs) {
|
||||
List<Widget> getCustonWidget(List<CargoType> customs) {
|
||||
return customs.map((c) {
|
||||
return Container(
|
||||
child: _row(c.productType, "\$ " + c.fee.toStringAsFixed(2), ''),
|
||||
child: _row(c.name, "\$ " + c.customDutyFee.toStringAsFixed(2), ''),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
_minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? "";
|
||||
_deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? "";
|
||||
_volumetricRatio.text = rate.volumetricRatio?.toStringAsFixed(2) ?? "";
|
||||
_diffDiscountWeight.text = rate.diffDiscountWeight?.toStringAsFixed(2) ?? "";
|
||||
_diffDiscountWeight.text =
|
||||
rate.diffDiscountWeight?.toStringAsFixed(2) ?? "";
|
||||
_diffWeightRate.text = rate.diffWeightRate?.toStringAsFixed(2) ?? "";
|
||||
}
|
||||
|
||||
@@ -162,120 +163,4 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
);
|
||||
return rate.isChangedForEdit(_rate);
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(List<CargoType> cargos) {
|
||||
return cargos.map((r) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CargoEditor(cargo: r)),
|
||||
);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
r.name,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(
|
||||
r.rate.toString(),
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<MyDataRow> getCustomsRows(List<CustomDuty> customs) {
|
||||
return customs.map((c) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CustomEditor(custom: c)),
|
||||
);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
c.productType,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(
|
||||
c.fee.toString(),
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<MyDataRow> getDiscounts(List<DiscountByWeight> discounts) {
|
||||
return discounts.map((d) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// CupertinoPageRoute(builder: (context) => CargoEditor(rate: r)),
|
||||
// );
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
"${d.weight} lb",
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
Center(
|
||||
child: new Text(
|
||||
d.discount.toString(),
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_row(String desc, String price, String unit) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 25, top: 5, bottom: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text('$desc ', style: TextStyle(fontSize: 15)),
|
||||
Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 3.0),
|
||||
child: Text(
|
||||
'$price',
|
||||
style: TextStyle(color: primaryColor, fontSize: 14),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'$unit',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
width: 50,
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +77,11 @@ class _ReceivingEditorState extends State<ReceivingEditor> {
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
this.user = u;
|
||||
});
|
||||
})),
|
||||
},popPage: true)),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
final shipmentWeightBox = DisplayText(
|
||||
labelTextKey: "shipment.box.shipment.weight",
|
||||
text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0),
|
||||
@@ -191,7 +192,8 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _box.deliveryAddress,
|
||||
)),
|
||||
deliveryAddresses:
|
||||
deliveryAddressModel.deliveryAddresses)),
|
||||
);
|
||||
if (d == null) return;
|
||||
setState(() {
|
||||
|
||||
@@ -91,6 +91,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
|
||||
bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff;
|
||||
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
|
||||
final fromTimeBox = InputTime(
|
||||
labelTextKey: 'shipment.from',
|
||||
iconData: Icons.timer,
|
||||
@@ -129,6 +130,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
deliveryAddresses: deliveryAddressModel.deliveryAddresses,
|
||||
)),
|
||||
);
|
||||
if (address == null) return;
|
||||
|
||||
@@ -4,9 +4,9 @@ import 'package:fcs/pages/user_search/user_serach.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class UserListRow extends StatefulWidget {
|
||||
final CallbackUserSelect callbackUserSelect;
|
||||
final OnUserRowSelect onUserRowSelect;
|
||||
final User user;
|
||||
const UserListRow({this.user, this.callbackUserSelect});
|
||||
const UserListRow({this.user, this.onUserRowSelect});
|
||||
|
||||
@override
|
||||
_UserListRowState createState() => _UserListRowState();
|
||||
@@ -30,9 +30,8 @@ class _UserListRowState extends State<UserListRow> {
|
||||
color: Colors.white,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
if (widget.callbackUserSelect != null)
|
||||
widget.callbackUserSelect(widget.user);
|
||||
if (widget.onUserRowSelect != null)
|
||||
widget.onUserRowSelect(widget.user);
|
||||
},
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
|
||||
@@ -5,19 +5,22 @@ import 'package:fcs/pages/user_search/user_list_row.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
typedef CallbackUserSelect(User suer);
|
||||
typedef OnUserSelect(User suer);
|
||||
typedef OnUserRowSelect(User suer);
|
||||
|
||||
Future<User> searchUser(BuildContext context,
|
||||
{CallbackUserSelect callbackUserSelect}) async =>
|
||||
{OnUserSelect onUserSelect, bool popPage = false}) async =>
|
||||
await showSearch<User>(
|
||||
context: context,
|
||||
delegate: UserSearchDelegate(callbackUserSelect: callbackUserSelect),
|
||||
delegate:
|
||||
UserSearchDelegate(onUserSelect: onUserSelect, popPage: popPage),
|
||||
);
|
||||
|
||||
class UserSearchDelegate extends SearchDelegate<User> {
|
||||
final CallbackUserSelect callbackUserSelect;
|
||||
final OnUserSelect onUserSelect;
|
||||
final bool popPage;
|
||||
|
||||
UserSearchDelegate({this.callbackUserSelect});
|
||||
UserSearchDelegate({this.onUserSelect, this.popPage});
|
||||
|
||||
@override
|
||||
String get searchFieldLabel => 'Search by FCS ID or Name';
|
||||
@@ -77,7 +80,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
|
||||
children: snapshot.data
|
||||
.map((u) => UserListRow(
|
||||
user: u,
|
||||
callbackUserSelect: callbackUserSelect,
|
||||
onUserRowSelect: (u) => _onUserRowSelect(context, u),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
@@ -113,4 +116,13 @@ class UserSearchDelegate extends SearchDelegate<User> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_onUserRowSelect(BuildContext context, User user) {
|
||||
if (onUserSelect != null) {
|
||||
onUserSelect(user);
|
||||
}
|
||||
if (popPage) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,42 @@
|
||||
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/delivery_address/delivery_address_editor.dart';
|
||||
import 'package:fcs/pages/delivery_address/delivery_address_row.dart';
|
||||
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
typedef OnAdded();
|
||||
|
||||
class DeliveryAddressSelection extends StatelessWidget {
|
||||
final DeliveryAddress deliveryAddress;
|
||||
final List<DeliveryAddress> deliveryAddresses;
|
||||
final User user;
|
||||
final OnAdded onAdded;
|
||||
|
||||
const DeliveryAddressSelection({Key key, this.deliveryAddress})
|
||||
const DeliveryAddressSelection(
|
||||
{Key key,
|
||||
this.deliveryAddress,
|
||||
this.deliveryAddresses,
|
||||
this.user,
|
||||
this.onAdded})
|
||||
: super(key: key);
|
||||
|
||||
Future<List<DeliveryAddress>> _getDeliverAddresses(
|
||||
BuildContext context) async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
|
||||
var _deliveryAddresses = await addressModel.getDeliveryAddresses(user.id);
|
||||
return _deliveryAddresses;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var shipmentModel = Provider.of<DeliveryAddressModel>(context);
|
||||
|
||||
if (user != null) {}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
@@ -32,9 +50,15 @@ class DeliveryAddressSelection extends StatelessWidget {
|
||||
color: primaryColor, fontSize: 20),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressEditor()));
|
||||
onPressed: () async {
|
||||
bool updated = await Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressEditor(
|
||||
user: user,
|
||||
)));
|
||||
if (updated && onAdded != null) {
|
||||
onAdded();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: LocalText(context, "delivery_address.new_address",
|
||||
@@ -47,9 +71,9 @@ class DeliveryAddressSelection extends StatelessWidget {
|
||||
separatorBuilder: (c, i) => Divider(
|
||||
color: primaryColor,
|
||||
),
|
||||
itemCount: shipmentModel.deliveryAddresses.length,
|
||||
itemCount: deliveryAddresses.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _row(context, shipmentModel.deliveryAddresses[index]);
|
||||
return _row(context, deliveryAddresses[index]);
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'local_text.dart';
|
||||
class DialogInput extends StatefulWidget {
|
||||
final String value;
|
||||
final String label;
|
||||
|
||||
const DialogInput({Key key, this.label, this.value}) : super(key: key);
|
||||
@override
|
||||
_DialogInputState createState() => _DialogInputState();
|
||||
@@ -15,6 +16,7 @@ class DialogInput extends StatefulWidget {
|
||||
class _DialogInputState extends State<DialogInput> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
TextEditingController _controller = new TextEditingController();
|
||||
final _focusNode = FocusNode();
|
||||
|
||||
bool _isLoading = false;
|
||||
|
||||
@@ -23,6 +25,12 @@ class _DialogInputState extends State<DialogInput> {
|
||||
super.initState();
|
||||
if (widget.value != null) {
|
||||
_controller.text = widget.value;
|
||||
_focusNode.addListener(() {
|
||||
if (_focusNode.hasFocus) {
|
||||
_controller.selection = TextSelection(
|
||||
baseOffset: 0, extentOffset: _controller.text.length);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +49,8 @@ class _DialogInputState extends State<DialogInput> {
|
||||
key: _formKey,
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
autofocus: true,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration(
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
|
||||
Reference in New Issue
Block a user