fix errors

This commit is contained in:
Sai Naw Wun
2020-10-22 04:14:53 +06:30
parent 2021f74872
commit e5540c5491
32 changed files with 1069 additions and 811 deletions

View File

@@ -457,6 +457,8 @@
"invoice.shipment_weight":"Shipment weight", "invoice.shipment_weight":"Shipment weight",
"invoice.popupmenu.pending":"Pending", "invoice.popupmenu.pending":"Pending",
"invoice.popupmenu.paid":"Paid", "invoice.popupmenu.paid":"Paid",
"invoice.shipment.title":"Select FCS shipment",
"invoice.customer.title":"Select Customer",
"Invoices End ================================================================":"", "Invoices End ================================================================":"",
"Discount Start ================================================================":"", "Discount Start ================================================================":"",
@@ -469,6 +471,8 @@
"discount.amount":"Amount", "discount.amount":"Amount",
"discount.status":"Status", "discount.status":"Status",
"discount.edit.delete.confirm":"Delete this discount?", "discount.edit.delete.confirm":"Delete this discount?",
"discount.popupmenu.available":"Available discounts",
"discount.popupmenu.used":"Used discounts",
"Discount End ================================================================":"", "Discount End ================================================================":"",
"delivery_addresses Start ================================================================":"", "delivery_addresses Start ================================================================":"",

View File

@@ -457,6 +457,8 @@
"invoice.shipment_weight":"Shipment weight", "invoice.shipment_weight":"Shipment weight",
"invoice.popupmenu.pending":"Pending", "invoice.popupmenu.pending":"Pending",
"invoice.popupmenu.paid":"Paid", "invoice.popupmenu.paid":"Paid",
"invoice.shipment.title":"Select FCS shipment",
"invoice.customer.title":"Select Customer",
"Invoices End ================================================================":"", "Invoices End ================================================================":"",
"Discount Start ================================================================":"", "Discount Start ================================================================":"",
@@ -469,6 +471,8 @@
"discount.amount":"ပမာဏ", "discount.amount":"ပမာဏ",
"discount.status":"အခြေအနေ", "discount.status":"အခြေအနေ",
"discount.edit.delete.confirm":"လျှော့စျေးကို ဖျက်မလား?", "discount.edit.delete.confirm":"လျှော့စျေးကို ဖျက်မလား?",
"discount.popupmenu.available":"Available discounts",
"discount.popupmenu.used":"Used discounts",
"Discount End ================================================================":"", "Discount End ================================================================":"",
"delivery_addresses Start ================================================================":"", "delivery_addresses Start ================================================================":"",

View File

@@ -13,6 +13,7 @@ const custom_duties_collection = "custom_duties";
const discounts_by_weights_collection = "discounts_by_weight"; const discounts_by_weights_collection = "discounts_by_weight";
const shipments_collection = "shipments"; const shipments_collection = "shipments";
const cartons_collection = "cartons"; const cartons_collection = "cartons";
const discounts_collection = "discounts";
// docs // docs
const setting_doc_id = "setting"; const setting_doc_id = "setting";

View File

@@ -9,6 +9,9 @@ class CargoType {
int shipmentWeight; int shipmentWeight;
double amount; double amount;
double calRate;
double calWeight;
factory CargoType.fromMap(Map<String, dynamic> map, String id) { factory CargoType.fromMap(Map<String, dynamic> map, String id) {
return CargoType( return CargoType(
id: id, id: id,

View File

@@ -43,10 +43,9 @@ class Carton {
String remark; String remark;
DateTime arrivedDate; DateTime arrivedDate;
String cartonNumber; String cartonNumber;
List<String> packageIDs; List<String> packageIDs;
List<Package> packages; List<Package> packages;
List<CargoType> cargoTypes; List<CargoType> cargoTypes;
List<Carton> cartons; List<Carton> cartons;
@@ -193,4 +192,10 @@ class Carton {
deliveryAddress: _da, deliveryAddress: _da,
cargoTypes: cargoTypes); cargoTypes: cargoTypes);
} }
@override
bool operator ==(Object other) => other is Carton && other.id == id;
@override
int get hashCode => id.hashCode;
} }

View File

@@ -22,4 +22,10 @@ class CustomDuty {
'fee': fee, 'fee': fee,
}; };
} }
@override
bool operator ==(Object other) => other is CustomDuty && other.id == id;
@override
int get hashCode => id.hashCode;
} }

View File

@@ -1,3 +1,10 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package.dart'; import 'package.dart';
import 'receipt.dart'; import 'receipt.dart';
@@ -8,13 +15,89 @@ class Invoice {
String customerName; String customerName;
String customerPhoneNumber; String customerPhoneNumber;
double amount; double amount;
String discount;
String status; String status;
String paymentAttachment; String paymentAttachment;
double handlingFee;
double deliveryFee;
double paidAmount;
List<Package> packages; List<Package> packages;
List<Receipt> receipts; List<Receipt> receipts;
List<String> receiptPhotos; List<String> receiptPhotos;
List<CustomDuty> customDuties;
List<Carton> cartons;
Discount discount;
List<CargoType> getCargoTypes(Rate rate) {
List<CargoType> cargoTypes = [];
double actualWeight = 0;
double shipmentWeight = 0;
cartons.forEach((c) {
c.cargoTypes.forEach((tc) {
if (cargoTypes.contains(tc)) {
CargoType existing = cargoTypes.firstWhere((wc) => wc.id == tc.id);
existing.weight += tc.weight;
} else {
cargoTypes.add(tc);
}
actualWeight += tc.weight;
});
double volume = (c.length ?? 0) * (c.width ?? 0) * (c.height ?? 0);
double sw = volume / rate.volumetricRatio ?? 0;
shipmentWeight += sw;
});
DiscountByWeight discountByWeight = rate.getDiscountByWeight(
shipmentWeight > actualWeight ? shipmentWeight : actualWeight);
cargoTypes.forEach((e) {
print(actualWeight > shipmentWeight);
double cargoWeight = actualWeight > shipmentWeight
? e.weight
: e.weight / actualWeight * shipmentWeight;
double r =
e.rate - (discountByWeight != null ? discountByWeight.discount : 0);
double amount = cargoWeight * r;
e.calRate = r;
e.calWeight = cargoWeight;
e.amount = amount;
});
return cargoTypes;
}
double getTotal(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.amount + p);
return total;
}
double getNetAmount(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.amount + p);
total += getCustomFee();
total += getDeliveryFee();
total += getHandlingFee();
total -= getDiscount();
return total;
}
double getTotalBalance(Rate rate) {
return getNetAmount(rate) - (paidAmount ?? 0);
}
double getCustomFee() {
return customDuties == null ? 0 : customDuties.fold(0, (p, d) => p + d.fee);
}
double getHandlingFee() {
return handlingFee == null ? 0 : handlingFee;
}
double getDeliveryFee() {
return deliveryFee == null ? 0 : deliveryFee;
}
double getDiscount() => discount == null ? 0 : discount.amount;
Invoice( Invoice(
{this.id, {this.id,
@@ -28,6 +111,9 @@ class Invoice {
this.paymentAttachment, this.paymentAttachment,
this.packages, this.packages,
this.receiptPhotos, this.receiptPhotos,
this.customDuties,
this.cartons,
this.handlingFee,
this.receipts}); this.receipts});
double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p); double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p);

View File

