fix: payment receive and made.

This commit is contained in:
a.bouhuolia
2021-03-09 17:47:01 +02:00
parent 2494a33d21
commit 59f8010122
31 changed files with 395 additions and 349 deletions

View File

@@ -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
);

View File

@@ -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);
}