@@ -16,7 +16,8 @@ import type { Account } from '@/models/account.ts';
1616import type { TransactionCategory } from '@/models/transaction_category.ts' ;
1717import type {
1818 TransactionReconciliationStatementResponse ,
19- TransactionReconciliationStatementResponseItem
19+ TransactionReconciliationStatementResponseItemWithInfo ,
20+ TransactionReconciliationStatementResponseWithInfo
2021} from '@/models/transaction.ts' ;
2122
2223import { replaceAll } from '@/lib/common.ts' ;
@@ -48,7 +49,7 @@ export function useReconciliationStatementPageBase() {
4849 const accountId = ref < string > ( '' ) ;
4950 const startTime = ref < number > ( 0 ) ;
5051 const endTime = ref < number > ( 0 ) ;
51- const reconciliationStatements = ref < TransactionReconciliationStatementResponse | undefined > ( undefined ) ;
52+ const reconciliationStatements = ref < TransactionReconciliationStatementResponseWithInfo | undefined > ( undefined ) ;
5253
5354 const firstDayOfWeek = computed < WeekDayValue > ( ( ) => userStore . currentUserFirstDayOfWeek ) ;
5455 const fiscalYearStart = computed < number > ( ( ) => userStore . currentUserFiscalYearStart ) ;
@@ -113,7 +114,34 @@ export function useReconciliationStatementPageBase() {
113114 }
114115 } ) ;
115116
116- function getDisplayTransactionType ( transaction : TransactionReconciliationStatementResponseItem ) : string {
117+ function setReconciliationStatements ( response : TransactionReconciliationStatementResponse | undefined ) {
118+ if ( ! response ) {
119+ reconciliationStatements . value = undefined ;
120+ return ;
121+ }
122+
123+ const responseWithInfo : TransactionReconciliationStatementResponseWithInfo = {
124+ transactions : response . transactions . map ( transaction => {
125+ const transactionWithInfo : TransactionReconciliationStatementResponseItemWithInfo = {
126+ ...transaction ,
127+ sourceAccount : allAccountsMap . value [ transaction . sourceAccountId ] ,
128+ sourceAccountName : allAccountsMap . value [ transaction . sourceAccountId ] ?. name || '' ,
129+ destinationAccount : transaction . destinationAccountId && transaction . destinationAccountId !== '0' ? allAccountsMap . value [ transaction . destinationAccountId ] : undefined ,
130+ category : allCategoriesMap . value [ transaction . categoryId ] ,
131+ categoryName : allCategoriesMap . value [ transaction . categoryId ] ?. name || ''
132+ } ;
133+ return transactionWithInfo ;
134+ } ) ,
135+ totalInflows : response . totalInflows ,
136+ totalOutflows : response . totalOutflows ,
137+ openingBalance : response . openingBalance ,
138+ closingBalance : response . closingBalance
139+ } ;
140+
141+ reconciliationStatements . value = responseWithInfo ;
142+ }
143+
144+ function getDisplayTransactionType ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
117145 if ( transaction . type === TransactionType . ModifyBalance ) {
118146 return tt ( 'Modify Balance' ) ;
119147 } else if ( transaction . type === TransactionType . Income ) {
@@ -131,54 +159,44 @@ export function useReconciliationStatementPageBase() {
131159 }
132160 }
133161
134- function getDisplayDateTime ( transaction : TransactionReconciliationStatementResponseItem ) : string {
162+ function getDisplayDateTime ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
135163 return formatUnixTimeToLongDateTime ( transaction . time , transaction . utcOffset , currentTimezoneOffsetMinutes . value ) ;
136164 }
137165
138- function getDisplayDate ( transaction : TransactionReconciliationStatementResponseItem ) : string {
166+ function getDisplayDate ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
139167 return formatUnixTimeToLongDate ( transaction . time , transaction . utcOffset , currentTimezoneOffsetMinutes . value ) ;
140168 }
141169
142- function getDisplayTime ( transaction : TransactionReconciliationStatementResponseItem ) : string {
170+ function getDisplayTime ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
143171 return formatUnixTimeToShortTime ( transaction . time , transaction . utcOffset , currentTimezoneOffsetMinutes . value ) ;
144172 }
145173
146- function getDisplayTimezone ( transaction : TransactionReconciliationStatementResponseItem ) : string {
174+ function getDisplayTimezone ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
147175 return `UTC${ getUtcOffsetByUtcOffsetMinutes ( transaction . utcOffset ) } ` ;
148176 }
149177
150- function getDisplaySourceAmount ( transaction : TransactionReconciliationStatementResponseItem ) : string {
151- let currency = defaultCurrency . value ;
152-
153- if ( allAccountsMap . value [ transaction . sourceAccountId ] ) {
154- currency = allAccountsMap . value [ transaction . sourceAccountId ] ! . currency ;
155- }
156-
178+ function getDisplaySourceAmount ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
179+ const currency = transaction . sourceAccount ?. currency ?? defaultCurrency . value ;
157180 return formatAmountToLocalizedNumeralsWithCurrency ( transaction . sourceAmount , currency ) ;
158181 }
159182
160- function getDisplayDestinationAmount ( transaction : TransactionReconciliationStatementResponseItem ) : string {
161- let currency = defaultCurrency . value ;
162-
163- if ( allAccountsMap . value [ transaction . destinationAccountId ] ) {
164- currency = allAccountsMap . value [ transaction . destinationAccountId ] ! . currency ;
165- }
166-
183+ function getDisplayDestinationAmount ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
184+ const currency = transaction . destinationAccount ?. currency ?? defaultCurrency . value ;
167185 return formatAmountToLocalizedNumeralsWithCurrency ( transaction . destinationAmount , currency ) ;
168186 }
169187
170- function getDisplayAccountBalance ( transaction : TransactionReconciliationStatementResponseItem ) : string {
188+ function getDisplayAccountBalance ( transaction : TransactionReconciliationStatementResponseItemWithInfo ) : string {
171189 let currency = defaultCurrency . value ;
172190 let isLiabilityAccount = false ;
173191
174192 if ( transaction . type === TransactionType . Transfer && transaction . destinationAccountId === accountId . value ) {
175- if ( allAccountsMap . value [ transaction . destinationAccountId ] ) {
176- currency = allAccountsMap . value [ transaction . destinationAccountId ] ! . currency ;
177- isLiabilityAccount = allAccountsMap . value [ transaction . destinationAccountId ] ! . isLiability ;
193+ if ( transaction . destinationAccount ) {
194+ currency = transaction . destinationAccount . currency ;
195+ isLiabilityAccount = transaction . destinationAccount . isLiability ;
178196 }
179- } else if ( allAccountsMap . value [ transaction . sourceAccountId ] ) {
180- currency = allAccountsMap . value [ transaction . sourceAccountId ] ! . currency ;
181- isLiabilityAccount = allAccountsMap . value [ transaction . sourceAccountId ] ! . isLiability ;
197+ } else if ( transaction . sourceAccount ) {
198+ currency = transaction . sourceAccount . currency ;
199+ isLiabilityAccount = transaction . sourceAccount . isLiability ;
182200 }
183201
184202 if ( isLiabilityAccount ) {
@@ -211,18 +229,18 @@ export function useReconciliationStatementPageBase() {
211229 const rows = transactions . map ( transaction => {
212230 const transactionTime = parseDateTimeFromUnixTime ( transaction . time , transaction . utcOffset , currentTimezoneOffsetMinutes . value ) . getUnixTime ( ) ;
213231 const type = getDisplayTransactionType ( transaction ) ;
214- let categoryName = allCategoriesMap . value [ transaction . categoryId ] ?. name || '' ;
232+ let categoryName = transaction . categoryName ;
215233 let displayAmount = formatAmountToWesternArabicNumeralsWithoutDigitGrouping ( transaction . sourceAmount ) ;
216- let displayAccountName = allAccountsMap . value [ transaction . sourceAccountId ] ?. name || '' ;
234+ let displayAccountName = transaction . sourceAccountName ;
217235
218236 if ( transaction . type === TransactionType . ModifyBalance ) {
219237 categoryName = tt ( 'Modify Balance' ) ;
220238 } else if ( transaction . type === TransactionType . Transfer && transaction . destinationAccountId === accountId . value ) {
221239 displayAmount = formatAmountToWesternArabicNumeralsWithoutDigitGrouping ( transaction . destinationAmount ) ;
222240 }
223241
224- if ( transaction . type === TransactionType . Transfer && allAccountsMap . value [ transaction . destinationAccountId ] ) {
225- displayAccountName = displayAccountName + ' → ' + ( allAccountsMap . value [ transaction . destinationAccountId ] ?. name || '' ) ;
242+ if ( transaction . type === TransactionType . Transfer && transaction . destinationAccount ) {
243+ displayAccountName = displayAccountName + ' → ' + ( transaction . destinationAccount ?. name || '' ) ;
226244 }
227245
228246 let displayAccountBalance = '' ;
@@ -272,8 +290,6 @@ export function useReconciliationStatementPageBase() {
272290 currentAccountCurrency,
273291 isCurrentLiabilityAccount,
274292 exportFileName,
275- allAccountsMap,
276- allCategoriesMap,
277293 displayStartDateTime,
278294 displayEndDateTime,
279295 displayTotalInflows,
@@ -282,6 +298,7 @@ export function useReconciliationStatementPageBase() {
282298 displayOpeningBalance,
283299 displayClosingBalance,
284300 // functions
301+ setReconciliationStatements,
285302 getDisplayTransactionType,
286303 getDisplayDateTime,
287304 getDisplayDate,
0 commit comments