Skip to content

Commit

Permalink
Merge pull request #342 from bigcapitalhq/big-130-edited-transactions…
Browse files Browse the repository at this point in the history
…-does-not-reflect-on-reports

hotfix: editing sales and expense transactions don't reflect GL entries
  • Loading branch information
abouolia authored Jan 29, 2024
2 parents 0414c09 + ba387e8 commit 6b77bda
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 13 deletions.
9 changes: 4 additions & 5 deletions packages/server/src/api/controllers/Purchases/VendorCredit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,19 @@ export default class VendorCreditController extends BaseController {
res: Response,
next: NextFunction
) => {
const { id: billId } = req.params;
const { id: vendorCreditId } = req.params;
const { tenantId, user } = req;
const vendorCreditEditDTO: IVendorCreditEditDTO = this.matchedBodyData(req);

try {
await this.editVendorCreditService.editVendorCredit(
tenantId,
billId,
vendorCreditEditDTO,
user
vendorCreditId,
vendorCreditEditDTO
);

return res.status(200).send({
id: billId,
id: vendorCreditId,
message: 'The vendor credit has been edited successfully.',
});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/CreditNotes/EditCreditNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class EditCreditNote extends BaseCreditNotes {
} as ICreditNoteEditingPayload);

// Saves the credit note graph to the storage.
const creditNote = await CreditNote.query(trx).upsertGraph({
const creditNote = await CreditNote.query(trx).upsertGraphAndFetch({
id: creditNoteId,
...creditNoteModel,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/Expenses/CRUD/EditExpense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class EditExpense {
} as IExpenseEventEditingPayload);

// 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,
...expenseObj,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Knex } from 'knex';
import { Service, Inject } from 'typedi';
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Service, Inject } from 'typedi';
import { ExpenseGLEntries } from './ExpenseGLEntries';

@Service()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export class ExpensesWriteGLSubscriber {
authorizedUser,
trx,
}: IExpenseEventEditPayload) => {
// In case expense published, write journal entries.
if (expense.publishedAt) return;
// Cannot continue if the expense is not published.
if (!expense.publishedAt) return;

await this.expenseGLEntries.writeExpenseGLEntries(
await this.expenseGLEntries.rewriteExpenseGLEntries(
tenantId,
expense.id,
trx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UnitOfWork from '@/services/UnitOfWork';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
import events from '@/subscribers/events';
import HasTenancyService from '@/services/Tenancy/TenancyService';

@Service()
export default class EditVendorCredit extends BaseVendorCredit {
Expand All @@ -21,6 +22,9 @@ export default class EditVendorCredit extends BaseVendorCredit {
@Inject()
private itemsEntriesService: ItemsEntriesService;

@Inject()
private tenancy: HasTenancyService;

/**
* Deletes the given vendor credit.
* @param {number} tenantId - Tenant id.
Expand All @@ -31,7 +35,7 @@ export default class EditVendorCredit extends BaseVendorCredit {
vendorCreditId: number,
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.
const oldVendorCredit = await this.getVendorCreditOrThrowError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class SaleReceiptGLEntries {
): Promise<void> => {
const { SaleReceipt } = this.tenancy.models(tenantId);

const saleReceipt = await SaleReceipt.query()
const saleReceipt = await SaleReceipt.query(trx)
.findById(saleReceiptId)
.withGraphFetched('entries.item');

Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/hooks/query/bills.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const commonInvalidateQueries = (queryClient) => {
// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);

// Invalidate the transactions by reference.
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);

// Invalidate items associated bills transactions.
queryClient.invalidateQueries(t.ITEMS_ASSOCIATED_WITH_BILLS);

Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/hooks/query/creditNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const commonInvalidateQueries = (queryClient) => {
// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);

// Invalidate transactions by reference.
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);

// Invalidate mutate base currency abilities.
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
};
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/hooks/query/invoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const commonInvalidateQueries = (queryClient) => {

// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);

// Invalidate transactions by reference.
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);

// Invalidate accounts.
queryClient.invalidateQueries(t.ACCOUNTS);
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/hooks/query/paymentReceives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const commonInvalidateQueries = (client) => {
// Invalidate financial reports.
client.invalidateQueries(t.FINANCIAL_REPORT);

// Invalidate transactions by reference.
client.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);

// Invalidate customers.
client.invalidateQueries(t.CUSTOMERS);
client.invalidateQueries(t.CUSTOMER);
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/hooks/query/receipts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const commonInvalidateQueries = (queryClient) => {
// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);

// Invalidate the transactions by reference.
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);

// Invalidate the cashflow transactions.
queryClient.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
queryClient.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/hooks/query/vendorCredit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const commonInvalidateQueries = (queryClient) => {
// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);

// Invalidate the transactions by reference.
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);

// Invalidate mutate base currency abilities.
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
};
Expand Down

0 comments on commit 6b77bda

Please sign in to comment.