mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: get specifici payment receive/made details.
This commit is contained in:
@@ -31,20 +31,6 @@ export default class BillsPayments extends BaseController {
|
||||
router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
'/new-page/entries',
|
||||
[query('vendor_id').exists()],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillPaymentNewPageEntries.bind(this)),
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get(
|
||||
'/:id/edit-page',
|
||||
this.specificBillPaymentValidateSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillPaymentEditPage.bind(this)),
|
||||
this.handleServiceError
|
||||
);
|
||||
router.post(
|
||||
'/',
|
||||
[...this.billPaymentSchemaValidation],
|
||||
@@ -69,6 +55,20 @@ export default class BillsPayments extends BaseController {
|
||||
asyncMiddleware(this.deleteBillPayment.bind(this)),
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get(
|
||||
'/new-page/entries',
|
||||
[query('vendor_id').exists()],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillPaymentNewPageEntries.bind(this)),
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get(
|
||||
'/:id/edit-page',
|
||||
this.specificBillPaymentValidateSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillPaymentEditPage.bind(this)),
|
||||
this.handleServiceError
|
||||
);
|
||||
router.get(
|
||||
'/:id/bills',
|
||||
this.specificBillPaymentValidateSchema,
|
||||
@@ -156,10 +156,14 @@ export default class BillsPayments extends BaseController {
|
||||
|
||||
/**
|
||||
* Retrieve the bill payment edit page details.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async getBillPaymentEditPage(req: Request, res: Response, next: NextFunction) {
|
||||
async getBillPaymentEditPage(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const { id: paymentReceiveId } = req.params;
|
||||
|
||||
@@ -169,7 +173,7 @@ export default class BillsPayments extends BaseController {
|
||||
entries,
|
||||
} = await this.billPaymentService.getBillPaymentEditPage(
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
paymentReceiveId
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
@@ -265,16 +269,13 @@ export default class BillsPayments extends BaseController {
|
||||
const { id: billPaymentId } = req.params;
|
||||
|
||||
try {
|
||||
const {
|
||||
billPayment,
|
||||
payableBills,
|
||||
paymentMadeBills,
|
||||
} = await this.billPaymentService.getBillPayment(tenantId, billPaymentId);
|
||||
const billPayment = await this.billPaymentService.getBillPayment(
|
||||
tenantId,
|
||||
billPaymentId
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
bill_payment: this.transfromToResponse({ ...billPayment }),
|
||||
payable_bills: this.transfromToResponse([...payableBills]),
|
||||
payment_bills: this.transfromToResponse([...paymentMadeBills]),
|
||||
bill_payment: this.transfromToResponse(billPayment),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -40,13 +40,6 @@ export default class PaymentReceivesController extends BaseController {
|
||||
asyncMiddleware(this.newPaymentReceive.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:id/invoices',
|
||||
this.paymentReceiveValidation,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getPaymentReceiveInvoices.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:id/edit-page',
|
||||
this.paymentReceiveValidation,
|
||||
@@ -56,13 +49,24 @@ export default class PaymentReceivesController extends BaseController {
|
||||
);
|
||||
router.get(
|
||||
'/new-page/entries',
|
||||
[
|
||||
query('customer_id').exists().isNumeric().toInt(),
|
||||
],
|
||||
[query('customer_id').exists().isNumeric().toInt()],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getPaymentReceiveNewPageEntries.bind(this)),
|
||||
this.getPaymentReceiveNewPageEntries.bind(this)
|
||||
);
|
||||
router.get(
|
||||
'/:id/invoices',
|
||||
this.paymentReceiveValidation,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getPaymentReceiveInvoices.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:id',
|
||||
this.paymentReceiveValidation,
|
||||
this.asyncMiddleware(this.getPaymentReceive.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/',
|
||||
this.validatePaymentReceiveList,
|
||||
@@ -224,14 +228,18 @@ export default class PaymentReceivesController extends BaseController {
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
async getPaymentReceiveEditPage(req: Request, res: Response, next: NextFunction) {
|
||||
async getPaymentReceiveEditPage(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId, user } = req;
|
||||
const { id: paymentReceiveId } = req.params;
|
||||
|
||||
try {
|
||||
const {
|
||||
paymentReceive,
|
||||
entries
|
||||
entries,
|
||||
} = await this.paymentReceiveService.getPaymentReceiveEditPage(
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
@@ -317,10 +325,14 @@ export default class PaymentReceivesController extends BaseController {
|
||||
* @param {Request} req - Request.
|
||||
* @param {Response} res - Response.
|
||||
*/
|
||||
async getPaymentReceiveNewPageEntries(req, res) {
|
||||
async getPaymentReceiveNewPageEntries(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const { customerId } = this.matchedQueryData(req);
|
||||
|
||||
|
||||
try {
|
||||
const entries = await this.paymentReceiveService.getNewPageEntries(
|
||||
tenantId,
|
||||
@@ -329,7 +341,33 @@ export default class PaymentReceivesController extends BaseController {
|
||||
return res.status(200).send({
|
||||
entries: this.transfromToResponse(entries),
|
||||
});
|
||||
} catch (error) {}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the payment receive details.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async getPaymentReceive(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { id: paymentReceiveId } = req.params;
|
||||
|
||||
try {
|
||||
const paymentReceive = await this.paymentReceiveService.getPaymentReceive(
|
||||
tenantId,
|
||||
paymentReceiveId
|
||||
);
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.send({ payment_receive: this.transfromToResponse(paymentReceive) });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,9 +401,7 @@ export default class PaymentReceivesController extends BaseController {
|
||||
}
|
||||
if (error.errorType === 'DEPOSIT_ACCOUNT_INVALID_TYPE') {
|
||||
return res.boom.badRequest(null, {
|
||||
errors: [
|
||||
{ type: 'DEPOSIT_ACCOUNT_INVALID_TYPE', code: 300 },
|
||||
],
|
||||
errors: [{ type: 'DEPOSIT_ACCOUNT_INVALID_TYPE', code: 300 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'INVALID_PAYMENT_AMOUNT_INVALID') {
|
||||
|
||||
@@ -482,6 +482,31 @@ export default class BillPaymentsService {
|
||||
return bills;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve bill payment.
|
||||
* @param {number} tenantId
|
||||
* @param {number} billPyamentId
|
||||
* @return {Promise<IBillPayment>}
|
||||
*/
|
||||
public async getBillPayment(
|
||||
tenantId: number,
|
||||
billPyamentId: number
|
||||
): Promise<IBillPayment> {
|
||||
const { BillPayment } = this.tenancy.models(tenantId);
|
||||
|
||||
const billPayment = await BillPayment.query()
|
||||
.withGraphFetched('entries')
|
||||
.withGraphFetched('vendor')
|
||||
.withGraphFetched('paymentAccount')
|
||||
.withGraphFetched('transactions')
|
||||
.findById(billPyamentId);
|
||||
|
||||
if (!billPayment) {
|
||||
throw new ServiceError(ERRORS.PAYMENT_MADE_NOT_FOUND);
|
||||
}
|
||||
return billPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records bill payment receive journal transactions.
|
||||
* @param {number} tenantId -
|
||||
@@ -491,7 +516,7 @@ export default class BillPaymentsService {
|
||||
public async recordJournalEntries(
|
||||
tenantId: number,
|
||||
billPayment: IBillPayment,
|
||||
override: boolean = false,
|
||||
override: boolean = false
|
||||
) {
|
||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
||||
const { accountRepository } = this.tenancy.repositories(tenantId);
|
||||
@@ -612,7 +637,7 @@ export default class BillPaymentsService {
|
||||
tenantId: number,
|
||||
billPaymentId: number
|
||||
): Promise<{
|
||||
billPayment: Omit<IBillPayment, "entries">;
|
||||
billPayment: Omit<IBillPayment, 'entries'>;
|
||||
entries: IBillReceivePageEntry[];
|
||||
}> {
|
||||
const { BillPayment, Bill } = this.tenancy.models(tenantId);
|
||||
@@ -634,17 +659,17 @@ export default class BillPaymentsService {
|
||||
.where('vendor_id', billPayment.vendorId)
|
||||
.whereNotIn(
|
||||
'id',
|
||||
billPayment.entries.map((e) => e.billId),
|
||||
billPayment.entries.map((e) => e.billId)
|
||||
)
|
||||
.orderBy('bill_date', 'ASC');
|
||||
|
||||
// Mapping the payable bills to entries.
|
||||
const restPayableEntries = resPayableBills.map(this.mapBillToPageEntry);
|
||||
const entries = [...paymentEntries, ...restPayableEntries];
|
||||
|
||||
|
||||
return {
|
||||
billPayment: omit(billPayment, ['entries']),
|
||||
entries
|
||||
entries,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -712,7 +737,7 @@ export default class BillPaymentsService {
|
||||
date: bill.billDate,
|
||||
totalPaymentAmount: bill.paymentAmount,
|
||||
paymentAmount: 0,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -722,7 +747,7 @@ export default class BillPaymentsService {
|
||||
*/
|
||||
async getNewPageEntries(
|
||||
tenantId: number,
|
||||
vendorId: number,
|
||||
vendorId: number
|
||||
): Promise<IBillReceivePageEntry[]> {
|
||||
const { Bill } = this.tenancy.models(tenantId);
|
||||
|
||||
|
||||
@@ -465,6 +465,31 @@ export default class PaymentReceiveService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payment receive details.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {number} paymentReceiveId - Payment receive id.
|
||||
* @return {Promise<IPaymentReceive>}
|
||||
*/
|
||||
async getPaymentReceive(
|
||||
tenantId: number,
|
||||
paymentReceiveId: number
|
||||
): Promise<IPaymentReceive> {
|
||||
const { PaymentReceive } = this.tenancy.models(tenantId);
|
||||
const paymentReceive = await PaymentReceive.query()
|
||||
.withGraphFetched('customer')
|
||||
.withGraphFetched('depositAccount')
|
||||
.withGraphFetched('entries')
|
||||
.withGraphFetched('transactions')
|
||||
.findById(paymentReceiveId);
|
||||
|
||||
if (!paymentReceive) {
|
||||
throw new ServiceError(ERRORS.PAYMENT_RECEIVE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
return paymentReceive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive edit page invoices entries from the given sale invoices models.
|
||||
* @param {ISaleInvoice[]} invoices - Invoices.
|
||||
|
||||
Reference in New Issue
Block a user