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

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