Compare commits

..

1 Commits

Author SHA1 Message Date
Ahmed Bouhuolia
8f30c86f5f fizx: remove debug console.log 2024-07-30 21:54:55 +02:00
135 changed files with 902 additions and 2805 deletions

View File

@@ -132,24 +132,6 @@
"contributions": [
"bug"
]
},
{
"login": "oleynikd",
"name": "Denis",
"avatar_url": "https://avatars.githubusercontent.com/u/3976868?v=4",
"profile": "https://github.com/oleynikd",
"contributions": [
"bug"
]
},
{
"login": "mittalsam98",
"name": "Sachin Mittal",
"avatar_url": "https://avatars.githubusercontent.com/u/42431274?v=4",
"profile": "https://myself.vercel.app/",
"contributions": [
"bug"
]
}
],
"contributorsPerLine": 7,

View File

@@ -126,10 +126,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="http://vederis.id"><img src="https://avatars.githubusercontent.com/u/13505006?v=4?s=100" width="100px;" alt="Vederis Leunardus"/><br /><sub><b>Vederis Leunardus</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=cloudsbird" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://www.pivoten.com"><img src="https://avatars.githubusercontent.com/u/104120598?v=4?s=100" width="100px;" alt="Chris Cantrell"/><br /><sub><b>Chris Cantrell</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Accantrell72" title="Bug reports">🐛</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/oleynikd"><img src="https://avatars.githubusercontent.com/u/3976868?v=4?s=100" width="100px;" alt="Denis"/><br /><sub><b>Denis</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Aoleynikd" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://myself.vercel.app/"><img src="https://avatars.githubusercontent.com/u/42431274?v=4?s=100" width="100px;" alt="Sachin Mittal"/><br /><sub><b>Sachin Mittal</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Amittalsam98" title="Bug reports">🐛</a></td>
</tr>
</tbody>
</table>

View File

@@ -250,12 +250,10 @@ export class AttachmentsController extends BaseController {
res: Response,
next: NextFunction
): Promise<Response | void> {
const { tenantId } = req;
const { id: documentKey } = req.params;
try {
const presignedUrl = await this.attachmentsApplication.getPresignedUrl(
tenantId,
documentKey
);
return res.status(200).send({ presignedUrl });

View File

@@ -1,9 +1,9 @@
import { Inject, Service } from 'typedi';
import { NextFunction, Request, Response, Router } from 'express';
import BaseController from '@/api/controllers/BaseController';
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
import { GetBankAccountSummary } from '@/services/Banking/BankAccounts/GetBankAccountSummary';
import { BankAccountsApplication } from '@/services/Banking/BankAccounts/BankAccountsApplication';
import { param } from 'express-validator';
@Service()
export class BankAccountsController extends BaseController {
@@ -25,22 +25,6 @@ export class BankAccountsController extends BaseController {
this.disconnectBankAccount.bind(this)
);
router.post('/:bankAccountId/update', this.refreshBankAccount.bind(this));
router.post(
'/:bankAccountId/pause_feeds',
[
param('bankAccountId').exists().isNumeric().toInt(),
],
this.validationResult,
this.pauseBankAccountFeeds.bind(this)
);
router.post(
'/:bankAccountId/resume_feeds',
[
param('bankAccountId').exists().isNumeric().toInt(),
],
this.validationResult,
this.resumeBankAccountFeeds.bind(this)
);
return router;
}
@@ -125,58 +109,4 @@ export class BankAccountsController extends BaseController {
next(error);
}
}
/**
* Resumes the bank account feeds sync.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @returns {Promise<Response | void>}
*/
async resumeBankAccountFeeds(
req: Request<{ bankAccountId: number }>,
res: Response,
next: NextFunction
) {
const { bankAccountId } = req.params;
const { tenantId } = req;
try {
await this.bankAccountsApp.resumeBankAccount(tenantId, bankAccountId);
return res.status(200).send({
message: 'The bank account feeds syncing has been resumed.',
id: bankAccountId,
});
} catch (error) {
next(error);
}
}
/**
* Pauses the bank account feeds sync.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @returns {Promise<Response | void>}
*/
async pauseBankAccountFeeds(
req: Request<{ bankAccountId: number }>,
res: Response,
next: NextFunction
) {
const { bankAccountId } = req.params;
const { tenantId } = req;
try {
await this.bankAccountsApp.pauseBankAccount(tenantId, bankAccountId);
return res.status(200).send({
message: 'The bank account feeds syncing has been paused.',
id: bankAccountId,
});
} catch (error) {
next(error);
}
}
}

View File

