This commit is contained in:
2021-01-10 23:06:15 +06:30
45 changed files with 1273 additions and 769 deletions

View File

@@ -275,7 +275,7 @@
"box.packages":"Packages", "box.packages":"Packages",
"box.tracking.id":"Tracking ID", "box.tracking.id":"Tracking ID",
"box.market":"Market", "box.market":"Market",
"box.cargo.save.btn":"Save", "box.cargo.save.btn":"Select",
"box.type.title":"Carton types", "box.type.title":"Carton types",
"box.shipment.boxes":"Cartons", "box.shipment.boxes":"Cartons",
"box.shipment_number":"Shipment number", "box.shipment_number":"Shipment number",
@@ -300,6 +300,7 @@
"box.min_caton.form.title":"Mix Carton", "box.min_caton.form.title":"Mix Carton",
"box.mix_carton_btn":"Create mix carton", "box.mix_carton_btn":"Create mix carton",
"box.mix_type":"Mix Box Types", "box.mix_type":"Mix Box Types",
"box.selection":"Carton Selection",
"Boxes End ================================================================":"", "Boxes End ================================================================":"",
"Delivery Start ================================================================":"", "Delivery Start ================================================================":"",

View File

@@ -275,7 +275,7 @@
"box.packages":"အထုပ်များ", "box.packages":"အထုပ်များ",
"box.tracking.id":"Tracking ID", "box.tracking.id":"Tracking ID",
"box.market":"အွန်လိုင်စျေးဆိုင်", "box.market":"အွန်လိုင်စျေးဆိုင်",
"box.cargo.save.btn":"သိမ်းဆည်းမည်", "box.cargo.save.btn":"ရွေးမည်",
"box.type.title":"သေတ္တာအမျိုးအစားများ", "box.type.title":"သေတ္တာအမျိုးအစားများ",
"box.shipment.boxes":"သေတ္တာများ", "box.shipment.boxes":"သေတ္တာများ",
"box.shipment_number":"ပို့ဆောင်နံပါတ်", "box.shipment_number":"ပို့ဆောင်နံပါတ်",
@@ -300,6 +300,7 @@
"box.min_caton.form.title":"Mix Carton", "box.min_caton.form.title":"Mix Carton",
"box.mix_carton_btn":"Create mix carton", "box.mix_carton_btn":"Create mix carton",
"box.mix_type":"Mix Box Types", "box.mix_type":"Mix Box Types",
"box.selection":"သေတ္တာ ရွေးချယ်ခြင်း",
"Boxes End ================================================================":"", "Boxes End ================================================================":"",
"Delivery Start ================================================================":"", "Delivery Start ================================================================":"",

View File

