mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
fix: items accounts issue.
fix: write item id, transaction reference and number on journal entries.
This commit is contained in:
@@ -466,7 +466,7 @@ export default class ItemsController extends BaseController {
|
|||||||
}
|
}
|
||||||
if (error.errorType === 'INVENTORY_ACCOUNT_NOT_INVENTORY') {
|
if (error.errorType === 'INVENTORY_ACCOUNT_NOT_INVENTORY') {
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
errors: [{ type: 'INVENTORY.ACCOUNT.NOT.CURRENT.ASSET', code: 300 }],
|
errors: [{ type: 'INVENTORY.ACCOUNT.NOT.INVENTORY.TYPE', code: 300 }],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'ITEMS_HAVE_ASSOCIATED_TRANSACTIONS') {
|
if (error.errorType === 'ITEMS_HAVE_ASSOCIATED_TRANSACTIONS') {
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ export interface IJournalEntry {
|
|||||||
|
|
||||||
referenceTypeFormatted: string,
|
referenceTypeFormatted: string,
|
||||||
|
|
||||||
|
itemId?: number,
|
||||||
|
transactionNumber?: string,
|
||||||
|
referenceNumber?: string,
|
||||||
|
|
||||||
transactionType?: string,
|
transactionType?: string,
|
||||||
note?: string,
|
note?: string,
|
||||||
userId?: number,
|
userId?: number,
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export interface ISaleInvoice {
|
|||||||
dueAmount: number,
|
dueAmount: number,
|
||||||
overdueDays: number,
|
overdueDays: number,
|
||||||
customerId: number,
|
customerId: number,
|
||||||
|
referenceNo: string,
|
||||||
|
invoiceNo: string,
|
||||||
entries: IItemEntry[],
|
entries: IItemEntry[],
|
||||||
deliveredAt: string | Date,
|
deliveredAt: string | Date,
|
||||||
userId: number,
|
userId: number,
|
||||||
|
|||||||
@@ -15,37 +15,6 @@ import {
|
|||||||
IItemEntry,
|
IItemEntry,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
|
|
||||||
interface IInventoryCostEntity {
|
|
||||||
date: Date;
|
|
||||||
|
|
||||||
referenceType: string;
|
|
||||||
referenceId: number;
|
|
||||||
|
|
||||||
costAccount: number;
|
|
||||||
incomeAccount: number;
|
|
||||||
inventoryAccount: number;
|
|
||||||
|
|
||||||
inventory: number;
|
|
||||||
cost: number;
|
|
||||||
income: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NonInventoryJEntries {
|
|
||||||
date: Date;
|
|
||||||
|
|
||||||
referenceType: string;
|
|
||||||
referenceId: number;
|
|
||||||
|
|
||||||
receivable: number;
|
|
||||||
payable: number;
|
|
||||||
|
|
||||||
incomeAccountId: number;
|
|
||||||
income: number;
|
|
||||||
|
|
||||||
costAccountId: number;
|
|
||||||
cost: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class JournalCommands {
|
export default class JournalCommands {
|
||||||
journal: JournalPoster;
|
journal: JournalPoster;
|
||||||
|
|
||||||
@@ -90,6 +59,9 @@ export default class JournalCommands {
|
|||||||
referenceType: 'Bill',
|
referenceType: 'Bill',
|
||||||
date: formattedDate,
|
date: formattedDate,
|
||||||
userId: bill.userId,
|
userId: bill.userId,
|
||||||
|
|
||||||
|
referenceNumber: bill.referenceNo,
|
||||||
|
transactionNumber: bill.billNumber,
|
||||||
};
|
};
|
||||||
// Overrides the old bill entries.
|
// Overrides the old bill entries.
|
||||||
if (override) {
|
if (override) {
|
||||||
@@ -122,6 +94,7 @@ export default class JournalCommands {
|
|||||||
? item.inventoryAccountId
|
? item.inventoryAccountId
|
||||||
: item.costAccountId,
|
: item.costAccountId,
|
||||||
index: index + 2,
|
index: index + 2,
|
||||||
|
itemId: entry.itemId
|
||||||
});
|
});
|
||||||
this.journal.debit(debitEntry);
|
this.journal.debit(debitEntry);
|
||||||
});
|
});
|
||||||
@@ -362,6 +335,7 @@ export default class JournalCommands {
|
|||||||
debit: inventoryCostLot.cost,
|
debit: inventoryCostLot.cost,
|
||||||
account: inventoryCostLot.item.costAccountId,
|
account: inventoryCostLot.item.costAccountId,
|
||||||
index: 3,
|
index: 3,
|
||||||
|
itemId: inventoryCostLot.itemId
|
||||||
});
|
});
|
||||||
// XXX Credit - Inventory account.
|
// XXX Credit - Inventory account.
|
||||||
const inventoryEntry = new JournalEntry({
|
const inventoryEntry = new JournalEntry({
|
||||||
@@ -369,6 +343,7 @@ export default class JournalCommands {
|
|||||||
credit: inventoryCostLot.cost,
|
credit: inventoryCostLot.cost,
|
||||||
account: inventoryCostLot.item.inventoryAccountId,
|
account: inventoryCostLot.item.inventoryAccountId,
|
||||||
index: 4,
|
index: 4,
|
||||||
|
itemId: inventoryCostLot.itemId
|
||||||
});
|
});
|
||||||
this.journal.credit(inventoryEntry);
|
this.journal.credit(inventoryEntry);
|
||||||
this.journal.debit(costEntry);
|
this.journal.debit(costEntry);
|
||||||
@@ -395,6 +370,9 @@ export default class JournalCommands {
|
|||||||
referenceId: saleInvoice.id,
|
referenceId: saleInvoice.id,
|
||||||
date: saleInvoice.invoiceDate,
|
date: saleInvoice.invoiceDate,
|
||||||
userId: saleInvoice.userId,
|
userId: saleInvoice.userId,
|
||||||
|
|
||||||
|
transactionNumber: saleInvoice.invoiceNo,
|
||||||
|
referenceNumber: saleInvoice.referenceNo,
|
||||||
};
|
};
|
||||||
// XXX Debit - Receivable account.
|
// XXX Debit - Receivable account.
|
||||||
const receivableEntry = new JournalEntry({
|
const receivableEntry = new JournalEntry({
|
||||||
@@ -416,6 +394,7 @@ export default class JournalCommands {
|
|||||||
account: entry.item.sellAccountId,
|
account: entry.item.sellAccountId,
|
||||||
note: entry.description,
|
note: entry.description,
|
||||||
index: index + 2,
|
index: index + 2,
|
||||||
|
itemId: entry.itemId,
|
||||||
});
|
});
|
||||||
this.journal.credit(incomeEntry);
|
this.journal.credit(incomeEntry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
|||||||
import TenancyService from 'services/Tenancy/TenancyService';
|
import TenancyService from 'services/Tenancy/TenancyService';
|
||||||
import { ServiceError } from 'exceptions';
|
import { ServiceError } from 'exceptions';
|
||||||
import InventoryService from 'services/Inventory/Inventory';
|
import InventoryService from 'services/Inventory/Inventory';
|
||||||
import { ACCOUNT_ROOT_TYPE, ACCOUNT_TYPE } from 'data/AccountTypes'
|
import { ACCOUNT_PARENT_TYPE, ACCOUNT_ROOT_TYPE, ACCOUNT_TYPE } from 'data/AccountTypes'
|
||||||
|
|
||||||
const ERRORS = {
|
const ERRORS = {
|
||||||
NOT_FOUND: 'NOT_FOUND',
|
NOT_FOUND: 'NOT_FOUND',
|
||||||
@@ -131,7 +131,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
throw new ServiceError(ERRORS.COST_ACCOUNT_NOT_FOUMD);
|
throw new ServiceError(ERRORS.COST_ACCOUNT_NOT_FOUMD);
|
||||||
|
|
||||||
// Detarmines the cost of goods sold account.
|
// Detarmines the cost of goods sold account.
|
||||||
} else if (foundAccount.isRootType(ACCOUNT_ROOT_TYPE.EXPENSE)) {
|
} else if (!foundAccount.isParentType(ACCOUNT_PARENT_TYPE.EXPENSE)) {
|
||||||
this.logger.info('[items] validate cost account not COGS type.', {
|
this.logger.info('[items] validate cost account not COGS type.', {
|
||||||
tenantId,
|
tenantId,
|
||||||
costAccountId,
|
costAccountId,
|
||||||
@@ -167,7 +167,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
});
|
});
|
||||||
throw new ServiceError(ERRORS.SELL_ACCOUNT_NOT_FOUND);
|
throw new ServiceError(ERRORS.SELL_ACCOUNT_NOT_FOUND);
|
||||||
|
|
||||||
} else if (!foundAccount.isRootType(ACCOUNT_ROOT_TYPE.INCOME)) {
|
} else if (!foundAccount.isParentType(ACCOUNT_ROOT_TYPE.INCOME)) {
|
||||||
this.logger.info('[items] sell account not income type.', {
|
this.logger.info('[items] sell account not income type.', {
|
||||||
tenantId,
|
tenantId,
|
||||||
sellAccountId,
|
sellAccountId,
|
||||||
@@ -204,7 +204,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
});
|
});
|
||||||
throw new ServiceError(ERRORS.INVENTORY_ACCOUNT_NOT_FOUND);
|
throw new ServiceError(ERRORS.INVENTORY_ACCOUNT_NOT_FOUND);
|
||||||
|
|
||||||
} else if (foundAccount.isAccountType(ACCOUNT_TYPE.INVENTORY)) {
|
} else if (!foundAccount.isAccountType(ACCOUNT_TYPE.INVENTORY)) {
|
||||||
this.logger.info('[items] inventory account not inventory type.', {
|
this.logger.info('[items] inventory account not inventory type.', {
|
||||||
tenantId,
|
tenantId,
|
||||||
inventoryAccountId,
|
inventoryAccountId,
|
||||||
|
|||||||
Reference in New Issue
Block a user