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

View File

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

View File

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

View File

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

View File

@@ -43,10 +43,9 @@ class Carton {
String remark;
DateTime arrivedDate;
String cartonNumber;
List<String> packageIDs;
List<Package> packages;
List<CargoType> cargoTypes;
List<Carton> cartons;
@@ -193,4 +192,10 @@ class Carton {
deliveryAddress: _da,
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,
};
}
@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 'receipt.dart';
@@ -8,13 +15,89 @@ class Invoice {
String customerName;
String customerPhoneNumber;
double amount;
String discount;
String status;
String paymentAttachment;
double handlingFee;
double deliveryFee;
double paidAmount;
List<Package> packages;
List<Receipt> receipts;
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(
{this.id,
@@ -28,6 +111,9 @@ class Invoice {
this.paymentAttachment,
this.packages,
this.receiptPhotos,
this.customDuties,
this.cartons,
this.handlingFee,
this.receipts});
double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p);

View File

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

View File

@@ -490,7 +490,7 @@ class _CartonEditorState extends State<CartonEditor> {
showMsgDialog(context, "Error", "Invalid delivery address");
return;
}
if (isSmallBag && _mixCarton == null) {
if (isSmallBag && _mixCarton == null && _isNew) {
showMsgDialog(context, "Error", "Invalid mix carton");
return;
}
@@ -507,7 +507,9 @@ class _CartonEditorState extends State<CartonEditor> {
carton.width = w;
carton.height = h;
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(() {
_isLoading = true;
});

View File

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

View File

@@ -174,6 +174,21 @@ class CartonModel extends BaseModel {
.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 {
String path = "/$cartons_collection";
var querySnap = await Firestore.instance

View File

@@ -96,6 +96,25 @@ class CustomerModel extends BaseModel {
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) {
return Services.instance.userService.enableUser(user.id, enabled);
}

View File

@@ -67,17 +67,7 @@ class _DeliverListState extends State<DeliverList> {
backgroundColor: primaryColor,
title: LocalText(context, "delivery",
color: Colors.white, fontSize: 20),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
iconSize: 30,
// onPressed: () => showPlacesSearch(context),
),
popupMenu
],
actions: <Widget>[popupMenu],
),
body: Column(
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/model/discount_model.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/progress.dart';
import 'package:flutter/cupertino.dart';
@@ -12,29 +14,48 @@ import 'package:provider/provider.dart';
import 'discount_editor.dart';
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
_DiscountListState createState() => _DiscountListState();
}
class _DiscountListState extends State<DiscountList> {
bool _isLoading = false;
bool _selected = false;
var _controller = ScrollController();
@override
void initState() {
super.initState();
if (widget.selected != null) {
_selected = widget.selected;
}
_controller.addListener(() async {
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
Provider.of<DiscountModel>(context, listen: false).loadMore();
}
});
Provider.of<DiscountModel>(context, listen: false).initData();
}
@override
Widget build(BuildContext 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(
inAsyncCall: _isLoading,
child: Scaffold(
@@ -48,26 +69,53 @@ class _DiscountListState extends State<DiscountList> {
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: primaryColor,
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
)
],
actions: <Widget>[popupMenu],
),
body: ListView.separated(
separatorBuilder: (context, index) => Divider(
color: Colors.black,
height: 1,
),
itemCount: discountModel.discounts.length,
itemBuilder: (BuildContext context, int index) {
var discount = discountModel.discounts[index];
return DiscountListRow(
key: ValueKey(discount.id),
discount: discount,
);
},
body: Column(
children: [
Expanded(
child: ListView.separated(
separatorBuilder: (context, index) => Divider(
color: Colors.black,
height: 1,
),
controller: _controller,
itemCount: discountModel.discounts.length,
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(
onPressed: () {

View File

@@ -8,9 +8,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart';
typedef OnSelect(Discount discount);
class DiscountListRow extends StatelessWidget {
final OnSelect onSelect;
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");
@@ -18,11 +21,9 @@ class DiscountListRow extends StatelessWidget {
Widget build(BuildContext context) {
return InkWell(
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => DiscountEditor(discount: discount)),
);
if (onSelect != null) {
onSelect(discount);
}
},
child: Container(
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:fcs/data/services/services.dart';
import 'package:fcs/domain/constants.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:logging/logging.dart';
@@ -11,7 +13,28 @@ class DiscountModel extends BaseModel {
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) {
super.initUser(user);
@@ -22,7 +45,7 @@ class DiscountModel extends BaseModel {
if (listener != null) listener.cancel();
try {
listener = Firestore.instance
.collection("/discounts")
.collection("/$discounts_collection")
.orderBy("code", descending: false)
.snapshots()
.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
logout() async {
discounts = [];
if (listener != null) await listener.cancel();
if (_used != null) _used.close();
_discounts = [];
}
Future<void> addDiscount(Discount discount) async {

View File

@@ -83,7 +83,7 @@ class FcsShipmentModel extends BaseModel {
}
Future<void> loadMore() async {
if (_shipped.ended && _selectedIndex == 1) return;
if (_shipped.ended || _selectedIndex == 1) return;
isLoading = true;
notifyListeners();
await _shipped.load(onFinished: () {
@@ -132,6 +132,24 @@ class FcsShipmentModel extends BaseModel {
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) {
super.initUser(user);
}

View File

@@ -77,12 +77,7 @@ class _InvoiceListState extends State<InvoiceList> {
backgroundColor: primaryColor,
title: LocalText(context, 'invoices.title',
color: Colors.white, fontSize: 20),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search, color: Colors.white),
onPressed: () {}),
popupMenu
],
actions: <Widget>[popupMenu],
),
floatingActionButton: owner
? 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/helpers/theme.dart';
import 'package:fcs/pages/customer/customer_editor.dart';
import 'package:fcs/pages/customer/model/customer_model.dart';
import 'package:fcs/pages/invoice/invoice_editor.dart';
import 'package:fcs/pages/widgets/local_text.dart';
@@ -11,6 +11,10 @@ import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class InvoiceCustomerList extends StatefulWidget {
final FcsShipment fcsShipment;
const InvoiceCustomerList({Key key, this.fcsShipment}) : super(key: key);
@override
_InvoiceCustomerListState createState() => _InvoiceCustomerListState();
}
@@ -19,11 +23,24 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
var dateFormatter = new DateFormat('dd MMM yyyy - hh:mm:ss a');
final double dotSize = 15.0;
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
Widget build(BuildContext context) {
var customerModel = Provider.of<CustomerModel>(context);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
@@ -51,9 +68,9 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: customerModel.customers.length,
itemCount: _users.length,
itemBuilder: (BuildContext context, int index) {
User customer = customerModel.customers[index];
User customer = _users[index];
return _item(customer);
}),
),
@@ -67,7 +84,10 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
return InkWell(
onTap: () {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => InvoiceEditor(customer: customer)));
builder: (context) => InvoiceEditor(
customer: customer,
fcsShipment: widget.fcsShipment,
)));
},
child: Padding(
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),
child: new Row(
children: <Widget>[
InkWell(
onTap: () => _select(customer),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
padding: const EdgeInsets.only(
left: 10.0, right: 10, top: 6, bottom: 6),
decoration: BoxDecoration(
color: primaryColor,
borderRadius:
BorderRadius.all(Radius.circular(35.0))),
child: Text(
customer.initial,
style: TextStyle(fontSize: 30, color: Colors.white),
),
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
padding: const EdgeInsets.only(
left: 10.0, right: 10, top: 6, bottom: 6),
decoration: BoxDecoration(
color: primaryColor,
borderRadius:
BorderRadius.all(Radius.circular(35.0))),
child: Text(
customer.initial,
style: TextStyle(fontSize: 30, color: Colors.white),
),
),
),
@@ -113,7 +130,7 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
Padding(
padding: const EdgeInsets.only(top: 2.0),
child: new Text(
customer.getLastMessage,
customer.phoneNumber,
style: new TextStyle(
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/carton.dart';
import 'package:fcs/domain/entities/custom_duty.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/payment_method.dart';
import 'package:fcs/domain/entities/user.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/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/util.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/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/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_text.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_file.dart';
import 'package:fcs/pages/widgets/my_data_table.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.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:provider/provider.dart';
import 'invoice_custom_table.dart';
class InvoiceEditor extends StatefulWidget {
final Invoice invoice;
final User customer;
InvoiceEditor({this.invoice, this.customer});
final FcsShipment fcsShipment;
InvoiceEditor({this.invoice, this.customer, this.fcsShipment});
@override
_InvoiceEditorState createState() => _InvoiceEditorState();
@@ -63,31 +62,27 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
Invoice _invoice;
bool _isLoading = false;
List<Carton> _boxes = [];
List<Carton> _cartons = [];
bool isSwitched = false;
int deliveryfee = 0;
double customFee = 10.0;
double handlingFee = 10.0; // it will get from shipment
double total = 0;
Discount _discount;
bool isNew = false;
bool _isNew = false;
Discount selectedDiscount;
int selectedDiscountAmt;
PaymentMethod paymentMethod;
PaymentMethod _paymentMethod;
double volumetricRatio = 0;
List<Carton> selectedBoxes = [];
List<CustomDuty> customs = [];
List<CargoType> _cargoTypes = [
CargoType(name: 'General Cargo', weight: 33, rate: 6),
CargoType(name: 'Medicine', weight: 33, rate: 7),
CargoType(name: 'Dangerous Cargo', weight: 33, rate: 8)
];
List<String> _receipts = [
"assets/buying_online_with_first_last_name.png",
];
// List<CargoType> _cargoTypes = [
// CargoType(name: 'General Cargo', weight: 33, rate: 6),
// CargoType(name: 'Medicine', weight: 33, rate: 7),
// CargoType(name: 'Dangerous Cargo', weight: 33, rate: 8)
// ];
@override
void initState() {
@@ -98,6 +93,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
.volumetricRatio;
if (widget.invoice != null) {
_isNew = false;
_invoice = widget.invoice;
_invoiceNumberController.text = _invoice.invoiceNumber;
_dateController.text = dateFormatter.format(_invoice.invoiceDate);
@@ -114,67 +110,33 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
(_invoice.amount - _invoice.receipts[0].amount).toString();
// _boxes = _invoice.packages;
} else {
_isNew = true;
_dateController.text = dateFormatter.format(DateTime.now());
_amountController.text = '0';
_handlingFeeController.text = '0';
_customFeeController.text = '0';
_descriptionController.text = '';
_balanceController.text = '0';
_invoice = Invoice(customDuties: [], cartons: []);
}
if (widget.customer != null && widget.invoice == null) {
user = widget.customer;
setState(() {
isNew = true;
_isNew = true;
});
}
_boxes = [
Carton(
shipmentNumber: "A202",
receiverNumber: "3",
receiverName: "Ko Myo Min",
boxNumber: "1",
rate: 7,
packageType: "General",
weight: 75,
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)
])
];
_loadCartons();
}
_loadCartons() async {
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
List<Carton> cartons = await cartonModel.getCartonsForInvoice(
widget.fcsShipment.id, widget.customer.id);
setState(() {
_cartons = cartons;
});
}
@override
@@ -187,6 +149,8 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
var mainModel = Provider.of<MainModel>(context);
var discountModel = Provider.of<DiscountModel>(context);
var paymentMethodModel = Provider.of<PaymentMethodModel>(context);
var rateModel = Provider.of<ShipmentRateModel>(context);
var rate = rateModel.rate;
final nameBox = DisplayText(
iconData: Feather.user,
@@ -203,6 +167,64 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
labelTextKey: "box.fcs.id",
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(
inAsyncCall: _isLoading,
@@ -235,59 +257,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
text: _invoiceNumberController.text),
fcsIDBox,
nameBox,
isNew ? Container() : statusBox,
_isNew ? Container() : statusBox,
SizedBox(height: 20),
LocalTitle(textKey: "invoice.box_info"),
Center(child: Column(children: getCartonRows(context))),
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)),
customTableHeaderBox,
customTableBox,
SizedBox(height: 20),
cartonTable,
LocalTitle(textKey: "invoice.cargo_type"),
Column(children: getCargoTableByBox(context)),
cargoTypeTableBox,
// Column(children: getCargoTableByBox(context)),
SizedBox(height: 20),
Container(
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) => {},
),
),
],
),
),
paymentTypesBox,
SizedBox(height: 20),
isNew
_isNew
? Container()
: LocalTitle(
textKey: "invoice.payment_attachment",
@@ -306,7 +288,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
getLocalString(context, 'invoice.btn_save'))
],
)),
isNew
_isNew
? Container()
: fcsButton(context,
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) {
double balance = 0;
double custom = customFee != 0 ? customFee.toDouble() : 0;
@@ -813,78 +308,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
return balance;
}
List<MyDataRow> getBoxRow(BuildContext context) {
return _boxes.map((p) {
p.cargoTypes.map((cargo) {
_cargoTypes.asMap().map((index, _cargo) {
if (_cargo.id == cargo.id) {
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();
_addCustom(CustomDuty customDuty) {
if (customDuty == null) return;
setState(() {
_invoice.customDuties.remove(customDuty);
_invoice.customDuties.add(customDuty);
});
}
List<MyDataRow> getCargoDataRow(BuildContext context) {
return _cargoTypes.asMap().entries.map((c) {
var cargo = c.value;
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,
// )),
// ])
// )
;
_removeCustom(CustomDuty customDuty) {
setState(() {
_invoice.customDuties.remove(customDuty);
});
}
_save() {}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -10,12 +10,14 @@ import 'package:intl/intl.dart';
typedef CallbackPackageSelect(Package package);
class PackageListRow extends StatelessWidget {
final bool isCustomer;
final Package package;
final CallbackPackageSelect callbackPackageSelect;
final double dotSize = 15.0;
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);
@override
@@ -29,7 +31,10 @@ class PackageListRow extends StatelessWidget {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => PackageInfo(package: package)),
builder: (context) => PackageInfo(
package: package,
isCustomer: isCustomer,
)),
);
},
child: Container(

View File

@@ -301,8 +301,6 @@ class _ProfileState extends State<Profile> {
});
try {
await context.read<MainModel>().signout();
Navigator.of(context).pushNamedAndRemoveUntil(
"/welcome", ModalRoute.withName('/welcome'));
} catch (e) {} finally {
Future.delayed(Duration(seconds: 1), () {
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,
title: LocalText(context, "shipment",
fontSize: 18, color: Colors.white),
actions: <Widget>[
widget.forCustomer
? Container()
: IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
iconSize: 30,
// onPressed: () => showPlacesSearch(context),
),
popupMenu
],
actions: <Widget>[popupMenu],
),
floatingActionButton: widget.forCustomer
? FloatingActionButton.extended(