update invoice

This commit is contained in:
PhyoThandar
2020-10-14 20:56:46 +06:30
parent 1052278029
commit f2e8487122
14 changed files with 1758 additions and 292 deletions

View File

@@ -1,20 +1,24 @@
import 'package:fcs/domain/entities/box.dart';
import 'package:fcs/domain/entities/cargo.dart';
import 'package:fcs/domain/entities/custom.dart';
import 'package:fcs/domain/entities/discount.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/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/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/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';
@@ -34,7 +38,8 @@ import 'box_addition.dart';
class InvoiceEditor extends StatefulWidget {
final Invoice invoice;
InvoiceEditor({this.invoice});
final User customer;
InvoiceEditor({this.invoice, this.customer});
@override
_InvoiceEditorState createState() => _InvoiceEditorState();
@@ -63,14 +68,17 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
bool isSwitched = false;
int deliveryfee = 0;
int customFee = 10;
int handlingFee = 0;
double total = 0;
Discount _discount;
bool isNew = false;
Discount selectedDiscount;
int selectedDiscountAmt;
PaymentMethod paymentMethod;
double volumetricRatio = 0;
List<Box> selectedBoxes = [];
List<Custom> customs = [];
List<Cargo> _cargoTypes = [
Cargo(type: 'General Cargo', weight: 33, price: 6),
@@ -85,6 +93,10 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
@override
void initState() {
super.initState();
volumetricRatio =
Provider.of<MainModel>(context, listen: false).setting.volumetricRatio;
if (widget.invoice != null) {
_invoice = widget.invoice;
_invoiceNumberController.text = _invoice.invoiceNumber;
@@ -108,6 +120,10 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
_customFeeController.text = '0';
_descriptionController.text = '';
_balanceController.text = '0';
}
if (widget.customer != null) {
user = widget.customer;
setState(() {
isNew = true;
});
@@ -172,17 +188,33 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
var discountModel = Provider.of<DiscountModel>(context);
var paymentMethodModel = Provider.of<PaymentMethodModel>(context);
final discountBox = Container(
child: DiscountDropdown<Discount>(
callback: (v) {
setState(() {
selectedDiscount = v;
});
},
iconData: Entypo.price_ribbon,
selectedValue: selectedDiscount,
values: discountModel.discounts,
));
final nameBox = DisplayText(
iconData: Feather.user,
labelTextKey: 'invoice.customer_name',
text: user != null ? user.name : '');
final statusBox = DisplayText(
text: _statusController.text,
iconData: Icons.av_timer,
labelTextKey: 'invoice.status');
final fcsIDBox = Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: user != null ? user.fcsID : "",
labelTextKey: "box.fcs.id",
icon: FcsIDIcon(),
)),
IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) {
setState(() {
this.user = u;
});
})),
],
);
return LocalProgress(
inAsyncCall: _isLoading,
@@ -202,7 +234,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
padding: const EdgeInsets.all(8.0),
child: ListView(
children: <Widget>[
LocalTitle(textKey: "package.create.name"),
LocalTitle(textKey: "invoice.customer_info"),
DisplayText(
labelTextKey: 'invoice.date',
iconData: Icons.date_range,
@@ -213,73 +245,27 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
labelTextKey: 'invoice.number',
iconData: FontAwesomeIcons.fileInvoice,
text: _invoiceNumberController.text),
widget.invoice == null
? Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: user != null ? user.name : "",
labelTextKey: "invoice.customer_name",
iconData: Feather.user,
)),
IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () =>
searchUser(context, callbackUserSelect: (u) {
setState(() {
this.user = u;
});
})),
],
)
: DisplayText(
text: _nameController.text,
iconData: Feather.user,
labelTextKey: 'invoice.customer_name'),
InputText(
controller: _handlingFeeController,
iconData: FontAwesomeIcons.moneyBill,
labelTextKey: 'invoice.handling_fee'),
SizedBox(height: 15),
discountBox,
widget.invoice == null
? Container()
: DisplayText(
text: _statusController.text,
iconData: Icons.av_timer,
labelTextKey: 'invoice.status'),
SizedBox(height: 30),
fcsIDBox,
nameBox,
isNew ? statusBox : Container(),
SizedBox(height: 20),
LocalTitle(textKey: "invoice.box_info"),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: MyDataTable(
headingRowHeight: 40,
// columnSpacing: 20,
columns: [
MyDataColumn(
label: Text(''),
),
MyDataColumn(
label: LocalText(
context,
"invoice.box.number",
color: Colors.grey,
),
),
MyDataColumn(
label: Text(
getLocalString(context, "invoice.box.length") +
' x ' +
getLocalString(context, "invoice.box.width") +
' x ' +
getLocalString(context, "invoice.box.height"),
),
),
],
rows: getBoxRow(context),
),
),
SizedBox(height: 40),
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 {
Custom custom = await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) => CustomList()));
setState(() {
if (custom != null) customs.add(custom);
});
})),
Column(children: getCustomFeeRows(context)),
SizedBox(height: 20),
LocalTitle(textKey: "invoice.cargo_type"),
Column(children: getCargoTableByBox(context)),
SizedBox(height: 20),
@@ -296,7 +282,10 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
Container(
width: 150.0,
child: DropdownButtonFormField(
icon: Icon(Icons.edit),
icon: Icon(
Icons.edit,
color: primaryColor,
),
value: paymentMethod,
items: paymentMethodModel.paymentMethods
.map((e) => DropdownMenuItem(
@@ -308,31 +297,12 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
],
),
),
SizedBox(height: 30),
!isNew
? Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Row(
children: [
Icon(Icons.receipt, color: primaryColor),
SizedBox(width: 10),
LocalText(
context,
"invoice.payment_attachment",
color: Colors.grey,
fontSize: 20,
fontWeight: FontWeight.w700,
),
],
),
),
Spacer(),
Icon(Icons.add, color: primaryColor),
],
)
: Container(),
SizedBox(height: 20),
LocalTitle(
textKey: "invoice.payment_attachment",
trailing: IconButton(
icon: Icon(Icons.add_circle, color: primaryColor),
onPressed: () async {})),
widget.invoice == null
? fcsButton(
context, getLocalString(context, 'invoice.btn_create'))
@@ -356,6 +326,168 @@ 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: 33,
child: Checkbox(
value: true, onChanged: (v) {}, activeColor: primaryColor),
),
Expanded(flex: 1, child: Text(box.packageNumber)),
Expanded(
flex: 1,
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: 1,
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;
@@ -431,8 +563,9 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.total',
@@ -440,6 +573,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
),
),
),
SizedBox(width: 40),
Expanded(
child: Text(
'\$ $total',
@@ -453,12 +587,13 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 10),
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 0),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.discount_value',
@@ -466,9 +601,20 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
),
),
),
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}',
'\$ ( ${_discount != null ? _discount.amount.toInt() : 0} )',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
@@ -482,18 +628,21 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 20.0, bottom: 0.0),
left: 5.0, right: 5.0, top: 10.0, bottom: 0.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
'invoice.custom_fee',
color: Colors.black,
),
)),
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,
@@ -506,6 +655,37 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
),
));
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,
),
),
),
new IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: () async {}),
Expanded(
child: Text('\$ $handlingFee',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
@@ -630,8 +810,9 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
getTotalBalance(total) {
double balance = 0;
double custom = customFee != 0 ? customFee.toDouble() : 0;
double discount = _discount != null ? _discount.amount.toDouble() : 0;
double deliveryFee = deliveryfee != 0 ? deliveryfee.toDouble() : 0;
balance = (total + custom + deliveryFee) - 100.0;
balance = (total + custom + deliveryFee) - discount;
return balance;
}