This commit is contained in:
Hillel Coren 2019-06-06 10:57:57 +03:00
parent 48b1c5e14a
commit d40cc06b7d
4 changed files with 43 additions and 3 deletions

View File

@ -120,6 +120,8 @@ abstract class CurrencyEntity extends Object
@override
double get listDisplayAmount => null;
static Serializer<CurrencyEntity> get serializer =>
_$currencyEntitySerializer;
}

View File

@ -156,11 +156,15 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
// STARTER: state getters - do not remove comment
ExpenseState get expenseState => selectedCompanyState.expenseState;
ListUIState get expenseListState => uiState.expenseUIState.listUIState;
ExpenseUIState get expenseUIState => uiState.expenseUIState;
VendorState get vendorState => selectedCompanyState.vendorState;
ListUIState get vendorListState => uiState.vendorUIState.listUIState;
VendorUIState get vendorUIState => uiState.vendorUIState;
TaskState get taskState => selectedCompanyState.taskState;
@ -191,6 +195,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
String toString() {
//return 'Is Loading: ${this.isLoading}, Invoice: ${this.invoiceUIState.selected}';
//return 'Expense Categories: ${selectedCompany.expenseCategories}';
return 'Expense: ${uiState.expenseUIState.editing.expenseCurrencyId} - Invoice: ${uiState.expenseUIState.editing.invoiceCurrencyId}';
return 'Route: ${uiState.currentRoute}';
}
}

View File

@ -8,6 +8,7 @@ import 'package:invoiceninja_flutter/utils/formatting.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
import 'package:invoiceninja_flutter/redux/static/static_selectors.dart';
import 'package:invoiceninja_flutter/utils/money.dart';
class ExpenseEditSettings extends StatefulWidget {
const ExpenseEditSettings({
@ -184,9 +185,17 @@ class ExpenseEditSettingsState extends State<ExpenseEditSettings> {
initialValue: staticState
.currencyMap[viewModel.expense.invoiceCurrencyId]
?.name,
onSelected: (SelectableEntity currency) =>
viewModel.onChanged(viewModel.expense.rebuild(
(b) => b..invoiceCurrencyId = currency.id)),
onSelected: (SelectableEntity currency) {
final exchangeRate = getExchangeRate(context,
fromCurrencyId: expense.expenseCurrencyId,
toCurrencyId: currency.id);
viewModel.onChanged(expense.rebuild((b) => b
..invoiceCurrencyId = currency.id
..exchangeRate = exchangeRate));
_exchangeRateController.text = formatNumber(
exchangeRate, context,
formatNumberType: FormatNumberType.input);
},
),
TextFormField(
controller: _exchangeRateController,

24
lib/utils/money.dart Normal file
View File

@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
double getExchangeRate(BuildContext context,
{int fromCurrencyId, int toCurrencyId}) {
final state = StoreProvider.of<AppState>(context).state;
final currencyMap = state.staticState.currencyMap;
final fromCurrency = currencyMap[fromCurrencyId];
final toCurrency = currencyMap[toCurrencyId];
// TODO replace with data from server
final baseCurrency = currencyMap[kCurrencyUSDollar];
if (fromCurrency == baseCurrency) {
return toCurrency.exchangeRate;
}
if (toCurrency == baseCurrency) {
return 1 / fromCurrency.exchangeRate;
}
return toCurrency.exchangeRate * (1 / fromCurrency.exchangeRate);
}