mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix(Contacts): validate contact associated transcations.
This commit is contained in:
@@ -33,8 +33,8 @@ import { ERRORS } from './constants';
|
||||
* Bill payments service.
|
||||
* @service
|
||||
*/
|
||||
@Service()
|
||||
export default class BillPaymentsService {
|
||||
@Service('BillPayments')
|
||||
export default class BillPaymentsService implements IBillPaymentsService {
|
||||
@Inject()
|
||||
accountsService: AccountsService;
|
||||
|
||||
@@ -178,7 +178,7 @@ export default class BillPaymentsService {
|
||||
|
||||
if (notOpenedBills.length > 0) {
|
||||
throw new ServiceError(ERRORS.BILLS_NOT_OPENED_YET, null, {
|
||||
notOpenedBills
|
||||
notOpenedBills,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -696,4 +696,19 @@ export default class BillPaymentsService {
|
||||
);
|
||||
await Promise.all(opers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the given vendor has no associated payments.
|
||||
* @param {number} tenantId
|
||||
* @param {number} vendorId
|
||||
*/
|
||||
public async validateVendorHasNoPayments(tenantId: number, vendorId: number) {
|
||||
const { BillPayment } = this.tenancy.models(tenantId);
|
||||
|
||||
const payments = await BillPayment.query().where('vendor_id', vendorId);
|
||||
|
||||
if (payments.length > 0) {
|
||||
throw new ServiceError(ERRORS.VENDOR_HAS_PAYMENTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,6 @@ export const ERRORS = {
|
||||
BILL_PAYMENT_ENTRIES_NOT_FOUND: 'BILL_PAYMENT_ENTRIES_NOT_FOUND',
|
||||
INVALID_BILL_PAYMENT_AMOUNT: 'INVALID_BILL_PAYMENT_AMOUNT',
|
||||
PAYMENT_NUMBER_SHOULD_NOT_MODIFY: 'PAYMENT_NUMBER_SHOULD_NOT_MODIFY',
|
||||
BILLS_NOT_OPENED_YET: 'BILLS_NOT_OPENED_YET'
|
||||
BILLS_NOT_OPENED_YET: 'BILLS_NOT_OPENED_YET',
|
||||
VENDOR_HAS_PAYMENTS: 'VENDOR_HAS_PAYMENTS'
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
IPaginationMeta,
|
||||
IFilterMeta,
|
||||
IBillsFilter,
|
||||
IBillsService
|
||||
} from 'interfaces';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import ItemsService from 'services/Items/ItemsService';
|
||||
@@ -34,8 +35,8 @@ import { ERRORS } from './constants';
|
||||
* Vendor bills services.
|
||||
* @service
|
||||
*/
|
||||
@Service()
|
||||
export default class BillsService extends SalesInvoicesCost {
|
||||
@Service('Bills')
|
||||
export default class BillsService extends SalesInvoicesCost implements IBillsService {
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
|
||||
@@ -141,13 +142,10 @@ export default class BillsService extends SalesInvoicesCost {
|
||||
|
||||
/**
|
||||
* Validate the bill has no payment entries.
|
||||
* @param {number} tenantId
|
||||
* @param {number} tenantId
|
||||
* @param {number} billId - Bill id.
|
||||
*/
|
||||
private async validateBillHasNoEntries(
|
||||
tenantId,
|
||||
billId: number,
|
||||
) {
|
||||
private async validateBillHasNoEntries(tenantId, billId: number) {
|
||||
const { BillPaymentEntry } = this.tenancy.models(tenantId);
|
||||
|
||||
// Retireve the bill associate payment made entries.
|
||||
@@ -578,4 +576,22 @@ export default class BillsService extends SalesInvoicesCost {
|
||||
'Bill'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the given vendor has no associated bills transactions.
|
||||
* @param {number} tenantId
|
||||
* @param {number} vendorId - Vendor id.
|
||||
*/
|
||||
public async validateVendorHasNoBills(
|
||||
tenantId: number,
|
||||
vendorId: number
|
||||
) {
|
||||
const { Bill } = this.tenancy.models(tenantId);
|
||||
|
||||
const bills = await Bill.query().where('vendor_id', vendorId);
|
||||
|
||||
if (bills.length > 0) {
|
||||
throw new ServiceError(ERRORS.VENDOR_HAS_BILLS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ export const ERRORS = {
|
||||
NOT_PURCHASE_ABLE_ITEMS: 'NOT_PURCHASE_ABLE_ITEMS',
|
||||
BILL_ALREADY_OPEN: 'BILL_ALREADY_OPEN',
|
||||
BILL_NO_IS_REQUIRED: 'BILL_NO_IS_REQUIRED',
|
||||
BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES: 'BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES'
|
||||
BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES: 'BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES',
|
||||
VENDOR_HAS_BILLS: 'VENDOR_HAS_BILLS'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user