mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
hotfix: editing sales and expense transactions don't reflect GL entries
This commit is contained in:
@@ -320,20 +320,19 @@ export default class VendorCreditController extends BaseController {
|
|||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
) => {
|
) => {
|
||||||
const { id: billId } = req.params;
|
const { id: vendorCreditId } = req.params;
|
||||||
const { tenantId, user } = req;
|
const { tenantId, user } = req;
|
||||||
const vendorCreditEditDTO: IVendorCreditEditDTO = this.matchedBodyData(req);
|
const vendorCreditEditDTO: IVendorCreditEditDTO = this.matchedBodyData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.editVendorCreditService.editVendorCredit(
|
await this.editVendorCreditService.editVendorCredit(
|
||||||
tenantId,
|
tenantId,
|
||||||
billId,
|
vendorCreditId,
|
||||||
vendorCreditEditDTO,
|
vendorCreditEditDTO
|
||||||
user
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: billId,
|
id: vendorCreditId,
|
||||||
message: 'The vendor credit has been edited successfully.',
|
message: 'The vendor credit has been edited successfully.',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export default class EditCreditNote extends BaseCreditNotes {
|
|||||||
} as ICreditNoteEditingPayload);
|
} as ICreditNoteEditingPayload);
|
||||||
|
|
||||||
// Saves the credit note graph to the storage.
|
// Saves the credit note graph to the storage.
|
||||||
const creditNote = await CreditNote.query(trx).upsertGraph({
|
const creditNote = await CreditNote.query(trx).upsertGraphAndFetch({
|
||||||
id: creditNoteId,
|
id: creditNoteId,
|
||||||
...creditNoteModel,
|
...creditNoteModel,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export class EditExpense {
|
|||||||
} as IExpenseEventEditingPayload);
|
} as IExpenseEventEditingPayload);
|
||||||
|
|
||||||
// Upsert the expense object with expense entries.
|
// Upsert the expense object with expense entries.
|
||||||
const expense: IExpense = await Expense.query(trx).upsertGraph({
|
const expense: IExpense = await Expense.query(trx).upsertGraphAndFetch({
|
||||||
id: expenseId,
|
id: expenseId,
|
||||||
...expenseObj,
|
...expenseObj,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
|
import { Service, Inject } from 'typedi';
|
||||||
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { Service, Inject } from 'typedi';
|
|
||||||
import { ExpenseGLEntries } from './ExpenseGLEntries';
|
import { ExpenseGLEntries } from './ExpenseGLEntries';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ export class ExpensesWriteGLSubscriber {
|
|||||||
authorizedUser,
|
authorizedUser,
|
||||||
trx,
|
trx,
|
||||||
}: IExpenseEventEditPayload) => {
|
}: IExpenseEventEditPayload) => {
|
||||||
// In case expense published, write journal entries.
|
// Cannot continue if the expense is not published.
|
||||||
if (expense.publishedAt) return;
|
if (!expense.publishedAt) return;
|
||||||
|
|
||||||
await this.expenseGLEntries.writeExpenseGLEntries(
|
await this.expenseGLEntries.rewriteExpenseGLEntries(
|
||||||
tenantId,
|
tenantId,
|
||||||
expense.id,
|
expense.id,
|
||||||
trx
|
trx
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import UnitOfWork from '@/services/UnitOfWork';
|
|||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||||
import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
|
import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
|
||||||
import events from '@/subscribers/events';
|
import events from '@/subscribers/events';
|
||||||
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class EditVendorCredit extends BaseVendorCredit {
|
export default class EditVendorCredit extends BaseVendorCredit {
|
||||||
@@ -21,6 +22,9 @@ export default class EditVendorCredit extends BaseVendorCredit {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private itemsEntriesService: ItemsEntriesService;
|
private itemsEntriesService: ItemsEntriesService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the given vendor credit.
|
* Deletes the given vendor credit.
|
||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
@@ -31,7 +35,7 @@ export default class EditVendorCredit extends BaseVendorCredit {
|
|||||||
vendorCreditId: number,
|
vendorCreditId: number,
|
||||||
vendorCreditDTO: IVendorCreditEditDTO
|
vendorCreditDTO: IVendorCreditEditDTO
|
||||||
) => {
|
) => {
|
||||||
const { VendorCredit } = this.tenancy.models(tenantId);
|
const { VendorCredit, Contact } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
// Retrieve the vendor credit or throw not found service error.
|
// Retrieve the vendor credit or throw not found service error.
|
||||||
const oldVendorCredit = await this.getVendorCreditOrThrowError(
|
const oldVendorCredit = await this.getVendorCreditOrThrowError(
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class SaleReceiptGLEntries {
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const { SaleReceipt } = this.tenancy.models(tenantId);
|
const { SaleReceipt } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const saleReceipt = await SaleReceipt.query()
|
const saleReceipt = await SaleReceipt.query(trx)
|
||||||
.findById(saleReceiptId)
|
.findById(saleReceiptId)
|
||||||
.withGraphFetched('entries.item');
|
.withGraphFetched('entries.item');
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
|
|
||||||
|
// Invalidate the transactions by reference.
|
||||||
|
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||||
|
|
||||||
// Invalidate items associated bills transactions.
|
// Invalidate items associated bills transactions.
|
||||||
queryClient.invalidateQueries(t.ITEMS_ASSOCIATED_WITH_BILLS);
|
queryClient.invalidateQueries(t.ITEMS_ASSOCIATED_WITH_BILLS);
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
|
|
||||||
|
// Invalidate transactions by reference.
|
||||||
|
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||||
|
|
||||||
// Invalidate mutate base currency abilities.
|
// Invalidate mutate base currency abilities.
|
||||||
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
|
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
|
|
||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
|
|
||||||
|
// Invalidate transactions by reference.
|
||||||
|
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||||
|
|
||||||
// Invalidate accounts.
|
// Invalidate accounts.
|
||||||
queryClient.invalidateQueries(t.ACCOUNTS);
|
queryClient.invalidateQueries(t.ACCOUNTS);
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ const commonInvalidateQueries = (client) => {
|
|||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
client.invalidateQueries(t.FINANCIAL_REPORT);
|
client.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
|
|
||||||
|
// Invalidate transactions by reference.
|
||||||
|
client.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||||
|
|
||||||
// Invalidate customers.
|
// Invalidate customers.
|
||||||
client.invalidateQueries(t.CUSTOMERS);
|
client.invalidateQueries(t.CUSTOMERS);
|
||||||
client.invalidateQueries(t.CUSTOMER);
|
client.invalidateQueries(t.CUSTOMER);
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
|
|
||||||
|
// Invalidate the transactions by reference.
|
||||||
|
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||||
|
|
||||||
// Invalidate the cashflow transactions.
|
// Invalidate the cashflow transactions.
|
||||||
queryClient.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
queryClient.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||||
queryClient.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
queryClient.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
|
|
||||||
|
// Invalidate the transactions by reference.
|
||||||
|
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||||
|
|
||||||
// Invalidate mutate base currency abilities.
|
// Invalidate mutate base currency abilities.
|
||||||
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
|
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user