mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-23 16:19:49 +00:00
Compare commits
1 Commits
big-150-ca
...
v0.15.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2baa667c5d |
@@ -13,9 +13,9 @@ export default class CashflowController {
|
|||||||
router() {
|
router() {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.use(Container.get(CommandCashflowTransaction).router());
|
|
||||||
router.use(Container.get(GetCashflowTransaction).router());
|
router.use(Container.get(GetCashflowTransaction).router());
|
||||||
router.use(Container.get(GetCashflowAccounts).router());
|
router.use(Container.get(GetCashflowAccounts).router());
|
||||||
|
router.use(Container.get(CommandCashflowTransaction).router());
|
||||||
router.use(Container.get(DeleteCashflowTransaction).router());
|
router.use(Container.get(DeleteCashflowTransaction).router());
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
|
|||||||
@@ -3,15 +3,14 @@ import { Router, Request, Response, NextFunction } from 'express';
|
|||||||
import { param } from 'express-validator';
|
import { param } from 'express-validator';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
|
import DeleteCashflowTransactionService from '../../../services/Cashflow/DeleteCashflowTransactionService';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
|
|
||||||
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
||||||
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DeleteCashflowTransactionController extends BaseController {
|
export default class DeleteCashflowTransaction extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
private cashflowApplication: CashflowApplication;
|
deleteCashflowService: DeleteCashflowTransactionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller router.
|
* Controller router.
|
||||||
@@ -45,7 +44,7 @@ export default class DeleteCashflowTransactionController extends BaseController
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { oldCashflowTransaction } =
|
const { oldCashflowTransaction } =
|
||||||
await this.cashflowApplication.deleteTransaction(
|
await this.deleteCashflowService.deleteCashflowTransaction(
|
||||||
tenantId,
|
tenantId,
|
||||||
transactionId
|
transactionId
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query } from 'express-validator';
|
import { param, query } from 'express-validator';
|
||||||
|
import GetCashflowAccountsService from '@/services/Cashflow/GetCashflowAccountsService';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
|
import GetCashflowTransactionsService from '@/services/Cashflow/GetCashflowTransactionsService';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
||||||
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class GetCashflowAccounts extends BaseController {
|
export default class GetCashflowAccounts extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
private cashflowApplication: CashflowApplication;
|
getCashflowAccountsService: GetCashflowAccountsService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
getCashflowTransactionsService: GetCashflowTransactionsService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller router.
|
* Controller router.
|
||||||
@@ -58,7 +62,10 @@ export default class GetCashflowAccounts extends BaseController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const cashflowAccounts =
|
const cashflowAccounts =
|
||||||
await this.cashflowApplication.getCashflowAccounts(tenantId, filter);
|
await this.getCashflowAccountsService.getCashflowAccounts(
|
||||||
|
tenantId,
|
||||||
|
filter
|
||||||
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
cashflow_accounts: this.transfromToResponse(cashflowAccounts),
|
cashflow_accounts: this.transfromToResponse(cashflowAccounts),
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ import { Service, Inject } from 'typedi';
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { param } from 'express-validator';
|
import { param } from 'express-validator';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
|
import GetCashflowTransactionsService from '@/services/Cashflow/GetCashflowTransactionsService';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
||||||
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class GetCashflowAccounts extends BaseController {
|
export default class GetCashflowAccounts extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
private cashflowApplication: CashflowApplication;
|
getCashflowTransactionsService: GetCashflowTransactionsService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller router.
|
* Controller router.
|
||||||
@@ -43,10 +43,11 @@ export default class GetCashflowAccounts extends BaseController {
|
|||||||
const { transactionId } = req.params;
|
const { transactionId } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cashflowTransaction = await this.cashflowApplication.getTransaction(
|
const cashflowTransaction =
|
||||||
tenantId,
|
await this.getCashflowTransactionsService.getCashflowTransaction(
|
||||||
transactionId
|
tenantId,
|
||||||
);
|
transactionId
|
||||||
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
cashflow_transaction: this.transfromToResponse(cashflowTransaction),
|
cashflow_transaction: this.transfromToResponse(cashflowTransaction),
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { ValidationChain, check, param, query } from 'express-validator';
|
import { check } from 'express-validator';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
|
import NewCashflowTransactionService from '@/services/Cashflow/NewCashflowTransactionService';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
import { AbilitySubject, CashflowAction } from '@/interfaces';
|
||||||
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class NewCashflowTransactionController extends BaseController {
|
export default class NewCashflowTransactionController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
private cashflowApplication: CashflowApplication;
|
private newCashflowTranscationService: NewCashflowTransactionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
@@ -18,18 +18,6 @@ export default class NewCashflowTransactionController extends BaseController {
|
|||||||
public router() {
|
public router() {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/transactions/uncategorized/:id',
|
|
||||||
this.asyncMiddleware(this.getUncategorizedCashflowTransaction),
|
|
||||||
this.catchServiceErrors
|
|
||||||
);
|
|
||||||
router.get(
|
|
||||||
'/transactions/:id/uncategorized',
|
|
||||||
this.getUncategorizedTransactionsValidationSchema,
|
|
||||||
this.validationResult,
|
|
||||||
this.asyncMiddleware(this.getUncategorizedCashflowTransactions),
|
|
||||||
this.catchServiceErrors
|
|
||||||
);
|
|
||||||
router.post(
|
router.post(
|
||||||
'/transactions',
|
'/transactions',
|
||||||
CheckPolicies(CashflowAction.Create, AbilitySubject.Cashflow),
|
CheckPolicies(CashflowAction.Create, AbilitySubject.Cashflow),
|
||||||
@@ -38,72 +26,13 @@ export default class NewCashflowTransactionController extends BaseController {
|
|||||||
this.asyncMiddleware(this.newCashflowTransaction),
|
this.asyncMiddleware(this.newCashflowTransaction),
|
||||||
this.catchServiceErrors
|
this.catchServiceErrors
|
||||||
);
|
);
|
||||||
router.post(
|
|
||||||
'/transactions/:id/uncategorize',
|
|
||||||
this.revertCategorizedCashflowTransaction,
|
|
||||||
this.catchServiceErrors
|
|
||||||
);
|
|
||||||
router.post(
|
|
||||||
'/transactions/:id/categorize',
|
|
||||||
this.categorizeCashflowTransactionValidationSchema,
|
|
||||||
this.validationResult,
|
|
||||||
this.categorizeCashflowTransaction,
|
|
||||||
this.catchServiceErrors
|
|
||||||
);
|
|
||||||
router.post(
|
|
||||||
'/transaction/:id/categorize/expense',
|
|
||||||
this.categorizeAsExpenseValidationSchema,
|
|
||||||
this.validationResult,
|
|
||||||
this.categorizesCashflowTransactionAsExpense,
|
|
||||||
this.catchServiceErrors
|
|
||||||
);
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Getting uncategorized transactions validation schema.
|
|
||||||
* @returns {ValidationChain}
|
|
||||||
*/
|
|
||||||
public get getUncategorizedTransactionsValidationSchema() {
|
|
||||||
return [
|
|
||||||
param('id').exists().isNumeric().toInt(),
|
|
||||||
query('page').optional().isNumeric().toInt(),
|
|
||||||
query('page_size').optional().isNumeric().toInt(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize as expense validation schema.
|
|
||||||
*/
|
|
||||||
public get categorizeAsExpenseValidationSchema() {
|
|
||||||
return [
|
|
||||||
check('expense_account_id').exists(),
|
|
||||||
check('date').isISO8601().exists(),
|
|
||||||
check('reference_no').optional(),
|
|
||||||
check('exchange_rate').optional().isFloat({ gt: 0 }).toFloat(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize cashflow tranasction validation schema.
|
|
||||||
*/
|
|
||||||
public get categorizeCashflowTransactionValidationSchema() {
|
|
||||||
return [
|
|
||||||
check('date').exists().isISO8601().toDate(),
|
|
||||||
check('credit_account_id').exists().isInt().toInt(),
|
|
||||||
check('transaction_number').optional(),
|
|
||||||
check('transaction_type').exists(),
|
|
||||||
check('reference_no').optional(),
|
|
||||||
check('exchange_rate').optional().isFloat({ gt: 0 }).toFloat(),
|
|
||||||
check('description').optional(),
|
|
||||||
check('branch_id').optional({ nullable: true }).isNumeric().toInt(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New cashflow transaction validation schema.
|
* New cashflow transaction validation schema.
|
||||||
*/
|
*/
|
||||||
public get newTransactionValidationSchema() {
|
get newTransactionValidationSchema() {
|
||||||
return [
|
return [
|
||||||
check('date').exists().isISO8601().toDate(),
|
check('date').exists().isISO8601().toDate(),
|
||||||
check('reference_no').optional({ nullable: true }).trim().escape(),
|
check('reference_no').optional({ nullable: true }).trim().escape(),
|
||||||
@@ -119,7 +48,9 @@ export default class NewCashflowTransactionController extends BaseController {
|
|||||||
check('credit_account_id').exists().isInt().toInt(),
|
check('credit_account_id').exists().isInt().toInt(),
|
||||||
|
|
||||||
check('exchange_rate').optional().isFloat({ gt: 0 }).toFloat(),
|
check('exchange_rate').optional().isFloat({ gt: 0 }).toFloat(),
|
||||||
|
|
||||||
check('branch_id').optional({ nullable: true }).isNumeric().toInt(),
|
check('branch_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||||
|
|
||||||
check('publish').default(false).isBoolean().toBoolean(),
|
check('publish').default(false).isBoolean().toBoolean(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -139,12 +70,13 @@ export default class NewCashflowTransactionController extends BaseController {
|
|||||||
const ownerContributionDTO = this.matchedBodyData(req);
|
const ownerContributionDTO = this.matchedBodyData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cashflowTransaction =
|
const { cashflowTransaction } =
|
||||||
await this.cashflowApplication.createTransaction(
|
await this.newCashflowTranscationService.newCashflowTransaction(
|
||||||
tenantId,
|
tenantId,
|
||||||
ownerContributionDTO,
|
ownerContributionDTO,
|
||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: cashflowTransaction.id,
|
id: cashflowTransaction.id,
|
||||||
message: 'New cashflow transaction has been created successfully.',
|
message: 'New cashflow transaction has been created successfully.',
|
||||||
@@ -154,147 +86,11 @@ export default class NewCashflowTransactionController extends BaseController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Revert the categorized cashflow transaction.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
private revertCategorizedCashflowTransaction = async (
|
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) => {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const { id: cashflowTransactionId } = req.params;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await this.cashflowApplication.uncategorizeTransaction(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId
|
|
||||||
);
|
|
||||||
return res.status(200).send({ data });
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize the cashflow transaction.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
private categorizeCashflowTransaction = async (
|
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) => {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const { id: cashflowTransactionId } = req.params;
|
|
||||||
const cashflowTransaction = this.matchedBodyData(req);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.cashflowApplication.categorizeTransaction(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId,
|
|
||||||
cashflowTransaction
|
|
||||||
);
|
|
||||||
return res.status(200).send({
|
|
||||||
message: 'The cashflow transaction has been created successfully.',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize the transaction as expense transaction.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
private categorizesCashflowTransactionAsExpense = async (
|
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) => {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const { id: cashflowTransactionId } = req.params;
|
|
||||||
const cashflowTransaction = this.matchedBodyData(req);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.cashflowApplication.categorizeAsExpense(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId,
|
|
||||||
cashflowTransaction
|
|
||||||
);
|
|
||||||
return res.status(200).send({
|
|
||||||
message: 'The cashflow transaction has been created successfully.',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the uncategorized cashflow transactions.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
public getUncategorizedCashflowTransaction = async (
|
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) => {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const { id: transactionId } = req.params;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await this.cashflowApplication.getUncategorizedTransaction(
|
|
||||||
tenantId,
|
|
||||||
transactionId
|
|
||||||
);
|
|
||||||
return res.status(200).send({ data });
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the uncategorized cashflow transactions.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
public getUncategorizedCashflowTransactions = async (
|
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) => {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const { id: accountId } = req.params;
|
|
||||||
const query = this.matchedQueryData(req);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await this.cashflowApplication.getUncategorizedTransactions(
|
|
||||||
tenantId,
|
|
||||||
accountId,
|
|
||||||
query
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).send(data);
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the service errors.
|
* Handle the service errors.
|
||||||
* @param error
|
* @param error
|
||||||
* @param {Request} req
|
* @param req
|
||||||
* @param {res
|
* @param res
|
||||||
* @param next
|
* @param next
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
@@ -344,16 +140,6 @@ export default class NewCashflowTransactionController extends BaseController {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'UNCATEGORIZED_TRANSACTION_TYPE_INVALID') {
|
|
||||||
return res.boom.badRequest(null, {
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
type: 'UNCATEGORIZED_TRANSACTION_TYPE_INVALID',
|
|
||||||
code: 4100,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
exports.up = function (knex) {
|
|
||||||
return knex.schema.createTable(
|
|
||||||
'uncategorized_cashflow_transactions',
|
|
||||||
(table) => {
|
|
||||||
table.increments('id');
|
|
||||||
table.date('date').index();
|
|
||||||
table.decimal('amount');
|
|
||||||
table.string('currency_code');
|
|
||||||
table.string('reference_no').index();
|
|
||||||
table.string('payee');
|
|
||||||
table
|
|
||||||
.integer('account_id')
|
|
||||||
.unsigned()
|
|
||||||
.references('id')
|
|
||||||
.inTable('accounts');
|
|
||||||
table.string('description');
|
|
||||||
table.string('categorize_ref_type');
|
|
||||||
table.integer('categorize_ref_id').unsigned();
|
|
||||||
table.boolean('categorized').defaultTo(false);
|
|
||||||
table.string('plaid_transaction_id');
|
|
||||||
table.timestamps();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = function (knex) {
|
|
||||||
return knex.schema.dropTableIfExists('uncategorized_cashflow_transactions');
|
|
||||||
};
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
exports.up = function (knex) {
|
|
||||||
return knex.schema.table('accounts', (table) => {
|
|
||||||
table.integer('uncategorized_transactions').defaultTo(0);
|
|
||||||
table.boolean('is_system_account').defaultTo(true);
|
|
||||||
table.boolean('is_feeds_active').defaultTo(false);
|
|
||||||
table.datetime('last_feeds_updated_at').nullable();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = function (knex) {};
|
|
||||||
@@ -233,38 +233,3 @@ export interface ICashflowTransactionSchema {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ICashflowTransactionInput extends ICashflowTransactionSchema {}
|
export interface ICashflowTransactionInput extends ICashflowTransactionSchema {}
|
||||||
|
|
||||||
export interface ICategorizeCashflowTransactioDTO {
|
|
||||||
creditAccountId: number;
|
|
||||||
referenceNo: string;
|
|
||||||
transactionNumber: string;
|
|
||||||
transactionType: string;
|
|
||||||
exchangeRate: number;
|
|
||||||
description: string;
|
|
||||||
branchId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IUncategorizedCashflowTransaction {
|
|
||||||
id?: number;
|
|
||||||
amount: number;
|
|
||||||
date: Date;
|
|
||||||
currencyCode: string;
|
|
||||||
accountId: number;
|
|
||||||
description: string;
|
|
||||||
referenceNo: string;
|
|
||||||
categorizeRefType: string;
|
|
||||||
categorizeRefId: number;
|
|
||||||
categorized: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface CreateUncategorizedTransactionDTO {
|
|
||||||
date: Date | string;
|
|
||||||
accountId: number;
|
|
||||||
amount: number;
|
|
||||||
currencyCode: string;
|
|
||||||
payee?: string;
|
|
||||||
description?: string;
|
|
||||||
referenceNo?: string | null;
|
|
||||||
plaidTransactionId?: string | null;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { IAccount } from './Account';
|
import { IAccount } from './Account';
|
||||||
import { IUncategorizedCashflowTransaction } from './CashFlow';
|
|
||||||
|
|
||||||
export interface ICashflowAccountTransactionsFilter {
|
export interface ICashflowAccountTransactionsFilter {
|
||||||
page: number;
|
page: number;
|
||||||
@@ -125,39 +124,8 @@ export interface ICommandCashflowDeletedPayload {
|
|||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICashflowTransactionCategorizedPayload {
|
|
||||||
tenantId: number;
|
|
||||||
cashflowTransactionId: number;
|
|
||||||
cashflowTransaction: ICashflowTransaction;
|
|
||||||
trx: Knex.Transaction;
|
|
||||||
}
|
|
||||||
export interface ICashflowTransactionUncategorizingPayload {
|
|
||||||
tenantId: number;
|
|
||||||
uncategorizedTransaction: IUncategorizedCashflowTransaction;
|
|
||||||
trx: Knex.Transaction;
|
|
||||||
}
|
|
||||||
export interface ICashflowTransactionUncategorizedPayload {
|
|
||||||
tenantId: number;
|
|
||||||
uncategorizedTransaction: IUncategorizedCashflowTransaction;
|
|
||||||
oldUncategorizedTransaction: IUncategorizedCashflowTransaction;
|
|
||||||
trx: Knex.Transaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum CashflowAction {
|
export enum CashflowAction {
|
||||||
Create = 'Create',
|
Create = 'Create',
|
||||||
Delete = 'Delete',
|
Delete = 'Delete',
|
||||||
View = 'View',
|
View = 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CategorizeTransactionAsExpenseDTO {
|
|
||||||
expenseAccountId: number;
|
|
||||||
exchangeRate: number;
|
|
||||||
referenceNo: string;
|
|
||||||
description: string;
|
|
||||||
branchId?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGetUncategorizedTransactionsQuery {
|
|
||||||
page?: number;
|
|
||||||
pageSize?: number;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ export interface PlaidTransaction {
|
|||||||
iso_currency_code: string;
|
iso_currency_code: string;
|
||||||
transaction_id: string;
|
transaction_id: string;
|
||||||
transaction_type: string;
|
transaction_type: string;
|
||||||
payment_meta: { reference_number: string | null; payee: string | null };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PlaidFetchedTransactionsUpdates {
|
export interface PlaidFetchedTransactionsUpdates {
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ import { PlaidUpdateTransactionsOnItemCreatedSubscriber } from '@/services/Banki
|
|||||||
import { InvoiceChangeStatusOnMailSentSubscriber } from '@/services/Sales/Invoices/subscribers/InvoiceChangeStatusOnMailSentSubscriber';
|
import { InvoiceChangeStatusOnMailSentSubscriber } from '@/services/Sales/Invoices/subscribers/InvoiceChangeStatusOnMailSentSubscriber';
|
||||||
import { SaleReceiptMarkClosedOnMailSentSubcriber } from '@/services/Sales/Receipts/subscribers/SaleReceiptMarkClosedOnMailSentSubcriber';
|
import { SaleReceiptMarkClosedOnMailSentSubcriber } from '@/services/Sales/Receipts/subscribers/SaleReceiptMarkClosedOnMailSentSubcriber';
|
||||||
import { SaleEstimateMarkApprovedOnMailSent } from '@/services/Sales/Estimates/subscribers/SaleEstimateMarkApprovedOnMailSent';
|
import { SaleEstimateMarkApprovedOnMailSent } from '@/services/Sales/Estimates/subscribers/SaleEstimateMarkApprovedOnMailSent';
|
||||||
import { DeleteCashflowTransactionOnUncategorize } from '@/services/Cashflow/subscribers/DeleteCashflowTransactionOnUncategorize';
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
return new EventPublisher();
|
return new EventPublisher();
|
||||||
@@ -213,9 +212,6 @@ export const susbcribers = () => {
|
|||||||
SyncItemTaxRateOnEditTaxSubscriber,
|
SyncItemTaxRateOnEditTaxSubscriber,
|
||||||
|
|
||||||
// Plaid
|
// Plaid
|
||||||
PlaidUpdateTransactionsOnItemCreatedSubscriber,
|
PlaidUpdateTransactionsOnItemCreatedSubscriber
|
||||||
|
|
||||||
// Cashflow
|
|
||||||
DeleteCashflowTransactionOnUncategorize,
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ import TaxRate from 'models/TaxRate';
|
|||||||
import TaxRateTransaction from 'models/TaxRateTransaction';
|
import TaxRateTransaction from 'models/TaxRateTransaction';
|
||||||
import Attachment from 'models/Attachment';
|
import Attachment from 'models/Attachment';
|
||||||
import PlaidItem from 'models/PlaidItem';
|
import PlaidItem from 'models/PlaidItem';
|
||||||
import UncategorizedCashflowTransaction from 'models/UncategorizedCashflowTransaction';
|
|
||||||
|
|
||||||
export default (knex) => {
|
export default (knex) => {
|
||||||
const models = {
|
const models = {
|
||||||
@@ -127,8 +126,7 @@ export default (knex) => {
|
|||||||
TaxRate,
|
TaxRate,
|
||||||
TaxRateTransaction,
|
TaxRateTransaction,
|
||||||
Attachment,
|
Attachment,
|
||||||
PlaidItem,
|
PlaidItem
|
||||||
UncategorizedCashflowTransaction
|
|
||||||
};
|
};
|
||||||
return mapValues(models, (model) => model.bindKnex(knex));
|
return mapValues(models, (model) => model.bindKnex(knex));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -196,7 +196,6 @@ export default class Account extends mixin(TenantModel, [
|
|||||||
const Expense = require('models/Expense');
|
const Expense = require('models/Expense');
|
||||||
const ExpenseEntry = require('models/ExpenseCategory');
|
const ExpenseEntry = require('models/ExpenseCategory');
|
||||||
const ItemEntry = require('models/ItemEntry');
|
const ItemEntry = require('models/ItemEntry');
|
||||||
const UncategorizedTransaction = require('models/UncategorizedCashflowTransaction');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
@@ -306,21 +305,6 @@ export default class Account extends mixin(TenantModel, [
|
|||||||
to: 'items_entries.sellAccountId',
|
to: 'items_entries.sellAccountId',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Associated uncategorized transactions.
|
|
||||||
*/
|
|
||||||
uncategorizedTransactions: {
|
|
||||||
relation: Model.HasManyRelation,
|
|
||||||
modelClass: UncategorizedTransaction.default,
|
|
||||||
join: {
|
|
||||||
from: 'accounts.id',
|
|
||||||
to: 'uncategorized_cashflow_transactions.accountId',
|
|
||||||
},
|
|
||||||
filter: (query) => {
|
|
||||||
query.where('categorized', false);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export default class CashflowTransaction extends TenantModel {
|
|||||||
transactionType: string;
|
transactionType: string;
|
||||||
amount: number;
|
amount: number;
|
||||||
exchangeRate: number;
|
exchangeRate: number;
|
||||||
uncategorize: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name.
|
* Table name.
|
||||||
|
|||||||
@@ -215,10 +215,6 @@ export default class Expense extends mixin(TenantModel, [
|
|||||||
to: 'branches.id',
|
to: 'branches.id',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
media: {
|
media: {
|
||||||
relation: Model.ManyToManyRelation,
|
relation: Model.ManyToManyRelation,
|
||||||
modelClass: Media.default,
|
modelClass: Media.default,
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
/* eslint-disable global-require */
|
|
||||||
import TenantModel from 'models/TenantModel';
|
|
||||||
import { Model, ModelOptions, QueryContext } from 'objection';
|
|
||||||
import Account from './Account';
|
|
||||||
|
|
||||||
export default class UncategorizedCashflowTransaction extends TenantModel {
|
|
||||||
id!: number;
|
|
||||||
amount!: number;
|
|
||||||
categorized!: boolean;
|
|
||||||
accountId!: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table name.
|
|
||||||
*/
|
|
||||||
static get tableName() {
|
|
||||||
return 'uncategorized_cashflow_transactions';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timestamps columns.
|
|
||||||
*/
|
|
||||||
static get timestamps() {
|
|
||||||
return ['createdAt', 'updatedAt'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Virtual attributes.
|
|
||||||
*/
|
|
||||||
static get virtualAttributes() {
|
|
||||||
return [
|
|
||||||
'withdrawal',
|
|
||||||
'deposit',
|
|
||||||
'isDepositTransaction',
|
|
||||||
'isWithdrawalTransaction',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the withdrawal amount.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
public get withdrawal() {
|
|
||||||
return this.amount < 0 ? Math.abs(this.amount) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the deposit amount.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
public get deposit(): number {
|
|
||||||
return this.amount > 0 ? Math.abs(this.amount) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detarmines whether the transaction is deposit transaction.
|
|
||||||
*/
|
|
||||||
public get isDepositTransaction(): boolean {
|
|
||||||
return 0 < this.deposit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detarmines whether the transaction is withdrawal transaction.
|
|
||||||
*/
|
|
||||||
public get isWithdrawalTransaction(): boolean {
|
|
||||||
return 0 < this.withdrawal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Relationship mapping.
|
|
||||||
*/
|
|
||||||
static get relationMappings() {
|
|
||||||
const Account = require('models/Account');
|
|
||||||
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* Transaction may has associated to account.
|
|
||||||
*/
|
|
||||||
account: {
|
|
||||||
relation: Model.BelongsToOneRelation,
|
|
||||||
modelClass: Account.default,
|
|
||||||
join: {
|
|
||||||
from: 'uncategorized_cashflow_transactions.accountId',
|
|
||||||
to: 'accounts.id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the count of uncategorized transactions for the associated account
|
|
||||||
* based on the specified operation.
|
|
||||||
* @param {QueryContext} queryContext - The query context for the transaction.
|
|
||||||
* @param {boolean} increment - Indicates whether to increment or decrement the count.
|
|
||||||
*/
|
|
||||||
private async updateUncategorizedTransactionCount(
|
|
||||||
queryContext: QueryContext,
|
|
||||||
increment: boolean
|
|
||||||
) {
|
|
||||||
const operation = increment ? 'increment' : 'decrement';
|
|
||||||
const amount = increment ? 1 : -1;
|
|
||||||
|
|
||||||
await Account.query(queryContext.transaction)
|
|
||||||
.findById(this.accountId)
|
|
||||||
[operation]('uncategorized_transactions', amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs after insert.
|
|
||||||
* @param {QueryContext} queryContext
|
|
||||||
*/
|
|
||||||
public async $afterInsert(queryContext) {
|
|
||||||
await super.$afterInsert(queryContext);
|
|
||||||
await this.updateUncategorizedTransactionCount(queryContext, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs after update.
|
|
||||||
* @param {ModelOptions} opt
|
|
||||||
* @param {QueryContext} queryContext
|
|
||||||
*/
|
|
||||||
public async $afterUpdate(
|
|
||||||
opt: ModelOptions,
|
|
||||||
queryContext: QueryContext
|
|
||||||
): Promise<any> {
|
|
||||||
await super.$afterUpdate(opt, queryContext);
|
|
||||||
|
|
||||||
if (this.id && this.categorized) {
|
|
||||||
await this.updateUncategorizedTransactionCount(queryContext, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs after delete.
|
|
||||||
* @param {QueryContext} queryContext
|
|
||||||
*/
|
|
||||||
public async $afterDelete(queryContext: QueryContext) {
|
|
||||||
await super.$afterDelete(queryContext);
|
|
||||||
await this.updateUncategorizedTransactionCount(queryContext, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,9 +8,9 @@ import {
|
|||||||
transformPlaidAccountToCreateAccount,
|
transformPlaidAccountToCreateAccount,
|
||||||
transformPlaidTrxsToCashflowCreate,
|
transformPlaidTrxsToCashflowCreate,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { DeleteCashflowTransaction } from '@/services/Cashflow/DeleteCashflowTransactionService';
|
import NewCashflowTransactionService from '@/services/Cashflow/NewCashflowTransactionService';
|
||||||
|
import DeleteCashflowTransactionService from '@/services/Cashflow/DeleteCashflowTransactionService';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
|
||||||
|
|
||||||
const CONCURRENCY_ASYNC = 10;
|
const CONCURRENCY_ASYNC = 10;
|
||||||
|
|
||||||
@@ -23,10 +23,10 @@ export class PlaidSyncDb {
|
|||||||
private createAccountService: CreateAccount;
|
private createAccountService: CreateAccount;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private cashflowApp: CashflowApplication;
|
private createCashflowTransactionService: NewCashflowTransactionService;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private deleteCashflowTransactionService: DeleteCashflowTransaction;
|
private deleteCashflowTransactionService: DeleteCashflowTransactionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs the plaid accounts to the system accounts.
|
* Syncs the plaid accounts to the system accounts.
|
||||||
@@ -36,14 +36,11 @@ export class PlaidSyncDb {
|
|||||||
*/
|
*/
|
||||||
public async syncBankAccounts(
|
public async syncBankAccounts(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
plaidAccounts: PlaidAccount[],
|
plaidAccounts: PlaidAccount[]
|
||||||
institution: any
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const transformToPlaidAccounts =
|
const accountCreateDTOs = R.map(transformPlaidAccountToCreateAccount)(
|
||||||
transformPlaidAccountToCreateAccount(institution);
|
plaidAccounts
|
||||||
|
);
|
||||||
const accountCreateDTOs = R.map(transformToPlaidAccounts)(plaidAccounts);
|
|
||||||
|
|
||||||
await bluebird.map(
|
await bluebird.map(
|
||||||
accountCreateDTOs,
|
accountCreateDTOs,
|
||||||
(createAccountDTO: any) =>
|
(createAccountDTO: any) =>
|
||||||
@@ -78,18 +75,17 @@ export class PlaidSyncDb {
|
|||||||
cashflowAccount.id,
|
cashflowAccount.id,
|
||||||
openingEquityBalance.id
|
openingEquityBalance.id
|
||||||
);
|
);
|
||||||
const uncategorizedTransDTOs =
|
const accountsCashflowDTO = R.map(transformTransaction)(plaidTranasctions);
|
||||||
R.map(transformTransaction)(plaidTranasctions);
|
|
||||||
|
|
||||||
// Creating account transaction queue.
|
// Creating account transaction queue.
|
||||||
await bluebird.map(
|
await bluebird.map(
|
||||||
uncategorizedTransDTOs,
|
accountsCashflowDTO,
|
||||||
(uncategoriedDTO) =>
|
(cashflowDTO) =>
|
||||||
this.cashflowApp.createUncategorizedTransaction(
|
this.createCashflowTransactionService.newCashflowTransaction(
|
||||||
tenantId,
|
tenantId,
|
||||||
uncategoriedDTO
|
cashflowDTO
|
||||||
),
|
),
|
||||||
{ concurrency: 1 }
|
{ concurrency: CONCURRENCY_ASYNC }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,38 +157,4 @@ export class PlaidSyncDb {
|
|||||||
|
|
||||||
await PlaidItem.query().findOne({ plaidItemId }).patch({ lastCursor });
|
await PlaidItem.query().findOne({ plaidItemId }).patch({ lastCursor });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the last feeds updated at of the given Plaid accounts ids.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {string[]} plaidAccountIds
|
|
||||||
*/
|
|
||||||
public async updateLastFeedsUpdatedAt(
|
|
||||||
tenantId: number,
|
|
||||||
plaidAccountIds: string[]
|
|
||||||
) {
|
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
await Account.query().whereIn('plaid_account_id', plaidAccountIds).patch({
|
|
||||||
lastFeedsUpdatedAt: new Date(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the accounts feed active status of the given Plaid accounts ids.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number[]} plaidAccountIds
|
|
||||||
* @param {boolean} isFeedsActive
|
|
||||||
*/
|
|
||||||
public async updateAccountsFeedsActive(
|
|
||||||
tenantId: number,
|
|
||||||
plaidAccountIds: string[],
|
|
||||||
isFeedsActive: boolean = true
|
|
||||||
) {
|
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
await Account.query().whereIn('plaid_account_id', plaidAccountIds).patch({
|
|
||||||
isFeedsActive,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,19 +25,11 @@ export class PlaidUpdateTransactions {
|
|||||||
const request = { access_token: accessToken };
|
const request = { access_token: accessToken };
|
||||||
const plaidInstance = new PlaidClientWrapper();
|
const plaidInstance = new PlaidClientWrapper();
|
||||||
const {
|
const {
|
||||||
data: { accounts, item },
|
data: { accounts },
|
||||||
} = await plaidInstance.accountsGet(request);
|
} = await plaidInstance.accountsGet(request);
|
||||||
|
|
||||||
const plaidAccountsIds = accounts.map((a) => a.account_id);
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: { institution },
|
|
||||||
} = await plaidInstance.institutionsGetById({
|
|
||||||
institution_id: item.institution_id,
|
|
||||||
country_codes: ['US', 'UK'],
|
|
||||||
});
|
|
||||||
// Update the DB.
|
// Update the DB.
|
||||||
await this.plaidSync.syncBankAccounts(tenantId, accounts, institution);
|
await this.plaidSync.syncBankAccounts(tenantId, accounts);
|
||||||
await this.plaidSync.syncAccountsTransactions(
|
await this.plaidSync.syncAccountsTransactions(
|
||||||
tenantId,
|
tenantId,
|
||||||
added.concat(modified)
|
added.concat(modified)
|
||||||
@@ -45,12 +37,6 @@ export class PlaidUpdateTransactions {
|
|||||||
await this.plaidSync.syncRemoveTransactions(tenantId, removed);
|
await this.plaidSync.syncRemoveTransactions(tenantId, removed);
|
||||||
await this.plaidSync.syncTransactionsCursor(tenantId, plaidItemId, cursor);
|
await this.plaidSync.syncTransactionsCursor(tenantId, plaidItemId, cursor);
|
||||||
|
|
||||||
// Update the last feeds updated at of the updated accounts.
|
|
||||||
await this.plaidSync.updateLastFeedsUpdatedAt(tenantId, plaidAccountsIds);
|
|
||||||
|
|
||||||
// Turn on the accounts feeds flag.
|
|
||||||
await this.plaidSync.updateAccountsFeedsActive(tenantId, plaidAccountsIds);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addedCount: added.length,
|
addedCount: added.length,
|
||||||
modifiedCount: modified.length,
|
modifiedCount: modified.length,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import {
|
import {
|
||||||
CreateUncategorizedTransactionDTO,
|
|
||||||
IAccountCreateDTO,
|
IAccountCreateDTO,
|
||||||
|
ICashflowNewCommandDTO,
|
||||||
PlaidAccount,
|
PlaidAccount,
|
||||||
PlaidTransaction,
|
PlaidTransaction,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
@@ -11,44 +11,51 @@ import {
|
|||||||
* @param {PlaidAccount} plaidAccount
|
* @param {PlaidAccount} plaidAccount
|
||||||
* @returns {IAccountCreateDTO}
|
* @returns {IAccountCreateDTO}
|
||||||
*/
|
*/
|
||||||
export const transformPlaidAccountToCreateAccount = R.curry(
|
export const transformPlaidAccountToCreateAccount = (
|
||||||
(institution: any, plaidAccount: PlaidAccount): IAccountCreateDTO => {
|
plaidAccount: PlaidAccount
|
||||||
return {
|
): IAccountCreateDTO => {
|
||||||
name: `${institution.name} - ${plaidAccount.name}`,
|
return {
|
||||||
code: '',
|
name: plaidAccount.name,
|
||||||
description: plaidAccount.official_name,
|
code: '',
|
||||||
currencyCode: plaidAccount.balances.iso_currency_code,
|
description: plaidAccount.official_name,
|
||||||
accountType: 'cash',
|
currencyCode: plaidAccount.balances.iso_currency_code,
|
||||||
active: true,
|
accountType: 'cash',
|
||||||
plaidAccountId: plaidAccount.account_id,
|
active: true,
|
||||||
bankBalance: plaidAccount.balances.current,
|
plaidAccountId: plaidAccount.account_id,
|
||||||
accountMask: plaidAccount.mask,
|
bankBalance: plaidAccount.balances.current,
|
||||||
};
|
accountMask: plaidAccount.mask,
|
||||||
}
|
};
|
||||||
);
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transformes the plaid transaction to cashflow create DTO.
|
* Transformes the plaid transaction to cashflow create DTO.
|
||||||
* @param {number} cashflowAccountId - Cashflow account ID.
|
* @param {number} cashflowAccountId - Cashflow account ID.
|
||||||
* @param {number} creditAccountId - Credit account ID.
|
* @param {number} creditAccountId - Credit account ID.
|
||||||
* @param {PlaidTransaction} plaidTranasction - Plaid transaction.
|
* @param {PlaidTransaction} plaidTranasction - Plaid transaction.
|
||||||
* @returns {CreateUncategorizedTransactionDTO}
|
* @returns {ICashflowNewCommandDTO}
|
||||||
*/
|
*/
|
||||||
export const transformPlaidTrxsToCashflowCreate = R.curry(
|
export const transformPlaidTrxsToCashflowCreate = R.curry(
|
||||||
(
|
(
|
||||||
cashflowAccountId: number,
|
cashflowAccountId: number,
|
||||||
creditAccountId: number,
|
creditAccountId: number,
|
||||||
plaidTranasction: PlaidTransaction
|
plaidTranasction: PlaidTransaction
|
||||||
): CreateUncategorizedTransactionDTO => {
|
): ICashflowNewCommandDTO => {
|
||||||
return {
|
return {
|
||||||
date: plaidTranasction.date,
|
date: plaidTranasction.date,
|
||||||
amount: plaidTranasction.amount,
|
|
||||||
|
transactionType: 'OwnerContribution',
|
||||||
description: plaidTranasction.name,
|
description: plaidTranasction.name,
|
||||||
payee: plaidTranasction.payment_meta?.payee,
|
|
||||||
|
amount: plaidTranasction.amount,
|
||||||
|
exchangeRate: 1,
|
||||||
currencyCode: plaidTranasction.iso_currency_code,
|
currencyCode: plaidTranasction.iso_currency_code,
|
||||||
accountId: cashflowAccountId,
|
creditAccountId,
|
||||||
referenceNo: plaidTranasction.payment_meta?.reference_number,
|
cashflowAccountId,
|
||||||
|
|
||||||
|
// transactionNumber: string;
|
||||||
|
// referenceNo: string;
|
||||||
plaidTransactionId: plaidTranasction.transaction_id,
|
plaidTransactionId: plaidTranasction.transaction_id,
|
||||||
|
publish: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,213 +0,0 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import { DeleteCashflowTransaction } from './DeleteCashflowTransactionService';
|
|
||||||
import { UncategorizeCashflowTransaction } from './UncategorizeCashflowTransaction';
|
|
||||||
import { CategorizeCashflowTransaction } from './CategorizeCashflowTransaction';
|
|
||||||
import {
|
|
||||||
CategorizeTransactionAsExpenseDTO,
|
|
||||||
CreateUncategorizedTransactionDTO,
|
|
||||||
ICashflowAccountsFilter,
|
|
||||||
ICashflowNewCommandDTO,
|
|
||||||
ICategorizeCashflowTransactioDTO,
|
|
||||||
IGetUncategorizedTransactionsQuery,
|
|
||||||
} from '@/interfaces';
|
|
||||||
import { CategorizeTransactionAsExpense } from './CategorizeTransactionAsExpense';
|
|
||||||
import { GetUncategorizedTransactions } from './GetUncategorizedTransactions';
|
|
||||||
import { CreateUncategorizedTransaction } from './CreateUncategorizedTransaction';
|
|
||||||
import { GetUncategorizedTransaction } from './GetUncategorizedTransaction';
|
|
||||||
import NewCashflowTransactionService from './NewCashflowTransactionService';
|
|
||||||
import GetCashflowAccountsService from './GetCashflowAccountsService';
|
|
||||||
import { GetCashflowTransactionService } from './GetCashflowTransactionsService';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class CashflowApplication {
|
|
||||||
@Inject()
|
|
||||||
private createTransactionService: NewCashflowTransactionService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private deleteTransactionService: DeleteCashflowTransaction;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private getCashflowAccountsService: GetCashflowAccountsService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private getCashflowTransactionService: GetCashflowTransactionService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private uncategorizeTransactionService: UncategorizeCashflowTransaction;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private categorizeTransactionService: CategorizeCashflowTransaction;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private categorizeAsExpenseService: CategorizeTransactionAsExpense;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private getUncategorizedTransactionsService: GetUncategorizedTransactions;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private getUncategorizedTransactionService: GetUncategorizedTransaction;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private createUncategorizedTransactionService: CreateUncategorizedTransaction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {ICashflowNewCommandDTO} transactionDTO
|
|
||||||
* @param {number} userId
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public createTransaction(
|
|
||||||
tenantId: number,
|
|
||||||
transactionDTO: ICashflowNewCommandDTO,
|
|
||||||
userId?: number
|
|
||||||
) {
|
|
||||||
return this.createTransactionService.newCashflowTransaction(
|
|
||||||
tenantId,
|
|
||||||
transactionDTO,
|
|
||||||
userId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the given cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} cashflowTransactionId
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public deleteTransaction(tenantId: number, cashflowTransactionId: number) {
|
|
||||||
return this.deleteTransactionService.deleteCashflowTransaction(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves specific cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} cashflowTransactionId
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public getTransaction(tenantId: number, cashflowTransactionId: number) {
|
|
||||||
return this.getCashflowTransactionService.getCashflowTransaction(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the cashflow accounts.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {ICashflowAccountsFilter} filterDTO
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public getCashflowAccounts(
|
|
||||||
tenantId: number,
|
|
||||||
filterDTO: ICashflowAccountsFilter
|
|
||||||
) {
|
|
||||||
return this.getCashflowAccountsService.getCashflowAccounts(
|
|
||||||
tenantId,
|
|
||||||
filterDTO
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new uncategorized cash transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {CreateUncategorizedTransactionDTO} createUncategorizedTransactionDTO
|
|
||||||
* @returns {IUncategorizedCashflowTransaction}
|
|
||||||
*/
|
|
||||||
public createUncategorizedTransaction(
|
|
||||||
tenantId: number,
|
|
||||||
createUncategorizedTransactionDTO: CreateUncategorizedTransactionDTO
|
|
||||||
) {
|
|
||||||
return this.createUncategorizedTransactionService.create(
|
|
||||||
tenantId,
|
|
||||||
createUncategorizedTransactionDTO
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uncategorize the given cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} cashflowTransactionId
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public uncategorizeTransaction(
|
|
||||||
tenantId: number,
|
|
||||||
cashflowTransactionId: number
|
|
||||||
) {
|
|
||||||
return this.uncategorizeTransactionService.uncategorize(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize the given cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} cashflowTransactionId
|
|
||||||
* @param {ICategorizeCashflowTransactioDTO} categorizeDTO
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public categorizeTransaction(
|
|
||||||
tenantId: number,
|
|
||||||
cashflowTransactionId: number,
|
|
||||||
categorizeDTO: ICategorizeCashflowTransactioDTO
|
|
||||||
) {
|
|
||||||
return this.categorizeTransactionService.categorize(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId,
|
|
||||||
categorizeDTO
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorizes the given cashflow transaction as expense transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} cashflowTransactionId
|
|
||||||
* @param {CategorizeTransactionAsExpenseDTO} transactionDTO
|
|
||||||
*/
|
|
||||||
public categorizeAsExpense(
|
|
||||||
tenantId: number,
|
|
||||||
cashflowTransactionId: number,
|
|
||||||
transactionDTO: CategorizeTransactionAsExpenseDTO
|
|
||||||
) {
|
|
||||||
return this.categorizeAsExpenseService.categorize(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionId,
|
|
||||||
transactionDTO
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the uncategorized cashflow transactions.
|
|
||||||
* @param {number} tenantId
|
|
||||||
*/
|
|
||||||
public getUncategorizedTransactions(
|
|
||||||
tenantId: number,
|
|
||||||
accountId: number,
|
|
||||||
query: IGetUncategorizedTransactionsQuery
|
|
||||||
) {
|
|
||||||
return this.getUncategorizedTransactionsService.getTransactions(
|
|
||||||
tenantId,
|
|
||||||
accountId,
|
|
||||||
query
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves specific uncategorized transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} uncategorizedTransactionId
|
|
||||||
*/
|
|
||||||
public getUncategorizedTransaction(
|
|
||||||
tenantId: number,
|
|
||||||
uncategorizedTransactionId: number
|
|
||||||
) {
|
|
||||||
return this.getUncategorizedTransactionService.getTransaction(
|
|
||||||
tenantId,
|
|
||||||
uncategorizedTransactionId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
|
import * as R from 'ramda';
|
||||||
import {
|
import {
|
||||||
ILedgerEntry,
|
ILedgerEntry,
|
||||||
ICashflowTransaction,
|
ICashflowTransaction,
|
||||||
AccountNormal,
|
AccountNormal,
|
||||||
|
ICashflowTransactionLine,
|
||||||
} from '../../interfaces';
|
} from '../../interfaces';
|
||||||
import {
|
import {
|
||||||
transformCashflowTransactionType,
|
transformCashflowTransactionType,
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
|
||||||
import events from '@/subscribers/events';
|
|
||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
|
||||||
import UnitOfWork from '../UnitOfWork';
|
|
||||||
import {
|
|
||||||
ICashflowTransactionCategorizedPayload,
|
|
||||||
ICashflowTransactionUncategorizingPayload,
|
|
||||||
ICategorizeCashflowTransactioDTO,
|
|
||||||
} from '@/interfaces';
|
|
||||||
import { Knex } from 'knex';
|
|
||||||
import { transformCategorizeTransToCashflow } from './utils';
|
|
||||||
import { CommandCashflowValidator } from './CommandCasflowValidator';
|
|
||||||
import NewCashflowTransactionService from './NewCashflowTransactionService';
|
|
||||||
import { TransferAuthorizationGuaranteeDecision } from 'plaid';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class CategorizeCashflowTransaction {
|
|
||||||
@Inject()
|
|
||||||
private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private eventPublisher: EventPublisher;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private uow: UnitOfWork;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private commandValidators: CommandCashflowValidator;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private createCashflow: NewCashflowTransactionService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize the given cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {ICategorizeCashflowTransactioDTO} categorizeDTO
|
|
||||||
*/
|
|
||||||
public async categorize(
|
|
||||||
tenantId: number,
|
|
||||||
uncategorizedTransactionId: number,
|
|
||||||
categorizeDTO: ICategorizeCashflowTransactioDTO
|
|
||||||
) {
|
|
||||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
// Retrieves the uncategorized transaction or throw an error.
|
|
||||||
const transaction = await UncategorizedCashflowTransaction.query()
|
|
||||||
.findById(uncategorizedTransactionId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
// Validates the transaction shouldn't be categorized before.
|
|
||||||
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(
|
|
||||||
transaction,
|
|
||||||
categorizeDTO.transactionType
|
|
||||||
);
|
|
||||||
// Edits the cashflow transaction under UOW env.
|
|
||||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
|
||||||
// Triggers `onTransactionCategorizing` event.
|
|
||||||
await this.eventPublisher.emitAsync(
|
|
||||||
events.cashflow.onTransactionCategorizing,
|
|
||||||
{
|
|
||||||
tenantId,
|
|
||||||
trx,
|
|
||||||
} as ICashflowTransactionUncategorizingPayload
|
|
||||||
);
|
|
||||||
// Transformes the categorize DTO to the cashflow transaction.
|
|
||||||
const cashflowTransactionDTO = transformCategorizeTransToCashflow(
|
|
||||||
transaction,
|
|
||||||
categorizeDTO
|
|
||||||
);
|
|
||||||
// Creates a new cashflow transaction.
|
|
||||||
const cashflowTransaction =
|
|
||||||
await this.createCashflow.newCashflowTransaction(
|
|
||||||
tenantId,
|
|
||||||
cashflowTransactionDTO
|
|
||||||
);
|
|
||||||
// Updates the uncategorized transaction as categorized.
|
|
||||||
await UncategorizedCashflowTransaction.query(trx).patchAndFetchById(
|
|
||||||
uncategorizedTransactionId,
|
|
||||||
{
|
|
||||||
categorized: true,
|
|
||||||
categorizeRefType: 'CashflowTransaction',
|
|
||||||
categorizeRefId: cashflowTransaction.id,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// Triggers `onCashflowTransactionCategorized` event.
|
|
||||||
await this.eventPublisher.emitAsync(
|
|
||||||
events.cashflow.onTransactionCategorized,
|
|
||||||
{
|
|
||||||
tenantId,
|
|
||||||
// cashflowTransaction,
|
|
||||||
trx,
|
|
||||||
} as ICashflowTransactionCategorizedPayload
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
import {
|
|
||||||
CategorizeTransactionAsExpenseDTO,
|
|
||||||
ICashflowTransactionCategorizedPayload,
|
|
||||||
} from '@/interfaces';
|
|
||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import UnitOfWork from '../UnitOfWork';
|
|
||||||
import events from '@/subscribers/events';
|
|
||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
|
||||||
import { Knex } from 'knex';
|
|
||||||
import { CreateExpense } from '../Expenses/CRUD/CreateExpense';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class CategorizeTransactionAsExpense {
|
|
||||||
@Inject()
|
|
||||||
private uow: UnitOfWork;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private eventPublisher: EventPublisher;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private createExpenseService: CreateExpense;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize the transaction as expense transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} cashflowTransactionId
|
|
||||||
* @param {CategorizeTransactionAsExpenseDTO} transactionDTO
|
|
||||||
*/
|
|
||||||
public async categorize(
|
|
||||||
tenantId: number,
|
|
||||||
cashflowTransactionId: number,
|
|
||||||
transactionDTO: CategorizeTransactionAsExpenseDTO
|
|
||||||
) {
|
|
||||||
const { CashflowTransaction } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
const transaction = await CashflowTransaction.query()
|
|
||||||
.findById(cashflowTransactionId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
|
||||||
// Triggers `onTransactionUncategorizing` event.
|
|
||||||
await this.eventPublisher.emitAsync(
|
|
||||||
events.cashflow.onTransactionCategorizingAsExpense,
|
|
||||||
{
|
|
||||||
tenantId,
|
|
||||||
trx,
|
|
||||||
} as ICashflowTransactionCategorizedPayload
|
|
||||||
);
|
|
||||||
// Creates a new expense transaction.
|
|
||||||
const expenseTransaction = await this.createExpenseService.newExpense(
|
|
||||||
tenantId,
|
|
||||||
{
|
|
||||||
|
|
||||||
},
|
|
||||||
1
|
|
||||||
);
|
|
||||||
// Updates the item on the storage and fetches the updated once.
|
|
||||||
const cashflowTransaction = await CashflowTransaction.query(
|
|
||||||
trx
|
|
||||||
).patchAndFetchById(cashflowTransactionId, {
|
|
||||||
categorizeRefType: 'Expense',
|
|
||||||
categorizeRefId: expenseTransaction.id,
|
|
||||||
uncategorized: true,
|
|
||||||
});
|
|
||||||
// Triggers `onTransactionUncategorized` event.
|
|
||||||
await this.eventPublisher.emitAsync(
|
|
||||||
events.cashflow.onTransactionCategorizedAsExpense,
|
|
||||||
{
|
|
||||||
tenantId,
|
|
||||||
cashflowTransaction,
|
|
||||||
trx,
|
|
||||||
} as ICashflowTransactionUncategorizedPayload
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
import { includes, camelCase, upperFirst } from 'lodash';
|
import { includes, camelCase, upperFirst } from 'lodash';
|
||||||
import { IAccount, IUncategorizedCashflowTransaction } from '@/interfaces';
|
import { IAccount } from '@/interfaces';
|
||||||
import { getCashflowTransactionType } from './utils';
|
import { getCashflowTransactionType } from './utils';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import {
|
import { CASHFLOW_TRANSACTION_TYPE, ERRORS } from './constants';
|
||||||
CASHFLOW_DIRECTION,
|
|
||||||
CASHFLOW_TRANSACTION_TYPE,
|
|
||||||
ERRORS,
|
|
||||||
} from './constants';
|
|
||||||
import CashflowTransaction from '@/models/CashflowTransaction';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class CommandCashflowValidator {
|
export class CommandCashflowValidator {
|
||||||
@@ -51,52 +46,4 @@ export class CommandCashflowValidator {
|
|||||||
}
|
}
|
||||||
return transformedType;
|
return transformedType;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the given transaction should be categorized.
|
|
||||||
* @param {CashflowTransaction} cashflowTransaction
|
|
||||||
*/
|
|
||||||
public validateTransactionShouldCategorized(
|
|
||||||
cashflowTransaction: CashflowTransaction
|
|
||||||
) {
|
|
||||||
if (!cashflowTransaction.uncategorize) {
|
|
||||||
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the given transcation shouldn't be categorized.
|
|
||||||
* @param {CashflowTransaction} cashflowTransaction
|
|
||||||
*/
|
|
||||||
public validateTransactionShouldNotCategorized(
|
|
||||||
cashflowTransaction: CashflowTransaction
|
|
||||||
) {
|
|
||||||
if (cashflowTransaction.uncategorize) {
|
|
||||||
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {uncategorizeTransaction}
|
|
||||||
* @param {string} transactionType
|
|
||||||
* @throws {ServiceError(ERRORS.UNCATEGORIZED_TRANSACTION_TYPE_INVALID)}
|
|
||||||
*/
|
|
||||||
public validateUncategorizeTransactionType(
|
|
||||||
uncategorizeTransaction: IUncategorizedCashflowTransaction,
|
|
||||||
transactionType: string
|
|
||||||
) {
|
|
||||||
const type = getCashflowTransactionType(
|
|
||||||
upperFirst(camelCase(transactionType)) as CASHFLOW_TRANSACTION_TYPE
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
(type.direction === CASHFLOW_DIRECTION.IN &&
|
|
||||||
uncategorizeTransaction.isDepositTransaction) ||
|
|
||||||
(type.direction === CASHFLOW_DIRECTION.OUT &&
|
|
||||||
uncategorizeTransaction.isWithdrawalTransaction)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new ServiceError(ERRORS.UNCATEGORIZED_TRANSACTION_TYPE_INVALID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
|
||||||
import UnitOfWork, { IsolationLevel } from '../UnitOfWork';
|
|
||||||
import { Knex } from 'knex';
|
|
||||||
import { CreateUncategorizedTransactionDTO } from '@/interfaces';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class CreateUncategorizedTransaction {
|
|
||||||
@Inject()
|
|
||||||
private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private uow: UnitOfWork;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an uncategorized cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {CreateUncategorizedTransactionDTO} createDTO
|
|
||||||
*/
|
|
||||||
public create(
|
|
||||||
tenantId: number,
|
|
||||||
createDTO: CreateUncategorizedTransactionDTO
|
|
||||||
) {
|
|
||||||
const { UncategorizedCashflowTransaction, Account } =
|
|
||||||
this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
return this.uow.withTransaction(
|
|
||||||
tenantId,
|
|
||||||
async (trx: Knex.Transaction) => {
|
|
||||||
const transaction = await UncategorizedCashflowTransaction.query(
|
|
||||||
trx
|
|
||||||
).insertAndFetch({
|
|
||||||
...createDTO,
|
|
||||||
});
|
|
||||||
|
|
||||||
return transaction;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,15 +13,15 @@ import UnitOfWork from '@/services/UnitOfWork';
|
|||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class DeleteCashflowTransaction {
|
export default class CommandCashflowTransactionService {
|
||||||
@Inject()
|
@Inject()
|
||||||
private tenancy: HasTenancyService;
|
tenancy: HasTenancyService;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private eventPublisher: EventPublisher;
|
eventPublisher: EventPublisher;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private uow: UnitOfWork;
|
uow: UnitOfWork;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the cashflow transaction with associated journal entries.
|
* Deletes the cashflow transaction with associated journal entries.
|
||||||
|
|||||||
@@ -4,13 +4,17 @@ import { CashflowTransactionTransformer } from './CashflowTransactionTransformer
|
|||||||
import { ERRORS } from './constants';
|
import { ERRORS } from './constants';
|
||||||
import { ICashflowTransaction } from '@/interfaces';
|
import { ICashflowTransaction } from '@/interfaces';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
|
import I18nService from '@/services/I18n/I18nService';
|
||||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class GetCashflowTransactionService {
|
export default class GetCashflowTransactionsService {
|
||||||
@Inject()
|
@Inject()
|
||||||
private tenancy: HasTenancyService;
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private i18nService: I18nService;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private transfromer: TransformerInjectable;
|
private transfromer: TransformerInjectable;
|
||||||
|
|
||||||
@@ -31,7 +35,6 @@ export class GetCashflowTransactionService {
|
|||||||
.withGraphFetched('entries.cashflowAccount')
|
.withGraphFetched('entries.cashflowAccount')
|
||||||
.withGraphFetched('entries.creditAccount')
|
.withGraphFetched('entries.creditAccount')
|
||||||
.withGraphFetched('transactions.account')
|
.withGraphFetched('transactions.account')
|
||||||
.orderBy('date', 'DESC')
|
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
this.throwErrorCashflowTranscationNotFound(cashflowTransaction);
|
this.throwErrorCashflowTranscationNotFound(cashflowTransaction);
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
|
||||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
|
||||||
import { UncategorizedTransactionTransformer } from './UncategorizedTransactionTransformer';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class GetUncategorizedTransaction {
|
|
||||||
@Inject()
|
|
||||||
private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private transformer: TransformerInjectable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves specific uncategorized cashflow transaction.
|
|
||||||
* @param {number} tenantId - Tenant id.
|
|
||||||
* @param {number} uncategorizedTransactionId - Uncategorized transaction id.
|
|
||||||
*/
|
|
||||||
public async getTransaction(
|
|
||||||
tenantId: number,
|
|
||||||
uncategorizedTransactionId: number
|
|
||||||
) {
|
|
||||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
const transaction = await UncategorizedCashflowTransaction.query()
|
|
||||||
.findById(uncategorizedTransactionId)
|
|
||||||
.withGraphFetched('account')
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
return this.transformer.transform(
|
|
||||||
tenantId,
|
|
||||||
transaction,
|
|
||||||
new UncategorizedTransactionTransformer()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
|
||||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
|
||||||
import { UncategorizedTransactionTransformer } from './UncategorizedTransactionTransformer';
|
|
||||||
import { IGetUncategorizedTransactionsQuery } from '@/interfaces';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class GetUncategorizedTransactions {
|
|
||||||
@Inject()
|
|
||||||
private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private transformer: TransformerInjectable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the uncategorized cashflow transactions.
|
|
||||||
* @param {number} tenantId - Tenant id.
|
|
||||||
* @param {number} accountId - Account Id.
|
|
||||||
*/
|
|
||||||
public async getTransactions(
|
|
||||||
tenantId: number,
|
|
||||||
accountId: number,
|
|
||||||
query: IGetUncategorizedTransactionsQuery
|
|
||||||
) {
|
|
||||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
// Parsed query with default values.
|
|
||||||
const _query = {
|
|
||||||
page: 1,
|
|
||||||
pageSize: 20,
|
|
||||||
...query,
|
|
||||||
};
|
|
||||||
const { results, pagination } =
|
|
||||||
await UncategorizedCashflowTransaction.query()
|
|
||||||
.where('accountId', accountId)
|
|
||||||
.where('categorized', false)
|
|
||||||
.withGraphFetched('account')
|
|
||||||
.orderBy('date', 'DESC')
|
|
||||||
.pagination(_query.page - 1, _query.pageSize);
|
|
||||||
|
|
||||||
const data = await this.transformer.transform(
|
|
||||||
tenantId,
|
|
||||||
results,
|
|
||||||
new UncategorizedTransactionTransformer()
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
data,
|
|
||||||
pagination,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { pick } from 'lodash';
|
import { isEmpty, pick } from 'lodash';
|
||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import {
|
import {
|
||||||
ICashflowNewCommandDTO,
|
ICashflowNewCommandDTO,
|
||||||
ICashflowTransaction,
|
ICashflowTransaction,
|
||||||
|
ICashflowTransactionLine,
|
||||||
ICommandCashflowCreatedPayload,
|
ICommandCashflowCreatedPayload,
|
||||||
ICommandCashflowCreatingPayload,
|
ICommandCashflowCreatingPayload,
|
||||||
ICashflowTransactionInput,
|
ICashflowTransactionInput,
|
||||||
@@ -125,7 +126,7 @@ export default class NewCashflowTransactionService {
|
|||||||
tenantId: number,
|
tenantId: number,
|
||||||
newTransactionDTO: ICashflowNewCommandDTO,
|
newTransactionDTO: ICashflowNewCommandDTO,
|
||||||
userId?: number
|
userId?: number
|
||||||
): Promise<ICashflowTransaction> => {
|
): Promise<{ cashflowTransaction: ICashflowTransaction }> => {
|
||||||
const { CashflowTransaction, Account } = this.tenancy.models(tenantId);
|
const { CashflowTransaction, Account } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
// Retrieves the cashflow account or throw not found error.
|
// Retrieves the cashflow account or throw not found error.
|
||||||
@@ -174,7 +175,7 @@ export default class NewCashflowTransactionService {
|
|||||||
trx,
|
trx,
|
||||||
} as ICommandCashflowCreatedPayload
|
} as ICommandCashflowCreatedPayload
|
||||||
);
|
);
|
||||||
return cashflowTransaction;
|
return { cashflowTransaction };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import { Knex } from 'knex';
|
|
||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
|
||||||
import UnitOfWork from '../UnitOfWork';
|
|
||||||
import events from '@/subscribers/events';
|
|
||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
|
||||||
import {
|
|
||||||
ICashflowTransactionUncategorizedPayload,
|
|
||||||
ICashflowTransactionUncategorizingPayload,
|
|
||||||
} from '@/interfaces';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class UncategorizeCashflowTransaction {
|
|
||||||
@Inject()
|
|
||||||
private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private eventPublisher: EventPublisher;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private uow: UnitOfWork;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uncategorizes the given cashflow transaction.
|
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} cashflowTransactionId
|
|
||||||
*/
|
|
||||||
public async uncategorize(
|
|
||||||
tenantId: number,
|
|
||||||
uncategorizedTransactionId: number
|
|
||||||
) {
|
|
||||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
const oldUncategorizedTransaction =
|
|
||||||
await UncategorizedCashflowTransaction.query()
|
|
||||||
.findById(uncategorizedTransactionId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
// Updates the transaction under UOW.
|
|
||||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
|
||||||
// Triggers `onTransactionUncategorizing` event.
|
|
||||||
await this.eventPublisher.emitAsync(
|
|
||||||
events.cashflow.onTransactionUncategorizing,
|
|
||||||
{
|
|
||||||
tenantId,
|
|
||||||
trx,
|
|
||||||
} as ICashflowTransactionUncategorizingPayload
|
|
||||||
);
|
|
||||||
// Removes the ref relation with the related transaction.
|
|
||||||
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,
|
|
||||||
uncategorizedTransaction,
|
|
||||||
oldUncategorizedTransaction,
|
|
||||||
trx,
|
|
||||||
} as ICashflowTransactionUncategorizedPayload
|
|
||||||
);
|
|
||||||
return uncategorizedTransaction;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
|
||||||
import { formatNumber } from '@/utils';
|
|
||||||
|
|
||||||
export class UncategorizedTransactionTransformer extends Transformer {
|
|
||||||
/**
|
|
||||||
* Include these attributes to sale invoice object.
|
|
||||||
* @returns {string[]}
|
|
||||||
*/
|
|
||||||
public includeAttributes = (): string[] => {
|
|
||||||
return [
|
|
||||||
'formattedAmount',
|
|
||||||
'formattedDate',
|
|
||||||
'formattetDepositAmount',
|
|
||||||
'formattedWithdrawalAmount',
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formattes the transaction date.
|
|
||||||
* @param transaction
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
public formattedDate(transaction) {
|
|
||||||
return this.formatDate(transaction.date);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatted amount.
|
|
||||||
* @param transaction
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
public formattedAmount(transaction) {
|
|
||||||
return formatNumber(transaction.amount, {
|
|
||||||
currencyCode: transaction.currencyCode,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatted deposit amount.
|
|
||||||
* @param transaction
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
protected formattetDepositAmount(transaction) {
|
|
||||||
if (transaction.isDepositTransaction) {
|
|
||||||
return formatNumber(transaction.deposit, {
|
|
||||||
currencyCode: transaction.currencyCode,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatted withdrawal amount.
|
|
||||||
* @param transaction
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
protected formattedWithdrawalAmount(transaction) {
|
|
||||||
if (transaction.isWithdrawalTransaction) {
|
|
||||||
return formatNumber(transaction.withdrawal, {
|
|
||||||
currencyCode: transaction.currencyCode,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,10 +8,7 @@ export const ERRORS = {
|
|||||||
CREDIT_ACCOUNTS_IDS_NOT_FOUND: 'CREDIT_ACCOUNTS_IDS_NOT_FOUND',
|
CREDIT_ACCOUNTS_IDS_NOT_FOUND: 'CREDIT_ACCOUNTS_IDS_NOT_FOUND',
|
||||||
CREDIT_ACCOUNTS_HAS_INVALID_TYPE: 'CREDIT_ACCOUNTS_HAS_INVALID_TYPE',
|
CREDIT_ACCOUNTS_HAS_INVALID_TYPE: 'CREDIT_ACCOUNTS_HAS_INVALID_TYPE',
|
||||||
ACCOUNT_ID_HAS_INVALID_TYPE: 'ACCOUNT_ID_HAS_INVALID_TYPE',
|
ACCOUNT_ID_HAS_INVALID_TYPE: 'ACCOUNT_ID_HAS_INVALID_TYPE',
|
||||||
ACCOUNT_HAS_ASSOCIATED_TRANSACTIONS: 'account_has_associated_transactions',
|
ACCOUNT_HAS_ASSOCIATED_TRANSACTIONS: 'account_has_associated_transactions'
|
||||||
TRANSACTION_ALREADY_CATEGORIZED: 'TRANSACTION_ALREADY_CATEGORIZED',
|
|
||||||
TRANSACTION_ALREADY_UNCATEGORIZED: 'TRANSACTION_ALREADY_UNCATEGORIZED',
|
|
||||||
UNCATEGORIZED_TRANSACTION_TYPE_INVALID: 'UNCATEGORIZED_TRANSACTION_TYPE_INVALID'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum CASHFLOW_DIRECTION {
|
export enum CASHFLOW_DIRECTION {
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import events from '@/subscribers/events';
|
|
||||||
import { ICashflowTransactionUncategorizedPayload } from '@/interfaces';
|
|
||||||
import { DeleteCashflowTransaction } from '../DeleteCashflowTransactionService';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class DeleteCashflowTransactionOnUncategorize {
|
|
||||||
@Inject()
|
|
||||||
private deleteCashflowTransactionService: DeleteCashflowTransaction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attaches events with handlers.
|
|
||||||
*/
|
|
||||||
public attach = (bus) => {
|
|
||||||
bus.subscribe(
|
|
||||||
events.cashflow.onTransactionUncategorized,
|
|
||||||
this.deleteCashflowTransactionOnUncategorize.bind(this)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the cashflow transaction on uncategorize transaction.
|
|
||||||
* @param {ICashflowTransactionUncategorizedPayload} payload
|
|
||||||
*/
|
|
||||||
public async deleteCashflowTransactionOnUncategorize({
|
|
||||||
tenantId,
|
|
||||||
oldUncategorizedTransaction,
|
|
||||||
trx,
|
|
||||||
}: ICashflowTransactionUncategorizedPayload) {
|
|
||||||
// Deletes the cashflow transaction.
|
|
||||||
if (
|
|
||||||
oldUncategorizedTransaction.categorizeRefType === 'CashflowTransaction'
|
|
||||||
) {
|
|
||||||
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
|
|
||||||
tenantId,
|
|
||||||
oldUncategorizedTransaction.categorizeRefId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,9 @@
|
|||||||
import { upperFirst, camelCase, omit } from 'lodash';
|
import { upperFirst, camelCase } from 'lodash';
|
||||||
import {
|
import {
|
||||||
CASHFLOW_TRANSACTION_TYPE,
|
CASHFLOW_TRANSACTION_TYPE,
|
||||||
CASHFLOW_TRANSACTION_TYPE_META,
|
CASHFLOW_TRANSACTION_TYPE_META,
|
||||||
ICashflowTransactionTypeMeta,
|
ICashflowTransactionTypeMeta,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import {
|
|
||||||
ICashflowNewCommandDTO,
|
|
||||||
ICashflowTransaction,
|
|
||||||
ICategorizeCashflowTransactioDTO,
|
|
||||||
IUncategorizedCashflowTransaction,
|
|
||||||
} from '@/interfaces';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures the given transaction type to transformed to appropriate format.
|
* Ensures the given transaction type to transformed to appropriate format.
|
||||||
@@ -38,29 +32,3 @@ export function getCashflowTransactionType(
|
|||||||
export const getCashflowAccountTransactionsTypes = () => {
|
export const getCashflowAccountTransactionsTypes = () => {
|
||||||
return Object.values(CASHFLOW_TRANSACTION_TYPE_META).map((meta) => meta.type);
|
return Object.values(CASHFLOW_TRANSACTION_TYPE_META).map((meta) => meta.type);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Tranasformes the given uncategorized transaction and categorized DTO
|
|
||||||
* to cashflow create DTO.
|
|
||||||
* @param {IUncategorizedCashflowTransaction} uncategorizeModel
|
|
||||||
* @param {ICategorizeCashflowTransactioDTO} categorizeDTO
|
|
||||||
* @returns {ICashflowNewCommandDTO}
|
|
||||||
*/
|
|
||||||
export const transformCategorizeTransToCashflow = (
|
|
||||||
uncategorizeModel: IUncategorizedCashflowTransaction,
|
|
||||||
categorizeDTO: ICategorizeCashflowTransactioDTO
|
|
||||||
): ICashflowNewCommandDTO => {
|
|
||||||
return {
|
|
||||||
date: uncategorizeModel.date,
|
|
||||||
referenceNo: categorizeDTO.referenceNo || uncategorizeModel.referenceNo,
|
|
||||||
description: categorizeDTO.description || uncategorizeModel.description,
|
|
||||||
cashflowAccountId: uncategorizeModel.accountId,
|
|
||||||
creditAccountId: categorizeDTO.creditAccountId,
|
|
||||||
exchangeRate: categorizeDTO.exchangeRate || 1,
|
|
||||||
currencyCode: uncategorizeModel.currencyCode,
|
|
||||||
amount: uncategorizeModel.amount,
|
|
||||||
transactionNumber: categorizeDTO.transactionNumber,
|
|
||||||
transactionType: categorizeDTO.transactionType,
|
|
||||||
publish: true,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -392,15 +392,6 @@ export default {
|
|||||||
|
|
||||||
onTransactionDeleting: 'onCashflowTransactionDeleting',
|
onTransactionDeleting: 'onCashflowTransactionDeleting',
|
||||||
onTransactionDeleted: 'onCashflowTransactionDeleted',
|
onTransactionDeleted: 'onCashflowTransactionDeleted',
|
||||||
|
|
||||||
onTransactionCategorizing: 'onTransactionCategorizing',
|
|
||||||
onTransactionCategorized: 'onCashflowTransactionCategorized',
|
|
||||||
|
|
||||||
onTransactionUncategorizing: 'onTransactionUncategorizing',
|
|
||||||
onTransactionUncategorized: 'onTransactionUncategorized',
|
|
||||||
|
|
||||||
onTransactionCategorizingAsExpense: 'onTransactionCategorizingAsExpense',
|
|
||||||
onTransactionCategorizedAsExpense: 'onTransactionCategorizedAsExpense',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,111 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { useUncontrolled } from '@/hooks/useUncontrolled';
|
|
||||||
|
|
||||||
const ContentTabsRoot = styled('div')`
|
|
||||||
display: flex;
|
|
||||||
gap: 10px;
|
|
||||||
`;
|
|
||||||
interface ContentTabItemRootProps {
|
|
||||||
active?: boolean;
|
|
||||||
}
|
|
||||||
const ContentTabItemRoot = styled.button<ContentTabItemRootProps>`
|
|
||||||
flex: 1 0;
|
|
||||||
background: #fff;
|
|
||||||
border: 1px solid #e1e2e8;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 11px;
|
|
||||||
text-align: left;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
${(props) =>
|
|
||||||
props.active &&
|
|
||||||
`
|
|
||||||
border-color: #1552c8;
|
|
||||||
box-shadow: 0 0 0 0.25px #1552c8;
|
|
||||||
|
|
||||||
${ContentTabTitle} {
|
|
||||||
color: #1552c8;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
${ContentTabDesc} {
|
|
||||||
color: #1552c8;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
&:hover,
|
|
||||||
&:active {
|
|
||||||
border-color: #1552c8;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
const ContentTabTitle = styled('h3')`
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 400;
|
|
||||||
color: #2f343c;
|
|
||||||
`;
|
|
||||||
const ContentTabDesc = styled('p')`
|
|
||||||
margin: 0;
|
|
||||||
color: #5f6b7c;
|
|
||||||
margin-top: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
interface ContentTabsItemProps {
|
|
||||||
id: string;
|
|
||||||
title?: React.ReactNode;
|
|
||||||
description?: React.ReactNode;
|
|
||||||
active?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ContentTabsItem = ({
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
active,
|
|
||||||
onClick,
|
|
||||||
}: ContentTabsItemProps) => {
|
|
||||||
return (
|
|
||||||
<ContentTabItemRoot active={active} onClick={onClick}>
|
|
||||||
<ContentTabTitle>{title}</ContentTabTitle>
|
|
||||||
<ContentTabDesc>{description}</ContentTabDesc>
|
|
||||||
</ContentTabItemRoot>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ContentTabsProps {
|
|
||||||
initialValue?: string;
|
|
||||||
value?: string;
|
|
||||||
onChange?: (value: string) => void;
|
|
||||||
children?: React.ReactNode;
|
|
||||||
className?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ContentTabs({
|
|
||||||
initialValue,
|
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
}: ContentTabsProps) {
|
|
||||||
const [localValue, handleItemChange] = useUncontrolled<string>({
|
|
||||||
initialValue,
|
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
finalValue: '',
|
|
||||||
});
|
|
||||||
const tabs = React.Children.toArray(children);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ContentTabsRoot className={className}>
|
|
||||||
{tabs.map((tab) => (
|
|
||||||
<ContentTabsItem
|
|
||||||
key={tab.key}
|
|
||||||
{...tab.props}
|
|
||||||
active={localValue === tab.props.id}
|
|
||||||
onClick={() => handleItemChange(tab.props?.id)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</ContentTabsRoot>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ContentTabs.Tab = ContentTabsItem;
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from './ContentTabs';
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import clsx from 'classnames';
|
|
||||||
import { Classes } from '@blueprintjs/core';
|
import { Classes } from '@blueprintjs/core';
|
||||||
import { LoadingIndicator } from '../Indicator';
|
import { LoadingIndicator } from '../Indicator';
|
||||||
|
|
||||||
@@ -12,8 +11,8 @@ export function DrawerLoading({ loading, mount = false, children }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DrawerBody({ children, className }) {
|
export function DrawerBody({ children }) {
|
||||||
return <div className={clsx(Classes.DRAWER_BODY, className)}>{children}</div>;
|
return <div className={Classes.DRAWER_BODY}>{children}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from './DrawerActionsBar';
|
export * from './DrawerActionsBar';
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import WarehouseTransferDetailDrawer from '@/containers/Drawers/WarehouseTransfe
|
|||||||
import TaxRateDetailsDrawer from '@/containers/TaxRates/drawers/TaxRateDetailsDrawer/TaxRateDetailsDrawer';
|
import TaxRateDetailsDrawer from '@/containers/TaxRates/drawers/TaxRateDetailsDrawer/TaxRateDetailsDrawer';
|
||||||
|
|
||||||
import { DRAWERS } from '@/constants/drawers';
|
import { DRAWERS } from '@/constants/drawers';
|
||||||
import CategorizeTransactionDrawer from '@/containers/CashFlow/CategorizeTransaction/drawers/CategorizeTransactionDrawer/CategorizeTransactionDrawer';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drawers container of the dashboard.
|
* Drawers container of the dashboard.
|
||||||
@@ -62,7 +61,6 @@ export default function DrawersContainer() {
|
|||||||
name={DRAWERS.WAREHOUSE_TRANSFER_DETAILS}
|
name={DRAWERS.WAREHOUSE_TRANSFER_DETAILS}
|
||||||
/>
|
/>
|
||||||
<TaxRateDetailsDrawer name={DRAWERS.TAX_RATE_DETAILS} />
|
<TaxRateDetailsDrawer name={DRAWERS.TAX_RATE_DETAILS} />
|
||||||
<CategorizeTransactionDrawer name={DRAWERS.CATEGORIZE_TRANSACTION} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ const SelectButton = styled(Button)`
|
|||||||
position: relative;
|
position: relative;
|
||||||
padding-right: 30px;
|
padding-right: 30px;
|
||||||
|
|
||||||
&.bp4-small {
|
&.bp4-small{
|
||||||
padding-right: 24px;
|
padding-right: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:not(.is-selected):not([class*='bp4-intent-']):not(.bp4-minimal) {
|
&:not(.is-selected):not([class*='bp4-intent-']):not(.bp4-minimal) {
|
||||||
color: #8f99a8;
|
color: #5c7080;
|
||||||
}
|
}
|
||||||
&:after {
|
&:after {
|
||||||
content: '';
|
content: '';
|
||||||
|
|||||||
@@ -23,5 +23,4 @@ export enum DRAWERS {
|
|||||||
REFUND_VENDOR_CREDIT_DETAILS = 'refund-vendor-detail-drawer',
|
REFUND_VENDOR_CREDIT_DETAILS = 'refund-vendor-detail-drawer',
|
||||||
WAREHOUSE_TRANSFER_DETAILS = 'warehouse-transfer-detail-drawer',
|
WAREHOUSE_TRANSFER_DETAILS = 'warehouse-transfer-detail-drawer',
|
||||||
TAX_RATE_DETAILS = 'tax-rate-detail-drawer',
|
TAX_RATE_DETAILS = 'tax-rate-detail-drawer',
|
||||||
CATEGORIZE_TRANSACTION = 'categorize-transaction',
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ export const TABLES = {
|
|||||||
EXPENSES: 'expenses',
|
EXPENSES: 'expenses',
|
||||||
CASHFLOW_ACCOUNTS: 'cashflow_accounts',
|
CASHFLOW_ACCOUNTS: 'cashflow_accounts',
|
||||||
CASHFLOW_Transactions: 'cashflow_transactions',
|
CASHFLOW_Transactions: 'cashflow_transactions',
|
||||||
UNCATEGORIZED_CASHFLOW_TRANSACTION: 'UNCATEGORIZED_CASHFLOW_TRANSACTION',
|
|
||||||
CREDIT_NOTES: 'credit_notes',
|
CREDIT_NOTES: 'credit_notes',
|
||||||
VENDOR_CREDITS: 'vendor_credits',
|
VENDOR_CREDITS: 'vendor_credits',
|
||||||
WAREHOUSE_TRANSFERS: 'warehouse_transfers',
|
WAREHOUSE_TRANSFERS: 'warehouse_transfers',
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import { flatten, map } from 'lodash';
|
|
||||||
import { IntersectionObserver } from '@/components';
|
|
||||||
import { useAccountTransactionsInfinity } from '@/hooks/query';
|
|
||||||
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
|
|
||||||
|
|
||||||
const AccountTransactionsAllBootContext = React.createContext();
|
|
||||||
|
|
||||||
function flattenInfinityPages(data) {
|
|
||||||
return flatten(map(data.pages, (page) => page.transactions));
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AccountTransactionsAllPoviderProps {
|
|
||||||
children: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Account transctions all provider.
|
|
||||||
*/
|
|
||||||
function AccountTransactionsAllProvider({
|
|
||||||
children,
|
|
||||||
}: AccountTransactionsAllPoviderProps) {
|
|
||||||
const { accountId } = useAccountTransactionsContext();
|
|
||||||
|
|
||||||
// Fetch cashflow account transactions list
|
|
||||||
const {
|
|
||||||
data: cashflowTransactionsPages,
|
|
||||||
isFetching: isCashFlowTransactionsFetching,
|
|
||||||
isLoading: isCashFlowTransactionsLoading,
|
|
||||||
isSuccess: isCashflowTransactionsSuccess,
|
|
||||||
fetchNextPage: fetchNextTransactionsPage,
|
|
||||||
isFetchingNextPage: isCashflowTransactionsFetchingNextPage,
|
|
||||||
hasNextPage: hasCashflowTransactionsNextPgae,
|
|
||||||
} = useAccountTransactionsInfinity(accountId, {
|
|
||||||
page_size: 50,
|
|
||||||
account_id: accountId,
|
|
||||||
});
|
|
||||||
// Memorized the cashflow account transactions.
|
|
||||||
const cashflowTransactions = React.useMemo(
|
|
||||||
() =>
|
|
||||||
isCashflowTransactionsSuccess
|
|
||||||
? flattenInfinityPages(cashflowTransactionsPages)
|
|
||||||
: [],
|
|
||||||
[cashflowTransactionsPages, isCashflowTransactionsSuccess],
|
|
||||||
);
|
|
||||||
// Handle the observer ineraction.
|
|
||||||
const handleObserverInteract = React.useCallback(() => {
|
|
||||||
if (!isCashFlowTransactionsFetching && hasCashflowTransactionsNextPgae) {
|
|
||||||
fetchNextTransactionsPage();
|
|
||||||
}
|
|
||||||
}, [
|
|
||||||
isCashFlowTransactionsFetching,
|
|
||||||
hasCashflowTransactionsNextPgae,
|
|
||||||
fetchNextTransactionsPage,
|
|
||||||
]);
|
|
||||||
// Provider payload.
|
|
||||||
const provider = {
|
|
||||||
cashflowTransactions,
|
|
||||||
isCashFlowTransactionsFetching,
|
|
||||||
isCashFlowTransactionsLoading,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AccountTransactionsAllBootContext.Provider value={provider}>
|
|
||||||
{children}
|
|
||||||
<IntersectionObserver
|
|
||||||
onIntersect={handleObserverInteract}
|
|
||||||
enabled={!isCashflowTransactionsFetchingNextPage}
|
|
||||||
/>
|
|
||||||
</AccountTransactionsAllBootContext.Provider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const useAccountTransactionsAllContext = () =>
|
|
||||||
React.useContext(AccountTransactionsAllBootContext);
|
|
||||||
|
|
||||||
export { AccountTransactionsAllProvider, useAccountTransactionsAllContext };
|
|
||||||
@@ -18,10 +18,10 @@ import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
|||||||
|
|
||||||
import { useMemorizedColumnsWidths } from '@/hooks';
|
import { useMemorizedColumnsWidths } from '@/hooks';
|
||||||
import { useAccountTransactionsColumns, ActionsMenu } from './components';
|
import { useAccountTransactionsColumns, ActionsMenu } from './components';
|
||||||
|
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
|
||||||
import { handleCashFlowTransactionType } from './utils';
|
import { handleCashFlowTransactionType } from './utils';
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
import { useAccountTransactionsAllContext } from './AccountTransactionsAllBoot';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account transactions data table.
|
* Account transactions data table.
|
||||||
@@ -41,7 +41,7 @@ function AccountTransactionsDataTable({
|
|||||||
|
|
||||||
// Retrieve list context.
|
// Retrieve list context.
|
||||||
const { cashflowTransactions, isCashFlowTransactionsLoading } =
|
const { cashflowTransactions, isCashFlowTransactionsLoading } =
|
||||||
useAccountTransactionsAllContext();
|
useAccountTransactionsContext();
|
||||||
|
|
||||||
// Local storage memorizing columns widths.
|
// Local storage memorizing columns widths.
|
||||||
const [initialColumnsWidths, , handleColumnResizing] =
|
const [initialColumnsWidths, , handleColumnResizing] =
|
||||||
@@ -51,10 +51,11 @@ function AccountTransactionsDataTable({
|
|||||||
const handleDeleteTransaction = ({ reference_id }) => {
|
const handleDeleteTransaction = ({ reference_id }) => {
|
||||||
openAlert('account-transaction-delete', { referenceId: reference_id });
|
openAlert('account-transaction-delete', { referenceId: reference_id });
|
||||||
};
|
};
|
||||||
// Handle view details action.
|
|
||||||
const handleViewDetailCashflowTransaction = (referenceType) => {
|
const handleViewDetailCashflowTransaction = (referenceType) => {
|
||||||
handleCashFlowTransactionType(referenceType, openDrawer);
|
handleCashFlowTransactionType(referenceType, openDrawer);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle cell click.
|
// Handle cell click.
|
||||||
const handleCellClick = (cell, event) => {
|
const handleCellClick = (cell, event) => {
|
||||||
const referenceType = cell.row.original;
|
const referenceType = cell.row.original;
|
||||||
|
|||||||
@@ -84,18 +84,6 @@ function AccountBankBalanceItem() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AccountNumberItem() {
|
|
||||||
const { currentAccount } = useAccountTransactionsContext();
|
|
||||||
|
|
||||||
if (!currentAccount.account_mask) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AccountBalanceItemWrap>
|
|
||||||
Account Number: xxx{currentAccount.account_mask}
|
|
||||||
</AccountBalanceItemWrap>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function AccountTransactionsDetailsBarSkeleton() {
|
function AccountTransactionsDetailsBarSkeleton() {
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
@@ -113,7 +101,6 @@ function AccountTransactionsDetailsContent() {
|
|||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<AccountSwitchItem />
|
<AccountSwitchItem />
|
||||||
<AccountNumberItem />
|
|
||||||
<AccountBalanceItem />
|
<AccountBalanceItem />
|
||||||
<AccountBankBalanceItem />
|
<AccountBankBalanceItem />
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { ContentTabs } from '@/components/ContentTabs/ContentTabs';
|
|
||||||
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
|
|
||||||
|
|
||||||
const AccountContentTabs = styled(ContentTabs)`
|
|
||||||
margin: 15px 15px 0 15px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export function AccountTransactionsFilterTabs() {
|
|
||||||
const { filterTab, setFilterTab, currentAccount } =
|
|
||||||
useAccountTransactionsContext();
|
|
||||||
|
|
||||||
const handleChange = (value) => {
|
|
||||||
setFilterTab(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
const hasUncategorizedTransx = Boolean(
|
|
||||||
currentAccount.uncategorized_transactions,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AccountContentTabs value={filterTab} onChange={handleChange}>
|
|
||||||
<ContentTabs.Tab
|
|
||||||
id={'dashboard'}
|
|
||||||
title={'Dashboard'}
|
|
||||||
description={'Account Summary'}
|
|
||||||
/>
|
|
||||||
{hasUncategorizedTransx && (
|
|
||||||
<ContentTabs.Tab
|
|
||||||
id={'uncategorized'}
|
|
||||||
title={
|
|
||||||
<>
|
|
||||||
<span style={{ color: '#ff0000' }}>
|
|
||||||
{currentAccount.uncategorized_transactions}
|
|
||||||
</span>{' '}
|
|
||||||
Uncategorized Transactions
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
description={'For Bank Statement'}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<ContentTabs.Tab
|
|
||||||
id="all"
|
|
||||||
title={'All Transactions'}
|
|
||||||
description={'In Bigcapital'}
|
|
||||||
/>
|
|
||||||
</AccountContentTabs>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,16 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { Suspense } from 'react';
|
import React from 'react';
|
||||||
import { Spinner } from '@blueprintjs/core';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import '@/style/pages/CashFlow/AccountTransactions/List.scss';
|
import '@/style/pages/CashFlow/AccountTransactions/List.scss';
|
||||||
|
|
||||||
import { DashboardPageContent } from '@/components';
|
import { DashboardPageContent } from '@/components';
|
||||||
|
|
||||||
import AccountTransactionsActionsBar from './AccountTransactionsActionsBar';
|
import AccountTransactionsActionsBar from './AccountTransactionsActionsBar';
|
||||||
import {
|
import AccountTransactionsDataTable from './AccountTransactionsDataTable';
|
||||||
AccountTransactionsProvider,
|
import { AccountTransactionsProvider } from './AccountTransactionsProvider';
|
||||||
useAccountTransactionsContext,
|
|
||||||
} from './AccountTransactionsProvider';
|
|
||||||
import { AccountTransactionsDetailsBar } from './AccountTransactionsDetailsBar';
|
import { AccountTransactionsDetailsBar } from './AccountTransactionsDetailsBar';
|
||||||
import { AccountTransactionsProgressBar } from './components';
|
import { AccountTransactionsProgressBar } from './components';
|
||||||
import { AccountTransactionsFilterTabs } from './AccountTransactionsFilterTabs';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account transactions list.
|
* Account transactions list.
|
||||||
@@ -26,11 +23,9 @@ function AccountTransactionsList() {
|
|||||||
<AccountTransactionsProgressBar />
|
<AccountTransactionsProgressBar />
|
||||||
|
|
||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<AccountTransactionsFilterTabs />
|
<CashflowTransactionsTableCard>
|
||||||
|
<AccountTransactionsDataTable />
|
||||||
<Suspense fallback={<Spinner size={30} />}>
|
</CashflowTransactionsTableCard>
|
||||||
<AccountTransactionsContent />
|
|
||||||
</Suspense>
|
|
||||||
</DashboardPageContent>
|
</DashboardPageContent>
|
||||||
</AccountTransactionsProvider>
|
</AccountTransactionsProvider>
|
||||||
);
|
);
|
||||||
@@ -38,20 +33,11 @@ function AccountTransactionsList() {
|
|||||||
|
|
||||||
export default AccountTransactionsList;
|
export default AccountTransactionsList;
|
||||||
|
|
||||||
const AccountsTransactionsAll = React.lazy(
|
const CashflowTransactionsTableCard = styled.div`
|
||||||
() => import('./AccountsTransactionsAll'),
|
border: 2px solid #f0f0f0;
|
||||||
);
|
border-radius: 10px;
|
||||||
|
padding: 30px 18px;
|
||||||
const AccountsTransactionsUncategorized = React.lazy(
|
margin: 30px 15px;
|
||||||
() => import('./AllTransactionsUncategorized'),
|
background: #fff;
|
||||||
);
|
flex: 0 1;
|
||||||
|
`;
|
||||||
function AccountTransactionsContent() {
|
|
||||||
const { filterTab } = useAccountTransactionsContext();
|
|
||||||
|
|
||||||
return filterTab === 'uncategorized' ? (
|
|
||||||
<AccountsTransactionsUncategorized />
|
|
||||||
) : (
|
|
||||||
<AccountsTransactionsAll />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { DashboardInsider } from '@/components';
|
import { flatten, map } from 'lodash';
|
||||||
import { useCashflowAccounts, useAccount } from '@/hooks/query';
|
import { IntersectionObserver, DashboardInsider } from '@/components';
|
||||||
import { useAppQueryString } from '@/hooks';
|
import {
|
||||||
|
useAccountTransactionsInfinity,
|
||||||
|
useCashflowAccounts,
|
||||||
|
useAccount,
|
||||||
|
} from '@/hooks/query';
|
||||||
|
|
||||||
const AccountTransactionsContext = React.createContext();
|
const AccountTransactionsContext = React.createContext();
|
||||||
|
|
||||||
|
function flattenInfinityPages(data) {
|
||||||
|
return flatten(map(data.pages, (page) => page.transactions));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account transctions provider.
|
* Account transctions provider.
|
||||||
*/
|
*/
|
||||||
@@ -14,12 +22,29 @@ function AccountTransactionsProvider({ query, ...props }) {
|
|||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const accountId = parseInt(id, 10);
|
const accountId = parseInt(id, 10);
|
||||||
|
|
||||||
const [locationQuery, setLocationQuery] = useAppQueryString();
|
// Fetch cashflow account transactions list
|
||||||
|
const {
|
||||||
|
data: cashflowTransactionsPages,
|
||||||
|
isFetching: isCashFlowTransactionsFetching,
|
||||||
|
isLoading: isCashFlowTransactionsLoading,
|
||||||
|
isSuccess: isCashflowTransactionsSuccess,
|
||||||
|
fetchNextPage: fetchNextTransactionsPage,
|
||||||
|
isFetchingNextPage,
|
||||||
|
hasNextPage,
|
||||||
|
} = useAccountTransactionsInfinity(accountId, {
|
||||||
|
page_size: 50,
|
||||||
|
account_id: accountId,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Memorized the cashflow account transactions.
|
||||||
|
const cashflowTransactions = React.useMemo(
|
||||||
|
() =>
|
||||||
|
isCashflowTransactionsSuccess
|
||||||
|
? flattenInfinityPages(cashflowTransactionsPages)
|
||||||
|
: [],
|
||||||
|
[cashflowTransactionsPages, isCashflowTransactionsSuccess],
|
||||||
|
);
|
||||||
|
|
||||||
const filterTab = locationQuery?.filter || 'all';
|
|
||||||
const setFilterTab = (value: string) => {
|
|
||||||
setLocationQuery({ filter: value });
|
|
||||||
};
|
|
||||||
// Fetch cashflow accounts.
|
// Fetch cashflow accounts.
|
||||||
const {
|
const {
|
||||||
data: cashflowAccounts,
|
data: cashflowAccounts,
|
||||||
@@ -28,31 +53,40 @@ function AccountTransactionsProvider({ query, ...props }) {
|
|||||||
} = useCashflowAccounts(query, { keepPreviousData: true });
|
} = useCashflowAccounts(query, { keepPreviousData: true });
|
||||||
|
|
||||||
// Retrieve specific account details.
|
// Retrieve specific account details.
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: currentAccount,
|
data: currentAccount,
|
||||||
isFetching: isCurrentAccountFetching,
|
isFetching: isCurrentAccountFetching,
|
||||||
isLoading: isCurrentAccountLoading,
|
isLoading: isCurrentAccountLoading,
|
||||||
} = useAccount(accountId, { keepPreviousData: true });
|
} = useAccount(accountId, { keepPreviousData: true });
|
||||||
|
|
||||||
|
// Handle the observer ineraction.
|
||||||
|
const handleObserverInteract = React.useCallback(() => {
|
||||||
|
if (!isFetchingNextPage && hasNextPage) {
|
||||||
|
fetchNextTransactionsPage();
|
||||||
|
}
|
||||||
|
}, [isFetchingNextPage, hasNextPage, fetchNextTransactionsPage]);
|
||||||
|
|
||||||
// Provider payload.
|
// Provider payload.
|
||||||
const provider = {
|
const provider = {
|
||||||
accountId,
|
accountId,
|
||||||
|
cashflowTransactions,
|
||||||
cashflowAccounts,
|
cashflowAccounts,
|
||||||
currentAccount,
|
currentAccount,
|
||||||
|
isCashFlowTransactionsFetching,
|
||||||
|
isCashFlowTransactionsLoading,
|
||||||
isCashFlowAccountsFetching,
|
isCashFlowAccountsFetching,
|
||||||
isCashFlowAccountsLoading,
|
isCashFlowAccountsLoading,
|
||||||
isCurrentAccountFetching,
|
isCurrentAccountFetching,
|
||||||
isCurrentAccountLoading,
|
isCurrentAccountLoading,
|
||||||
|
|
||||||
filterTab,
|
|
||||||
setFilterTab,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardInsider name={'account-transactions'}>
|
<DashboardInsider name={'account-transactions'}>
|
||||||
<AccountTransactionsContext.Provider value={provider} {...props} />
|
<AccountTransactionsContext.Provider value={provider} {...props} />
|
||||||
|
<IntersectionObserver
|
||||||
|
onIntersect={handleObserverInteract}
|
||||||
|
enabled={!isFetchingNextPage}
|
||||||
|
/>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { Tag } from '@blueprintjs/core';
|
|
||||||
|
|
||||||
const Root = styled.div`
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
gap: 10px;
|
|
||||||
margin-bottom: 18px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const FilterTag = styled(Tag)`
|
|
||||||
min-height: 26px;
|
|
||||||
|
|
||||||
&.bp4-minimal:not([class*='bp4-intent-']) {
|
|
||||||
background: #fff;
|
|
||||||
border: 1px solid #e1e2e8;
|
|
||||||
|
|
||||||
&.bp4-interactive:hover {
|
|
||||||
background-color: rgba(143, 153, 168, 0.05);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export function AccountTransactionsUncategorizeFilter() {
|
|
||||||
return (
|
|
||||||
<Root>
|
|
||||||
<FilterTag round interactive>
|
|
||||||
All <strong>(2)</strong>
|
|
||||||
</FilterTag>
|
|
||||||
<FilterTag round minimal interactive>
|
|
||||||
Recognized <strong>(0)</strong>
|
|
||||||
</FilterTag>
|
|
||||||
</Root>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
import {
|
|
||||||
DataTable,
|
|
||||||
TableFastCell,
|
|
||||||
TableSkeletonRows,
|
|
||||||
TableSkeletonHeader,
|
|
||||||
TableVirtualizedListRows,
|
|
||||||
FormattedMessage as T,
|
|
||||||
} from '@/components';
|
|
||||||
import { TABLES } from '@/constants/tables';
|
|
||||||
|
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
|
||||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
|
||||||
|
|
||||||
import { useMemorizedColumnsWidths } from '@/hooks';
|
|
||||||
import {
|
|
||||||
ActionsMenu,
|
|
||||||
useAccountUncategorizedTransactionsColumns,
|
|
||||||
} from './components';
|
|
||||||
import { useAccountUncategorizedTransactionsContext } from './AllTransactionsUncategorizedBoot';
|
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
|
||||||
import { DRAWERS } from '@/constants/drawers';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Account transactions data table.
|
|
||||||
*/
|
|
||||||
function AccountTransactionsDataTable({
|
|
||||||
// #withSettings
|
|
||||||
cashflowTansactionsTableSize,
|
|
||||||
|
|
||||||
// #withDrawerActions
|
|
||||||
openDrawer,
|
|
||||||
}) {
|
|
||||||
// Retrieve table columns.
|
|
||||||
const columns = useAccountUncategorizedTransactionsColumns();
|
|
||||||
|
|
||||||
// Retrieve list context.
|
|
||||||
const { uncategorizedTransactions, isUncategorizedTransactionsLoading } =
|
|
||||||
useAccountUncategorizedTransactionsContext();
|
|
||||||
|
|
||||||
// Local storage memorizing columns widths.
|
|
||||||
const [initialColumnsWidths, , handleColumnResizing] =
|
|
||||||
useMemorizedColumnsWidths(TABLES.UNCATEGORIZED_CASHFLOW_TRANSACTION);
|
|
||||||
|
|
||||||
// Handle cell click.
|
|
||||||
const handleCellClick = (cell, event) => {
|
|
||||||
openDrawer(DRAWERS.CATEGORIZE_TRANSACTION, {
|
|
||||||
uncategorizedTransactionId: cell.row.original.id,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CashflowTransactionsTable
|
|
||||||
noInitialFetch={true}
|
|
||||||
columns={columns}
|
|
||||||
data={uncategorizedTransactions || []}
|
|
||||||
sticky={true}
|
|
||||||
loading={isUncategorizedTransactionsLoading}
|
|
||||||
headerLoading={isUncategorizedTransactionsLoading}
|
|
||||||
expandColumnSpace={1}
|
|
||||||
expandToggleColumn={2}
|
|
||||||
selectionColumnWidth={45}
|
|
||||||
TableCellRenderer={TableFastCell}
|
|
||||||
TableLoadingRenderer={TableSkeletonRows}
|
|
||||||
TableRowsRenderer={TableVirtualizedListRows}
|
|
||||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
|
||||||
ContextMenu={ActionsMenu}
|
|
||||||
onCellClick={handleCellClick}
|
|
||||||
// #TableVirtualizedListRows props.
|
|
||||||
vListrowHeight={cashflowTansactionsTableSize === 'small' ? 32 : 40}
|
|
||||||
vListOverscanRowCount={0}
|
|
||||||
initialColumnsWidths={initialColumnsWidths}
|
|
||||||
onColumnResizing={handleColumnResizing}
|
|
||||||
noResults={<T id={'cash_flow.account_transactions.no_results'} />}
|
|
||||||
className="table-constrant"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withSettings(({ cashflowTransactionsSettings }) => ({
|
|
||||||
cashflowTansactionsTableSize: cashflowTransactionsSettings?.tableSize,
|
|
||||||
})),
|
|
||||||
withDrawerActions,
|
|
||||||
)(AccountTransactionsDataTable);
|
|
||||||
|
|
||||||
const DashboardConstrantTable = styled(DataTable)`
|
|
||||||
.table {
|
|
||||||
.thead {
|
|
||||||
.th {
|
|
||||||
background: #fff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tbody {
|
|
||||||
.tr:last-child .td {
|
|
||||||
border-bottom: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CashflowTransactionsTable = styled(DashboardConstrantTable)`
|
|
||||||
.table .tbody {
|
|
||||||
.tbody-inner .tr.no-results {
|
|
||||||
.td {
|
|
||||||
padding: 2rem 0;
|
|
||||||
font-size: 14px;
|
|
||||||
color: #888;
|
|
||||||
font-weight: 400;
|
|
||||||
border-bottom: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tbody-inner {
|
|
||||||
.tr .td:not(:first-child) {
|
|
||||||
border-left: 1px solid #e6e6e6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.td-description {
|
|
||||||
color: #5f6b7c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
import '@/style/pages/CashFlow/AccountTransactions/List.scss';
|
|
||||||
|
|
||||||
import AccountTransactionsDataTable from './AccountTransactionsDataTable';
|
|
||||||
import { AccountTransactionsUncategorizeFilter } from './AccountTransactionsUncategorizeFilter';
|
|
||||||
import { AccountTransactionsAllProvider } from './AccountTransactionsAllBoot';
|
|
||||||
|
|
||||||
const Box = styled.div`
|
|
||||||
margin: 30px 15px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CashflowTransactionsTableCard = styled.div`
|
|
||||||
border: 2px solid #f0f0f0;
|
|
||||||
border-radius: 10px;
|
|
||||||
padding: 30px 18px;
|
|
||||||
background: #fff;
|
|
||||||
flex: 0 1;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default function AccountTransactionsAll() {
|
|
||||||
return (
|
|
||||||
<AccountTransactionsAllProvider>
|
|
||||||
<Box>
|
|
||||||
<AccountTransactionsUncategorizeFilter />
|
|
||||||
|
|
||||||
<CashflowTransactionsTableCard>
|
|
||||||
<AccountTransactionsDataTable />
|
|
||||||
</CashflowTransactionsTableCard>
|
|
||||||
</Box>
|
|
||||||
</AccountTransactionsAllProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
import '@/style/pages/CashFlow/AccountTransactions/List.scss';
|
|
||||||
|
|
||||||
import AccountTransactionsUncategorizedTable from './AccountTransactionsUncategorizedTable';
|
|
||||||
import { AccountUncategorizedTransactionsBoot } from './AllTransactionsUncategorizedBoot';
|
|
||||||
|
|
||||||
const Box = styled.div`
|
|
||||||
margin: 30px 15px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CashflowTransactionsTableCard = styled.div`
|
|
||||||
border: 2px solid #f0f0f0;
|
|
||||||
border-radius: 10px;
|
|
||||||
padding: 30px 18px;
|
|
||||||
background: #fff;
|
|
||||||
flex: 0 1;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default function AllTransactionsUncategorized() {
|
|
||||||
return (
|
|
||||||
<AccountUncategorizedTransactionsBoot>
|
|
||||||
<Box>
|
|
||||||
<CashflowTransactionsTableCard>
|
|
||||||
<AccountTransactionsUncategorizedTable />
|
|
||||||
</CashflowTransactionsTableCard>
|
|
||||||
</Box>
|
|
||||||
</AccountUncategorizedTransactionsBoot>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import { flatten, map } from 'lodash';
|
|
||||||
import { IntersectionObserver } from '@/components';
|
|
||||||
import { useAccountUncategorizedTransactionsInfinity } from '@/hooks/query';
|
|
||||||
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
|
|
||||||
|
|
||||||
const AccountUncategorizedTransactionsContext = React.createContext();
|
|
||||||
|
|
||||||
function flattenInfinityPagesData(data) {
|
|
||||||
return flatten(map(data.pages, (page) => page.data));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Account uncategorized transctions provider.
|
|
||||||
*/
|
|
||||||
function AccountUncategorizedTransactionsBoot({ children }) {
|
|
||||||
const { accountId } = useAccountTransactionsContext();
|
|
||||||
|
|
||||||
// Fetches the uncategorized transactions.
|
|
||||||
const {
|
|
||||||
data: uncategorizedTransactionsPage,
|
|
||||||
isFetching: isUncategorizedTransactionFetching,
|
|
||||||
isLoading: isUncategorizedTransactionsLoading,
|
|
||||||
isSuccess: isUncategorizedTransactionsSuccess,
|
|
||||||
isFetchingNextPage: isUncategorizedTransactionFetchNextPage,
|
|
||||||
fetchNextPage: fetchNextUncategorizedTransactionsPage,
|
|
||||||
hasNextPage: hasUncategorizedTransactionsNextPage,
|
|
||||||
} = useAccountUncategorizedTransactionsInfinity(accountId, {
|
|
||||||
page_size: 50,
|
|
||||||
});
|
|
||||||
// Memorized the cashflow account transactions.
|
|
||||||
const uncategorizedTransactions = React.useMemo(
|
|
||||||
() =>
|
|
||||||
isUncategorizedTransactionsSuccess
|
|
||||||
? flattenInfinityPagesData(uncategorizedTransactionsPage)
|
|
||||||
: [],
|
|
||||||
[uncategorizedTransactionsPage, isUncategorizedTransactionsSuccess],
|
|
||||||
);
|
|
||||||
// Handle the observer ineraction.
|
|
||||||
const handleObserverInteract = React.useCallback(() => {
|
|
||||||
if (
|
|
||||||
!isUncategorizedTransactionFetching &&
|
|
||||||
hasUncategorizedTransactionsNextPage
|
|
||||||
) {
|
|
||||||
fetchNextUncategorizedTransactionsPage();
|
|
||||||
}
|
|
||||||
}, [
|
|
||||||
isUncategorizedTransactionFetching,
|
|
||||||
hasUncategorizedTransactionsNextPage,
|
|
||||||
fetchNextUncategorizedTransactionsPage,
|
|
||||||
]);
|
|
||||||
// Provider payload.
|
|
||||||
const provider = {
|
|
||||||
uncategorizedTransactions,
|
|
||||||
isUncategorizedTransactionFetching,
|
|
||||||
isUncategorizedTransactionsLoading,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AccountUncategorizedTransactionsContext.Provider value={provider}>
|
|
||||||
{children}
|
|
||||||
<IntersectionObserver
|
|
||||||
onIntersect={handleObserverInteract}
|
|
||||||
enabled={!isUncategorizedTransactionFetchNextPage}
|
|
||||||
/>
|
|
||||||
</AccountUncategorizedTransactionsContext.Provider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const useAccountUncategorizedTransactionsContext = () =>
|
|
||||||
React.useContext(AccountUncategorizedTransactionsContext);
|
|
||||||
|
|
||||||
export {
|
|
||||||
AccountUncategorizedTransactionsBoot,
|
|
||||||
useAccountUncategorizedTransactionsContext,
|
|
||||||
};
|
|
||||||
@@ -39,7 +39,6 @@ export function ActionsMenu({
|
|||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve account transctions table columns.
|
* Retrieve account transctions table columns.
|
||||||
*/
|
*/
|
||||||
@@ -132,75 +131,7 @@ export function useAccountTransactionsColumns() {
|
|||||||
* Account transactions progress bar.
|
* Account transactions progress bar.
|
||||||
*/
|
*/
|
||||||
export function AccountTransactionsProgressBar() {
|
export function AccountTransactionsProgressBar() {
|
||||||
const { isCashFlowTransactionsFetching, isUncategorizedTransactionFetching } =
|
const { isCashFlowTransactionsFetching } = useAccountTransactionsContext();
|
||||||
useAccountTransactionsContext();
|
|
||||||
|
|
||||||
return isCashFlowTransactionsFetching ||
|
return isCashFlowTransactionsFetching ? <MaterialProgressBar /> : null;
|
||||||
isUncategorizedTransactionFetching ? (
|
|
||||||
<MaterialProgressBar />
|
|
||||||
) : 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: intl.get('reference_no'),
|
|
||||||
accessor: 'reference_number',
|
|
||||||
width: 50,
|
|
||||||
className: 'reference_number',
|
|
||||||
clickable: true,
|
|
||||||
textOverview: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'deposit',
|
|
||||||
Header: intl.get('cash_flow.label.deposit'),
|
|
||||||
accessor: 'formattet_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,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,12 +110,12 @@ function CashFlowAccountsActionsBar({
|
|||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
|
|
||||||
<NavbarGroup align={Alignment.RIGHT}>
|
<NavbarGroup align={Alignment.RIGHT}>
|
||||||
<Button
|
{/* <Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
text={'Connect to Bank / Credit Card'}
|
text={'Connect to Bank / Credit Card'}
|
||||||
onClick={handleConnectToBank}
|
onClick={handleConnectToBank}
|
||||||
/>
|
/>
|
||||||
<NavbarDivider />
|
<NavbarDivider /> */}
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon="refresh-16" iconSize={14} />}
|
icon={<Icon icon="refresh-16" iconSize={14} />}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import { DrawerHeaderContent, DrawerLoading } from '@/components';
|
|
||||||
import { DRAWERS } from '@/constants/drawers';
|
|
||||||
import {
|
|
||||||
useAccounts,
|
|
||||||
useBranches,
|
|
||||||
useUncategorizedTransaction,
|
|
||||||
} from '@/hooks/query';
|
|
||||||
import { useFeatureCan } from '@/hooks/state';
|
|
||||||
import { Features } from '@/constants';
|
|
||||||
|
|
||||||
const CategorizeTransactionBootContext = React.createContext();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize transcation boot.
|
|
||||||
*/
|
|
||||||
function CategorizeTransactionBoot({ uncategorizedTransactionId, ...props }) {
|
|
||||||
// Detarmines whether the feature is enabled.
|
|
||||||
const { featureCan } = useFeatureCan();
|
|
||||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
|
||||||
|
|
||||||
// Fetches accounts list.
|
|
||||||
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
|
|
||||||
|
|
||||||
// Fetches the branches list.
|
|
||||||
const { data: branches, isLoading: isBranchesLoading } = useBranches(
|
|
||||||
{},
|
|
||||||
{ enabled: isBranchFeatureCan },
|
|
||||||
);
|
|
||||||
// Retrieves the uncategorized transaction.
|
|
||||||
const {
|
|
||||||
data: uncategorizedTransaction,
|
|
||||||
isLoading: isUncategorizedTransactionLoading,
|
|
||||||
} = useUncategorizedTransaction(uncategorizedTransactionId);
|
|
||||||
|
|
||||||
const provider = {
|
|
||||||
uncategorizedTransactionId,
|
|
||||||
uncategorizedTransaction,
|
|
||||||
isUncategorizedTransactionLoading,
|
|
||||||
branches,
|
|
||||||
accounts,
|
|
||||||
isBranchesLoading,
|
|
||||||
isAccountsLoading,
|
|
||||||
};
|
|
||||||
const isLoading =
|
|
||||||
isBranchesLoading || isUncategorizedTransactionLoading || isAccountsLoading;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DrawerLoading loading={isLoading}>
|
|
||||||
<DrawerHeaderContent
|
|
||||||
name={DRAWERS.CATEGORIZE_TRANSACTION}
|
|
||||||
title={'Categorize Transaction'}
|
|
||||||
/>
|
|
||||||
<CategorizeTransactionBootContext.Provider value={provider} {...props} />
|
|
||||||
</DrawerLoading>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const useCategorizeTransactionBoot = () =>
|
|
||||||
React.useContext(CategorizeTransactionBootContext);
|
|
||||||
|
|
||||||
export { CategorizeTransactionBoot, useCategorizeTransactionBoot };
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { DrawerBody } from '@/components';
|
|
||||||
import { CategorizeTransactionBoot } from './CategorizeTransactionBoot';
|
|
||||||
import { CategorizeTransactionForm } from './CategorizeTransactionForm';
|
|
||||||
|
|
||||||
export default function CategorizeTransactionContent({
|
|
||||||
uncategorizedTransactionId,
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<CategorizeTransactionBoot
|
|
||||||
uncategorizedTransactionId={uncategorizedTransactionId}
|
|
||||||
>
|
|
||||||
<CategorizeTransactionDrawerBody>
|
|
||||||
<CategorizeTransactionForm />
|
|
||||||
</CategorizeTransactionDrawerBody>
|
|
||||||
</CategorizeTransactionBoot>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CategorizeTransactionDrawerBody = styled(DrawerBody)`
|
|
||||||
padding: 20px;
|
|
||||||
background-color: #fff;
|
|
||||||
`;
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React, { lazy } from 'react';
|
|
||||||
import { Drawer, DrawerSuspense } from '@/components';
|
|
||||||
import withDrawers from '@/containers/Drawer/withDrawers';
|
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
|
||||||
|
|
||||||
const CategorizeTransactionContent = lazy(
|
|
||||||
() => import('./CategorizeTransactionContent'),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize the uncategorized transaction drawer.
|
|
||||||
*/
|
|
||||||
function CategorizeTransactionDrawer({
|
|
||||||
name,
|
|
||||||
// #withDrawer
|
|
||||||
isOpen,
|
|
||||||
payload: { uncategorizedTransactionId },
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<Drawer
|
|
||||||
isOpen={isOpen}
|
|
||||||
name={name}
|
|
||||||
style={{ minWidth: '480px', maxWidth: '600px' }}
|
|
||||||
size={'40%'}
|
|
||||||
>
|
|
||||||
<DrawerSuspense>
|
|
||||||
<CategorizeTransactionContent
|
|
||||||
uncategorizedTransactionId={uncategorizedTransactionId}
|
|
||||||
/>
|
|
||||||
</DrawerSuspense>
|
|
||||||
</Drawer>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(withDrawers())(CategorizeTransactionDrawer);
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import * as Yup from 'yup';
|
|
||||||
|
|
||||||
const Schema = Yup.object().shape({
|
|
||||||
amount: Yup.string().required().label('Amount'),
|
|
||||||
exchangeRate: Yup.string().required().label('Exchange rate'),
|
|
||||||
transactionType: Yup.string().required().label('Transaction type'),
|
|
||||||
date: Yup.string().required().label('Date'),
|
|
||||||
creditAccountId: Yup.string().required().label('Credit account'),
|
|
||||||
referenceNo: Yup.string().optional().label('Reference No.'),
|
|
||||||
description: Yup.string().optional().label('Description'),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const CreateCategorizeTransactionSchema = Schema;
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Formik, Form } from 'formik';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { CreateCategorizeTransactionSchema } from './CategorizeTransactionForm.schema';
|
|
||||||
import { CategorizeTransactionFormContent } from './CategorizeTransactionFormContent';
|
|
||||||
import { CategorizeTransactionFormFooter } from './CategorizeTransactionFormFooter';
|
|
||||||
import { useCategorizeTransaction } from '@/hooks/query';
|
|
||||||
import { useCategorizeTransactionBoot } from './CategorizeTransactionBoot';
|
|
||||||
import { DRAWERS } from '@/constants/drawers';
|
|
||||||
import {
|
|
||||||
transformToCategorizeForm,
|
|
||||||
defaultInitialValues,
|
|
||||||
tranformToRequest,
|
|
||||||
} from './_utils';
|
|
||||||
import { compose } from '@/utils';
|
|
||||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
|
||||||
import { AppToaster } from '@/components';
|
|
||||||
import { Intent } from '@blueprintjs/core';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize cashflow transaction form dialog content.
|
|
||||||
*/
|
|
||||||
function CategorizeTransactionFormRoot({
|
|
||||||
// #withDrawerActions
|
|
||||||
closeDrawer,
|
|
||||||
}) {
|
|
||||||
const { uncategorizedTransactionId, uncategorizedTransaction } =
|
|
||||||
useCategorizeTransactionBoot();
|
|
||||||
const { mutateAsync: categorizeTransaction } = useCategorizeTransaction();
|
|
||||||
|
|
||||||
// Callbacks handles form submit.
|
|
||||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
|
||||||
const transformedValues = tranformToRequest(values);
|
|
||||||
|
|
||||||
setSubmitting(true);
|
|
||||||
categorizeTransaction([uncategorizedTransactionId, transformedValues])
|
|
||||||
.then(() => {
|
|
||||||
setSubmitting(false);
|
|
||||||
closeDrawer(DRAWERS.CATEGORIZE_TRANSACTION);
|
|
||||||
|
|
||||||
AppToaster.show({
|
|
||||||
message: 'The uncategorized transaction has been categorized.',
|
|
||||||
intent: Intent.SUCCESS,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setSubmitting(false);
|
|
||||||
AppToaster.show({
|
|
||||||
message: 'Something went wrong!',
|
|
||||||
intent: Intent.DANGER,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
// Form initial values in create and edit mode.
|
|
||||||
const initialValues = {
|
|
||||||
...defaultInitialValues,
|
|
||||||
/**
|
|
||||||
* We only care about the fields in the form. Previously unfilled optional
|
|
||||||
* values such as `notes` come back from the API as null, so remove those
|
|
||||||
* as well.
|
|
||||||
*/
|
|
||||||
...transformToCategorizeForm(uncategorizedTransaction),
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DivRoot>
|
|
||||||
<Formik
|
|
||||||
validationSchema={CreateCategorizeTransactionSchema}
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={handleFormSubmit}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<CategorizeTransactionFormContent />
|
|
||||||
<CategorizeTransactionFormFooter />
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</DivRoot>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CategorizeTransactionForm = compose(withDrawerActions)(
|
|
||||||
CategorizeTransactionFormRoot,
|
|
||||||
);
|
|
||||||
|
|
||||||
const DivRoot = styled.div`
|
|
||||||
.bp4-form-group .bp4-form-content {
|
|
||||||
flex: 1 0;
|
|
||||||
}
|
|
||||||
.bp4-form-group .bp4-label {
|
|
||||||
width: 140px;
|
|
||||||
}
|
|
||||||
.bp4-form-group {
|
|
||||||
margin-bottom: 18px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { FormGroup } from '@blueprintjs/core';
|
|
||||||
import { FFormGroup, FSelect, } from '@/components';
|
|
||||||
import { getAddMoneyInOptions, getAddMoneyOutOptions } from '@/constants';
|
|
||||||
import { useFormikContext } from 'formik';
|
|
||||||
import { useCategorizeTransactionBoot } from './CategorizeTransactionBoot';
|
|
||||||
|
|
||||||
// Retrieves the add money in button options.
|
|
||||||
const MoneyInOptions = getAddMoneyInOptions();
|
|
||||||
const MoneyOutOptions = getAddMoneyOutOptions();
|
|
||||||
|
|
||||||
const Title = styled('h3')`
|
|
||||||
font-size: 20px;
|
|
||||||
font-weight: 400;
|
|
||||||
color: #cd4246;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export function CategorizeTransactionFormContent() {
|
|
||||||
const { uncategorizedTransaction } = useCategorizeTransactionBoot();
|
|
||||||
|
|
||||||
const transactionTypes = uncategorizedTransaction?.is_deposit_transaction
|
|
||||||
? MoneyInOptions
|
|
||||||
: MoneyOutOptions;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FormGroup label={'Amount'} inline>
|
|
||||||
<Title>{uncategorizedTransaction.formatted_amount}</Title>
|
|
||||||
</FormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'category'} label={'Category'} fastField inline>
|
|
||||||
<FSelect
|
|
||||||
name={'transactionType'}
|
|
||||||
items={transactionTypes}
|
|
||||||
popoverProps={{ minimal: true }}
|
|
||||||
valueAccessor={'value'}
|
|
||||||
textAccessor={'name'}
|
|
||||||
fill
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<CategorizeTransactionFormSubContent />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CategorizeTransactionOtherIncome = React.lazy(
|
|
||||||
() => import('./MoneyIn/CategorizeTransactionOtherIncome'),
|
|
||||||
);
|
|
||||||
|
|
||||||
const CategorizeTransactionOwnerContribution = React.lazy(
|
|
||||||
() => import('./MoneyIn/CategorizeTransactionOwnerContribution'),
|
|
||||||
);
|
|
||||||
|
|
||||||
const CategorizeTransactionTransferFrom = React.lazy(
|
|
||||||
() => import('./MoneyIn/CategorizeTransactionTransferFrom'),
|
|
||||||
);
|
|
||||||
|
|
||||||
const CategorizeTransactionOtherExpense = React.lazy(
|
|
||||||
() => import('./MoneyOut/CategorizeTransactionOtherExpense'),
|
|
||||||
);
|
|
||||||
|
|
||||||
const CategorizeTransactionToAccount = React.lazy(
|
|
||||||
() => import('./MoneyOut/CategorizeTransactionToAccount'),
|
|
||||||
);
|
|
||||||
|
|
||||||
const CategorizeTransactionOwnerDrawings = React.lazy(
|
|
||||||
() => import('./MoneyOut/CategorizeTransactionOwnerDrawings'),
|
|
||||||
);
|
|
||||||
|
|
||||||
function CategorizeTransactionFormSubContent() {
|
|
||||||
const { values } = useFormikContext();
|
|
||||||
|
|
||||||
// Other expense.
|
|
||||||
if (values.transactionType === 'other_expense') {
|
|
||||||
return <CategorizeTransactionOtherExpense />;
|
|
||||||
// Owner contribution.
|
|
||||||
} else if (values.transactionType === 'owner_contribution') {
|
|
||||||
return <CategorizeTransactionOwnerContribution />;
|
|
||||||
// Other Income.
|
|
||||||
} else if (values.transactionType === 'other_income') {
|
|
||||||
return <CategorizeTransactionOtherIncome />;
|
|
||||||
// Transfer from account.
|
|
||||||
} else if (values.transactionType === 'transfer_from_account') {
|
|
||||||
return <CategorizeTransactionTransferFrom />;
|
|
||||||
// Transfer to account.
|
|
||||||
} else if (values.transactionType === 'transfer_to_account') {
|
|
||||||
return <CategorizeTransactionToAccount />;
|
|
||||||
// Owner drawings.
|
|
||||||
} else if (values.transactionType === 'OwnerDrawing') {
|
|
||||||
return <CategorizeTransactionOwnerDrawings />;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import * as R from 'ramda';
|
|
||||||
import { Button, Classes, Intent } from '@blueprintjs/core';
|
|
||||||
import { useFormikContext } from 'formik';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
|
||||||
import { DRAWERS } from '@/constants/drawers';
|
|
||||||
import { Group } from '@/components';
|
|
||||||
|
|
||||||
function CategorizeTransactionFormFooterRoot({
|
|
||||||
// #withDrawerActions
|
|
||||||
closeDrawer,
|
|
||||||
}) {
|
|
||||||
const { isSubmitting } = useFormikContext();
|
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
closeDrawer(DRAWERS.CATEGORIZE_TRANSACTION);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Root>
|
|
||||||
<div className={Classes.DRAWER_FOOTER}>
|
|
||||||
<Group spacing={10}>
|
|
||||||
<Button
|
|
||||||
intent={Intent.PRIMARY}
|
|
||||||
loading={isSubmitting}
|
|
||||||
style={{ minWidth: '75px' }}
|
|
||||||
type="submit"
|
|
||||||
>
|
|
||||||
Save
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
disabled={isSubmitting}
|
|
||||||
onClick={handleClose}
|
|
||||||
style={{ minWidth: '75px' }}
|
|
||||||
>
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
</div>
|
|
||||||
</Root>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CategorizeTransactionFormFooter = R.compose(withDrawerActions)(
|
|
||||||
CategorizeTransactionFormFooterRoot,
|
|
||||||
);
|
|
||||||
|
|
||||||
const Root = styled.div`
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
background: #fff;
|
|
||||||
`;
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Position } from '@blueprintjs/core';
|
|
||||||
import {
|
|
||||||
AccountsSelect,
|
|
||||||
FDateInput,
|
|
||||||
FFormGroup,
|
|
||||||
FInputGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
import { useCategorizeTransactionBoot } from '../CategorizeTransactionBoot';
|
|
||||||
|
|
||||||
export default function CategorizeTransactionOtherIncome() {
|
|
||||||
const { accounts } = useCategorizeTransactionBoot();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FFormGroup name={'date'} label={'Date'} fastField inline>
|
|
||||||
<FDateInput
|
|
||||||
name={'date'}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
|
||||||
formatDate={(date) => date.toLocaleDateString()}
|
|
||||||
parseDate={(str) => new Date(str)}
|
|
||||||
inputProps={{ fill: true }}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'debitAccountId'}
|
|
||||||
label={'To Account'}
|
|
||||||
fastField={true}
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'debitAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'creditAccountId'}
|
|
||||||
label={'Income Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'creditAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
filterByRootTypes={['income']}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'referenceNo'} label={'Reference No.'} fastField inline>
|
|
||||||
<FInputGroup name={'reference_no'} fill />
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'description'} label={'Description'} fastField inline>
|
|
||||||
<FTextArea
|
|
||||||
name={'description'}
|
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Position } from '@blueprintjs/core';
|
|
||||||
import {
|
|
||||||
AccountsSelect,
|
|
||||||
FDateInput,
|
|
||||||
FFormGroup,
|
|
||||||
FInputGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
import { useCategorizeTransactionBoot } from '../CategorizeTransactionBoot';
|
|
||||||
|
|
||||||
export default function CategorizeTransactionOwnerContribution() {
|
|
||||||
const { accounts } = useCategorizeTransactionBoot();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FFormGroup name={'date'} label={'Date'} fastField inline>
|
|
||||||
<FDateInput
|
|
||||||
name={'date'}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
|
||||||
formatDate={(date) => date.toLocaleDateString()}
|
|
||||||
parseDate={(str) => new Date(str)}
|
|
||||||
inputProps={{ fill: true }}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'debitAccountId'}
|
|
||||||
label={'From Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'debitAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'creditAccountId'}
|
|
||||||
label={'Equity Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'creditAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
filterByRootTypes={['equity']}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'referenceNo'} label={'Reference No.'} fastField inline>
|
|
||||||
<FInputGroup name={'reference_no'} fill />
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'description'} label={'Description'} fastField inline>
|
|
||||||
<FTextArea name={'description'} growVertically large fill />
|
|
||||||
</FFormGroup>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Position } from '@blueprintjs/core';
|
|
||||||
import {
|
|
||||||
AccountsSelect,
|
|
||||||
FDateInput,
|
|
||||||
FFormGroup,
|
|
||||||
FInputGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
import { useCategorizeTransactionBoot } from '../CategorizeTransactionBoot';
|
|
||||||
|
|
||||||
export default function CategorizeTransactionTransferFrom() {
|
|
||||||
const { accounts } = useCategorizeTransactionBoot();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FFormGroup name={'date'} label={'Date'} fastField inline>
|
|
||||||
<FDateInput
|
|
||||||
name={'date'}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
|
||||||
formatDate={(date) => date.toLocaleDateString()}
|
|
||||||
parseDate={(str) => new Date(str)}
|
|
||||||
inputProps={{ fill: true }}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'debitAccountId'}
|
|
||||||
label={'From Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'debitAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'creditAccountId'}
|
|
||||||
label={'To Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'to_account_id'}
|
|
||||||
items={accounts}
|
|
||||||
filterByRootTypes={['asset']}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'referenceNo'} label={'Reference No.'} fastField inline>
|
|
||||||
<FInputGroup name={'reference_no'} fill />
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'description'} label={'Description'} fastField inline>
|
|
||||||
<FTextArea
|
|
||||||
name={'description'}
|
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Position } from '@blueprintjs/core';
|
|
||||||
import {
|
|
||||||
AccountsSelect,
|
|
||||||
FDateInput,
|
|
||||||
FFormGroup,
|
|
||||||
FInputGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
import { useCategorizeTransactionBoot } from '../CategorizeTransactionBoot';
|
|
||||||
|
|
||||||
export default function CategorizeTransactionOtherExpense() {
|
|
||||||
const { accounts } = useCategorizeTransactionBoot();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FFormGroup name={'date'} label={'Date'} fastField inline>
|
|
||||||
<FDateInput
|
|
||||||
name={'date'}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
|
||||||
formatDate={(date) => date.toLocaleDateString()}
|
|
||||||
parseDate={(str) => new Date(str)}
|
|
||||||
inputProps={{ fill: true }}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'debitAccountId'}
|
|
||||||
label={'Payment Account'}
|
|
||||||
fastField={true}
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'debitAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'creditAccountId'}
|
|
||||||
label={'Expense Account'}
|
|
||||||
fastField={true}
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'creditAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
filterByRootTypes={['expense']}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'referenceNo'} label={'Reference No.'} fastField inline>
|
|
||||||
<FInputGroup name={'reference_no'} fill />
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'description'} label={'Description'} fastField inline>
|
|
||||||
<FTextArea
|
|
||||||
name={'description'}
|
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Position } from '@blueprintjs/core';
|
|
||||||
import {
|
|
||||||
AccountsSelect,
|
|
||||||
FDateInput,
|
|
||||||
FFormGroup,
|
|
||||||
FInputGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
import { useCategorizeTransactionBoot } from '../CategorizeTransactionBoot';
|
|
||||||
|
|
||||||
export default function CategorizeTransactionOwnerDrawings() {
|
|
||||||
const { accounts } = useCategorizeTransactionBoot();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FFormGroup name={'date'} label={'Date'} fastField inline>
|
|
||||||
<FDateInput
|
|
||||||
name={'date'}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
|
||||||
formatDate={(date) => date.toLocaleDateString()}
|
|
||||||
parseDate={(str) => new Date(str)}
|
|
||||||
inputProps={{ fill: true }}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'debitAccountId'}
|
|
||||||
label={'Debit Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'debitAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'creditAccountId'}
|
|
||||||
label={'Equity Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'creditAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
filterByRootTypes={['equity']}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'referenceNo'} label={'Reference No.'} fastField inline>
|
|
||||||
<FInputGroup name={'reference_no'} fill />
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'description'} label={'Description'} fastField inline>
|
|
||||||
<FTextArea
|
|
||||||
name={'description'}
|
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Position } from '@blueprintjs/core';
|
|
||||||
import {
|
|
||||||
AccountsSelect,
|
|
||||||
FDateInput,
|
|
||||||
FFormGroup,
|
|
||||||
FInputGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
import { useCategorizeTransactionBoot } from '../CategorizeTransactionBoot';
|
|
||||||
|
|
||||||
export default function CategorizeTransactionToAccount() {
|
|
||||||
const { accounts } = useCategorizeTransactionBoot();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FFormGroup name={'date'} label={'Date'} fastField inline>
|
|
||||||
<FDateInput
|
|
||||||
name={'date'}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
|
||||||
formatDate={(date) => date.toLocaleDateString()}
|
|
||||||
parseDate={(str) => new Date(str)}
|
|
||||||
inputProps={{ fill: true }}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'debitAccountId'}
|
|
||||||
label={'From Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'debitAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup
|
|
||||||
name={'creditAccountId'}
|
|
||||||
label={'To Account'}
|
|
||||||
fastField
|
|
||||||
inline
|
|
||||||
>
|
|
||||||
<AccountsSelect
|
|
||||||
name={'creditAccountId'}
|
|
||||||
items={accounts}
|
|
||||||
filterByRootTypes={['assset']}
|
|
||||||
fastField
|
|
||||||
fill
|
|
||||||
allowCreate
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'referenceNo'} label={'Reference No.'} fastField inline>
|
|
||||||
<FInputGroup name={'reference_no'} fill />
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<FFormGroup name={'description'} label={'Description'} fastField inline>
|
|
||||||
<FTextArea
|
|
||||||
name={'description'}
|
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { transformToForm, transfromToSnakeCase } from '@/utils';
|
|
||||||
|
|
||||||
// Default initial form values.
|
|
||||||
export const defaultInitialValues = {
|
|
||||||
amount: '',
|
|
||||||
date: '',
|
|
||||||
creditAccountId: '',
|
|
||||||
debitAccountId: '',
|
|
||||||
exchangeRate: '1',
|
|
||||||
transactionType: '',
|
|
||||||
referenceNo: '',
|
|
||||||
description: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const transformToCategorizeForm = (uncategorizedTransaction) => {
|
|
||||||
const defaultValues = {
|
|
||||||
debitAccountId: uncategorizedTransaction.account_id,
|
|
||||||
transactionType: uncategorizedTransaction.is_deposit_transaction
|
|
||||||
? 'other_income'
|
|
||||||
: 'other_expense',
|
|
||||||
amount: uncategorizedTransaction.amount,
|
|
||||||
date: uncategorizedTransaction.date,
|
|
||||||
};
|
|
||||||
return transformToForm(defaultValues, defaultInitialValues);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export const tranformToRequest = (formValues) => {
|
|
||||||
return transfromToSnakeCase(formValues);
|
|
||||||
};
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from './CategorizeTransactionDrawer';
|
|
||||||
@@ -26,7 +26,6 @@ function ConnectBankDialogBodyRoot({
|
|||||||
const { mutateAsync: getPlaidLinkToken } = useGetPlaidLinkToken();
|
const { mutateAsync: getPlaidLinkToken } = useGetPlaidLinkToken();
|
||||||
const setPlaidId = useSetBankingPlaidToken();
|
const setPlaidId = useSetBankingPlaidToken();
|
||||||
|
|
||||||
// Handles the form submitting.
|
|
||||||
const handleSubmit = (
|
const handleSubmit = (
|
||||||
values: ConnectBankDialogForm,
|
values: ConnectBankDialogForm,
|
||||||
{ setSubmitting }: FormikHelpers<ConnectBankDialogForm>,
|
{ setSubmitting }: FormikHelpers<ConnectBankDialogForm>,
|
||||||
|
|||||||
@@ -1,48 +1,30 @@
|
|||||||
// @ts-nocheck
|
import { Button } from '@blueprintjs/core';
|
||||||
import styled from 'styled-components';
|
import { FFormGroup, FSelect } from '@/components';
|
||||||
import { Stack } from '@/components';
|
import { useFormikContext } from 'formik';
|
||||||
import { TellerIcon } from '../Icons/TellerIcon';
|
|
||||||
import { YodleeIcon } from '../Icons/YodleeIcon';
|
|
||||||
import { PlaidIcon } from '../Icons/PlaidIcon';
|
|
||||||
import { BankServiceCard } from './ConnectBankServiceCard';
|
|
||||||
|
|
||||||
const TopDesc = styled('p')`
|
|
||||||
margin-bottom: 20px;
|
|
||||||
color: #5f6b7c;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export function ConnectBankDialogContent() {
|
export function ConnectBankDialogContent() {
|
||||||
|
const { isSubmitting } = useFormikContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<TopDesc>
|
<FFormGroup
|
||||||
Connect your bank accounts and fetch the bank transactions using
|
label={'Banking Syncing Service Provider'}
|
||||||
one of our supported third-party service providers.
|
name={'serviceProvider'}
|
||||||
</TopDesc>
|
>
|
||||||
|
<FSelect
|
||||||
|
name={'serviceProvider'}
|
||||||
|
valueAccessor={'key'}
|
||||||
|
textAccessor={'label'}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
items={BankFeedsServiceProviders}
|
||||||
|
/>
|
||||||
|
</FFormGroup>
|
||||||
|
|
||||||
<Stack>
|
<Button type={'submit'} loading={isSubmitting}>
|
||||||
<BankServiceCard
|
Connect
|
||||||
title={'Plaid (US, UK & Canada)'}
|
</Button>
|
||||||
icon={<PlaidIcon />}
|
|
||||||
>
|
|
||||||
Plaid gives the connection to 12,000 financial institutions across US, UK and Canada.
|
|
||||||
</BankServiceCard>
|
|
||||||
|
|
||||||
<BankServiceCard
|
|
||||||
title={'Teller (US) — Soon'}
|
|
||||||
icon={<TellerIcon />}
|
|
||||||
disabled
|
|
||||||
>
|
|
||||||
Connect instantly with more than 5,000 financial institutions across US.
|
|
||||||
</BankServiceCard>
|
|
||||||
|
|
||||||
<BankServiceCard
|
|
||||||
title={'Yodlee (Global) — Soon'}
|
|
||||||
icon={<YodleeIcon />}
|
|
||||||
disabled
|
|
||||||
>
|
|
||||||
Connect instantly with a global network of financial institutions.
|
|
||||||
</BankServiceCard>
|
|
||||||
</Stack>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const BankFeedsServiceProviders = [{ label: 'Plaid', key: 'plaid' }];
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
import { Group } from '@/components';
|
|
||||||
|
|
||||||
const BankServiceIcon = styled('div')`
|
|
||||||
height: 40px;
|
|
||||||
width: 40px;
|
|
||||||
border: 1px solid #c8cad0;
|
|
||||||
border-radius: 3px;
|
|
||||||
display: flex;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
const BankServiceContent = styled(`div`)`
|
|
||||||
flex: 1 0;
|
|
||||||
`;
|
|
||||||
const BankServiceCardRoot = styled('button')`
|
|
||||||
border-radius: 3px;
|
|
||||||
border: 1px solid #c8cad0;
|
|
||||||
transition: all 0.1s ease-in-out;
|
|
||||||
background: transparent;
|
|
||||||
text-align: inherit;
|
|
||||||
padding: 14px;
|
|
||||||
|
|
||||||
&:not(:disabled) {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
&:hover:not(:disabled) {
|
|
||||||
border-color: #0153cc;
|
|
||||||
}
|
|
||||||
&:disabled {
|
|
||||||
background: #f9fdff;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
const BankServiceTitle = styled(`h3`)`
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 14px;
|
|
||||||
color: #2d333d;
|
|
||||||
`;
|
|
||||||
const BankServiceDesc = styled('p')`
|
|
||||||
margin-top: 4px;
|
|
||||||
margin-bottom: 6px;
|
|
||||||
font-size: 13px;
|
|
||||||
color: #738091;
|
|
||||||
`;
|
|
||||||
|
|
||||||
interface BankServiceCardProps {
|
|
||||||
title: string;
|
|
||||||
children: React.ReactNode;
|
|
||||||
disabled?: boolean;
|
|
||||||
icon: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function BankServiceCard({
|
|
||||||
title,
|
|
||||||
children,
|
|
||||||
icon,
|
|
||||||
disabled,
|
|
||||||
}: BankServiceCardProps) {
|
|
||||||
return (
|
|
||||||
<BankServiceCardRoot disabled={disabled}>
|
|
||||||
<Group>
|
|
||||||
<BankServiceIcon>{icon}</BankServiceIcon>
|
|
||||||
<BankServiceContent>
|
|
||||||
<BankServiceTitle>{title}</BankServiceTitle>
|
|
||||||
<BankServiceDesc>{children}</BankServiceDesc>
|
|
||||||
</BankServiceContent>
|
|
||||||
</Group>
|
|
||||||
</BankServiceCardRoot>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
|
|
||||||
export const PlaidIcon = (props: any) => (
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width={30}
|
|
||||||
height={30}
|
|
||||||
viewBox={'0 0 48 48'}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
fill="#111"
|
|
||||||
fillRule="evenodd"
|
|
||||||
d="M18.637 0 4.09 3.81.081 18.439l5.014 5.148L0 28.65l3.773 14.693 14.484 4.047 5.096-5.064 5.014 5.147 14.547-3.81 4.008-14.63-5.013-5.146 5.095-5.063L43.231 4.13 28.745.083l-5.094 5.063zM9.71 6.624l7.663-2.008 3.351 3.44-4.887 4.856zm16.822 1.478 3.405-3.383 7.63 2.132-6.227 6.187zM4.672 17.238l2.111-7.705 6.125 6.288-4.886 4.856zm29.547-1.243 6.227-6.189 1.986 7.74-3.404 3.384zm-15.502-.127 4.887-4.856 4.807 4.936-4.886 4.856zm-7.814 7.765 4.886-4.856 4.81 4.936-4.888 4.856zm15.503.127 4.886-4.856L36.1 23.84l-4.887 4.856zM4.57 29.927l3.406-3.385 4.807 4.937-6.225 6.186zm14.021 1.598 4.887-4.856 4.808 4.936-4.886 4.856zm15.502.128 4.887-4.856 3.351 3.439-2.11 7.705zm-24.656 8.97 6.226-6.189 4.81 4.936-3.406 3.385zm16.843-1.206 4.886-4.856 6.126 6.289-7.662 2.007z"
|
|
||||||
mask="url(#a)"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
export const TellerIcon = () => (
|
|
||||||
<svg
|
|
||||||
height={30}
|
|
||||||
width={30}
|
|
||||||
viewBox="0 0 789 789"
|
|
||||||
fill="none"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
>
|
|
||||||
<g clip-path="url(#clip0_4283_1925)">
|
|
||||||
<path
|
|
||||||
d="M433.606 360.544C351.138 278.075 351.138 144.366 433.606 61.8977C516.075 -20.5711 649.784 -20.5711 732.252 61.8977C814.721 144.366 814.721 278.075 732.252 360.544C649.784 443.012 516.075 443.012 433.606 360.544Z"
|
|
||||||
fill="#FF5833"
|
|
||||||
></path>
|
|
||||||
<path
|
|
||||||
d="M639.444 578.592C639.444 599.543 622.46 616.527 601.509 616.527H215.57C194.62 616.527 177.636 599.543 177.636 578.592V192.654C177.636 171.703 194.62 154.719 215.57 154.719H601.509C622.46 154.719 639.444 171.703 639.444 192.654V578.592Z"
|
|
||||||
fill="#0057FF"
|
|
||||||
></path>
|
|
||||||
<path
|
|
||||||
d="M379.425 154.717L601.501 154.717C622.452 154.717 639.436 171.701 639.436 192.651V414.731C568.518 434.347 489.361 416.283 433.616 360.538C377.871 304.793 359.807 225.635 379.425 154.717Z"
|
|
||||||
fill="#FF77FA"
|
|
||||||
></path>
|
|
||||||
<path
|
|
||||||
d="M383.842 410.314C466.311 492.783 466.311 626.492 383.842 708.961L334.294 758.508C294.899 797.904 231.025 797.904 191.63 758.509L35.647 602.526C-3.74884 563.13 -3.74887 499.257 35.647 459.861L85.1942 410.314C167.663 327.845 301.372 327.845 383.842 410.314Z"
|
|
||||||
fill="#3CE475"
|
|
||||||
></path>
|
|
||||||
<path
|
|
||||||
d="M437.917 616.525H215.576C194.626 616.525 177.642 599.541 177.642 578.59L177.642 356.224C248.655 336.442 327.991 354.472 383.833 410.314C439.68 466.161 457.708 545.507 437.917 616.525Z"
|
|
||||||
fill="#00FFFF"
|
|
||||||
></path>
|
|
||||||
</g>
|
|
||||||
<defs>
|
|
||||||
<clipPath id="clip0_4283_1925">
|
|
||||||
<rect
|
|
||||||
width="2427.58"
|
|
||||||
height="788.009"
|
|
||||||
fill="white"
|
|
||||||
transform="translate(0.55127 0.0461426)"
|
|
||||||
></rect>
|
|
||||||
</clipPath>
|
|
||||||
</defs>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
export const YodleeIcon = (props: any) => (
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
xmlSpace="preserve"
|
|
||||||
id="Layer_1"
|
|
||||||
x={0}
|
|
||||||
y={0}
|
|
||||||
style={{
|
|
||||||
width: 28,
|
|
||||||
height: 28,
|
|
||||||
}}
|
|
||||||
viewBox="0 0 30 57.5"
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<style>{'.st0{fill:#343741}.st1{fill:#0084d4}.st3{fill:#8bd3e6}'}</style>
|
|
||||||
<path
|
|
||||||
d="m15.1 30.2 4.4-1.4-4.4-1.4-4.4 1.4z"
|
|
||||||
style={{
|
|
||||||
fill: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M0 0v9.8l19.5 6.3 15-4.9zM0 12.7v9.8l15.1-4.9zM19.5 28.8l15-4.9-4.3-1.4-15.1 4.9zM19.5 41.4l15-4.9-4.3-1.4L15.1 40zM10.7 28.8 0 32.3v2.8l15.1-4.9z"
|
|
||||||
className="st3"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M0 35.1v9.8L15.1 40zM15.1 30.2l15.1 4.9 4.3-1.4-15-4.9z"
|
|
||||||
className="st0"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M34.5 33.7v-9.8l-15 4.9zM0 35.1 15.1 40l15.1-4.9-15.1-4.9z"
|
|
||||||
className="st1"
|
|
||||||
/>
|
|
||||||
<path d="M0 47.7v9.8l34.5-11.2-15-4.9z" className="st0" />
|
|
||||||
<path d="M34.5 46.3v-9.8l-15 4.9z" className="st1" />
|
|
||||||
<path
|
|
||||||
d="m15.1 17.6 15.1 4.9 4.3-1.5-15-4.9zM15.1 27.4 0 22.5v2.8l10.7 3.5z"
|
|
||||||
className="st0"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M34.5 21v-9.8l-15 4.9zM0 22.5l15.1 4.9 15.1-4.9-15.1-4.9zM0 25.3v7l10.7-3.5z"
|
|
||||||
className="st1"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
@@ -14,18 +14,14 @@ import { useEstimateDetailDrawerContext } from './EstimateDetailDrawerProvider';
|
|||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
||||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||||
import {
|
import { SaleEstimateAction, AbilitySubject } from '@/constants/abilityOption';
|
||||||
SaleEstimateAction,
|
|
||||||
AbilitySubject,
|
|
||||||
SaleInvoiceAction,
|
|
||||||
} from '@/constants/abilityOption';
|
|
||||||
import { EstimateMoreMenuItems } from './components';
|
import { EstimateMoreMenuItems } from './components';
|
||||||
import {
|
import {
|
||||||
DrawerActionsBar,
|
DrawerActionsBar,
|
||||||
Icon,
|
Icon,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
Can,
|
Can,
|
||||||
If,
|
Choose,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
@@ -46,7 +42,7 @@ function EstimateDetailActionsBar({
|
|||||||
closeDrawer,
|
closeDrawer,
|
||||||
}) {
|
}) {
|
||||||
// Estimate details drawer context.
|
// Estimate details drawer context.
|
||||||
const { estimateId, estimate } = useEstimateDetailDrawerContext();
|
const { estimateId } = useEstimateDetailDrawerContext();
|
||||||
|
|
||||||
// History.
|
// History.
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -56,15 +52,6 @@ function EstimateDetailActionsBar({
|
|||||||
history.push(`/estimates/${estimateId}/edit`);
|
history.push(`/estimates/${estimateId}/edit`);
|
||||||
closeDrawer(DRAWERS.ESTIMATE_DETAILS);
|
closeDrawer(DRAWERS.ESTIMATE_DETAILS);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle convert to invoice.
|
|
||||||
const handleConvertEstimate = () => {
|
|
||||||
history.push(`/invoices/new?from_estimate_id=${estimateId}`, {
|
|
||||||
action: estimateId,
|
|
||||||
});
|
|
||||||
closeDrawer(DRAWERS.ESTIMATE_DETAILS);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle delete sale estimate.
|
// Handle delete sale estimate.
|
||||||
const handleDeleteEstimate = () => {
|
const handleDeleteEstimate = () => {
|
||||||
openAlert('estimate-delete', { estimateId });
|
openAlert('estimate-delete', { estimateId });
|
||||||
@@ -95,18 +82,7 @@ function EstimateDetailActionsBar({
|
|||||||
/>
|
/>
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
</Can>
|
</Can>
|
||||||
<Can I={SaleInvoiceAction.Create} a={AbilitySubject.Invoice}>
|
|
||||||
<If condition={!estimate.is_converted_to_invoice}>
|
|
||||||
<Button
|
|
||||||
className={Classes.MINIMAL}
|
|
||||||
intent={Intent.SUCCESS}
|
|
||||||
icon={<Icon icon="tick" />}
|
|
||||||
text={<T id={'convert_to_invoice'} />}
|
|
||||||
onClick={handleConvertEstimate}
|
|
||||||
/>
|
|
||||||
<NavbarDivider />
|
|
||||||
</If>
|
|
||||||
</Can>
|
|
||||||
<Can I={SaleEstimateAction.View} a={AbilitySubject.Estimate}>
|
<Can I={SaleEstimateAction.View} a={AbilitySubject.Estimate}>
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
|
|||||||
@@ -57,11 +57,6 @@ function InvoiceDetailActionsBar({
|
|||||||
closeDrawer(DRAWERS.INVOICE_DETAILS);
|
closeDrawer(DRAWERS.INVOICE_DETAILS);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hanlde deliver sale invoice.
|
|
||||||
const handleDeliverInvoice = ({ id }) => {
|
|
||||||
openAlert('invoice-deliver', { invoiceId });
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle convert to invoice.
|
// Handle convert to invoice.
|
||||||
const handleConvertToCreitNote = () => {
|
const handleConvertToCreitNote = () => {
|
||||||
history.push(`/credit-notes/new?from_invoice_id=${invoiceId}`, {
|
history.push(`/credit-notes/new?from_invoice_id=${invoiceId}`, {
|
||||||
@@ -158,7 +153,6 @@ function InvoiceDetailActionsBar({
|
|||||||
onCancelBadDebt: handleCancelBadDebtInvoice,
|
onCancelBadDebt: handleCancelBadDebtInvoice,
|
||||||
onNotifyViaSMS: handleNotifyViaSMS,
|
onNotifyViaSMS: handleNotifyViaSMS,
|
||||||
onConvert: handleConvertToCreitNote,
|
onConvert: handleConvertToCreitNote,
|
||||||
onDeliver: handleDeliverInvoice,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Can>
|
</Can>
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
Choose,
|
Choose,
|
||||||
Can,
|
Can,
|
||||||
If,
|
|
||||||
TextOverviewTooltipCell,
|
TextOverviewTooltipCell,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { SaleInvoiceAction, AbilitySubject } from '@/constants/abilityOption';
|
import { SaleInvoiceAction, AbilitySubject } from '@/constants/abilityOption';
|
||||||
@@ -95,7 +94,7 @@ export const useInvoiceReadonlyEntriesColumns = () => {
|
|||||||
* @returns {React.JSX}
|
* @returns {React.JSX}
|
||||||
*/
|
*/
|
||||||
export const BadDebtMenuItem = ({
|
export const BadDebtMenuItem = ({
|
||||||
payload: { onCancelBadDebt, onBadDebt, onNotifyViaSMS, onConvert, onDeliver },
|
payload: { onCancelBadDebt, onBadDebt, onNotifyViaSMS, onConvert },
|
||||||
}) => {
|
}) => {
|
||||||
const { invoice } = useInvoiceDetailDrawerContext();
|
const { invoice } = useInvoiceDetailDrawerContext();
|
||||||
|
|
||||||
@@ -109,12 +108,6 @@ export const BadDebtMenuItem = ({
|
|||||||
}}
|
}}
|
||||||
content={
|
content={
|
||||||
<Menu>
|
<Menu>
|
||||||
<If condition={!invoice.is_delivered}>
|
|
||||||
<MenuItem
|
|
||||||
onClick={onDeliver}
|
|
||||||
text={<T id={'mark_as_delivered'} />}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
<Choose>
|
<Choose>
|
||||||
<Choose.When condition={!invoice.is_writtenoff}>
|
<Choose.When condition={!invoice.is_writtenoff}>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ export function useDeleteCashflowTransaction(props) {
|
|||||||
export function useAccountTransactionsInfinity(
|
export function useAccountTransactionsInfinity(
|
||||||
accountId,
|
accountId,
|
||||||
query,
|
query,
|
||||||
infinityProps,
|
|
||||||
axios,
|
axios,
|
||||||
|
infinityProps,
|
||||||
) {
|
) {
|
||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
@@ -134,45 +134,6 @@ export function useAccountTransactionsInfinity(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve account transactions infinity scrolling.
|
|
||||||
* @param {number} accountId
|
|
||||||
* @param {*} axios
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
export function useAccountUncategorizedTransactionsInfinity(
|
|
||||||
accountId,
|
|
||||||
query,
|
|
||||||
infinityProps,
|
|
||||||
axios,
|
|
||||||
) {
|
|
||||||
const apiRequest = useApiRequest();
|
|
||||||
|
|
||||||
return useInfiniteQuery(
|
|
||||||
[t.CASHFLOW_ACCOUNT_UNCATEGORIZED_TRANSACTIONS_INFINITY, accountId],
|
|
||||||
async ({ pageParam = 1 }) => {
|
|
||||||
const response = await apiRequest.http({
|
|
||||||
...axios,
|
|
||||||
method: 'get',
|
|
||||||
url: `/api/cashflow/transactions/${accountId}/uncategorized`,
|
|
||||||
params: { page: pageParam, ...query },
|
|
||||||
});
|
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
getPreviousPageParam: (firstPage) => firstPage.pagination.page - 1,
|
|
||||||
getNextPageParam: (lastPage) => {
|
|
||||||
const { pagination } = lastPage;
|
|
||||||
|
|
||||||
return pagination.total > pagination.page_size * pagination.page
|
|
||||||
? lastPage.pagination.page + 1
|
|
||||||
: undefined;
|
|
||||||
},
|
|
||||||
...infinityProps,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh cashflow transactions infinity.
|
* Refresh cashflow transactions infinity.
|
||||||
*/
|
*/
|
||||||
@@ -211,48 +172,3 @@ export function useRefreshCashflowTransactions() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves specific uncategorized transaction.
|
|
||||||
* @param {number} uncategorizedTranasctionId -
|
|
||||||
*/
|
|
||||||
export function useUncategorizedTransaction(
|
|
||||||
uncategorizedTranasctionId: nunber,
|
|
||||||
props,
|
|
||||||
) {
|
|
||||||
return useRequestQuery(
|
|
||||||
[t.CASHFLOW_UNCAATEGORIZED_TRANSACTION, uncategorizedTranasctionId],
|
|
||||||
{
|
|
||||||
method: 'get',
|
|
||||||
url: `cashflow/transactions/uncategorized/${uncategorizedTranasctionId}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
select: (res) => res.data?.data,
|
|
||||||
...props,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorize the cashflow transaction.
|
|
||||||
*/
|
|
||||||
export function useCategorizeTransaction(props) {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const apiRequest = useApiRequest();
|
|
||||||
|
|
||||||
return useMutation(
|
|
||||||
([id, values]) =>
|
|
||||||
apiRequest.post(`cashflow/transactions/${id}/categorize`, values),
|
|
||||||
{
|
|
||||||
onSuccess: (res, id) => {
|
|
||||||
// Invalidate queries.
|
|
||||||
commonInvalidateQueries(queryClient);
|
|
||||||
queryClient.invalidateQueries(t.CASHFLOW_UNCAATEGORIZED_TRANSACTION);
|
|
||||||
queryClient.invalidateQueries(
|
|
||||||
t.CASHFLOW_ACCOUNT_UNCATEGORIZED_TRANSACTIONS_INFINITY,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
...props,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useQueryClient, useMutation } from 'react-query';
|
|||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import { transformPagination } from '@/utils';
|
import { transformPagination } from '@/utils';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import { useRequestPdf } from '../utils';
|
import { useRequestPdf } from '../useRequestPdf';
|
||||||
import t from './types';
|
import t from './types';
|
||||||
|
|
||||||
const commonInvalidateQueries = (queryClient) => {
|
const commonInvalidateQueries = (queryClient) => {
|
||||||
@@ -354,7 +354,5 @@ export function useRefundCreditTransaction(id, props, requestProps) {
|
|||||||
* Retrieve the credit note pdf document data,
|
* Retrieve the credit note pdf document data,
|
||||||
*/
|
*/
|
||||||
export function usePdfCreditNote(creditNoteId) {
|
export function usePdfCreditNote(creditNoteId) {
|
||||||
return useRequestPdf({
|
return useRequestPdf({ url: `sales/credit_notes/${creditNoteId}` });
|
||||||
url: `sales/credit_notes/${creditNoteId}`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
import { useQueryClient, useMutation } from 'react-query';
|
import { useQueryClient, useMutation } from 'react-query';
|
||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import { useRequestPdf } from '../utils';
|
|
||||||
|
|
||||||
import { transformPagination } from '@/utils';
|
import { transformPagination } from '@/utils';
|
||||||
import t from './types';
|
import t from './types';
|
||||||
|
import { useRequestPdf } from '../useRequestPdf';
|
||||||
|
|
||||||
const commonInvalidateQueries = (queryClient) => {
|
const commonInvalidateQueries = (queryClient) => {
|
||||||
// Invalidate estimates.
|
// Invalidate estimates.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useQueryClient, useMutation } from 'react-query';
|
|||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import { transformPagination } from '@/utils';
|
import { transformPagination } from '@/utils';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import { useRequestPdf } from '../utils';
|
import { useRequestPdf } from '../useRequestPdf';
|
||||||
import t from './types';
|
import t from './types';
|
||||||
|
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { useMutation, useQueryClient } from 'react-query';
|
|||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import { transformPagination, saveInvoke } from '@/utils';
|
import { transformPagination, saveInvoke } from '@/utils';
|
||||||
import { useRequestPdf } from '../utils';
|
|
||||||
|
|
||||||
import t from './types';
|
import t from './types';
|
||||||
|
import { useRequestPdf } from '../useRequestPdf';
|
||||||
|
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
const commonInvalidateQueries = (client) => {
|
const commonInvalidateQueries = (client) => {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { useQueryClient, useMutation } from 'react-query';
|
import { useQueryClient, useMutation } from 'react-query';
|
||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import { useRequestPdf } from '../utils';
|
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import { transformPagination } from '@/utils';
|
import { transformPagination } from '@/utils';
|
||||||
|
import { useRequestPdf } from '../useRequestPdf';
|
||||||
import t from './types';
|
import t from './types';
|
||||||
|
|
||||||
const commonInvalidateQueries = (queryClient) => {
|
const commonInvalidateQueries = (queryClient) => {
|
||||||
@@ -165,9 +165,7 @@ export function useReceipt(id, props) {
|
|||||||
* @param {number} receiptId -
|
* @param {number} receiptId -
|
||||||
*/
|
*/
|
||||||
export function usePdfReceipt(receiptId: number) {
|
export function usePdfReceipt(receiptId: number) {
|
||||||
return useRequestPdf({
|
return useRequestPdf({ url: `sales/receipts/${receiptId}` });
|
||||||
url: `sales/receipts/${receiptId}`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useRefreshReceipts() {
|
export function useRefreshReceipts() {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const SALE_RECEIPTS = {
|
|||||||
SALE_RECEIPT: 'SALE_RECEIPT',
|
SALE_RECEIPT: 'SALE_RECEIPT',
|
||||||
SALE_RECEIPT_SMS_DETAIL: 'SALE_RECEIPT_SMS_DETAIL',
|
SALE_RECEIPT_SMS_DETAIL: 'SALE_RECEIPT_SMS_DETAIL',
|
||||||
NOTIFY_SALE_RECEIPT_BY_SMS: 'NOTIFY_SALE_RECEIPT_BY_SMS',
|
NOTIFY_SALE_RECEIPT_BY_SMS: 'NOTIFY_SALE_RECEIPT_BY_SMS',
|
||||||
SALE_RECEIPT_MAIL_OPTIONS: 'SALE_RECEIPT_MAIL_OPTIONS',
|
SALE_RECEIPT_MAIL_OPTIONS: 'SALE_RECEIPT_MAIL_OPTIONS'
|
||||||
};
|
};
|
||||||
|
|
||||||
const INVENTORY_ADJUSTMENTS = {
|
const INVENTORY_ADJUSTMENTS = {
|
||||||
@@ -115,7 +115,7 @@ const SALE_INVOICES = {
|
|||||||
BAD_DEBT: 'BAD_DEBT',
|
BAD_DEBT: 'BAD_DEBT',
|
||||||
CANCEL_BAD_DEBT: 'CANCEL_BAD_DEBT',
|
CANCEL_BAD_DEBT: 'CANCEL_BAD_DEBT',
|
||||||
SALE_INVOICE_PAYMENT_TRANSACTIONS: 'SALE_INVOICE_PAYMENT_TRANSACTIONS',
|
SALE_INVOICE_PAYMENT_TRANSACTIONS: 'SALE_INVOICE_PAYMENT_TRANSACTIONS',
|
||||||
SALE_INVOICE_DEFAULT_OPTIONS: 'SALE_INVOICE_DEFAULT_OPTIONS',
|
SALE_INVOICE_DEFAULT_OPTIONS: 'SALE_INVOICE_DEFAULT_OPTIONS'
|
||||||
};
|
};
|
||||||
|
|
||||||
const USERS = {
|
const USERS = {
|
||||||
@@ -200,9 +200,6 @@ const CASH_FLOW_ACCOUNTS = {
|
|||||||
CASH_FLOW_TRANSACTION: 'CASH_FLOW_TRANSACTION',
|
CASH_FLOW_TRANSACTION: 'CASH_FLOW_TRANSACTION',
|
||||||
CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY:
|
CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY:
|
||||||
'CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY',
|
'CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY',
|
||||||
CASHFLOW_ACCOUNT_UNCATEGORIZED_TRANSACTIONS_INFINITY:
|
|
||||||
'CASHFLOW_ACCOUNT_UNCATEGORIZED_TRANSACTIONS_INFINITY',
|
|
||||||
CASHFLOW_UNCAATEGORIZED_TRANSACTION: 'CASHFLOW_UNCAATEGORIZED_TRANSACTION',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const TARNSACTIONS_LOCKING = {
|
const TARNSACTIONS_LOCKING = {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ export * from './usePrevious';
|
|||||||
export * from './useUpdateEffect';
|
export * from './useUpdateEffect';
|
||||||
export * from './useWatch';
|
export * from './useWatch';
|
||||||
export * from './useWhen';
|
export * from './useWhen';
|
||||||
export * from './useRequestPdf';
|
|
||||||
export * from './useIntersectionObserver';
|
export * from './useIntersectionObserver';
|
||||||
export * from './useAbilityContext';
|
export * from './useAbilityContext';
|
||||||
export * from './useCustomCompareEffect';
|
export * from './useCustomCompareEffect';
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import useApiRequest from '../useRequest';
|
|
||||||
|
|
||||||
export const useRequestPdf = (url) => {
|
|
||||||
const apiRequest = useApiRequest();
|
|
||||||
const [isLoading, setIsLoading] = React.useState(false);
|
|
||||||
const [isLoaded, setIsLoaded] = React.useState(false);
|
|
||||||
const [pdfUrl, setPdfUrl] = React.useState('');
|
|
||||||
const [response, setResponse] = React.useState(null);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
setIsLoading(true);
|
|
||||||
apiRequest
|
|
||||||
.get(url, {
|
|
||||||
headers: { accept: 'application/pdf' },
|
|
||||||
responseType: 'blob',
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
// Create a Blob from the PDF Stream.
|
|
||||||
const file = new Blob([response.data], { type: 'application/pdf' });
|
|
||||||
|
|
||||||
// Build a URL from the file
|
|
||||||
const fileURL = URL.createObjectURL(file);
|
|
||||||
|
|
||||||
setPdfUrl(fileURL);
|
|
||||||
setIsLoading(false);
|
|
||||||
setIsLoaded(true);
|
|
||||||
setResponse(response);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return {
|
|
||||||
isLoading,
|
|
||||||
isLoaded,
|
|
||||||
pdfUrl,
|
|
||||||
response,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -382,12 +382,6 @@ export default {
|
|||||||
],
|
],
|
||||||
viewBox: '0 0 20 20',
|
viewBox: '0 0 20 20',
|
||||||
},
|
},
|
||||||
tick: {
|
|
||||||
path: [
|
|
||||||
'M14,3c-0.28,0-0.53,0.11-0.71,0.29L6,10.59L2.71,7.29C2.53,7.11,2.28,7,2,7C1.45,7,1,7.45,1,8c0,0.28,0.11,0.53,0.29,0.71l4,4C5.47,12.89,5.72,13,6,13s0.53-0.11,0.71-0.29l8-8C14.89,4.53,15,4.28,15,4C15,3.45,14.55,3,14,3z',
|
|
||||||
],
|
|
||||||
viewBox: '0 0 16 16',
|
|
||||||
},
|
|
||||||
'swap-vert': {
|
'swap-vert': {
|
||||||
path: [
|
path: [
|
||||||
'M10.6,10.9V5.4H9v5.5H6.7L9.8,14l3.1-3.1ZM5.1,0,2,3.1H4.3V8.6H5.9V3.1H8.2Z',
|
'M10.6,10.9V5.4H9v5.5H6.7L9.8,14l3.1-3.1ZM5.1,0,2,3.1H4.3V8.6H5.9V3.1H8.2Z',
|
||||||
|
|||||||
@@ -212,16 +212,6 @@ $dashboard-views-bar-height: 44px;
|
|||||||
background: rgba(219, 55, 55, 0.1);
|
background: rgba(219, 55, 55, 0.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&.#{$ns}-minimal.#{$ns}-intent-success{
|
|
||||||
color: #1c6e42;
|
|
||||||
|
|
||||||
&:hover,
|
|
||||||
&:focus {
|
|
||||||
background: rgba(35, 133, 81, 0.1);
|
|
||||||
color: #1c6e42;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
&.button--blue-highlight {
|
&.button--blue-highlight {
|
||||||
background-color: #ebfaff;
|
background-color: #ebfaff;
|
||||||
|
|||||||
Reference in New Issue
Block a user