mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Merge branch 'master' of https://github.com/abouolia/Bigcapital
This commit is contained in:
@@ -1,34 +1,38 @@
|
|||||||
import { check, param, query, body, ValidationChain } from 'express-validator';
|
import { check, param, query, body, ValidationChain } from 'express-validator';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { Inject } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import BaseController from 'api/controllers/BaseController';
|
import BaseController from 'api/controllers/BaseController';
|
||||||
import ContactsService from 'services/Contacts/ContactsService';
|
import ContactsService from 'services/Contacts/ContactsService';
|
||||||
|
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||||
import { DATATYPES_LENGTH } from 'data/DataTypes';
|
import { DATATYPES_LENGTH } from 'data/DataTypes';
|
||||||
import { Service } from 'typedi';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ContactsController extends BaseController {
|
export default class ContactsController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
contactsService: ContactsService;
|
contactsService: ContactsService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
dynamicListService: DynamicListingService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Express router.
|
* Express router.
|
||||||
*/
|
*/
|
||||||
router() {
|
router() {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/auto-complete',
|
||||||
|
[...this.autocompleteQuerySchema],
|
||||||
|
this.validationResult,
|
||||||
|
this.asyncMiddleware(this.autocompleteContacts.bind(this)),
|
||||||
|
this.dynamicListService.handlerErrorsToResponse
|
||||||
|
);
|
||||||
router.get(
|
router.get(
|
||||||
'/:id',
|
'/:id',
|
||||||
[param('id').exists().isNumeric().toInt()],
|
[param('id').exists().isNumeric().toInt()],
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
this.asyncMiddleware(this.getContact.bind(this))
|
this.asyncMiddleware(this.getContact.bind(this))
|
||||||
);
|
);
|
||||||
router.get(
|
|
||||||
'/auto-complete',
|
|
||||||
[...this.autocompleteQuerySchema],
|
|
||||||
this.validationResult,
|
|
||||||
this.asyncMiddleware(this.autocompleteContacts.bind(this))
|
|
||||||
);
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +83,13 @@ export default class ContactsController extends BaseController {
|
|||||||
const filter = {
|
const filter = {
|
||||||
filterRoles: [],
|
filterRoles: [],
|
||||||
sortOrder: 'asc',
|
sortOrder: 'asc',
|
||||||
columnSortBy: 'created_at',
|
columnSortBy: 'display_name',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
...this.matchedQueryData(req),
|
...this.matchedQueryData(req),
|
||||||
};
|
};
|
||||||
|
if (filter.stringifiedFilterRoles) {
|
||||||
|
filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const contacts = await this.contactsService.autocompleteContacts(
|
const contacts = await this.contactsService.autocompleteContacts(
|
||||||
tenantId,
|
tenantId,
|
||||||
|
|||||||
@@ -216,38 +216,11 @@ export default class ItemsController extends BaseController {
|
|||||||
|
|
||||||
query('stringified_filter_roles').optional().isJSON(),
|
query('stringified_filter_roles').optional().isJSON(),
|
||||||
query('limit').optional().isNumeric().toInt(),
|
query('limit').optional().isNumeric().toInt(),
|
||||||
|
|
||||||
|
query('keyword').optional().isString().trim().escape(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-complete list.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
async autocompleteList(req: Request, res: Response, next: NextFunction) {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const filter = {
|
|
||||||
filterRoles: [],
|
|
||||||
sortOrder: 'asc',
|
|
||||||
columnSortBy: 'created_at',
|
|
||||||
limit: 10,
|
|
||||||
...this.matchedQueryData(req),
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const items = await this.itemsService.autocompleteItems(
|
|
||||||
tenantId,
|
|
||||||
filter
|
|
||||||
);
|
|
||||||
return res.status(200).send({
|
|
||||||
items,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the given item details to the storage.
|
* Stores the given item details to the storage.
|
||||||
* @param {Request} req
|
* @param {Request} req
|
||||||
@@ -410,6 +383,38 @@ export default class ItemsController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-complete list.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
async autocompleteList(req: Request, res: Response, next: NextFunction) {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const filter = {
|
||||||
|
filterRoles: [],
|
||||||
|
sortOrder: 'asc',
|
||||||
|
columnSortBy: 'name',
|
||||||
|
limit: 10,
|
||||||
|
keyword: '',
|
||||||
|
...this.matchedQueryData(req),
|
||||||
|
};
|
||||||
|
if (filter.stringifiedFilterRoles) {
|
||||||
|
filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const items = await this.itemsService.autocompleteItems(
|
||||||
|
tenantId,
|
||||||
|
filter
|
||||||
|
);
|
||||||
|
return res.status(200).send({
|
||||||
|
items,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes items in bulk.
|
* Deletes items in bulk.
|
||||||
* @param {Request} req
|
* @param {Request} req
|
||||||
@@ -533,6 +538,15 @@ export default class ItemsController extends BaseController {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (error.errorType === 'ITEM_CANNOT_CHANGE_INVENTORY_TYPE') {
|
||||||
|
return res.status(400).send({
|
||||||
|
errors: [{
|
||||||
|
type: 'ITEM_CANNOT_CHANGE_INVENTORY_TYPE',
|
||||||
|
message: 'Cannot change inventory item type',
|
||||||
|
code: 340,
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import SaleInvoiceService from 'services/Sales/SalesInvoices';
|
|||||||
import ItemsService from 'services/Items/ItemsService';
|
import ItemsService from 'services/Items/ItemsService';
|
||||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||||
import { ServiceError } from 'exceptions';
|
import { ServiceError } from 'exceptions';
|
||||||
import { ISaleInvoiceDTO, ISalesInvoicesFilter } from 'interfaces';
|
import { ISaleInvoiceDTO, ISaleInvoiceCreateDTO } from 'interfaces';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SaleInvoicesController extends BaseController {
|
export default class SaleInvoicesController extends BaseController {
|
||||||
@@ -153,7 +153,7 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
async newSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
async newSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
||||||
const { tenantId, user } = req;
|
const { tenantId, user } = req;
|
||||||
const saleInvoiceDTO: ISaleInvoiceDTO = this.matchedBodyData(req);
|
const saleInvoiceDTO: ISaleInvoiceCreateDTO = this.matchedBodyData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Creates a new sale invoice with associated entries.
|
// Creates a new sale invoice with associated entries.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { ServiceError } from 'exceptions';
|
|||||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SalesReceiptsController extends BaseController{
|
export default class SalesReceiptsController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
saleReceiptService: SaleReceiptService;
|
saleReceiptService: SaleReceiptService;
|
||||||
|
|
||||||
@@ -24,36 +24,35 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
'/:id/close',
|
'/:id/close',
|
||||||
[
|
[...this.specificReceiptValidationSchema],
|
||||||
...this.specificReceiptValidationSchema,
|
|
||||||
],
|
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.closeSaleReceipt.bind(this)),
|
asyncMiddleware(this.closeSaleReceipt.bind(this)),
|
||||||
this.handleServiceErrors,
|
this.handleServiceErrors
|
||||||
)
|
);
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
'/:id', [
|
'/:id',
|
||||||
|
[
|
||||||
...this.specificReceiptValidationSchema,
|
...this.specificReceiptValidationSchema,
|
||||||
...this.salesReceiptsValidationSchema,
|
...this.salesReceiptsValidationSchema,
|
||||||
],
|
],
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.editSaleReceipt.bind(this)),
|
asyncMiddleware(this.editSaleReceipt.bind(this)),
|
||||||
this.handleServiceErrors,
|
this.handleServiceErrors
|
||||||
);
|
);
|
||||||
router.post(
|
router.post(
|
||||||
'/',
|
'/',
|
||||||
this.salesReceiptsValidationSchema,
|
this.salesReceiptsValidationSchema,
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.newSaleReceipt.bind(this)),
|
asyncMiddleware(this.newSaleReceipt.bind(this)),
|
||||||
this.handleServiceErrors,
|
this.handleServiceErrors
|
||||||
);
|
);
|
||||||
router.delete(
|
router.delete(
|
||||||
'/:id',
|
'/:id',
|
||||||
this.specificReceiptValidationSchema,
|
this.specificReceiptValidationSchema,
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.deleteSaleReceipt.bind(this)),
|
asyncMiddleware(this.deleteSaleReceipt.bind(this)),
|
||||||
this.handleServiceErrors,
|
this.handleServiceErrors
|
||||||
);
|
);
|
||||||
router.get(
|
router.get(
|
||||||
'/',
|
'/',
|
||||||
@@ -61,15 +60,14 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.getSalesReceipts.bind(this)),
|
asyncMiddleware(this.getSalesReceipts.bind(this)),
|
||||||
this.handleServiceErrors,
|
this.handleServiceErrors,
|
||||||
this.dynamicListService.handlerErrorsToResponse,
|
this.dynamicListService.handlerErrorsToResponse
|
||||||
);
|
);
|
||||||
router.get(
|
router.get(
|
||||||
'/:id', [
|
'/:id',
|
||||||
...this.specificReceiptValidationSchema,
|
[...this.specificReceiptValidationSchema],
|
||||||
],
|
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.getSaleReceipt.bind(this)),
|
asyncMiddleware(this.getSaleReceipt.bind(this)),
|
||||||
this.handleServiceErrors,
|
this.handleServiceErrors
|
||||||
);
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
@@ -94,8 +92,14 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
check('entries.*.item_id').exists().isNumeric().toInt(),
|
check('entries.*.item_id').exists().isNumeric().toInt(),
|
||||||
check('entries.*.quantity').exists().isNumeric().toInt(),
|
check('entries.*.quantity').exists().isNumeric().toInt(),
|
||||||
check('entries.*.rate').exists().isNumeric().toInt(),
|
check('entries.*.rate').exists().isNumeric().toInt(),
|
||||||
check('entries.*.discount').optional({ nullable: true }).isNumeric().toInt(),
|
check('entries.*.discount')
|
||||||
check('entries.*.description').optional({ nullable: true }).trim().escape(),
|
.optional({ nullable: true })
|
||||||
|
.isNumeric()
|
||||||
|
.toInt(),
|
||||||
|
check('entries.*.description')
|
||||||
|
.optional({ nullable: true })
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
check('receipt_message').optional().trim().escape(),
|
check('receipt_message').optional().trim().escape(),
|
||||||
check('statement').optional().trim().escape(),
|
check('statement').optional().trim().escape(),
|
||||||
@@ -106,9 +110,7 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
* Specific sale receipt validation schema.
|
* Specific sale receipt validation schema.
|
||||||
*/
|
*/
|
||||||
get specificReceiptValidationSchema() {
|
get specificReceiptValidationSchema() {
|
||||||
return [
|
return [param('id').exists().isNumeric().toInt()];
|
||||||
param('id').exists().isNumeric().toInt()
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,11 +138,10 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Store the given sale receipt details with associated entries.
|
// Store the given sale receipt details with associated entries.
|
||||||
const storedSaleReceipt = await this.saleReceiptService
|
const storedSaleReceipt = await this.saleReceiptService.createSaleReceipt(
|
||||||
.createSaleReceipt(
|
tenantId,
|
||||||
tenantId,
|
saleReceiptDTO
|
||||||
saleReceiptDTO,
|
);
|
||||||
);
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: storedSaleReceipt.id,
|
id: storedSaleReceipt.id,
|
||||||
message: 'Sale receipt has been created successfully.',
|
message: 'Sale receipt has been created successfully.',
|
||||||
@@ -188,7 +189,7 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
await this.saleReceiptService.editSaleReceipt(
|
await this.saleReceiptService.editSaleReceipt(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleReceiptId,
|
saleReceiptId,
|
||||||
saleReceipt,
|
saleReceipt
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleReceiptId,
|
id: saleReceiptId,
|
||||||
@@ -211,10 +212,7 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Update the given sale receipt details.
|
// Update the given sale receipt details.
|
||||||
await this.saleReceiptService.closeSaleReceipt(
|
await this.saleReceiptService.closeSaleReceipt(tenantId, saleReceiptId);
|
||||||
tenantId,
|
|
||||||
saleReceiptId,
|
|
||||||
);
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleReceiptId,
|
id: saleReceiptId,
|
||||||
message: 'Sale receipt has been closed successfully.',
|
message: 'Sale receipt has been closed successfully.',
|
||||||
@@ -244,8 +242,11 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { salesReceipts, pagination, filterMeta } = await this.saleReceiptService
|
const {
|
||||||
.salesReceiptsList(tenantId, filter);
|
salesReceipts,
|
||||||
|
pagination,
|
||||||
|
filterMeta,
|
||||||
|
} = await this.saleReceiptService.salesReceiptsList(tenantId, filter);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
sale_receipts: salesReceipts,
|
sale_receipts: salesReceipts,
|
||||||
@@ -268,11 +269,14 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const saleReceipt = await this.saleReceiptService.getSaleReceipt(tenantId, saleReceiptId);
|
const saleReceipt = await this.saleReceiptService.getSaleReceipt(
|
||||||
|
tenantId,
|
||||||
|
saleReceiptId
|
||||||
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
sale_receipt: saleReceipt,
|
sale_receipt: saleReceipt,
|
||||||
})
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -285,36 +289,41 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @param {NextFunction} next
|
* @param {NextFunction} next
|
||||||
*/
|
*/
|
||||||
handleServiceErrors(error: Error, req: Request, res: Response, next: NextFunction) {
|
handleServiceErrors(
|
||||||
|
error: Error,
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
if (error instanceof ServiceError) {
|
if (error instanceof ServiceError) {
|
||||||
if (error.errorType === 'SALE_RECEIPT_NOT_FOUND') {
|
if (error.errorType === 'SALE_RECEIPT_NOT_FOUND') {
|
||||||
return res.boom.badRequest(null, {
|
return res.boom.badRequest(null, {
|
||||||
errors: [{ type: 'SALE_RECEIPT_NOT_FOUND', code: 100 }],
|
errors: [{ type: 'SALE_RECEIPT_NOT_FOUND', code: 100 }],
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'DEPOSIT_ACCOUNT_NOT_FOUND') {
|
if (error.errorType === 'DEPOSIT_ACCOUNT_NOT_FOUND') {
|
||||||
return res.boom.badRequest(null, {
|
return res.boom.badRequest(null, {
|
||||||
errors: [{ type: 'DEPOSIT_ACCOUNT_NOT_FOUND', code: 200 }],
|
errors: [{ type: 'DEPOSIT_ACCOUNT_NOT_FOUND', code: 200 }],
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'DEPOSIT_ACCOUNT_NOT_CURRENT_ASSET') {
|
if (error.errorType === 'DEPOSIT_ACCOUNT_NOT_CURRENT_ASSET') {
|
||||||
return res.boom.badRequest(null, {
|
return res.boom.badRequest(null, {
|
||||||
errors: [{ type: 'DEPOSIT_ACCOUNT_NOT_CURRENT_ASSET', code: 300 }],
|
errors: [{ type: 'DEPOSIT_ACCOUNT_NOT_CURRENT_ASSET', code: 300 }],
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'ITEMS_NOT_FOUND') {
|
if (error.errorType === 'ITEMS_NOT_FOUND') {
|
||||||
return res.boom.badRequest(null, {
|
return res.boom.badRequest(null, {
|
||||||
errors: [{ type: 'ITEMS_NOT_FOUND', code: 400, }],
|
errors: [{ type: 'ITEMS_NOT_FOUND', code: 400 }],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'ENTRIES_IDS_NOT_FOUND') {
|
if (error.errorType === 'ENTRIES_IDS_NOT_FOUND') {
|
||||||
return res.boom.badRequest(null, {
|
return res.boom.badRequest(null, {
|
||||||
errors: [{ type: 'ENTRIES_IDS_NOT_FOUND', code: 500, }],
|
errors: [{ type: 'ENTRIES_IDS_NOT_FOUND', code: 500 }],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'NOT_SELL_ABLE_ITEMS') {
|
if (error.errorType === 'NOT_SELL_ABLE_ITEMS') {
|
||||||
return res.boom.badRequest(null, {
|
return res.boom.badRequest(null, {
|
||||||
errors: [{ type: 'NOT_SELL_ABLE_ITEMS', code: 600, }],
|
errors: [{ type: 'NOT_SELL_ABLE_ITEMS', code: 600 }],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'SALE.RECEIPT.NOT.FOUND') {
|
if (error.errorType === 'SALE.RECEIPT.NOT.FOUND') {
|
||||||
@@ -340,4 +349,4 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
}
|
}
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
// Contact Interfaces.
|
import { IFilterRole } from "./DynamicFilter";
|
||||||
|
|
||||||
import { IDynamicListFilter } from "./DynamicFilter";
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
export interface IContactAddress {
|
export interface IContactAddress {
|
||||||
@@ -208,6 +206,9 @@ export interface ICustomersFilter extends IDynamicListFilter {
|
|||||||
export interface IContactsAutoCompleteFilter {
|
export interface IContactsAutoCompleteFilter {
|
||||||
limit: number,
|
limit: number,
|
||||||
keyword: string,
|
keyword: string,
|
||||||
|
filterRoles?: IFilterRole[];
|
||||||
|
columnSortBy: string;
|
||||||
|
sortOrder: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IContactAutoCompleteItem {
|
export interface IContactAutoCompleteItem {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IDynamicListFilter } from 'interfaces/DynamicFilter';
|
import { IFilterRole } from 'interfaces/DynamicFilter';
|
||||||
|
|
||||||
export interface IItem{
|
export interface IItem{
|
||||||
id: number,
|
id: number,
|
||||||
@@ -72,7 +72,7 @@ export interface IItemsService {
|
|||||||
itemsList(tenantId: number, itemsFilter: IItemsFilter): Promise<{items: IItem[]}>;
|
itemsList(tenantId: number, itemsFilter: IItemsFilter): Promise<{items: IItem[]}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IItemsFilter extends IDynamicListFilter {
|
export interface IItemsFilter extends IDynamicListFilterDTO {
|
||||||
stringifiedFilterRoles?: string,
|
stringifiedFilterRoles?: string,
|
||||||
page: number,
|
page: number,
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
@@ -81,5 +81,7 @@ export interface IItemsFilter extends IDynamicListFilter {
|
|||||||
export interface IItemsAutoCompleteFilter {
|
export interface IItemsAutoCompleteFilter {
|
||||||
limit: number,
|
limit: number,
|
||||||
keyword: string,
|
keyword: string,
|
||||||
|
filterRoles?: IFilterRole[];
|
||||||
|
columnSortBy: string;
|
||||||
|
sortOrder: string;
|
||||||
}
|
}
|
||||||
@@ -97,6 +97,12 @@ export default class Contact extends TenantModel {
|
|||||||
|
|
||||||
static get fields() {
|
static get fields() {
|
||||||
return {
|
return {
|
||||||
|
contact_service: {
|
||||||
|
column: 'contact_service',
|
||||||
|
},
|
||||||
|
display_name: {
|
||||||
|
column: 'display_name',
|
||||||
|
},
|
||||||
created_at: {
|
created_at: {
|
||||||
column: 'created_at',
|
column: 'created_at',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -417,6 +417,8 @@ export default class JournalCommands {
|
|||||||
referenceId: saleReceipt.id,
|
referenceId: saleReceipt.id,
|
||||||
date: saleReceipt.receiptDate,
|
date: saleReceipt.receiptDate,
|
||||||
userId: saleReceipt.userId,
|
userId: saleReceipt.userId,
|
||||||
|
transactionNumber: saleReceipt.receiptNumber,
|
||||||
|
referenceNumber: saleReceipt.referenceNo,
|
||||||
};
|
};
|
||||||
// XXX Debit - Deposit account.
|
// XXX Debit - Deposit account.
|
||||||
const depositEntry = new JournalEntry({
|
const depositEntry = new JournalEntry({
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ export default class ContactsService {
|
|||||||
// Retrieve contacts list by the given query.
|
// Retrieve contacts list by the given query.
|
||||||
const contacts = await Contact.query().onBuild((builder) => {
|
const contacts = await Contact.query().onBuild((builder) => {
|
||||||
if (contactsFilter.keyword) {
|
if (contactsFilter.keyword) {
|
||||||
builder.where('display_name', 'LIKE', contactsFilter.keyword);
|
builder.where('display_name', 'LIKE', `%${contactsFilter.keyword}%`);
|
||||||
}
|
}
|
||||||
dynamicList.buildQuery()(builder);
|
dynamicList.buildQuery()(builder);
|
||||||
builder.limit(contactsFilter.limit);
|
builder.limit(contactsFilter.limit);
|
||||||
|
|||||||
@@ -227,6 +227,37 @@ export default class ItemsService implements IItemsService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {IItemDTO} itemDTO - Item DTO.
|
||||||
|
* @param {IItem} oldItem -
|
||||||
|
*/
|
||||||
|
private transformEditItemDTOToModel(itemDTO: IItemDTO, oldItem: IItem) {
|
||||||
|
return {
|
||||||
|
...itemDTO,
|
||||||
|
...(itemDTO.type === 'inventory' && oldItem.type !== 'inventory'
|
||||||
|
? {
|
||||||
|
quantityOnHand: 0,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate item type in edit item mode, cannot change item inventory type.
|
||||||
|
* @param {IItemDTO} itemDTO
|
||||||
|
* @param {IItem} oldItem
|
||||||
|
*/
|
||||||
|
private validateEditItemInventoryType(itemDTO: IItemDTO, oldItem: IItem) {
|
||||||
|
if (
|
||||||
|
itemDTO.type &&
|
||||||
|
oldItem.type === 'inventory' &&
|
||||||
|
itemDTO.type !== oldItem.type
|
||||||
|
) {
|
||||||
|
throw new ServiceError(ERRORS.ITEM_CANNOT_CHANGE_INVENTORY_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new item.
|
* Creates a new item.
|
||||||
* @param {number} tenantId DTO
|
* @param {number} tenantId DTO
|
||||||
@@ -288,6 +319,11 @@ export default class ItemsService implements IItemsService {
|
|||||||
// Validates the given item existance on the storage.
|
// Validates the given item existance on the storage.
|
||||||
const oldItem = await this.getItemOrThrowError(tenantId, itemId);
|
const oldItem = await this.getItemOrThrowError(tenantId, itemId);
|
||||||
|
|
||||||
|
this.validateEditItemInventoryType(itemDTO, oldItem);
|
||||||
|
|
||||||
|
// Transform the edit item DTO to model.
|
||||||
|
const itemModel = this.transformEditItemDTOToModel(itemDTO, oldItem);
|
||||||
|
|
||||||
// Validate whether the given item name already exists on the storage.
|
// Validate whether the given item name already exists on the storage.
|
||||||
await this.validateItemNameUniquiness(tenantId, itemDTO.name, itemId);
|
await this.validateItemNameUniquiness(tenantId, itemDTO.name, itemId);
|
||||||
|
|
||||||
@@ -318,7 +354,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newItem = await Item.query().patchAndFetchById(itemId, {
|
const newItem = await Item.query().patchAndFetchById(itemId, {
|
||||||
...itemDTO,
|
...itemModel,
|
||||||
});
|
});
|
||||||
this.logger.info('[items] item edited successfully.', {
|
this.logger.info('[items] item edited successfully.', {
|
||||||
tenantId,
|
tenantId,
|
||||||
@@ -523,14 +559,14 @@ export default class ItemsService implements IItemsService {
|
|||||||
|
|
||||||
dynamicFilter.buildQuery()(builder);
|
dynamicFilter.buildQuery()(builder);
|
||||||
builder.limit(itemsFilter.limit);
|
builder.limit(itemsFilter.limit);
|
||||||
});
|
|
||||||
|
|
||||||
// const autocompleteItems = this.transformAutoCompleteItems(items);
|
if (itemsFilter.keyword) {
|
||||||
|
builder.where('name', 'LIKE', `%${itemsFilter.keyword}%`);
|
||||||
|
}
|
||||||
|
});
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
// transformAutoCompleteItems(item)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the given item or items have no associated invoices or bills.
|
* Validates the given item or items have no associated invoices or bills.
|
||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
export const ERRORS = {
|
export const ERRORS = {
|
||||||
NOT_FOUND: 'NOT_FOUND',
|
NOT_FOUND: 'NOT_FOUND',
|
||||||
ITEMS_NOT_FOUND: 'ITEMS_NOT_FOUND',
|
ITEMS_NOT_FOUND: 'ITEMS_NOT_FOUND',
|
||||||
@@ -18,4 +17,5 @@ export const ERRORS = {
|
|||||||
|
|
||||||
ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT:
|
ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT:
|
||||||
'ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT',
|
'ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT',
|
||||||
|
ITEM_CANNOT_CHANGE_INVENTORY_TYPE: 'ITEM_CANNOT_CHANGE_INVENTORY_TYPE',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -181,19 +181,16 @@ export default class SalesReceiptService {
|
|||||||
tenantId,
|
tenantId,
|
||||||
saleReceiptDTO.depositAccountId
|
saleReceiptDTO.depositAccountId
|
||||||
);
|
);
|
||||||
|
|
||||||
// Validate items IDs existance on the storage.
|
// Validate items IDs existance on the storage.
|
||||||
await this.itemsEntriesService.validateItemsIdsExistance(
|
await this.itemsEntriesService.validateItemsIdsExistance(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleReceiptDTO.entries
|
saleReceiptDTO.entries
|
||||||
);
|
);
|
||||||
|
|
||||||
// Validate the sellable items.
|
// Validate the sellable items.
|
||||||
await this.itemsEntriesService.validateNonSellableEntriesItems(
|
await this.itemsEntriesService.validateNonSellableEntriesItems(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleReceiptDTO.entries
|
saleReceiptDTO.entries
|
||||||
);
|
);
|
||||||
|
|
||||||
// Validate sale receipt number uniuqiness.
|
// Validate sale receipt number uniuqiness.
|
||||||
if (saleReceiptDTO.receiptNumber) {
|
if (saleReceiptDTO.receiptNumber) {
|
||||||
await this.validateReceiptNumberUnique(
|
await this.validateReceiptNumberUnique(
|
||||||
@@ -460,7 +457,7 @@ export default class SalesReceiptService {
|
|||||||
saleReceipt: ISaleReceipt,
|
saleReceipt: ISaleReceipt,
|
||||||
override?: boolean
|
override?: boolean
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.inventoryService.recordInventoryTransactionsFromItemsEntries(
|
return this.inventoryService.recordInventoryTransactionsFromItemsEntries(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleReceipt.id,
|
saleReceipt.id,
|
||||||
'SaleReceipt',
|
'SaleReceipt',
|
||||||
@@ -468,15 +465,6 @@ export default class SalesReceiptService {
|
|||||||
'OUT',
|
'OUT',
|
||||||
override,
|
override,
|
||||||
);
|
);
|
||||||
// Triggers `onInventoryTransactionsCreated` event.
|
|
||||||
this.eventDispatcher.dispatch(
|
|
||||||
events.saleReceipt.onInventoryTransactionsCreated,
|
|
||||||
{
|
|
||||||
tenantId,
|
|
||||||
saleReceipt,
|
|
||||||
saleReceiptId: saleReceipt.id,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user