mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
fix: transaction type in customer/vendor transactions report.
This commit is contained in:
@@ -30,7 +30,6 @@ export const useCustomersTransactionsColumns = () => {
|
|||||||
},
|
},
|
||||||
className: 'customer_name',
|
className: 'customer_name',
|
||||||
textOverview: true,
|
textOverview: true,
|
||||||
// width: 240,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'account_name' }),
|
Header: formatMessage({ id: 'account_name' }),
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ export interface ILedgerEntry {
|
|||||||
accountNormal: string;
|
accountNormal: string;
|
||||||
contactId?: number;
|
contactId?: number;
|
||||||
date: Date | string;
|
date: Date | string;
|
||||||
|
transactionType: string,
|
||||||
|
transactionNumber: string,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export interface ITransactionsByContactsTransaction {
|
|||||||
accountName: string,
|
accountName: string,
|
||||||
runningBalance: ITransactionsByContactsAmount;
|
runningBalance: ITransactionsByContactsAmount;
|
||||||
currencyCode: string;
|
currencyCode: string;
|
||||||
referenceNumber: string;
|
transactionType: string;
|
||||||
transactionNumber: string;
|
transactionNumber: string;
|
||||||
createdAt: string|Date,
|
createdAt: string|Date,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default class Ledger implements ILedger {
|
|||||||
* @param {ILedgerEntry[]} entries
|
* @param {ILedgerEntry[]} entries
|
||||||
*/
|
*/
|
||||||
constructor(entries: ILedgerEntry[]) {
|
constructor(entries: ILedgerEntry[]) {
|
||||||
this.entries = Ledger.mappingEntries(entries);
|
this.entries = entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,11 +75,11 @@ export default class Ledger implements ILedger {
|
|||||||
return closingBalance;
|
return closingBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mappingEntries(entries): ILedgerEntry[] {
|
static mappingTransactions(entries): ILedgerEntry[] {
|
||||||
return entries.map(this.mapEntry);
|
return entries.map(this.mapTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
static mapEntry(entry): ILedgerEntry {
|
static mapTransaction(entry): ILedgerEntry {
|
||||||
return {
|
return {
|
||||||
credit: defaultTo(entry.credit, 0),
|
credit: defaultTo(entry.credit, 0),
|
||||||
debit: defaultTo(entry.debit, 0),
|
debit: defaultTo(entry.debit, 0),
|
||||||
@@ -88,7 +88,14 @@ export default class Ledger implements ILedger {
|
|||||||
contactId: entry.contactId,
|
contactId: entry.contactId,
|
||||||
date: entry.date,
|
date: entry.date,
|
||||||
transactionNumber: entry.transactionNumber,
|
transactionNumber: entry.transactionNumber,
|
||||||
|
transactionType: entry.referenceTypeFormatted,
|
||||||
referenceNumber: entry.referenceNumber,
|
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
|
filter.asDate
|
||||||
);
|
);
|
||||||
// Ledger query.
|
// Ledger query.
|
||||||
const ledger = new Ledger(customersTransactions);
|
const ledger = Ledger.fromTransactions(customersTransactions);
|
||||||
|
|
||||||
// Report instance.
|
// Report instance.
|
||||||
const report = new CustomerBalanceSummaryReport(
|
const report = new CustomerBalanceSummaryReport(
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default class TransactionsByContact extends FinancialSheet {
|
|||||||
accountName: account.name,
|
accountName: account.name,
|
||||||
currencyCode: 'USD',
|
currencyCode: 'USD',
|
||||||
transactionNumber: transaction.transactionNumber,
|
transactionNumber: transaction.transactionNumber,
|
||||||
referenceNumber: transaction.referenceNumber,
|
transactionType: transaction.transactionType,
|
||||||
date: transaction.date,
|
date: transaction.date,
|
||||||
createdAt: transaction.createdAt,
|
createdAt: transaction.createdAt,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default class TransactionsByContactsTableRows {
|
|||||||
const columns = [
|
const columns = [
|
||||||
{ key: 'date', accessor: this.dateAccessor },
|
{ key: 'date', accessor: this.dateAccessor },
|
||||||
{ key: 'account', accessor: 'accountName' },
|
{ key: 'account', accessor: 'accountName' },
|
||||||
{ key: 'referenceNumber', accessor: 'referenceNumber' },
|
{ key: 'transactionType', accessor: 'transactionType' },
|
||||||
{ key: 'transactionNumber', accessor: 'transactionNumber' },
|
{ key: 'transactionNumber', accessor: 'transactionNumber' },
|
||||||
{ key: 'credit', accessor: 'credit.formattedAmount' },
|
{ key: 'credit', accessor: 'credit.formattedAmount' },
|
||||||
{ key: 'debit', accessor: 'debit.formattedAmount' },
|
{ key: 'debit', accessor: 'debit.formattedAmount' },
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
import TransactionsByCustomers from './TransactionsByCustomers';
|
import TransactionsByCustomers from './TransactionsByCustomers';
|
||||||
import Ledger from 'services/Accounting/Ledger';
|
import Ledger from 'services/Accounting/Ledger';
|
||||||
import { ACCOUNT_TYPE } from 'data/AccountTypes';
|
import { ACCOUNT_TYPE } from 'data/AccountTypes';
|
||||||
import AccountRepository from 'repositories/AccountRepository';
|
|
||||||
|
|
||||||
export default class TransactionsByCustomersService
|
export default class TransactionsByCustomersService
|
||||||
implements ITransactionsByCustomersService {
|
implements ITransactionsByCustomersService {
|
||||||
@@ -97,7 +96,7 @@ export default class TransactionsByCustomersService
|
|||||||
async getCustomersPeriodTransactions(
|
async getCustomersPeriodTransactions(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
fromDate: Date,
|
fromDate: Date,
|
||||||
toDate: Date,
|
toDate: Date
|
||||||
): Promise<ILedgerEntry[]> {
|
): Promise<ILedgerEntry[]> {
|
||||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
const { AccountTransaction } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
@@ -115,7 +114,13 @@ export default class TransactionsByCustomersService
|
|||||||
query.whereIn('accountId', receivableAccountsIds);
|
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 accountsGraph = await accountRepository.getDependencyGraph();
|
||||||
const customers = await Customer.query().orderBy('displayName');
|
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.
|
// Retrieve all ledger transactions of the opening balance of.
|
||||||
const openingBalanceTransactions = await this.getCustomersOpeningBalance(
|
const openingBalanceTransactions = await this.getCustomersOpeningBalance(
|
||||||
tenantId,
|
tenantId,
|
||||||
openingBalanceDate,
|
openingBalanceDate
|
||||||
);
|
);
|
||||||
// Retrieve all ledger transactions between opeing and closing period.
|
// Retrieve all ledger transactions between opeing and closing period.
|
||||||
const customersTransactions = await this.getCustomersPeriodTransactions(
|
const customersTransactions = await this.getCustomersPeriodTransactions(
|
||||||
tenantId,
|
tenantId,
|
||||||
query.fromDate,
|
query.fromDate,
|
||||||
query.toDate,
|
query.toDate
|
||||||
);
|
);
|
||||||
// Concats the opening balance and period customer ledger transactions.
|
// Concats the opening balance and period customer ledger transactions.
|
||||||
const journalTransactions = [
|
const journalTransactions = [
|
||||||
...openingBalanceTransactions,
|
...openingBalanceTransactions,
|
||||||
...customersTransactions,
|
...customersTransactions,
|
||||||
];
|
];
|
||||||
const journal = new Ledger(journalTransactions);
|
const journal = Ledger.fromTransactions(journalTransactions);
|
||||||
|
|
||||||
// Transactions by customers data mapper.
|
// Transactions by customers data mapper.
|
||||||
const reportInstance = new TransactionsByCustomers(
|
const reportInstance = new TransactionsByCustomers(
|
||||||
|
|||||||
@@ -126,7 +126,13 @@ export default class TransactionsByVendorsService
|
|||||||
query.whereIn('accountId', receivableAccountsIds);
|
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) {
|
async getReportTransactions(tenantId: number, fromDate: Date, toDate: Date) {
|
||||||
@@ -172,7 +178,7 @@ export default class TransactionsByVendorsService
|
|||||||
filter.toDate
|
filter.toDate
|
||||||
);
|
);
|
||||||
// Ledger collection.
|
// Ledger collection.
|
||||||
const journal = new Ledger(journalTransactions);
|
const journal = Ledger.fromTransactions(journalTransactions);
|
||||||
|
|
||||||
// Transactions by customers data mapper.
|
// Transactions by customers data mapper.
|
||||||
const reportInstance = new TransactionsByVendor(
|
const reportInstance = new TransactionsByVendor(
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export default class VendorBalanceSummaryService
|
|||||||
const vendors = await this.getReportVendors(tenantId, query.vendorsIds);
|
const vendors = await this.getReportVendors(tenantId, query.vendorsIds);
|
||||||
|
|
||||||
// Ledger query.
|
// Ledger query.
|
||||||
const ledger = new Ledger(vendorsTransactions);
|
const ledger = Ledger.fromTransactions(vendorsTransactions);
|
||||||
|
|
||||||
// Report instance.
|
// Report instance.
|
||||||
const reportInstance = new VendorBalanceSummaryReport(
|
const reportInstance = new VendorBalanceSummaryReport(
|
||||||
|
|||||||
Reference in New Issue
Block a user