Dashboard
This commit is contained in:
parent
2e27264d75
commit
410dcf0339
|
|
@ -5,12 +5,13 @@ import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|||
|
||||
class DashboardChart extends StatefulWidget {
|
||||
const DashboardChart(
|
||||
{this.series, this.amount, this.previousAmount, this.title});
|
||||
{this.series, this.amount, this.previousAmount, this.title, this.currencyId});
|
||||
|
||||
final List<charts.Series> series;
|
||||
final double previousAmount;
|
||||
final double amount;
|
||||
final String title;
|
||||
final int currencyId;
|
||||
|
||||
@override
|
||||
_DashboardChartState createState() => _DashboardChartState();
|
||||
|
|
@ -37,7 +38,7 @@ class _DashboardChartState extends State<DashboardChart> {
|
|||
|
||||
setState(() {
|
||||
if (date != null) {
|
||||
_title = formatNumber(total, context);
|
||||
_title = formatNumber(total, context, currencyId: widget.currencyId);
|
||||
_subtitle = formatDate(date.toIso8601String(), context);
|
||||
} else {
|
||||
_title = null;
|
||||
|
|
@ -66,14 +67,14 @@ class _DashboardChartState extends State<DashboardChart> {
|
|||
|
||||
final bool isIncrease = widget.amount >= widget.previousAmount;
|
||||
final String changeAmount = (isIncrease ? '+' : '') +
|
||||
formatNumber(widget.amount - widget.previousAmount, context);
|
||||
formatNumber(widget.amount - widget.previousAmount, context, currencyId: widget.currencyId);
|
||||
final changePercent = (isIncrease ? '+' : '-') +
|
||||
formatNumber(
|
||||
widget.amount != 0 && widget.previousAmount != 0
|
||||
? round(widget.previousAmount / widget.amount * 100, 2)
|
||||
: 0.0,
|
||||
context,
|
||||
formatNumberType: FormatNumberType.percent);
|
||||
formatNumberType: FormatNumberType.percent, currencyId: widget.currencyId);
|
||||
final String changeString = widget.amount == 0 || widget.previousAmount == 0
|
||||
? ''
|
||||
: '$changeAmount ($changePercent)';
|
||||
|
|
@ -93,7 +94,7 @@ class _DashboardChartState extends State<DashboardChart> {
|
|||
style: Theme.of(context).textTheme.subhead),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(formatNumber(widget.amount, context),
|
||||
Text(formatNumber(widget.amount, context, currencyId: widget.currencyId),
|
||||
style: Theme.of(context).textTheme.headline),
|
||||
SizedBox(width: 12.0),
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -158,10 +158,12 @@ class DashboardPanels extends StatelessWidget {
|
|||
}
|
||||
|
||||
return DashboardChart(
|
||||
series: series,
|
||||
amount: total,
|
||||
previousAmount: previousTotal,
|
||||
title: localization.invoices);
|
||||
series: series,
|
||||
amount: total,
|
||||
previousAmount: previousTotal,
|
||||
title: localization.invoices,
|
||||
currencyId: settings.currencyId,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _paymentChart(BuildContext context) {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ String formatNumber(
|
|||
double value,
|
||||
BuildContext context, {
|
||||
int clientId,
|
||||
int currencyId,
|
||||
FormatNumberType formatNumberType = FormatNumberType.money,
|
||||
bool zeroIsNull = false,
|
||||
}) {
|
||||
|
|
@ -51,7 +52,6 @@ String formatNumber(
|
|||
final ClientEntity client =
|
||||
state.selectedCompanyState.clientState.map[clientId];
|
||||
|
||||
int currencyId;
|
||||
int countryId;
|
||||
|
||||
if (client != null && client.countryId > 0) {
|
||||
|
|
@ -62,7 +62,9 @@ String formatNumber(
|
|||
countryId = kCountryUnitedStates;
|
||||
}
|
||||
|
||||
if (client != null && client.currencyId > 0) {
|
||||
if (currencyId != null) {
|
||||
// do nothing
|
||||
} else if (client != null && client.currencyId > 0) {
|
||||
currencyId = client.currencyId;
|
||||
} else if (company.currencyId > 0) {
|
||||
currencyId = company.currencyId;
|
||||
|
|
@ -185,18 +187,19 @@ String formatDateRange(String startDate, String endDate, BuildContext context) {
|
|||
final today = DateTime.now();
|
||||
|
||||
final startDateTime = DateTime.tryParse(startDate).toLocal();
|
||||
final startFormatter = DateFormat(today.year == startDateTime.year ? 'MMM d' : 'MMM d, yyy');
|
||||
final startFormatter =
|
||||
DateFormat(today.year == startDateTime.year ? 'MMM d' : 'MMM d, yyy');
|
||||
final startDateTimeString = startFormatter.format(startDateTime);
|
||||
|
||||
final endDateTime = DateTime.tryParse(endDate).toLocal();
|
||||
final endFormatter = DateFormat(today.year == endDateTime.year ? 'MMM d' : 'MMM d, yyy');
|
||||
final endFormatter =
|
||||
DateFormat(today.year == endDateTime.year ? 'MMM d' : 'MMM d, yyy');
|
||||
final endDateTimeString = endFormatter.format(endDateTime);
|
||||
|
||||
return '$startDateTimeString - $endDateTimeString';
|
||||
}
|
||||
|
||||
String formatDate(String value, BuildContext context,
|
||||
{bool showTime = false}) {
|
||||
String formatDate(String value, BuildContext context, {bool showTime = false}) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '';
|
||||
}
|
||||
|
|
@ -207,14 +210,14 @@ String formatDate(String value, BuildContext context,
|
|||
if (showTime) {
|
||||
final dateFormats = state.staticState.datetimeFormatMap;
|
||||
final dateFormatId = company.datetimeFormatId > 0
|
||||
? company.datetimeFormatId
|
||||
: kDefaultDateTimeFormat;
|
||||
? company.datetimeFormatId
|
||||
: kDefaultDateTimeFormat;
|
||||
final formatter = DateFormat(dateFormats[dateFormatId].format);
|
||||
return formatter.format(DateTime.tryParse(value).toLocal());
|
||||
} else {
|
||||
final dateFormats = state.staticState.dateFormatMap;
|
||||
final dateFormatId =
|
||||
company.dateFormatId > 0 ? company.dateFormatId : kDefaultDateFormat;
|
||||
company.dateFormatId > 0 ? company.dateFormatId : kDefaultDateFormat;
|
||||
final formatter = DateFormat(dateFormats[dateFormatId].format);
|
||||
return formatter.format(DateTime.tryParse(value));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue