feat: wip categorize the cashflow transactions

This commit is contained in:
Ahmed Bouhuolia
2024-03-06 22:15:31 +02:00
parent a17b4f6a8a
commit d87d674aba
27 changed files with 768 additions and 144 deletions

View File

@@ -79,13 +79,14 @@ export class CategorizeCashflowTransaction {
cashflowTransactionDTO
);
// Updates the uncategorized transaction as categorized.
await UncategorizedCashflowTransaction.query(trx)
.findById(uncategorizedTransactionId)
.patch({
await UncategorizedCashflowTransaction.query(trx).patchAndFetchById(
uncategorizedTransactionId,
{
categorized: true,
categorizeRefType: 'CashflowTransaction',
categorizeRefId: cashflowTransaction.id,
});
}
);
// Triggers `onCashflowTransactionCategorized` event.
await this.eventPublisher.emitAsync(
events.cashflow.onTransactionCategorized,

View File

@@ -31,6 +31,7 @@ export default class GetCashflowTransactionsService {
.withGraphFetched('entries.cashflowAccount')
.withGraphFetched('entries.creditAccount')
.withGraphFetched('transactions.account')
.orderBy('date', 'DESC')
.throwIfNotFound();
this.throwErrorCashflowTranscationNotFound(cashflowTransaction);

View File

@@ -24,7 +24,8 @@ export class GetUncategorizedTransactions {
.where('accountId', accountId)
.where('categorized', false)
.withGraphFetched('account')
.pagination(0, 10);
.orderBy('date', 'DESC')
.pagination(0, 1000);
const data = await this.transformer.transform(
tenantId,

View File

@@ -8,6 +8,7 @@ export class UncategorizedTransactionTransformer extends Transformer {
*/
public includeAttributes = (): string[] => {
return [
'formattedAmount',
'formattedDate',
'formattetDepositAmount',
'formattedWithdrawalAmount',
@@ -23,6 +24,17 @@ export class UncategorizedTransactionTransformer extends Transformer {
return this.formatDate(transaction.date);
}
/**
* Formatted amount.
* @param transaction
* @returns {string}
*/
public formattedAmount(transaction) {
return formatNumber(transaction.amount, {
currencyCode: transaction.currencyCode,
});
}
/**
* Formatted deposit amount.
* @param transaction

View File

@@ -55,7 +55,7 @@ export const transformCategorizeTransToCashflow = (
referenceNo: categorizeDTO.referenceNo || uncategorizeModel.referenceNo,
description: categorizeDTO.description || uncategorizeModel.description,
cashflowAccountId: uncategorizeModel.accountId,
creditAccountId: categorizeDTO.fromAccountId || categorizeDTO.toAccountId,
creditAccountId: categorizeDTO.creditAccountId,
exchangeRate: categorizeDTO.exchangeRate || 1,
currencyCode: uncategorizeModel.currencyCode,
amount: uncategorizeModel.amount,