2020-10-22 04:14:53 +06:30
|
|
|
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';
|
2020-10-22 05:27:03 +06:30
|
|
|
import 'package:intl/intl.dart';
|
2020-10-22 04:14:53 +06:30
|
|
|
|
|
|
|
|
typedef OnDiscountSelected(Discount discount);
|
|
|
|
|
typedef OnDeliveryFeeSelected(bool selected);
|
2020-10-22 05:27:03 +06:30
|
|
|
final formatter = new NumberFormat("#,###.00");
|
2020-10-22 04:14:53 +06:30
|
|
|
|
|
|
|
|
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,
|
2020-10-22 05:27:03 +06:30
|
|
|
child: Text(
|
|
|
|
|
'${cargo.calWeight.toStringAsFixed(2)} x ${cargo.calRate.toStringAsFixed(2)}',
|
2020-10-22 04:14:53 +06:30
|
|
|
textAlign: TextAlign.center)),
|
|
|
|
|
Expanded(
|
2020-10-22 05:27:03 +06:30
|
|
|
child: Text('\$ ${amount.toStringAsFixed(2)}',
|
2020-10-22 04:14:53 +06:30
|
|
|
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(
|
2020-10-22 05:27:03 +06:30
|
|
|
'\$ ${total.toStringAsFixed(2)}',
|
2020-10-22 04:14:53 +06:30
|
|
|
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(
|
2020-10-22 05:27:03 +06:30
|
|
|
child:
|
|
|
|
|
Text('\$ ( ${invoice.getDiscount().toStringAsFixed(2)} )',
|
|
|
|
|
textAlign: TextAlign.end,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
)))
|
2020-10-22 04:14:53 +06:30
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
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(
|
2020-10-22 05:27:03 +06:30
|
|
|
child: Text('\$ ${invoice.getCustomFee().toStringAsFixed(2)}',
|
2020-10-22 04:14:53 +06:30
|
|
|
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(
|
2020-10-22 05:27:03 +06:30
|
|
|
child: Text(
|
|
|
|
|
'\$ ${invoice.getHandlingFee().toStringAsFixed(2) ?? ""}',
|
2020-10-22 04:14:53 +06:30
|
|
|
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(
|
2020-10-22 05:27:03 +06:30
|
|
|
child:
|
|
|
|
|
Text('\$ ${invoice.getDeliveryFee().toStringAsFixed(2)}',
|
|
|
|
|
textAlign: TextAlign.end,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
)))
|
2020-10-22 04:14:53 +06:30
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
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(
|
2020-10-22 05:27:03 +06:30
|
|
|
child: Text(
|
|
|
|
|
'\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}',
|
2020-10-22 04:14:53 +06:30
|
|
|
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(
|
2020-10-22 05:27:03 +06:30
|
|
|
child: Text(
|
|
|
|
|
'\$ ${invoice.getTotalBalance(rate).toStringAsFixed(2)}',
|
2020-10-22 04:14:53 +06:30
|
|
|
textAlign: TextAlign.end,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: primaryColor)))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return dataRow;
|
|
|
|
|
}
|
|
|
|
|
}
|