Merge pull request #877 from bigcapitalhq/fix-import-bank-transactions

fix: import bank transactions
This commit is contained in:
Ahmed Bouhuolia
2025-12-22 22:52:34 +02:00
committed by GitHub
10 changed files with 86 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { Knex } from 'knex';
import * as yup from 'yup';
import uniqid from 'uniqid';
import * as uniqid from 'uniqid';
import { Importable } from '../../Import/Importable';
import { CreateUncategorizedTransactionService } from './CreateUncategorizedTransaction.service';
import { ImportableContext } from '../../Import/interfaces';
@@ -9,8 +9,10 @@ import { BankTransactionsSampleData } from '../../BankingTransactions/constants'
import { Account } from '@/modules/Accounts/models/Account.model';
import { CreateUncategorizedTransactionDTO } from '../types/BankingCategorize.types';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { ImportableService } from '../../Import/decorators/Import.decorator';
import { UncategorizedBankTransaction } from '../../BankingTransactions/models/UncategorizedBankTransaction';
@Injectable()
@ImportableService({ name: UncategorizedBankTransaction.name })
export class UncategorizedTransactionsImportable extends Importable {
constructor(
private readonly createUncategorizedTransaction: CreateUncategorizedTransactionService,

View File

@@ -83,4 +83,4 @@ const models = [
CreateBankTransactionService
],
})
export class BankingTransactionsModule {}
export class BankingTransactionsModule { }

View File

@@ -0,0 +1,72 @@
export const UncategorizedBankTransactionMeta = {
defaultFilterField: 'createdAt',
defaultSort: {
sortOrder: 'DESC',
sortField: 'created_at',
},
importable: true,
fields: {
date: {
name: 'Date',
column: 'date',
fieldType: 'date',
},
payee: {
name: 'Payee',
column: 'payee',
fieldType: 'text',
},
description: {
name: 'Description',
column: 'description',
fieldType: 'text',
},
referenceNo: {
name: 'Reference No.',
column: 'reference_no',
fieldType: 'text',
},
amount: {
name: 'Amount',
column: 'Amount',
fieldType: 'numeric',
required: true,
},
account: {
name: 'Account',
column: 'account_id',
fieldType: 'relation',
to: { model: 'Account', to: 'id' },
},
createdAt: {
name: 'Created At',
column: 'createdAt',
fieldType: 'date',
importable: false,
},
},
fields2: {
date: {
name: 'Date',
fieldType: 'date',
required: true,
},
payee: {
name: 'Payee',
fieldType: 'text',
},
description: {
name: 'Description',
fieldType: 'text',
},
referenceNo: {
name: 'Reference No.',
fieldType: 'text',
},
amount: {
name: 'Amount',
fieldType: 'number',
required: true,
},
},
};

View File

@@ -2,7 +2,10 @@
import * as moment from 'moment';
import { Model } from 'objection';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
import { UncategorizedBankTransactionMeta } from './UncategorizedBankTransaction.meta';
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
@InjectModelMeta(UncategorizedBankTransactionMeta)
export class UncategorizedBankTransaction extends TenantBaseModel {
readonly amount!: number;
readonly date!: Date | string;

View File

@@ -22,7 +22,7 @@ export class ImportFileCommon {
private readonly importFileValidator: ImportFileDataValidator,
private readonly resource: ResourceService,
private readonly importableRegistry: ImportableRegistry,
) {}
) { }
/**
* Imports the given parsed data to the resource storage through registered importable service.

View File

@@ -84,7 +84,7 @@ export class ImportFileUploadService {
} catch (error) {
throw error;
}
const _params = this.importFileCommon.transformParams(resource, params);
const _params = await this.importFileCommon.transformParams(resource, params);
const paramsStringified = JSON.stringify(_params);
const tenant = await this.tenancyContext.getTenant();

View File

@@ -15,7 +15,7 @@ export const TABLES = {
EXPENSES: 'expenses',
CASHFLOW_ACCOUNTS: 'cashflow_accounts',
CASHFLOW_Transactions: 'cashflow_transactions',
UNCATEGORIZED_CASHFLOW_TRANSACTION: 'UNCATEGORIZED_CASHFLOW_TRANSACTION',
UNCATEGORIZED_BANK_TRANSACTION: 'UNCATEGORIZED_BANK_TRANSACTION',
CREDIT_NOTES: 'credit_notes',
VENDOR_CREDITS: 'vendor_credits',
WAREHOUSE_TRANSFERS: 'warehouse_transfers',

View File

@@ -60,7 +60,7 @@ function AccountTransactionsDataTable({
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.UNCATEGORIZED_CASHFLOW_TRANSACTION);
useMemorizedColumnsWidths(TABLES.UNCATEGORIZED_BANK_TRANSACTION);
// Handle cell click.
const handleCellClick = (cell) => {

View File

@@ -21,7 +21,7 @@ export default function ImportUncategorizedTransactions() {
return (
<DashboardInsider name={'import-uncategorized-bank-transactions'}>
<ImportView
resource={'uncategorized_cashflow_transaction'}
resource={'uncategorized_bank_transaction'}
params={{ accountId: params.id }}
onImportSuccess={handleImportSuccess}
onCancelClick={handleCnacelBtnClick}

View File

@@ -208,7 +208,7 @@ const invalidateResourcesOnImport = (
queryClient.invalidateQueries(T.MANUAL_JOURNALS);
break;
case 'UncategorizedCashflowTransaction':
case 'UncategorizedBankTransaction':
queryClient.invalidateQueries(T.CASH_FLOW_TRANSACTIONS);
queryClient.invalidateQueries(T.CASH_FLOW_TRANSACTIONS);
queryClient.invalidateQueries(T.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);