code refactor
This commit is contained in:
@@ -51,6 +51,10 @@ export function useReconciliationStatementPageBase() {
|
||||
const currentTimezoneOffsetMinutes = computed<number>(() => getTimezoneOffsetMinutes(settingsStore.appSettings.timeZone));
|
||||
const defaultCurrency = computed<string>(() => userStore.currentUserDefaultCurrency);
|
||||
|
||||
const currentAccount = computed(() => allAccountsMap.value[accountId.value]);
|
||||
const currentAccountCurrency = computed<string>(() => currentAccount.value?.currency ?? defaultCurrency.value);
|
||||
const isCurrentLiabilityAccount = computed<boolean>(() => currentAccount.value?.isLiability ?? false);
|
||||
|
||||
const exportFileName = computed<string>(() => {
|
||||
const nickname = userStore.currentUserNickname;
|
||||
|
||||
@@ -66,16 +70,6 @@ export function useReconciliationStatementPageBase() {
|
||||
const allAccountsMap = computed<Record<string, Account>>(() => accountsStore.allAccountsMap);
|
||||
const allCategoriesMap = computed<Record<string, TransactionCategory>>(() => transactionCategoriesStore.allTransactionCategoriesMap);
|
||||
|
||||
const accountCurrency = computed<string>(() => {
|
||||
let currency = defaultCurrency.value;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
currency = allAccountsMap.value[accountId.value].currency;
|
||||
}
|
||||
|
||||
return currency;
|
||||
});
|
||||
|
||||
const totalOutflows = computed<number>(() => {
|
||||
let totalOutflows = 0;
|
||||
|
||||
@@ -117,42 +111,30 @@ export function useReconciliationStatementPageBase() {
|
||||
});
|
||||
|
||||
const displayTotalOutflows = computed<string>(() => {
|
||||
return formatAmountWithCurrency(totalOutflows.value, accountCurrency.value);
|
||||
return formatAmountWithCurrency(totalOutflows.value, currentAccountCurrency.value);
|
||||
});
|
||||
|
||||
const displayTotalInflows = computed<string>(() => {
|
||||
return formatAmountWithCurrency(totalInflows.value, accountCurrency.value);
|
||||
return formatAmountWithCurrency(totalInflows.value, currentAccountCurrency.value);
|
||||
});
|
||||
|
||||
const displayTotalBalance = computed<string>(() => {
|
||||
return formatAmountWithCurrency(totalInflows.value - totalOutflows.value, accountCurrency.value);
|
||||
return formatAmountWithCurrency(totalInflows.value - totalOutflows.value, currentAccountCurrency.value);
|
||||
});
|
||||
|
||||
const displayOpeningBalance = computed<string>(() => {
|
||||
let isLiabilityAccount = false;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
isLiabilityAccount = allAccountsMap.value[accountId.value].isLiability;
|
||||
}
|
||||
|
||||
if (isLiabilityAccount) {
|
||||
return formatAmountWithCurrency(-openingBalance.value, accountCurrency.value);
|
||||
if (isCurrentLiabilityAccount.value) {
|
||||
return formatAmountWithCurrency(-openingBalance.value, currentAccountCurrency.value);
|
||||
} else {
|
||||
return formatAmountWithCurrency(openingBalance.value, accountCurrency.value);
|
||||
return formatAmountWithCurrency(openingBalance.value, currentAccountCurrency.value);
|
||||
}
|
||||
});
|
||||
|
||||
const displayClosingBalance = computed<string>(() => {
|
||||
let isLiabilityAccount = false;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
isLiabilityAccount = allAccountsMap.value[accountId.value].isLiability;
|
||||
}
|
||||
|
||||
if (isLiabilityAccount) {
|
||||
return formatAmountWithCurrency(-closingBalance.value, accountCurrency.value);
|
||||
if (isCurrentLiabilityAccount.value) {
|
||||
return formatAmountWithCurrency(-closingBalance.value, currentAccountCurrency.value);
|
||||
} else {
|
||||
return formatAmountWithCurrency(closingBalance.value, accountCurrency.value);
|
||||
return formatAmountWithCurrency(closingBalance.value, currentAccountCurrency.value);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -213,14 +195,8 @@ export function useReconciliationStatementPageBase() {
|
||||
separator = '\t';
|
||||
}
|
||||
|
||||
let isLiabilityAccount = false;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
isLiabilityAccount = allAccountsMap.value[accountId.value].isLiability;
|
||||
}
|
||||
|
||||
const digitGroupingSymbol = getCurrentDigitGroupingSymbol();
|
||||
const accountBalanceName = isLiabilityAccount ? 'Account Outstanding Balance' : 'Account Balance';
|
||||
const accountBalanceName = isCurrentLiabilityAccount.value ? 'Account Outstanding Balance' : 'Account Balance';
|
||||
|
||||
const header = [
|
||||
tt('Transaction Time'),
|
||||
@@ -263,7 +239,7 @@ export function useReconciliationStatementPageBase() {
|
||||
|
||||
let displayAccountBalance = '';
|
||||
|
||||
if (isLiabilityAccount) {
|
||||
if (isCurrentLiabilityAccount.value) {
|
||||
displayAccountBalance = removeAll(formatAmount(-transaction.accountBalance), digitGroupingSymbol);
|
||||
} else {
|
||||
displayAccountBalance = removeAll(formatAmount(transaction.accountBalance), digitGroupingSymbol);
|
||||
@@ -302,6 +278,9 @@ export function useReconciliationStatementPageBase() {
|
||||
// computed states
|
||||
currentTimezoneOffsetMinutes,
|
||||
defaultCurrency,
|
||||
currentAccount,
|
||||
currentAccountCurrency,
|
||||
isCurrentLiabilityAccount,
|
||||
exportFileName,
|
||||
allAccountsMap,
|
||||
allCategoriesMap,
|
||||
|
||||
@@ -244,6 +244,7 @@ const {
|
||||
currentTimezoneOffsetMinutes,
|
||||
allAccountsMap,
|
||||
allCategoriesMap,
|
||||
isCurrentLiabilityAccount,
|
||||
exportFileName,
|
||||
displayStartDateTime,
|
||||
displayEndDateTime,
|
||||
@@ -274,7 +275,6 @@ const countPerPage = ref<number>(10);
|
||||
|
||||
let rejectFunc: ((reason?: unknown) => void) | null = null;
|
||||
|
||||
const account = computed(() => allAccountsMap.value[accountId.value]);
|
||||
const reconciliationStatementsTablePageOptions = computed<ReconciliationStatementDialogTablePageOption[]>(() => getTablePageOptions(reconciliationStatements.value?.length));
|
||||
|
||||
const totalPageCount = computed<number>(() => {
|
||||
@@ -293,7 +293,7 @@ const totalPageCount = computed<number>(() => {
|
||||
|
||||
const dataTableHeaders = computed<object[]>(() => {
|
||||
const headers: object[] = [];
|
||||
const accountBalanceName = account.value?.isLiability ? 'Account Outstanding Balance' : 'Account Balance';
|
||||
const accountBalanceName = isCurrentLiabilityAccount.value ? 'Account Outstanding Balance' : 'Account Balance';
|
||||
|
||||
headers.push({ key: 'time', value: 'time', title: tt('Transaction Time'), sortable: true, nowrap: true });
|
||||
headers.push({ key: 'type', value: 'type', title: tt('Type'), sortable: true, nowrap: true });
|
||||
|
||||
Reference in New Issue
Block a user