mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
refactor(nestjs): add importable service to other modules
This commit is contained in:
@@ -18,6 +18,7 @@ import { LedgerModule } from '../Ledger/Ledger.module';
|
||||
import { AccountsModule } from '../Accounts/Accounts.module';
|
||||
import { BillPaymentsExportable } from './queries/BillPaymentsExportable';
|
||||
import { GetBillPayments } from '../Bills/queries/GetBillPayments';
|
||||
import { BillPaymentsImportable } from './commands/BillPaymentsImportable';
|
||||
|
||||
@Module({
|
||||
imports: [LedgerModule, AccountsModule],
|
||||
@@ -37,9 +38,15 @@ import { GetBillPayments } from '../Bills/queries/GetBillPayments';
|
||||
BillPaymentGLEntries,
|
||||
BillPaymentGLEntriesSubscriber,
|
||||
GetBillPayments,
|
||||
BillPaymentsExportable
|
||||
BillPaymentsExportable,
|
||||
BillPaymentsImportable,
|
||||
],
|
||||
exports: [
|
||||
BillPaymentValidators,
|
||||
CreateBillPaymentService,
|
||||
BillPaymentsExportable,
|
||||
BillPaymentsImportable,
|
||||
],
|
||||
exports: [BillPaymentValidators, CreateBillPaymentService],
|
||||
controllers: [BillPaymentsController],
|
||||
})
|
||||
export class BillPaymentsModule {}
|
||||
|
||||
@@ -1,45 +1,49 @@
|
||||
// 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';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Knex } from 'knex';
|
||||
import { CreateBillPaymentService } from './CreateBillPayment.service';
|
||||
import { Importable } from '@/modules/Import/Importable';
|
||||
import { CreateBillPaymentDto } from '../dtos/BillPayment.dto';
|
||||
import { BillsPaymentsSampleData } from '../constants';
|
||||
import { ImportableService } from '@/modules/Import/decorators/Import.decorator';
|
||||
import { BillPayment } from '../models/BillPayment';
|
||||
|
||||
// @Service()
|
||||
// export class BillPaymentsImportable extends Importable {
|
||||
// @Inject()
|
||||
// private createBillPaymentService: CreateBillPayment;
|
||||
@Injectable()
|
||||
@ImportableService({ name: BillPayment.name })
|
||||
export class BillPaymentsImportable extends Importable {
|
||||
constructor(
|
||||
private readonly createBillPaymentService: CreateBillPaymentService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 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
|
||||
// );
|
||||
// }
|
||||
/**
|
||||
* Importing to account service.
|
||||
* @param {number} tenantId
|
||||
* @param {IAccountCreateDTO} createAccountDTO
|
||||
* @returns
|
||||
*/
|
||||
public importable(
|
||||
billPaymentDTO: CreateBillPaymentDto,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createBillPaymentService.createBillPayment(
|
||||
billPaymentDTO,
|
||||
trx
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Concurrrency controlling of the importing process.
|
||||
// * @returns {number}
|
||||
// */
|
||||
// public get concurrency() {
|
||||
// return 1;
|
||||
// }
|
||||
/**
|
||||
* 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;
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Retrieves the sample data that used to download accounts sample sheet.
|
||||
*/
|
||||
public sampleData(): any[] {
|
||||
return BillsPaymentsSampleData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
import { Features } from "@/common/types/Features";
|
||||
|
||||
export const BillPaymentMeta = {
|
||||
defaultFilterField: 'vendor',
|
||||
defaultSort: {
|
||||
sortOrder: 'DESC',
|
||||
sortField: 'bill_date',
|
||||
},
|
||||
exportable: true,
|
||||
exportFlattenOn: 'entries',
|
||||
|
||||
importable: true,
|
||||
importAggregator: 'group',
|
||||
importAggregateOn: 'entries',
|
||||
importAggregateBy: 'paymentNumber',
|
||||
fields: {
|
||||
vendor: {
|
||||
name: 'bill_payment.field.vendor',
|
||||
column: 'vendor_id',
|
||||
fieldType: 'relation',
|
||||
|
||||
relationType: 'enumeration',
|
||||
relationKey: 'vendor',
|
||||
|
||||
relationEntityLabel: 'display_name',
|
||||
relationEntityKey: 'id',
|
||||
},
|
||||
amount: {
|
||||
name: 'bill_payment.field.amount',
|
||||
column: 'amount',
|
||||
fieldType: 'number',
|
||||
},
|
||||
due_amount: {
|
||||
name: 'bill_payment.field.due_amount',
|
||||
column: 'due_amount',
|
||||
fieldType: 'number',
|
||||
},
|
||||
payment_account: {
|
||||
name: 'bill_payment.field.payment_account',
|
||||
column: 'payment_account_id',
|
||||
fieldType: 'relation',
|
||||
|
||||
relationType: 'enumeration',
|
||||
relationKey: 'paymentAccount',
|
||||
|
||||
relationEntityLabel: 'name',
|
||||
relationEntityKey: 'slug',
|
||||
},
|
||||
payment_number: {
|
||||
name: 'bill_payment.field.payment_number',
|
||||
column: 'payment_number',
|
||||
fieldType: 'text',
|
||||
},
|
||||
payment_date: {
|
||||
name: 'bill_payment.field.payment_date',
|
||||
column: 'payment_date',
|
||||
fieldType: 'date',
|
||||
},
|
||||
reference_no: {
|
||||
name: 'bill_payment.field.reference_no',
|
||||
column: 'reference',
|
||||
fieldType: 'text',
|
||||
},
|
||||
description: {
|
||||
name: 'bill_payment.field.description',
|
||||
column: 'description',
|
||||
fieldType: 'text',
|
||||
},
|
||||
created_at: {
|
||||
name: 'bill_payment.field.created_at',
|
||||
column: 'created_at',
|
||||
fieldType: 'date',
|
||||
},
|
||||
},
|
||||
columns: {
|
||||
vendor: {
|
||||
name: 'bill_payment.field.vendor',
|
||||
type: 'relation',
|
||||
accessor: 'vendor.displayName',
|
||||
},
|
||||
paymentDate: {
|
||||
name: 'bill_payment.field.payment_date',
|
||||
type: 'date',
|
||||
accessor: 'formattedPaymentDate',
|
||||
},
|
||||
paymentNumber: {
|
||||
name: 'bill_payment.field.payment_number',
|
||||
type: 'text',
|
||||
},
|
||||
paymentAccount: {
|
||||
name: 'bill_payment.field.payment_account',
|
||||
accessor: 'paymentAccount.name',
|
||||
type: 'text',
|
||||
},
|
||||
amount: {
|
||||
name: 'Amount',
|
||||
accessor: 'formattedAmount',
|
||||
},
|
||||
currencyCode: {
|
||||
name: 'Currency Code',
|
||||
type: 'text',
|
||||
printable: false,
|
||||
},
|
||||
exchangeRate: {
|
||||
name: 'bill_payment.field.exchange_rate',
|
||||
type: 'number',
|
||||
printable: false,
|
||||
},
|
||||
statement: {
|
||||
name: 'bill_payment.field.note',
|
||||
type: 'text',
|
||||
printable: false,
|
||||
},
|
||||
reference: {
|
||||
name: 'bill_payment.field.reference',
|
||||
type: 'text',
|
||||
},
|
||||
entries: {
|
||||
name: 'Entries',
|
||||
accessor: 'entries',
|
||||
type: 'collection',
|
||||
collectionOf: 'object',
|
||||
columns: {
|
||||
date: {
|
||||
name: 'Bill date',
|
||||
accessor: 'bill.formattedBillDate',
|
||||
},
|
||||
billNo: {
|
||||
name: 'Bill No.',
|
||||
accessor: 'bill.billNo',
|
||||
},
|
||||
billRefNo: {
|
||||
name: 'Bill Reference No.',
|
||||
accessor: 'bill.referenceNo',
|
||||
},
|
||||
billAmount: {
|
||||
name: 'Bill Amount',
|
||||
accessor: 'bill.totalFormatted',
|
||||
},
|
||||
paidAmount: {
|
||||
name: 'Paid Amount',
|
||||
accessor: 'paymentAmountFormatted',
|
||||
},
|
||||
},
|
||||
},
|
||||
branch: {
|
||||
name: 'Branch',
|
||||
type: 'text',
|
||||
accessor: 'branch.name',
|
||||
features: [Features.BRANCHES],
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
vendorId: {
|
||||
name: 'bill_payment.field.vendor',
|
||||
fieldType: 'relation',
|
||||
relationModel: 'Contact',
|
||||
relationImportMatch: ['displayName'],
|
||||
required: true,
|
||||
},
|
||||
payment_date: {
|
||||
name: 'bill_payment.field.payment_date',
|
||||
fieldType: 'date',
|
||||
required: true,
|
||||
},
|
||||
paymentNumber: {
|
||||
name: 'bill_payment.field.payment_number',
|
||||
fieldType: 'text',
|
||||
unique: true,
|
||||
importHint: 'The payment number should be unique.',
|
||||
},
|
||||
paymentAccountId: {
|
||||
name: 'bill_payment.field.payment_account',
|
||||
fieldType: 'relation',
|
||||
relationModel: 'Account',
|
||||
relationImportMatch: ['name', 'code'],
|
||||
required: true,
|
||||
importHint: 'Matches the account name or code.',
|
||||
},
|
||||
exchangeRate: {
|
||||
name: 'bill_payment.field.exchange_rate',
|
||||
fieldType: 'number',
|
||||
},
|
||||
statement: {
|
||||
name: 'bill_payment.field.note',
|
||||
fieldType: 'text',
|
||||
},
|
||||
reference: {
|
||||
name: 'bill_payment.field.reference',
|
||||
fieldType: 'text',
|
||||
},
|
||||
entries: {
|
||||
name: 'bill_payment.field.entries',
|
||||
column: 'entries',
|
||||
fieldType: 'collection',
|
||||
collectionOf: 'object',
|
||||
collectionMinLength: 1,
|
||||
required: true,
|
||||
fields: {
|
||||
billId: {
|
||||
name: 'bill_payment.field.entries.bill',
|
||||
fieldType: 'relation',
|
||||
relationModel: 'Bill',
|
||||
relationImportMatch: 'billNumber',
|
||||
required: true,
|
||||
importHint: 'Matches the bill number.',
|
||||
},
|
||||
paymentAmount: {
|
||||
name: 'bill_payment.field.entries.payment_amount',
|
||||
fieldType: 'number',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
branchId: {
|
||||
name: 'Branch',
|
||||
fieldType: 'relation',
|
||||
relationModel: 'Branch',
|
||||
relationImportMatch: ['name', 'code'],
|
||||
features: [Features.BRANCHES],
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -9,8 +9,15 @@ import { BaseModel } from '@/models/Model';
|
||||
import { BillPaymentEntry } from './BillPaymentEntry';
|
||||
import { Vendor } from '@/modules/Vendors/models/Vendor';
|
||||
import { Document } from '@/modules/ChromiumlyTenancy/models/Document';
|
||||
import { ImportableModel } from '@/modules/Import/decorators/Import.decorator';
|
||||
import { ExportableModel } from '@/modules/Export/decorators/ExportableModel.decorator';
|
||||
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
|
||||
import { BillPaymentMeta } from './BillPayment.meta';
|
||||
|
||||
export class BillPayment extends BaseModel{
|
||||
@ImportableModel()
|
||||
@ExportableModel()
|
||||
@InjectModelMeta(BillPaymentMeta)
|
||||
export class BillPayment extends BaseModel {
|
||||
vendorId: number;
|
||||
amount: number;
|
||||
currencyCode: string;
|
||||
|
||||
Reference in New Issue
Block a user