@@ -1,8 +1,12 @@
import { Inject, Service } from 'typedi';
import { body, param } from 'express-validator';
import { NextFunction, Request, Response, Router } from 'express';
import BaseController from '@/api/controllers/BaseController';
import { MatchBankTransactionsApplication } from '@/services/Banking/Matching/MatchBankTransactionsApplication';
import { body, param } from 'express-validator';
import {
GetMatchedTransactionsFilter,
IMatchTransactionsDTO,
} from '@/services/Banking/Matching/types';
@Service()
export class BankTransactionsMatchingController extends BaseController {
@@ -16,17 +20,9 @@ export class BankTransactionsMatchingController extends BaseController {
const router = Router();
router.post(
'/unmatch/:transactionId',
[param('transactionId').exists()],
this.validationResult,
this.unmatchMatchedBankTransaction.bind(this)
);
router.post(
'/match',
'/:transactionId',
[
body('uncategorizedTransactions').exists().isArray({ min: 1 }),
body('uncategorizedTransactions.*').isNumeric().toInt(),
param('transactionId').exists(),
body('matchedTransactions').isArray({ min: 1 }),
body('matchedTransactions.*.reference_type').exists(),
body('matchedTransactions.*.reference_id').isNumeric().toInt(),
@@ -34,6 +30,12 @@ export class BankTransactionsMatchingController extends BaseController {
this.validationResult,
this.matchBankTransaction.bind(this)
);
router.post(
'/unmatch/:transactionId',
[param('transactionId').exists()],
this.validationResult,
this.unmatchMatchedBankTransaction.bind(this)
);
return router;
}
@@ -48,21 +50,21 @@ export class BankTransactionsMatchingController extends BaseController {
req: Request<{ transactionId: number }>,
res: Response,
next: NextFunction
): Promise<Response | null> {
) {
const { tenantId } = req;
const bodyData = this.matchedBodyData(req);
const uncategorizedTransactions = bodyData?.uncategorizedTransactions;
const matchedTransactions = bodyData?.matchedTransactions;
const { transactionId } = req.params;
const matchTransactionDTO = this.matchedBodyData(
req
) as IMatchTransactionsDTO;
try {
await this.bankTransactionsMatchingApp.matchTransaction(
tenantId,
uncategorizedTransactions,
matchedTransactions
transactionId,
matchTransactionDTO
);
return res.status(200).send({
ids: uncategorizedTransactions,
id: transactionId,
message: 'The bank transaction has been matched.',
});
} catch (error) {

View File

@@ -6,7 +6,6 @@ import { BankingRulesController } from './BankingRulesController';
import { BankTransactionsMatchingController } from './BankTransactionsMatchingController';
import { RecognizedTransactionsController } from './RecognizedTransactionsController';
import { BankAccountsController } from './BankAccountsController';
import { BankingUncategorizedController } from './BankingUncategorizedController';
@Service()
export class BankingController extends BaseController {
@@ -30,10 +29,6 @@ export class BankingController extends BaseController {
'/bank_accounts',
Container.get(BankAccountsController).router()
);
router.use(
'/categorize',
Container.get(BankingUncategorizedController).router()
);
return router;
}
}

View File

@@ -34,15 +34,16 @@ export class BankingRulesController extends BaseController {
body('conditions.*.comparator')
.exists()
.isIn(['equals', 'contains', 'not_contain'])
.default('contain')
.trim(),
body('conditions.*.value').exists().trim(),
.default('contain'),
body('conditions.*.value').exists(),
// Assign
body('assign_category').isString(),
body('assign_account_id').isInt({ min: 0 }),
body('assign_payee').isString().optional({ nullable: true }),
body('assign_memo').isString().optional({ nullable: true }),
body('recognition').isBoolean().toBoolean().optional({ nullable: true }),
];
}

View File

@@ -1,57 +0,0 @@
import { Inject, Service } from 'typedi';
import { NextFunction, Request, Response, Router } from 'express';
import { query } from 'express-validator';
import BaseController from '../BaseController';
import { GetAutofillCategorizeTransaction } from '@/services/Banking/RegonizeTranasctions/GetAutofillCategorizeTransaction';
@Service()
export class BankingUncategorizedController extends BaseController {
@Inject()
private getAutofillCategorizeTransactionService: GetAutofillCategorizeTransaction;
/**
* Router constructor.
*/
router() {
const router = Router();
router.get(
'/autofill',
[
query('uncategorizedTransactionIds').isArray({ min: 1 }),
query('uncategorizedTransactionIds.*').isNumeric().toInt(),
],
this.validationResult,
this.getAutofillCategorizeTransaction.bind(this)
);
return router;
}
/**
* Retrieves the autofill values of the categorize form of the given
* uncategorized transactions.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @returns {Promise<Response | null>}
*/
public async getAutofillCategorizeTransaction(
req: Request,
res: Response,
next: NextFunction
) {
const { tenantId } = req;
const uncategorizedTransactionIds = req.query.uncategorizedTransactionIds;
try {
const data =
await this.getAutofillCategorizeTransactionService.getAutofillCategorizeTransaction(
tenantId,
uncategorizedTransactionIds
);
return res.status(200).send({ data });
} catch (error) {
next(error);
}
}
}

View File

@@ -42,11 +42,7 @@ export class ExcludeBankTransactionsController extends BaseController {
);
router.get(
'/excluded',
[
query('account_id').optional().isNumeric().toInt(),
query('page').optional().isNumeric().toInt(),
query('page_size').optional().isNumeric().toInt(),
],
[],
this.validationResult,
this.getExcludedBankTransactions.bind(this)
);
@@ -181,7 +177,7 @@ export class ExcludeBankTransactionsController extends BaseController {
next: NextFunction
): Promise<Response | void> {
const { tenantId } = req;
const filter = this.matchedQueryData(req);
const filter = this.matchedBodyData(req);
try {
const data =

View File

@@ -1,6 +1,5 @@
import { Inject, Service } from 'typedi';
import { NextFunction, Request, Response, Router } from 'express';
import { query } from 'express-validator';
import BaseController from '@/api/controllers/BaseController';
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
@@ -15,16 +14,7 @@ export class RecognizedTransactionsController extends BaseController {
router() {
const router = Router();
router.get(
'/',
[
query('page').optional().isNumeric().toInt(),
query('page_size').optional().isNumeric().toInt(),
query('account_id').optional().isNumeric().toInt(),
],
this.validationResult,
this.getRecognizedTransactions.bind(this)
);
router.get('/', this.getRecognizedTransactions.bind(this));
router.get(
'/transactions/:uncategorizedTransactionId',
this.getRecognizedTransaction.bind(this)

View File

@@ -1,6 +1,6 @@
import { Service, Inject } from 'typedi';
import { Router, Request, Response, NextFunction } from 'express';
import { param, query } from 'express-validator';
import { param } from 'express-validator';
import BaseController from '../BaseController';
import { ServiceError } from '@/exceptions';
import CheckPolicies from '@/api/middleware/CheckPolicies';
@@ -24,12 +24,7 @@ export default class GetCashflowAccounts extends BaseController {
const router = Router();
router.get(
'/transactions/matches',
[
query('uncategorizeTransactionsIds').exists().isArray({ min: 1 }),
query('uncategorizeTransactionsIds.*').exists().isNumeric().toInt(),
],
this.validationResult,
'/transactions/:transactionId/matches',
this.getMatchedTransactions.bind(this)
);
router.get(
@@ -49,7 +44,7 @@ export default class GetCashflowAccounts extends BaseController {
* @param {NextFunction} next
*/
private getCashflowTransaction = async (
req: Request<{ transactionId: number }>,
req: Request,
res: Response,
next: NextFunction
) => {
@@ -76,24 +71,19 @@ export default class GetCashflowAccounts extends BaseController {
* @param {NextFunction} next
*/
private async getMatchedTransactions(
req: Request<
{ transactionId: number },
null,
null,
{ uncategorizeTransactionsIds: Array<number> }
>,
req: Request<{ transactionId: number }>,
res: Response,
next: NextFunction
) {
const { tenantId } = req;
const uncategorizeTransactionsIds = req.query.uncategorizeTransactionsIds;
const { transactionId } = req.params;
const filter = this.matchedQueryData(req) as GetMatchedTransactionsFilter;
try {
const data =
await this.bankTransactionsMatchingApp.getMatchedTransactions(
tenantId,
uncategorizeTransactionsIds,
transactionId,
filter
);
return res.status(200).send(data);

View File

@@ -1,15 +1,10 @@
import { Service, Inject } from 'typedi';
import { ValidationChain, check, param, query } from 'express-validator';
import { Router, Request, Response, NextFunction } from 'express';
import { omit } from 'lodash';
import BaseController from '../BaseController';
import { ServiceError } from '@/exceptions';
import CheckPolicies from '@/api/middleware/CheckPolicies';
import {
AbilitySubject,
CashflowAction,
ICategorizeCashflowTransactioDTO,
} from '@/interfaces';
import { AbilitySubject, CashflowAction } from '@/interfaces';
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
@Service()
@@ -49,7 +44,7 @@ export default class NewCashflowTransactionController extends BaseController {
this.catchServiceErrors
);
router.post(
'/transactions/categorize',
'/transactions/:id/categorize',
this.categorizeCashflowTransactionValidationSchema,
this.validationResult,
this.categorizeCashflowTransaction,
@@ -94,7 +89,6 @@ export default class NewCashflowTransactionController extends BaseController {
*/
public get categorizeCashflowTransactionValidationSchema() {
return [
check('uncategorized_transaction_ids').exists().isArray({ min: 1 }),
check('date').exists().isISO8601().toDate(),
check('credit_account_id').exists().isInt().toInt(),
check('transaction_number').optional(),
@@ -167,7 +161,7 @@ export default class NewCashflowTransactionController extends BaseController {
* @param {NextFunction} next
*/
private revertCategorizedCashflowTransaction = async (
req: Request<{ id: number }>,
req: Request,
res: Response,
next: NextFunction
) => {
@@ -197,19 +191,14 @@ export default class NewCashflowTransactionController extends BaseController {
next: NextFunction
) => {
const { tenantId } = req;
const matchedObject = this.matchedBodyData(req);
const categorizeDTO = omit(matchedObject, [
'uncategorizedTransactionIds',
]) as ICategorizeCashflowTransactioDTO;
const uncategorizedTransactionIds =
matchedObject.uncategorizedTransactionIds;
const { id: cashflowTransactionId } = req.params;
const cashflowTransaction = this.matchedBodyData(req);
try {
await this.cashflowApplication.categorizeTransaction(
tenantId,
uncategorizedTransactionIds,
categorizeDTO
cashflowTransactionId,
cashflowTransaction
);
return res.status(200).send({
message: 'The cashflow transaction has been created successfully.',
@@ -280,7 +269,7 @@ export default class NewCashflowTransactionController extends BaseController {
* @param {NextFunction} next
*/
public getUncategorizedCashflowTransactions = async (
req: Request<{ id: number }>,
req: Request,
res: Response,
next: NextFunction
) => {

View File

@@ -1,11 +0,0 @@
exports.up = function (knex) {
return knex.schema.table('plaid_items', (table) => {
table.datetime('paused_at');
});
};
exports.down = function (knex) {
return knex.schema.table('plaid_items', (table) => {
table.dropColumn('paused_at');
});
};

View File

@@ -236,7 +236,6 @@ export interface ICashflowTransactionSchema {
export interface ICashflowTransactionInput extends ICashflowTransactionSchema {}
export interface ICategorizeCashflowTransactioDTO {
date: Date;
creditAccountId: number;
referenceNo: string;
transactionNumber: string;

View File

@@ -130,23 +130,20 @@ export interface ICommandCashflowDeletedPayload {
export interface ICashflowTransactionCategorizedPayload {
tenantId: number;
uncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
uncategorizedTransaction: any;
cashflowTransaction: ICashflowTransaction;
oldUncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
categorizeDTO: any;
trx: Knex.Transaction;
}
export interface ICashflowTransactionUncategorizingPayload {
tenantId: number;
uncategorizedTransactionId: number;
oldUncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
uncategorizedTransaction: IUncategorizedCashflowTransaction;
trx: Knex.Transaction;
}
export interface ICashflowTransactionUncategorizedPayload {
tenantId: number;
uncategorizedTransactionId: number;
uncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
oldUncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
uncategorizedTransaction: IUncategorizedCashflowTransaction;
oldUncategorizedTransaction: IUncategorizedCashflowTransaction;
trx: Knex.Transaction;
}

View File

@@ -13,9 +13,7 @@ import { PaymentReceiveMailNotificationJob } from '@/services/Sales/PaymentRecei
import { PlaidFetchTransactionsJob } from '@/services/Banking/Plaid/PlaidFetchTransactionsJob';
import { ImportDeleteExpiredFilesJobs } from '@/services/Import/jobs/ImportDeleteExpiredFilesJob';
import { SendVerifyMailJob } from '@/services/Authentication/jobs/SendVerifyMailJob';
import { ReregonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/jobs/RerecognizeTransactionsJob';
import { RegonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/jobs/RecognizeTransactionsJob';
import { RevertRegonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/jobs/RevertRecognizedTransactionsJob';
import { RegonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/RecognizeTransactionsJob';
export default ({ agenda }: { agenda: Agenda }) => {
new ResetPasswordMailJob(agenda);
@@ -33,8 +31,6 @@ export default ({ agenda }: { agenda: Agenda }) => {
new ImportDeleteExpiredFilesJobs(agenda);
new SendVerifyMailJob(agenda);
new RegonizeTransactionsJob(agenda);
new ReregonizeTransactionsJob(agenda);
new RevertRegonizeTransactionsJob(agenda);
agenda.start().then(() => {
agenda.every('1 hours', 'delete-expired-imported-files', {});

View File

@@ -1,8 +1,6 @@
import TenantModel from 'models/TenantModel';
export default class PlaidItem extends TenantModel {
pausedAt: Date;
/**
* Table name.
*/
@@ -23,19 +21,4 @@ export default class PlaidItem extends TenantModel {
static get relationMappings() {
return {};
}
/**
* Virtual attributes.
*/
static get virtualAttributes() {
return ['isPaused'];
}
/**
* Detarmines whether the Plaid item feeds syncing is paused.
* @return {boolean}
*/
get isPaused() {
return !!this.pausedAt;
}
}

View File

@@ -20,7 +20,6 @@ export default class UncategorizedCashflowTransaction extends mixin(
description!: string;
plaidTransactionId!: string;
recognizedTransactionId!: number;
excludedAt: Date;
/**
* Table name.
@@ -32,7 +31,7 @@ export default class UncategorizedCashflowTransaction extends mixin(
/**
* Timestamps columns.
*/
get timestamps() {
static get timestamps() {
return ['createdAt', 'updatedAt'];
}
@@ -46,7 +45,6 @@ export default class UncategorizedCashflowTransaction extends mixin(
'isDepositTransaction',
'isWithdrawalTransaction',
'isRecognized',
'isExcluded'
];
}
@@ -91,14 +89,6 @@ export default class UncategorizedCashflowTransaction extends mixin(
return !!this.recognizedTransactionId;
}
/**
* Detarmines whether the transaction is excluded.
* @returns {boolean}
*/
public get isExcluded(): boolean {
return !!this.excludedAt;
}
/**
* Model modifiers.
*/

View File

@@ -18,18 +18,9 @@ export class AccountTransformer extends Transformer {
'flattenName',
'bankBalanceFormatted',
'lastFeedsUpdatedAtFormatted',
'isFeedsPaused',
];
};
/**
* Exclude attributes.
* @returns {string[]}
*/
public excludeAttributes = (): string[] => {
return ['plaidItem'];
};
/**
* Retrieves the flatten name with all dependants accounts names.
* @param {IAccount} account -
@@ -75,15 +66,6 @@ export class AccountTransformer extends Transformer {
return this.formatDate(account.lastFeedsUpdatedAt);
};
/**
* Detarmines whether the bank account connection is paused.
* @param account
* @returns {boolean}
*/
protected isFeedsPaused = (account: any): boolean => {
return account.plaidItem?.isPaused || false;
};
/**
* Transformes the accounts collection to flat or nested array.
* @param {IAccount[]}

View File

@@ -25,10 +25,7 @@ export class GetAccount {
const { accountRepository } = this.tenancy.repositories(tenantId);
// Find the given account or throw not found error.
const account = await Account.query()
.findById(accountId)
.withGraphFetched('plaidItem')
.throwIfNotFound();
const account = await Account.query().findById(accountId).throwIfNotFound();
const accountsGraph = await accountRepository.getDependencyGraph();

View File

@@ -96,11 +96,10 @@ export class AttachmentsApplication {
/**
* Retrieves the presigned url of the given attachment key.
* @param {number} tenantId
* @param {string} key
* @returns {Promise<string>}
*/
public getPresignedUrl(tenantId: number, key: string): Promise<string> {
return this.getPresignedUrlService.getPresignedUrl(tenantId, key);
public getPresignedUrl(key: string): Promise<string> {
return this.getPresignedUrlService.getPresignedUrl(key);
}
}

View File

@@ -1,34 +1,20 @@
import { Inject, Service } from 'typedi';
import { Service } from 'typedi';
import { GetObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { s3 } from '@/lib/S3/S3';
import config from '@/config';
import HasTenancyService from '../Tenancy/TenancyService';
@Service()
export class getAttachmentPresignedUrl {
@Inject()
private tenancy: HasTenancyService;
/**
* Retrieves the presigned url of the given attachment key with the original filename.
* @param {number} tenantId
* Retrieves the presigned url of the given attachment key.
* @param {string} key
* @returns {string}
* @returns {Promise<string?>}
*/
async getPresignedUrl(tenantId: number, key: string) {
const { Document } = this.tenancy.models(tenantId);
const foundDocument = await Document.query().findOne({ key });
let ResponseContentDisposition = 'attachment';
if (foundDocument && foundDocument.originName) {
ResponseContentDisposition += `; filename="${foundDocument.originName}"`;
}
async getPresignedUrl(key: string) {
const command = new GetObjectCommand({
Bucket: config.s3.bucket,
Key: key,
ResponseContentDisposition,
});
const signedUrl = await getSignedUrl(s3, command, { expiresIn: 300 });

View File

@@ -1,8 +1,6 @@
import { Inject, Service } from 'typedi';
import { DisconnectBankAccount } from './DisconnectBankAccount';
import { RefreshBankAccountService } from './RefreshBankAccount';
import { PauseBankAccountFeeds } from './PauseBankAccountFeeds';
import { ResumeBankAccountFeeds } from './ResumeBankAccountFeeds';
@Service()
export class BankAccountsApplication {
@@ -12,12 +10,6 @@ export class BankAccountsApplication {
@Inject()
private refreshBankAccountService: RefreshBankAccountService;
@Inject()
private resumeBankAccountFeedsService: ResumeBankAccountFeeds;
@Inject()
private pauseBankAccountFeedsService: PauseBankAccountFeeds;
/**
* Disconnects the given bank account.
* @param {number} tenantId
@@ -35,7 +27,7 @@ export class BankAccountsApplication {
* Refresh the bank transactions of the given bank account.
* @param {number} tenantId
* @param {number} bankAccountId
* @returns {Promise<void>}
* @returns {Promise<void>}
*/
async refreshBankAccount(tenantId: number, bankAccountId: number) {
return this.refreshBankAccountService.refreshBankAccount(
@@ -43,30 +35,4 @@ export class BankAccountsApplication {
bankAccountId
);
}
/**
* Pauses the feeds sync of the given bank account.
* @param {number} tenantId
* @param {number} bankAccountId
* @returns {Promise<void>}
*/
async pauseBankAccount(tenantId: number, bankAccountId: number) {
return this.pauseBankAccountFeedsService.pauseBankAccountFeeds(
tenantId,
bankAccountId
);
}
/**
* Resumes the feeds sync of the given bank account.
* @param {number} tenantId
* @param {number} bankAccountId
* @returns {Promise<void>}
*/
async resumeBankAccount(tenantId: number, bankAccountId: number) {
return this.resumeBankAccountFeedsService.resumeBankAccountFeeds(
tenantId,
bankAccountId
);
}
}

View File

@@ -1,7 +1,6 @@
import { Inject, Service } from 'typedi';
import { initialize } from 'objection';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { UncategorizedTransactionTransformer } from '@/services/Cashflow/UncategorizedTransactionTransformer';
@Service()
export class GetBankAccountSummary {
@@ -32,21 +31,17 @@ export class GetBankAccountSummary {
.findById(bankAccountId)
.throwIfNotFound();
const commonQuery = (q) => {
// Include just the given account.
q.where('accountId', bankAccountId);
// Only the not excluded.
q.modify('notExcluded');
// Only the not categorized.
q.modify('notCategorized');
};
// Retrieves the uncategorized transactions count of the given bank account.
const uncategorizedTranasctionsCount =
await UncategorizedCashflowTransaction.query().onBuild((q) => {
commonQuery(q);
// Include just the given account.
q.where('accountId', bankAccountId);
// Only the not excluded.
q.modify('notExcluded');
// Only the not categorized.
q.modify('notCategorized');
// Only the not matched bank transactions.
q.withGraphJoined('matchedBankTransactions');
@@ -57,40 +52,25 @@ export class GetBankAccountSummary {
q.first();
});
// Retrives the recognized transactions count.
const recognizedTransactionsCount =
await UncategorizedCashflowTransaction.query().onBuild((q) => {
commonQuery(q);
q.withGraphJoined('recognizedTransaction');
q.whereNotNull('recognizedTransaction.id');
// Count the results.
q.count('uncategorized_cashflow_transactions.id as total');
q.first();
});
const excludedTransactionsCount =
await UncategorizedCashflowTransaction.query().onBuild((q) => {
q.where('accountId', bankAccountId);
q.modify('excluded');
// Count the results.
q.count('uncategorized_cashflow_transactions.id as total');
q.first();
});
// Retrieves the recognized transactions count of the given bank account.
const recognizedTransactionsCount = await RecognizedBankTransaction.query()
.whereExists(
UncategorizedCashflowTransaction.query().where(
'accountId',
bankAccountId
)
)
.count('id as total')
.first();
const totalUncategorizedTransactions =
uncategorizedTranasctionsCount?.total || 0;
const totalRecognizedTransactions = recognizedTransactionsCount?.total || 0;
const totalExcludedTransactions = excludedTransactionsCount?.total || 0;
return {
name: bankAccount.name,
totalUncategorizedTransactions,
totalRecognizedTransactions,
totalExcludedTransactions,
};
}
}

View File

@@ -1,44 +0,0 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork';
import { ServiceError } from '@/exceptions';
import { ERRORS } from './types';
@Service()
export class PauseBankAccountFeeds {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private uow: UnitOfWork;
/**
* Pauses the bankfeed syncing of the given bank account.
* @param {number} tenantId
* @param {number} bankAccountId
* @returns {Promise<void>}
*/
public async pauseBankAccountFeeds(tenantId: number, bankAccountId: number) {
const { Account, PlaidItem } = this.tenancy.models(tenantId);
const oldAccount = await Account.query()
.findById(bankAccountId)
.withGraphFetched('plaidItem')
.throwIfNotFound();
// Can't continue if the bank account is not connected.
if (!oldAccount.plaidItem) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED);
}
// Cannot continue if the bank account feeds is already paused.
if (oldAccount.plaidItem.isPaused) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_FEEDS_ALREADY_PAUSED);
}
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({
pausedAt: new Date(),
});
});
}
}

View File

@@ -1,43 +0,0 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork';
import { ServiceError } from '@/exceptions';
import { ERRORS } from './types';
@Service()
export class ResumeBankAccountFeeds {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private uow: UnitOfWork;
/**
* Resumes the bank feeds syncing of the bank account.
* @param {number} tenantId
* @param {number} bankAccountId
* @returns {Promise<void>}
*/
public async resumeBankAccountFeeds(tenantId: number, bankAccountId: number) {
const { Account, PlaidItem } = this.tenancy.models(tenantId);
const oldAccount = await Account.query()
.findById(bankAccountId)
.withGraphFetched('plaidItem');
// Can't continue if the bank account is not connected.
if (!oldAccount.plaidItem) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED);
}
// Cannot continue if the bank account feeds is already paused.
if (!oldAccount.plaidItem.isPaused) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_FEEDS_ALREADY_RESUMED);
}
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({
pausedAt: null,
});
});
}
}

View File

@@ -14,6 +14,4 @@ export interface IBankAccountDisconnectedEventPayload {
export const ERRORS = {
BANK_ACCOUNT_NOT_CONNECTED: 'BANK_ACCOUNT_NOT_CONNECTED',
BANK_ACCOUNT_FEEDS_ALREADY_PAUSED: 'BANK_ACCOUNT_FEEDS_ALREADY_PAUSED',
BANK_ACCOUNT_FEEDS_ALREADY_RESUMED: 'BANK_ACCOUNT_FEEDS_ALREADY_RESUMED',
};

View File

@@ -1,11 +1,7 @@
import { Knex } from 'knex';
import { Inject, Service } from 'typedi';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork';
import {
validateTransactionNotCategorized,
validateTransactionNotExcluded,
} from './utils';
import { Inject, Service } from 'typedi';
import { validateTransactionNotCategorized } from './utils';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
import {
@@ -41,13 +37,9 @@ export class ExcludeBankTransaction {
.findById(uncategorizedTransactionId)
.throwIfNotFound();
// Validate the transaction shouldn't be excluded.
validateTransactionNotExcluded(oldUncategorizedTransaction);
// Validate the transaction shouldn't be categorized.
validateTransactionNotCategorized(oldUncategorizedTransaction);
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
return this.uow.withTransaction(tenantId, async (trx) => {
await this.eventPublisher.emitAsync(events.bankTransactions.onExcluding, {
tenantId,
uncategorizedTransactionId,

View File

@@ -1,6 +1,6 @@
import { Inject, Service } from 'typedi';
import PromisePool from '@supercharge/promise-pool';
import { castArray, uniq } from 'lodash';
import { castArray } from 'lodash';
import { ExcludeBankTransaction } from './ExcludeBankTransaction';
@Service()
@@ -18,7 +18,7 @@ export class ExcludeBankTransactions {
tenantId: number,
bankTransactionIds: Array<number> | number
) {
const _bankTransactionIds = uniq(castArray(bankTransactionIds));
const _bankTransactionIds = castArray(bankTransactionIds);
await PromisePool.withConcurrency(1)
.for(_bankTransactionIds)

View File

@@ -1,11 +1,7 @@
import { Knex } from 'knex';
import { Inject, Service } from 'typedi';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork';
import {
validateTransactionNotCategorized,
validateTransactionShouldBeExcluded,
} from './utils';
import { Inject, Service } from 'typedi';
import { validateTransactionNotCategorized } from './utils';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
import {
@@ -41,13 +37,9 @@ export class UnexcludeBankTransaction {
.findById(uncategorizedTransactionId)
.throwIfNotFound();
// Validate the transaction should be excludded.
validateTransactionShouldBeExcluded(oldUncategorizedTransaction);
// Validate the transaction shouldn't be categorized.
validateTransactionNotCategorized(oldUncategorizedTransaction);
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
return this.uow.withTransaction(tenantId, async (trx) => {
await this.eventPublisher.emitAsync(
events.bankTransactions.onUnexcluding,
{

View File

@@ -1,7 +1,7 @@
import { Inject, Service } from 'typedi';
import PromisePool from '@supercharge/promise-pool';
import { UnexcludeBankTransaction } from './UnexcludeBankTransaction';
import { castArray, uniq } from 'lodash';
import { castArray } from 'lodash';
@Service()
export class UnexcludeBankTransactions {
@@ -17,7 +17,7 @@ export class UnexcludeBankTransactions {
tenantId: number,
bankTransactionIds: Array<number> | number
) {
const _bankTransactionIds = uniq(castArray(bankTransactionIds));
const _bankTransactionIds = castArray(bankTransactionIds);
await PromisePool.withConcurrency(1)
.for(_bankTransactionIds)

View File

@@ -3,8 +3,6 @@ import UncategorizedCashflowTransaction from '@/models/UncategorizedCashflowTran
const ERRORS = {
TRANSACTION_ALREADY_CATEGORIZED: 'TRANSACTION_ALREADY_CATEGORIZED',
TRANSACTION_ALREADY_EXCLUDED: 'TRANSACTION_ALREADY_EXCLUDED',
TRANSACTION_NOT_EXCLUDED: 'TRANSACTION_NOT_EXCLUDED',
};
export const validateTransactionNotCategorized = (
@@ -14,19 +12,3 @@ export const validateTransactionNotCategorized = (
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED);
}
};
export const validateTransactionNotExcluded = (
transaction: UncategorizedCashflowTransaction
) => {
if (transaction.isExcluded) {
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_EXCLUDED);
}
};
export const validateTransactionShouldBeExcluded = (
transaction: UncategorizedCashflowTransaction
) => {
if (!transaction.isExcluded) {
throw new ServiceError(ERRORS.TRANSACTION_NOT_EXCLUDED);
}
};

View File

@@ -1,7 +1,6 @@
import { Inject, Service } from 'typedi';
import * as R from 'ramda';
import moment from 'moment';
import { first, sumBy } from 'lodash';
import { PromisePool } from '@supercharge/promise-pool';
import { GetMatchedTransactionsFilter, MatchedTransactionsPOJO } from './types';
import { GetMatchedTransactionsByExpenses } from './GetMatchedTransactionsByExpenses';
@@ -48,24 +47,21 @@ export class GetMatchedTransactions {
/**
* Retrieves the matched transactions.
* @param {number} tenantId -
* @param {Array<number>} uncategorizedTransactionIds - Uncategorized transactions ids.
* @param {GetMatchedTransactionsFilter} filter -
* @returns {Promise<MatchedTransactionsPOJO>}
*/
public async getMatchedTransactions(
tenantId: number,
uncategorizedTransactionIds: Array<number>,
uncategorizedTransactionId: number,
filter: GetMatchedTransactionsFilter
): Promise<MatchedTransactionsPOJO> {
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
const uncategorizedTransactions =
const uncategorizedTransaction =
await UncategorizedCashflowTransaction.query()
.whereIn('id', uncategorizedTransactionIds)
.findById(uncategorizedTransactionId)
.throwIfNotFound();
const totalPending = Math.abs(sumBy(uncategorizedTransactions, 'amount'));
const filtered = filter.transactionType
? this.registered.filter((item) => item.type === filter.transactionType)
: this.registered;
@@ -75,14 +71,14 @@ export class GetMatchedTransactions {
.process(async ({ type, service }) => {
return service.getMatchedTransactions(tenantId, filter);
});
const { perfectMatches, possibleMatches } = this.groupMatchedResults(
uncategorizedTransactions,
uncategorizedTransaction,
matchedTransactions
);
return {
perfectMatches,
possibleMatches,
totalPending,
};
}
@@ -94,20 +90,20 @@ export class GetMatchedTransactions {
* @returns {MatchedTransactionsPOJO}
*/
private groupMatchedResults(
uncategorizedTransactions: Array<any>,
uncategorizedTransaction,
matchedTransactions
): MatchedTransactionsPOJO {
const results = R.compose(R.flatten)(matchedTransactions?.results);
const firstUncategorized = first(uncategorizedTransactions);
const amount = sumBy(uncategorizedTransactions, 'amount');
const date = firstUncategorized.date;
// Sort the results based on amount, date, and transaction type
const closestResullts = sortClosestMatchTransactions(amount, date, results);
const closestResullts = sortClosestMatchTransactions(
uncategorizedTransaction,
results
);
const perfectMatches = R.filter(
(match) =>
match.amount === amount && moment(match.date).isSame(date, 'day'),
match.amount === uncategorizedTransaction.amount &&
moment(match.date).isSame(uncategorizedTransaction.date, 'day'),
closestResullts
);
const possibleMatches = R.difference(closestResullts, perfectMatches);

View File

@@ -7,7 +7,6 @@ import {
MatchedTransactionsPOJO,
} from './types';
import { Inject, Service } from 'typedi';
import PromisePool from '@supercharge/promise-pool';
export abstract class GetMatchedTransactionsByType {
@Inject()
@@ -44,28 +43,24 @@ export abstract class GetMatchedTransactionsByType {
}
/**
* Creates the common matched transaction.
*
* @param {number} tenantId
* @param {Array<number>} uncategorizedTransactionIds
* @param {number} uncategorizedTransactionId
* @param {IMatchTransactionDTO} matchTransactionDTO
* @param {Knex.Transaction} trx
*/
public async createMatchedTransaction(
tenantId: number,
uncategorizedTransactionIds: Array<number>,
uncategorizedTransactionId: number,
matchTransactionDTO: IMatchTransactionDTO,
trx?: Knex.Transaction
) {
const { MatchedBankTransaction } = this.tenancy.models(tenantId);
await PromisePool.withConcurrency(2)
.for(uncategorizedTransactionIds)
.process(async (uncategorizedTransactionId) => {
await MatchedBankTransaction.query(trx).insert({
uncategorizedTransactionId,
referenceType: matchTransactionDTO.referenceType,
referenceId: matchTransactionDTO.referenceId,
});
});
await MatchedBankTransaction.query(trx).insert({
uncategorizedTransactionId,
referenceType: matchTransactionDTO.referenceType,
referenceId: matchTransactionDTO.referenceId,
});
}
}

View File

@@ -2,7 +2,7 @@ import { Inject, Service } from 'typedi';
import { GetMatchedTransactions } from './GetMatchedTransactions';
import { MatchBankTransactions } from './MatchTransactions';
import { UnmatchMatchedBankTransaction } from './UnmatchMatchedTransaction';
import { GetMatchedTransactionsFilter, IMatchTransactionDTO } from './types';
import { GetMatchedTransactionsFilter, IMatchTransactionsDTO } from './types';
@Service()
export class MatchBankTransactionsApplication {
@@ -23,12 +23,12 @@ export class MatchBankTransactionsApplication {
*/
public getMatchedTransactions(
tenantId: number,
uncategorizedTransactionsIds: Array<number>,
uncategorizedTransactionId: number,
filter: GetMatchedTransactionsFilter
) {
return this.getMatchedTransactionsService.getMatchedTransactions(
tenantId,
uncategorizedTransactionsIds,
uncategorizedTransactionId,
filter
);
}
@@ -42,13 +42,13 @@ export class MatchBankTransactionsApplication {
*/
public matchTransaction(
tenantId: number,
uncategorizedTransactionId: number | Array<number>,
matchedTransactions: Array<IMatchTransactionDTO>
uncategorizedTransactionId: number,
matchTransactionsDTO: IMatchTransactionsDTO
): Promise<void> {
return this.matchTransactionService.matchTransaction(
tenantId,
uncategorizedTransactionId,
matchedTransactions
matchTransactionsDTO
);
}

View File

@@ -1,4 +1,4 @@
import { castArray } from 'lodash';
import { isEmpty } from 'lodash';
import { Knex } from 'knex';
import { Inject, Service } from 'typedi';
import { PromisePool } from '@supercharge/promise-pool';
@@ -10,16 +10,11 @@ import {
ERRORS,
IBankTransactionMatchedEventPayload,
IBankTransactionMatchingEventPayload,
IMatchTransactionDTO,
IMatchTransactionsDTO,
} from './types';
import { MatchTransactionsTypes } from './MatchTransactionsTypes';
import { ServiceError } from '@/exceptions';
import {
sumMatchTranasctions,
sumUncategorizedTransactions,
validateUncategorizedTransactionsExcluded,
validateUncategorizedTransactionsNotMatched,
} from './_utils';
import { sumMatchTranasctions } from './_utils';
@Service()
export class MatchBankTransactions {
@@ -44,25 +39,27 @@ export class MatchBankTransactions {
*/
async validate(
tenantId: number,
uncategorizedTransactionId: number | Array<number>,
matchedTransactions: Array<IMatchTransactionDTO>
uncategorizedTransactionId: number,
matchTransactionsDTO: IMatchTransactionsDTO
) {
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
const uncategorizedTransactionIds = castArray(uncategorizedTransactionId);
const { matchedTransactions } = matchTransactionsDTO;
// Validates the uncategorized transaction existance.
const uncategorizedTransactions =
const uncategorizedTransaction =
await UncategorizedCashflowTransaction.query()
.whereIn('id', uncategorizedTransactionIds)
.findById(uncategorizedTransactionId)
.withGraphFetched('matchedBankTransactions')
.throwIfNotFound();
// Validates the uncategorized transaction is not already matched.
validateUncategorizedTransactionsNotMatched(uncategorizedTransactions);
if (!isEmpty(uncategorizedTransaction.matchedBankTransactions)) {
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_MATCHED);
}
// Validate the uncategorized transaction is not excluded.
validateUncategorizedTransactionsExcluded(uncategorizedTransactions);
if (uncategorizedTransaction.excluded) {
throw new ServiceError(ERRORS.CANNOT_MATCH_EXCLUDED_TRANSACTION);
}
// Validates the given matched transaction.
const validateMatchedTransaction = async (matchedTransaction) => {
const getMatchedTransactionsService =
@@ -97,12 +94,9 @@ export class MatchBankTransactions {
const totalMatchedTranasctions = sumMatchTranasctions(
validatationResult.results
);
const totalUncategorizedTransactions = sumUncategorizedTransactions(
uncategorizedTransactions
);
// Validates the total given matching transcations whether is not equal
// uncategorized transaction amount.
if (totalUncategorizedTransactions !== totalMatchedTranasctions) {
if (totalMatchedTranasctions !== uncategorizedTransaction.amount) {
throw new ServiceError(ERRORS.TOTAL_MATCHING_TRANSACTIONS_INVALID);
}
}
@@ -115,23 +109,23 @@ export class MatchBankTransactions {
*/
public async matchTransaction(
tenantId: number,
uncategorizedTransactionId: number | Array<number>,
matchedTransactions: Array<IMatchTransactionDTO>
uncategorizedTransactionId: number,
matchTransactionsDTO: IMatchTransactionsDTO
): Promise<void> {
const uncategorizedTransactionIds = castArray(uncategorizedTransactionId);
const { matchedTransactions } = matchTransactionsDTO;
// Validates the given matching transactions DTO.
await this.validate(
tenantId,
uncategorizedTransactionIds,
matchedTransactions
uncategorizedTransactionId,
matchTransactionsDTO
);
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
// Triggers the event `onBankTransactionMatching`.
await this.eventPublisher.emitAsync(events.bankMatch.onMatching, {
tenantId,
uncategorizedTransactionIds,
matchedTransactions,
uncategorizedTransactionId,
matchTransactionsDTO,
trx,
} as IBankTransactionMatchingEventPayload);
@@ -145,16 +139,17 @@ export class MatchBankTransactions {
);
await getMatchedTransactionsService.createMatchedTransaction(
tenantId,
uncategorizedTransactionIds,
uncategorizedTransactionId,
matchedTransaction,
trx
);
});
// Triggers the event `onBankTransactionMatched`.
await this.eventPublisher.emitAsync(events.bankMatch.onMatched, {
tenantId,
uncategorizedTransactionIds,
matchedTransactions,
uncategorizedTransactionId,
matchTransactionsDTO,
trx,
} as IBankTransactionMatchedEventPayload);
});

View File

@@ -1,23 +1,22 @@
import moment from 'moment';
import * as R from 'ramda';
import UncategorizedCashflowTransaction from '@/models/UncategorizedCashflowTransaction';
import { ERRORS, MatchedTransactionPOJO } from './types';
import { isEmpty, sumBy } from 'lodash';
import { ServiceError } from '@/exceptions';
import { MatchedTransactionPOJO } from './types';
export const sortClosestMatchTransactions = (
amount: number,
date: Date,
uncategorizedTransaction: UncategorizedCashflowTransaction,
matches: MatchedTransactionPOJO[]
) => {
return R.sortWith([
// Sort by amount difference (closest to uncategorized transaction amount first)
R.ascend((match: MatchedTransactionPOJO) =>
Math.abs(match.amount - amount)
Math.abs(match.amount - uncategorizedTransaction.amount)
),
// Sort by date difference (closest to uncategorized transaction date first)
R.ascend((match: MatchedTransactionPOJO) =>
Math.abs(moment(match.date).diff(moment(date), 'days'))
Math.abs(
moment(match.date).diff(moment(uncategorizedTransaction.date), 'days')
)
),
])(matches);
};
@@ -30,36 +29,3 @@ export const sumMatchTranasctions = (transactions: Array<any>) => {
0
);
};
export const sumUncategorizedTransactions = (
uncategorizedTransactions: Array<any>
) => {
return sumBy(uncategorizedTransactions, 'amount');
};
export const validateUncategorizedTransactionsNotMatched = (
uncategorizedTransactions: any
) => {
const matchedTransactions = uncategorizedTransactions.filter(
(trans) => !isEmpty(trans.matchedBankTransactions)
);
//
if (matchedTransactions.length > 0) {
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_MATCHED, '', {
matchedTransactionsIds: matchedTransactions?.map((m) => m.id),
});
}
};
export const validateUncategorizedTransactionsExcluded = (
uncategorizedTransactions: any
) => {
const excludedTransactions = uncategorizedTransactions.filter(
(trans) => trans.excluded
);
if (excludedTransactions.length > 0) {
throw new ServiceError(ERRORS.CANNOT_MATCH_EXCLUDED_TRANSACTION, '', {
excludedTransactionsIds: excludedTransactions.map((e) => e.id),
});
}
};

View File

@@ -5,7 +5,6 @@ import {
IBankTransactionUnmatchedEventPayload,
} from '../types';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import PromisePool from '@supercharge/promise-pool';
@Service()
export class DecrementUncategorizedTransactionOnMatching {
@@ -31,24 +30,18 @@ export class DecrementUncategorizedTransactionOnMatching {
*/
public async decrementUnCategorizedTransactionsOnMatching({
tenantId,
uncategorizedTransactionIds,
uncategorizedTransactionId,
trx,
}: IBankTransactionMatchedEventPayload) {
const { UncategorizedCashflowTransaction, Account } =
this.tenancy.models(tenantId);
const uncategorizedTransactions =
await UncategorizedCashflowTransaction.query().whereIn(
'id',
uncategorizedTransactionIds
);
await PromisePool.withConcurrency(1)
.for(uncategorizedTransactions)
.process(async (transaction) => {
await Account.query(trx)
.findById(transaction.accountId)
.decrement('uncategorizedTransactions', 1);
});
const transaction = await UncategorizedCashflowTransaction.query().findById(
uncategorizedTransactionId
);
await Account.query(trx)
.findById(transaction.accountId)
.decrement('uncategorizedTransactions', 1);
}
/**

View File

@@ -2,15 +2,15 @@ import { Knex } from 'knex';
export interface IBankTransactionMatchingEventPayload {
tenantId: number;
uncategorizedTransactionIds: Array<number>;
matchedTransactions: Array<IMatchTransactionDTO>;
uncategorizedTransactionId: number;
matchTransactionsDTO: IMatchTransactionsDTO;
trx?: Knex.Transaction;
}
export interface IBankTransactionMatchedEventPayload {
tenantId: number;
uncategorizedTransactionIds: Array<number>;
matchedTransactions: Array<IMatchTransactionDTO>;
uncategorizedTransactionId: number;
matchTransactionsDTO: IMatchTransactionsDTO;
trx?: Knex.Transaction;
}
@@ -32,7 +32,6 @@ export interface IMatchTransactionDTO {
}
export interface IMatchTransactionsDTO {
uncategorizedTransactionIds: Array<number>;
matchedTransactions: Array<IMatchTransactionDTO>;
}
@@ -58,7 +57,6 @@ export interface MatchedTransactionPOJO {
export type MatchedTransactionsPOJO = {
perfectMatches: Array<MatchedTransactionPOJO>;
possibleMatches: Array<MatchedTransactionPOJO>;
totalPending: number;
};
export const ERRORS = {

View File

@@ -1,15 +1,11 @@
import { Inject, Service } from 'typedi';
import { PlaidUpdateTransactions } from './PlaidUpdateTransactions';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@Service()
export class PlaidWebooks {
@Inject()
private updateTransactionsService: PlaidUpdateTransactions;
@Inject()
private tenancy: HasTenancyService;
/**
* Listens to Plaid webhooks
* @param {number} tenantId - Tenant Id.
@@ -65,7 +61,7 @@ export class PlaidWebooks {
plaidItemId: string
): void {
console.log(
`PLAID WEBHOOK: TRANSACTIONS: ${webhookCode}: Plaid_item_id ${plaidItemId}: ${additionalInfo}`
`WEBHOOK: TRANSACTIONS: ${webhookCode}: Plaid_item_id ${plaidItemId}: ${additionalInfo}`
);
}
@@ -82,21 +78,8 @@ export class PlaidWebooks {
plaidItemId: string,
webhookCode: string
): Promise<void> {
const { PlaidItem } = this.tenancy.models(tenantId);
const plaidItem = await PlaidItem.query()
.findById(plaidItemId)
.throwIfNotFound();
switch (webhookCode) {
case 'SYNC_UPDATES_AVAILABLE': {
if (plaidItem.isPaused) {
this.serverLogAndEmitSocket(
'Plaid item syncing is paused.',
webhookCode,
plaidItemId
);
return;
}
// Fired when new transactions data becomes available.
const { addedCount, modifiedCount, removedCount } =
await this.updateTransactionsService.updateTransactions(

View File

@@ -35,8 +35,7 @@ export class RecognizeSyncedBankTranasctions extends EventSubscriber {
runAfterTransaction(trx, async () => {
await this.recognizeTranasctionsService.recognizeTransactions(
tenantId,
null,
{ batch }
batch
);
});
};

View File

@@ -1,45 +0,0 @@
import { Inject, Service } from 'typedi';
import { castArray, first, uniq } from 'lodash';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import { GetAutofillCategorizeTransctionTransformer } from './GetAutofillCategorizeTransactionTransformer';
@Service()
export class GetAutofillCategorizeTransaction {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private transformer: TransformerInjectable;
/**
* Retrieves the autofill values of categorize transactions form.
* @param {number} tenantId - Tenant id.
* @param {Array<number> | number} uncategorizeTransactionsId - Uncategorized transactions ids.
*/
public async getAutofillCategorizeTransaction(
tenantId: number,
uncategorizeTransactionsId: Array<number> | number
) {
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
const uncategorizeTransactionsIds = uniq(
castArray(uncategorizeTransactionsId)
);
const uncategorizedTransactions =
await UncategorizedCashflowTransaction.query()
.whereIn('id', uncategorizeTransactionsIds)
.withGraphFetched('recognizedTransaction.assignAccount')
.withGraphFetched('recognizedTransaction.bankRule')
.throwIfNotFound();
return this.transformer.transform(
tenantId,
{},
new GetAutofillCategorizeTransctionTransformer(),
{
uncategorizedTransactions,
firstUncategorizedTransaction: first(uncategorizedTransactions),
}
);
}
}

View File

@@ -1,176 +0,0 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { sumBy } from 'lodash';
export class GetAutofillCategorizeTransctionTransformer extends Transformer {
/**
* Included attributes to the object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return [
'amount',
'formattedAmount',
'isRecognized',
'date',
'formattedDate',
'creditAccountId',
'debitAccountId',
'referenceNo',
'transactionType',
'recognizedByRuleId',
'recognizedByRuleName',
'isWithdrawalTransaction',
'isDepositTransaction',
];
};
/**
* Detarmines whether the transaction is recognized.
* @returns {boolean}
*/
public isRecognized() {
return !!this.options.firstUncategorizedTransaction?.recognizedTransaction;
}
/**
* Retrieves the total amount of uncategorized transactions.
* @returns {number}
*/
public amount() {
return sumBy(this.options.uncategorizedTransactions, 'amount');
}
/**
* Retrieves the formatted total amount of uncategorized transactions.
* @returns {string}
*/
public formattedAmount() {
return this.formatNumber(this.amount(), {
currencyCode: 'USD',
money: true,
});
}
/**
* Detarmines whether the transaction is deposit.
* @returns {boolean}
*/
public isDepositTransaction() {
const amount = this.amount();
return amount > 0;
}
/**
* Detarmines whether the transaction is withdrawal.
* @returns {boolean}
*/
public isWithdrawalTransaction() {
const amount = this.amount();
return amount < 0;
}
/**
*
* @param {string}
*/
public date() {
return this.options.firstUncategorizedTransaction?.date || null;
}
/**
* Retrieves the formatted date of uncategorized transaction.
* @returns {string}
*/
public formattedDate() {
return this.formatDate(this.date());
}
/**
*
* @param {string}
*/
public referenceNo() {
return this.options.firstUncategorizedTransaction?.referenceNo || null;
}
/**
*
* @returns {number}
*/
public creditAccountId() {
return (
this.options.firstUncategorizedTransaction?.recognizedTransaction
?.assignedAccountId || null
);
}
/**
*
* @returns {number}
*/
public debitAccountId() {
return this.options.firstUncategorizedTransaction?.accountId || null;
}
/**
* Retrieves the assigned category of recognized transaction, if is not recognized
* returns the default transaction type depends on the transaction normal.
* @returns {string}
*/
public transactionType() {
const assignedCategory =
this.options.firstUncategorizedTransaction?.recognizedTransaction
?.assignedCategory;
return (
assignedCategory ||
(this.isDepositTransaction() ? 'other_income' : 'other_expense')
);
}
/**
*
* @returns {string}
*/
public payee() {
return (
this.options.firstUncategorizedTransaction?.recognizedTransaction
?.assignedPayee || null
);
}
/**
*
* @returns {string}
*/
public memo() {
return (
this.options.firstUncategorizedTransaction?.recognizedTransaction
?.assignedMemo || null
);
}
/**
* Retrieves the rule id the transaction recongized by.
* @returns {string}
*/
public recognizedByRuleId() {
return (
this.options.firstUncategorizedTransaction?.recognizedTransaction
?.bankRuleId || null
);
}
/**
* Retrieves the rule name the transaction recongized by.
* @returns {string}
*/
public recognizedByRuleName() {
return (
this.options.firstUncategorizedTransaction?.recognizedTransaction
?.bankRule?.name || null
);
}
}

View File

@@ -1,13 +1,11 @@
import { Knex } from 'knex';
import { Inject, Service } from 'typedi';
import { castArray, isEmpty } from 'lodash';
import UncategorizedCashflowTransaction from '@/models/UncategorizedCashflowTransaction';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { transformToMapBy } from '@/utils';
import { Inject, Service } from 'typedi';
import { PromisePool } from '@supercharge/promise-pool';
import { BankRule } from '@/models/BankRule';
import { bankRulesMatchTransaction } from './_utils';
import { RecognizeTransactionsCriteria } from './_types';
@Service()
export class RecognizeTranasctionsService {
@@ -50,42 +48,24 @@ export class RecognizeTranasctionsService {
/**
* Regonized the uncategorized transactions.
* @param {number} tenantId -
* @param {number|Array<number>} ruleId - The target rule id/ids.
* @param {RecognizeTransactionsCriteria}
* @param {Knex.Transaction} trx -
*/
public async recognizeTransactions(
tenantId: number,
ruleId?: number | Array<number>,
transactionsCriteria?: RecognizeTransactionsCriteria,
batch: string = '',
trx?: Knex.Transaction
) {
const { UncategorizedCashflowTransaction, BankRule } =
this.tenancy.models(tenantId);
const uncategorizedTranasctions =
await UncategorizedCashflowTransaction.query(trx).onBuild((query) => {
query.modify('notRecognized');
query.modify('notCategorized');
await UncategorizedCashflowTransaction.query().onBuild((query) => {
query.where('recognized_transaction_id', null);
query.where('categorized', false);
// Filter the transactions based on the given criteria.
if (transactionsCriteria?.batch) {
query.where('batch', transactionsCriteria.batch);
}
if (transactionsCriteria?.accountId) {
query.where('accountId', transactionsCriteria.accountId);
}
if (batch) query.where('batch', batch);
});
const bankRules = await BankRule.query(trx).onBuild((q) => {
const rulesIds = castArray(ruleId);
if (!isEmpty(rulesIds)) {
q.whereIn('id', rulesIds);
}
q.withGraphFetched('conditions');
});
const bankRules = await BankRule.query().withGraphFetched('conditions');
const bankRulesByAccountId = transformToMapBy(
bankRules,
'applyIfAccountId'

View File

@@ -1,5 +1,5 @@
import Container, { Service } from 'typedi';
import { RecognizeTranasctionsService } from '../RecognizeTranasctionsService';
import { RecognizeTranasctionsService } from './RecognizeTranasctionsService';
@Service()
export class RegonizeTransactionsJob {
@@ -18,15 +18,11 @@ export class RegonizeTransactionsJob {
* Triggers sending invoice mail.
*/
private handler = async (job, done: Function) => {
const { tenantId, ruleId, transactionsCriteria } = job.attrs.data;
const { tenantId, batch } = job.attrs.data;
const regonizeTransactions = Container.get(RecognizeTranasctionsService);
try {
await regonizeTransactions.recognizeTransactions(
tenantId,
ruleId,
transactionsCriteria
);
await regonizeTransactions.recognizeTransactions(tenantId, batch);
done();
} catch (error) {
console.log(error);

View File

@@ -1,72 +0,0 @@
import { Inject, Service } from 'typedi';
import { castArray } from 'lodash';
import { Knex } from 'knex';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork';
import { RevertRecognizedTransactionsCriteria } from './_types';
@Service()
export class RevertRecognizedTransactions {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private uow: UnitOfWork;
/**
* Revert and unlinks the recognized transactions based on the given bank rule
* and transactions criteria..
* @param {number} tenantId - Tenant id.
* @param {number|Array<number>} bankRuleId - Bank rule id.
* @param {RevertRecognizedTransactionsCriteria} transactionsCriteria -
* @param {Knex.Transaction} trx - Knex transaction.
* @returns {Promise<void>}
*/
public async revertRecognizedTransactions(
tenantId: number,
ruleId?: number | Array<number>,
transactionsCriteria?: RevertRecognizedTransactionsCriteria,
trx?: Knex.Transaction
): Promise<void> {
const { UncategorizedCashflowTransaction, RecognizedBankTransaction } =
this.tenancy.models(tenantId);
const rulesIds = castArray(ruleId);
return this.uow.withTransaction(
tenantId,
async (trx: Knex.Transaction) => {
// Retrieves all the recognized transactions of the banbk rule.
const uncategorizedTransactions =
await UncategorizedCashflowTransaction.query(trx).onBuild((q) => {
q.withGraphJoined('recognizedTransaction');
q.whereNotNull('recognizedTransaction.id');
if (rulesIds.length > 0) {
q.whereIn('recognizedTransaction.bankRuleId', rulesIds);
}
if (transactionsCriteria?.accountId) {
q.where('accountId', transactionsCriteria.accountId);
}
if (transactionsCriteria?.batch) {
q.where('batch', transactionsCriteria.batch);
}
});
const uncategorizedTransactionIds = uncategorizedTransactions.map(
(r) => r.id
);
// Unlink the recongized transactions out of uncategorized transactions.
await UncategorizedCashflowTransaction.query(trx)
.whereIn('id', uncategorizedTransactionIds)
.patch({
recognizedTransactionId: null,
});
// Delete the recognized bank transactions that assocaited to bank rule.
await RecognizedBankTransaction.query(trx)
.whereIn('uncategorizedTransactionId', uncategorizedTransactionIds)
.delete();
},
trx
);
}
}

View File

@@ -1,11 +0,0 @@
export interface RevertRecognizedTransactionsCriteria {
batch?: string;
accountId?: number;
}
export interface RecognizeTransactionsCriteria {
batch?: string;
accountId?: number;
}

View File

@@ -1,4 +1,3 @@
import { lowerCase } from 'lodash';
import UncategorizedCashflowTransaction from '@/models/UncategorizedCashflowTransaction';
import {
BankRuleApplyIfTransactionType,
@@ -52,15 +51,12 @@ const matchNumberCondition = (
const matchTextCondition = (
transaction: UncategorizedCashflowTransaction,
condition: IBankRuleCondition
): boolean => {
) => {
switch (condition.comparator) {
case BankRuleConditionComparator.Equals:
return transaction[condition.field] === condition.value;
case BankRuleConditionComparator.Contains:
const fieldValue = lowerCase(transaction[condition.field]);
const conditionValue = lowerCase(condition.value);
return fieldValue.includes(conditionValue);
return transaction[condition.field]?.includes(condition.value.toString());
case BankRuleConditionComparator.NotContain:
return !transaction[condition.field]?.includes(
condition.value.toString()
@@ -105,4 +101,4 @@ const determineFieldType = (field: string): string => {
default:
return 'unknown';
}
};
};

View File

@@ -41,10 +41,14 @@ export class TriggerRecognizedTransactions {
*/
private async recognizedTransactionsOnRuleCreated({
tenantId,
bankRule,
createRuleDTO,
}: IBankRuleEventCreatedPayload) {
const payload = { tenantId, ruleId: bankRule.id };
const payload = { tenantId };
// Cannot run recognition if the option is not enabled.
if (createRuleDTO.recognition) {
return;
}
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
}
@@ -55,14 +59,14 @@ export class TriggerRecognizedTransactions {
private async recognizedTransactionsOnRuleEdited({
tenantId,
editRuleDTO,
ruleId,
}: IBankRuleEventEditedPayload) {
const payload = { tenantId, ruleId };
const payload = { tenantId };
await this.agenda.now(
'rerecognize-uncategorized-transactions-job',
payload
);
// Cannot run recognition if the option is not enabled.
if (!editRuleDTO.recognition) {
return;
}
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
}
/**
@@ -71,13 +75,9 @@ export class TriggerRecognizedTransactions {
*/
private async recognizedTransactionsOnRuleDeleted({
tenantId,
ruleId,
}: IBankRuleEventDeletedPayload) {
const payload = { tenantId, ruleId };
await this.agenda.now(
'revert-recognized-uncategorized-transactions-job',
payload
);
const payload = { tenantId };
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
}
/**
@@ -91,7 +91,7 @@ export class TriggerRecognizedTransactions {
}: IImportFileCommitedEventPayload) {
const importFile = await Import.query().findOne({ importId });
const batch = importFile.paramsParsed.batch;
const payload = { tenantId, transactionsCriteria: { batch } };
const payload = { tenantId, batch };
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
}

View File

@@ -1,45 +0,0 @@
import Container, { Service } from 'typedi';
import { RecognizeTranasctionsService } from '../RecognizeTranasctionsService';
import { RevertRecognizedTransactions } from '../RevertRecognizedTransactions';
@Service()
export class ReregonizeTransactionsJob {
/**
* Constructor method.
*/
constructor(agenda) {
agenda.define(
'rerecognize-uncategorized-transactions-job',
{ priority: 'high', concurrency: 2 },
this.handler
);
}
/**
* Triggers sending invoice mail.
*/
private handler = async (job, done: Function) => {
const { tenantId, ruleId, transactionsCriteria } = job.attrs.data;
const regonizeTransactions = Container.get(RecognizeTranasctionsService);
const revertRegonizedTransactions = Container.get(
RevertRecognizedTransactions
);
try {
await revertRegonizedTransactions.revertRecognizedTransactions(
tenantId,
ruleId,
transactionsCriteria
);
await regonizeTransactions.recognizeTransactions(
tenantId,
ruleId,
transactionsCriteria
);
done();
} catch (error) {
console.log(error);
done(error);
}
};
}

View File

@@ -1,38 +0,0 @@
import Container, { Service } from 'typedi';
import { RevertRecognizedTransactions } from '../RevertRecognizedTransactions';
@Service()
export class RevertRegonizeTransactionsJob {
/**
* Constructor method.
*/
constructor(agenda) {
agenda.define(
'revert-recognized-uncategorized-transactions-job',
{ priority: 'high', concurrency: 2 },
this.handler
);
}
/**
* Triggers sending invoice mail.
*/
private handler = async (job, done: Function) => {
const { tenantId, ruleId, transactionsCriteria } = job.attrs.data;
const revertRegonizedTransactions = Container.get(
RevertRecognizedTransactions
);
try {
await revertRegonizedTransactions.revertRecognizedTransactions(
tenantId,
ruleId,
transactionsCriteria
);
done();
} catch (error) {
console.log(error);
done(error);
}
};
}

View File

@@ -62,7 +62,6 @@ export class CreateBankRuleService {
await this.eventPublisher.emitAsync(events.bankRules.onCreated, {
tenantId,
createRuleDTO,
bankRule,
trx,
} as IBankRuleEventCreatedPayload);

View File

@@ -64,10 +64,9 @@ export class EditBankRuleService {
} as IBankRuleEventEditingPayload);
// Updates the given bank rule.
await BankRule.query(trx).upsertGraphAndFetch({
...tranformDTO,
id: ruleId,
});
await BankRule.query(trx)
.findById(ruleId)
.patch({ ...tranformDTO });
// Triggers `onBankRuleEdited` event.
await this.eventPublisher.emitAsync(events.bankRules.onEdited, {

View File

@@ -0,0 +1,54 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork';
@Service()
export class UnlinkBankRuleRecognizedTransactions {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private uow: UnitOfWork;
/**
* Unlinks the given bank rule out of recognized transactions.
* @param {number} tenantId - Tenant id.
* @param {number} bankRuleId - Bank rule id.
* @param {Knex.Transaction} trx - Knex transaction.
* @returns {Promise<void>}
*/
public async unlinkBankRuleOutRecognizedTransactions(
tenantId: number,
bankRuleId: number,
trx?: Knex.Transaction
): Promise<void> {
const { UncategorizedCashflowTransaction, RecognizedBankTransaction } =
this.tenancy.models(tenantId);
return this.uow.withTransaction(
tenantId,
async (trx: Knex.Transaction) => {
// Retrieves all the recognized transactions of the banbk rule.
const recognizedTransactions = await RecognizedBankTransaction.query(
trx
).where('bankRuleId', bankRuleId);
const uncategorizedTransactionIds = recognizedTransactions.map(
(r) => r.uncategorizedTransactionId
);
// Unlink the recongized transactions out of uncategorized transactions.
await UncategorizedCashflowTransaction.query(trx)
.whereIn('id', uncategorizedTransactionIds)
.patch({
recognizedTransactionId: null,
});
// Delete the recognized bank transactions that assocaited to bank rule.
await RecognizedBankTransaction.query(trx)
.where({ bankRuleId })
.delete();
},
trx
);
}
}

View File

@@ -1,12 +1,12 @@
import { Inject, Service } from 'typedi';
import events from '@/subscribers/events';
import { UnlinkBankRuleRecognizedTransactions } from '../UnlinkBankRuleRecognizedTransactions';
import { IBankRuleEventDeletingPayload } from '../types';
import { RevertRecognizedTransactions } from '../../RegonizeTranasctions/RevertRecognizedTransactions';
@Service()
export class UnlinkBankRuleOnDeleteBankRule {
@Inject()
private revertRecognizedTransactionsService: RevertRecognizedTransactions;
private unlinkBankRule: UnlinkBankRuleRecognizedTransactions;
/**
* Constructor method.
@@ -26,7 +26,7 @@ export class UnlinkBankRuleOnDeleteBankRule {
tenantId,
ruleId,
}: IBankRuleEventDeletingPayload) {
await this.revertRecognizedTransactionsService.revertRecognizedTransactions(
await this.unlinkBankRule.unlinkBankRuleOutRecognizedTransactions(
tenantId,
ruleId
);

View File

@@ -16,7 +16,7 @@ export interface IBankRuleCondition {
id?: number;
field: BankRuleConditionField;
comparator: BankRuleConditionComparator;
value: string;
value: number;
}
export enum BankRuleConditionType {
@@ -30,7 +30,6 @@ export enum BankRuleApplyIfTransactionType {
}
export interface IBankRule {
id?: number;
name: string;
order?: number;
applyIfAccountId: number;
@@ -72,6 +71,8 @@ export interface IBankRuleCommonDTO {
assignAccountId: number;
assignPayee?: string;
assignMemo?: string;
recognition?: boolean;
}
export interface ICreateBankRuleDTO extends IBankRuleCommonDTO {}
@@ -85,7 +86,6 @@ export interface IBankRuleEventCreatingPayload {
export interface IBankRuleEventCreatedPayload {
tenantId: number;
createRuleDTO: ICreateBankRuleDTO;
bankRule: IBankRule;
trx?: Knex.Transaction;
}

View File

@@ -164,12 +164,12 @@ export class CashflowApplication {
*/
public categorizeTransaction(
tenantId: number,
uncategorizeTransactionIds: Array<number>,
cashflowTransactionId: number,
categorizeDTO: ICategorizeCashflowTransactioDTO
) {
return this.categorizeTransactionService.categorize(
tenantId,
uncategorizeTransactionIds,
cashflowTransactionId,
categorizeDTO
);
}

View File

@@ -1,6 +1,4 @@
import { Inject, Service } from 'typedi';
import { castArray } from 'lodash';
import { Knex } from 'knex';
import HasTenancyService from '../Tenancy/TenancyService';
import events from '@/subscribers/events';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
@@ -10,12 +8,12 @@ import {
ICashflowTransactionUncategorizingPayload,
ICategorizeCashflowTransactioDTO,
} from '@/interfaces';
import {
transformCategorizeTransToCashflow,
validateUncategorizedTransactionsNotExcluded,
} from './utils';
import { Knex } from 'knex';
import { transformCategorizeTransToCashflow } from './utils';
import { CommandCashflowValidator } from './CommandCasflowValidator';
import NewCashflowTransactionService from './NewCashflowTransactionService';
import { ServiceError } from '@/exceptions';
import { ERRORS } from './constants';
@Service()
export class CategorizeCashflowTransaction {
@@ -41,29 +39,27 @@ export class CategorizeCashflowTransaction {
*/
public async categorize(
tenantId: number,
uncategorizedTransactionId: number | Array<number>,
uncategorizedTransactionId: number,
categorizeDTO: ICategorizeCashflowTransactioDTO
) {
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
const uncategorizedTransactionIds = castArray(uncategorizedTransactionId);
// Retrieves the uncategorized transaction or throw an error.
const oldUncategorizedTransactions =
await UncategorizedCashflowTransaction.query()
.whereIn('id', uncategorizedTransactionIds)
.throwIfNotFound();
const transaction = await UncategorizedCashflowTransaction.query()
.findById(uncategorizedTransactionId)
.throwIfNotFound();
// Validate cannot categorize excluded transaction.
validateUncategorizedTransactionsNotExcluded(oldUncategorizedTransactions);
if (transaction.excluded) {
throw new ServiceError(ERRORS.CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION);
}
// Validates the transaction shouldn't be categorized before.
this.commandValidators.validateTransactionsShouldNotCategorized(
oldUncategorizedTransactions
);
this.commandValidators.validateTransactionShouldNotCategorized(transaction);
// Validate the uncateogirzed transaction if it's deposit the transaction direction
// should `IN` and the same thing if it's withdrawal the direction should be OUT.
this.commandValidators.validateUncategorizeTransactionType(
oldUncategorizedTransactions,
transaction,
categorizeDTO.transactionType
);
// Edits the cashflow transaction under UOW env.
@@ -73,13 +69,12 @@ export class CategorizeCashflowTransaction {
events.cashflow.onTransactionCategorizing,
{
tenantId,
oldUncategorizedTransactions,
trx,
} as ICashflowTransactionUncategorizingPayload
);
// Transformes the categorize DTO to the cashflow transaction.
const cashflowTransactionDTO = transformCategorizeTransToCashflow(
oldUncategorizedTransactions,
transaction,
categorizeDTO
);
// Creates a new cashflow transaction.
@@ -88,20 +83,15 @@ export class CategorizeCashflowTransaction {
tenantId,
cashflowTransactionDTO
);
// Updates the uncategorized transaction as categorized.
await UncategorizedCashflowTransaction.query(trx)
.whereIn('id', uncategorizedTransactionIds)
.patch({
categorized: true,
categorizeRefType: 'CashflowTransaction',
categorizeRefId: cashflowTransaction.id,
});
// Fetch the new updated uncategorized transactions.
const uncategorizedTransactions =
await UncategorizedCashflowTransaction.query(trx).whereIn(
'id',
uncategorizedTransactionIds
const uncategorizedTransaction =
await UncategorizedCashflowTransaction.query(trx).patchAndFetchById(
uncategorizedTransactionId,
{
categorized: true,
categorizeRefType: 'CashflowTransaction',
categorizeRefId: cashflowTransaction.id,
}
);
// Triggers `onCashflowTransactionCategorized` event.
await this.eventPublisher.emitAsync(
@@ -109,8 +99,7 @@ export class CategorizeCashflowTransaction {
{
tenantId,
cashflowTransaction,
uncategorizedTransactions,
oldUncategorizedTransactions,
uncategorizedTransaction,
categorizeDTO,
trx,
} as ICashflowTransactionCategorizedPayload

View File

@@ -1,5 +1,5 @@
import { Service } from 'typedi';
import { includes, camelCase, upperFirst, sumBy } from 'lodash';
import { includes, camelCase, upperFirst } from 'lodash';
import { IAccount, IUncategorizedCashflowTransaction } from '@/interfaces';
import { getCashflowTransactionType } from './utils';
import { ServiceError } from '@/exceptions';
@@ -68,15 +68,11 @@ export class CommandCashflowValidator {
* Validate the given transcation shouldn't be categorized.
* @param {CashflowTransaction} cashflowTransaction
*/
public validateTransactionsShouldNotCategorized(
cashflowTransactions: Array<IUncategorizedCashflowTransaction>
public validateTransactionShouldNotCategorized(
cashflowTransaction: CashflowTransaction
) {
const categorized = cashflowTransactions.filter((t) => t.categorized);
if (categorized?.length > 0) {
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED, '', {
ids: categorized.map((t) => t.id),
});
if (cashflowTransaction.uncategorize) {
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED);
}
}
@@ -87,19 +83,17 @@ export class CommandCashflowValidator {
* @throws {ServiceError(ERRORS.UNCATEGORIZED_TRANSACTION_TYPE_INVALID)}
*/
public validateUncategorizeTransactionType(
uncategorizeTransactions: Array<IUncategorizedCashflowTransaction>,
uncategorizeTransaction: IUncategorizedCashflowTransaction,
transactionType: string
) {
const amount = sumBy(uncategorizeTransactions, 'amount');
const isDepositTransaction = amount > 0;
const isWithdrawalTransaction = amount <= 0;
const type = getCashflowTransactionType(
transactionType as CASHFLOW_TRANSACTION_TYPE
upperFirst(camelCase(transactionType)) as CASHFLOW_TRANSACTION_TYPE
);
if (
(type.direction === CASHFLOW_DIRECTION.IN && isDepositTransaction) ||
(type.direction === CASHFLOW_DIRECTION.OUT && isWithdrawalTransaction)
(type.direction === CASHFLOW_DIRECTION.IN &&
uncategorizeTransaction.isDepositTransaction) ||
(type.direction === CASHFLOW_DIRECTION.OUT &&
uncategorizeTransaction.isWithdrawalTransaction)
) {
return;
}

View File

@@ -34,7 +34,6 @@ export class GetRecognizedTransactionsService {
q.withGraphFetched('recognizedTransaction.assignAccount');
q.withGraphFetched('recognizedTransaction.bankRule');
q.whereNotNull('recognizedTransactionId');
q.modify('notExcluded');
if (_filter.accountId) {
q.where('accountId', _filter.accountId);

View File

@@ -8,7 +8,6 @@ import {
ICashflowTransactionUncategorizedPayload,
ICashflowTransactionUncategorizingPayload,
} from '@/interfaces';
import { validateTransactionShouldBeCategorized } from './utils';
@Service()
export class UncategorizeCashflowTransaction {
@@ -25,12 +24,11 @@ export class UncategorizeCashflowTransaction {
* Uncategorizes the given cashflow transaction.
* @param {number} tenantId
* @param {number} cashflowTransactionId
* @returns {Promise<Array<number>>}
*/
public async uncategorize(
tenantId: number,
uncategorizedTransactionId: number
): Promise<Array<number>> {
) {
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
const oldUncategorizedTransaction =
@@ -38,22 +36,6 @@ export class UncategorizeCashflowTransaction {
.findById(uncategorizedTransactionId)
.throwIfNotFound();
validateTransactionShouldBeCategorized(oldUncategorizedTransaction);
const associatedUncategorizedTransactions =
await UncategorizedCashflowTransaction.query()
.where('categorizeRefId', oldUncategorizedTransaction.categorizeRefId)
.where(
'categorizeRefType',
oldUncategorizedTransaction.categorizeRefType
);
const oldUncategorizedTransactions = [
oldUncategorizedTransaction,
...associatedUncategorizedTransactions,
];
const oldUncategoirzedTransactionsIds = oldUncategorizedTransactions.map(
(t) => t.id
);
// Updates the transaction under UOW.
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
// Triggers `onTransactionUncategorizing` event.
@@ -61,36 +43,30 @@ export class UncategorizeCashflowTransaction {
events.cashflow.onTransactionUncategorizing,
{
tenantId,
uncategorizedTransactionId,
oldUncategorizedTransactions,
trx,
} as ICashflowTransactionUncategorizingPayload
);
// Removes the ref relation with the related transaction.
await UncategorizedCashflowTransaction.query(trx)
.whereIn('id', oldUncategoirzedTransactionsIds)
.patch({
categorized: false,
categorizeRefId: null,
categorizeRefType: null,
});
const uncategorizedTransactions =
await UncategorizedCashflowTransaction.query(trx).whereIn(
'id',
oldUncategoirzedTransactionsIds
const uncategorizedTransaction =
await UncategorizedCashflowTransaction.query(trx).updateAndFetchById(
uncategorizedTransactionId,
{
categorized: false,
categorizeRefId: null,
categorizeRefType: null,
}
);
// Triggers `onTransactionUncategorized` event.
await this.eventPublisher.emitAsync(
events.cashflow.onTransactionUncategorized,
{
tenantId,
uncategorizedTransactionId,
uncategorizedTransactions,
oldUncategorizedTransactions,
uncategorizedTransaction,
oldUncategorizedTransaction,
trx,
} as ICashflowTransactionUncategorizedPayload
);
return oldUncategoirzedTransactionsIds;
return uncategorizedTransaction;
});
}
}

View File

@@ -16,9 +16,7 @@ export const ERRORS = {
CANNOT_DELETE_TRANSACTION_CONVERTED_FROM_UNCATEGORIZED:
'CANNOT_DELETE_TRANSACTION_CONVERTED_FROM_UNCATEGORIZED',
CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION: 'CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION',
TRANSACTION_NOT_CATEGORIZED: 'TRANSACTION_NOT_CATEGORIZED'
CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION: 'CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION'
};
export enum CASHFLOW_DIRECTION {

View File

@@ -5,7 +5,6 @@ import {
ICashflowTransactionCategorizedPayload,
ICashflowTransactionUncategorizedPayload,
} from '@/interfaces';
import PromisePool from '@supercharge/promise-pool';
@Service()
export class DecrementUncategorizedTransactionOnCategorize {
@@ -35,18 +34,13 @@ export class DecrementUncategorizedTransactionOnCategorize {
*/
public async decrementUnCategorizedTransactionsOnCategorized({
tenantId,
uncategorizedTransactions,
trx
uncategorizedTransaction,
}: ICashflowTransactionCategorizedPayload) {
const { Account } = this.tenancy.models(tenantId);
await PromisePool.withConcurrency(1)
.for(uncategorizedTransactions)
.process(async (uncategorizedTransaction) => {
await Account.query(trx)
.findById(uncategorizedTransaction.accountId)
.decrement('uncategorizedTransactions', 1);
});
await Account.query()
.findById(uncategorizedTransaction.accountId)
.decrement('uncategorizedTransactions', 1);
}
/**
@@ -55,18 +49,13 @@ export class DecrementUncategorizedTransactionOnCategorize {
*/
public async incrementUnCategorizedTransactionsOnUncategorized({
tenantId,
uncategorizedTransactions,
trx
uncategorizedTransaction,
}: ICashflowTransactionUncategorizedPayload) {
const { Account } = this.tenancy.models(tenantId);
await PromisePool.withConcurrency(1)
.for(uncategorizedTransactions)
.process(async (uncategorizedTransaction) => {
await Account.query(trx)
.findById(uncategorizedTransaction.accountId)
.increment('uncategorizedTransactions', 1);
});
await Account.query()
.findById(uncategorizedTransaction.accountId)
.increment('uncategorizedTransactions', 1);
}
/**

View File

@@ -1,10 +1,8 @@
import { Inject, Service } from 'typedi';
import { PromisePool } from '@supercharge/promise-pool';
import events from '@/subscribers/events';
import { ICashflowTransactionUncategorizedPayload } from '@/interfaces';
import { DeleteCashflowTransaction } from '../DeleteCashflowTransactionService';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { ServiceError } from '@/exceptions';
@Service()
export class DeleteCashflowTransactionOnUncategorize {
@@ -27,27 +25,18 @@ export class DeleteCashflowTransactionOnUncategorize {
*/
public async deleteCashflowTransactionOnUncategorize({
tenantId,
oldUncategorizedTransactions,
oldUncategorizedTransaction,
trx,
}: ICashflowTransactionUncategorizedPayload) {
const _oldUncategorizedTransactions = oldUncategorizedTransactions.filter(
(transaction) => transaction.categorizeRefType === 'CashflowTransaction'
);
// Deletes the cashflow transaction.
if (_oldUncategorizedTransactions.length > 0) {
const result = await PromisePool.withConcurrency(1)
.for(_oldUncategorizedTransactions)
.process(async (oldUncategorizedTransaction) => {
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
tenantId,
oldUncategorizedTransaction.categorizeRefId,
trx
);
});
if (result.errors.length > 0) {
throw new ServiceError('SOMETHING_WRONG');
}
if (
oldUncategorizedTransaction.categorizeRefType === 'CashflowTransaction'
) {
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
tenantId,
oldUncategorizedTransaction.categorizeRefId
);
}
}
}

View File

@@ -1,8 +1,7 @@
import { upperFirst, camelCase, first, sum, sumBy } from 'lodash';
import { upperFirst, camelCase } from 'lodash';
import {
CASHFLOW_TRANSACTION_TYPE,
CASHFLOW_TRANSACTION_TYPE_META,
ERRORS,
ICashflowTransactionTypeMeta,
} from './constants';
import {
@@ -10,8 +9,6 @@ import {
ICategorizeCashflowTransactioDTO,
IUncategorizedCashflowTransaction,
} from '@/interfaces';
import { UncategorizeCashflowTransaction } from './UncategorizeCashflowTransaction';
import { ServiceError } from '@/exceptions';
/**
* Ensures the given transaction type to transformed to appropriate format.
@@ -30,9 +27,7 @@ export const transformCashflowTransactionType = (type) => {
export function getCashflowTransactionType(
transactionType: CASHFLOW_TRANSACTION_TYPE
): ICashflowTransactionTypeMeta {
const _transactionType = transformCashflowTransactionType(transactionType);
return CASHFLOW_TRANSACTION_TYPE_META[_transactionType];
return CASHFLOW_TRANSACTION_TYPE_META[transactionType];
}
/**
@@ -51,46 +46,22 @@ export const getCashflowAccountTransactionsTypes = () => {
* @returns {ICashflowNewCommandDTO}
*/
export const transformCategorizeTransToCashflow = (
uncategorizeTransactions: Array<IUncategorizedCashflowTransaction>,
uncategorizeModel: IUncategorizedCashflowTransaction,
categorizeDTO: ICategorizeCashflowTransactioDTO
): ICashflowNewCommandDTO => {
const uncategorizeTransaction = first(uncategorizeTransactions);
const amount = sumBy(uncategorizeTransactions, 'amount');
const amountAbs = Math.abs(amount);
return {
date: categorizeDTO.date,
referenceNo: categorizeDTO.referenceNo,
description: categorizeDTO.description,
cashflowAccountId: uncategorizeTransaction.accountId,
date: uncategorizeModel.date,
referenceNo: categorizeDTO.referenceNo || uncategorizeModel.referenceNo,
description: categorizeDTO.description || uncategorizeModel.description,
cashflowAccountId: uncategorizeModel.accountId,
creditAccountId: categorizeDTO.creditAccountId,
exchangeRate: categorizeDTO.exchangeRate || 1,
currencyCode: categorizeDTO.currencyCode,
amount: amountAbs,
currencyCode: uncategorizeModel.currencyCode,
amount: uncategorizeModel.amount,
transactionNumber: categorizeDTO.transactionNumber,
transactionType: categorizeDTO.transactionType,
uncategorizedTransactionId: uncategorizeModel.id,
branchId: categorizeDTO?.branchId,
publish: true,
};
};
export const validateUncategorizedTransactionsNotExcluded = (
transactions: Array<UncategorizeCashflowTransaction>
) => {
const excluded = transactions.filter((tran) => tran.excluded);
if (excluded?.length > 0) {
throw new ServiceError(ERRORS.CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION, '', {
ids: excluded.map((t) => t.id),
});
}
};
export const validateTransactionShouldBeCategorized = (
uncategorizedTransaction: any
) => {
if (!uncategorizedTransaction.categorized) {
throw new ServiceError(ERRORS.TRANSACTION_NOT_CATEGORIZED);
}
};

View File

@@ -1,9 +1,5 @@
// @ts-nocheck
import React, { forwardRef, Ref } from 'react';
import {
AppShellProvider,
useAppShellContext,
} from './AppContentShellProvider';
import React from 'react';
import { AppShellProvider, useAppShellContext } from './AppContentShellProvider';
import { Box, BoxProps } from '../../Layout';
import styles from './AppContentShell.module.scss';
@@ -16,73 +12,50 @@ interface AppContentShellProps {
hideMain?: boolean;
}
export const AppContentShell = forwardRef(
(
{
asideProps,
mainProps,
topbarOffset = 0,
hideAside = false,
hideMain = false,
...restProps
}: AppContentShellProps,
ref: Ref<HTMLDivElement>,
) => {
return (
<AppShellProvider
mainProps={mainProps}
asideProps={asideProps}
topbarOffset={topbarOffset}
hideAside={hideAside}
hideMain={hideMain}
>
<Box {...restProps} className={styles.root} ref={ref} />
</AppShellProvider>
);
},
);
AppContentShell.displayName = 'AppContentShell';
export function AppContentShell({
asideProps,
mainProps,
topbarOffset = 0,
hideAside = false,
hideMain = false,
...restProps
}: AppContentShellProps) {
return (
<AppShellProvider
mainProps={mainProps}
asideProps={asideProps}
topbarOffset={topbarOffset}
hideAside={hideAside}
hideMain={hideMain}
>
<Box {...restProps} className={styles.root} />
</AppShellProvider>
);
}
interface AppContentShellMainProps extends BoxProps {}
/**
* Main content of the app shell.
* @param {AppContentShellMainProps} props -
* @returns {React.ReactNode}
*/
const AppContentShellMain = forwardRef(
({ ...props }: AppContentShellMainProps, ref: Ref<HTMLDivElement>) => {
const { hideMain } = useAppShellContext();
function AppContentShellMain({ ...props }: AppContentShellMainProps) {
const { hideMain } = useAppShellContext();
if (hideMain === true) {
return null;
}
return <Box {...props} className={styles.main} ref={ref} />;
},
);
AppContentShellMain.displayName = 'AppContentShellMain';
if (hideMain === true) {
return null;
}
return <Box {...props} className={styles.main} />;
}
interface AppContentShellAsideProps extends BoxProps {
children: React.ReactNode;
}
/**
* Aside content of the app shell.
* @param {AppContentShellAsideProps} props
* @returns {React.ReactNode}
*/
const AppContentShellAside = forwardRef(
({ ...props }: AppContentShellAsideProps, ref: Ref<HTMLDivElement>) => {
const { hideAside } = useAppShellContext();
function AppContentShellAside({ ...props }: AppContentShellAsideProps) {
const { hideAside } = useAppShellContext();
if (hideAside === true) {
return null;
}
return <Box {...props} className={styles.aside} ref={ref} />;
},
);
AppContentShellAside.displayName = 'AppContentShellAside';
if (hideAside === true) {
return null;
}
return <Box {...props} className={styles.aside} />;
}
AppContentShell.Main = AppContentShellMain;
AppContentShell.Aside = AppContentShellAside;

View File

@@ -15,7 +15,7 @@ import { useAuthActions } from '@/hooks/state';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { useAuthenticatedAccount } from '@/hooks/query';
import { useAuthenticatedAccount, useDashboardMeta } from '@/hooks/query';
import { firstLettersArgs, compose } from '@/utils';
/**
@@ -31,6 +31,9 @@ function DashboardTopbarUser({
// Retrieve authenticated user information.
const { data: user } = useAuthenticatedAccount();
const { data: dashboardMeta } = useDashboardMeta({
keepPreviousData: true,
});
const onClickLogout = () => {
setLogout();
};
@@ -58,6 +61,12 @@ function DashboardTopbarUser({
}
/>
<MenuDivider />
{dashboardMeta.is_bigcapital_cloud && (
<MenuItem
text={'Billing'}
onClick={() => history.push('/billing')}
/>
)}
<MenuItem
text={<T id={'keyboard_shortcuts'} />}
onClick={onKeyboardShortcut}

View File

@@ -25,13 +25,14 @@ function TableVirtualizedListRow({ index, isScrolling, isVisible, style }) {
export function TableVirtualizedListRows() {
const {
table: { page },
props: { vListrowHeight, vListOverscanRowCount, windowScrollerProps },
props: { vListrowHeight, vListOverscanRowCount },
} = useContext(TableContext);
// Dashboard content pane.
const scrollElement =
windowScrollerProps?.scrollElement ||
document.querySelector(`.${CLASSES.DASHBOARD_CONTENT_PANE}`);
const dashboardContentPane = React.useMemo(
() => document.querySelector(`.${CLASSES.DASHBOARD_CONTENT_PANE}`),
[],
);
const rowRenderer = React.useCallback(
({ key, ...args }) => <TableVirtualizedListRow {...args} key={key} />,
@@ -39,7 +40,7 @@ export function TableVirtualizedListRows() {
);
return (
<WindowScroller scrollElement={scrollElement}>
<WindowScroller scrollElement={dashboardContentPane}>
{({ height, isScrolling, onChildScroll, scrollTop }) => (
<AutoSizer disableHeight>
{({ width }) => (

View File

@@ -52,7 +52,6 @@ import ReceiptMailDialog from '@/containers/Sales/Receipts/ReceiptMailDialog/Rec
import PaymentMailDialog from '@/containers/Sales/PaymentReceives/PaymentMailDialog/PaymentMailDialog';
import { ExportDialog } from '@/containers/Dialogs/ExportDialog';
import { RuleFormDialog } from '@/containers/Banking/Rules/RuleFormDialog/RuleFormDialog';
import { DisconnectBankAccountDialog } from '@/containers/CashFlow/AccountTransactions/dialogs/DisconnectBankAccountDialog/DisconnectBankAccountDialog';
/**
* Dialogs container.
@@ -149,10 +148,7 @@ export default function DialogsContainer() {
<ReceiptMailDialog dialogName={DialogsName.ReceiptMail} />
<PaymentMailDialog dialogName={DialogsName.PaymentMail} />
<ExportDialog dialogName={DialogsName.Export} />
<RuleFormDialog dialogName={DialogsName.BankRuleForm} />
<DisconnectBankAccountDialog
dialogName={DialogsName.DisconnectBankAccountConfirmation}
/>
<RuleFormDialog dialogName={DialogsName.BankRuleForm} />
</div>
);
}

View File

@@ -1,15 +1,12 @@
import React, { forwardRef, Ref } from 'react';
import React from 'react';
import { HTMLDivProps, Props } from '@blueprintjs/core';
export interface BoxProps extends Props, HTMLDivProps {
className?: string;
}
export const Box = forwardRef(
({ className, ...rest }: BoxProps, ref: Ref<HTMLDivElement>) => {
const Element = 'div';
export function Box({ className, ...rest }: BoxProps) {
const Element = 'div';
return <Element className={className} ref={ref} {...rest} />;
},
);
Box.displayName = '@bigcapital/Box';
return <Element className={className} {...rest} />;
}

View File

@@ -75,6 +75,5 @@ export enum DialogsName {
GeneralLedgerPdfPreview = 'GeneralLedgerPdfPreview',
SalesTaxLiabilitySummaryPdfPreview = 'SalesTaxLiabilitySummaryPdfPreview',
Export = 'Export',
BankRuleForm = 'BankRuleForm',
DisconnectBankAccountConfirmation = 'DisconnectBankAccountConfirmation',
BankRuleForm = 'BankRuleForm'
}

View File

@@ -8,10 +8,6 @@ export default [
disabled: false,
href: '/preferences/general',
},
{
text: 'Billing',
href: '/preferences/billing',
},
{
text: <T id={'users'} />,
href: '/preferences/users',

View File

@@ -1,10 +0,0 @@
export const BANK_QUERY_KEY = {
BANK_RULES: 'BANK_RULE',
BANK_TRANSACTION_MATCHES: 'BANK_TRANSACTION_MATCHES',
RECOGNIZED_BANK_TRANSACTION: 'RECOGNIZED_BANK_TRANSACTION',
EXCLUDED_BANK_TRANSACTIONS_INFINITY: 'EXCLUDED_BANK_TRANSACTIONS_INFINITY',
RECOGNIZED_BANK_TRANSACTIONS_INFINITY:
'RECOGNIZED_BANK_TRANSACTIONS_INFINITY',
BANK_ACCOUNT_SUMMARY_META: 'BANK_ACCOUNT_SUMMARY_META',
AUTOFILL_CATEGORIZE_BANK_TRANSACTION: 'AUTOFILL_CATEGORIZE_BANK_TRANSACTION',
};

View File

@@ -28,7 +28,6 @@ import TaxRatesAlerts from '@/containers/TaxRates/alerts';
import { CashflowAlerts } from '../CashFlow/CashflowAlerts';
import { BankRulesAlerts } from '../Banking/Rules/RulesList/BankRulesAlerts';
import { SubscriptionAlerts } from '../Subscriptions/alerts/alerts';
import { BankAccountAlerts } from '@/containers/CashFlow/AccountTransactions/alerts';
export default [
...AccountsAlerts,
@@ -59,6 +58,5 @@ export default [
...TaxRatesAlerts,
...CashflowAlerts,
...BankRulesAlerts,
...SubscriptionAlerts,
...BankAccountAlerts,
...SubscriptionAlerts
];

View File

@@ -12,7 +12,6 @@ import {
PopoverInteractionKind,
Position,
Intent,
Switch,
Tooltip,
MenuDivider,
} from '@blueprintjs/core';
@@ -41,14 +40,12 @@ import withSettingsActions from '@/containers/Settings/withSettingsActions';
import { compose } from '@/utils';
import {
useDisconnectBankAccount,
useUpdateBankAccount,
useExcludeUncategorizedTransactions,
useUnexcludeUncategorizedTransactions,
} from '@/hooks/query/bank-rules';
import { withBankingActions } from '../withBankingActions';
import { withBanking } from '../withBanking';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { DialogsName } from '@/constants/dialogs';
function AccountTransactionsActionsBar({
// #withDialogActions
@@ -63,13 +60,6 @@ function AccountTransactionsActionsBar({
// #withBanking
uncategorizedTransationsIdsSelected,
excludedTransactionsIdsSelected,
openMatchingTransactionAside,
// #withBankingActions
enableMultipleCategorization,
// #withAlerts
openAlert,
}) {
const history = useHistory();
const { accountId, currentAccount } = useAccountTransactionsContext();
@@ -77,6 +67,7 @@ function AccountTransactionsActionsBar({
// Refresh cashflow infinity transactions hook.
const { refresh } = useRefreshCashflowTransactionsInfinity();
const { mutateAsync: disconnectBankAccount } = useDisconnectBankAccount();
const { mutateAsync: updateBankAccount } = useUpdateBankAccount();
// Retrieves the money in/out buttons options.
@@ -84,7 +75,6 @@ function AccountTransactionsActionsBar({
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
const isFeedsActive = !!currentAccount.is_feeds_active;
const isFeedsPaused = currentAccount.is_feeds_paused;
const isSyncingOwner = currentAccount.is_syncing_owner;
// Handle table row size change.
@@ -118,9 +108,19 @@ function AccountTransactionsActionsBar({
// Handles the bank account disconnect click.
const handleDisconnectClick = () => {
openDialog(DialogsName.DisconnectBankAccountConfirmation, {
bankAccountId: accountId,
});
disconnectBankAccount({ bankAccountId: accountId })
.then(() => {
AppToaster.show({
message: 'The bank account has been disconnected.',
intent: Intent.SUCCESS,
});
})
.catch((error) => {
AppToaster.show({
message: 'Something went wrong.',
intent: Intent.DANGER,
});
});
};
// handles the bank update button click.
const handleBankUpdateClick = () => {
@@ -191,23 +191,6 @@ function AccountTransactionsActionsBar({
});
};
// Handle multi select transactions for categorization or matching.
const handleMultipleCategorizingSwitch = (event) => {
enableMultipleCategorization(event.currentTarget.checked);
}
// Handle resume bank feeds syncing.
const handleResumeFeedsSyncing = () => {
openAlert('resume-feeds-syncing-bank-accounnt', {
bankAccountId: accountId,
});
};
// Handles pause bank feeds syncing.
const handlePauseFeedsSyncing = () => {
openAlert('pause-feeds-syncing-bank-accounnt', {
bankAccountId: accountId,
});
};
return (
<DashboardActionsBar>
<NavbarGroup>
@@ -255,9 +238,7 @@ function AccountTransactionsActionsBar({
<Tooltip
content={
isFeedsActive
? isFeedsPaused
? 'The bank syncing is paused'
: 'The bank syncing is active'
? 'The bank syncing is active'
: 'The bank syncing is disconnected'
}
minimal={true}
@@ -266,13 +247,7 @@ function AccountTransactionsActionsBar({
<Button
className={Classes.MINIMAL}
icon={<Icon icon="feed" iconSize={16} />}
intent={
isFeedsActive
? isFeedsPaused
? Intent.WARNING
: Intent.SUCCESS
: Intent.DANGER
}
intent={isFeedsActive ? Intent.SUCCESS : Intent.DANGER}
/>
</Tooltip>
</If>
@@ -300,22 +275,6 @@ function AccountTransactionsActionsBar({
</NavbarGroup>
<NavbarGroup align={Alignment.RIGHT}>
{openMatchingTransactionAside && (
<Tooltip
content={
'Enables to categorize or matching multiple bank transactions into one transaction.'
}
position={Position.BOTTOM}
minimal
>
<Switch
label={'Multi Select'}
inline
onChange={handleMultipleCategorizingSwitch}
/>
</Tooltip>
)}
<NavbarDivider />
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
@@ -329,23 +288,6 @@ function AccountTransactionsActionsBar({
<MenuItem onClick={handleBankUpdateClick} text={'Update'} />
<MenuDivider />
</If>
<If condition={isSyncingOwner && isFeedsActive && !isFeedsPaused}>
<MenuItem
onClick={handlePauseFeedsSyncing}
text={'Pause bank feeds'}
/>
<MenuDivider />
</If>
<If condition={isSyncingOwner && isFeedsActive && isFeedsPaused}>
<MenuItem
onClick={handleResumeFeedsSyncing}
text={'Resume bank feeds'}
/>
<MenuDivider />
</If>
<MenuItem onClick={handleBankRulesClick} text={'Bank rules'} />
<If condition={isSyncingOwner && isFeedsActive}>
@@ -369,7 +311,6 @@ function AccountTransactionsActionsBar({
export default compose(
withDialogActions,
withAlertActions,
withSettingsActions,
withSettings(({ cashflowTransactionsSettings }) => ({
cashflowTansactionsTableSize: cashflowTransactionsSettings?.tableSize,
@@ -378,12 +319,9 @@ export default compose(
({
uncategorizedTransationsIdsSelected,
excludedTransactionsIdsSelected,
openMatchingTransactionAside,
}) => ({
uncategorizedTransationsIdsSelected,
excludedTransactionsIdsSelected,
openMatchingTransactionAside,
}),
),
withBankingActions,
)(AccountTransactionsActionsBar);

View File

@@ -1,5 +1,4 @@
// @ts-nocheck
import { useMemo } from 'react';
import styled from 'styled-components';
import { ContentTabs } from '@/components/ContentTabs/ContentTabs';
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
@@ -9,19 +8,15 @@ const AccountContentTabs = styled(ContentTabs)`
`;
export function AccountTransactionsFilterTabs() {
const { filterTab, setFilterTab, bankAccountMetaSummary, currentAccount } =
const { filterTab, setFilterTab, currentAccount } =
useAccountTransactionsContext();
const handleChange = (value) => {
setFilterTab(value);
};
// Detarmines whether show the uncategorized transactions tab.
const hasUncategorizedTransx = useMemo(
() =>
bankAccountMetaSummary?.totalUncategorizedTransactions > 0 ||
bankAccountMetaSummary?.totalExcludedTransactions > 0,
[bankAccountMetaSummary],
const hasUncategorizedTransx = Boolean(
currentAccount.uncategorized_transactions,
);
return (

View File

@@ -29,41 +29,28 @@ function AccountTransactionsListRoot({
return (
<AccountTransactionsProvider>
<AppContentShell hideAside={!openMatchingTransactionAside}>
<AccountTransactionsMain />
<AccountTransactionsAside />
<AppContentShell.Main>
<AccountTransactionsActionsBar />
<AccountTransactionsDetailsBar />
<AccountTransactionsProgressBar />
<DashboardPageContent>
<AccountTransactionsFilterTabs />
<Suspense fallback={<Spinner size={30} />}>
<AccountTransactionsContent />
</Suspense>
</DashboardPageContent>
</AppContentShell.Main>
<AppContentShell.Aside>
<CategorizeTransactionAside />
</AppContentShell.Aside>
</AppContentShell>
</AccountTransactionsProvider>
);
}
function AccountTransactionsMain() {
const { setScrollableRef } = useAccountTransactionsContext();
return (
<AppContentShell.Main ref={(e) => setScrollableRef(e)}>
<AccountTransactionsActionsBar />
<AccountTransactionsDetailsBar />
<AccountTransactionsProgressBar />
<DashboardPageContent>
<AccountTransactionsFilterTabs />
<Suspense fallback={<Spinner size={30} />}>
<AccountTransactionsContent />
</Suspense>
</DashboardPageContent>
</AppContentShell.Main>
);
}
function AccountTransactionsAside() {
return (
<AppContentShell.Aside>
<CategorizeTransactionAside />
</AppContentShell.Aside>
);
}
export default R.compose(
withBanking(
({ selectedUncategorizedTransactionId, openMatchingTransactionAside }) => ({

View File

@@ -1,5 +1,5 @@
// @ts-nocheck
import React, { useRef, useState } from 'react';
import React from 'react';
import { useParams } from 'react-router-dom';
import { DashboardInsider } from '@/components';
import { useCashflowAccounts, useAccount } from '@/hooks/query';
@@ -41,8 +41,6 @@ function AccountTransactionsProvider({ query, ...props }) {
isLoading: isBankAccountMetaSummaryLoading,
} = useGetBankAccountSummaryMeta(accountId);
const [scrollableRef, setScrollableRef] = useState();
// Provider payload.
const provider = {
accountId,
@@ -58,9 +56,6 @@ function AccountTransactionsProvider({ query, ...props }) {
filterTab,
setFilterTab,
scrollableRef,
setScrollableRef
};
return (

View File

@@ -1,6 +1,5 @@
// @ts-nocheck
import React from 'react';
import clsx from 'classnames';
import styled from 'styled-components';
import { Intent } from '@blueprintjs/core';
import {
@@ -13,20 +12,17 @@ import {
AppToaster,
} from '@/components';
import { TABLES } from '@/constants/tables';
import { ActionsMenu } from './components';
import { ActionsMenu } from './UncategorizedTransactions/components';
import withSettings from '@/containers/Settings/withSettings';
import { withBankingActions } from '../../withBankingActions';
import { withBankingActions } from '../withBankingActions';
import { useMemorizedColumnsWidths } from '@/hooks';
import { useAccountUncategorizedTransactionsContext } from '../AllTransactionsUncategorizedBoot';
import { useAccountUncategorizedTransactionsColumns } from './components';
import { useAccountUncategorizedTransactionsContext } from './AllTransactionsUncategorizedBoot';
import { useExcludeUncategorizedTransaction } from '@/hooks/query/bank-rules';
import { useAccountUncategorizedTransactionsColumns } from './hooks';
import { useAccountTransactionsContext } from '../AccountTransactionsProvider';
import { compose } from '@/utils';
import { withBanking } from '../../withBanking';
import styles from './AccountTransactionsUncategorizedTable.module.scss';
/**
* Account transactions data table.
@@ -35,22 +31,13 @@ function AccountTransactionsDataTable({
// #withSettings
cashflowTansactionsTableSize,
// #withBanking
openMatchingTransactionAside,
enableMultipleCategorization,
// #withBankingActions
setUncategorizedTransactionIdForMatching,
setUncategorizedTransactionsSelected,
addTransactionsToCategorizeSelected,
setTransactionsToCategorizeSelected,
}) {
// Retrieve table columns.
const columns = useAccountUncategorizedTransactionsColumns();
const { scrollableRef } = useAccountTransactionsContext();
// Retrieve list context.
const { uncategorizedTransactions, isUncategorizedTransactionsLoading } =
useAccountUncategorizedTransactionsContext();
@@ -64,21 +51,12 @@ function AccountTransactionsDataTable({
// Handle cell click.
const handleCellClick = (cell) => {
if (enableMultipleCategorization) {
addTransactionsToCategorizeSelected(cell.row.original.id);
} else {
setTransactionsToCategorizeSelected(cell.row.original.id);
}
setUncategorizedTransactionIdForMatching(cell.row.original.id);
};
// Handles categorize button click.
const handleCategorizeBtnClick = (transaction) => {
setUncategorizedTransactionIdForMatching(transaction.id);
};
// handles table selected rows change.
const handleSelectedRowsChange = (selected) => {
const transactionIds = selected.map((r) => r.original.id);
setUncategorizedTransactionsSelected(transactionIds);
};
// Handle exclude transaction.
const handleExcludeTransaction = (transaction) => {
excludeTransaction(transaction.id)
@@ -88,7 +66,7 @@ function AccountTransactionsDataTable({
message: 'The bank transaction has been excluded successfully.',
});
})
.catch(() => {
.catch((error) => {
AppToaster.show({
intent: Intent.DANGER,
message: 'Something went wrong.',
@@ -96,6 +74,12 @@ function AccountTransactionsDataTable({
});
};
// Handle selected rows change.
const handleSelectedRowsChange = (selected) => {
const _selectedIds = selected?.map((row) => row.original.id);
setUncategorizedTransactionsSelected(_selectedIds);
};
return (
<CashflowTransactionsTable
noInitialFetch={true}
@@ -122,15 +106,12 @@ function AccountTransactionsDataTable({
noResults={
'There is no uncategorized transactions in the current account.'
}
className="table-constrant"
onSelectedRowsChange={handleSelectedRowsChange}
payload={{
onExclude: handleExcludeTransaction,
onCategorize: handleCategorizeBtnClick,
}}
onSelectedRowsChange={handleSelectedRowsChange}
windowScrollerProps={{ scrollElement: scrollableRef }}
className={clsx('table-constrant', styles.table, {
[styles.showCategorizeColumn]: enableMultipleCategorization,
})}
/>
);
}
@@ -140,12 +121,6 @@ export default compose(
cashflowTansactionsTableSize: cashflowTransactionsSettings?.tableSize,
})),
withBankingActions,
withBanking(
({ openMatchingTransactionAside, enableMultipleCategorization }) => ({
openMatchingTransactionAside,
enableMultipleCategorization,
}),
),
)(AccountTransactionsDataTable);
const DashboardConstrantTable = styled(DataTable)`

View File

@@ -16,7 +16,6 @@ import { TABLES } from '@/constants/tables';
import { useMemorizedColumnsWidths } from '@/hooks';
import { useExcludedTransactionsColumns } from './_utils';
import { useExcludedTransactionsBoot } from './ExcludedTransactionsTableBoot';
import { useAccountTransactionsContext } from '../AccountTransactionsProvider';
import { ActionsMenu } from './_components';
import { useUnexcludeUncategorizedTransaction } from '@/hooks/query/bank-rules';
@@ -38,8 +37,6 @@ function ExcludedTransactionsTableRoot({
const { mutateAsync: unexcludeBankTransaction } =
useUnexcludeUncategorizedTransaction();
const { scrollableRef } = useAccountTransactionsContext();
// Retrieve table columns.
const columns = useExcludedTransactionsColumns();
@@ -100,7 +97,6 @@ function ExcludedTransactionsTableRoot({
className="table-constrant"
selectionColumn={true}
onSelectedRowsChange={handleSelectedRowsChange}
windowScrollerProps={{ scrollElement: scrollableRef }}
payload={{
onRestore: handleRestoreClick,
}}

View File

@@ -20,7 +20,6 @@ import { useRecognizedTransactionsBoot } from './RecognizedTransactionsTableBoot
import { ActionsMenu } from './_components';
import { compose } from '@/utils';
import { useAccountTransactionsContext } from '../AccountTransactionsProvider';
import { useExcludeUncategorizedTransaction } from '@/hooks/query/bank-rules';
import {
WithBankingActionsProps,
@@ -34,8 +33,8 @@ interface RecognizedTransactionsTableProps extends WithBankingActionsProps {}
* Renders the recognized account transactions datatable.
*/
function RecognizedTransactionsTableRoot({
// #withBankingActions
setTransactionsToCategorizeSelected,
// #withBanking
setUncategorizedTransactionIdForMatching,
}: RecognizedTransactionsTableProps) {
const { mutateAsync: excludeBankTransaction } =
useExcludeUncategorizedTransaction();
@@ -50,11 +49,9 @@ function RecognizedTransactionsTableRoot({
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.UNCATEGORIZED_ACCOUNT_TRANSACTIONS);
const { scrollableRef } = useAccountTransactionsContext();
// Handle cell click.
const handleCellClick = (cell, event) => {
setTransactionsToCategorizeSelected(
setUncategorizedTransactionIdForMatching(
cell.row.original.uncategorized_transaction_id,
);
};
@@ -77,7 +74,7 @@ function RecognizedTransactionsTableRoot({
// Handles categorize button click.
const handleCategorizeClick = (transaction) => {
setTransactionsToCategorizeSelected(
setUncategorizedTransactionIdForMatching(
transaction.uncategorized_transaction_id,
);
};
@@ -105,7 +102,6 @@ function RecognizedTransactionsTableRoot({
vListOverscanRowCount={0}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
windowScrollerProps={{ scrollElement: scrollableRef }}
noResults={<RecognizedTransactionsTableNoResults />}
className="table-constrant"
payload={{

View File

@@ -43,7 +43,6 @@ function RecognizedTransactionsTableBoot({
hasNextPage: hasUncategorizedTransactionsNextPage,
} = useRecognizedBankTransactionsInfinity({
page_size: 50,
account_id: accountId,
});
// Memorized the cashflow account transactions.
const recognizedTransactions = React.useMemo(

View File

@@ -1,15 +0,0 @@
.table :global .td.categorize_include,
.table :global .th.categorize_include {
display: none;
}
.table.showCategorizeColumn :global .td.categorize_include,
.table.showCategorizeColumn :global .th.categorize_include {
display: flex;
}
.categorizeCheckbox:global(.bp4-checkbox) :global .bp4-control-indicator {
border-radius: 20px;
}

View File

@@ -1,6 +1,6 @@
import * as R from 'ramda';
import { useEffect } from 'react';
import AccountTransactionsUncategorizedTable from './AccountTransactionsUncategorizedTable';
import AccountTransactionsUncategorizedTable from '../AccountTransactionsUncategorizedTable';
import { AccountUncategorizedTransactionsBoot } from '../AllTransactionsUncategorizedBoot';
import { AccountTransactionsCard } from './AccountTransactionsCard';
import {

View File

@@ -1,157 +0,0 @@
// @ts-nocheck
import React from 'react';
import intl from 'react-intl-universal';
import {
Checkbox,
Intent,
PopoverInteractionKind,
Position,
Tag,
Tooltip,
} from '@blueprintjs/core';
import {
useAddTransactionsToCategorizeSelected,
useIsTransactionToCategorizeSelected,
useRemoveTransactionsToCategorizeSelected,
} from '@/hooks/state/banking';
import { Box, Icon } from '@/components';
import styles from './AccountTransactionsUncategorizedTable.module.scss';
function statusAccessor(transaction) {
return transaction.is_recognized ? (
<Tooltip
interactionKind={PopoverInteractionKind.HOVER}
position={Position.RIGHT}
content={
<Box>
<span>{transaction.assigned_category_formatted}</span>
<Icon
icon={'arrowRight'}
color={'#8F99A8'}
iconSize={12}
style={{ marginLeft: 8, marginRight: 8 }}
/>
<span>{transaction.assigned_account_name}</span>
</Box>
}
>
<Box>
<Tag intent={Intent.SUCCESS} interactive>
Recognized
</Tag>
</Box>
</Tooltip>
) : null;
}
interface TransactionSelectCheckboxProps {
transactionId: number;
}
function TransactionSelectCheckbox({
transactionId,
}: TransactionSelectCheckboxProps) {
const addTransactionsToCategorizeSelected =
useAddTransactionsToCategorizeSelected();
const removeTransactionsToCategorizeSelected =
useRemoveTransactionsToCategorizeSelected();
const isTransactionSelected =
useIsTransactionToCategorizeSelected(transactionId);
const handleChange = (event) => {
isTransactionSelected
? removeTransactionsToCategorizeSelected(transactionId)
: addTransactionsToCategorizeSelected(transactionId);
};
return (
<Checkbox
large
checked={isTransactionSelected}
onChange={handleChange}
className={styles.categorizeCheckbox}
/>
);
}
/**
* Retrieve account uncategorized transctions table columns.
*/
export function useAccountUncategorizedTransactionsColumns() {
return React.useMemo(
() => [
{
id: 'date',
Header: intl.get('date'),
accessor: 'formatted_date',
width: 40,
clickable: true,
textOverview: true,
},
{
id: 'description',
Header: 'Description',
accessor: 'description',
width: 160,
textOverview: true,
clickable: true,
},
{
id: 'payee',
Header: 'Payee',
accessor: 'payee',
width: 60,
clickable: true,
textOverview: true,
},
{
id: 'reference_number',
Header: 'Ref.#',
accessor: 'reference_no',
width: 50,
clickable: true,
textOverview: true,
},
{
id: 'status',
Header: 'Status',
accessor: statusAccessor,
},
{
id: 'deposit',
Header: intl.get('cash_flow.label.deposit'),
accessor: 'formatted_deposit_amount',
width: 40,
className: 'deposit',
textOverview: true,
align: 'right',
clickable: true,
},
{
id: 'withdrawal',
Header: intl.get('cash_flow.label.withdrawal'),
accessor: 'formatted_withdrawal_amount',
className: 'withdrawal',
width: 40,
textOverview: true,
align: 'right',
clickable: true,
},
{
id: 'categorize_include',
Header: '',
accessor: (value) => (
<TransactionSelectCheckbox transactionId={value.id} />
),
width: 20,
minWidth: 20,
maxWidth: 20,
align: 'right',
className: 'categorize_include selection-checkbox',
},
],
[],
);
}

View File

@@ -1,68 +0,0 @@
// @ts-nocheck
import React from 'react';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster, FormattedMessage as T } from '@/components';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { usePauseFeedsBankAccount } from '@/hooks/query/bank-accounts';
import { compose } from '@/utils';
/**
* Pause feeds of the bank account alert.
*/
function PauseFeedsBankAccountAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { bankAccountId },
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: pauseBankAccountFeeds, isLoading } =
usePauseFeedsBankAccount();
// Handle activate item alert cancel.
const handleCancelActivateItem = () => {
closeAlert(name);
};
// Handle confirm item activated.
const handleConfirmItemActivate = () => {
pauseBankAccountFeeds({ bankAccountId })
.then(() => {
AppToaster.show({
message: 'The bank feeds of the bank account has been paused.',
intent: Intent.SUCCESS,
});
})
.catch((error) => {})
.finally(() => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={'Pause bank feeds'}
intent={Intent.WARNING}
isOpen={isOpen}
onCancel={handleCancelActivateItem}
loading={isLoading}
onConfirm={handleConfirmItemActivate}
>
<p>
Are you sure want to pause bank feeds syncing of this bank account, you
can always resume it again?
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(PauseFeedsBankAccountAlert);

View File

@@ -1,69 +0,0 @@
// @ts-nocheck
import React from 'react';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster, FormattedMessage as T } from '@/components';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { useResumeFeedsBankAccount } from '@/hooks/query/bank-accounts';
import { compose } from '@/utils';
/**
* Resume bank account feeds alert.
*/
function ResumeFeedsBankAccountAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { bankAccountId },
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: resumeFeedsBankAccount, isLoading } =
useResumeFeedsBankAccount();
// Handle activate item alert cancel.
const handleCancelActivateItem = () => {
closeAlert(name);
};
// Handle confirm item activated.
const handleConfirmItemActivate = () => {
resumeFeedsBankAccount({ bankAccountId })
.then(() => {
AppToaster.show({
message: 'The bank feeds of the bank account has been resumed.',
intent: Intent.SUCCESS,
});
})
.catch((error) => {})
.finally(() => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={'Resume bank feeds'}
intent={Intent.SUCCESS}
isOpen={isOpen}
onCancel={handleCancelActivateItem}
loading={isLoading}
onConfirm={handleConfirmItemActivate}
>
<p>
Are you sure want to resume bank feeds syncing of this bank account, you
can always pause it again?
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(ResumeFeedsBankAccountAlert);

View File

@@ -1,24 +0,0 @@
// @ts-nocheck
import React from 'react';
const ResumeFeedsBankAccountAlert = React.lazy(
() => import('./ResumeFeedsBankAccount'),
);
const PauseFeedsBankAccountAlert = React.lazy(
() => import('./PauseFeedsBankAccount'),
);
/**
* Bank account alerts.
*/
export const BankAccountAlerts = [
{
name: 'resume-feeds-syncing-bank-accounnt',
component: ResumeFeedsBankAccountAlert,
},
{
name: 'pause-feeds-syncing-bank-accounnt',
component: PauseFeedsBankAccountAlert,
},
];

View File

@@ -150,3 +150,99 @@ export function AccountTransactionsProgressBar() {
<MaterialProgressBar />
) : null;
}
function statusAccessor(transaction) {
return transaction.is_recognized ? (
<Tooltip
compact
interactionKind={PopoverInteractionKind.HOVER}
position={Position.RIGHT}
content={
<Box>
<span>{transaction.assigned_category_formatted}</span>
<Icon
icon={'arrowRight'}
color={'#8F99A8'}
iconSize={12}
style={{ marginLeft: 8, marginRight: 8 }}
/>
<span>{transaction.assigned_account_name}</span>
</Box>
}
>
<Box>
<Tag intent={Intent.SUCCESS} interactive>
Recognized
</Tag>
</Box>
</Tooltip>
) : null;
}
/**
* Retrieve account uncategorized transctions table columns.
*/
export function useAccountUncategorizedTransactionsColumns() {
return React.useMemo(
() => [
{
id: 'date',
Header: intl.get('date'),
accessor: 'formatted_date',
width: 40,
clickable: true,
textOverview: true,
},
{
id: 'description',
Header: 'Description',
accessor: 'description',
width: 160,
textOverview: true,
clickable: true,
},
{
id: 'payee',
Header: 'Payee',
accessor: 'payee',
width: 60,
clickable: true,
textOverview: true,
},
{
id: 'reference_number',
Header: 'Ref.#',
accessor: 'reference_no',
width: 50,
clickable: true,
textOverview: true,
},
{
id: 'status',
Header: 'Status',
accessor: statusAccessor,
},
{
id: 'deposit',
Header: intl.get('cash_flow.label.deposit'),
accessor: 'formatted_deposit_amount',
width: 40,
className: 'deposit',
textOverview: true,
align: 'right',
clickable: true,
},
{
id: 'withdrawal',
Header: intl.get('cash_flow.label.withdrawal'),
accessor: 'formatted_withdrawal_amount',
className: 'withdrawal',
width: 40,
textOverview: true,
align: 'right',
clickable: true,
},
],
[],
);
}

View File

@@ -1,42 +0,0 @@
// @ts-nocheck
import React from 'react';
import { Dialog, DialogSuspense } from '@/components';
import withDialogRedux from '@/components/DialogReduxConnect';
import { compose } from '@/utils';
const DisconnectBankAccountDialogContent = React.lazy(
() => import('./DisconnectBankAccountDialogContent'),
);
/**
* Disconnect bank account confirmation dialog.
*/
function DisconnectBankAccountDialogRoot({
dialogName,
payload: { bankAccountId },
isOpen,
}) {
return (
<Dialog
name={dialogName}
title={'Disconnect Bank Account'}
isOpen={isOpen}
canEscapeJeyClose={true}
autoFocus={true}
style={{ width: 400 }}
>
<DialogSuspense>
<DisconnectBankAccountDialogContent
dialogName={dialogName}
bankAccountId={bankAccountId}
/>
</DialogSuspense>
</Dialog>
);
}
export const DisconnectBankAccountDialog = compose(withDialogRedux())(
DisconnectBankAccountDialogRoot,
);
DisconnectBankAccountDialog.displayName = 'DisconnectBankAccountDialog';

View File

@@ -1,104 +0,0 @@
// @ts-nocheck
import * as Yup from 'yup';
import { Button, Intent, Classes } from '@blueprintjs/core';
import * as R from 'ramda';
import { Form, Formik, FormikHelpers } from 'formik';
import { AppToaster, FFormGroup, FInputGroup } from '@/components';
import { useDisconnectBankAccount } from '@/hooks/query/bank-rules';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { DialogsName } from '@/constants/dialogs';
interface DisconnectFormValues {
label: string;
}
const initialValues = {
label: '',
};
const Schema = Yup.object().shape({
label: Yup.string().required().label('Confirmation'),
});
interface DisconnectBankAccountDialogContentProps {
bankAccountId: number;
}
function DisconnectBankAccountDialogContent({
bankAccountId,
// #withDialogActions
closeDialog,
}: DisconnectBankAccountDialogContentProps) {
const { mutateAsync: disconnectBankAccount } = useDisconnectBankAccount();
const handleSubmit = (
values: DisconnectFormValues,
{ setErrors, setSubmitting }: FormikHelpers<DisconnectFormValues>,
) => {
debugger;
setSubmitting(true);
if (values.label !== 'DISCONNECT ACCOUNT') {
setErrors({
label: 'The entered value is incorrect.',
});
setSubmitting(false);
return;
}
disconnectBankAccount({ bankAccountId })
.then(() => {
setSubmitting(false);
AppToaster.show({
message: 'The bank account has been disconnected.',
intent: Intent.SUCCESS,
});
closeDialog(DialogsName.DisconnectBankAccountConfirmation);
})
.catch((error) => {
setSubmitting(false);
AppToaster.show({
message: 'Something went wrong.',
intent: Intent.DANGER,
});
});
};
const handleCancelBtnClick = () => {
closeDialog(DialogsName.DisconnectBankAccountConfirmation);
};
return (
<Formik
onSubmit={handleSubmit}
validationSchema={Schema}
initialValues={initialValues}
>
<Form>
<div className={Classes.DIALOG_BODY}>
<FFormGroup
label={`Type "DISCONNECT ACCOUNT"`}
name={'label'}
fastField
>
<FInputGroup name={'label'} fastField />
</FFormGroup>
</div>
<div className={Classes.DIALOG_FOOTER}>
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
<Button type="submit" intent={Intent.DANGER}>
Disconnect Bank Account
</Button>
<Button intent={Intent.NONE} onClick={handleCancelBtnClick}>
Cancel
</Button>
</div>
</div>
</Form>
</Formik>
);
}
export default R.compose(withDialogActions)(DisconnectBankAccountDialogContent);

View File

@@ -6,13 +6,10 @@ import { useAccounts, useBranches } from '@/hooks/query';
import { useFeatureCan } from '@/hooks/state';
import { Features } from '@/constants';
import { Spinner } from '@blueprintjs/core';
import {
GetAutofillCategorizeTransaction,
useGetAutofillCategorizeTransaction,
} from '@/hooks/query/bank-rules';
import { useGetRecognizedBankTransaction } from '@/hooks/query/bank-rules';
import { useCategorizeTransactionTabsBoot } from '@/containers/CashFlow/CategorizeTransactionAside/CategorizeTransactionTabsBoot';
interface CategorizeTransactionBootProps {
uncategorizedTransactionsIds: Array<number>;
children: React.ReactNode;
}
@@ -22,8 +19,8 @@ interface CategorizeTransactionBootValue {
isBranchesLoading: boolean;
isAccountsLoading: boolean;
primaryBranch: any;
autofillCategorizeValues: null | GetAutofillCategorizeTransaction;
isAutofillCategorizeValuesLoading: boolean;
recognizedTranasction: any;
isRecognizedTransactionLoading: boolean;
}
const CategorizeTransactionBootContext =
@@ -35,9 +32,11 @@ const CategorizeTransactionBootContext =
* Categorize transcation boot.
*/
function CategorizeTransactionBoot({
uncategorizedTransactionsIds,
...props
}: CategorizeTransactionBootProps) {
const { uncategorizedTransaction, uncategorizedTransactionId } =
useCategorizeTransactionTabsBoot();
// Detarmines whether the feature is enabled.
const { featureCan } = useFeatureCan();
const isBranchFeatureCan = featureCan(Features.Branches);
@@ -50,11 +49,13 @@ function CategorizeTransactionBoot({
{},
{ enabled: isBranchFeatureCan },
);
// Fetches the autofill values of categorize transaction.
// Fetches the recognized transaction.
const {
data: autofillCategorizeValues,
isLoading: isAutofillCategorizeValuesLoading,
} = useGetAutofillCategorizeTransaction(uncategorizedTransactionsIds, {});
data: recognizedTranasction,
isLoading: isRecognizedTransactionLoading,
} = useGetRecognizedBankTransaction(uncategorizedTransactionId, {
enabled: !!uncategorizedTransaction.is_recognized,
});
// Retrieves the primary branch.
const primaryBranch = useMemo(
@@ -68,11 +69,11 @@ function CategorizeTransactionBoot({
isBranchesLoading,
isAccountsLoading,
primaryBranch,
autofillCategorizeValues,
isAutofillCategorizeValuesLoading,
recognizedTranasction,
isRecognizedTransactionLoading,
};
const isLoading =
isBranchesLoading || isAccountsLoading || isAutofillCategorizeValuesLoading;
isBranchesLoading || isAccountsLoading || isRecognizedTransactionLoading;
if (isLoading) {
<Spinner size={30} />;

View File

@@ -8,15 +8,15 @@ export function CategorizeTransactionBranchField() {
const { branches } = useCategorizeTransactionBoot();
return (
<FeatureCan feature={Features.Branches}>
<FFormGroup name={'branchId'} label={'Branch'} fastField inline>
<FFormGroup name={'branchId'} label={'Branch'} fastField inline>
<FeatureCan feature={Features.Branches}>
<BranchSuggestField
name={'branchId'}
items={branches}
popoverProps={{ minimal: true }}
fill
/>
</FFormGroup>
</FeatureCan>
</FeatureCan>
</FFormGroup>
);
}

View File

@@ -1,16 +1,15 @@
// @ts-nocheck
import styled from 'styled-components';
import * as R from 'ramda';
import { CategorizeTransactionBoot } from './CategorizeTransactionBoot';
import { CategorizeTransactionForm } from './CategorizeTransactionForm';
import { withBanking } from '@/containers/CashFlow/withBanking';
import { useCategorizeTransactionTabsBoot } from '@/containers/CashFlow/CategorizeTransactionAside/CategorizeTransactionTabsBoot';
export function CategorizeTransactionContent() {
const { uncategorizedTransactionId } = useCategorizeTransactionTabsBoot();
function CategorizeTransactionContentRoot({
transactionsToCategorizeIdsSelected,
}) {
return (
<CategorizeTransactionBoot
uncategorizedTransactionsIds={transactionsToCategorizeIdsSelected}
uncategorizedTransactionId={uncategorizedTransactionId}
>
<CategorizeTransactionDrawerBody>
<CategorizeTransactionForm />
@@ -19,12 +18,6 @@ function CategorizeTransactionContentRoot({
);
}
export const CategorizeTransactionContent = R.compose(
withBanking(({ transactionsToCategorizeIdsSelected }) => ({
transactionsToCategorizeIdsSelected,
})),
)(CategorizeTransactionContentRoot);
const CategorizeTransactionDrawerBody = styled.div`
display: flex;
flex-direction: column;

View File

@@ -22,7 +22,7 @@ function CategorizeTransactionFormRoot({
// #withBankingActions
closeMatchingTransactionAside,
}) {
const { uncategorizedTransactionIds } = useCategorizeTransactionTabsBoot();
const { uncategorizedTransactionId } = useCategorizeTransactionTabsBoot();
const { mutateAsync: categorizeTransaction } = useCategorizeTransaction();
// Form initial values in create and edit mode.
@@ -30,10 +30,10 @@ function CategorizeTransactionFormRoot({
// Callbacks handles form submit.
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
const _values = tranformToRequest(values, uncategorizedTransactionIds);
const transformedValues = tranformToRequest(values);
setSubmitting(true);
categorizeTransaction(_values)
categorizeTransaction([uncategorizedTransactionId, transformedValues])
.then(() => {
setSubmitting(false);

View File

@@ -6,7 +6,6 @@ import { Box, FFormGroup, FSelect } from '@/components';
import { getAddMoneyInOptions, getAddMoneyOutOptions } from '@/constants';
import { useFormikContext } from 'formik';
import { useCategorizeTransactionTabsBoot } from '@/containers/CashFlow/CategorizeTransactionAside/CategorizeTransactionTabsBoot';
import { useCategorizeTransactionBoot } from './CategorizeTransactionBoot';
// Retrieves the add money in button options.
const MoneyInOptions = getAddMoneyInOptions();
@@ -19,18 +18,16 @@ const Title = styled('h3')`
`;
export function CategorizeTransactionFormContent() {
const { autofillCategorizeValues } = useCategorizeTransactionBoot();
const { uncategorizedTransaction } = useCategorizeTransactionTabsBoot();
const transactionTypes = autofillCategorizeValues?.isDepositTransaction
const transactionTypes = uncategorizedTransaction?.is_deposit_transaction
? MoneyInOptions
: MoneyOutOptions;
const formattedAmount = autofillCategorizeValues?.formattedAmount;
return (
<Box style={{ flex: 1, margin: 20 }}>
<FormGroup label={'Amount'} inline>
<Title>{formattedAmount}</Title>
<Title>{uncategorizedTransaction.formatted_amount}</Title>
</FormGroup>
<FFormGroup name={'category'} label={'Category'} fastField inline>

View File

@@ -1,8 +1,8 @@
// @ts-nocheck
import * as R from 'ramda';
import { transformToForm, transfromToSnakeCase } from '@/utils';
import { useCategorizeTransactionTabsBoot } from '@/containers/CashFlow/CategorizeTransactionAside/CategorizeTransactionTabsBoot';
import { useCategorizeTransactionBoot } from './CategorizeTransactionBoot';
import { GetAutofillCategorizeTransaction } from '@/hooks/query/bank-rules';
// Default initial form values.
export const defaultInitialValues = {
@@ -18,28 +18,48 @@ export const defaultInitialValues = {
};
export const transformToCategorizeForm = (
autofillCategorizeTransaction: GetAutofillCategorizeTransaction,
uncategorizedTransaction: any,
recognizedTransaction?: any,
) => {
return transformToForm(autofillCategorizeTransaction, defaultInitialValues);
let defaultValues = {
debitAccountId: uncategorizedTransaction.account_id,
transactionType: uncategorizedTransaction.is_deposit_transaction
? 'other_income'
: 'other_expense',
amount: uncategorizedTransaction.amount,
date: uncategorizedTransaction.date,
};
if (recognizedTransaction) {
const recognizedDefaults = getRecognizedTransactionDefaultValues(
recognizedTransaction,
);
defaultValues = R.merge(defaultValues, recognizedDefaults);
}
return transformToForm(defaultValues, defaultInitialValues);
};
export const tranformToRequest = (
formValues: Record<string, any>,
uncategorizedTransactionIds: Array<number>,
export const getRecognizedTransactionDefaultValues = (
recognizedTransaction: any,
) => {
return {
uncategorized_transaction_ids: uncategorizedTransactionIds,
...transfromToSnakeCase(formValues),
creditAccountId: recognizedTransaction.assignedAccountId || '',
// transactionType: recognizedTransaction.assignCategory,
referenceNo: recognizedTransaction.referenceNo || '',
};
};
export const tranformToRequest = (formValues: Record<string, any>) => {
return transfromToSnakeCase(formValues);
};
/**
* Categorize transaction form initial values.
* @returns
*/
export const useCategorizeTransactionFormInitialValues = () => {
const { primaryBranch, autofillCategorizeValues } =
const { primaryBranch, recognizedTranasction } =
useCategorizeTransactionBoot();
const { uncategorizedTransaction } = useCategorizeTransactionTabsBoot();
return {
...defaultInitialValues,
@@ -48,7 +68,10 @@ export const useCategorizeTransactionFormInitialValues = () => {
* values such as `notes` come back from the API as null, so remove those
* as well.
*/
...transformToCategorizeForm(autofillCategorizeValues),
...transformToCategorizeForm(
uncategorizedTransaction,
recognizedTranasction,
),
/** Assign the primary branch id as default value. */
branchId: primaryBranch?.id || null,

View File

@@ -19,32 +19,20 @@ function CategorizeTransactionAsideRoot({
// #withBanking
selectedUncategorizedTransactionId,
resetTransactionsToCategorizeSelected,
enableMultipleCategorization,
}: CategorizeTransactionAsideProps) {
//
//
useEffect(
() => () => {
// Close the reconcile matching form.
closeReconcileMatchingTransaction();
// Reset the selected transactions to categorize.
resetTransactionsToCategorizeSelected();
// Disable multi matching.
enableMultipleCategorization(false);
},
[
closeReconcileMatchingTransaction,
resetTransactionsToCategorizeSelected,
enableMultipleCategorization,
],
[closeReconcileMatchingTransaction],
);
const handleClose = () => {
closeMatchingTransactionAside();
}
// Cannot continue if there is no selected transactions.;
};
const uncategorizedTransactionId = selectedUncategorizedTransactionId;
if (!selectedUncategorizedTransactionId) {
return null;
}
@@ -52,7 +40,7 @@ function CategorizeTransactionAsideRoot({
<Aside title={'Categorize Bank Transaction'} onClose={handleClose}>
<Aside.Body>
<CategorizeTransactionTabsBoot
uncategorizedTransactionId={selectedUncategorizedTransactionId}
uncategorizedTransactionId={uncategorizedTransactionId}
>
<CategorizeTransactionTabs />
</CategorizeTransactionTabsBoot>
@@ -63,7 +51,7 @@ function CategorizeTransactionAsideRoot({
export const CategorizeTransactionAside = R.compose(
withBankingActions,
withBanking(({ transactionsToCategorizeIdsSelected }) => ({
selectedUncategorizedTransactionId: transactionsToCategorizeIdsSelected,
withBanking(({ selectedUncategorizedTransactionId }) => ({
selectedUncategorizedTransactionId,
})),
)(CategorizeTransactionAsideRoot);

View File

@@ -2,10 +2,14 @@
import { Tab, Tabs } from '@blueprintjs/core';
import { MatchingBankTransaction } from './MatchingTransaction';
import { CategorizeTransactionContent } from '../CategorizeTransaction/drawers/CategorizeTransactionDrawer/CategorizeTransactionContent';
import { useCategorizeTransactionTabsBoot } from './CategorizeTransactionTabsBoot';
import styles from './CategorizeTransactionTabs.module.scss';
export function CategorizeTransactionTabs() {
const defaultSelectedTabId = 'categorize';
const { uncategorizedTransaction } = useCategorizeTransactionTabsBoot();
const defaultSelectedTabId = uncategorizedTransaction?.is_recognized
? 'categorize'
: 'matching';
return (
<Tabs

View File

@@ -1,13 +1,16 @@
// @ts-nocheck
import React, { useMemo } from 'react';
import { castArray, uniq } from 'lodash';
import React from 'react';
import { Spinner } from '@blueprintjs/core';
import { useUncategorizedTransaction } from '@/hooks/query';
interface CategorizeTransactionTabsValue {
uncategorizedTransactionIds: Array<number>;
uncategorizedTransactionId: number;
isUncategorizedTransactionLoading: boolean;
uncategorizedTransaction: any;
}
interface CategorizeTransactionTabsBootProps {
uncategorizedTransactionIds: number | Array<number>;
uncategorizedTransactionId: number;
children: React.ReactNode;
}
@@ -23,23 +26,28 @@ export function CategorizeTransactionTabsBoot({
uncategorizedTransactionId,
children,
}: CategorizeTransactionTabsBootProps) {
const uncategorizedTransactionIds = useMemo(
() => uniq(castArray(uncategorizedTransactionId)),
[uncategorizedTransactionId],
);
const {
data: uncategorizedTransaction,
isLoading: isUncategorizedTransactionLoading,
} = useUncategorizedTransaction(uncategorizedTransactionId);
const provider = {
uncategorizedTransactionIds,
uncategorizedTransactionId,
uncategorizedTransaction,
isUncategorizedTransactionLoading,
};
// Use a key prop to force re-render of children when `uncategorizedTransactionIds` changes
const isLoading = isUncategorizedTransactionLoading;
// Use a key prop to force re-render of children when uncategorizedTransactionId changes
const childrenPerKey = React.useMemo(() => {
return React.Children.map(children, (child) =>
React.cloneElement(child, {
key: uncategorizedTransactionIds?.join(','),
}),
React.cloneElement(child, { key: uncategorizedTransactionId }),
);
}, [children, uncategorizedTransactionIds]);
}, [children, uncategorizedTransactionId]);
if (isLoading) {
return <Spinner size={30} />;
}
return (
<CategorizeTransactionTabsBootContext.Provider value={provider}>
{childrenPerKey}

Some files were not shown because too many files have changed in this diff Show More