mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
fix: payment receive and made.
This commit is contained in:
@@ -4,11 +4,11 @@ import { check, param, query, ValidationChain } from 'express-validator';
|
||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import BaseController from 'api/controllers/BaseController';
|
||||
import BillPaymentsService from 'services/Purchases/BillPayments';
|
||||
import BillPaymentsService from 'services/Purchases/BillPayments/BillPayments';
|
||||
import BillPaymentsPages from 'services/Purchases/BillPayments/BillPaymentsPages';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import AccountsService from 'services/Accounts/AccountsService';
|
||||
import ResourceController from '../Resources';
|
||||
import { Request } from 'express-validator/src/base';
|
||||
|
||||
|
||||
/**
|
||||
* Bills payments controller.
|
||||
@@ -25,6 +25,9 @@ export default class BillsPayments extends BaseController {
|
||||
@Inject()
|
||||
dynamicListService: DynamicListingService;
|
||||
|
||||
@Inject()
|
||||
billPaymentsPages: BillPaymentsPages;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
@@ -144,7 +147,7 @@ export default class BillsPayments extends BaseController {
|
||||
const { vendorId } = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const entries = await this.billPaymentService.getNewPageEntries(
|
||||
const entries = await this.billPaymentsPages.getNewPageEntries(
|
||||
tenantId,
|
||||
vendorId
|
||||
);
|
||||
@@ -171,7 +174,7 @@ export default class BillsPayments extends BaseController {
|
||||
const {
|
||||
billPayment,
|
||||
entries,
|
||||
} = await this.billPaymentService.getBillPaymentEditPage(
|
||||
} = await this.billPaymentsPages.getBillPaymentEditPage(
|
||||
tenantId,
|
||||
paymentReceiveId
|
||||
);
|
||||
|
||||
@@ -4,7 +4,8 @@ import { Inject, Service } from 'typedi';
|
||||
import { IPaymentReceiveDTO } from 'interfaces';
|
||||
import BaseController from 'api/controllers/BaseController';
|
||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
import PaymentReceiveService from 'services/Sales/PaymentsReceives';
|
||||
import PaymentReceiveService from 'services/Sales/PaymentReceives/PaymentsReceives';
|
||||
import PaymentReceivesPages from 'services/Sales/PaymentReceives/PaymentReceivesPages';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import { ServiceError } from 'exceptions';
|
||||
|
||||
@@ -17,6 +18,9 @@ export default class PaymentReceivesController extends BaseController {
|
||||
@Inject()
|
||||
paymentReceiveService: PaymentReceiveService;
|
||||
|
||||
@Inject()
|
||||
PaymentReceivesPages: PaymentReceivesPages;
|
||||
|
||||
@Inject()
|
||||
dynamicListService: DynamicListingService;
|
||||
|
||||
@@ -132,9 +136,7 @@ export default class PaymentReceivesController extends BaseController {
|
||||
* @return {Array}
|
||||
*/
|
||||
get newPaymentReceiveValidation() {
|
||||
return [
|
||||
...this.paymentReceiveSchema,
|
||||
];
|
||||
return [...this.paymentReceiveSchema];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,6 +151,9 @@ export default class PaymentReceivesController extends BaseController {
|
||||
|
||||
/**
|
||||
* Records payment receive to the given customer with associated invoices.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @return {Response}
|
||||
*/
|
||||
async newPaymentReceive(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, user } = req;
|
||||
@@ -165,6 +170,7 @@ export default class PaymentReceivesController extends BaseController {
|
||||
message: 'The payment receive has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
@@ -222,39 +228,6 @@ export default class PaymentReceivesController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given payment receive details.
|
||||
* @asycn
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
async getPaymentReceiveEditPage(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId, user } = req;
|
||||
const { id: paymentReceiveId } = req.params;
|
||||
|
||||
try {
|
||||
const {
|
||||
paymentReceive,
|
||||
entries,
|
||||
} = await this.paymentReceiveService.getPaymentReceiveEditPage(
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
user
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
payment_receive: this.transfromToResponse({ ...paymentReceive }),
|
||||
entries: this.transfromToResponse([...entries]),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale invoices that associated with the given payment receive.
|
||||
* @param {Request} req
|
||||
@@ -334,7 +307,7 @@ export default class PaymentReceivesController extends BaseController {
|
||||
const { customerId } = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const entries = await this.paymentReceiveService.getNewPageEntries(
|
||||
const entries = await this.PaymentReceivesPages.getNewPageEntries(
|
||||
tenantId,
|
||||
customerId
|
||||
);
|
||||
@@ -346,6 +319,39 @@ export default class PaymentReceivesController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given payment receive details.
|
||||
* @asycn
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
async getPaymentReceiveEditPage(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId, user } = req;
|
||||
const { id: paymentReceiveId } = req.params;
|
||||
|
||||
try {
|
||||
const {
|
||||
paymentReceive,
|
||||
entries,
|
||||
} = await this.PaymentReceivesPages.getPaymentReceiveEditPage(
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
user
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
payment_receive: this.transfromToResponse({ ...paymentReceive }),
|
||||
entries: this.transfromToResponse([...entries]),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the payment receive details.
|
||||
* @param {Request} req
|
||||
@@ -454,6 +460,11 @@ export default class PaymentReceivesController extends BaseController {
|
||||
errors: [{ type: 'PAYMENT_CUSTOMER_SHOULD_NOT_UPDATE', code: 1200 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'PAYMENT_RECEIVE_NO_REQUIRED') {
|
||||
return res.boom.badRequest(null, {
|
||||
errors: [{ type: 'PAYMENT_RECEIVE_NO_REQUIRED', code: 1300 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
next(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user