mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat: more resources support importing
This commit is contained in:
@@ -88,7 +88,8 @@ export class CreateExpense {
|
||||
public newExpense = async (
|
||||
tenantId: number,
|
||||
expenseDTO: IExpenseCreateDTO,
|
||||
authorizedUser: ISystemUser
|
||||
authorizedUser: ISystemUser,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<IExpense> => {
|
||||
const { Expense } = await this.tenancy.models(tenantId);
|
||||
|
||||
@@ -103,28 +104,32 @@ export class CreateExpense {
|
||||
);
|
||||
// Writes the expense transaction with associated transactions under
|
||||
// unit-of-work envirement.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onExpenseCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.expenses.onCreating, {
|
||||
trx,
|
||||
tenantId,
|
||||
expenseDTO,
|
||||
} as IExpenseCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onExpenseCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.expenses.onCreating, {
|
||||
trx,
|
||||
tenantId,
|
||||
expenseDTO,
|
||||
} as IExpenseCreatingPayload);
|
||||
|
||||
// Creates a new expense transaction graph.
|
||||
const expense: IExpense = await Expense.query(trx).upsertGraph(
|
||||
expenseObj
|
||||
);
|
||||
// Triggers `onExpenseCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.expenses.onCreated, {
|
||||
tenantId,
|
||||
expenseId: expense.id,
|
||||
authorizedUser,
|
||||
expense,
|
||||
trx,
|
||||
} as IExpenseCreatedPayload);
|
||||
// Creates a new expense transaction graph.
|
||||
const expense: IExpense = await Expense.query(trx).upsertGraph(
|
||||
expenseObj
|
||||
);
|
||||
// Triggers `onExpenseCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.expenses.onCreated, {
|
||||
tenantId,
|
||||
expenseId: expense.id,
|
||||
authorizedUser,
|
||||
expense,
|
||||
trx,
|
||||
} as IExpenseCreatedPayload);
|
||||
|
||||
return expense;
|
||||
});
|
||||
return expense;
|
||||
},
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
46
packages/server/src/services/Expenses/ExpensesImportable.ts
Normal file
46
packages/server/src/services/Expenses/ExpensesImportable.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { IExpenseCreateDTO } from '@/interfaces';
|
||||
import { Importable } from '../Import/Importable';
|
||||
import { CreateExpense } from './CRUD/CreateExpense';
|
||||
import { ExpensesSampleData } from './constants';
|
||||
|
||||
@Service()
|
||||
export class ExpensesImportable extends Importable {
|
||||
@Inject()
|
||||
private createExpenseService: CreateExpense;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createAccountDTO: IExpenseCreateDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createExpenseService.newExpense(
|
||||
tenantId,
|
||||
createAccountDTO,
|
||||
{},
|
||||
trx
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Concurrrency controlling of the importing process.
|
||||
* @returns {number}
|
||||
*/
|
||||
public get concurrency() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sample data that used to download accounts sample sheet.
|
||||
*/
|
||||
public sampleData(): any[] {
|
||||
return ExpensesSampleData;
|
||||
}
|
||||
}
|
||||
@@ -36,3 +36,43 @@ export const ERRORS = {
|
||||
EXPENSE_ALREADY_PUBLISHED: 'expense_already_published',
|
||||
EXPENSE_HAS_ASSOCIATED_LANDED_COST: 'EXPENSE_HAS_ASSOCIATED_LANDED_COST',
|
||||
};
|
||||
|
||||
export const ExpensesSampleData = [
|
||||
{
|
||||
'Payment Date': '2024-03-01',
|
||||
'Reference No.': 'REF-1',
|
||||
'Payment Account': 'Petty Cash',
|
||||
Description: 'Vel et dolorem architecto veniam.',
|
||||
'Currency Code': '',
|
||||
'Exchange Rate': '',
|
||||
'Expense Account': 'Utilities Expense',
|
||||
Amount: 9000,
|
||||
'Line Description': 'Voluptates voluptas corporis vel.',
|
||||
Publish: 'T',
|
||||
},
|
||||
{
|
||||
'Payment Date': '2024-03-02',
|
||||
'Reference No.': 'REF-2',
|
||||
'Payment Account': 'Petty Cash',
|
||||
Description: 'Id est molestias.',
|
||||
'Currency Code': '',
|
||||
'Exchange Rate': '',
|
||||
'Expense Account': 'Utilities Expense',
|
||||
Amount: 9000,
|
||||
'Line Description': 'Eos voluptatem cumque et voluptate reiciendis.',
|
||||
Publish: 'T',
|
||||
},
|
||||
{
|
||||
'Payment Date': '2024-03-03',
|
||||
'Reference No.': 'REF-3',
|
||||
'Payment Account': 'Petty Cash',
|
||||
Description: 'Quam cupiditate at nihil dicta dignissimos non fugit illo.',
|
||||
'Currency Code': '',
|
||||
'Exchange Rate': '',
|
||||
'Expense Account': 'Utilities Expense',
|
||||
Amount: 9000,
|
||||
'Line Description':
|
||||
'Hic alias rerum sed commodi dolores sint animi perferendis.',
|
||||
Publish: 'T',
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user