mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
fix: add user id to sale invoice non-inventory journal entries.
This commit is contained in:
@@ -146,14 +146,15 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
* @param {Function} next
|
* @param {Function} next
|
||||||
*/
|
*/
|
||||||
async newSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
async newSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
||||||
const { tenantId } = req;
|
const { tenantId, user } = req;
|
||||||
const saleInvoiceOTD: ISaleInvoiceDTO = this.matchedBodyData(req);
|
const saleInvoiceDTO: ISaleInvoiceDTO = this.matchedBodyData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Creates a new sale invoice with associated entries.
|
// Creates a new sale invoice with associated entries.
|
||||||
const storedSaleInvoice = await this.saleInvoiceService.createSaleInvoice(
|
const storedSaleInvoice = await this.saleInvoiceService.createSaleInvoice(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleInvoiceOTD
|
saleInvoiceDTO,
|
||||||
|
user
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: storedSaleInvoice.id,
|
id: storedSaleInvoice.id,
|
||||||
@@ -171,7 +172,7 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
* @param {Function} next
|
* @param {Function} next
|
||||||
*/
|
*/
|
||||||
async editSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
async editSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
||||||
const { tenantId } = req;
|
const { tenantId, user } = req;
|
||||||
const { id: saleInvoiceId } = req.params;
|
const { id: saleInvoiceId } = req.params;
|
||||||
const saleInvoiceOTD: ISaleInvoiceDTO = this.matchedBodyData(req);
|
const saleInvoiceOTD: ISaleInvoiceDTO = this.matchedBodyData(req);
|
||||||
|
|
||||||
@@ -180,7 +181,8 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
await this.saleInvoiceService.editSaleInvoice(
|
await this.saleInvoiceService.editSaleInvoice(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleInvoiceId,
|
saleInvoiceId,
|
||||||
saleInvoiceOTD
|
saleInvoiceOTD,
|
||||||
|
user
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleInvoiceId,
|
id: saleInvoiceId,
|
||||||
@@ -198,12 +200,15 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
* @param {NextFunction} next -
|
* @param {NextFunction} next -
|
||||||
*/
|
*/
|
||||||
async deliverSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
async deliverSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
||||||
const { tenantId } = req;
|
const { tenantId, user } = req;
|
||||||
const { id: saleInvoiceId } = req.params;
|
const { id: saleInvoiceId } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.saleInvoiceService.deliverSaleInvoice(tenantId, saleInvoiceId);
|
await this.saleInvoiceService.deliverSaleInvoice(
|
||||||
|
tenantId,
|
||||||
|
saleInvoiceId,
|
||||||
|
user
|
||||||
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleInvoiceId,
|
id: saleInvoiceId,
|
||||||
message: 'The given sale invoice has been delivered successfully',
|
message: 'The given sale invoice has been delivered successfully',
|
||||||
@@ -221,11 +226,11 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
async deleteSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
async deleteSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
||||||
const { id: saleInvoiceId } = req.params;
|
const { id: saleInvoiceId } = req.params;
|
||||||
const { tenantId } = req;
|
const { tenantId, user } = req;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Deletes the sale invoice with associated entries and journal transaction.
|
// Deletes the sale invoice with associated entries and journal transaction.
|
||||||
await this.saleInvoiceService.deleteSaleInvoice(tenantId, saleInvoiceId);
|
await this.saleInvoiceService.deleteSaleInvoice(tenantId, saleInvoiceId, user);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleInvoiceId,
|
id: saleInvoiceId,
|
||||||
@@ -388,7 +393,9 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
}
|
}
|
||||||
if (error.errorType === 'INVOICE_HAS_ASSOCIATED_PAYMENT_ENTRIES') {
|
if (error.errorType === 'INVOICE_HAS_ASSOCIATED_PAYMENT_ENTRIES') {
|
||||||
return res.boom.badRequest(null, {
|
return res.boom.badRequest(null, {
|
||||||
errors: [{ type: 'INVOICE_HAS_ASSOCIATED_PAYMENT_ENTRIES', code: 1100 }],
|
errors: [
|
||||||
|
{ type: 'INVOICE_HAS_ASSOCIATED_PAYMENT_ENTRIES', code: 1100 },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -538,16 +538,24 @@ export default class JournalCommands {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {ISaleInvoice} saleInvoice
|
||||||
|
* @param {number} receivableAccountsId
|
||||||
|
* @param {number} authorizedUserId
|
||||||
|
*/
|
||||||
saleInvoiceNonInventory(
|
saleInvoiceNonInventory(
|
||||||
saleInvoice: ISaleInvoice & {
|
saleInvoice: ISaleInvoice & {
|
||||||
entries: IItemEntry & { item: IItem };
|
entries: IItemEntry & { item: IItem };
|
||||||
},
|
},
|
||||||
receivableAccountsId: number
|
receivableAccountsId: number,
|
||||||
|
authorizedUserId: number,
|
||||||
) {
|
) {
|
||||||
const commonEntry = {
|
const commonEntry = {
|
||||||
referenceType: 'SaleInvoice',
|
referenceType: 'SaleInvoice',
|
||||||
referenceId: saleInvoice.id,
|
referenceId: saleInvoice.id,
|
||||||
date: saleInvoice.invoiceDate,
|
date: saleInvoice.invoiceDate,
|
||||||
|
userId: authorizedUserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
// XXX Debit - Receivable account.
|
// XXX Debit - Receivable account.
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import {
|
|||||||
ISalesInvoicesFilter,
|
ISalesInvoicesFilter,
|
||||||
IPaginationMeta,
|
IPaginationMeta,
|
||||||
IFilterMeta,
|
IFilterMeta,
|
||||||
|
ISystemUser,
|
||||||
|
ISystemService,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import events from 'subscribers/events';
|
import events from 'subscribers/events';
|
||||||
import InventoryService from 'services/Inventory/Inventory';
|
import InventoryService from 'services/Inventory/Inventory';
|
||||||
@@ -163,7 +165,8 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
*/
|
*/
|
||||||
public async createSaleInvoice(
|
public async createSaleInvoice(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoiceDTO: ISaleInvoiceCreateDTO
|
saleInvoiceDTO: ISaleInvoiceCreateDTO,
|
||||||
|
authorizedUser: ISystemUser
|
||||||
): Promise<ISaleInvoice> {
|
): Promise<ISaleInvoice> {
|
||||||
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
||||||
|
|
||||||
@@ -202,6 +205,7 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
tenantId,
|
tenantId,
|
||||||
saleInvoice,
|
saleInvoice,
|
||||||
saleInvoiceId: saleInvoice.id,
|
saleInvoiceId: saleInvoice.id,
|
||||||
|
authorizedUser,
|
||||||
});
|
});
|
||||||
this.logger.info('[sale_invoice] successfully inserted.', {
|
this.logger.info('[sale_invoice] successfully inserted.', {
|
||||||
tenantId,
|
tenantId,
|
||||||
@@ -222,7 +226,8 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
public async editSaleInvoice(
|
public async editSaleInvoice(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoiceId: number,
|
saleInvoiceId: number,
|
||||||
saleInvoiceDTO: any
|
saleInvoiceDTO: any,
|
||||||
|
authorizedUser: ISystemUser
|
||||||
): Promise<ISaleInvoice> {
|
): Promise<ISaleInvoice> {
|
||||||
const { SaleInvoice } = this.tenancy.models(tenantId);
|
const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
@@ -280,6 +285,7 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
oldSaleInvoice,
|
oldSaleInvoice,
|
||||||
tenantId,
|
tenantId,
|
||||||
saleInvoiceId,
|
saleInvoiceId,
|
||||||
|
authorizedUser,
|
||||||
});
|
});
|
||||||
return saleInvoice;
|
return saleInvoice;
|
||||||
}
|
}
|
||||||
@@ -292,7 +298,8 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
*/
|
*/
|
||||||
public async deliverSaleInvoice(
|
public async deliverSaleInvoice(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoiceId: number
|
saleInvoiceId: number,
|
||||||
|
authorizedUser: ISystemUser
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
||||||
|
|
||||||
@@ -345,7 +352,8 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
*/
|
*/
|
||||||
public async deleteSaleInvoice(
|
public async deleteSaleInvoice(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoiceId: number
|
saleInvoiceId: number,
|
||||||
|
authorizedUser: ISystemUser
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { ItemEntry } = this.tenancy.models(tenantId);
|
const { ItemEntry } = this.tenancy.models(tenantId);
|
||||||
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
||||||
@@ -383,6 +391,7 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
tenantId,
|
tenantId,
|
||||||
oldSaleInvoice,
|
oldSaleInvoice,
|
||||||
saleInvoiceId,
|
saleInvoiceId,
|
||||||
|
authorizedUser,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +409,7 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoiceId: number,
|
saleInvoiceId: number,
|
||||||
saleInvoiceDate: Date,
|
saleInvoiceDate: Date,
|
||||||
override?: boolean
|
override?: boolean,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Gets the next inventory lot number.
|
// Gets the next inventory lot number.
|
||||||
const lotNumber = this.inventoryService.getNextLotNumber(tenantId);
|
const lotNumber = this.inventoryService.getNextLotNumber(tenantId);
|
||||||
@@ -454,6 +463,7 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
public async recordNonInventoryJournalEntries(
|
public async recordNonInventoryJournalEntries(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoiceId: number,
|
saleInvoiceId: number,
|
||||||
|
authorizedUserId: number,
|
||||||
override: boolean = false
|
override: boolean = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
const { saleInvoiceRepository } = this.tenancy.repositories(tenantId);
|
||||||
@@ -471,8 +481,12 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
saleInvoiceId,
|
saleInvoiceId,
|
||||||
'entries.item'
|
'entries.item'
|
||||||
);
|
);
|
||||||
|
await this.writeNonInventoryInvoiceEntries(
|
||||||
await this.writeNonInventoryInvoiceEntries(tenantId, saleInvoice, override);
|
tenantId,
|
||||||
|
saleInvoice,
|
||||||
|
authorizedUserId,
|
||||||
|
override
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -514,7 +528,8 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
*/
|
*/
|
||||||
public async getSaleInvoice(
|
public async getSaleInvoice(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoiceId: number
|
saleInvoiceId: number,
|
||||||
|
authorizedUser: ISystemUser
|
||||||
): Promise<ISaleInvoice> {
|
): Promise<ISaleInvoice> {
|
||||||
const { SaleInvoice } = this.tenancy.models(tenantId);
|
const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
|
|||||||
@@ -184,12 +184,12 @@ export default class SaleInvoicesCost {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the sale invoice journal entries.
|
* Writes the sale invoice journal entries.
|
||||||
* @param {SaleInvoice} saleInvoice -
|
|
||||||
*/
|
*/
|
||||||
async writeNonInventoryInvoiceEntries(
|
async writeNonInventoryInvoiceEntries(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
saleInvoice: ISaleInvoice,
|
saleInvoice: ISaleInvoice,
|
||||||
override: boolean
|
authorizedUserId: number,
|
||||||
|
override: boolean = false,
|
||||||
) {
|
) {
|
||||||
const { accountRepository } = this.tenancy.repositories(tenantId);
|
const { accountRepository } = this.tenancy.repositories(tenantId);
|
||||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
const { AccountTransaction } = this.tenancy.models(tenantId);
|
||||||
@@ -210,7 +210,11 @@ export default class SaleInvoicesCost {
|
|||||||
journal.fromTransactions(oldTransactions);
|
journal.fromTransactions(oldTransactions);
|
||||||
journal.removeEntries();
|
journal.removeEntries();
|
||||||
}
|
}
|
||||||
journalCommands.saleInvoiceNonInventory(saleInvoice, receivableAccount.id);
|
journalCommands.saleInvoiceNonInventory(
|
||||||
|
saleInvoice,
|
||||||
|
receivableAccount.id,
|
||||||
|
authorizedUserId,
|
||||||
|
);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
journal.deleteEntries(),
|
journal.deleteEntries(),
|
||||||
|
|||||||
@@ -99,10 +99,11 @@ export default class SaleInvoiceSubscriber {
|
|||||||
*/
|
*/
|
||||||
@On(events.saleInvoice.onCreated)
|
@On(events.saleInvoice.onCreated)
|
||||||
@On(events.saleInvoice.onEdited)
|
@On(events.saleInvoice.onEdited)
|
||||||
public async handleWritingNonInventoryEntries({ tenantId, saleInvoice }) {
|
public async handleWritingNonInventoryEntries({ tenantId, saleInvoice, authorizedUser }) {
|
||||||
await this.saleInvoicesService.recordNonInventoryJournalEntries(
|
await this.saleInvoicesService.recordNonInventoryJournalEntries(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleInvoice.id
|
saleInvoice.id,
|
||||||
|
authorizedUser.id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user