Expense changes

This commit is contained in:
Hillel Coren 2021-01-11 21:03:04 +02:00
parent 27741ed1c4
commit 1fb118b076
6 changed files with 33 additions and 21 deletions

View File

@ -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;

View File

@ -663,7 +663,7 @@ List<ChartDataGroup> 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

View File

@ -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;
}
});

View File

@ -138,7 +138,7 @@ class _ExpenseEditState extends State<ExpenseEdit>
child: Text(
localization.expenseTotal +
': ' +
formatNumber(expense.amountWithTax, context,
formatNumber(expense.grossAmount, context,
currencyId: expense.currencyId),
style: TextStyle(
color: viewModel.state.prefState.enableDarkMode

View File

@ -245,7 +245,7 @@ class ExpenseEditSettingsState extends State<ExpenseEditSettings> {
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)),
),

View File

@ -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(),