mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat: wip migrate to nestjs
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { omit, sumBy } from 'lodash';
|
||||
import * as R from 'ramda';
|
||||
import moment from 'moment';
|
||||
import composeAsync from 'async/compose';
|
||||
import * as moment from 'moment';
|
||||
import * as composeAsync from 'async/compose';
|
||||
import {
|
||||
ISaleInvoiceCreateDTO,
|
||||
ISaleInvoiceEditDTO,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { SaleInvoice } from '../models/SaleInvoice';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { ERRORS } from '../constants';
|
||||
|
||||
@Injectable()
|
||||
export class CommandSaleInvoiceValidators {
|
||||
constructor(private readonly saleInvoiceModel: typeof SaleInvoice) {}
|
||||
constructor(
|
||||
@Inject(SaleInvoice.name)
|
||||
private readonly saleInvoiceModel: typeof SaleInvoice,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Validates the given invoice is existance.
|
||||
|
||||
@@ -14,22 +14,23 @@ import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { ERRORS } from '../constants';
|
||||
import { events } from '@/common/events/events';
|
||||
import { PaymentReceivedEntry } from '@/modules/PaymentReceived/models/PaymentReceivedEntry';
|
||||
import CreditNoteAppliedInvoice from '@/modules/CreditNotes/models/CreditNoteAppliedInvoice';
|
||||
import { CreditNoteAppliedInvoice } from '@/modules/CreditNotes/models/CreditNoteAppliedInvoice';
|
||||
|
||||
@Injectable()
|
||||
export class DeleteSaleInvoice {
|
||||
constructor(
|
||||
@Inject(PaymentReceivedEntry)
|
||||
private paymentReceivedEntryModel: typeof PaymentReceivedEntry,
|
||||
|
||||
@Inject(CreditNoteAppliedInvoice)
|
||||
private creditNoteAppliedInvoiceModel: typeof CreditNoteAppliedInvoice,
|
||||
|
||||
@Inject(SaleInvoice)
|
||||
private saleInvoiceModel: typeof SaleInvoice,
|
||||
private unlockEstimateFromInvoice: UnlinkConvertedSaleEstimate,
|
||||
private eventPublisher: EventEmitter2,
|
||||
private uow: UnitOfWork,
|
||||
|
||||
@Inject(PaymentReceivedEntry.name)
|
||||
private paymentReceivedEntryModel: typeof PaymentReceivedEntry,
|
||||
|
||||
@Inject(CreditNoteAppliedInvoice.name)
|
||||
private creditNoteAppliedInvoiceModel: typeof CreditNoteAppliedInvoice,
|
||||
|
||||
@Inject(SaleInvoice.name)
|
||||
private saleInvoiceModel: typeof SaleInvoice,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -41,8 +42,8 @@ export class DeleteSaleInvoice {
|
||||
const entries = await this.paymentReceivedEntryModel
|
||||
.query()
|
||||
.where('invoice_id', saleInvoiceId);
|
||||
|
||||
if (entries.length > 0) {
|
||||
|
||||
if (entries.length > 0) {
|
||||
throw new ServiceError(ERRORS.INVOICE_HAS_ASSOCIATED_PAYMENT_ENTRIES);
|
||||
}
|
||||
return entries;
|
||||
|
||||
@@ -16,8 +16,8 @@ export class GenerateShareLink {
|
||||
private uow: UnitOfWork,
|
||||
private eventPublisher: EventEmitter2,
|
||||
private transformer: TransformerInjectable,
|
||||
@Inject(SaleInvoice) private saleInvoiceModel: typeof SaleInvoice,
|
||||
@Inject(PaymentLink) private paymentLinkModel: typeof PaymentLink,
|
||||
@Inject(SaleInvoice.name) private saleInvoiceModel: typeof SaleInvoice,
|
||||
@Inject(PaymentLink.name) private paymentLinkModel: typeof PaymentLink,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// import { Service } from 'typedi';
|
||||
// import { ISaleInvoice, AccountNormal, ILedgerEntry, ILedger } from '@/interfaces';
|
||||
// import Ledger from '@/services/Accounting/Ledger';
|
||||
|
||||
// @Service()
|
||||
// export class SaleInvoiceWriteoffGLEntries {
|
||||
// /**
|
||||
// * Retrieves the invoice write-off common GL entry.
|
||||
// * @param {ISaleInvoice} saleInvoice
|
||||
// */
|
||||
// private getInvoiceWriteoffGLCommonEntry = (saleInvoice: ISaleInvoice) => {
|
||||
// return {
|
||||
// date: saleInvoice.invoiceDate,
|
||||
|
||||
// currencyCode: saleInvoice.currencyCode,
|
||||
// exchangeRate: saleInvoice.exchangeRate,
|
||||
|
||||
// transactionId: saleInvoice.id,
|
||||
// transactionType: 'InvoiceWriteOff',
|
||||
// transactionNumber: saleInvoice.invoiceNo,
|
||||
|
||||
// referenceNo: saleInvoice.referenceNo,
|
||||
// branchId: saleInvoice.branchId,
|
||||
// };
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Retrieves the invoice write-off receiveable GL entry.
|
||||
// * @param {number} ARAccountId
|
||||
// * @param {ISaleInvoice} saleInvoice
|
||||
// * @returns {ILedgerEntry}
|
||||
// */
|
||||
// private getInvoiceWriteoffGLReceivableEntry = (
|
||||
// ARAccountId: number,
|
||||
// saleInvoice: ISaleInvoice
|
||||
// ): ILedgerEntry => {
|
||||
// const commontEntry = this.getInvoiceWriteoffGLCommonEntry(saleInvoice);
|
||||
|
||||
// return {
|
||||
// ...commontEntry,
|
||||
// credit: saleInvoice.localWrittenoffAmount,
|
||||
// accountId: ARAccountId,
|
||||
// contactId: saleInvoice.customerId,
|
||||
// debit: 0,
|
||||
// index: 1,
|
||||
// indexGroup: 300,
|
||||
// accountNormal: saleInvoice.writtenoffExpenseAccount.accountNormal,
|
||||
// };
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Retrieves the invoice write-off expense GL entry.
|
||||
// * @param {ISaleInvoice} saleInvoice
|
||||
// * @returns {ILedgerEntry}
|
||||
// */
|
||||
// private getInvoiceWriteoffGLExpenseEntry = (
|
||||
// saleInvoice: ISaleInvoice
|
||||
// ): ILedgerEntry => {
|
||||
// const commontEntry = this.getInvoiceWriteoffGLCommonEntry(saleInvoice);
|
||||
|
||||
// return {
|
||||
// ...commontEntry,
|
||||
// debit: saleInvoice.localWrittenoffAmount,
|
||||
// accountId: saleInvoice.writtenoffExpenseAccountId,
|
||||
// credit: 0,
|
||||
// index: 2,
|
||||
// indexGroup: 300,
|
||||
// accountNormal: AccountNormal.DEBIT,
|
||||
// };
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Retrieves the invoice write-off GL entries.
|
||||
// * @param {number} ARAccountId
|
||||
// * @param {ISaleInvoice} saleInvoice
|
||||
// * @returns {ILedgerEntry[]}
|
||||
// */
|
||||
// public getInvoiceWriteoffGLEntries = (
|
||||
// ARAccountId: number,
|
||||
// saleInvoice: ISaleInvoice
|
||||
// ): ILedgerEntry[] => {
|
||||
// const creditEntry = this.getInvoiceWriteoffGLExpenseEntry(saleInvoice);
|
||||
// const debitEntry = this.getInvoiceWriteoffGLReceivableEntry(
|
||||
// ARAccountId,
|
||||
// saleInvoice
|
||||
// );
|
||||
// return [debitEntry, creditEntry];
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Retrieves the invoice write-off ledger.
|
||||
// * @param {number} ARAccountId
|
||||
// * @param {ISaleInvoice} saleInvoice
|
||||
// * @returns {Ledger}
|
||||
// */
|
||||
// public getInvoiceWriteoffLedger = (
|
||||
// ARAccountId: number,
|
||||
// saleInvoice: ISaleInvoice
|
||||
// ): ILedger => {
|
||||
// const entries = this.getInvoiceWriteoffGLEntries(ARAccountId, saleInvoice);
|
||||
|
||||
// return new Ledger(entries);
|
||||
// };
|
||||
// }
|
||||
@@ -0,0 +1,88 @@
|
||||
// import { Knex } from 'knex';
|
||||
// import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { SaleInvoiceWriteoffGLEntries } from './SaleInvoiceWriteoffGLEntries';
|
||||
|
||||
// @Service()
|
||||
// export class SaleInvoiceWriteoffGLStorage {
|
||||
// @Inject()
|
||||
// private invoiceWriteoffLedger: SaleInvoiceWriteoffGLEntries;
|
||||
|
||||
// @Inject()
|
||||
// private ledgerStorage: LedgerStorageService;
|
||||
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
|
||||
// /**
|
||||
// * Writes the invoice write-off GL entries.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} saleInvoiceId
|
||||
// * @param {Knex.Transaction} trx
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public writeInvoiceWriteoffEntries = async (
|
||||
// tenantId: number,
|
||||
// saleInvoiceId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||
// const { accountRepository } = this.tenancy.repositories(tenantId);
|
||||
|
||||
// // Retrieves the sale invoice.
|
||||
// const saleInvoice = await SaleInvoice.query(trx)
|
||||
// .findById(saleInvoiceId)
|
||||
// .withGraphFetched('writtenoffExpenseAccount');
|
||||
|
||||
// // Find or create the A/R account.
|
||||
// const ARAccount = await accountRepository.findOrCreateAccountReceivable(
|
||||
// saleInvoice.currencyCode,
|
||||
// {},
|
||||
// trx
|
||||
// );
|
||||
// // Retrieves the invoice write-off ledger.
|
||||
// const ledger = this.invoiceWriteoffLedger.getInvoiceWriteoffLedger(
|
||||
// ARAccount.id,
|
||||
// saleInvoice
|
||||
// );
|
||||
// return this.ledgerStorage.commit(tenantId, ledger, trx);
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Rewrites the invoice write-off GL entries.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} saleInvoiceId
|
||||
// * @param {Knex.Transactio} actiontrx
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public rewriteInvoiceWriteoffEntries = async (
|
||||
// tenantId: number,
|
||||
// saleInvoiceId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// await this.revertInvoiceWriteoffEntries(tenantId, saleInvoiceId, trx);
|
||||
|
||||
// await this.writeInvoiceWriteoffEntries(tenantId, saleInvoiceId, trx);
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Reverts the invoice write-off GL entries.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} saleInvoiceId
|
||||
// * @param {Knex.Transaction} trx
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public revertInvoiceWriteoffEntries = async (
|
||||
// tenantId: number,
|
||||
// saleInvoiceId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// await this.ledgerStorage.deleteByReference(
|
||||
// tenantId,
|
||||
// saleInvoiceId,
|
||||
// 'InvoiceWriteOff',
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
@@ -0,0 +1,35 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { ISalesInvoicesFilter } from '@/interfaces';
|
||||
// import { SaleInvoiceApplication } from './SaleInvoices.application';
|
||||
// import { Exportable } from '@/services/Export/Exportable';
|
||||
// import { EXPORT_SIZE_LIMIT } from '@/services/Export/constants';
|
||||
|
||||
// @Service()
|
||||
// export class SaleInvoicesExportable extends Exportable {
|
||||
// @Inject()
|
||||
// private saleInvoicesApplication: SaleInvoiceApplication;
|
||||
|
||||
// /**
|
||||
// * Retrieves the accounts data to exportable sheet.
|
||||
// * @param {number} tenantId
|
||||
// * @returns
|
||||
// */
|
||||
// public exportable(tenantId: number, query: ISalesInvoicesFilter) {
|
||||
// const filterQuery = (query) => {
|
||||
// query.withGraphFetched('branch');
|
||||
// query.withGraphFetched('warehouse');
|
||||
// };
|
||||
// const parsedQuery = {
|
||||
// sortOrder: 'desc',
|
||||
// columnSortBy: 'created_at',
|
||||
// ...query,
|
||||
// page: 1,
|
||||
// pageSize: EXPORT_SIZE_LIMIT,
|
||||
// filterQuery,
|
||||
// } as ISalesInvoicesFilter;
|
||||
|
||||
// return this.saleInvoicesApplication
|
||||
// .getSaleInvoices(tenantId, parsedQuery)
|
||||
// .then((output) => output.salesInvoices);
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,46 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { Knex } from 'knex';
|
||||
// import { ISaleInvoiceCreateDTO } from '@/interfaces';
|
||||
// import { CreateSaleInvoice } from './commands/CreateSaleInvoice.service';
|
||||
// import { Importable } from '@/services/Import/Importable';
|
||||
// import { SaleInvoicesSampleData } from './constants';
|
||||
|
||||
// @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 SaleInvoicesSampleData;
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user