mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
fix: make unique number of sales and purchases transactions is optional.
This commit is contained in:
@@ -124,7 +124,7 @@ export default class BillPaymentsService {
|
||||
* @param {string} paymentMadeNumber -
|
||||
* @return {Promise<IBillPayment>}
|
||||
*/
|
||||
private async validatePaymentNumber(tenantId: number, paymentMadeNumber: string, notPaymentMadeId?: string) {
|
||||
private async validatePaymentNumber(tenantId: number, paymentMadeNumber: string, notPaymentMadeId?: number) {
|
||||
const { BillPayment } = this.tenancy.models(tenantId);
|
||||
|
||||
const foundBillPayment = await BillPayment.query()
|
||||
@@ -259,8 +259,9 @@ export default class BillPaymentsService {
|
||||
await this.getPaymentAccountOrThrowError(tenantId, billPaymentObj.paymentAccountId);
|
||||
|
||||
// Validate the payment number uniquiness.
|
||||
await this.validatePaymentNumber(tenantId, billPaymentObj.paymentNumber);
|
||||
|
||||
if (billPaymentObj.paymentNumber) {
|
||||
await this.validatePaymentNumber(tenantId, billPaymentObj.paymentNumber);
|
||||
}
|
||||
// Validates the bills existance and associated to the given vendor.
|
||||
await this.validateBillsExistance(tenantId, billPaymentObj.entries, billPaymentDTO.vendorId);
|
||||
|
||||
@@ -328,6 +329,10 @@ export default class BillPaymentsService {
|
||||
// Validates the bills due payment amount.
|
||||
await this.validateBillsDueAmount(tenantId, billPaymentObj.entries);
|
||||
|
||||
// Validate the payment number uniquiness.
|
||||
if (billPaymentObj.paymentNumber) {
|
||||
await this.validatePaymentNumber(tenantId, billPaymentObj.paymentNumber, billPaymentId);
|
||||
}
|
||||
const billPayment = await BillPayment.query()
|
||||
.upsertGraphAndFetch({
|
||||
id: billPaymentId,
|
||||
|
||||
@@ -181,9 +181,13 @@ export default class BillsService extends SalesInvoicesCost {
|
||||
this.logger.info('[bill] trying to create a new bill', { tenantId, billDTO });
|
||||
const billObj = await this.billDTOToModel(tenantId, billDTO);
|
||||
|
||||
// Retrieve vendor or throw not found service error.
|
||||
await this.getVendorOrThrowError(tenantId, billDTO.vendorId);
|
||||
await this.validateBillNumberExists(tenantId, billDTO.billNumber);
|
||||
|
||||
// Validate the bill number uniqiness on the storage.
|
||||
if (billDTO.billNumber) {
|
||||
await this.validateBillNumberExists(tenantId, billDTO.billNumber);
|
||||
}
|
||||
// Validate items IDs existance.
|
||||
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, billDTO.entries);
|
||||
|
||||
@@ -237,9 +241,13 @@ export default class BillsService extends SalesInvoicesCost {
|
||||
const oldBill = await this.getBillOrThrowError(tenantId, billId);
|
||||
const billObj = await this.billDTOToModel(tenantId, billDTO, oldBill);
|
||||
|
||||
// Retrieve vendor details or throw not found service error.
|
||||
await this.getVendorOrThrowError(tenantId, billDTO.vendorId);
|
||||
await this.validateBillNumberExists(tenantId, billDTO.billNumber, billId);
|
||||
|
||||
// Validate bill number uniqiness on the storage.
|
||||
if (billDTO.billNumber) {
|
||||
await this.validateBillNumberExists(tenantId, billDTO.billNumber, billId);
|
||||
}
|
||||
await this.itemsEntriesService.validateEntriesIdsExistance(tenantId, billId, 'Bill', billDTO.entries);
|
||||
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, billDTO.entries);
|
||||
await this.itemsEntriesService.validateNonPurchasableEntriesItems(tenantId, billDTO.entries);
|
||||
|
||||
@@ -193,8 +193,9 @@ export default class PaymentReceiveService {
|
||||
const paymentAmount = sumBy(paymentReceiveDTO.entries, 'paymentAmount');
|
||||
|
||||
// Validate payment receive number uniquiness.
|
||||
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo);
|
||||
|
||||
if (paymentReceiveDTO.paymentReceiveNo) {
|
||||
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo);
|
||||
}
|
||||
// Validate customer existance.
|
||||
await this.customersService.getCustomerByIdOrThrowError(tenantId, paymentReceiveDTO.customerId);
|
||||
|
||||
@@ -255,8 +256,9 @@ export default class PaymentReceiveService {
|
||||
const oldPaymentReceive = await this.getPaymentReceiveOrThrowError(tenantId, paymentReceiveId);
|
||||
|
||||
// Validate payment receive number uniquiness.
|
||||
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo, paymentReceiveId);
|
||||
|
||||
if (paymentReceiveDTO.paymentReceiveNo) {
|
||||
await this.validatePaymentReceiveNoExistance(tenantId, paymentReceiveDTO.paymentReceiveNo, paymentReceiveId);
|
||||
}
|
||||
// Validate the deposit account existance and type.
|
||||
this.getDepositAccountOrThrowError(tenantId, paymentReceiveDTO.depositAccountId);
|
||||
|
||||
|
||||
@@ -99,8 +99,9 @@ export default class SaleEstimateService {
|
||||
};
|
||||
|
||||
// Validate estimate number uniquiness on the storage.
|
||||
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber);
|
||||
|
||||
if (estimateDTO.estimateNumber) {
|
||||
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber);
|
||||
}
|
||||
// Retrieve the given customer or throw not found service error.
|
||||
await this.customersService.getCustomer(tenantId, estimateDTO.customerId);
|
||||
|
||||
@@ -146,8 +147,9 @@ export default class SaleEstimateService {
|
||||
};
|
||||
|
||||
// Validate estimate number uniquiness on the storage.
|
||||
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber, estimateId);
|
||||
|
||||
if (estimateDTO.estimateNumber) {
|
||||
await this.validateEstimateNumberExistance(tenantId, estimateDTO.estimateNumber, estimateId);
|
||||
}
|
||||
// Retrieve the given customer or throw not found service error.
|
||||
await this.customersService.getCustomer(tenantId, estimateDTO.customerId);
|
||||
|
||||
|
||||
@@ -126,8 +126,9 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
||||
await this.customersService.getCustomerByIdOrThrowError(tenantId, saleInvoiceDTO.customerId);
|
||||
|
||||
// Validate sale invoice number uniquiness.
|
||||
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo);
|
||||
|
||||
if (saleInvoiceDTO.invoiceNo) {
|
||||
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo);
|
||||
}
|
||||
// Validate items ids existance.
|
||||
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, saleInvoiceDTO.entries);
|
||||
await this.itemsEntriesService.validateNonSellableEntriesItems(tenantId, saleInvoiceDTO.entries);
|
||||
@@ -174,8 +175,9 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
||||
await this.customersService.getCustomerByIdOrThrowError(tenantId, saleInvoiceDTO.customerId);
|
||||
|
||||
// Validate sale invoice number uniquiness.
|
||||
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo, saleInvoiceId);
|
||||
|
||||
if (saleInvoiceDTO.invoiceNo) {
|
||||
await this.validateInvoiceNumberUnique(tenantId, saleInvoiceDTO.invoiceNo, saleInvoiceId);
|
||||
}
|
||||
// Validate items ids existance.
|
||||
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, saleInvoiceDTO.entries);
|
||||
|
||||
|
||||
@@ -127,8 +127,9 @@ export default class SalesReceiptService {
|
||||
await this.itemsEntriesService.validateNonSellableEntriesItems(tenantId, saleReceiptDTO.entries);
|
||||
|
||||
// Validate sale receipt number uniuqiness.
|
||||
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber);
|
||||
|
||||
if (saleReceiptDTO.receiptNumber) {
|
||||
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber);
|
||||
}
|
||||
this.logger.info('[sale_receipt] trying to insert sale receipt graph.', { tenantId, saleReceiptDTO });
|
||||
const saleReceipt = await SaleReceipt.query()
|
||||
.insertGraphAndFetch({
|
||||
@@ -173,7 +174,9 @@ export default class SalesReceiptService {
|
||||
await this.itemsEntriesService.validateNonSellableEntriesItems(tenantId, saleReceiptDTO.entries);
|
||||
|
||||
// Validate sale receipt number uniuqiness.
|
||||
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber, saleReceiptId);
|
||||
if (saleReceiptDTO.receiptNumber) {
|
||||
await this.validateReceiptNumberUnique(tenantId, saleReceiptDTO.receiptNumber, saleReceiptId);
|
||||
}
|
||||
|
||||
const saleReceipt = await SaleReceipt.query()
|
||||
.upsertGraphAndFetch({
|
||||
|
||||
Reference in New Issue
Block a user