mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: rewrite repositories with base entity repository class.
feat: sales and purchases status. feat: sales and purchases auto-increment number. fix: settings find query with extra columns.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import { Router, Request, Response } from 'express';
|
||||
import MomentFormat from 'lib/MomentFormats';
|
||||
import moment from 'moment';
|
||||
|
||||
export default class Ping {
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,14 @@ export default class BillsController extends BaseController {
|
||||
asyncMiddleware(this.newBill.bind(this)),
|
||||
this.handleServiceError,
|
||||
);
|
||||
router.post(
|
||||
'/:id/open', [
|
||||
...this.specificBillValidationSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.openBill.bind(this)),
|
||||
this.handleServiceError,
|
||||
);
|
||||
router.post(
|
||||
'/:id', [
|
||||
...this.billValidationSchema,
|
||||
@@ -94,6 +102,8 @@ export default class BillsController extends BaseController {
|
||||
check('due_date').optional().isISO8601(),
|
||||
check('vendor_id').exists().isNumeric().toInt(),
|
||||
check('note').optional().trim().escape(),
|
||||
check('open').default(false).isBoolean().toBoolean(),
|
||||
|
||||
check('entries').isArray({ min: 1 }),
|
||||
|
||||
check('entries.*.id').optional().isNumeric().toInt(),
|
||||
@@ -117,6 +127,8 @@ export default class BillsController extends BaseController {
|
||||
check('due_date').optional().isISO8601(),
|
||||
check('vendor_id').exists().isNumeric().toInt(),
|
||||
check('note').optional().trim().escape(),
|
||||
check('open').default(false).isBoolean().toBoolean(),
|
||||
|
||||
check('entries').isArray({ min: 1 }),
|
||||
|
||||
check('entries.*.id').optional().isNumeric().toInt(),
|
||||
@@ -185,12 +197,13 @@ export default class BillsController extends BaseController {
|
||||
* @param {Response} res
|
||||
*/
|
||||
async editBill(req: Request, res: Response, next: NextFunction) {
|
||||
const { id: billId } = req.params;
|
||||
const { id: billId, user } = req.params;
|
||||
const { tenantId } = req;
|
||||
const billDTO: IBillEditDTO = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
const editedBill = await this.billsService.editBill(tenantId, billId, billDTO);
|
||||
await this.billsService.editBill(tenantId, billId, billDTO, user);
|
||||
|
||||
return res.status(200).send({
|
||||
id: billId,
|
||||
message: 'The bill has been edited successfully.',
|
||||
@@ -200,6 +213,27 @@ export default class BillsController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the given bill.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
async openBill(req: Request, res: Response, next: NextFunction) {
|
||||
const { id: billId } = req.params;
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
await this.billsService.openBill(tenantId, billId);
|
||||
|
||||
return res.status(200).send({
|
||||
id: billId,
|
||||
message: 'The bill has been opened successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given bill details with associated item entries.
|
||||
* @param {Request} req
|
||||
@@ -339,6 +373,11 @@ export default class BillsController extends BaseController {
|
||||
errors: [{ type: 'ITEMS_NOT_FOUND', code: 1000 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'BILL_ALREADY_OPEN') {
|
||||
return res.boom.badRequest(null, {
|
||||
errors: [{ type: 'BILL_ALREADY_OPEN', code: 1100 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
import SaleEstimateService from 'services/Sales/SalesEstimate';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import { ServiceError } from "exceptions";
|
||||
import { Request } from 'express-validator/src/base';
|
||||
|
||||
@Service()
|
||||
export default class SalesEstimatesController extends BaseController {
|
||||
@@ -30,6 +31,15 @@ export default class SalesEstimatesController extends BaseController {
|
||||
asyncMiddleware(this.newEstimate.bind(this)),
|
||||
this.handleServiceErrors,
|
||||
);
|
||||
router.post(
|
||||
'/:id/deliver',
|
||||
[
|
||||
...this.validateSpecificEstimateSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.deliverSaleEstimate.bind(this)),
|
||||
this.handleServiceErrors,
|
||||
);
|
||||
router.post(
|
||||
'/:id', [
|
||||
...this.validateSpecificEstimateSchema,
|
||||
@@ -75,6 +85,7 @@ export default class SalesEstimatesController extends BaseController {
|
||||
check('expiration_date').optional().isISO8601(),
|
||||
check('reference').optional(),
|
||||
check('estimate_number').exists().trim().escape(),
|
||||
check('delivered').default(false).isBoolean().toBoolean(),
|
||||
|
||||
check('entries').exists().isArray({ min: 1 }),
|
||||
check('entries.*.index').exists().isNumeric().toInt(),
|
||||
@@ -170,6 +181,27 @@ export default class SalesEstimatesController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver the given sale estimate.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async deliverSaleEstimate(req: Request, res: Response, next: NextFunction) {
|
||||
const { id: estimateId } = req.params;
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
await this.saleEstimateService.deliverSaleEstimate(tenantId, estimateId);
|
||||
|
||||
return res.status(200).send({
|
||||
id: estimateId,
|
||||
message: 'The sale estimate has been delivered successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given estimate with associated entries.
|
||||
*/
|
||||
|
||||
@@ -28,11 +28,23 @@ export default class SaleInvoicesController extends BaseController{
|
||||
|
||||
router.post(
|
||||
'/',
|
||||
this.saleInvoiceValidationSchema,
|
||||
[
|
||||
...this.saleInvoiceValidationSchema,
|
||||
check('from_estimate_id').optional().isNumeric().toInt(),
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.newSaleInvoice.bind(this)),
|
||||
this.handleServiceErrors,
|
||||
);
|
||||
router.post(
|
||||
'/:id/deliver',
|
||||
[
|
||||
...this.specificSaleInvoiceValidation,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.deliverSaleInvoice.bind(this)),
|
||||
this.handleServiceErrors,
|
||||
)
|
||||
router.post(
|
||||
'/:id',
|
||||
[
|
||||
@@ -86,7 +98,7 @@ export default class SaleInvoicesController extends BaseController{
|
||||
check('due_date').exists().isISO8601(),
|
||||
check('invoice_no').optional().trim().escape(),
|
||||
check('reference_no').optional().trim().escape(),
|
||||
check('status').exists().trim().escape(),
|
||||
check('delivered').default(false).isBoolean().toBoolean(),
|
||||
|
||||
check('invoice_message').optional().trim().escape(),
|
||||
check('terms_conditions').optional().trim().escape(),
|
||||
@@ -172,6 +184,28 @@ export default class SaleInvoicesController extends BaseController{
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver the given sale invoice.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async deliverSaleInvoice(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { id: saleInvoiceId } = req.params;
|
||||
|
||||
try {
|
||||
await this.saleInvoiceService.deliverSaleInvoice(tenantId, saleInvoiceId);
|
||||
|
||||
return res.status(200).send({
|
||||
id: saleInvoiceId,
|
||||
message: 'The given sale invoice has been published successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the sale invoice with associated entries and journal transactions.
|
||||
@@ -319,6 +353,11 @@ export default class SaleInvoicesController extends BaseController{
|
||||
errors: [{ type: 'CUSTOMER_NOT_FOUND', code: 200 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'SALE_INVOICE_ALREADY_DELIVERED') {
|
||||
return res.boom.badRequest(null, {
|
||||
errors: [{ type: 'SALE_INVOICE_ALREADY_DELIVERED', code: 200 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { Container } from 'typedi';
|
||||
import SettingsStore from 'services/Settings/SettingsStore';
|
||||
|
||||
|
||||
export default async (req: Request, res: Response, next: NextFunction) => {
|
||||
const { tenantId } = req.user;
|
||||
const { knex } = req;
|
||||
@@ -10,16 +10,19 @@ export default async (req: Request, res: Response, next: NextFunction) => {
|
||||
const tenantContainer = Container.of(`tenant-${tenantId}`);
|
||||
|
||||
if (tenantContainer && !tenantContainer.has('settings')) {
|
||||
const { settingRepository } = tenantContainer.get('repositories');
|
||||
|
||||
Logger.info('[settings_middleware] initialize settings store.');
|
||||
const settings = new SettingsStore(knex);
|
||||
|
||||
Logger.info('[settings_middleware] load settings from storage or cache.');
|
||||
await settings.load();
|
||||
|
||||
const settings = new SettingsStore(settingRepository);
|
||||
tenantContainer.set('settings', settings);
|
||||
}
|
||||
Logger.info('[settings_middleware] get settings instance from container.');
|
||||
const settings = tenantContainer.get('settings');
|
||||
|
||||
Logger.info('[settings_middleware] load settings from storage or cache.');
|
||||
await settings.load();
|
||||
|
||||
req.settings = settings;
|
||||
|
||||
res.on('finish', async () => {
|
||||
|
||||
Reference in New Issue
Block a user