mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
feat: wip categorize the cashflow transactions
This commit is contained in:
@@ -80,10 +80,7 @@ export default class NewCashflowTransactionController extends BaseController {
|
||||
public get categorizeCashflowTransactionValidationSchema() {
|
||||
return [
|
||||
check('date').exists().isISO8601().toDate(),
|
||||
oneOf([
|
||||
check('to_account_id').exists().isInt().toInt(),
|
||||
check('from_account_id').exists().isInt().toInt(),
|
||||
]),
|
||||
check('credit_account_id').exists().isInt().toInt(),
|
||||
check('transaction_number').optional(),
|
||||
check('transaction_type').exists(),
|
||||
check('reference_no').optional(),
|
||||
|
||||
@@ -235,8 +235,7 @@ export interface ICashflowTransactionSchema {
|
||||
export interface ICashflowTransactionInput extends ICashflowTransactionSchema {}
|
||||
|
||||
export interface ICategorizeCashflowTransactioDTO {
|
||||
fromAccountId: number;
|
||||
toAccountId: number;
|
||||
creditAccountId: number;
|
||||
referenceNo: string;
|
||||
transactionNumber: string;
|
||||
transactionType: string;
|
||||
|
||||
@@ -318,7 +318,7 @@ export default class Account extends mixin(TenantModel, [
|
||||
to: 'uncategorized_cashflow_transactions.accountId',
|
||||
},
|
||||
filter: (query) => {
|
||||
query.filter('categorized', false);
|
||||
query.where('categorized', false);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable global-require */
|
||||
import TenantModel from 'models/TenantModel';
|
||||
import { Model } from 'objection';
|
||||
import { Model, ModelOptions, QueryContext } from 'objection';
|
||||
import Account from './Account';
|
||||
|
||||
export default class UncategorizedCashflowTransaction extends TenantModel {
|
||||
@@ -95,6 +95,19 @@ export default class UncategorizedCashflowTransaction extends TenantModel {
|
||||
.increment('uncategorized_transactions', 1);
|
||||
}
|
||||
|
||||
public async $afterUpdate(
|
||||
opt: ModelOptions,
|
||||
queryContext: QueryContext
|
||||
): void | Promise<any> {
|
||||
await super.$afterUpdate(opt, queryContext);
|
||||
|
||||
if (this.id && this.categorized) {
|
||||
await Account.query(queryContext.transaction)
|
||||
.findById(this.accountId)
|
||||
.decrement('uncategorized_transactions', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param queryContext
|
||||
@@ -102,7 +115,7 @@ export default class UncategorizedCashflowTransaction extends TenantModel {
|
||||
public async $afterDelete(queryContext) {
|
||||
await super.$afterDelete(queryContext);
|
||||
|
||||
await Account.query()
|
||||
await Account.query(queryContext.transaction)
|
||||
.findById(this.accountId)
|
||||
.decrement('uncategorized_transactions', 1);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -31,6 +31,7 @@ export default class GetCashflowTransactionsService {
|
||||
.withGraphFetched('entries.cashflowAccount')
|
||||
.withGraphFetched('entries.creditAccount')
|
||||
.withGraphFetched('transactions.account')
|
||||
.orderBy('date', 'DESC')
|
||||
.throwIfNotFound();
|
||||
|
||||
this.throwErrorCashflowTranscationNotFound(cashflowTransaction);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user