mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: more resources support importing
This commit is contained in:
@@ -12,7 +12,7 @@ export const VendorsSampleData = [
|
||||
"Opening Balance At": "2022-02-02",
|
||||
"Opening Balance Ex. Rate": 2,
|
||||
"Currency": "LYD",
|
||||
"Active": "F",
|
||||
"Active": "T",
|
||||
"Note": "Doloribus autem optio temporibus dolores mollitia sit.",
|
||||
"Billing Address 1": "862 Jessika Well",
|
||||
"Billing Address 2": "1091 Dorthy Mount",
|
||||
@@ -42,7 +42,7 @@ export const VendorsSampleData = [
|
||||
"Opening Balance At": "2022-02-02",
|
||||
"Opening Balance Ex. Rate": 2,
|
||||
"Currency": "LYD",
|
||||
"Active": "F",
|
||||
"Active": "T",
|
||||
"Note": "Doloribus dolore dolor dicta vitae in fugit nisi quibusdam.",
|
||||
"Billing Address 1": "532 Simonis Spring",
|
||||
"Billing Address 2": "3122 Nicolas Inlet",
|
||||
@@ -72,7 +72,7 @@ export const VendorsSampleData = [
|
||||
"Opening Balance At": "2022-02-02",
|
||||
"Opening Balance Ex. Rate": 2,
|
||||
"Currency": "LYD",
|
||||
"Active": "F",
|
||||
"Active": "T",
|
||||
"Note": "Vero quibusdam rem fugit aperiam est modi.",
|
||||
"Billing Address 1": "214 Sauer Villages",
|
||||
"Billing Address 2": "30687 Kacey Square",
|
||||
@@ -102,7 +102,7 @@ export const VendorsSampleData = [
|
||||
"Opening Balance At": "2022-02-02",
|
||||
"Opening Balance Ex. Rate": 2,
|
||||
"Currency": "LYD",
|
||||
"Active": "F",
|
||||
"Active": "T",
|
||||
"Note": "Quis cumque molestias rerum.",
|
||||
"Billing Address 1": "22590 Cathy Harbor",
|
||||
"Billing Address 2": "24493 Brycen Brooks",
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -8,6 +8,10 @@ import { ItemsImportable } from '../Items/ItemsImportable';
|
||||
import { ItemCategoriesImportable } from '../ItemCategories/ItemCategoriesImportable';
|
||||
import { ManualJournalImportable } from '../ManualJournals/ManualJournalsImport';
|
||||
import { BillsImportable } from '../Purchases/Bills/BillsImportable';
|
||||
import { ExpensesImportable } from '../Expenses/ExpensesImportable';
|
||||
import { SaleInvoicesImportable } from '../Sales/Invoices/SaleInvoicesImportable';
|
||||
import { SaleEstimatesImportable } from '../Sales/Estimates/SaleEstimatesImportable';
|
||||
import { BillPaymentsImportable } from '../Purchases/BillPayments/BillPaymentsImportable';
|
||||
|
||||
@Service()
|
||||
export class ImportableResources {
|
||||
@@ -32,6 +36,10 @@ export class ImportableResources {
|
||||
{ resource: 'ItemCategory', importable: ItemCategoriesImportable },
|
||||
{ resource: 'ManualJournal', importable: ManualJournalImportable },
|
||||
{ resource: 'Bill', importable: BillsImportable },
|
||||
{ resource: 'Expense', importable: ExpensesImportable },
|
||||
{ resource: 'SaleInvoice', importable: SaleInvoicesImportable },
|
||||
{ resource: 'SaleEstimate', importable: SaleEstimatesImportable },
|
||||
{ resource: 'BillPayment', importable: BillPaymentsImportable },
|
||||
];
|
||||
|
||||
public get registry() {
|
||||
|
||||
@@ -102,7 +102,10 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
}
|
||||
});
|
||||
if (foundItemCategory) {
|
||||
throw new ServiceError(ERRORS.CATEGORY_NAME_EXISTS);
|
||||
throw new ServiceError(
|
||||
ERRORS.CATEGORY_NAME_EXISTS,
|
||||
'The item category name is already exist.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,10 @@ export class CommandManualJournalValidators {
|
||||
}
|
||||
});
|
||||
if (journals.length > 0) {
|
||||
throw new ServiceError(ERRORS.JOURNAL_NUMBER_EXISTS);
|
||||
throw new ServiceError(
|
||||
ERRORS.JOURNAL_NUMBER_EXISTS,
|
||||
'The journal number is already exist.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { IBillPaymentDTO } from '@/interfaces';
|
||||
import { CreateBillPayment } from './CreateBillPayment';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
import { BillsPaymentsSampleData } from './constants';
|
||||
|
||||
@Service()
|
||||
export class BillPaymentsImportable extends Importable {
|
||||
@Inject()
|
||||
private createBillPaymentService: CreateBillPayment;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
billPaymentDTO: IBillPaymentDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createBillPaymentService.createBillPayment(
|
||||
tenantId,
|
||||
billPaymentDTO,
|
||||
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 BillsPaymentsSampleData;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,8 @@ export class CreateBillPayment {
|
||||
*/
|
||||
public async createBillPayment(
|
||||
tenantId: number,
|
||||
billPaymentDTO: IBillPaymentDTO
|
||||
billPaymentDTO: IBillPaymentDTO,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<IBillPayment> {
|
||||
const { BillPayment, Contact } = this.tenancy.models(tenantId);
|
||||
|
||||
@@ -97,28 +98,32 @@ export class CreateBillPayment {
|
||||
);
|
||||
// Writes bill payment transacation with associated transactions
|
||||
// under unit-of-work envirement.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onBillPaymentCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.billPayment.onCreating, {
|
||||
tenantId,
|
||||
billPaymentDTO,
|
||||
trx,
|
||||
} as IBillPaymentCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onBillPaymentCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.billPayment.onCreating, {
|
||||
tenantId,
|
||||
billPaymentDTO,
|
||||
trx,
|
||||
} as IBillPaymentCreatingPayload);
|
||||
|
||||
// Writes the bill payment graph to the storage.
|
||||
const billPayment = await BillPayment.query(trx).insertGraphAndFetch({
|
||||
...billPaymentObj,
|
||||
});
|
||||
// Writes the bill payment graph to the storage.
|
||||
const billPayment = await BillPayment.query(trx).insertGraphAndFetch({
|
||||
...billPaymentObj,
|
||||
});
|
||||
|
||||
// Triggers `onBillPaymentCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.billPayment.onCreated, {
|
||||
tenantId,
|
||||
billPayment,
|
||||
billPaymentId: billPayment.id,
|
||||
trx,
|
||||
} as IBillPaymentEventCreatedPayload);
|
||||
// Triggers `onBillPaymentCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.billPayment.onCreated, {
|
||||
tenantId,
|
||||
billPayment,
|
||||
billPaymentId: billPayment.id,
|
||||
trx,
|
||||
} as IBillPaymentEventCreatedPayload);
|
||||
|
||||
return billPayment;
|
||||
});
|
||||
return billPayment;
|
||||
},
|
||||
trx
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,3 +15,36 @@ export const ERRORS = {
|
||||
};
|
||||
|
||||
export const DEFAULT_VIEWS = [];
|
||||
|
||||
export const BillsPaymentsSampleData = [
|
||||
{
|
||||
'Payment Date': '2024-03-01',
|
||||
Vendor: 'Gabriel Kovacek',
|
||||
'Payment No.': 'P-10001',
|
||||
'Reference No.': 'REF-1',
|
||||
'Payment Account': 'Petty Cash',
|
||||
Statement: 'Vel et dolorem architecto veniam.',
|
||||
'Bill No': 'B-120',
|
||||
'Payment Amount': 100,
|
||||
},
|
||||
{
|
||||
'Payment Date': '2024-03-02',
|
||||
Vendor: 'Gabriel Kovacek',
|
||||
'Payment No.': 'P-10002',
|
||||
'Reference No.': 'REF-2',
|
||||
'Payment Account': 'Petty Cash',
|
||||
Statement: 'Id est molestias.',
|
||||
'Bill No': 'B-121',
|
||||
'Payment Amount': 100,
|
||||
},
|
||||
{
|
||||
'Payment Date': '2024-03-03',
|
||||
Vendor: 'Gabriel Kovacek',
|
||||
'Payment No.': 'P-10003',
|
||||
'Reference No.': 'REF-3',
|
||||
'Payment Account': 'Petty Cash',
|
||||
Statement: 'Quam cupiditate at nihil dicta dignissimos non fugit illo.',
|
||||
'Bill No': 'B-122',
|
||||
'Payment Amount': 100,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Knex } from 'knex';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
import { CreateBill } from './CreateBill';
|
||||
import { IBillDTO } from '@/interfaces';
|
||||
import { BillsSampleData } from './constants';
|
||||
|
||||
@Service()
|
||||
export class BillsImportable extends Importable {
|
||||
@@ -20,7 +21,6 @@ export class BillsImportable extends Importable {
|
||||
createAccountDTO: IBillDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
console.log(JSON.stringify(createAccountDTO));
|
||||
return this.createBillService.createBill(
|
||||
tenantId,
|
||||
createAccountDTO,
|
||||
@@ -41,6 +41,6 @@ export class BillsImportable extends Importable {
|
||||
* Retrieves the sample data that used to download accounts sample sheet.
|
||||
*/
|
||||
public sampleData(): any[] {
|
||||
return [];
|
||||
return BillsSampleData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ export class BillsValidators {
|
||||
|
||||
/**
|
||||
* Validates the bill amount is bigger than paid amount.
|
||||
* @param {number} billAmount
|
||||
* @param {number} paidAmount
|
||||
* @param {number} billAmount
|
||||
* @param {number} paidAmount
|
||||
*/
|
||||
public validateBillAmountBiggerPaidAmount(
|
||||
billAmount: number,
|
||||
paidAmount: number,
|
||||
paidAmount: number
|
||||
) {
|
||||
if (billAmount < paidAmount) {
|
||||
throw new ServiceError(ERRORS.BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT);
|
||||
@@ -53,7 +53,10 @@ export class BillsValidators {
|
||||
});
|
||||
|
||||
if (foundBills.length > 0) {
|
||||
throw new ServiceError(ERRORS.BILL_NUMBER_EXISTS);
|
||||
throw new ServiceError(
|
||||
ERRORS.BILL_NUMBER_EXISTS,
|
||||
'The bill number is not unique.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,3 +75,49 @@ export const DEFAULT_VIEWS = [
|
||||
columns: DEFAULT_VIEW_COLUMNS,
|
||||
},
|
||||
];
|
||||
|
||||
export const BillsSampleData = [
|
||||
{
|
||||
'Bill No.': 'B-101',
|
||||
'Reference No.': 'REF0',
|
||||
Date: '2024-01-01',
|
||||
'Due Date': '2024-03-01',
|
||||
Vendor: 'Gabriel Kovacek',
|
||||
'Exchange Rate': 1,
|
||||
Note: 'Vel in sit sint.',
|
||||
Open: 'T',
|
||||
Item: 'VonRueden, Ruecker and Hettinger',
|
||||
Quantity: 100,
|
||||
Rate: 100,
|
||||
'Line Description': 'Id a vel quis vel aut.',
|
||||
},
|
||||
{
|
||||
'Bill No.': 'B-102',
|
||||
'Reference No.': 'REF0',
|
||||
Date: '2024-01-01',
|
||||
'Due Date': '2024-03-01',
|
||||
Vendor: 'Gabriel Kovacek',
|
||||
'Exchange Rate': 1,
|
||||
Note: 'Quia ut dolorem qui sint velit.',
|
||||
Open: 'T',
|
||||
Item: 'Thompson - Reichert',
|
||||
Quantity: 200,
|
||||
Rate: 50,
|
||||
'Line Description':
|
||||
'Nesciunt in adipisci quia ab reiciendis nam sed saepe consequatur.',
|
||||
},
|
||||
{
|
||||
'Bill No.': 'B-103',
|
||||
'Reference No.': 'REF0',
|
||||
Date: '2024-01-01',
|
||||
'Due Date': '2024-03-01',
|
||||
Vendor: 'Gabriel Kovacek',
|
||||
'Exchange Rate': 1,
|
||||
Note: 'Dolore aut voluptatem minus pariatur alias pariatur.',
|
||||
Open: 'T',
|
||||
Item: 'VonRueden, Ruecker and Hettinger',
|
||||
Quantity: 100,
|
||||
Rate: 100,
|
||||
'Line Description': 'Quam eligendi provident.',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -105,11 +105,14 @@ export default class ResourceService {
|
||||
const $enumerationType = (field) =>
|
||||
field.fieldType === 'enumeration' ? field : undefined;
|
||||
|
||||
const $hasFields = (field) => 'undefined' !== typeof field.fields ? field : undefined;
|
||||
|
||||
const naviagations = [
|
||||
['fields', qim.$each, 'name'],
|
||||
['fields2', qim.$each, 'name'],
|
||||
['fields', qim.$each, $enumerationType, 'options', qim.$each, 'label'],
|
||||
['fields2', qim.$each, 'name'],
|
||||
['fields2', qim.$each, $enumerationType, 'options', qim.$each, 'label'],
|
||||
['fields2', qim.$each, $hasFields, 'fields', qim.$each, 'name'],
|
||||
];
|
||||
return this.i18nService.i18nApply(naviagations, meta, tenantId);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ export class CreateSaleEstimate {
|
||||
*/
|
||||
public async createEstimate(
|
||||
tenantId: number,
|
||||
estimateDTO: ISaleEstimateDTO
|
||||
estimateDTO: ISaleEstimateDTO,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<ISaleEstimate> {
|
||||
const { SaleEstimate, Contact } = this.tenancy.models(tenantId);
|
||||
|
||||
@@ -75,28 +76,32 @@ export class CreateSaleEstimate {
|
||||
estimateDTO.entries
|
||||
);
|
||||
// Creates a sale estimate transaction with associated transactions as UOW.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onSaleEstimateCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.saleEstimate.onCreating, {
|
||||
estimateDTO,
|
||||
tenantId,
|
||||
trx,
|
||||
} as ISaleEstimateCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onSaleEstimateCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.saleEstimate.onCreating, {
|
||||
estimateDTO,
|
||||
tenantId,
|
||||
trx,
|
||||
} as ISaleEstimateCreatingPayload);
|
||||
|
||||
// Upsert the sale estimate graph to the storage.
|
||||
const saleEstimate = await SaleEstimate.query(trx).upsertGraphAndFetch({
|
||||
...estimateObj,
|
||||
});
|
||||
// Triggers `onSaleEstimateCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.saleEstimate.onCreated, {
|
||||
tenantId,
|
||||
saleEstimate,
|
||||
saleEstimateId: saleEstimate.id,
|
||||
saleEstimateDTO: estimateDTO,
|
||||
trx,
|
||||
} as ISaleEstimateCreatedPayload);
|
||||
// Upsert the sale estimate graph to the storage.
|
||||
const saleEstimate = await SaleEstimate.query(trx).upsertGraphAndFetch({
|
||||
...estimateObj,
|
||||
});
|
||||
// Triggers `onSaleEstimateCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.saleEstimate.onCreated, {
|
||||
tenantId,
|
||||
saleEstimate,
|
||||
saleEstimateId: saleEstimate.id,
|
||||
saleEstimateDTO: estimateDTO,
|
||||
trx,
|
||||
} as ISaleEstimateCreatedPayload);
|
||||
|
||||
return saleEstimate;
|
||||
});
|
||||
return saleEstimate;
|
||||
},
|
||||
trx
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,10 @@ export class SaleEstimateValidators {
|
||||
}
|
||||
});
|
||||
if (foundSaleEstimate) {
|
||||
throw new ServiceError(ERRORS.SALE_ESTIMATE_NUMBER_EXISTANCE);
|
||||
throw new ServiceError(
|
||||
ERRORS.SALE_ESTIMATE_NUMBER_EXISTANCE,
|
||||
'The given sale estimate is not unique.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { ISaleEstimateDTO } from '@/interfaces';
|
||||
import { CreateSaleEstimate } from './CreateSaleEstimate';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
import { SaleEstimatesSampleData } from './constants';
|
||||
|
||||
@Service()
|
||||
export class SaleEstimatesImportable extends Importable {
|
||||
@Inject()
|
||||
private createEstimateService: CreateSaleEstimate;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createEstimateDTO: ISaleEstimateDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createEstimateService.createEstimate(
|
||||
tenantId,
|
||||
createEstimateDTO,
|
||||
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 SaleEstimatesSampleData;
|
||||
}
|
||||
}
|
||||
@@ -122,3 +122,54 @@ export const DEFAULT_VIEWS = [
|
||||
columns: DEFAULT_VIEW_COLUMNS,
|
||||
},
|
||||
];
|
||||
|
||||
export const SaleEstimatesSampleData = [
|
||||
{
|
||||
Customer: 'Ambrose Olson',
|
||||
'Estimate Date': '2024-01-01',
|
||||
'Expiration Date': '2025-01-01',
|
||||
'Estimate No.': 'EST-0001',
|
||||
'Reference No.': 'REF-0001',
|
||||
Currency: '',
|
||||
'Exchange Rate': '',
|
||||
Note: 'Vel autem quis aut ab.',
|
||||
'Terms & Conditions': 'Provident illo architecto sit iste in.',
|
||||
Delivered: 'T',
|
||||
'Item Name': 'Hettinger, Schumm and Bartoletti',
|
||||
Quantity: 1000,
|
||||
Rate: 20,
|
||||
'Line Description': 'Rem esse doloremque praesentium harum maiores.',
|
||||
},
|
||||
{
|
||||
Customer: 'Ambrose Olson',
|
||||
'Estimate Date': '2024-01-02',
|
||||
'Expiration Date': '2025-01-02',
|
||||
'Estimate No.': 'EST-0002',
|
||||
'Reference No.': 'REF-0002',
|
||||
Currency: '',
|
||||
'Exchange Rate': '',
|
||||
Note: 'Tempora voluptas odio deleniti rerum vitae consequatur nihil quis sunt.',
|
||||
'Terms & Conditions': 'Ut eum incidunt quibusdam rerum vero.',
|
||||
Delivered: 'T',
|
||||
'Item Name': 'Hettinger, Schumm and Bartoletti',
|
||||
Quantity: 1000,
|
||||
Rate: 20,
|
||||
'Line Description': 'Qui voluptate aliquam maxime aliquam.',
|
||||
},
|
||||
{
|
||||
Customer: 'Ambrose Olson',
|
||||
'Estimate Date': '2024-01-03',
|
||||
'Expiration Date': '2025-01-03',
|
||||
'Estimate No.': 'EST-0003',
|
||||
'Reference No.': 'REF-0003',
|
||||
Currency: '',
|
||||
'Exchange Rate': '',
|
||||
Note: 'Quia voluptatem delectus doloremque.',
|
||||
'Terms & Conditions': 'Facilis porro vitae ratione.',
|
||||
Delivered: 'T',
|
||||
'Item Name': 'Hettinger, Schumm and Bartoletti',
|
||||
Quantity: 1000,
|
||||
Rate: 20,
|
||||
'Line Description': 'Qui suscipit ducimus qui qui.',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -51,7 +51,8 @@ export class CreateSaleInvoice {
|
||||
public createSaleInvoice = async (
|
||||
tenantId: number,
|
||||
saleInvoiceDTO: ISaleInvoiceCreateDTO,
|
||||
authorizedUser: ITenantUser
|
||||
authorizedUser: ITenantUser,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<ISaleInvoice> => {
|
||||
const { SaleInvoice, SaleEstimate, Contact } =
|
||||
this.tenancy.models(tenantId);
|
||||
@@ -96,33 +97,37 @@ export class CreateSaleInvoice {
|
||||
);
|
||||
}
|
||||
// Creates a new sale invoice and associated transactions under unit of work env.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onSaleInvoiceCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.saleInvoice.onCreating, {
|
||||
saleInvoiceDTO,
|
||||
tenantId,
|
||||
trx,
|
||||
} as ISaleInvoiceCreatingPaylaod);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onSaleInvoiceCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.saleInvoice.onCreating, {
|
||||
saleInvoiceDTO,
|
||||
tenantId,
|
||||
trx,
|
||||
} as ISaleInvoiceCreatingPaylaod);
|
||||
|
||||
// Create sale invoice graph to the storage.
|
||||
const saleInvoice = await SaleInvoice.query(trx).upsertGraph(
|
||||
saleInvoiceObj
|
||||
);
|
||||
const eventPayload: ISaleInvoiceCreatedPayload = {
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
saleInvoiceDTO,
|
||||
saleInvoiceId: saleInvoice.id,
|
||||
authorizedUser,
|
||||
trx,
|
||||
};
|
||||
// Triggers the event `onSaleInvoiceCreated`.
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.saleInvoice.onCreated,
|
||||
eventPayload
|
||||
);
|
||||
return saleInvoice;
|
||||
});
|
||||
// Create sale invoice graph to the storage.
|
||||
const saleInvoice = await SaleInvoice.query(trx).upsertGraph(
|
||||
saleInvoiceObj
|
||||
);
|
||||
const eventPayload: ISaleInvoiceCreatedPayload = {
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
saleInvoiceDTO,
|
||||
saleInvoiceId: saleInvoice.id,
|
||||
authorizedUser,
|
||||
trx,
|
||||
};
|
||||
// Triggers the event `onSaleInvoiceCreated`.
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.saleInvoice.onCreated,
|
||||
eventPayload
|
||||
);
|
||||
return saleInvoice;
|
||||
},
|
||||
trx
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { ISaleInvoiceCreateDTO } from '@/interfaces';
|
||||
import { CreateSaleInvoice } from './CreateSaleInvoice';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
|
||||
@Service()
|
||||
export class SaleInvoicesImportable extends Importable {
|
||||
@Inject()
|
||||
private createInvoiceService: CreateSaleInvoice;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createAccountDTO: ISaleInvoiceCreateDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createInvoiceService.createSaleInvoice(
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user