Added exchange rate
This commit is contained in:
parent
51436e1fa4
commit
a3a621a2ae
|
|
@ -256,14 +256,16 @@ void handleProductAction(
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case EntityAction.newInvoice:
|
case EntityAction.newInvoice:
|
||||||
|
final invoice = InvoiceEntity(state: state);
|
||||||
createEntity(
|
createEntity(
|
||||||
context: context,
|
context: context,
|
||||||
entity: InvoiceEntity(state: state).rebuild(
|
entity: invoice.rebuild(
|
||||||
(b) => b
|
(b) => b
|
||||||
..lineItems.addAll(
|
..lineItems.addAll(
|
||||||
productIds.map(
|
productIds.map(
|
||||||
(productId) => convertProductToInvoiceItem(
|
(productId) => convertProductToInvoiceItem(
|
||||||
company: state.company,
|
company: state.company,
|
||||||
|
invoice: invoice,
|
||||||
product: state.productState.map[productId],
|
product: state.productState.map[productId],
|
||||||
currencyMap: state.staticState.currencyMap,
|
currencyMap: state.staticState.currencyMap,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
|
||||||
InvoiceItemEntity convertProductToInvoiceItem({
|
InvoiceItemEntity convertProductToInvoiceItem({
|
||||||
@required ProductEntity product,
|
@required ProductEntity product,
|
||||||
@required CompanyEntity company,
|
@required CompanyEntity company,
|
||||||
|
@required InvoiceEntity invoice,
|
||||||
@required BuiltMap<String, CurrencyEntity> currencyMap,
|
@required BuiltMap<String, CurrencyEntity> currencyMap,
|
||||||
ClientEntity client,
|
ClientEntity client,
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -18,11 +19,8 @@ InvoiceItemEntity convertProductToInvoiceItem({
|
||||||
if (company.convertProductExchangeRate &&
|
if (company.convertProductExchangeRate &&
|
||||||
client != null &&
|
client != null &&
|
||||||
client.currencyId != company.currencyId) {
|
client.currencyId != company.currencyId) {
|
||||||
cost = cost *
|
cost = round(cost * invoice.exchangeRate,
|
||||||
getExchangeRateWithMap(currencyMap,
|
currencyMap[client.currencyId].precision);
|
||||||
fromCurrencyId: company.currencyId,
|
|
||||||
toCurrencyId: client.currencyId);
|
|
||||||
cost = round(cost, currencyMap[client.currencyId].precision);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return InvoiceItemEntity().rebuild((b) => b
|
return InvoiceItemEntity().rebuild((b) => b
|
||||||
|
|
|
||||||
|
|
@ -181,11 +181,8 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
||||||
final product = productState.map[productId];
|
final product = productState.map[productId];
|
||||||
final client =
|
final client =
|
||||||
state.clientState.get(invoice.clientId);
|
state.clientState.get(invoice.clientId);
|
||||||
final currencyId = client.getCurrencyId(
|
|
||||||
company: company,
|
|
||||||
group: state.groupState.get(client.groupId));
|
|
||||||
final currency =
|
final currency =
|
||||||
state.staticState.currencyMap[currencyId];
|
state.staticState.currencyMap[client.currencyId];
|
||||||
|
|
||||||
double cost = product.price;
|
double cost = product.price;
|
||||||
if (company.convertProductExchangeRate &&
|
if (company.convertProductExchangeRate &&
|
||||||
|
|
@ -225,9 +222,6 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
||||||
final item = lineItems[index];
|
final item = lineItems[index];
|
||||||
final product = productState.map[suggestion];
|
final product = productState.map[suggestion];
|
||||||
final client = state.clientState.get(invoice.clientId);
|
final client = state.clientState.get(invoice.clientId);
|
||||||
final currencyId = client.getCurrencyId(
|
|
||||||
company: company,
|
|
||||||
group: state.groupState.get(client.groupId));
|
|
||||||
|
|
||||||
double cost = product.price;
|
double cost = product.price;
|
||||||
if (company.convertProductExchangeRate &&
|
if (company.convertProductExchangeRate &&
|
||||||
|
|
@ -235,7 +229,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
||||||
client.currencyId != company.currencyId) {
|
client.currencyId != company.currencyId) {
|
||||||
cost = round(
|
cost = round(
|
||||||
cost * invoice.exchangeRate,
|
cost * invoice.exchangeRate,
|
||||||
state.staticState.currencyMap[currencyId]
|
state.staticState.currencyMap[client?.currencyId]
|
||||||
.precision);
|
.precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
|
||||||
convertProductToInvoiceItem(
|
convertProductToInvoiceItem(
|
||||||
company: company,
|
company: company,
|
||||||
product: entity as ProductEntity,
|
product: entity as ProductEntity,
|
||||||
|
invoice: state.invoiceUIState.editing,
|
||||||
currencyMap: state.staticState.currencyMap,
|
currencyMap: state.staticState.currencyMap,
|
||||||
client: state.clientState.get(widget.clientId),
|
client: state.clientState.get(widget.clientId),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue