feat(ManualJournals): Auto-increment.

fix(BillPayment): Validate the opened payment bills.
fix(redux): presist redux state.
fix(useRequestQuery): hook.
This commit is contained in:
a.bouhuolia
2021-03-18 14:23:37 +02:00
parent 4e8bdee97a
commit 9ff8e3159d
79 changed files with 1326 additions and 889 deletions

View File

@@ -172,6 +172,15 @@ export default class BillPaymentsService {
if (notFoundBillsIds.length > 0) {
throw new ServiceError(ERRORS.BILL_ENTRIES_IDS_NOT_FOUND);
}
// Validate the not opened bills.
const notOpenedBills = storedBills.filter((bill) => !bill.openedAt);
if (notOpenedBills.length > 0) {
throw new ServiceError(ERRORS.BILLS_NOT_OPENED_YET, null, {
notOpenedBills
});
}
}
/**

View File

@@ -9,4 +9,5 @@ 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'
};

View File

@@ -139,6 +139,26 @@ export default class BillsService extends SalesInvoicesCost {
}
}
/**
* Validate the bill has no payment entries.
* @param {number} tenantId
* @param {number} billId - Bill id.
*/
private async validateBillHasNoEntries(
tenantId,
billId: number,
) {
const { BillPaymentEntry } = this.tenancy.models(tenantId);
// Retireve the bill associate payment made entries.
const entries = await BillPaymentEntry.query().where('bill_id', billId);
if (entries.length > 0) {
throw new ServiceError(ERRORS.BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES);
}
return entries;
}
/**
* Validate the bill number require.
* @param {string} billNo -
@@ -354,6 +374,9 @@ export default class BillsService extends SalesInvoicesCost {
// Retrieve the given bill or throw not found error.
const oldBill = await this.getBillOrThrowError(tenantId, billId);
// Validate the purchase bill has no assocaited payments transactions.
await this.validateBillHasNoEntries(tenantId, billId);
// Delete all associated bill entries.
const deleteBillEntriesOper = ItemEntry.query()
.where('reference_type', 'Bill')

View File

@@ -7,5 +7,6 @@ export const ERRORS = {
BILL_ENTRIES_IDS_NOT_FOUND: 'BILL_ENTRIES_IDS_NOT_FOUND',
NOT_PURCHASE_ABLE_ITEMS: 'NOT_PURCHASE_ABLE_ITEMS',
BILL_ALREADY_OPEN: 'BILL_ALREADY_OPEN',
BILL_NO_IS_REQUIRED: 'BILL_NO_IS_REQUIRED'
BILL_NO_IS_REQUIRED: 'BILL_NO_IS_REQUIRED',
BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES: 'BILL_HAS_ASSOCIATED_PAYMENT_ENTRIES'
};