mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: configuring import services on more resources
This commit is contained in:
@@ -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,
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user