mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: configuring import services on more resources
This commit is contained in:
@@ -34,7 +34,7 @@ export default class CreateCreditNote extends BaseCreditNotes {
|
||||
public newCreditNote = async (
|
||||
tenantId: number,
|
||||
creditNoteDTO: ICreditNoteNewDTO,
|
||||
authorizedUser: ISystemUser
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
const { CreditNote, Contact } = this.tenancy.models(tenantId);
|
||||
|
||||
@@ -66,28 +66,32 @@ export default class CreateCreditNote extends BaseCreditNotes {
|
||||
customer.currencyCode
|
||||
);
|
||||
// Creates a new credit card transactions under unit-of-work envirement.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onCreditNoteCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.creditNote.onCreating, {
|
||||
tenantId,
|
||||
creditNoteDTO,
|
||||
trx,
|
||||
} as ICreditNoteCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onCreditNoteCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.creditNote.onCreating, {
|
||||
tenantId,
|
||||
creditNoteDTO,
|
||||
trx,
|
||||
} as ICreditNoteCreatingPayload);
|
||||
|
||||
// Upsert the credit note graph.
|
||||
const creditNote = await CreditNote.query(trx).upsertGraph({
|
||||
...creditNoteModel,
|
||||
});
|
||||
// Triggers `onCreditNoteCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.creditNote.onCreated, {
|
||||
tenantId,
|
||||
creditNoteDTO,
|
||||
creditNote,
|
||||
creditNoteId: creditNote.id,
|
||||
trx,
|
||||
} as ICreditNoteCreatedPayload);
|
||||
// Upsert the credit note graph.
|
||||
const creditNote = await CreditNote.query(trx).upsertGraph({
|
||||
...creditNoteModel,
|
||||
});
|
||||
// Triggers `onCreditNoteCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.creditNote.onCreated, {
|
||||
tenantId,
|
||||
creditNoteDTO,
|
||||
creditNote,
|
||||
creditNoteId: creditNote.id,
|
||||
trx,
|
||||
} as ICreditNoteCreatedPayload);
|
||||
|
||||
return creditNote;
|
||||
});
|
||||
return creditNote;
|
||||
},
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { ICreditNoteNewDTO } from '@/interfaces';
|
||||
import { Importable } from '../Import/Importable';
|
||||
import CreateCreditNote from './CreateCreditNote';
|
||||
|
||||
@Service()
|
||||
export class CreditNotesImportable extends Importable {
|
||||
@Inject()
|
||||
private createCreditNoteImportable: CreateCreditNote;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createAccountDTO: ICreditNoteNewDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createCreditNoteImportable.newCreditNote(
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@ import { ExpensesImportable } from '../Expenses/ExpensesImportable';
|
||||
import { SaleInvoicesImportable } from '../Sales/Invoices/SaleInvoicesImportable';
|
||||
import { SaleEstimatesImportable } from '../Sales/Estimates/SaleEstimatesImportable';
|
||||
import { BillPaymentsImportable } from '../Purchases/BillPayments/BillPaymentsImportable';
|
||||
import { VendorCreditsImportable } from '../Purchases/VendorCredits/VendorCreditsImportable';
|
||||
import { PaymentReceivesImportable } from '../Sales/PaymentReceives/PaymentReceivesImportable';
|
||||
import { CreditNotesImportable } from '../CreditNotes/CreditNotesImportable';
|
||||
import { SaleReceiptsImportable } from '../Sales/Receipts/SaleReceiptsImportable';
|
||||
|
||||
@Service()
|
||||
export class ImportableResources {
|
||||
@@ -40,6 +44,10 @@ export class ImportableResources {
|
||||
{ resource: 'SaleInvoice', importable: SaleInvoicesImportable },
|
||||
{ resource: 'SaleEstimate', importable: SaleEstimatesImportable },
|
||||
{ resource: 'BillPayment', importable: BillPaymentsImportable },
|
||||
{ resource: 'PaymentReceive', importable: PaymentReceivesImportable },
|
||||
{ resource: 'VendorCredit', importable: VendorCreditsImportable },
|
||||
{ resource: 'CreditNote', importable: CreditNotesImportable },
|
||||
{ resource: 'SaleReceipt', importable: SaleReceiptsImportable }
|
||||
];
|
||||
|
||||
public get registry() {
|
||||
|
||||
@@ -33,7 +33,8 @@ export default class CreateVendorCredit extends BaseVendorCredit {
|
||||
*/
|
||||
public newVendorCredit = async (
|
||||
tenantId: number,
|
||||
vendorCreditCreateDTO: IVendorCreditCreateDTO
|
||||
vendorCreditCreateDTO: IVendorCreditCreateDTO,
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
const { VendorCredit, Vendor } = this.tenancy.models(tenantId);
|
||||
|
||||
@@ -59,27 +60,31 @@ export default class CreateVendorCredit extends BaseVendorCredit {
|
||||
vendor.currencyCode
|
||||
);
|
||||
// Saves the vendor credit transactions under UOW envirement.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onVendorCreditCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.vendorCredit.onCreating, {
|
||||
tenantId,
|
||||
vendorCreditCreateDTO,
|
||||
trx,
|
||||
} as IVendorCreditCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onVendorCreditCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.vendorCredit.onCreating, {
|
||||
tenantId,
|
||||
vendorCreditCreateDTO,
|
||||
trx,
|
||||
} as IVendorCreditCreatingPayload);
|
||||
|
||||
// Saves the vendor credit graph.
|
||||
const vendorCredit = await VendorCredit.query(trx).upsertGraphAndFetch({
|
||||
...vendorCreditModel,
|
||||
});
|
||||
// Triggers `onVendorCreditCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.vendorCredit.onCreated, {
|
||||
tenantId,
|
||||
vendorCredit,
|
||||
vendorCreditCreateDTO,
|
||||
trx,
|
||||
} as IVendorCreditCreatedPayload);
|
||||
// Saves the vendor credit graph.
|
||||
const vendorCredit = await VendorCredit.query(trx).upsertGraphAndFetch({
|
||||
...vendorCreditModel,
|
||||
});
|
||||
// Triggers `onVendorCreditCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.vendorCredit.onCreated, {
|
||||
tenantId,
|
||||
vendorCredit,
|
||||
vendorCreditCreateDTO,
|
||||
trx,
|
||||
} as IVendorCreditCreatedPayload);
|
||||
|
||||
return vendorCredit;
|
||||
});
|
||||
return vendorCredit;
|
||||
},
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
import CreateVendorCredit from './CreateVendorCredit';
|
||||
import { IVendorCreditCreateDTO } from '@/interfaces';
|
||||
import { VendorCreditsSampleData } from './constants';
|
||||
|
||||
@Service()
|
||||
export class VendorCreditsImportable extends Importable {
|
||||
@Inject()
|
||||
private createVendorCreditService: CreateVendorCredit;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createPaymentDTO: IVendorCreditCreateDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createVendorCreditService.newVendorCredit(
|
||||
tenantId,
|
||||
createPaymentDTO,
|
||||
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 VendorCreditsSampleData;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
export const ERRORS = {
|
||||
VENDOR_CREDIT_NOT_FOUND: 'VENDOR_CREDIT_NOT_FOUND',
|
||||
VENDOR_CREDIT_ALREADY_OPENED: 'VENDOR_CREDIT_ALREADY_OPENED',
|
||||
VENDOR_CREDIT_HAS_NO_REMAINING_AMOUNT: 'VENDOR_CREDIT_HAS_NO_REMAINING_AMOUNT',
|
||||
VENDOR_CREDIT_APPLY_TO_BILLS_NOT_FOUND: 'VENDOR_CREDIT_APPLY_TO_BILLS_NOT_FOUND',
|
||||
VENDOR_CREDIT_HAS_NO_REMAINING_AMOUNT:
|
||||
'VENDOR_CREDIT_HAS_NO_REMAINING_AMOUNT',
|
||||
VENDOR_CREDIT_APPLY_TO_BILLS_NOT_FOUND:
|
||||
'VENDOR_CREDIT_APPLY_TO_BILLS_NOT_FOUND',
|
||||
BILLS_HAS_NO_REMAINING_AMOUNT: 'BILLS_HAS_NO_REMAINING_AMOUNT',
|
||||
VENDOR_CREDIT_HAS_REFUND_TRANSACTIONS: 'VENDOR_CREDIT_HAS_REFUND_TRANSACTIONS',
|
||||
VENDOR_CREDIT_HAS_APPLIED_BILLS: 'VENDOR_CREDIT_HAS_APPLIED_BILLS'
|
||||
VENDOR_CREDIT_HAS_REFUND_TRANSACTIONS:
|
||||
'VENDOR_CREDIT_HAS_REFUND_TRANSACTIONS',
|
||||
VENDOR_CREDIT_HAS_APPLIED_BILLS: 'VENDOR_CREDIT_HAS_APPLIED_BILLS',
|
||||
};
|
||||
|
||||
export const DEFAULT_VIEW_COLUMNS = [];
|
||||
@@ -62,3 +65,18 @@ export const DEFAULT_VIEWS = [
|
||||
columns: DEFAULT_VIEW_COLUMNS,
|
||||
},
|
||||
];
|
||||
|
||||
export const VendorCreditsSampleData = [
|
||||
{
|
||||
Vendor: 'Randall Kohler VENDOR',
|
||||
'Vendor Credit Date': '2024-01-01',
|
||||
'Vendor Credit No.': 'VC-0001',
|
||||
'Reference No.': 'REF-00001',
|
||||
'Exchange Rate': '',
|
||||
Note: 'Note',
|
||||
Open: 'T',
|
||||
'Item Name': 'Hettinger, Schumm and Bartoletti',
|
||||
Quantity: 100,
|
||||
Rate: 100,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -42,7 +42,8 @@ export class CreatePaymentReceive {
|
||||
public async createPaymentReceive(
|
||||
tenantId: number,
|
||||
paymentReceiveDTO: IPaymentReceiveCreateDTO,
|
||||
authorizedUser: ISystemUser
|
||||
authorizedUser: ISystemUser,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
const { PaymentReceive, Contact } = this.tenancy.models(tenantId);
|
||||
|
||||
@@ -88,31 +89,35 @@ export class CreatePaymentReceive {
|
||||
tenantMeta.baseCurrency
|
||||
);
|
||||
// Creates a payment receive transaction under UOW envirment.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onPaymentReceiveCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.paymentReceive.onCreating, {
|
||||
trx,
|
||||
paymentReceiveDTO,
|
||||
tenantId,
|
||||
} as IPaymentReceiveCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onPaymentReceiveCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.paymentReceive.onCreating, {
|
||||
trx,
|
||||
paymentReceiveDTO,
|
||||
tenantId,
|
||||
} as IPaymentReceiveCreatingPayload);
|
||||
|
||||
// Inserts the payment receive transaction.
|
||||
const paymentReceive = await PaymentReceive.query(
|
||||
trx
|
||||
).insertGraphAndFetch({
|
||||
...paymentReceiveObj,
|
||||
});
|
||||
// Triggers `onPaymentReceiveCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.paymentReceive.onCreated, {
|
||||
tenantId,
|
||||
paymentReceive,
|
||||
paymentReceiveId: paymentReceive.id,
|
||||
authorizedUser,
|
||||
trx,
|
||||
} as IPaymentReceiveCreatedPayload);
|
||||
// Inserts the payment receive transaction.
|
||||
const paymentReceive = await PaymentReceive.query(
|
||||
trx
|
||||
).insertGraphAndFetch({
|
||||
...paymentReceiveObj,
|
||||
});
|
||||
// Triggers `onPaymentReceiveCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.paymentReceive.onCreated, {
|
||||
tenantId,
|
||||
paymentReceive,
|
||||
paymentReceiveId: paymentReceive.id,
|
||||
authorizedUser,
|
||||
trx,
|
||||
} as IPaymentReceiveCreatedPayload);
|
||||
|
||||
return paymentReceive;
|
||||
});
|
||||
return paymentReceive;
|
||||
},
|
||||
trx
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { IPaymentReceiveCreateDTO } from '@/interfaces';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
import { CreatePaymentReceive } from './CreatePaymentReceive';
|
||||
|
||||
@Service()
|
||||
export class PaymentReceivesImportable extends Importable {
|
||||
@Inject()
|
||||
private createPaymentReceiveService: CreatePaymentReceive;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createPaymentDTO: IPaymentReceiveCreateDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createPaymentReceiveService.createPaymentReceive(
|
||||
tenantId,
|
||||
createPaymentDTO,
|
||||
{},
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,8 @@ export class CreateSaleReceipt {
|
||||
*/
|
||||
public async createSaleReceipt(
|
||||
tenantId: number,
|
||||
saleReceiptDTO: any
|
||||
saleReceiptDTO: any,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<ISaleReceipt> {
|
||||
const { SaleReceipt, Contact } = this.tenancy.models(tenantId);
|
||||
|
||||
@@ -80,27 +81,31 @@ export class CreateSaleReceipt {
|
||||
);
|
||||
}
|
||||
// Creates a sale receipt transaction and associated transactions under UOW env.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onSaleReceiptCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.saleReceipt.onCreating, {
|
||||
saleReceiptDTO,
|
||||
tenantId,
|
||||
trx,
|
||||
} as ISaleReceiptCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onSaleReceiptCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.saleReceipt.onCreating, {
|
||||
saleReceiptDTO,
|
||||
tenantId,
|
||||
trx,
|
||||
} as ISaleReceiptCreatingPayload);
|
||||
|
||||
// Inserts the sale receipt graph to the storage.
|
||||
const saleReceipt = await SaleReceipt.query().upsertGraph({
|
||||
...saleReceiptObj,
|
||||
});
|
||||
// Triggers `onSaleReceiptCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.saleReceipt.onCreated, {
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
saleReceiptId: saleReceipt.id,
|
||||
trx,
|
||||
} as ISaleReceiptCreatedPayload);
|
||||
// Inserts the sale receipt graph to the storage.
|
||||
const saleReceipt = await SaleReceipt.query().upsertGraph({
|
||||
...saleReceiptObj,
|
||||
});
|
||||
// Triggers `onSaleReceiptCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.saleReceipt.onCreated, {
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
saleReceiptId: saleReceipt.id,
|
||||
trx,
|
||||
} as ISaleReceiptCreatedPayload);
|
||||
|
||||
return saleReceipt;
|
||||
});
|
||||
return saleReceipt;
|
||||
},
|
||||
trx
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { IAccountCreateDTO } from '@/interfaces';
|
||||
import { CreateSaleReceipt } from './CreateSaleReceipt';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
import { SaleReceiptsSampleData } from './constants';
|
||||
|
||||
@Service()
|
||||
export class SaleReceiptsImportable extends Importable {
|
||||
@Inject()
|
||||
private createReceiptService: CreateSaleReceipt;
|
||||
|
||||
/**
|
||||
* Importing to sale receipts service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createAccountDTO: IAccountCreateDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createReceiptService.createSaleReceipt(
|
||||
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 SaleReceiptsSampleData;
|
||||
}
|
||||
}
|
||||
@@ -46,3 +46,23 @@ export const DEFAULT_VIEWS = [
|
||||
columns: DEFAULT_VIEW_COLUMNS,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
export const SaleReceiptsSampleData = [
|
||||
{
|
||||
"Receipt Date": "2023-01-01",
|
||||
"Customer": "Randall Kohler",
|
||||
"Deposit Account": "Petty Cash",
|
||||
"Exchange Rate": "",
|
||||
"Receipt Number": "REC-00001",
|
||||
"Reference No.": "REF-0001",
|
||||
"Statement": "Delectus unde aut soluta et accusamus placeat.",
|
||||
"Receipt Message": "Vitae asperiores dicta.",
|
||||
"Closed": "T",
|
||||
"Item": "Schmitt Group",
|
||||
"Quantity": 100,
|
||||
"Rate": 200,
|
||||
"Line Description": "Distinctio distinctio sit veritatis consequatur iste quod veritatis."
|
||||
}
|
||||
|
||||
]
|
||||
Reference in New Issue
Block a user