@@ -1,5 +1,8 @@
import 'dart:async'; 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/domain/entities/carton.dart';
import 'package:fcs/helpers/api_helper.dart'; import 'package:fcs/helpers/api_helper.dart';
import 'package:fcs/helpers/firebase_helper.dart'; import 'package:fcs/helpers/firebase_helper.dart';
@@ -11,9 +14,10 @@ class CartonDataProvider {
static final CartonDataProvider instance = CartonDataProvider._(); static final CartonDataProvider instance = CartonDataProvider._();
CartonDataProvider._(); CartonDataProvider._();
Future<void> createCarton(Carton carton) async { Future<Carton> createCarton(Carton carton) async {
return await requestAPI("/cartons", "POST", var data = await requestAPI("/cartons", "POST",
payload: carton.toMap(), token: await getToken()); payload: carton.toMap(), token: await getToken());
return Carton.fromMap(data, data['id']);
} }
Future<void> updateCarton(Carton carton) async { Future<void> updateCarton(Carton carton) async {
@@ -30,4 +34,32 @@ class CartonDataProvider {
return await requestAPI("/cartons/deliver", "PUT", return await requestAPI("/cartons/deliver", "PUT",
payload: carton.toMap(), token: await getToken()); 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;
}
}
} }

View File

@@ -36,6 +36,7 @@ class RateDataProvider {
.collection(config_collection) .collection(config_collection)
.document(rate_doc_id) .document(rate_doc_id)
.collection(cargo_types_collection) .collection(cargo_types_collection)
.where("custom_duty", isEqualTo: false)
.snapshots(); .snapshots();
await for (var snaps in snapshots) { await for (var snaps in snapshots) {
@@ -48,18 +49,19 @@ class RateDataProvider {
} }
} }
Stream<List<CustomDuty>> _customDutiesStream() async* { Stream<List<CargoType>> _customDutiesStream() async* {
List<CustomDuty> customDuries = []; List<CargoType> customDuries = [];
Stream<QuerySnapshot> snapshots = Firestore.instance Stream<QuerySnapshot> snapshots = Firestore.instance
.collection(config_collection) .collection(config_collection)
.document(rate_doc_id) .document(rate_doc_id)
.collection(custom_duties_collection) .collection(cargo_types_collection)
.where("custom_duty", isEqualTo: true)
.snapshots(); .snapshots();
await for (var snaps in snapshots) { await for (var snaps in snapshots) {
customDuries = []; customDuries = [];
customDuries = snaps.documents.map((snap) { customDuries = snaps.documents.map((snap) {
return CustomDuty.fromMap(snap.data, snap.documentID); return CargoType.fromMap(snap.data, snap.documentID);
}).toList(); }).toList();
yield customDuries; yield customDuries;
} }
@@ -84,7 +86,7 @@ class RateDataProvider {
StreamSubscription<Rate> rateListener; StreamSubscription<Rate> rateListener;
StreamSubscription<List<CargoType>> cargoListener; StreamSubscription<List<CargoType>> cargoListener;
StreamSubscription<List<CustomDuty>> customListener; StreamSubscription<List<CargoType>> customListener;
StreamSubscription<List<DiscountByWeight>> discountListener; StreamSubscription<List<DiscountByWeight>> discountListener;
Stream<Rate> rate() { Stream<Rate> rate() {
Future<void> _start() async { Future<void> _start() async {

View File

@@ -15,7 +15,7 @@ class CartonServiceImp implements CartonService {
final CartonDataProvider cartonDataProvider; final CartonDataProvider cartonDataProvider;
@override @override
Future<void> createCarton(Carton carton) { Future<Carton> createCarton(Carton carton) {
return cartonDataProvider.createCarton(carton); return cartonDataProvider.createCarton(carton);
} }
@@ -33,4 +33,9 @@ class CartonServiceImp implements CartonService {
Future<void> deliver(Carton carton) { Future<void> deliver(Carton carton) {
return cartonDataProvider.deliver(carton); return cartonDataProvider.deliver(carton);
} }
@override
Future<List<Carton>> searchCarton(String term) {
return cartonDataProvider.searchCarton(term);
}
} }

View File

@@ -1,8 +1,9 @@
import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/carton.dart';
abstract class CartonService { abstract class CartonService {
Future<void> createCarton(Carton carton); Future<Carton> createCarton(Carton carton);
Future<void> updateCarton(Carton carton); Future<void> updateCarton(Carton carton);
Future<void> deleteCarton(Carton carton); Future<void> deleteCarton(Carton carton);
Future<void> deliver(Carton carton); Future<void> deliver(Carton carton);
Future<List<Carton>> searchCarton(String term);
} }

View File

@@ -78,6 +78,7 @@ const shipment_courier_dropoff = "Courier drop off";
//Carton types //Carton types
const carton_from_packages = "From packages"; const carton_from_packages = "From packages";
const carton_from_cargos="From cargos";
const carton_from_shipments = "From shipments"; const carton_from_shipments = "From shipments";
const carton_mix_carton = "Mix carton"; const carton_mix_carton = "Mix carton";
const carton_small_bag = "Small bag"; const carton_small_bag = "Small bag";

View File

@@ -5,23 +5,13 @@ class CargoType {
double weight; double weight;
bool isChecked; bool isChecked;
int qty; int qty;
bool isCutomDuty = false; bool isCutomDuty;
double customDutyFee;
double get calAmount => (calRate ?? 0) * (calWeight ?? 0); double get calAmount => (calRate ?? 0) * (calWeight ?? 0);
double calRate; double calRate;
double calWeight; 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( CargoType(
{this.id, {this.id,
this.name, this.name,
@@ -31,7 +21,21 @@ class CargoType {
this.calRate, this.calRate,
this.isChecked = false, this.isChecked = false,
this.qty = 0, 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() { Map<String, dynamic> toMap() {
return { return {
@@ -41,6 +45,9 @@ class CargoType {
'weight': weight, 'weight': weight,
'cal_weight': calWeight, 'cal_weight': calWeight,
'cal_rate': calRate, 'cal_rate': calRate,
'custom_duty': isCutomDuty,
'custom_duty_fee': customDutyFee,
'qty': qty
}; };
} }
@@ -62,4 +69,10 @@ class CargoType {
bool isChangedForEdit(CargoType cargoType) { bool isChangedForEdit(CargoType cargoType) {
return cargoType.name != this.name || cargoType.rate != this.rate; 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;
}
} }

View File

@@ -12,8 +12,10 @@ class Carton {
String id; String id;
String shipmentID; String shipmentID;
String shipmentNumber; String shipmentNumber;
String senderID;
String senderFCSID; String senderFCSID;
String senderName; String senderName;
String receiverID;
String receiverFCSID; String receiverFCSID;
String receiverName; String receiverName;
String receiverAddress; String receiverAddress;
@@ -38,7 +40,6 @@ class Carton {
String mixCartonNumber; String mixCartonNumber;
String cartonSizeID; String cartonSizeID;
String cartonSizeName; String cartonSizeName;
String mixBoxType;
int rate; int rate;
int weight; int weight;
@@ -56,6 +57,11 @@ class Carton {
DeliveryAddress deliveryAddress; DeliveryAddress deliveryAddress;
Shipment shipment; Shipment shipment;
//for mix box
String mixBoxType;
List<Carton> mixCartons;
List<String> mixCartonIDs;
int get amount => rate != null && weight != null ? rate * weight : 0; int get amount => rate != null && weight != null ? rate * weight : 0;
String get packageNumber => String get packageNumber =>
@@ -74,7 +80,7 @@ class Carton {
height <= 0 || height <= 0 ||
volumetricRatio == null || volumetricRatio == null ||
volumetricRatio <= 0) return 0; volumetricRatio <= 0) return 0;
return ((length * width * height) / volumetricRatio).round(); return ((length * width * height) / volumetricRatio).round();
} }
@@ -126,8 +132,10 @@ class Carton {
{this.id, {this.id,
this.shipmentID, this.shipmentID,
this.shipmentNumber, this.shipmentNumber,
this.senderID,
this.senderFCSID, this.senderFCSID,
this.senderName, this.senderName,
this.receiverID,
this.receiverFCSID, this.receiverFCSID,
this.receiverName, this.receiverName,
this.receiverNumber, this.receiverNumber,
@@ -164,13 +172,16 @@ class Carton {
this.deliveryAddress, this.deliveryAddress,
this.cartonSizeID, this.cartonSizeID,
this.cartonSizeName, this.cartonSizeName,
this.mixBoxType}); this.mixBoxType,
this.mixCartons,
this.mixCartonIDs});
Map<String, dynamic> toMap() { 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 _packages = packages?.map((c) => c.toJson())?.toList();
List _mixCartons = mixCartons?.map((c) => c.toJson())?.toList();
return { return {
"id": id, 'id': id,
'fcs_shipment_id': fcsShipmentID, 'fcs_shipment_id': fcsShipmentID,
'user_id': userID, 'user_id': userID,
'cargo_types': _cargoTypes, 'cargo_types': _cargoTypes,
@@ -181,6 +192,14 @@ class Carton {
'delivery_address': deliveryAddress?.toMap(), 'delivery_address': deliveryAddress?.toMap(),
'carton_type': cartonType, 'carton_type': cartonType,
'mix_carton_id': mixCartonID, '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,30 +211,72 @@ class Carton {
List<Map<String, dynamic>>.from(map['cargo_types'] ?? []); List<Map<String, dynamic>>.from(map['cargo_types'] ?? []);
var cargoTypes = var cargoTypes =
cargoTypesMaps.map((e) => CargoType.fromMap(e, e["id"])).toList(); 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( return Carton(
id: docID, id: docID,
arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null, arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null,
shipmentID: map['shipment_id'], shipmentID: map['shipment_id'],
shipmentNumber: map['shipment_number'], shipmentNumber: map['shipment_number'],
receiverNumber: map['receiver_number'], receiverNumber: map['receiver_number'],
boxNumber: map['box_number'], boxNumber: map['box_number'],
length: map['length'], length: double.tryParse(map['length']?.toString()),
width: map['width'], width: double.tryParse(map['width']?.toString()),
height: map['height'], height: double.tryParse(map['height']?.toString()),
userName: map['user_name'], userName: map['user_name'],
fcsID: map['fcs_id'], fcsID: map['fcs_id'],
cartonType: map['carton_type'], cartonType: map['carton_type'],
cartonNumber: map['carton_number'], cartonNumber: map['carton_number'],
userID: map['user_id'], userID: map['user_id'],
fcsShipmentID: map['fcs_shipment_id'], fcsShipmentID: map['fcs_shipment_id'],
fcsShipmentNumber: map['fcs_shipment_number'], fcsShipmentNumber: map['fcs_shipment_number'],
isShipmentCarton: map['is_shipment_carton'], isShipmentCarton: map['is_shipment_carton'],
mixCartonID: map['mix_carton_id'], mixCartonID: map['mix_carton_id'],
mixCartonNumber: map['mix_carton_number'], mixCartonNumber: map['mix_carton_number'],
status: map['status'], status: map['status'],
packageIDs: List<String>.from(map['package_ids'] ?? []), packageIDs: List<String>.from(map['package_ids'] ?? []),
deliveryAddress: _da, 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 @override

View File

@@ -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) { bool isChangedForEdit(CartonSize cartonSize) {
return cartonSize.name != this.name || return cartonSize.name != this.name ||
cartonSize.length != this.length || cartonSize.length != this.length ||

View File

@@ -138,6 +138,14 @@ class Package {
package.fcsID != this.fcsID; 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 @override
bool operator ==(Object other) => other is Package && other.id == id; bool operator ==(Object other) => other is Package && other.id == id;

View File

@@ -1,4 +1,4 @@
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'cargo_type.dart'; import 'cargo_type.dart';
@@ -12,7 +12,7 @@ class Rate {
double diffWeightRate; double diffWeightRate;
List<CargoType> cargoTypes; List<CargoType> cargoTypes;
List<CustomDuty> customDuties; List<CargoType> customDuties;
List<DiscountByWeight> discountByWeights; List<DiscountByWeight> discountByWeights;
DiscountByWeight getDiscountByWeight(double weight) { DiscountByWeight getDiscountByWeight(double weight) {

View File

@@ -7,6 +7,7 @@ class DeliveryAddress {
String state; String state;
String phoneNumber; String phoneNumber;
bool isDefault; bool isDefault;
String userID;
DeliveryAddress( DeliveryAddress(
{this.id, {this.id,
this.fullName, this.fullName,
@@ -15,6 +16,7 @@ class DeliveryAddress {
this.city, this.city,
this.state, this.state,
this.phoneNumber, this.phoneNumber,
this.userID,
this.isDefault = false}); this.isDefault = false});
factory DeliveryAddress.fromMap(Map<String, dynamic> map, String docID) { factory DeliveryAddress.fromMap(Map<String, dynamic> map, String docID) {
@@ -39,6 +41,7 @@ class DeliveryAddress {
'city': city, 'city': city,
'state': state, 'state': state,
'phone_number': phoneNumber, 'phone_number': phoneNumber,
'user_id': userID,
}; };
} }

View File

@@ -123,7 +123,7 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
color: primaryColor, color: primaryColor,
), ),
onPressed: () async { onPressed: () async {
CustomDuty customDuty = await Navigator.of(context).push( CargoType customDuty = await Navigator.of(context).push(
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => builder: (context) =>
CustomList(selected: true))); CustomList(selected: true)));
@@ -143,14 +143,20 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
); );
} }
_addCustom(CustomDuty customDuty) { _addCustom(CargoType customDuty) {
if (customDuty == null) return; 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(() { setState(() {
cargos.add(CargoType( customDuty.qty = 1;
name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0)); customDuty.isChecked = false;
cargos.add(customDuty);
}); });
} }
} }

View File

@@ -238,10 +238,11 @@ class _CargoTableState extends State<CargoTable> {
child: InkWell( child: InkWell(
onTap: () async { onTap: () async {
String _t = await showDialog( String _t = await showDialog(
context: context, context: context,
builder: (_) => DialogInput( builder: (_) => DialogInput(
label: "shipment.cargo.total", label: "shipment.cargo.total",
value: totalWeight.toStringAsFixed(2))); value: totalWeight.toStringAsFixed(2)),
);
if (_t == null) return; if (_t == null) return;
setState(() { setState(() {

View File

@@ -10,13 +10,17 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/carton_package_table.dart'; import 'package:fcs/pages/carton/carton_package_table.dart';
import 'package:fcs/pages/carton_search/carton_search.dart'; import 'package:fcs/pages/carton_search/carton_search.dart';
import 'package:fcs/pages/carton_size/carton_size_list.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/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/package/model/package_model.dart'; import 'package:fcs/pages/package/model/package_model.dart';
import 'package:fcs/pages/rates/model/shipment_rate_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/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/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.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_button.dart';
import 'package:fcs/pages/widgets/local_dropdown.dart'; import 'package:fcs/pages/widgets/local_dropdown.dart';
import 'package:fcs/pages/widgets/local_radio_buttons.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/material.dart';
import 'package:flutter_icons/flutter_icons.dart'; import 'package:flutter_icons/flutter_icons.dart';
import 'package:provider/provider.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 'carton_row.dart';
import 'mix_carton_editor.dart';
import 'model/carton_model.dart'; import 'model/carton_model.dart';
import '../carton_size/model/carton_size_model.dart'; import '../carton_size/model/carton_size_model.dart';
import 'package_carton_editor.dart'; import 'package_carton_editor.dart';
@@ -47,21 +51,31 @@ class _CartonEditorState extends State<CartonEditor> {
TextEditingController _widthController = new TextEditingController(); TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController(); TextEditingController _heightController = new TextEditingController();
TextEditingController _lengthController = new TextEditingController(); TextEditingController _lengthController = new TextEditingController();
List<DeliveryAddress> _deliveryAddresses = [];
DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<CargoType> _cargoTypes = [];
Carton _carton; Carton _carton;
bool _isLoading = false; bool _isLoading = false;
bool _isNew; bool _isNew;
DeliveryAddress _deliveryAddress = new DeliveryAddress();
User _user; User _user;
String _selectedCartonType; String _selectedCartonType;
String _selectedMixType;
double volumetricRatio = 0; double volumetricRatio = 0;
double shipmentWeight = 0; double shipmentWeight = 0;
FcsShipment _fcsShipment; FcsShipment _fcsShipment;
List<FcsShipment> _fcsShipments; List<FcsShipment> _fcsShipments;
Carton _mixCarton;
List<Carton> _cartons = []; List<Carton> _cartons = [];
CartonSize selectedCatonSize;
//for mix carton
List<Carton> _mixCartons = []; List<Carton> _mixCartons = [];
String _selectedMixBoxType;
//for carton from cargos
User consignee;
User sender;
List<Carton> _cartonsForCargos = [];
@override @override
void initState() { void initState() {
@@ -82,9 +96,29 @@ class _CartonEditorState extends State<CartonEditor> {
_heightController.text = _carton.height.toString(); _heightController.text = _carton.height.toString();
_lengthController.text = _carton.length.toString(); _lengthController.text = _carton.length.toString();
_selectedCartonType = _carton.cartonType; _selectedCartonType = _carton.cartonType;
_cargoTypes = List.from(_carton.cargoTypes);
_isNew = false; _isNew = false;
_user = User(fcsID: _carton.fcsID, name: _carton.userName); _user = User(
_loadPackages(); 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 { } else {
_carton = Carton( _carton = Carton(
cargoTypes: [], cargoTypes: [],
@@ -95,14 +129,8 @@ class _CartonEditorState extends State<CartonEditor> {
_heightController.text = "0"; _heightController.text = "0";
_isNew = true; _isNew = true;
_selectedCartonType = carton_from_packages; _selectedCartonType = carton_from_packages;
_selectedMixType = mix_delivery; _selectedMixBoxType = mix_delivery;
_loadFcsShipments(); _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(() { setState(() {
_carton.packages = packages; _carton.packages = packages;
}); });
_populateDeliveryAddress(); // _populateDeliveryAddress();
} }
_populateDeliveryAddress() { // _populateDeliveryAddress() {
if (_carton.packages == null) return; // if (_carton.packages == null) return;
var d = _carton.packages // var d = _carton.packages
.firstWhere((p) => p.isChecked && p.deliveryAddress != null, // .firstWhere((p) => p.isChecked && p.deliveryAddress != null,
orElse: () => null) // orElse: () => null)
?.deliveryAddress; // ?.deliveryAddress;
setState(() { // setState(() {
_deliveryAddress = d; // _deliveryAddress = d;
}); // });
} // }
_calShipmentWeight() { _calShipmentWeight() {
double l = double.parse(_lengthController.text, (s) => 0); 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 @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
@@ -183,6 +236,8 @@ class _CartonEditorState extends State<CartonEditor> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var boxModel = Provider.of<CartonModel>(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; bool isMixBox = _selectedCartonType == carton_mix_box;
final shipmentBox = DisplayText( final shipmentBox = DisplayText(
@@ -219,13 +274,12 @@ class _CartonEditorState extends State<CartonEditor> {
_isNew _isNew
? IconButton( ? IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => onPressed: () => searchUser(context, onUserSelect: (u) {
searchUser(context, callbackUserSelect: (u) {
setState(() { setState(() {
this._user = u; this._user = u;
_loadPackages(); _loadPackages();
}); });
})) }, popPage: true))
: Container(), : Container(),
], ],
)); ));
@@ -238,7 +292,9 @@ class _CartonEditorState extends State<CartonEditor> {
final createBtn = LocalButton( final createBtn = LocalButton(
textKey: "box.complete.packaging", textKey: "box.complete.packaging",
callBack: _save, callBack: () {
Navigator.pop(context);
},
); );
final saveBtn = LocalButton( final saveBtn = LocalButton(
@@ -264,54 +320,7 @@ class _CartonEditorState extends State<CartonEditor> {
Icons.add_circle, Icons.add_circle,
color: primaryColor, color: primaryColor,
), ),
onPressed: () async { onPressed: _addCarton),
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;
});
}
}),
), ),
); );
@@ -330,16 +339,16 @@ class _CartonEditorState extends State<CartonEditor> {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
)), )),
Row( Row(
children: boxModel.mixTypes.map((e) { children: boxModel.mixBoxTypes.map((e) {
return Row( return Row(
children: [ children: [
Radio( Radio(
value: e, value: e,
groupValue: _selectedMixType, groupValue: _selectedMixBoxType,
activeColor: primaryColor, activeColor: primaryColor,
onChanged: (v) { onChanged: (v) {
setState(() { 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( final mixcartonTitleBox = Container(
child: LocalTitle( child: LocalTitle(
textKey: "box.mix_caton_title", textKey: "box.mix_caton_title",
@@ -360,15 +399,140 @@ class _CartonEditorState extends State<CartonEditor> {
Icons.add_circle, Icons.add_circle,
color: primaryColor, color: primaryColor,
), ),
onPressed: () { onPressed: () async {
Navigator.push( searchCarton(context, callbackCartonSelect: (c) {
context, _addMixCarton(c);
CupertinoPageRoute(builder: (context) => MixCartonEditor()), });
);
}, },
), ),
), ),
); );
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( return LocalProgress(
inAsyncCall: _isLoading, inAsyncCall: _isLoading,
@@ -391,7 +555,7 @@ class _CartonEditorState extends State<CartonEditor> {
backgroundColor: Colors.white, backgroundColor: Colors.white,
title: LocalText( title: LocalText(
context, context,
"box.info.title", _isNew ? "box.info.title" : "box.edit.title",
fontSize: 20, fontSize: 20,
color: primaryColor, color: primaryColor,
), ),
@@ -408,44 +572,98 @@ class _CartonEditorState extends State<CartonEditor> {
cartonTypeBox, cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"), LocalTitle(textKey: "box.shipment_info"),
_isNew ? fcsShipmentsBox : shipmentBox, _isNew ? fcsShipmentsBox : shipmentBox,
isMixBox ? mixTypeBox : Container(), isMixBox
? _isNew
? mixTypeBox
: mixTypeDisplayBox
: Container(),
...(isMixBox ...(isMixBox
? [ ? [
mixcartonTitleBox, mixcartonTitleBox,
Column( Column(
children: _getMixCartons( children: _getMixCartons(context, this._mixCartons)),
context,
this._mixCartons,
)),
] ]
: [ : [
fcsIDBox, isFromPackages ? fcsIDBox : Container(),
namebox, isFromPackages ? namebox : Container(),
CartonPackageTable( isFromPackages
packages: _carton.packages, ? CartonPackageTable(
onSelect: (p, checked) { packages: _carton.packages,
if (checked && onSelect: (p, checked) {
_deliveryAddress != null && if (checked &&
p.deliveryAddress?.id != _deliveryAddress.id) { _deliveryAddress != null &&
return; p.deliveryAddress?.id !=
} _deliveryAddress.id) {
setState(() { return;
p.isChecked = checked; }
}); setState(() {
_populateDeliveryAddress(); p.isChecked = checked;
}, });
), // _populateDeliveryAddress();
cartonTitleBox, },
Column( )
children: _getCartons( : Container(),
context, isFromCargos
this._cartons, ? Container(
)), padding: const EdgeInsets.only(top: 15),
child: Row(
children: [
Flexible(child: consigneeBox),
Flexible(child: shipperBox)
],
),
)
: Container(),
_isNew ? cartonTitleBox : Container(),
_isNew
? Column(
children: _getCartons(
context,
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( SizedBox(
height: 20, height: 20,
), ),
createBtn, isFromPackages || isFromCargos
? _isNew
? createBtn
: saveBtn
: Container(),
isMixBox ? createMixCarton : Container(),
SizedBox( SizedBox(
height: 20, height: 20,
), ),
@@ -456,19 +674,33 @@ class _CartonEditorState extends State<CartonEditor> {
); );
} }
_addCarton(Carton carton) {
if (carton == null) return;
this._cartons.add(carton);
setState(() {});
}
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) { List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
return cartons.map((c) { return cartons.asMap().entries.map((c) {
return InkWell( return InkWell(
onTap: () {}, 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(() {});
}
},
child: CartonRow( child: CartonRow(
key: ValueKey(c.id), key: ValueKey(c.value.id),
box: c, box: c.value,
), ),
); );
}).toList(); }).toList();
@@ -476,17 +708,16 @@ class _CartonEditorState extends State<CartonEditor> {
List<Widget> _getMixCartons(BuildContext context, List<Carton> cartons) { List<Widget> _getMixCartons(BuildContext context, List<Carton> cartons) {
return cartons.map((c) { return cartons.map((c) {
return InkWell( return CartonRow(
onTap: () {}, key: ValueKey(c.id),
child: CartonRow( box: c,
key: ValueKey(c.id), onRemove: (carton) {
box: c, _removeMixCarton(carton);
), },
); );
}).toList(); }).toList();
} }
CartonSize selectedCatonSize;
Widget cartonSizeDropdown() { Widget cartonSizeDropdown() {
List<CartonSize> _cartonSizes = List<CartonSize> _cartonSizes =
Provider.of<CartonSizeModel>(context).getCartonSizes; Provider.of<CartonSizeModel>(context).getCartonSizes;
@@ -565,70 +796,204 @@ class _CartonEditorState extends State<CartonEditor> {
); );
} }
_save() async { _addCargo(CargoType cargo) {
// bool isFromShipment = _selectedCartonType == carton_from_shipments; if (cargo == null) return;
// bool isSmallBag = _selectedCartonType == carton_small_bag; setState(() {
// if (_user == null && (isFromShipment || isSmallBag)) { _cargoTypes.remove(cargo);
// showMsgDialog(context, "Error", "Please select customer"); _cargoTypes.add(cargo);
// 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;
// }
// Carton carton = Carton(); _removeCargo(CargoType cargo) {
// carton.id = _carton.id; setState(() {
// carton.cartonType = _selectedCartonType; _cargoTypes.remove(cargo);
// carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; });
// carton.userID = _user?.id; }
// carton.cargoTypes = _carton.cargoTypes;
// carton.packages = _carton.packages.where((e) => e.isChecked).toList(); _addCarton() async {
// carton.mixCartonID = _mixCarton?.id; bool isFromPackages = _selectedCartonType == carton_from_packages;
// carton.length = l; bool isFromCargos = _selectedCartonType == carton_from_cargos;
// carton.width = w;
// carton.height = h; if (_fcsShipment == null && _isNew) {
// carton.deliveryAddress = _deliveryAddress; showMsgDialog(context, "Error", "Please select FCS shipment");
// setState(() { return;
// _isLoading = true; }
// });
// try { if (_user == null && isFromPackages) {
// CartonModel cartonModel = showMsgDialog(context, "Error", "Please select FCS ID");
// Provider.of<CartonModel>(context, listen: false); return;
// if (_isNew) { }
// await cartonModel.createCarton(carton);
// } else { if (consignee == null && isFromCargos) {
// await cartonModel.updateCarton(carton); showMsgDialog(context, "Error", "Please select consignee's FCS ID");
// } return;
// Navigator.pop(context, true); }
// } catch (e) {
// showMsgDialog(context, "Error", e.toString()); if (sender == null && isFromCargos) {
// } finally { showMsgDialog(context, "Error", "Please select sender's FCS ID");
// setState(() { return;
// _isLoading = false; }
// });
// } double l = double.parse(_lengthController.text, (s) => 0);
Navigator.pop(context, true); 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() { isDataChanged() {

View File

@@ -1,9 +1,11 @@
import 'package:fcs/domain/constants.dart'; import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton.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/entities/package.dart';
import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.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/main/util.dart';
import 'package:fcs/pages/package/model/package_model.dart'; import 'package:fcs/pages/package/model/package_model.dart';
import 'package:fcs/pages/rates/model/shipment_rate_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 volumetricRatio = 0;
double shipmentWeight = 0; double shipmentWeight = 0;
String selectMixBoxType; String selectMixBoxType;
List<Carton> _cartons = [];
bool isMixBox; bool isMixBox;
bool isFromShipments; bool isFromShipments;
bool isFromPackages; bool isFromPackages;
bool isSmallBag; bool isSmallBag;
bool isFromCartons;
bool isEdiable; bool isEdiable;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_box = widget.box; _box = widget.box;
// _box.cartonType = carton_from_cargos;
// _box.cartonType = carton_mix_box;
//for shipment weight //for shipment weight
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false) volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
.rate .rate
@@ -72,6 +75,7 @@ class _CartonInfoState extends State<CartonInfo> {
_updateBoxData(); _updateBoxData();
_loadPackages(); _loadPackages();
_loadMixCartons();
} }
_updateBoxData() { _updateBoxData() {
@@ -84,20 +88,25 @@ class _CartonInfoState extends State<CartonInfo> {
isFromShipments = _box.cartonType == carton_from_shipments; isFromShipments = _box.cartonType == carton_from_shipments;
isFromPackages = _box.cartonType == carton_from_packages; isFromPackages = _box.cartonType == carton_from_packages;
isSmallBag = _box.cartonType == carton_small_bag; isSmallBag = _box.cartonType == carton_small_bag;
isEdiable = !isMixBox && isFromCartons = _box.cartonType == carton_from_cargos;
(isFromPackages || isSmallBag) &&
isEdiable = (isFromPackages || isMixBox || isFromCartons) &&
_box.status == carton_packed_status; _box.status == carton_packed_status;
selectMixBoxType = _box.mixBoxType ?? "Mix Delivery"; selectMixBoxType = _box.mixBoxType ?? "";
_cartons = [ getCartonSize();
Carton( }
cartonNumber: "A100B-1#1",
cargoTypes: [CargoType(name: "General", weight: 12)], getCartonSize() {
userName: "Seven 7"), var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
Carton( cartonSizeModel.cartonSizes.forEach((c) {
cartonNumber: "A100B-1#2", if (c.length == _box.length &&
cargoTypes: [CargoType(name: "General", weight: 12)], c.width == _box.width &&
userName: "Seven 7"), c.height == _box.height) {
]; setState(() {
_cartonSizeController.text = c.name;
});
}
});
} }
_loadPackages() async { _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() { _calShipmentWeight() {
double l = double.parse(_lengthController.text, (s) => 0); double l = double.parse(_lengthController.text, (s) => 0);
double w = double.parse(_widthController.text, (s) => 0); double w = double.parse(_widthController.text, (s) => 0);
@@ -164,6 +187,55 @@ class _CartonInfoState extends State<CartonInfo> {
iconData: Icons.person, 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( final lengthBox = LengthPicker(
controller: _lengthController, controller: _lengthController,
lableKey: "box.length", lableKey: "box.length",
@@ -275,17 +347,29 @@ class _CartonInfoState extends State<CartonInfo> {
cartonTypeBox, cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"), LocalTitle(textKey: "box.shipment_info"),
shipmentBox, shipmentBox,
isSmallBag ? mixCartonNumberBox : Container(), // isSmallBag ? mixCartonNumberBox : Container(),
isMixBox ? Container() : fcsIDBox,
isMixBox ? Container() : customerNameBox,
isMixBox ? mixTypeBox : Container(),
isMixBox ? LocalTitle(textKey: "boxes.title") : Container(),
isMixBox isMixBox
? Column( ? Container()
children: _getCartons( : isFromPackages
context, ? fcsIDBox
this._cartons, : 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(), : Container(),
isFromPackages || isSmallBag isFromPackages || isSmallBag
? CartonPackageTable( ? CartonPackageTable(
@@ -294,7 +378,7 @@ class _CartonInfoState extends State<CartonInfo> {
: Container(), : Container(),
isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"), isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"),
isMixBox ? Container() : cargoTableBox, isMixBox ? Container() : cargoTableBox,
...(isFromPackages ...(isFromPackages || isFromCartons
? [ ? [
LocalTitle(textKey: "box.dimension"), LocalTitle(textKey: "box.dimension"),
cartonSizeBox, cartonSizeBox,
@@ -326,6 +410,7 @@ class _CartonInfoState extends State<CartonInfo> {
} }
_gotoEditor() async { _gotoEditor() async {
widget.box.mixCartons=_box.mixCartons;
bool updated = await Navigator.push<bool>( bool updated = await Navigator.push<bool>(
context, context,
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)), CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
@@ -335,9 +420,10 @@ class _CartonInfoState extends State<CartonInfo> {
var c = await cartonModel.getCarton(widget.box.id); var c = await cartonModel.getCarton(widget.box.id);
setState(() { setState(() {
_box = c; _box = c;
_loadPackages();
_loadMixCartons();
_updateBoxData(); _updateBoxData();
}); });
_loadPackages();
} }
} }

View File

@@ -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() {}
}

View File

@@ -13,6 +13,7 @@ import 'package:logging/logging.dart';
class CartonModel extends BaseModel { class CartonModel extends BaseModel {
List<Carton> _boxes = []; List<Carton> _boxes = [];
List<Carton> cartons = [];
final log = Logger('CartonModel'); final log = Logger('CartonModel');
List<Carton> get boxes => List<Carton> get boxes =>
_selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values); _selectedIndex == 1 ? _boxes : List<Carton>.from(_delivered.values);
@@ -22,6 +23,7 @@ class CartonModel extends BaseModel {
bool isLoading = false; bool isLoading = false;
StreamSubscription<QuerySnapshot> listener; StreamSubscription<QuerySnapshot> listener;
StreamSubscription<QuerySnapshot> cartonListener;
static List<ShipmentStatus> statusHistory = [ static List<ShipmentStatus> statusHistory = [
ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true), ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true),
ShipmentStatus(status: "Shipped", date: DateTime(2020, 6, 5), done: false), 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> cartonTypes = [
List<String> mixTypes = [mix_delivery, mix_pickup]; carton_from_packages,
// carton_from_cargos,
carton_mix_box
];
List<String> mixBoxTypes = [mix_delivery, mix_pickup];
List<String> cartonTypesInfo = [ List<String> cartonTypesInfo = [
carton_from_packages, carton_from_packages,
carton_from_cargos,
carton_mix_box, carton_mix_box,
carton_from_shipments, carton_from_shipments,
carton_small_bag carton_small_bag
@@ -75,6 +82,7 @@ class CartonModel extends BaseModel {
initData() { initData() {
_selectedIndex = 1; _selectedIndex = 1;
_loadBoxes(); _loadBoxes();
_loadCartonForMixBox();
if (_delivered != null) _delivered.close(); if (_delivered != null) _delivered.close();
_delivered = _getDelivered(); _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() { Paginator _getDelivered() {
if (user == null || !user.hasCarton()) return null; if (user == null || !user.hasCarton()) return null;
@@ -145,8 +182,10 @@ class CartonModel extends BaseModel {
@override @override
logout() async { logout() async {
if (listener != null) await listener.cancel(); if (listener != null) await listener.cancel();
if (cartonListener != null) await cartonListener.cancel();
if (_delivered != null) _delivered.close(); if (_delivered != null) _delivered.close();
_boxes = []; _boxes = [];
cartons = [];
} }
Future<List<Carton>> getCartons(String shipmentID) async { Future<List<Carton>> getCartons(String shipmentID) async {
@@ -207,7 +246,7 @@ class CartonModel extends BaseModel {
return Carton.fromMap(snap.data, snap.documentID); return Carton.fromMap(snap.data, snap.documentID);
} }
Future<void> createCarton(Carton carton) { Future<Carton> createCarton(Carton carton) {
return Services.instance.cartonService.createCarton(carton); return Services.instance.cartonService.createCarton(carton);
} }
@@ -220,38 +259,7 @@ class CartonModel extends BaseModel {
} }
Future<List<Carton>> searchCarton(String term) async { Future<List<Carton>> searchCarton(String term) async {
if (term == null || term == '') return List(); return Services.instance.cartonService.searchCarton(term);
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;
} }
} }

View File

@@ -1,7 +1,9 @@
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton_size.dart'; import 'package:fcs/domain/entities/carton_size.dart';
import 'package:fcs/domain/entities/package.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/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton_size/carton_size_list.dart'; import 'package:fcs/pages/carton_size/carton_size_list.dart';
@@ -29,7 +31,8 @@ import 'model/carton_model.dart';
class PackageCartonEditor extends StatefulWidget { class PackageCartonEditor extends StatefulWidget {
final Carton carton; final Carton carton;
final bool isNew; final bool isNew;
PackageCartonEditor({this.carton, this.isNew}); final User consignee;
PackageCartonEditor({this.carton, this.isNew, this.consignee});
@override @override
_PackageCartonEditorState createState() => _PackageCartonEditorState(); _PackageCartonEditorState createState() => _PackageCartonEditorState();
@@ -43,27 +46,65 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
Carton _carton; Carton _carton;
bool _isLoading = false; bool _isLoading = false;
DeliveryAddress _deliveryAddress = new DeliveryAddress(); DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<DeliveryAddress> _deliveryAddresses = [];
List<CargoType> _cargoTypes = []; List<CargoType> _cargoTypes = [];
CartonSize selectedCatonSize;
bool isFromPackages;
bool isFromCargos;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_load();
}
_load() {
_carton = widget.carton;
isFromPackages = _carton.cartonType == carton_from_packages;
isFromCargos = _carton.cartonType == carton_from_cargos;
_getDeliverAddresses();
if (widget.isNew) { if (widget.isNew) {
_carton = widget.carton;
_lengthCtl.text = "0"; _lengthCtl.text = "0";
_widthCtl.text = "0"; _widthCtl.text = "0";
_heightCtl.text = "0"; _heightCtl.text = "0";
} else { } else {
_carton = widget.carton;
_cargoTypes = List.from(widget.carton.cargoTypes); _cargoTypes = List.from(widget.carton.cargoTypes);
_lengthCtl.text = _carton.length.toString(); _lengthCtl.text = _carton.length.toString();
_widthCtl.text = _carton.width.toString(); _widthCtl.text = _carton.width.toString();
_heightCtl.text = _carton.height.toString(); _heightCtl.text = _carton.height.toString();
_deliveryAddress = _carton.deliveryAddress; _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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final lengthBox = LengthPicker( final lengthBox = LengthPicker(
@@ -94,7 +135,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
], ],
); );
final createBtn = LocalButton( final createBtn = LocalButton(
textKey: "box.new_carton_btn", textKey: widget.isNew ? "box.new_carton_btn" : "box.cargo.save.btn",
callBack: _creatCarton, callBack: _creatCarton,
); );
@@ -164,6 +205,9 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _deliveryAddress, deliveryAddress: _deliveryAddress,
deliveryAddresses: this._deliveryAddresses,
user: widget.consignee,
onAdded: () => _getDeliverAddresses(),
)), )),
); );
if (d == null) return; if (d == null) return;
@@ -182,7 +226,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
); );
} }
CartonSize selectedCatonSize;
Widget cartonSizeDropdown() { Widget cartonSizeDropdown() {
List<CartonSize> _cartonSizes = List<CartonSize> _cartonSizes =
Provider.of<CartonSizeModel>(context).getCartonSizes; Provider.of<CartonSizeModel>(context).getCartonSizes;
@@ -293,10 +336,21 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
carton.id = _carton.id; carton.id = _carton.id;
carton.cartonType = _carton.cartonType; carton.cartonType = _carton.cartonType;
carton.fcsShipmentID = _carton.fcsShipmentID; carton.fcsShipmentID = _carton.fcsShipmentID;
carton.userID = _carton.userID;
carton.cargoTypes = _cargoTypes; carton.cargoTypes = _cargoTypes;
carton.packages = _carton.packages.where((e) => e.isChecked).toList(); if (isFromPackages) {
// carton.cartonSizeID = selectedCatonSize?.id; carton.userID = _carton.userID;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
}
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.length = l;
carton.width = w; carton.width = w;
carton.height = h; carton.height = h;
@@ -308,11 +362,13 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
CartonModel cartonModel = CartonModel cartonModel =
Provider.of<CartonModel>(context, listen: false); Provider.of<CartonModel>(context, listen: false);
if (widget.isNew) { if (widget.isNew) {
await cartonModel.createCarton(carton); Carton _c = await cartonModel.createCarton(carton);
Navigator.pop(context, _c);
} else { } else {
await cartonModel.updateCarton(carton); await cartonModel.updateCarton(carton);
Carton _c = await cartonModel.getCarton(_carton.id);
Navigator.pop(context, _c);
} }
Navigator.pop(context, true);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {

View File

@@ -1,8 +1,11 @@
import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/model/carton_model.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/material.dart';
import 'package:flutter_icons/flutter_icons.dart'; import 'package:flutter_icons/flutter_icons.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'carton_list_row.dart'; import 'carton_list_row.dart';
@@ -21,7 +24,7 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
PartSearchDelegate({this.callbackCartonSelect}); PartSearchDelegate({this.callbackCartonSelect});
@override @override
String get searchFieldLabel => 'Search by Carton Number/Customer Name'; String get searchFieldLabel => 'Search by Carton Number';
@override @override
ThemeData appBarTheme(BuildContext context) { ThemeData appBarTheme(BuildContext context) {
@@ -40,6 +43,11 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
@override @override
List<Widget> buildActions(BuildContext context) { List<Widget> buildActions(BuildContext context) {
return [ return [
IconButton(
icon: Icon(MaterialCommunityIcons.barcode_scan,
size: 30, color: Colors.white),
onPressed: () => _scan(context),
),
IconButton( IconButton(
icon: Icon(Icons.clear), icon: Icon(Icons.clear),
onPressed: () => query = '', onPressed: () => query = '',
@@ -106,17 +114,41 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
@override @override
Widget buildSuggestions(BuildContext context) { Widget buildSuggestions(BuildContext context) {
final cartonModel = Provider.of<CartonModel>(context);
return Container( return Container(
child: Center( padding: EdgeInsets.only(top: 5),
child: Opacity( child: ListView(
opacity: 0.2, children: cartonModel.cartons
child: Icon( .map((u) => CartonListRow(
MaterialCommunityIcons.package, carton: u,
color: primaryColor, callbackCartonSelect: callbackCartonSelect,
size: 200, ))
), .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');
}
}
} }

View File

@@ -43,7 +43,7 @@ class _CustomerListState extends State<CustomerList> {
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon(Icons.search, color: Colors.white), icon: Icon(Icons.search, color: Colors.white),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
_select(u); _select(u);
})), })),
], ],

View File

@@ -172,7 +172,7 @@ class _InvitationCreateState extends State<InvitationCreate> {
} }
isDataChanged() { isDataChanged() {
String userName = _nameController.text; String userName = _nameController.text;
String phoneNumber = _phoneController.text; String phoneNumber = _phoneController.text;
return userName != "" || phoneNumber != ""; return userName != "" || phoneNumber != "";
} }

View File

@@ -1,3 +1,4 @@
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/delivery_address/model/delivery_address_model.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 { class DeliveryAddressEditor extends StatefulWidget {
final DeliveryAddress deliveryAddress; final DeliveryAddress deliveryAddress;
DeliveryAddressEditor({this.deliveryAddress}); final User user;
DeliveryAddressEditor({this.deliveryAddress, this.user});
@override @override
_DeliveryAddressEditorState createState() => _DeliveryAddressEditorState(); _DeliveryAddressEditorState createState() => _DeliveryAddressEditorState();
@@ -195,6 +197,9 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
if (!valid) { if (!valid) {
return; return;
} }
if (widget.user != null) {
deliveryAddress.userID = widget.user.id;
}
setState(() { setState(() {
_isLoading = true; _isLoading = true;
}); });
@@ -202,7 +207,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
try { try {
await deliveryAddressModel.createDeliveryAddress(deliveryAddress); await deliveryAddressModel.createDeliveryAddress(deliveryAddress);
Navigator.pop(context); Navigator.pop(context,true);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {
@@ -225,7 +230,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
try { try {
await deliveryAddressModel.updateDeliveryAddress(deliveryAddress); await deliveryAddressModel.updateDeliveryAddress(deliveryAddress);
Navigator.pop(context); Navigator.pop(context,true);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {
@@ -247,7 +252,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
DeliveryAddressModel deliveryAddressModel = DeliveryAddressModel deliveryAddressModel =
Provider.of<DeliveryAddressModel>(context, listen: false); Provider.of<DeliveryAddressModel>(context, listen: false);
await deliveryAddressModel.deleteDeliveryAddress(_deliveryAddress); await deliveryAddressModel.deleteDeliveryAddress(_deliveryAddress);
Navigator.pop(context); Navigator.pop(context,true);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {

View File

@@ -84,4 +84,16 @@ class DeliveryAddressModel extends BaseModel {
return Services.instance.deliveryAddressService return Services.instance.deliveryAddressService
.selectDefalutDeliveryAddress(deliveryAddress); .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();
}
} }

View File

@@ -77,12 +77,12 @@ class _DiscountEditorState extends State<DiscountEditor> {
)), )),
IconButton( IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
customerId = u.id; customerId = u.id;
customerName = u.name; customerName = u.name;
}); });
})), },popPage: true)),
], ],
); );

View File

@@ -70,19 +70,20 @@ class _PackageInfoState extends State<PackageInfo> {
bool canChangeDeliveryAddress = bool canChangeDeliveryAddress =
_package?.status == package_received_status || _package?.status == package_received_status ||
_package?.status == package_processed_status; _package?.status == package_processed_status;
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
final trackingIdBox = DisplayText( final trackingIdBox = DisplayText(
text: _package?.trackingID??"", text: _package?.trackingID ?? "",
labelTextKey: "package.tracking.id", labelTextKey: "package.tracking.id",
iconData: MaterialCommunityIcons.barcode_scan, iconData: MaterialCommunityIcons.barcode_scan,
); );
var fcsIDBox = DisplayText( var fcsIDBox = DisplayText(
text: _package?.fcsID??"", text: _package?.fcsID ?? "",
labelTextKey: "processing.fcs.id", labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(), icon: FcsIDIcon(),
); );
final customerNameBox = DisplayText( final customerNameBox = DisplayText(
text: _package?.userName??"", text: _package?.userName ?? "",
labelTextKey: "package.create.name", labelTextKey: "package.create.name",
iconData: Icons.perm_identity, iconData: Icons.perm_identity,
); );
@@ -120,8 +121,8 @@ class _PackageInfoState extends State<PackageInfo> {
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _package.deliveryAddress, deliveryAddress: _package.deliveryAddress,
)), deliveryAddresses: deliveryAddressModel.deliveryAddresses)),
); );
if (d == null) return; if (d == null) return;
_changeDeliverayAddress(d); _changeDeliverayAddress(d);
@@ -158,7 +159,9 @@ class _PackageInfoState extends State<PackageInfo> {
widget.isSearchResult ? Container() : fcsIDBox, widget.isSearchResult ? Container() : fcsIDBox,
widget.isSearchResult ? Container() : customerNameBox, widget.isSearchResult ? Container() : customerNameBox,
widget.isSearchResult ? Container() : marketBox, widget.isSearchResult ? Container() : marketBox,
_package==null || _package.photoUrls.length == 0 ? Container() : img, _package == null || _package.photoUrls.length == 0
? Container()
: img,
widget.isSearchResult ? Container() : descBox, widget.isSearchResult ? Container() : descBox,
remarkBox, remarkBox,
_package?.status == package_received_status && _package?.status == package_received_status &&

View File

@@ -23,7 +23,7 @@ class PackageListRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InkWell( return InkWell(
onTap: () { onTap: () {
if (callbackPackageSelect != null) { if (callbackPackageSelect != null) {
callbackPackageSelect(package); callbackPackageSelect(package);
return; return;

View File

@@ -47,7 +47,7 @@ class _PackageNewState extends State<PackageNew> {
)), )),
IconButton( IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
this.user = u; this.user = u;
}); });

View File

@@ -1,3 +1,4 @@
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/market.dart'; import 'package:fcs/domain/entities/market.dart';
import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/domain/entities/user.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/model/package_model.dart';
import 'package:fcs/pages/package/tracking_id_page.dart'; import 'package:fcs/pages/package/tracking_id_page.dart';
import 'package:fcs/pages/main/util.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/barcode_scanner.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/multi_img_controller.dart'; import 'package:fcs/pages/widgets/multi_img_controller.dart';
@@ -32,59 +35,60 @@ class PackageEditor extends StatefulWidget {
class _PackageEditorState extends State<PackageEditor> { class _PackageEditorState extends State<PackageEditor> {
TextEditingController _remarkCtl = new TextEditingController(); TextEditingController _remarkCtl = new TextEditingController();
TextEditingController _descCtl = new TextEditingController(); TextEditingController _descCtl = new TextEditingController();
TextEditingController _trackingIDCtl = new TextEditingController();
bool _isLoading = false; bool _isLoading = false;
bool _isNew;
MultiImgController multiImgController = MultiImgController(); MultiImgController multiImgController = MultiImgController();
Package _package = Package(); Package _package;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.package != null) { _package = Package();
_isNew = false; _loadPackageData(null);
_package = widget.package; }
_trackingIDCtl.text = _package.trackingID;
_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 ?? ""; selectedMarket = _package.market ?? "";
_descCtl.text = _package.desc; _descCtl.text = _package.desc;
_remarkCtl.text = _package.remark; _remarkCtl.text = _package.remark;
multiImgController.setImageFiles = _package.photoFiles; multiImgController.setImageUrls = _package.photoUrls;
} else { });
_isNew = true;
}
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final trackingIDBox = Container( var trackingIDBox = Row(
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: InputText( child: DisplayText(
iconData: MaterialCommunityIcons.barcode_scan, text: _package.trackingID,
labelTextKey: "processing.tracking.id", labelTextKey: "processing.tracking.id",
controller: _trackingIDCtl, iconData: MaterialCommunityIcons.barcode_scan,
)), )),
InkWell( IconButton(
onTap: _scan, icon: Icon(Icons.search, color: primaryColor),
child: Padding( onPressed: () => searchPackage(context, callbackPackageSelect: (u) {
padding: const EdgeInsets.all(8.0), _loadPackageData(u.id);
child: Column( Navigator.pop(context);
children: [ })),
Icon(
MaterialCommunityIcons.barcode_scan,
color: primaryColor,
),
Text("Scan")
],
),
),
),
], ],
)); );
final descBox = InputText( final descBox = InputText(
labelTextKey: 'processing.desc', labelTextKey: 'processing.desc',
@@ -114,7 +118,15 @@ class _PackageEditorState extends State<PackageEditor> {
centerTitle: true, centerTitle: true,
leading: new IconButton( leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30), 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, shadowColor: Colors.transparent,
backgroundColor: Colors.white, 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 { _selectPackage() async {
setState(() { setState(() {
_isLoading = true; _isLoading = true;
@@ -267,21 +254,17 @@ class _PackageEditorState extends State<PackageEditor> {
PackageModel packageModel = PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false); Provider.of<PackageModel>(context, listen: false);
try { try {
Package package=await packageModel.getPackageByTrackingID(_trackingIDCtl.text); _package.market = selectedMarket;
package.trackingID = _trackingIDCtl.text; _package.desc = _descCtl.text;
package.market = selectedMarket; _package.remark = _remarkCtl.text;
package.desc = _descCtl.text; _package.photoFiles = multiImgController.getUpdatedFile;
package.remark = _remarkCtl.text; _package.fcsID = widget.consignee.fcsID;
package.photoFiles = _isNew _package.senderFCSID = widget.sender?.fcsID;
? multiImgController.getAddedFile
: multiImgController.getUpdatedFile;
package.fcsID=widget.consignee.fcsID;
package.senderFCSID=widget.sender?.fcsID;
await packageModel.updateProcessing(package, await packageModel.updateProcessing(_package,
multiImgController.getAddedFile, multiImgController.getDeletedUrl); multiImgController.getAddedFile, multiImgController.getDeletedUrl);
Navigator.pop<Package>(context, package); Navigator.pop<Package>(context, _package);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
} finally { } finally {
@@ -290,4 +273,11 @@ class _PackageEditorState extends State<PackageEditor> {
}); });
} }
} }
isDataChanged() {
return selectedMarket != null ||
_descCtl.text != "" ||
_remarkCtl.text != "" ||
multiImgController.getAddedFile.isNotEmpty;
}
} }

View File

@@ -68,7 +68,7 @@ class _ProcessingEditEditorState extends State<ProcessingEditEditor> {
)), )),
IconButton( IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
this._user = u; this._user = u;
}); });
@@ -267,10 +267,23 @@ class _ProcessingEditEditorState extends State<ProcessingEditEditor> {
} }
isDataChanged() { isDataChanged() {
return _user.fcsID != "" || if (isNew) {
selectedMarket != "" || return _user.fcsID != "" ||
_descCtl.text != "" || selectedMarket != null ||
_remarkCtl.text != "" || _descCtl.text != "" ||
multiImgController.getAddedFile.isNotEmpty; _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;
}
} }
} }

View File

@@ -62,11 +62,11 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
)), )),
IconButton( IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
this.consignee = u; this.consignee = u;
}); });
})), }, popPage: true)),
], ],
); );
@@ -104,11 +104,11 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
)), )),
IconButton( IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
this.sender = u; this.sender = u;
}); });
})), }, popPage: true)),
], ],
); );
@@ -148,7 +148,8 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
), ),
onPressed: () async { onPressed: () async {
if (this.consignee == null) { if (this.consignee == null) {
showMsgDialog(context, "Warning", "Please select 'Consignee'"); showMsgDialog(
context, "Warning", "Please select 'Consignee'");
return; return;
} }
Package _package = await Navigator.push<Package>( Package _package = await Navigator.push<Package>(
@@ -181,13 +182,7 @@ class _ProcesingEditorState extends State<ProcesingEditor> {
icon: icon:
new Icon(CupertinoIcons.back, color: primaryColor, size: 30), new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
onPressed: () { onPressed: () {
if (isDataChanged()) { Navigator.of(context).pop();
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
}
}, },
), ),
shadowColor: Colors.transparent, 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);
}
}
} }

