mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: payment made form in new and edit mode.
This commit is contained in:
@@ -151,7 +151,8 @@ export default class BillsController extends BaseController {
|
||||
get dueBillsListingValidationSchema() {
|
||||
return [
|
||||
query('vendor_id').optional().trim().escape(),
|
||||
]
|
||||
query('payment_made_id').optional().trim().escape(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,7 +332,13 @@ export default class BillsController extends BaseController {
|
||||
errors: [{ type: 'BILL_ENTRIES_IDS_NOT_FOUND', code: 900 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'ITEMS_NOT_FOUND') {
|
||||
return res.boom.badRequest(null, {
|
||||
errors: [{ type: 'ITEMS_NOT_FOUND', code: 1000 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log(error.errorType);
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,8 +198,14 @@ export default class BillsPayments extends BaseController {
|
||||
const { id: billPaymentId } = req.params;
|
||||
|
||||
try {
|
||||
const billPayment = await this.billPaymentService.getBillPayment(tenantId, billPaymentId);
|
||||
return res.status(200).send({ bill_payment: billPayment });
|
||||
const { billPayment, payableBills } = await this.billPaymentService.getBillPayment(tenantId, billPaymentId);
|
||||
|
||||
return res.status(200).send({
|
||||
bill_payment: {
|
||||
...this.transfromToResponse({ ...billPayment }),
|
||||
payable_bills: payableBills,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { check, param, query } from 'express-validator';
|
||||
import { raw } from 'objection';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import BaseController from '../BaseController';
|
||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
@@ -52,11 +51,11 @@ export default class SaleInvoicesController extends BaseController{
|
||||
this.handleServiceErrors,
|
||||
);
|
||||
router.get(
|
||||
'/due', [
|
||||
'/payable', [
|
||||
...this.dueSalesInvoicesListValidationSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getDueInvoices.bind(this)),
|
||||
asyncMiddleware(this.getPayableInvoices.bind(this)),
|
||||
this.handleServiceErrors,
|
||||
);
|
||||
router.get(
|
||||
@@ -251,12 +250,12 @@ export default class SaleInvoicesController extends BaseController{
|
||||
* @param {NextFunction} next -
|
||||
* @return {Response|void}
|
||||
*/
|
||||
public async getDueInvoices(req: Request, res: Response, next: NextFunction) {
|
||||
public async getPayableInvoices(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { customerId } = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const salesInvoices = await this.saleInvoiceService.getDueInvoices(tenantId, customerId);
|
||||
const salesInvoices = await this.saleInvoiceService.getPayableInvoices(tenantId, customerId);
|
||||
|
||||
return res.status(200).send({
|
||||
sales_invoices: this.transfromToResponse(salesInvoices),
|
||||
|
||||
@@ -70,7 +70,7 @@ export default class BillPayment extends TenantModel {
|
||||
filter(builder) {
|
||||
builder.where('reference_type', 'BillPayment');
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -489,7 +489,7 @@ export default class BillPaymentsService {
|
||||
* @return {object}
|
||||
*/
|
||||
public async getBillPayment(tenantId: number, billPaymentId: number) {
|
||||
const { BillPayment } = this.tenancy.models(tenantId);
|
||||
const { BillPayment, Bill } = this.tenancy.models(tenantId);
|
||||
const billPayment = await BillPayment.query()
|
||||
.findById(billPaymentId)
|
||||
.withGraphFetched('entries')
|
||||
@@ -499,7 +499,16 @@ export default class BillPaymentsService {
|
||||
if (!billPayment) {
|
||||
throw new ServiceError(ERRORS.PAYMENT_MADE_NOT_FOUND);
|
||||
}
|
||||
return billPayment;
|
||||
|
||||
const payableBills = await Bill.query().onBuild((builder) => {
|
||||
const billsIds = billPayment.entries.map((entry) => entry.billId);
|
||||
|
||||
builder.where('vendor_id', billPayment.vendorId);
|
||||
builder.orWhereIn('id', billsIds);
|
||||
builder.orderByRaw(`FIELD(id, ${billsIds.join(', ')}) DESC`);
|
||||
builder.orderBy('bill_date', 'ASC');
|
||||
})
|
||||
return { billPayment, payableBills };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { omit, sumBy, pick, difference } from 'lodash';
|
||||
import { omit, sumBy, pick, difference, assignWith } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
@@ -23,11 +23,13 @@ import {
|
||||
IPaginationMeta,
|
||||
IFilterMeta,
|
||||
IBillsFilter,
|
||||
IBillPaymentEntry,
|
||||
} from 'interfaces';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import ItemsService from 'services/Items/ItemsService';
|
||||
import ItemsEntriesService from 'services/Items/ItemsEntriesService';
|
||||
import { Bill } from 'models';
|
||||
import PaymentMadesSubscriber from 'subscribers/paymentMades';
|
||||
|
||||
const ERRORS = {
|
||||
BILL_NOT_FOUND: 'BILL_NOT_FOUND',
|
||||
@@ -428,6 +430,7 @@ export default class BillsService extends SalesInvoicesCost {
|
||||
const { Bill } = this.tenancy.models(tenantId);
|
||||
|
||||
const dueBills = await Bill.query().onBuild((query) => {
|
||||
query.orderBy('bill_date', 'DESC');
|
||||
query.modify('dueBills');
|
||||
|
||||
if (vendorId) {
|
||||
|
||||
@@ -413,7 +413,7 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
||||
* @param {number} tenantId
|
||||
* @param {number} customerId
|
||||
*/
|
||||
public async getDueInvoices(
|
||||
public async getPayableInvoices(
|
||||
tenantId: number,
|
||||
customerId?: number,
|
||||
): Promise<ISaleInvoice> {
|
||||
|
||||
Reference in New Issue
Block a user