mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: aggregate rows on import feature
This commit is contained in:
@@ -73,9 +73,7 @@ export class CreateManualJournalService {
|
||||
return R.compose(
|
||||
// Omits the `branchId` from entries if multiply branches feature not active.
|
||||
this.branchesDTOTransformer.transformDTO(tenantId)
|
||||
)(
|
||||
initialDTO
|
||||
);
|
||||
)(initialDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +131,8 @@ export class CreateManualJournalService {
|
||||
public makeJournalEntries = async (
|
||||
tenantId: number,
|
||||
manualJournalDTO: IManualJournalDTO,
|
||||
authorizedUser: ISystemUser
|
||||
authorizedUser: ISystemUser,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<{ manualJournal: IManualJournal }> => {
|
||||
const { ManualJournal } = this.tenancy.models(tenantId);
|
||||
|
||||
@@ -156,27 +155,31 @@ export class CreateManualJournalService {
|
||||
);
|
||||
// Creates a manual journal transactions with associated transactions
|
||||
// under unit-of-work envirement.
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Triggers `onManualJournalCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.manualJournals.onCreating, {
|
||||
tenantId,
|
||||
manualJournalDTO,
|
||||
trx,
|
||||
} as IManualJournalCreatingPayload);
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx: Knex.Transaction) => {
|
||||
// Triggers `onManualJournalCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.manualJournals.onCreating, {
|
||||
tenantId,
|
||||
manualJournalDTO,
|
||||
trx,
|
||||
} as IManualJournalCreatingPayload);
|
||||
|
||||
// Upsert the manual journal object.
|
||||
const manualJournal = await ManualJournal.query(trx).upsertGraph({
|
||||
...manualJournalObj,
|
||||
});
|
||||
// Triggers `onManualJournalCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.manualJournals.onCreated, {
|
||||
tenantId,
|
||||
manualJournal,
|
||||
manualJournalId: manualJournal.id,
|
||||
trx,
|
||||
} as IManualJournalEventCreatedPayload);
|
||||
// Upsert the manual journal object.
|
||||
const manualJournal = await ManualJournal.query(trx).upsertGraph({
|
||||
...manualJournalObj,
|
||||
});
|
||||
// Triggers `onManualJournalCreated` event.
|
||||
await this.eventPublisher.emitAsync(events.manualJournals.onCreated, {
|
||||
tenantId,
|
||||
manualJournal,
|
||||
manualJournalId: manualJournal.id,
|
||||
trx,
|
||||
} as IManualJournalEventCreatedPayload);
|
||||
|
||||
return { manualJournal };
|
||||
});
|
||||
return { manualJournal };
|
||||
},
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Inject } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import * as Yup from 'yup';
|
||||
import { Importable } from '../Import/Importable';
|
||||
import { CreateManualJournalService } from './CreateManualJournal';
|
||||
import { IManualJournalDTO } from '@/interfaces';
|
||||
import { ImportableContext } from '../Import/interfaces';
|
||||
import { ManualJournalsSampleData } from './constants';
|
||||
|
||||
export class ManualJournalImportable extends Importable {
|
||||
@Inject()
|
||||
private createManualJournalService: CreateManualJournalService;
|
||||
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
tenantId: number,
|
||||
createJournalDTO: IManualJournalDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createManualJournalService.makeJournalEntries(
|
||||
tenantId,
|
||||
createJournalDTO,
|
||||
{},
|
||||
trx
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the DTO before passing it to importable and validation.
|
||||
* @param {Record<string, any>} createDTO
|
||||
* @param {ImportableContext} context
|
||||
* @returns {Record<string, any>}
|
||||
*/
|
||||
public transform(createDTO: Record<string, any>, context: ImportableContext) {
|
||||
return createDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Params validation schema.
|
||||
* @returns {ValidationSchema[]}
|
||||
*/
|
||||
public paramsValidationSchema() {
|
||||
return Yup.object().shape({
|
||||
autoIncrement: Yup.boolean(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sample data of manual journals that used to download sample sheet.
|
||||
* @returns {Record<string, any>}
|
||||
*/
|
||||
public sampleData(): Record<string, any>[] {
|
||||
return ManualJournalsSampleData;
|
||||
}
|
||||
}
|
||||
@@ -29,3 +29,36 @@ export const CONTACTS_CONFIG = [
|
||||
];
|
||||
|
||||
export const DEFAULT_VIEWS = [];
|
||||
|
||||
export const ManualJournalsSampleData = [
|
||||
{
|
||||
Date: '2024-02-02',
|
||||
'Journal No': 'J-100022',
|
||||
'Reference No.': 'REF-10000',
|
||||
'Currency Code': '',
|
||||
'Exchange Rate': '',
|
||||
'Journal Type': '',
|
||||
Description: 'Animi quasi qui itaque aut possimus illum est magnam enim.',
|
||||
Credit: 1000,
|
||||
Debit: 0,
|
||||
Note: 'Qui reprehenderit voluptate.',
|
||||
Account: 'Bank Account',
|
||||
Contact: '',
|
||||
Publish: 'T',
|
||||
},
|
||||
{
|
||||
Date: '2024-02-02',
|
||||
'Journal No': 'J-100022',
|
||||
'Reference No.': 'REF-10000',
|
||||
'Currency Code': '',
|
||||
'Exchange Rate': '',
|
||||
'Journal Type': '',
|
||||
Description: 'In assumenda dicta autem non est corrupti non et.',
|
||||
Credit: 0,
|
||||
Debit: 1000,
|
||||
Note: 'Omnis tempora qui fugiat neque dolor voluptatem aut repudiandae nihil.',
|
||||
Account: 'Bank Account',
|
||||
Contact: '',
|
||||
Publish: 'T',
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user