@@ -13,6 +13,7 @@ class Shipment {
String pickupTimeEnd; String pickupTimeEnd;
String userName; String userName;
String userID;
String phoneNumber; String phoneNumber;
int numberOfPackage; int numberOfPackage;
int weight; int weight;
@@ -35,6 +36,7 @@ class Shipment {
{this.id, {this.id,
this.shipmentNumber, this.shipmentNumber,
this.shipmentType, this.shipmentType,
this.userID,
this.userName, this.userName,
this.phoneNumber, this.phoneNumber,
this.pickupTimeStart, this.pickupTimeStart,
@@ -75,6 +77,7 @@ class Shipment {
return Shipment( return Shipment(
id: id, id: id,
userName: map['user_name'], userName: map['user_name'],
userID: map['user_id'],
shipmentNumber: map['shipment_number'], shipmentNumber: map['shipment_number'],
phoneNumber: map['phone_number'], phoneNumber: map['phone_number'],
pickupDate: pd == null ? null : pd.toDate(), pickupDate: pd == null ? null : pd.toDate(),
@@ -97,6 +100,7 @@ class Shipment {
return { return {
"id": id, "id": id,
'user_id': userID,
'cartons': _boxes, 'cartons': _boxes,
'shipment_type': shipmentType, 'shipment_type': shipmentType,
'pickup_address': pickupAddress.toMap(), 'pickup_address': pickupAddress.toMap(),

View File

@@ -490,7 +490,7 @@ class _CartonEditorState extends State<CartonEditor> {
showMsgDialog(context, "Error", "Invalid delivery address"); showMsgDialog(context, "Error", "Invalid delivery address");
return; return;
} }
if (isSmallBag && _mixCarton == null) { if (isSmallBag && _mixCarton == null && _isNew) {
showMsgDialog(context, "Error", "Invalid mix carton"); showMsgDialog(context, "Error", "Invalid mix carton");
return; return;
} }
@@ -507,7 +507,9 @@ class _CartonEditorState extends State<CartonEditor> {
carton.width = w; carton.width = w;
carton.height = h; carton.height = h;
carton.deliveryAddress = _deliveryAddress; carton.deliveryAddress = _deliveryAddress;
carton.cartons = _carton.cartons.where((c) => c.isChecked).toList(); carton.cartons = _carton.cartons == null
? []
: _carton.cartons.where((c) => c.isChecked).toList();
setState(() { setState(() {
_isLoading = true; _isLoading = true;
}); });

View File

@@ -68,17 +68,7 @@ class _CartonListState extends State<CartonList> {
backgroundColor: primaryColor, backgroundColor: primaryColor,
title: LocalText(context, "boxes.name", title: LocalText(context, "boxes.name",
color: Colors.white, fontSize: 20), color: Colors.white, fontSize: 20),
actions: <Widget>[ actions: <Widget>[popupMenu],
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
iconSize: 30, onPressed: () {},
// onPressed: () => showPlacesSearch(context),
),
popupMenu
],
), ),
floatingActionButton: FloatingActionButton.extended( floatingActionButton: FloatingActionButton.extended(
onPressed: () { onPressed: () {

View File

@@ -174,6 +174,21 @@ class CartonModel extends BaseModel {
.toList(); .toList();
} }
Future<List<Carton>> getCartonsForInvoice(
String fcsShipmentID, String userID) async {
String path = "/$cartons_collection";
var querySnap = await Firestore.instance
.collection(path)
// .where("fcs_shipment_id", isEqualTo: fcsShipmentID)
.where("user_id", isEqualTo: userID)
.where("is_deleted", isEqualTo: false)
.where("is_invoiced", isEqualTo: false)
.getDocuments();
return querySnap.documents
.map((e) => Carton.fromMap(e.data, e.documentID))
.toList();
}
Future<List<Carton>> getMixCartonsByFcsShipment(String fcsShipmentID) async { Future<List<Carton>> getMixCartonsByFcsShipment(String fcsShipmentID) async {
String path = "/$cartons_collection"; String path = "/$cartons_collection";
var querySnap = await Firestore.instance var querySnap = await Firestore.instance

View File

@@ -96,6 +96,25 @@ class CustomerModel extends BaseModel {
return User.fromMap(snap.data, snap.documentID); return User.fromMap(snap.data, snap.documentID);
} }
Future<List<User>> getInvoiceUsers(String fcsShipmentID) async {
List<User> users = [];
try {
var snaps = await Firestore.instance
.collection(
"/$fcs_shipment_collection/$fcsShipmentID/$user_collection")
.where("pending_invoice_carton_count", isGreaterThan: 0)
.getDocuments(source: Source.server);
users = snaps.documents.map((documentSnapshot) {
var user =
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
return user;
}).toList();
} catch (e) {
log.warning("Error!! $e");
}
return users;
}
Future<void> enableUser(User user, bool enabled) { Future<void> enableUser(User user, bool enabled) {
return Services.instance.userService.enableUser(user.id, enabled); return Services.instance.userService.enableUser(user.id, enabled);
} }

View File

@@ -67,17 +67,7 @@ class _DeliverListState extends State<DeliverList> {
backgroundColor: primaryColor, backgroundColor: primaryColor,
title: LocalText(context, "delivery", title: LocalText(context, "delivery",
color: Colors.white, fontSize: 20), color: Colors.white, fontSize: 20),
actions: <Widget>[ actions: <Widget>[popupMenu],
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
iconSize: 30,
// onPressed: () => showPlacesSearch(context),
),
popupMenu
],
), ),
body: Column( body: Column(
children: [ children: [

View File

@@ -3,6 +3,8 @@ import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/discount/discount_list_row.dart'; import 'package:fcs/pages/discount/discount_list_row.dart';
import 'package:fcs/pages/discount/model/discount_model.dart'; import 'package:fcs/pages/discount/model/discount_model.dart';
import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/main/util.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_text.dart'; import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart'; import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@@ -12,29 +14,48 @@ import 'package:provider/provider.dart';
import 'discount_editor.dart'; import 'discount_editor.dart';
class DiscountList extends StatefulWidget { class DiscountList extends StatefulWidget {
final bool selected; final bool selectionMode;
const DiscountList({Key key, this.selected}) : super(key: key); const DiscountList({Key key, this.selectionMode}) : super(key: key);
@override @override
_DiscountListState createState() => _DiscountListState(); _DiscountListState createState() => _DiscountListState();
} }
class _DiscountListState extends State<DiscountList> { class _DiscountListState extends State<DiscountList> {
bool _isLoading = false; bool _isLoading = false;
bool _selected = false; var _controller = ScrollController();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.selected != null) { _controller.addListener(() async {
_selected = widget.selected; if (_controller.position.pixels == _controller.position.maxScrollExtent) {
} Provider.of<DiscountModel>(context, listen: false).loadMore();
}
});
Provider.of<DiscountModel>(context, listen: false).initData();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var discountModel = Provider.of<DiscountModel>(context); var discountModel = Provider.of<DiscountModel>(context);
print('discounts => ${discountModel.discounts}');
final popupMenu = LocalPopupMenuButton(
popmenus: [
LocalPopupMenu(
id: 1,
textKey: "discount.popupmenu.available",
selected: discountModel.selectedIndex == 1),
LocalPopupMenu(
id: 2,
textKey: "discount.popupmenu.used",
selected: discountModel.selectedIndex == 2)
],
popupMenuCallback: (p) => this.setState(() {
discountModel.selectedIndex = p.id;
}),
);
return LocalProgress( return LocalProgress(
inAsyncCall: _isLoading, inAsyncCall: _isLoading,
child: Scaffold( child: Scaffold(
@@ -48,26 +69,53 @@ class _DiscountListState extends State<DiscountList> {
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
backgroundColor: primaryColor, backgroundColor: primaryColor,
actions: <Widget>[ actions: <Widget>[popupMenu],
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
)
],
), ),
body: ListView.separated( body: Column(
separatorBuilder: (context, index) => Divider( children: [
color: Colors.black, Expanded(
height: 1, child: ListView.separated(
), separatorBuilder: (context, index) => Divider(
itemCount: discountModel.discounts.length, color: Colors.black,
itemBuilder: (BuildContext context, int index) { height: 1,
var discount = discountModel.discounts[index]; ),
return DiscountListRow( controller: _controller,
key: ValueKey(discount.id), itemCount: discountModel.discounts.length,
discount: discount, itemBuilder: (BuildContext context, int index) {
); var discount = discountModel.discounts[index];
}, return DiscountListRow(
key: ValueKey(discount.id),
discount: discount,
onSelect: (d) {
if (widget.selectionMode) {
Navigator.pop(context, discount);
return;
}
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
DiscountEditor(discount: discount)),
);
},
);
},
),
),
discountModel.isLoading
? Container(
padding: EdgeInsets.all(8),
color: primaryColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Loading...",
style: TextStyle(color: Colors.white)),
],
),
)
: Container(),
],
), ),
floatingActionButton: FloatingActionButton.extended( floatingActionButton: FloatingActionButton.extended(
onPressed: () { onPressed: () {

View File

@@ -8,9 +8,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart'; import 'package:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
typedef OnSelect(Discount discount);
class DiscountListRow extends StatelessWidget { class DiscountListRow extends StatelessWidget {
final OnSelect onSelect;
final Discount discount; final Discount discount;
DiscountListRow({Key key, this.discount}) : super(key: key); DiscountListRow({Key key, this.discount, this.onSelect}) : super(key: key);
final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); final DateFormat dateFormat = new DateFormat("dd MMM yyyy");
@@ -18,11 +21,9 @@ class DiscountListRow extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InkWell( return InkWell(
onTap: () { onTap: () {
Navigator.push( if (onSelect != null) {
context, onSelect(discount);
CupertinoPageRoute( }
builder: (context) => DiscountEditor(discount: discount)),
);
}, },
child: Container( child: Container(
padding: EdgeInsets.only(left: 15, right: 15), padding: EdgeInsets.only(left: 15, right: 15),

View File

@@ -2,7 +2,9 @@ import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/data/services/services.dart'; import 'package:fcs/data/services/services.dart';
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/discount.dart'; import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/helpers/paginator.dart';
import 'package:fcs/pages/main/model/base_model.dart'; import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
@@ -11,7 +13,28 @@ class DiscountModel extends BaseModel {
StreamSubscription<QuerySnapshot> listener; StreamSubscription<QuerySnapshot> listener;
List<Discount> discounts = []; List<Discount> _discounts = [];
List<Discount> get discounts =>
_selectedIndex == 1 ? _discounts : List<Discount>.from(_used.values);
Paginator _used;
bool isLoading = false;
int _selectedIndex = 1;
set selectedIndex(int index) {
_selectedIndex = index;
notifyListeners();
}
get selectedIndex => _selectedIndex;
initData() {
_selectedIndex = 1;
_load();
if (_used != null) _used.close();
_used = _getUsed();
_used.load();
}
void initUser(user) { void initUser(user) {
super.initUser(user); super.initUser(user);
@@ -22,7 +45,7 @@ class DiscountModel extends BaseModel {
if (listener != null) listener.cancel(); if (listener != null) listener.cancel();
try { try {
listener = Firestore.instance listener = Firestore.instance
.collection("/discounts") .collection("/$discounts_collection")
.orderBy("code", descending: false) .orderBy("code", descending: false)
.snapshots() .snapshots()
.listen((snaps) { .listen((snaps) {
@@ -37,9 +60,42 @@ class DiscountModel extends BaseModel {
} }
} }
Paginator _getUsed() {
if (user == null || !user.hasFcsShipments()) return null;
var pageQuery = Firestore.instance
.collection("/$discounts_collection")
.where("status", isEqualTo: fcs_shipment_shipped_status)
.orderBy("code", descending: false);
var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) {
return Discount.fromMap(data, id);
});
return paginator;
}
Future<void> loadMore() async {
if (_used.ended || _selectedIndex == 1) return;
isLoading = true;
notifyListeners();
await _used.load(onFinished: () {
isLoading = false;
notifyListeners();
});
}
Future<void> refresh() async {
if (_selectedIndex == 1) return;
await _used.refresh(onFinished: () {
notifyListeners();
});
}
@override @override
logout() async { logout() async {
discounts = []; if (listener != null) await listener.cancel();
if (_used != null) _used.close();
_discounts = [];
} }
Future<void> addDiscount(Discount discount) async { Future<void> addDiscount(Discount discount) async {

View File

@@ -83,7 +83,7 @@ class FcsShipmentModel extends BaseModel {
} }
Future<void> loadMore() async { Future<void> loadMore() async {
if (_shipped.ended && _selectedIndex == 1) return; if (_shipped.ended || _selectedIndex == 1) return;
isLoading = true; isLoading = true;
notifyListeners(); notifyListeners();
await _shipped.load(onFinished: () { await _shipped.load(onFinished: () {
@@ -132,6 +132,24 @@ class FcsShipmentModel extends BaseModel {
return null; return null;
} }
Future<List<FcsShipment>> getInvoiceFcsShipments() async {
List<FcsShipment> fcsShipments = [];
try {
var snaps = await Firestore.instance
.collection("/$fcs_shipment_collection")
.where("pending_invoice_user_count", isGreaterThan: 0)
.getDocuments(source: Source.server);
fcsShipments = snaps.documents.map((documentSnapshot) {
var fcs = FcsShipment.fromMap(
documentSnapshot.data, documentSnapshot.documentID);
return fcs;
}).toList();
} catch (e) {
log.warning("Error!! $e");
}
return fcsShipments;
}
void initUser(user) { void initUser(user) {
super.initUser(user); super.initUser(user);
} }

View File

@@ -77,12 +77,7 @@ class _InvoiceListState extends State<InvoiceList> {
backgroundColor: primaryColor, backgroundColor: primaryColor,
title: LocalText(context, 'invoices.title', title: LocalText(context, 'invoices.title',
color: Colors.white, fontSize: 20), color: Colors.white, fontSize: 20),
actions: <Widget>[ actions: <Widget>[popupMenu],
IconButton(
icon: Icon(Icons.search, color: Colors.white),
onPressed: () {}),
popupMenu
],
), ),
floatingActionButton: owner floatingActionButton: owner
? FloatingActionButton.extended( ? FloatingActionButton.extended(

View File

@@ -0,0 +1,342 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/domain/entities/invoice.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/discount/discount_list.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
typedef OnDiscountSelected(Discount discount);
typedef OnDeliveryFeeSelected(bool selected);
class InvoiceCargoTable extends StatelessWidget {
final Invoice invoice;
final Rate rate;
final OnDiscountSelected discountSelected;
final OnDeliveryFeeSelected deliveryFeeSelected;
const InvoiceCargoTable(
{Key key,
this.invoice,
this.discountSelected,
this.deliveryFeeSelected,
this.rate})
: super(key: key);
@override
Widget build(BuildContext context) {
return Column(children: getRows(context));
}
getRows(BuildContext context) {
List<CargoType> _cargoTypes = invoice.getCargoTypes(rate);
double total = 0;
List<Widget> dataRow = _cargoTypes.map((cargo) {
var amount = cargo.calWeight * cargo.calRate;
total += amount;
return Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
child: Row(
children: [
Expanded(flex: 2, child: Text('${cargo.name}')),
Expanded(
flex: 2,
child: Text('${cargo.calWeight} x ${cargo.calRate}',
textAlign: TextAlign.center)),
Expanded(
child: Text('\$ $amount',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
);
}).toList();
dataRow.insert(
0,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(getLocalString(context, 'invoice.box.cargo_type'),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey))),
Expanded(
flex: 2,
child: Text(
getLocalString(context, 'cargo.weight') +
' x ' +
getLocalString(context, 'cargo.rate'),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey))),
Expanded(
child: Text(getLocalString(context, 'invoice.amount'),
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.total',
color: Colors.black,
),
),
),
SizedBox(width: 40),
Expanded(
child: Text(
'\$ $total',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.discount_value',
color: Colors.black,
),
),
),
new IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () async {
Discount discount = await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) =>
DiscountList(selectionMode: true)));
if (discountSelected != null) {
discountSelected(discount);
}
}),
Expanded(
child: Text('\$ ( ${invoice.getDiscount()} )',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 0.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.custom_fee',
color: Colors.black,
),
),
),
SizedBox(width: 40),
Expanded(
child: Text('\$ ${invoice.getCustomFee()}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)),
),
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 20.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.handling_fee',
color: Colors.black,
),
),
),
SizedBox(width: 50),
Expanded(
child: Text('\$ ${invoice.handlingFee?.toString() ?? ""}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.delivery_fee',
color: Colors.black,
),
)),
Switch(
value: (invoice.deliveryFee ?? 0) > 0,
onChanged: (value) {
if (deliveryFeeSelected != null) {
deliveryFeeSelected(value);
}
},
activeTrackColor: primaryColor.withOpacity(0.8),
activeColor: primaryColor,
),
Expanded(
child: Text('\$ ${invoice.getDeliveryFee()}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
child: Row(
children: [
Expanded(child: Text('')),
Expanded(
flex: 2,
child: Divider(
thickness: 3,
)),
],
)));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
'invoice.net_amount',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: Text('\$ ${invoice.getNetAmount(rate)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: primaryColor)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
'invoice.balance',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: Text('\$ ${invoice.getTotalBalance(rate)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: primaryColor)))
],
),
));
return dataRow;
}
}

View File

@@ -0,0 +1,113 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
typedef OnSelect = Function(Carton carton, bool checked);
class InvoiceCartonTable extends StatelessWidget {
final List<Carton> cartons;
final OnSelect onSelect;
const InvoiceCartonTable({Key key, this.cartons, this.onSelect})
: super(key: key);
@override
Widget build(BuildContext context) {
final tableTitle = Container(
padding: EdgeInsets.only(right: 10.0, top: 20),
child: Row(
children: <Widget>[
SizedBox(
width: 50,
),
SizedBox(
width: 150,
child: LocalText(context, 'invoice.box.number', color: Colors.grey),
),
LocalText(context, 'invoice.shipment_weight', color: Colors.grey),
],
),
);
final rows = cartons == null
? [Container()]
: cartons.asMap().entries.map((p) {
return Container(
color: p.value.isChecked
? Colors.grey.withOpacity(0.2)
: Colors.grey[50].withOpacity(0.2),
child: Container(
padding: EdgeInsets.only(
left: 0.0, right: 10.0, top: 3.0, bottom: 3.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: p.key == cartons.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
onSelect == null
? p.value.isChecked
? SizedBox(
child: Icon(Icons.check, color: primaryColor),
width: 30)
: SizedBox(width: 30)
: Checkbox(
value: p.value.isChecked,
activeColor: primaryColor,
onChanged: (bool check) {
if (onSelect != null) onSelect(p.value, check);
}),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
p.value.cartonNumber,
style: textStyle,
),
Text(
p.value.shipmentNumber ?? "",
style: textStyle,
),
],
)),
Flexible(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
new Text(
"${p.value?.length ?? ""} x ${p.value?.width ?? ""} x ${p.value?.height ?? ""}",
style: textStyle,
),
],
),
)
],
),
),
);
}).toList();
return Column(
children: [
LocalTitle(textKey: "invoice.box_info"),
tableTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: rows,
),
],
);
}
}

View File

@@ -0,0 +1,107 @@
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/my_data_table.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
typedef OnAdd(CustomDuty customDuty);
typedef OnRemove(CustomDuty customDuty);
class InvoiceCustomTable extends StatelessWidget {
final List<CustomDuty> customDuties;
final OnAdd onAdd;
final OnRemove onRemove;
const InvoiceCustomTable(
{Key key, this.customDuties, this.onAdd, this.onRemove})
: super(key: key);
@override
Widget build(BuildContext context) {
return MyDataTable(
headingRowHeight: 40,
columns: [
MyDataColumn(
label: LocalText(
context,
"rate.cutom.product_type",
color: Colors.grey,
),
),
MyDataColumn(
label: LocalText(
context,
"rate.custom.fee",
color: Colors.grey,
),
),
],
rows: getRows(context),
);
}
List<MyDataRow> getRows(BuildContext context) {
if (customDuties == null) {
return [];
}
double total = 0;
var rows = customDuties.map((c) {
total += c.fee;
return MyDataRow(
cells: [
MyDataCell(new Text(
c.productType == null ? "" : c.productType,
style: textStyle,
)),
MyDataCell(
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(c.fee == null ? "0" : c.fee.toString(), style: textStyle),
onRemove == null
? SizedBox(
width: 50,
)
: IconButton(
icon: Icon(
Icons.remove_circle,
color: primaryColor,
),
onPressed: () {
if (onRemove != null) onRemove(c);
})
],
),
),
],
);
}).toList();
var totalRow = MyDataRow(
onSelectChanged: (bool selected) {},
cells: [
MyDataCell(Align(
alignment: Alignment.centerRight,
child: LocalText(
context,
"invoice.total_custom_fee",
color: Colors.black87,
fontWeight: FontWeight.bold,
),
)),
MyDataCell(
Padding(
padding: const EdgeInsets.only(right: 48.0),
child: Align(
alignment: Alignment.centerRight,
child: Text(total.toString(),
style: TextStyle(fontWeight: FontWeight.bold))),
),
),
],
);
rows.add(totalRow);
return rows;
}
}

View File

@@ -1,6 +1,6 @@
import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/customer/customer_editor.dart';
import 'package:fcs/pages/customer/model/customer_model.dart'; import 'package:fcs/pages/customer/model/customer_model.dart';
import 'package:fcs/pages/invoice/invoice_editor.dart'; import 'package:fcs/pages/invoice/invoice_editor.dart';
import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/local_text.dart';
@@ -11,6 +11,10 @@ import 'package:intl/intl.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class InvoiceCustomerList extends StatefulWidget { class InvoiceCustomerList extends StatefulWidget {
final FcsShipment fcsShipment;
const InvoiceCustomerList({Key key, this.fcsShipment}) : super(key: key);
@override @override
_InvoiceCustomerListState createState() => _InvoiceCustomerListState(); _InvoiceCustomerListState createState() => _InvoiceCustomerListState();
} }
@@ -19,11 +23,24 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
var dateFormatter = new DateFormat('dd MMM yyyy - hh:mm:ss a'); var dateFormatter = new DateFormat('dd MMM yyyy - hh:mm:ss a');
final double dotSize = 15.0; final double dotSize = 15.0;
bool _isLoading = false; bool _isLoading = false;
List<User> _users = [];
@override
void initState() {
super.initState();
_load();
}
_load() async {
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
var users = await customerModel.getInvoiceUsers(widget.fcsShipment.id);
setState(() {
_users = users;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var customerModel = Provider.of<CustomerModel>(context);
return LocalProgress( return LocalProgress(
inAsyncCall: _isLoading, inAsyncCall: _isLoading,
child: Scaffold( child: Scaffold(
@@ -51,9 +68,9 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
), ),
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
shrinkWrap: true, shrinkWrap: true,
itemCount: customerModel.customers.length, itemCount: _users.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
User customer = customerModel.customers[index]; User customer = _users[index];
return _item(customer); return _item(customer);
}), }),
), ),
@@ -67,7 +84,10 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
return InkWell( return InkWell(
onTap: () { onTap: () {
Navigator.of(context).push(CupertinoPageRoute( Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => InvoiceEditor(customer: customer))); builder: (context) => InvoiceEditor(
customer: customer,
fcsShipment: widget.fcsShipment,
)));
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.only(left: 12.0, right: 12), padding: const EdgeInsets.only(left: 12.0, right: 12),
@@ -78,21 +98,18 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
padding: const EdgeInsets.symmetric(vertical: 2.0), padding: const EdgeInsets.symmetric(vertical: 2.0),
child: new Row( child: new Row(
children: <Widget>[ children: <Widget>[
InkWell( Padding(
onTap: () => _select(customer), padding: const EdgeInsets.all(5.0),
child: Padding( child: Container(
padding: const EdgeInsets.all(5.0), padding: const EdgeInsets.only(
child: Container( left: 10.0, right: 10, top: 6, bottom: 6),
padding: const EdgeInsets.only( decoration: BoxDecoration(
left: 10.0, right: 10, top: 6, bottom: 6), color: primaryColor,
decoration: BoxDecoration( borderRadius:
color: primaryColor, BorderRadius.all(Radius.circular(35.0))),
borderRadius: child: Text(
BorderRadius.all(Radius.circular(35.0))), customer.initial,
child: Text( style: TextStyle(fontSize: 30, color: Colors.white),
customer.initial,
style: TextStyle(fontSize: 30, color: Colors.white),
),
), ),
), ),
), ),
@@ -113,7 +130,7 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
Padding( Padding(
padding: const EdgeInsets.only(top: 2.0), padding: const EdgeInsets.only(top: 2.0),
child: new Text( child: new Text(
customer.getLastMessage, customer.phoneNumber,
style: new TextStyle( style: new TextStyle(
fontSize: 15.0, color: Colors.grey), fontSize: 15.0, color: Colors.grey),
), ),
@@ -140,9 +157,4 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
), ),
); );
} }
_select(User customer) {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => CustomerEditor(customer: customer)));
}
} }

View File

@@ -1,32 +1,28 @@
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.dart';
import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/entities/discount.dart'; import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/domain/entities/invoice.dart'; import 'package:fcs/domain/entities/invoice.dart';
import 'package:fcs/domain/entities/payment_method.dart'; import 'package:fcs/domain/entities/payment_method.dart';
import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:fcs/pages/discount/discount_list.dart'; import 'package:fcs/pages/discount/discount_list.dart';
import 'package:fcs/pages/discount/model/discount_model.dart'; import 'package:fcs/pages/discount/model/discount_model.dart';
import 'package:fcs/pages/main/model/language_model.dart'; import 'package:fcs/pages/invoice/invoice_cargo_table.dart';
import 'package:fcs/pages/invoice/invoice_carton_table.dart';
import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/payment_methods/model/payment_method_model.dart'; import 'package:fcs/pages/payment_methods/model/payment_method_model.dart';
import 'package:fcs/pages/rates/custom_list.dart'; import 'package:fcs/pages/rates/custom_list.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/widgets/bottom_up_page_route.dart';
import 'package:fcs/pages/widgets/discount_dropdown.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/input_text.dart';
import 'package:fcs/pages/widgets/local_dropdown.dart'; import 'package:fcs/pages/widgets/local_dropdown.dart';
import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart'; import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/multi_img_controller.dart'; import 'package:fcs/pages/widgets/multi_img_controller.dart';
import 'package:fcs/pages/widgets/multi_img_file.dart';
import 'package:fcs/pages/widgets/my_data_table.dart';
import 'package:fcs/pages/widgets/progress.dart'; import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -35,10 +31,13 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'invoice_custom_table.dart';
class InvoiceEditor extends StatefulWidget { class InvoiceEditor extends StatefulWidget {
final Invoice invoice; final Invoice invoice;
final User customer; final User customer;
InvoiceEditor({this.invoice, this.customer}); final FcsShipment fcsShipment;
InvoiceEditor({this.invoice, this.customer, this.fcsShipment});
@override @override
_InvoiceEditorState createState() => _InvoiceEditorState(); _InvoiceEditorState createState() => _InvoiceEditorState();
@@ -63,31 +62,27 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
Invoice _invoice; Invoice _invoice;
bool _isLoading = false; bool _isLoading = false;
List<Carton> _boxes = []; List<Carton> _cartons = [];
bool isSwitched = false; bool isSwitched = false;
int deliveryfee = 0; int deliveryfee = 0;
double customFee = 10.0; double customFee = 10.0;
double handlingFee = 10.0; // it will get from shipment double handlingFee = 10.0; // it will get from shipment
double total = 0; double total = 0;
Discount _discount; Discount _discount;
bool isNew = false; bool _isNew = false;
Discount selectedDiscount; Discount selectedDiscount;
int selectedDiscountAmt; int selectedDiscountAmt;
PaymentMethod paymentMethod; PaymentMethod _paymentMethod;
double volumetricRatio = 0; double volumetricRatio = 0;
List<Carton> selectedBoxes = []; List<Carton> selectedBoxes = [];
List<CustomDuty> customs = []; List<CustomDuty> customs = [];
List<CargoType> _cargoTypes = [ // List<CargoType> _cargoTypes = [
CargoType(name: 'General Cargo', weight: 33, rate: 6), // CargoType(name: 'General Cargo', weight: 33, rate: 6),
CargoType(name: 'Medicine', weight: 33, rate: 7), // CargoType(name: 'Medicine', weight: 33, rate: 7),
CargoType(name: 'Dangerous Cargo', weight: 33, rate: 8) // CargoType(name: 'Dangerous Cargo', weight: 33, rate: 8)
]; // ];
List<String> _receipts = [
"assets/buying_online_with_first_last_name.png",
];
@override @override
void initState() { void initState() {
@@ -98,6 +93,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
.volumetricRatio; .volumetricRatio;
if (widget.invoice != null) { if (widget.invoice != null) {
_isNew = false;
_invoice = widget.invoice; _invoice = widget.invoice;
_invoiceNumberController.text = _invoice.invoiceNumber; _invoiceNumberController.text = _invoice.invoiceNumber;
_dateController.text = dateFormatter.format(_invoice.invoiceDate); _dateController.text = dateFormatter.format(_invoice.invoiceDate);
@@ -114,67 +110,33 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
(_invoice.amount - _invoice.receipts[0].amount).toString(); (_invoice.amount - _invoice.receipts[0].amount).toString();
// _boxes = _invoice.packages; // _boxes = _invoice.packages;
} else { } else {
_isNew = true;
_dateController.text = dateFormatter.format(DateTime.now()); _dateController.text = dateFormatter.format(DateTime.now());
_amountController.text = '0'; _amountController.text = '0';
_handlingFeeController.text = '0'; _handlingFeeController.text = '0';
_customFeeController.text = '0'; _customFeeController.text = '0';
_descriptionController.text = ''; _descriptionController.text = '';
_balanceController.text = '0'; _balanceController.text = '0';
_invoice = Invoice(customDuties: [], cartons: []);
} }
if (widget.customer != null && widget.invoice == null) { if (widget.customer != null && widget.invoice == null) {
user = widget.customer; user = widget.customer;
setState(() { setState(() {
isNew = true; _isNew = true;
}); });
} }
_boxes = [ _loadCartons();
Carton( }
shipmentNumber: "A202",
receiverNumber: "3", _loadCartons() async {
receiverName: "Ko Myo Min", CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
boxNumber: "1", List<Carton> cartons = await cartonModel.getCartonsForInvoice(
rate: 7, widget.fcsShipment.id, widget.customer.id);
packageType: "General", setState(() {
weight: 75, _cartons = cartons;
status: "Packed", });
receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon',
cargoDesc: "Clothes",
arrivedDate: DateTime(2020, 6, 1),
width: 10,
height: 10,
length: 10,
// packages: packages,
// statusHistory: statusHistory,
cargoTypes: [
CargoType(name: 'General Cargo', weight: 25),
CargoType(name: 'Medicine', weight: 20),
CargoType(name: 'Dangerous Cargo', weight: 30)
]),
Carton(
shipmentNumber: "A202",
receiverNumber: "3",
receiverName: "Ko Myo Min",
boxNumber: "2",
rate: 7,
packageType: "General",
weight: 75,
status: "Packed",
cargoDesc: "Clothes",
arrivedDate: DateTime(2020, 6, 1),
width: 10,
height: 10,
length: 10,
// statusHistory: statusHistory,
// packages: packages,
receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon',
cargoTypes: [
CargoType(name: 'General Cargo', weight: 25),
CargoType(name: 'Medicine', weight: 20),
CargoType(name: 'Dangerous Cargo', weight: 30)
])
];
} }
@override @override
@@ -187,6 +149,8 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
var mainModel = Provider.of<MainModel>(context); var mainModel = Provider.of<MainModel>(context);
var discountModel = Provider.of<DiscountModel>(context); var discountModel = Provider.of<DiscountModel>(context);
var paymentMethodModel = Provider.of<PaymentMethodModel>(context); var paymentMethodModel = Provider.of<PaymentMethodModel>(context);
var rateModel = Provider.of<ShipmentRateModel>(context);
var rate = rateModel.rate;
final nameBox = DisplayText( final nameBox = DisplayText(
iconData: Feather.user, iconData: Feather.user,
@@ -203,6 +167,64 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
labelTextKey: "box.fcs.id", labelTextKey: "box.fcs.id",
icon: FcsIDIcon(), icon: FcsIDIcon(),
); );
final cartonTable = InvoiceCartonTable(
cartons: _cartons,
onSelect: (c, checked) {
setState(() {
c.isChecked = checked;
});
if (checked) {
_invoice.cartons.add(c);
} else {
_invoice.cartons.remove(c);
}
},
);
final customTableHeaderBox = LocalTitle(
textKey: "invoice.custom_fee",
trailing: IconButton(
icon: Icon(Icons.add_circle, color: primaryColor),
onPressed: () async {
CustomDuty customDuty = await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) => CustomList(selected: true)));
_addCustom(customDuty);
}));
final customTableBox = InvoiceCustomTable(
customDuties: _invoice.customDuties,
onAdd: (c) => _addCustom(c),
onRemove: (c) => _removeCustom(c),
);
var paymentTypesBox = LocalDropdown<PaymentMethod>(
callback: (v) {
setState(() {
_paymentMethod = v;
});
},
labelKey: "invoice.payment_method",
iconData: FontAwesome.money,
display: (u) => u.name,
selectedValue: _paymentMethod,
values: paymentMethodModel.paymentMethods,
);
final cargoTypeTableBox = InvoiceCargoTable(
invoice: _invoice,
rate: rate,
deliveryFeeSelected: (selected) {
setState(() {
if (selected) {
_invoice.deliveryFee = rate.deliveryFee;
} else {
_invoice.deliveryFee = 0;
}
});
},
discountSelected: (discount) {
setState(() {
_invoice.discount = discount;
});
},
);
return LocalProgress( return LocalProgress(
inAsyncCall: _isLoading, inAsyncCall: _isLoading,
@@ -235,59 +257,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
text: _invoiceNumberController.text), text: _invoiceNumberController.text),
fcsIDBox, fcsIDBox,
nameBox, nameBox,
isNew ? Container() : statusBox, _isNew ? Container() : statusBox,
SizedBox(height: 20), SizedBox(height: 20),
LocalTitle(textKey: "invoice.box_info"), customTableHeaderBox,
Center(child: Column(children: getCartonRows(context))), customTableBox,
SizedBox(height: 20),
LocalTitle(
textKey: "invoice.custom_fee",
trailing: IconButton(
icon: Icon(Icons.add_circle, color: primaryColor),
onPressed: () async {
CustomDuty custom = await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) =>
CustomList(selected: true)));
setState(() {
if (custom != null) customs.add(custom);
});
})),
Column(children: getCustomFeeRows(context)),
SizedBox(height: 20), SizedBox(height: 20),
cartonTable,
LocalTitle(textKey: "invoice.cargo_type"), LocalTitle(textKey: "invoice.cargo_type"),
Column(children: getCargoTableByBox(context)), cargoTypeTableBox,
// Column(children: getCargoTableByBox(context)),
SizedBox(height: 20), SizedBox(height: 20),
Container( paymentTypesBox,
padding: EdgeInsets.only(top: 5, left: 18),
child: Row(
children: <Widget>[
Expanded(
child: LocalText(context, 'invoice.payment_method',
fontSize: 16,
color: Colors.grey,
fontWeight: FontWeight.bold),
),
Container(
width: 150.0,
child: DropdownButtonFormField(
icon: Icon(
Icons.edit,
color: primaryColor,
),
value: paymentMethod,
items: paymentMethodModel.paymentMethods
.map((e) => DropdownMenuItem(
child: Text(e.name), value: e.name))
.toList(),
onChanged: (selected) => {},
),
),
],
),
),
SizedBox(height: 20), SizedBox(height: 20),
isNew _isNew
? Container() ? Container()
: LocalTitle( : LocalTitle(
textKey: "invoice.payment_attachment", textKey: "invoice.payment_attachment",
@@ -306,7 +288,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
getLocalString(context, 'invoice.btn_save')) getLocalString(context, 'invoice.btn_save'))
], ],
)), )),
isNew _isNew
? Container() ? Container()
: fcsButton(context, : fcsButton(context,
getLocalString(context, 'invoice.btn_payment_receipt')) getLocalString(context, 'invoice.btn_payment_receipt'))
@@ -317,493 +299,6 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
); );
} }
getCartonRows(BuildContext context) {
List<Widget> dataRow = [];
dataRow = _boxes.map((box) {
return Container(
height: 50,
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
padding:
const EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0, bottom: 5.0),
child: Row(
children: [
Container(
width: 35,
child: Checkbox(
value: true, onChanged: (v) {}, activeColor: primaryColor),
),
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(box.packageNumber),
Text(box.shipmentNumber),
],
)),
Expanded(
flex: 2,
child: Text(
box.length == null
? ""
: box.length.toString() +
' x ' +
box.length.toString() +
' x ' +
box.height.toString(),
textAlign: TextAlign.center)),
Expanded(
flex: 2,
child: Center(
child: Text(
box.getShipmentWeight(volumetricRatio).toString()))),
],
),
);
}).toList();
dataRow.insert(
0,
Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 5.0, bottom: 15.0),
child: Row(
children: [
Container(width: 33),
Expanded(
flex: 1,
child: Center(
child: LocalText(
context,
"invoice.box.number",
color: Colors.grey,
),
)),
Expanded(
flex: 2,
child: Center(
child: Text('L x W x H',
style: TextStyle(color: Colors.grey)))),
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
"invoice.shipment_weight",
color: Colors.grey,
),
)),
],
),
));
return dataRow;
}
getCustomFeeRows(BuildContext context) {
customFee = 0;
List<Widget> dataRow = [];
dataRow = customs.map((custom) {
customFee += custom.fee;
return Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
padding:
const EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0, bottom: 5.0),
child: Row(
children: [
Expanded(flex: 2, child: Text('${custom.productType}')),
Expanded(
flex: 1,
child: Text('\$ ${custom.fee}', textAlign: TextAlign.center)),
Expanded(
child: IconButton(
icon: Icon(Icons.remove_circle, color: primaryColor),
onPressed: () {
customs.remove(custom);
}))
],
),
);
}).toList();
dataRow.insert(
0,
Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Text('Product', style: TextStyle(color: Colors.grey))),
Expanded(
flex: 1,
child: Text('Fee',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey))),
Expanded(flex: 1, child: Container())
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
'invoice.total_custom_fee',
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
flex: 1,
child: Center(
child: Text('\$ $customFee',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold)))),
Expanded(
child: Container(),
)
],
),
));
return dataRow;
}
getCargoTableByBox(BuildContext context) {
var discountModel = Provider.of<DiscountModel>(context);
total = 0;
List<Widget> dataRow = _cargoTypes.map((cargo) {
var amount = cargo.weight * cargo.rate;
total += amount;
return Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
child: Row(
children: [
Expanded(flex: 2, child: Text('${cargo.name}')),
Expanded(
flex: 2,
child: Text('${cargo.weight} x ${cargo.rate}',
textAlign: TextAlign.center)),
Expanded(
child: Text('\$ $amount',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
);
}).toList();
dataRow.insert(
0,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(getLocalString(context, 'invoice.box.cargo_type'),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey))),
Expanded(
flex: 2,
child: Text(
getLocalString(context, 'cargo.weight') +
' x ' +
getLocalString(context, 'cargo.rate'),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey))),
Expanded(
child: Text(getLocalString(context, 'invoice.amount'),
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.total',
color: Colors.black,
),
),
),
SizedBox(width: 40),
Expanded(
child: Text(
'\$ $total',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.discount_value',
color: Colors.black,
),
),
),
new IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () async {
Discount discount = await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) =>
DiscountList(selected: true)));
setState(() {
if (discount != null) _discount = discount;
});
}),
Expanded(
child: Text(
'\$ ( ${_discount != null ? _discount.amount.toInt() : 0} )',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 0.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.custom_fee',
color: Colors.black,
),
),
),
SizedBox(width: 40),
Expanded(
child: Text('\$ ${customFee}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)),
),
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 20.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.handling_fee',
color: Colors.black,
),
),
),
SizedBox(width: 50),
Expanded(
child: Text('\$ ${handlingFee.toString()}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.delivery_fee',
color: Colors.black,
),
)),
Switch(
value: isSwitched,
onChanged: (value) {
setState(() {
isSwitched = value;
if (value) {
deliveryfee = 5;
} else {
deliveryfee = 0;
}
print(isSwitched);
});
},
activeTrackColor: primaryColor.withOpacity(0.8),
activeColor: primaryColor,
),
Expanded(
child: Text('\$ $deliveryfee',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
child: Row(
children: [
Expanded(child: Text('')),
Expanded(
flex: 2,
child: Divider(
thickness: 3,
)),
],
)));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
'invoice.net_amount',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: Text('\$ ${getTotalBalance(total)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: primaryColor)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
'invoice.balance',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: Text('\$ ${getTotalBalance(total)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: primaryColor)))
],
),
));
return dataRow;
}
getTotalBalance(total) { getTotalBalance(total) {
double balance = 0; double balance = 0;
double custom = customFee != 0 ? customFee.toDouble() : 0; double custom = customFee != 0 ? customFee.toDouble() : 0;
@@ -813,78 +308,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
return balance; return balance;
} }
List<MyDataRow> getBoxRow(BuildContext context) { _addCustom(CustomDuty customDuty) {
return _boxes.map((p) { if (customDuty == null) return;
p.cargoTypes.map((cargo) { setState(() {
_cargoTypes.asMap().map((index, _cargo) { _invoice.customDuties.remove(customDuty);
if (_cargo.id == cargo.id) { _invoice.customDuties.add(customDuty);
setState(() { });
_cargoTypes[index].weight += cargo.weight;
});
}
});
});
return MyDataRow(
onSelectChanged: (bool selected) {},
cells: [
MyDataCell(Checkbox(
value: true,
onChanged: (value) {
selectedBoxes.add(p);
},
)),
MyDataCell(new Text(
p.boxNumber == null
? ""
: '${p.shipmentNumber}-${p.receiverNumber} #${p.boxNumber}',
style: textStyle,
)),
MyDataCell(new Text(
p.length == null
? ""
: p.length.toString() +
' x ' +
p.length.toString() +
' x ' +
p.height.toString(),
style: textStyle,
)),
],
);
}).toList();
} }
List<MyDataRow> getCargoDataRow(BuildContext context) { _removeCustom(CustomDuty customDuty) {
return _cargoTypes.asMap().entries.map((c) { setState(() {
var cargo = c.value; _invoice.customDuties.remove(customDuty);
var amt = cargo.weight * cargo.rate; });
return MyDataRow(
onSelectChanged: (bool selected) {},
cells: [
MyDataCell(new Text(
cargo.name,
style: textStyle,
)),
MyDataCell(new Text(
cargo.weight.toString() + ' x ' + cargo.rate.toString(),
style: textStyle,
)),
MyDataCell(new Text(
"\$$amt",
style: textStyle,
)),
],
);
}).toList()
// .insert(_cargoTypes.length,MyDataRow(cells: [
// MyDataCell(new Text('')),
// MyDataCell(new Text('Total')),
// MyDataCell(new Text(
// "\$5000",
// style: textStyle,
// )),
// ])
// )
;
} }
_save() {}
} }