View File

@@ -69,7 +69,7 @@ class _ProcessingEditorState extends State<ProcessingEditor> {
)), )),
IconButton( IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
this._user = u; this._user = u;
}); });

View File

@@ -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/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/main/util.dart';
@@ -12,7 +12,7 @@ import 'package:provider/provider.dart';
import 'model/shipment_rate_model.dart'; import 'model/shipment_rate_model.dart';
class CustomEditor extends StatefulWidget { class CustomEditor extends StatefulWidget {
final CustomDuty custom; final CargoType custom;
CustomEditor({this.custom}); CustomEditor({this.custom});
@override @override
@@ -25,7 +25,7 @@ class _CustomEditorState extends State<CustomEditor> {
TextEditingController _shipmentRateController = new TextEditingController(); TextEditingController _shipmentRateController = new TextEditingController();
bool _isLoading = false; bool _isLoading = false;
CustomDuty _custom = new CustomDuty(); CargoType _custom = new CargoType();
bool _isNew = false; bool _isNew = false;
@override @override
@@ -33,11 +33,10 @@ class _CustomEditorState extends State<CustomEditor> {
super.initState(); super.initState();
if (widget.custom != null) { if (widget.custom != null) {
_custom = widget.custom; _custom = widget.custom;
_productController.text = _custom.productType; _productController.text = _custom.name;
_feeController.text = _custom.fee.toStringAsFixed(2); _feeController.text = _custom.customDutyFee.toStringAsFixed(2);
_shipmentRateController.text = _custom.shipmentRate == null _shipmentRateController.text =
? "" _custom.rate == null ? "" : _custom.rate.toStringAsFixed(2);
: _custom.shipmentRate.toStringAsFixed(2);
} else { } else {
_isNew = true; _isNew = true;
} }
@@ -123,11 +122,10 @@ class _CustomEditorState extends State<CustomEditor> {
try { try {
var shipmentRateModel = var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false); Provider.of<ShipmentRateModel>(context, listen: false);
CustomDuty _customduty = CustomDuty( CargoType _customduty = CargoType(
productType: _productController.text, name: _productController.text,
fee: double.parse(_feeController.text), customDutyFee: double.parse(_feeController.text),
shipmentRate: double.parse(_shipmentRateController.text)); rate: double.parse(_shipmentRateController.text));
print('_customduty => $_customduty');
if (_isNew) { if (_isNew) {
await shipmentRateModel.addCustomDuty(_customduty); await shipmentRateModel.addCustomDuty(_customduty);
} else { } else {
@@ -173,12 +171,11 @@ class _CustomEditorState extends State<CustomEditor> {
_feeController.text != "" || _feeController.text != "" ||
_shipmentRateController.text != ""; _shipmentRateController.text != "";
} else { } else {
CustomDuty _customduty = CustomDuty( CargoType _customduty = CargoType(
productType: _productController.text, name: _productController.text,
fee: double.parse(_feeController.text), customDutyFee: double.parse(_feeController.text),
// shipmentRate: double.parse(_shipmentRateController.text) rate: double.parse(_shipmentRateController.text));
); return widget.custom.isChangedForEditCustomDuty(_customduty);
return widget.custom.isChangedForEdit(_customduty);
} }
} }
} }

View File

@@ -1,3 +1,4 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
@@ -74,8 +75,7 @@ class _CustomListState extends State<CustomList> {
), ),
itemCount: shipmentRateModel.rate.customDuties.length, itemCount: shipmentRateModel.rate.customDuties.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
CustomDuty custom = CargoType custom = shipmentRateModel.rate.customDuties[index];
shipmentRateModel.rate.customDuties[index];
return InkWell( return InkWell(
onTap: () { onTap: () {
_selected _selected
@@ -86,11 +86,11 @@ class _CustomListState extends State<CustomList> {
}, },
child: Container( child: Container(
child: _row( child: _row(
custom.productType, custom.name,
"\$ " + custom.fee.toStringAsFixed(2), "Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2),
custom.shipmentRate == null custom.rate == null
? "" ? ""
: "\$ " + custom.shipmentRate.toStringAsFixed(2)), : "Shipment rate \$ " + custom.rate.toStringAsFixed(2)),
), ),
); );
}), }),
@@ -120,7 +120,7 @@ class _CustomListState extends State<CustomList> {
: Padding( : Padding(
padding: const EdgeInsets.only(top: 3.0), padding: const EdgeInsets.only(top: 3.0),
child: Text( child: Text(
"\$ " + "$shipmentRate", "$shipmentRate",
style: TextStyle(color: Colors.grey, fontSize: 14), style: TextStyle(color: Colors.grey, fontSize: 14),
), ),
) )

View File

@@ -50,16 +50,18 @@ class ShipmentRateModel extends BaseModel {
//CustomDuty //CustomDuty
Future<void> addCustomDuty(CustomDuty customDuty) { Future<void> addCustomDuty(CargoType customDuty) {
return Services.instance.rateService.createCustomDuty(customDuty); customDuty.isCutomDuty=true;
return Services.instance.rateService.createCargoType(customDuty);
} }
Future<void> updateCustomDuty(CustomDuty customDuty) { Future<void> updateCustomDuty(CargoType customDuty) {
return Services.instance.rateService.updateCustomDuty(customDuty); customDuty.isCutomDuty=true;
return Services.instance.rateService.updateCargoType(customDuty);
} }
Future<void> deleteCustomDuty(String id) { Future<void> deleteCustomDuty(String id) {
return Services.instance.rateService.deleteCustomDuty(id); return Services.instance.rateService.deleteCargoType(id);
} }
//Discount by weight //Discount by weight

View File

@@ -145,14 +145,10 @@ class _ShipmentRatesState extends State<ShipmentRates> {
"Volumetric Ratio", "Volumetric Ratio",
"${rate.volumetricRatio.toStringAsFixed(2)}", "${rate.volumetricRatio.toStringAsFixed(2)}",
"in3 per pound"), "in3 per pound"),
_row( _row("Weight difference discount",
"Weight difference discount", "${rate.diffDiscountWeight.toStringAsFixed(2)}", "pounds"),
"${rate.diffDiscountWeight.toStringAsFixed(2)}", _row("Weight difference rate",
"pounds"), "\$ ${rate.diffWeightRate.toStringAsFixed(2)}", ""),
_row(
"Weight difference rate",
"\$ ${rate.diffWeightRate.toStringAsFixed(2)}",
""),
Divider( Divider(
color: Colors.grey, color: Colors.grey,
), ),
@@ -195,10 +191,10 @@ class _ShipmentRatesState extends State<ShipmentRates> {
}).toList(); }).toList();
} }
List<Widget> getCustonWidget(List<CustomDuty> customs) { List<Widget> getCustonWidget(List<CargoType> customs) {
return customs.map((c) { return customs.map((c) {
return Container( return Container(
child: _row(c.productType, "\$ " + c.fee.toStringAsFixed(2), ''), child: _row(c.name, "\$ " + c.customDutyFee.toStringAsFixed(2), ''),
); );
}).toList(); }).toList();
} }

