diff --git a/lib/data/models/expense_model.dart b/lib/data/models/expense_model.dart index 445a77c7b..c8e13d35c 100644 --- a/lib/data/models/expense_model.dart +++ b/lib/data/models/expense_model.dart @@ -542,30 +542,42 @@ abstract class ExpenseEntity extends Object @override FormatNumberType get listDisplayAmountType => FormatNumberType.money; - double get amountWithTax { - var total = amount; - - if (usesInclusiveTaxes) { - return total; - } + double get taxAmount { + var total = 0.0; if (taxAmount1 != 0 || taxAmount2 != 0 || taxAmount3 != 0) { total += taxAmount1 + taxAmount2 + taxAmount3; } else { - if (taxRate1 != 0) { - total += amount * taxRate1 / 100; - } - if (taxRate2 != 0) { - total += amount * taxRate2 / 100; - } - if (taxRate3 != 0) { - total += amount * taxRate3 / 100; + if (usesInclusiveTaxes) { + if (taxRate1 != 0) { + total += amount - (amount / (1 + (taxRate1 / 100))); + } + if (taxRate2 != 0) { + total += amount - (amount / (1 + (taxRate2 / 100))); + } + if (taxRate3 != 0) { + total += amount - (amount / (1 + (taxRate3 / 100))); + } + } else { + if (taxRate1 != 0) { + total += amount * taxRate1 / 100; + } + if (taxRate2 != 0) { + total += amount * taxRate2 / 100; + } + if (taxRate3 != 0) { + total += amount * taxRate3 / 100; + } } } return total; } + double get netAmount => usesInclusiveTaxes ? amount - taxAmount : amount; + + double get grossAmount => usesInclusiveTaxes ? amount : amount + taxAmount; + String get statusId { if (isInvoiced) { return kExpenseStatusInvoiced; @@ -581,7 +593,7 @@ abstract class ExpenseEntity extends Object double get convertedAmount => round(amount * convertedExchangeRate, 2); double get convertedAmountWithTax => - round(amountWithTax * convertedExchangeRate, 2); + round(grossAmount * convertedExchangeRate, 2); bool get isInvoiced => invoiceId != null && invoiceId.isNotEmpty; diff --git a/lib/redux/dashboard/dashboard_selectors.dart b/lib/redux/dashboard/dashboard_selectors.dart index e8e437265..56fed19da 100644 --- a/lib/redux/dashboard/dashboard_selectors.dart +++ b/lib/redux/dashboard/dashboard_selectors.dart @@ -663,7 +663,7 @@ List chartExpenses( expenseMap.forEach((int, expense) { final currencyId = expense.currencyId; final date = expense.date; - double amount = expense.amountWithTax; + double amount = expense.grossAmount; if (expense.isDeleted) { // skip it diff --git a/lib/redux/vendor/vendor_selectors.dart b/lib/redux/vendor/vendor_selectors.dart index fde130c37..7198191cb 100644 --- a/lib/redux/vendor/vendor_selectors.dart +++ b/lib/redux/vendor/vendor_selectors.dart @@ -110,7 +110,7 @@ double calculateVendorBalance(String vendorId, String currencyId, if (expense.vendorId == vendorId && expense.isActive && (currencyId == null || expense.currencyId == currencyId)) { - total += expense.amountWithTax; + total += expense.grossAmount; } }); diff --git a/lib/ui/expense/edit/expense_edit.dart b/lib/ui/expense/edit/expense_edit.dart index 3fae4d4d4..01652d648 100644 --- a/lib/ui/expense/edit/expense_edit.dart +++ b/lib/ui/expense/edit/expense_edit.dart @@ -138,7 +138,7 @@ class _ExpenseEditState extends State child: Text( localization.expenseTotal + ': ' + - formatNumber(expense.amountWithTax, context, + formatNumber(expense.grossAmount, context, currencyId: expense.currencyId), style: TextStyle( color: viewModel.state.prefState.enableDarkMode diff --git a/lib/ui/expense/edit/expense_edit_settings.dart b/lib/ui/expense/edit/expense_edit_settings.dart index 97a53be75..fe9df8b37 100644 --- a/lib/ui/expense/edit/expense_edit_settings.dart +++ b/lib/ui/expense/edit/expense_edit_settings.dart @@ -245,7 +245,7 @@ class ExpenseEditSettingsState extends State { label: localization.enterTaxes, enabledLabel: localization.byAmount, disabledLabel: localization.byRate, - value: company.calculateExpenseTaxByAmount ?? false, + value: false, onChanged: (value) => viewModel.onChanged(expense .rebuild((b) => b..calculateExpenseTaxByAmount = value)), ), diff --git a/lib/ui/expense/view/expense_view_overview.dart b/lib/ui/expense/view/expense_view_overview.dart index d9f2aec11..6e57dceab 100644 --- a/lib/ui/expense/view/expense_view_overview.dart +++ b/lib/ui/expense/view/expense_view_overview.dart @@ -98,7 +98,7 @@ class ExpenseOverview extends StatelessWidget { statusLabel: localization.lookup('expense_status_${expense.statusId}'), label: localization.amount, - value: formatNumber(expense.amountWithTax, context, + value: formatNumber(expense.grossAmount, context, currencyId: expense.currencyId), secondLabel: localization.converted, secondValue: formatNumber( @@ -111,7 +111,7 @@ class ExpenseOverview extends StatelessWidget { statusLabel: localization.lookup('expense_status_${expense.statusId}'), label: localization.amount, - value: formatNumber(expense.amountWithTax, context, + value: formatNumber(expense.grossAmount, context, currencyId: expense.currencyId), ), ListDivider(),