From bd7c9db5f640785ca6c69c58a9cfe9a06c465451 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sun, 9 May 2021 03:10:36 +0200 Subject: [PATCH] fix: transaction type in customer/vendor transactions report. --- .../CustomersTransactions/components.js | 1 - server/src/interfaces/Ledger.ts | 2 ++ .../src/interfaces/TransactionsByContacts.ts | 2 +- server/src/services/Accounting/Ledger.ts | 15 +++++++++---- .../CustomerBalanceSummaryService.ts | 2 +- .../TransactionsByContact.ts | 2 +- .../TransactionsByContactTableRows.ts | 2 +- .../TransactionsByCustomersService.ts | 21 ++++++++++++------- .../TransactionsByVendorService.ts | 10 +++++++-- .../VendorBalanceSummaryService.ts | 2 +- 10 files changed, 40 insertions(+), 19 deletions(-) diff --git a/client/src/containers/FinancialStatements/CustomersTransactions/components.js b/client/src/containers/FinancialStatements/CustomersTransactions/components.js index d91deb006..04715aa57 100644 --- a/client/src/containers/FinancialStatements/CustomersTransactions/components.js +++ b/client/src/containers/FinancialStatements/CustomersTransactions/components.js @@ -30,7 +30,6 @@ export const useCustomersTransactionsColumns = () => { }, className: 'customer_name', textOverview: true, - // width: 240, }, { Header: formatMessage({ id: 'account_name' }), diff --git a/server/src/interfaces/Ledger.ts b/server/src/interfaces/Ledger.ts index 4df42ed07..e3dd19288 100644 --- a/server/src/interfaces/Ledger.ts +++ b/server/src/interfaces/Ledger.ts @@ -15,4 +15,6 @@ export interface ILedgerEntry { accountNormal: string; contactId?: number; date: Date | string; + transactionType: string, + transactionNumber: string, } diff --git a/server/src/interfaces/TransactionsByContacts.ts b/server/src/interfaces/TransactionsByContacts.ts index 0c9b96ae5..9f4569ba0 100644 --- a/server/src/interfaces/TransactionsByContacts.ts +++ b/server/src/interfaces/TransactionsByContacts.ts @@ -13,7 +13,7 @@ export interface ITransactionsByContactsTransaction { accountName: string, runningBalance: ITransactionsByContactsAmount; currencyCode: string; - referenceNumber: string; + transactionType: string; transactionNumber: string; createdAt: string|Date, }; diff --git a/server/src/services/Accounting/Ledger.ts b/server/src/services/Accounting/Ledger.ts index b0232b60f..93870dfdb 100644 --- a/server/src/services/Accounting/Ledger.ts +++ b/server/src/services/Accounting/Ledger.ts @@ -14,7 +14,7 @@ export default class Ledger implements ILedger { * @param {ILedgerEntry[]} entries */ constructor(entries: ILedgerEntry[]) { - this.entries = Ledger.mappingEntries(entries); + this.entries = entries; } /** @@ -75,11 +75,11 @@ export default class Ledger implements ILedger { return closingBalance; } - static mappingEntries(entries): ILedgerEntry[] { - return entries.map(this.mapEntry); + static mappingTransactions(entries): ILedgerEntry[] { + return entries.map(this.mapTransaction); } - static mapEntry(entry): ILedgerEntry { + static mapTransaction(entry): ILedgerEntry { return { credit: defaultTo(entry.credit, 0), debit: defaultTo(entry.debit, 0), @@ -88,7 +88,14 @@ export default class Ledger implements ILedger { contactId: entry.contactId, date: entry.date, transactionNumber: entry.transactionNumber, + transactionType: entry.referenceTypeFormatted, referenceNumber: entry.referenceNumber, + referenceType: entry.referenceType, } } + + static fromTransactions(transactions) { + const entries = Ledger.mappingTransactions(transactions); + return new Ledger(entries); + } } diff --git a/server/src/services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryService.ts b/server/src/services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryService.ts index 8be59fd37..7f648194a 100644 --- a/server/src/services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryService.ts +++ b/server/src/services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryService.ts @@ -140,7 +140,7 @@ export default class CustomerBalanceSummaryService filter.asDate ); // Ledger query. - const ledger = new Ledger(customersTransactions); + const ledger = Ledger.fromTransactions(customersTransactions); // Report instance. const report = new CustomerBalanceSummaryReport( diff --git a/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContact.ts b/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContact.ts index 47da452d0..b10820f32 100644 --- a/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContact.ts +++ b/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContact.ts @@ -31,7 +31,7 @@ export default class TransactionsByContact extends FinancialSheet { accountName: account.name, currencyCode: 'USD', transactionNumber: transaction.transactionNumber, - referenceNumber: transaction.referenceNumber, + transactionType: transaction.transactionType, date: transaction.date, createdAt: transaction.createdAt, }; diff --git a/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContactTableRows.ts b/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContactTableRows.ts index c71028838..147635e12 100644 --- a/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContactTableRows.ts +++ b/server/src/services/FinancialStatements/TransactionsByContact/TransactionsByContactTableRows.ts @@ -30,7 +30,7 @@ export default class TransactionsByContactsTableRows { const columns = [ { key: 'date', accessor: this.dateAccessor }, { key: 'account', accessor: 'accountName' }, - { key: 'referenceNumber', accessor: 'referenceNumber' }, + { key: 'transactionType', accessor: 'transactionType' }, { key: 'transactionNumber', accessor: 'transactionNumber' }, { key: 'credit', accessor: 'credit.formattedAmount' }, { key: 'debit', accessor: 'debit.formattedAmount' }, diff --git a/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts b/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts index bc9c91160..0bf91adba 100644 --- a/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts +++ b/server/src/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService.ts @@ -11,7 +11,6 @@ import { import TransactionsByCustomers from './TransactionsByCustomers'; import Ledger from 'services/Accounting/Ledger'; import { ACCOUNT_TYPE } from 'data/AccountTypes'; -import AccountRepository from 'repositories/AccountRepository'; export default class TransactionsByCustomersService implements ITransactionsByCustomersService { @@ -97,7 +96,7 @@ export default class TransactionsByCustomersService async getCustomersPeriodTransactions( tenantId: number, fromDate: Date, - toDate: Date, + toDate: Date ): Promise { const { AccountTransaction } = this.tenancy.models(tenantId); @@ -115,7 +114,13 @@ export default class TransactionsByCustomersService query.whereIn('accountId', receivableAccountsIds); }); - return R.compose(R.map(R.assoc('accountNormal', 'debit')))(transactions); + return R.compose( + R.map(R.assoc('accountNormal', 'debit')), + R.map((trans) => ({ + ...trans, + referenceTypeFormatted: trans.referenceTypeFormatted, + })), + )(transactions); } /** @@ -145,25 +150,27 @@ export default class TransactionsByCustomersService const accountsGraph = await accountRepository.getDependencyGraph(); const customers = await Customer.query().orderBy('displayName'); - const openingBalanceDate = moment(filter.fromDate).subtract(1, 'days').toDate(); + const openingBalanceDate = moment(filter.fromDate) + .subtract(1, 'days') + .toDate(); // Retrieve all ledger transactions of the opening balance of. const openingBalanceTransactions = await this.getCustomersOpeningBalance( tenantId, - openingBalanceDate, + openingBalanceDate ); // Retrieve all ledger transactions between opeing and closing period. const customersTransactions = await this.getCustomersPeriodTransactions( tenantId, query.fromDate, - query.toDate, + query.toDate ); // Concats the opening balance and period customer ledger transactions. const journalTransactions = [ ...openingBalanceTransactions, ...customersTransactions, ]; - const journal = new Ledger(journalTransactions); + const journal = Ledger.fromTransactions(journalTransactions); // Transactions by customers data mapper. const reportInstance = new TransactionsByCustomers( diff --git a/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts b/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts index 456750a45..df7686a1d 100644 --- a/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts +++ b/server/src/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService.ts @@ -126,7 +126,13 @@ export default class TransactionsByVendorsService query.whereIn('accountId', receivableAccountsIds); }); - return R.compose(R.map(R.assoc('accountNormal', 'credit')))(transactions); + return R.compose( + R.map(R.assoc('accountNormal', 'credit')), + R.map((trans) => ({ + ...trans, + referenceTypeFormatted: trans.referenceTypeFormatted, + })), + )(transactions); } async getReportTransactions(tenantId: number, fromDate: Date, toDate: Date) { @@ -172,7 +178,7 @@ export default class TransactionsByVendorsService filter.toDate ); // Ledger collection. - const journal = new Ledger(journalTransactions); + const journal = Ledger.fromTransactions(journalTransactions); // Transactions by customers data mapper. const reportInstance = new TransactionsByVendor( diff --git a/server/src/services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryService.ts b/server/src/services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryService.ts index 1df040a4a..bf8a93673 100644 --- a/server/src/services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryService.ts +++ b/server/src/services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryService.ts @@ -134,7 +134,7 @@ export default class VendorBalanceSummaryService const vendors = await this.getReportVendors(tenantId, query.vendorsIds); // Ledger query. - const ledger = new Ledger(vendorsTransactions); + const ledger = Ledger.fromTransactions(vendorsTransactions); // Report instance. const reportInstance = new VendorBalanceSummaryReport(