View File

@@ -44,7 +44,8 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
_minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? ""; _minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? "";
_deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? ""; _deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? "";
_volumetricRatio.text = rate.volumetricRatio?.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) ?? ""; _diffWeightRate.text = rate.diffWeightRate?.toStringAsFixed(2) ?? "";
} }
@@ -162,120 +163,4 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
); );
return rate.isChangedForEdit(_rate); 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,
),
],
));
}
} }

View File

@@ -77,11 +77,11 @@ class _ReceivingEditorState extends State<ReceivingEditor> {
)), )),
IconButton( IconButton(
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
this.user = u; this.user = u;
}); });
})), },popPage: true)),
], ],
); );

View File

@@ -81,6 +81,7 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
final shipmentWeightBox = DisplayText( final shipmentWeightBox = DisplayText(
labelTextKey: "shipment.box.shipment.weight", labelTextKey: "shipment.box.shipment.weight",
text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0), text: shipmentWeight == null ? "" : shipmentWeight.toStringAsFixed(0),
@@ -190,8 +191,9 @@ class _ShipmentBoxEditorState extends State<ShipmentBoxEditor> {
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _box.deliveryAddress, deliveryAddress: _box.deliveryAddress,
)), deliveryAddresses:
deliveryAddressModel.deliveryAddresses)),
); );
if (d == null) return; if (d == null) return;
setState(() { setState(() {

View File

@@ -91,6 +91,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup; bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup;
bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff; bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff;
bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff; bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff;
var deliveryAddressModel = Provider.of<DeliveryAddressModel>(context);
final fromTimeBox = InputTime( final fromTimeBox = InputTime(
labelTextKey: 'shipment.from', labelTextKey: 'shipment.from',
iconData: Icons.timer, iconData: Icons.timer,
@@ -129,6 +130,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => DeliveryAddressSelection( builder: (context) => DeliveryAddressSelection(
deliveryAddress: _shipment.pickupAddress, deliveryAddress: _shipment.pickupAddress,
deliveryAddresses: deliveryAddressModel.deliveryAddresses,
)), )),
); );
if (address == null) return; if (address == null) return;

View File

@@ -4,9 +4,9 @@ import 'package:fcs/pages/user_search/user_serach.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class UserListRow extends StatefulWidget { class UserListRow extends StatefulWidget {
final CallbackUserSelect callbackUserSelect; final OnUserRowSelect onUserRowSelect;
final User user; final User user;
const UserListRow({this.user, this.callbackUserSelect}); const UserListRow({this.user, this.onUserRowSelect});
@override @override
_UserListRowState createState() => _UserListRowState(); _UserListRowState createState() => _UserListRowState();
@@ -30,9 +30,8 @@ class _UserListRowState extends State<UserListRow> {
color: Colors.white, color: Colors.white,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
Navigator.pop(context); if (widget.onUserRowSelect != null)
if (widget.callbackUserSelect != null) widget.onUserRowSelect(widget.user);
widget.callbackUserSelect(widget.user);
}, },
child: Row( child: Row(
children: <Widget>[ children: <Widget>[

View File

@@ -5,19 +5,22 @@ import 'package:fcs/pages/user_search/user_list_row.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
typedef CallbackUserSelect(User suer); typedef OnUserSelect(User suer);
typedef OnUserRowSelect(User suer);
Future<User> searchUser(BuildContext context, Future<User> searchUser(BuildContext context,
{CallbackUserSelect callbackUserSelect}) async => {OnUserSelect onUserSelect, bool popPage = false}) async =>
await showSearch<User>( await showSearch<User>(
context: context, context: context,
delegate: UserSearchDelegate(callbackUserSelect: callbackUserSelect), delegate:
UserSearchDelegate(onUserSelect: onUserSelect, popPage: popPage),
); );
class UserSearchDelegate extends SearchDelegate<User> { class UserSearchDelegate extends SearchDelegate<User> {
final CallbackUserSelect callbackUserSelect; final OnUserSelect onUserSelect;
final bool popPage;
UserSearchDelegate({this.callbackUserSelect}); UserSearchDelegate({this.onUserSelect, this.popPage});
@override @override
String get searchFieldLabel => 'Search by FCS ID or Name'; String get searchFieldLabel => 'Search by FCS ID or Name';
@@ -77,7 +80,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
children: snapshot.data children: snapshot.data
.map((u) => UserListRow( .map((u) => UserListRow(
user: u, user: u,
callbackUserSelect: callbackUserSelect, onUserRowSelect: (u) => _onUserRowSelect(context, u),
)) ))
.toList(), .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);
}
}
} }

View File

@@ -1,24 +1,42 @@
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.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_editor.dart';
import 'package:fcs/pages/delivery_address/delivery_address_row.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/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:fcs/pages/widgets/local_text.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
typedef OnAdded();
class DeliveryAddressSelection extends StatelessWidget { class DeliveryAddressSelection extends StatelessWidget {
final DeliveryAddress deliveryAddress; 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); : 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var shipmentModel = Provider.of<DeliveryAddressModel>(context); if (user != null) {}
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
@@ -32,9 +50,15 @@ class DeliveryAddressSelection extends StatelessWidget {
color: primaryColor, fontSize: 20), color: primaryColor, fontSize: 20),
), ),
floatingActionButton: FloatingActionButton.extended( floatingActionButton: FloatingActionButton.extended(
onPressed: () { onPressed: () async {
Navigator.of(context).push(CupertinoPageRoute( bool updated = await Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => DeliveryAddressEditor())); builder: (context) => DeliveryAddressEditor(
user: user,
)));
if (updated && onAdded != null) {
onAdded();
Navigator.pop(context);
}
}, },
icon: Icon(Icons.add), icon: Icon(Icons.add),
label: LocalText(context, "delivery_address.new_address", label: LocalText(context, "delivery_address.new_address",
@@ -47,9 +71,9 @@ class DeliveryAddressSelection extends StatelessWidget {
separatorBuilder: (c, i) => Divider( separatorBuilder: (c, i) => Divider(
color: primaryColor, color: primaryColor,
), ),
itemCount: shipmentModel.deliveryAddresses.length, itemCount: deliveryAddresses.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return _row(context, shipmentModel.deliveryAddresses[index]); return _row(context, deliveryAddresses[index]);
}), }),
)); ));
} }

