add shipments
This commit is contained in:
@@ -6,11 +6,11 @@ import 'package:fcs/pages/carton/model/carton_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/shipment/model/shipment_model.dart';
|
||||
import 'package:fcs/pages/shipment/shipment_pack.dart';
|
||||
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
||||
import 'package:fcs/pages/widgets/local_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
||||
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
||||
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
|
||||
@@ -21,18 +21,20 @@ import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'box_row.dart';
|
||||
import 'shipment_assign.dart';
|
||||
import 'shipment_confirm.dart';
|
||||
import 'shipment_editor.dart';
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentInfo extends StatefulWidget {
|
||||
final bool isCustomer;
|
||||
final Shipment shipment;
|
||||
ShipmentInfo({this.shipment});
|
||||
ShipmentInfo({this.shipment, this.isCustomer});
|
||||
|
||||
@override
|
||||
_ShipmentInfoState createState() => _ShipmentInfoState();
|
||||
@@ -62,24 +64,22 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
|
||||
Shipment _shipment;
|
||||
bool _isLoading = false;
|
||||
bool _isCustomer;
|
||||
var now = new DateTime.now();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_shipment = widget.shipment;
|
||||
_isCustomer = widget.isCustomer;
|
||||
_loadCartons(_shipment.id);
|
||||
|
||||
if (widget.shipment != null) {
|
||||
_addressEditingController.text = _shipment.address;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_noOfPackageEditingController.text = _shipment.numberOfPackage.toString();
|
||||
_weightEditingController.text = _shipment.weight.toString();
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
// _handlingFeeController.text =
|
||||
// numberFormatter.format(_shipment.handlingFee);
|
||||
}
|
||||
_addressEditingController.text = _shipment.address;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_noOfPackageEditingController.text = _shipment.numberOfPackage.toString();
|
||||
_weightEditingController.text = _shipment.weight.toString();
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
}
|
||||
|
||||
_loadCartons(String shipmentID) async {
|
||||
@@ -90,6 +90,16 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
});
|
||||
}
|
||||
|
||||
_loadShipment(String id) async {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
Shipment s = await shipmentModel.getShipment(id);
|
||||
s.boxes = _shipment.boxes;
|
||||
setState(() {
|
||||
_shipment = s;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
@@ -103,7 +113,56 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
bool isCourierPickup = _shipment.shipmentType == shipment_courier_pickup;
|
||||
bool isLocalDropoff = _shipment.shipmentType == shipment_local_dropoff;
|
||||
bool isCourierDropoff = _shipment.shipmentType == shipment_courier_dropoff;
|
||||
bool isEditable = widget.isCustomer
|
||||
? (_shipment.isPending || _shipment.isAssigned)
|
||||
: (_shipment.isPending || _shipment.isAssigned || _shipment.isPickuped);
|
||||
bool canCancel =
|
||||
_shipment.isPending || _shipment.isConfirmed || _shipment.isAssigned;
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
enabled: _shipment.isPending && isLocalPickup,
|
||||
id: 1,
|
||||
textKey: "shipment.assign.for.pickup",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
enabled:
|
||||
(_shipment.isPickuped && isLocalPickup) || _shipment.isReceived,
|
||||
id: 3,
|
||||
textKey: "shipment.pack.menuitem",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
enabled: _shipment.isPending && (isCourierPickup || isCourierDropoff),
|
||||
id: 4,
|
||||
textKey: "shipment.confirm.menuitem",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
enabled: canCancel,
|
||||
id: 2,
|
||||
textKey: "btn.cancel",
|
||||
),
|
||||
],
|
||||
selectable: false,
|
||||
buttonIcon: Icons.more_vert,
|
||||
popupMenuCallback: (p) => p.id == 1
|
||||
? _gotoAssign()
|
||||
: p.id == 2
|
||||
? _cancel()
|
||||
: p.id == 3 ? _gotoPack() : p.id == 4 ? _gotoConfirm() : null,
|
||||
);
|
||||
final popupMenuCustomer = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
enabled: canCancel,
|
||||
id: 2,
|
||||
textKey: "btn.cancel",
|
||||
),
|
||||
],
|
||||
selectable: false,
|
||||
buttonIcon: Icons.more_vert,
|
||||
popupMenuCallback: (p) => p.id == 2 ? _cancel() : null,
|
||||
);
|
||||
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment);
|
||||
|
||||
final fromTimeBox = DisplayText(
|
||||
@@ -136,7 +195,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
onPressed: _openCourierWebsite,
|
||||
icon: Icon(Icons.open_in_new, color: primaryColor),
|
||||
label: Text(
|
||||
'Visit courier websie \nfor nearest drop-off',
|
||||
'Visit courier website \nfor nearest drop-off',
|
||||
style: TextStyle(fontSize: 16, color: primaryColor),
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
@@ -146,14 +205,40 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
iconData: Icons.location_on,
|
||||
labelKey: "shipment.location",
|
||||
);
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
var usersBox = DisplayText(
|
||||
labelTextKey: "shipment.staff",
|
||||
text: _shipment.pickupUserName,
|
||||
iconData: MaterialCommunityIcons.worker);
|
||||
var handlingFeeBox = DisplayText(
|
||||
labelTextKey: "shipment.handling.fee",
|
||||
text: "10",
|
||||
iconData: FontAwesomeIcons.moneyBill);
|
||||
final cancelBtn = LocalButton(
|
||||
textKey: "btn.cancel",
|
||||
callBack: _cancel,
|
||||
text: (_shipment.handlingFee ?? 0).toString(),
|
||||
iconData: FontAwesome.truck);
|
||||
|
||||
final assignCompleteBtn = LocalButton(
|
||||
textKey: "shipment.assign.complete.btn",
|
||||
callBack: _completeAssign,
|
||||
);
|
||||
final completePickupBtn = LocalButton(
|
||||
textKey: "shipment.pickup.complete.btn",
|
||||
callBack: _pickup,
|
||||
);
|
||||
final completePackBtn = LocalButton(
|
||||
textKey: "shipment.pack.complete.btn",
|
||||
callBack: _pack,
|
||||
);
|
||||
final confirmCompleteBtn = LocalButton(
|
||||
textKey: "shipment.confirm.complete.btn",
|
||||
callBack: _confirm,
|
||||
);
|
||||
|
||||
final fcsShipmentNumberBox = DisplayText(
|
||||
text: _shipment.fcsShipmentNumber,
|
||||
labelTextKey: "FCSshipment.number",
|
||||
iconData: Ionicons.ios_airplane,
|
||||
);
|
||||
final completeReceiveBtn = LocalButton(
|
||||
textKey: "shipment.receive.complete.btn",
|
||||
callBack: _receive,
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
@@ -178,24 +263,23 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit, color: primaryColor),
|
||||
onPressed: _edit,
|
||||
icon: Icon(Icons.edit,
|
||||
color: isEditable ? primaryColor : Colors.grey),
|
||||
onPressed: isEditable ? _edit : null,
|
||||
),
|
||||
widget.isCustomer ? popupMenuCustomer : popupMenu,
|
||||
]),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
shipmentNumberBox,
|
||||
|
||||
LocalTitle(textKey: "shipment.type"),
|
||||
LocalRadioButtons(
|
||||
readOnly: true,
|
||||
values: pickupModel.shipmentTypes,
|
||||
selectedValue: _shipment.shipmentType,
|
||||
),
|
||||
// handlingFeeBox,
|
||||
// shipmentTypeBox,
|
||||
...(isLocalDropoff
|
||||
? [
|
||||
LocalTitle(textKey: "shipment.location.dropoff"),
|
||||
@@ -218,17 +302,48 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
toTimeBox,
|
||||
]
|
||||
: []),
|
||||
// localDropoffAddress,
|
||||
// curierDropoffAddress,
|
||||
LocalTitle(
|
||||
textKey: "boxes.name",
|
||||
trailing: Text(
|
||||
"${_shipment.totalCount} Cartons - ${_shipment.totalWeight} lb"),
|
||||
),
|
||||
Column(
|
||||
children: getBoxList(context, _shipment.boxes),
|
||||
),
|
||||
_shipment.currentStatus == shipment_pending_status
|
||||
? cancelBtn
|
||||
: Container()
|
||||
!_isCustomer ? fcsShipmentNumberBox : Container(),
|
||||
...(_shipment.isAssigned ||
|
||||
_shipment.isConfirmed ||
|
||||
_shipment.isPending
|
||||
? [
|
||||
handlingFeeBox,
|
||||
]
|
||||
: []),
|
||||
...(isLocalPickup
|
||||
? [
|
||||
LocalTitle(textKey: "shipment.assign.for.pickup"),
|
||||
usersBox,
|
||||
]
|
||||
: []),
|
||||
...(isLocalPickup && !_isCustomer
|
||||
? [
|
||||
_shipment.isPending ? assignCompleteBtn : Container(),
|
||||
_shipment.isAssigned ? completePickupBtn : Container(),
|
||||
_shipment.isPickuped ? completePackBtn : Container(),
|
||||
]
|
||||
: []),
|
||||
...((isCourierPickup || isCourierDropoff) && !_isCustomer
|
||||
? [
|
||||
_shipment.isPending ? confirmCompleteBtn : Container(),
|
||||
_shipment.isConfirmed ? completeReceiveBtn : Container(),
|
||||
_shipment.isReceived ? completePackBtn : Container(),
|
||||
]
|
||||
: []),
|
||||
...((isLocalDropoff) && !_isCustomer
|
||||
? [
|
||||
_shipment.isPending ? completeReceiveBtn : Container(),
|
||||
_shipment.isReceived ? completePackBtn : Container(),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -256,13 +371,8 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
)),
|
||||
);
|
||||
if (updated ?? false) {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
Shipment s = await shipmentModel.getShipment(_shipment.id);
|
||||
setState(() {
|
||||
_shipment = s;
|
||||
});
|
||||
await _loadCartons(s.id);
|
||||
await _loadShipment(_shipment.id);
|
||||
await _loadCartons(_shipment.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,4 +404,164 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
|
||||
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
||||
launch("${mainModel.setting.courierWebsite}");
|
||||
}
|
||||
|
||||
_gotoAssign() async {
|
||||
bool assigned = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentAssign(
|
||||
shipment: _shipment,
|
||||
)),
|
||||
);
|
||||
if (assigned ?? false) {
|
||||
await _loadShipment(_shipment.id);
|
||||
}
|
||||
}
|
||||
|
||||
_completeAssign() {
|
||||
showConfirmDialog(context, "shipment.assign.complete.confirm", () {
|
||||
_completeAssignShipment();
|
||||
});
|
||||
}
|
||||
|
||||
_completeAssignShipment() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completeAssignShipment(_shipment);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_pickup() {
|
||||
showConfirmDialog(context, "shipment.pickup.complete.confirm", () {
|
||||
_pickupShipment();
|
||||
});
|
||||
}
|
||||
|
||||
_pickupShipment() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completePickupShipment(_shipment);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_gotoPack() async {
|
||||
bool assigned = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentPack(
|
||||
shipment: _shipment,
|
||||
)),
|
||||
);
|
||||
if (assigned ?? false) {
|
||||
await _loadShipment(_shipment.id);
|
||||
await _loadCartons(_shipment.id);
|
||||
}
|
||||
}
|
||||
|
||||
_pack() {
|
||||
showConfirmDialog(context, "shipment.pack.complete.confirm", () {
|
||||
_packShipment();
|
||||
});
|
||||
}
|
||||
|
||||
_packShipment() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completePackShipment(_shipment);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_gotoConfirm() async {
|
||||
bool assigned = await Navigator.push<bool>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ShipmentConfirm(
|
||||
shipment: _shipment,
|
||||
)),
|
||||
);
|
||||
if (assigned ?? false) {
|
||||
await _loadShipment(_shipment.id);
|
||||
}
|
||||
}
|
||||
|
||||
_confirm() {
|
||||
showConfirmDialog(context, "shipment.confirm.complete.confirm", () {
|
||||
_confirmShipment();
|
||||
});
|
||||
}
|
||||
|
||||
_confirmShipment() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completeConfirmShipment(_shipment);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_receive() {
|
||||
showConfirmDialog(context, "shipment.receive.complete.confirm", () {
|
||||
_receiveShipment();
|
||||
});
|
||||
}
|
||||
|
||||
_receiveShipment() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
await shipmentModel.completeReceiveShipment(_shipment);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user