mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import Ledger from '@/services/Accounting/Ledger';
|
||||
|
||||
@Service()
|
||||
export class InventoryCostGLStorage {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private ledgerStorage: LedgerStorageService;
|
||||
|
||||
/**
|
||||
* Reverts the inventory cost GL entries from the given starting date.
|
||||
* @param {number} tenantId
|
||||
* @param {Date} startingDate
|
||||
* @param {Knex.Transaction} trx
|
||||
*/
|
||||
public revertInventoryCostGLEntries = async (
|
||||
tenantId: number,
|
||||
startingDate: Date,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<void> => {
|
||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
// Retrieve transactions from specific date range and costable transactions only.
|
||||
const transactions = await AccountTransaction.query()
|
||||
.where('costable', true)
|
||||
.modify('filterDateRange', startingDate)
|
||||
.withGraphFetched('account');
|
||||
|
||||
// Transform transaction to ledger entries and reverse them.
|
||||
const reversedLedger = Ledger.fromTransactions(transactions).reverse();
|
||||
|
||||
// Deletes and reverts balances of the given ledger.
|
||||
await this.ledgerStorage.delete(tenantId, reversedLedger, trx);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user