mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
fix: transaction type in customer/vendor transactions report.
This commit is contained in:
@@ -15,4 +15,6 @@ export interface ILedgerEntry {
|
||||
accountNormal: string;
|
||||
contactId?: number;
|
||||
date: Date | string;
|
||||
transactionType: string,
|
||||
transactionNumber: string,
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface ITransactionsByContactsTransaction {
|
||||
accountName: string,
|
||||
runningBalance: ITransactionsByContactsAmount;
|
||||
currencyCode: string;
|
||||
referenceNumber: string;
|
||||
transactionType: string;
|
||||
transactionNumber: string;
|
||||
createdAt: string|Date,
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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' },
|
||||
|
||||
@@ -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<ILedgerEntry[]> {
|
||||
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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user