View File

@@ -1,3 +1,4 @@
import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/helpers/theme.dart'; import 'package:fcs/helpers/theme.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/shipment/model/shipment_model.dart'; import 'package:fcs/pages/shipment/model/shipment_model.dart';
@@ -16,10 +17,20 @@ class InvoiceShipmentList extends StatefulWidget {
class _InvoiceShipmentListState extends State<InvoiceShipmentList> { class _InvoiceShipmentListState extends State<InvoiceShipmentList> {
bool _isLoading = false; bool _isLoading = false;
List<FcsShipment> _fcsShipments = [];
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_load();
}
_load() async {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
var fcsShipments = await fcsShipmentModel.getInvoiceFcsShipments();
setState(() {
_fcsShipments = fcsShipments;
});
} }
@override @override
@@ -29,7 +40,6 @@ class _InvoiceShipmentListState extends State<InvoiceShipmentList> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
FcsShipmentModel fcsShipmentModel = Provider.of<FcsShipmentModel>(context);
return LocalProgress( return LocalProgress(
inAsyncCall: _isLoading, inAsyncCall: _isLoading,
child: DefaultTabController( child: DefaultTabController(
@@ -42,18 +52,8 @@ class _InvoiceShipmentListState extends State<InvoiceShipmentList> {
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
backgroundColor: primaryColor, backgroundColor: primaryColor,
title: LocalText(context, "shipment", title: LocalText(context, "invoice.shipment.title",
fontSize: 18, color: Colors.white), fontSize: 18, color: Colors.white),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
iconSize: 30,
// onPressed: () => showPlacesSearch(context),
),
],
), ),
body: new ListView.separated( body: new ListView.separated(
separatorBuilder: (context, index) => Divider( separatorBuilder: (context, index) => Divider(
@@ -62,10 +62,10 @@ class _InvoiceShipmentListState extends State<InvoiceShipmentList> {
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 15), padding: EdgeInsets.only(top: 15),
shrinkWrap: true, shrinkWrap: true,
itemCount: fcsShipmentModel.fcsShipments.length, itemCount: _fcsShipments.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return InvoiceShipmentListRow( return InvoiceShipmentListRow(
fcsShipment: fcsShipmentModel.fcsShipments[index]); fcsShipment: _fcsShipments[index]);
}), }),
), ),
), ),