View File

@@ -7,6 +7,7 @@ import 'local_text.dart';
class DialogInput extends StatefulWidget { class DialogInput extends StatefulWidget {
final String value; final String value;
final String label; final String label;
const DialogInput({Key key, this.label, this.value}) : super(key: key); const DialogInput({Key key, this.label, this.value}) : super(key: key);
@override @override
_DialogInputState createState() => _DialogInputState(); _DialogInputState createState() => _DialogInputState();
@@ -15,6 +16,7 @@ class DialogInput extends StatefulWidget {
class _DialogInputState extends State<DialogInput> { class _DialogInputState extends State<DialogInput> {
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
TextEditingController _controller = new TextEditingController(); TextEditingController _controller = new TextEditingController();
final _focusNode = FocusNode();
bool _isLoading = false; bool _isLoading = false;
@@ -23,6 +25,12 @@ class _DialogInputState extends State<DialogInput> {
super.initState(); super.initState();
if (widget.value != null) { if (widget.value != null) {
_controller.text = widget.value; _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, key: _formKey,
child: TextField( child: TextField(
controller: _controller, controller: _controller,
focusNode: _focusNode,
autofocus: true,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: new InputDecoration( decoration: new InputDecoration(
focusedBorder: UnderlineInputBorder( focusedBorder: UnderlineInputBorder(