View File

@@ -35,8 +35,10 @@ class _InvoiceShipmentListRowState extends State<InvoiceShipmentListRow> {
padding: EdgeInsets.only(left: 15, right: 15), padding: EdgeInsets.only(left: 15, right: 15),
child: InkWell( child: InkWell(
onTap: () { onTap: () {
Navigator.of(context).push( Navigator.of(context).push(CupertinoPageRoute(
CupertinoPageRoute(builder: (context) => InvoiceCustomerList())); builder: (context) => InvoiceCustomerList(
fcsShipment: _fcsShipment,
)));
}, },
child: Row( child: Row(
children: <Widget>[ children: <Widget>[

View File

@@ -130,8 +130,8 @@ class InvoiceModel extends BaseModel {
} }
Future<void> loadMore({bool isCustomer}) async { Future<void> loadMore({bool isCustomer}) async {
if (_selectedIndex == 1) return; // when paid menu is not selected return if (_paid.ended || _selectedIndex == 1)
if (_paid.ended) return; return; // when paid menu is not selected return
isLoading = true; isLoading = true;
notifyListeners(); notifyListeners();
await _paid.load(onFinished: () { await _paid.load(onFinished: () {

View File

@@ -148,7 +148,9 @@ class MainModel extends ChangeNotifier {
} }
Future<void> signout() async { Future<void> signout() async {
await removeMsgToken(); try {
await removeMsgToken();
} catch (e) {}
await Services.instance.authService.signout(); await Services.instance.authService.signout();
models.forEach((m) => m.logout()); models.forEach((m) => m.logout());
} }

View File

@@ -25,10 +25,12 @@ import 'package:provider/provider.dart';
final DateFormat dateFormat = DateFormat("d MMM yyyy"); final DateFormat dateFormat = DateFormat("d MMM yyyy");
class PackageInfo extends StatefulWidget { class PackageInfo extends StatefulWidget {
final isCustomer;
final isSearchResult; final isSearchResult;
final Package package; final Package package;
PackageInfo({this.package, this.isSearchResult = false}); PackageInfo(
{this.package, this.isSearchResult = false, this.isCustomer = false});
@override @override
_PackageInfoState createState() => _PackageInfoState(); _PackageInfoState createState() => _PackageInfoState();
@@ -156,7 +158,8 @@ class _PackageInfoState extends State<PackageInfo> {
_package.photoUrls.length == 0 ? Container() : img, _package.photoUrls.length == 0 ? Container() : img,
widget.isSearchResult ? Container() : descBox, widget.isSearchResult ? Container() : descBox,
remarkBox, remarkBox,
_package.status == package_processed_status _package.status == package_received_status &&
widget.isCustomer
? returnButton ? returnButton
: Container(), : Container(),
widget.isSearchResult ? Container() : deliveryAddressBox, widget.isSearchResult ? Container() : deliveryAddressBox,

View File

@@ -106,6 +106,7 @@ class _PackageListState extends State<PackageList> {
return PackageListRow( return PackageListRow(
key: ValueKey(packages[index].id), key: ValueKey(packages[index].id),
package: packages[index], package: packages[index],
isCustomer: widget.forCustomer,
); );
}), }),
onRefresh: () => onRefresh: () =>

View File

@@ -10,12 +10,14 @@ import 'package:intl/intl.dart';
typedef CallbackPackageSelect(Package package); typedef CallbackPackageSelect(Package package);
class PackageListRow extends StatelessWidget { class PackageListRow extends StatelessWidget {
final bool isCustomer;
final Package package; final Package package;
final CallbackPackageSelect callbackPackageSelect; final CallbackPackageSelect callbackPackageSelect;
final double dotSize = 15.0; final double dotSize = 15.0;
final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); final DateFormat dateFormat = new DateFormat("dd MMM yyyy");
PackageListRow({Key key, this.package, this.callbackPackageSelect}) PackageListRow(
{Key key, this.package, this.callbackPackageSelect, this.isCustomer})
: super(key: key); : super(key: key);
@override @override
@@ -29,7 +31,10 @@ class PackageListRow extends StatelessWidget {
Navigator.push( Navigator.push(
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => PackageInfo(package: package)), builder: (context) => PackageInfo(
package: package,
isCustomer: isCustomer,
)),
); );
}, },
child: Container( child: Container(

View File

@@ -301,8 +301,6 @@ class _ProfileState extends State<Profile> {
}); });
try { try {
await context.read<MainModel>().signout(); await context.read<MainModel>().signout();
Navigator.of(context).pushNamedAndRemoveUntil(
"/welcome", ModalRoute.withName('/welcome'));
} catch (e) {} finally { } catch (e) {} finally {
Future.delayed(Duration(seconds: 1), () { Future.delayed(Duration(seconds: 1), () {
if (mounted) { if (mounted) {
@@ -311,6 +309,8 @@ class _ProfileState extends State<Profile> {
}); });
} }
}); });
Navigator.of(context).pushNamedAndRemoveUntil(
"/welcome", ModalRoute.withName('/welcome'));
} }
}); });
} }

View File

@@ -88,19 +88,7 @@ class _ShipmentListState extends State<ShipmentList> {
backgroundColor: primaryColor, backgroundColor: primaryColor,
title: LocalText(context, "shipment", title: LocalText(context, "shipment",
fontSize: 18, color: Colors.white), fontSize: 18, color: Colors.white),
actions: <Widget>[ actions: <Widget>[popupMenu],
widget.forCustomer
? Container()
: IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
iconSize: 30,
// onPressed: () => showPlacesSearch(context),
),
popupMenu
],
), ),
floatingActionButton: widget.forCustomer floatingActionButton: widget.forCustomer
? FloatingActionButton.extended( ? FloatingActionButton.extended(